Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- c -*- --------------------------------------------------------------- * |
| 2 | * |
| 3 | * linux/fs/autofs/waitq.c |
| 4 | * |
| 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 6 | * Copyright 2001-2006 Ian Kent <raven@themaw.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This file is part of the Linux kernel and is made available under |
| 9 | * the terms of the GNU General Public License, version 2, or at your |
| 10 | * option, any later version, incorporated herein by reference. |
| 11 | * |
| 12 | * ------------------------------------------------------------------------- */ |
| 13 | |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/time.h> |
| 16 | #include <linux/signal.h> |
| 17 | #include <linux/file.h> |
| 18 | #include "autofs_i.h" |
| 19 | |
| 20 | /* We make this a static variable rather than a part of the superblock; it |
| 21 | is better if we don't reassign numbers easily even across filesystems */ |
| 22 | static autofs_wqt_t autofs4_next_wait_queue = 1; |
| 23 | |
| 24 | /* These are the signals we allow interrupting a pending mount */ |
| 25 | #define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT)) |
| 26 | |
| 27 | void autofs4_catatonic_mode(struct autofs_sb_info *sbi) |
| 28 | { |
| 29 | struct autofs_wait_queue *wq, *nwq; |
| 30 | |
Ian Kent | 5a11d4d | 2008-07-23 21:30:17 -0700 | [diff] [blame] | 31 | mutex_lock(&sbi->wq_mutex); |
| 32 | if (sbi->catatonic) { |
| 33 | mutex_unlock(&sbi->wq_mutex); |
| 34 | return; |
| 35 | } |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | DPRINTK("entering catatonic mode"); |
| 38 | |
| 39 | sbi->catatonic = 1; |
| 40 | wq = sbi->queues; |
| 41 | sbi->queues = NULL; /* Erase all wait queues */ |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 42 | while (wq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | nwq = wq->next; |
| 44 | wq->status = -ENOENT; /* Magic is gone - report failure */ |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 45 | if (wq->name.name) { |
| 46 | kfree(wq->name.name); |
| 47 | wq->name.name = NULL; |
| 48 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | wake_up_interruptible(&wq->queue); |
| 50 | wq = nwq; |
| 51 | } |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 52 | fput(sbi->pipe); /* Close the pipe */ |
| 53 | sbi->pipe = NULL; |
Ian Kent | 5a11d4d | 2008-07-23 21:30:17 -0700 | [diff] [blame] | 54 | sbi->pipefd = -1; |
| 55 | mutex_unlock(&sbi->wq_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static int autofs4_write(struct file *file, const void *addr, int bytes) |
| 59 | { |
| 60 | unsigned long sigpipe, flags; |
| 61 | mm_segment_t fs; |
| 62 | const char *data = (const char *)addr; |
| 63 | ssize_t wr = 0; |
| 64 | |
| 65 | /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/ |
| 66 | |
| 67 | sigpipe = sigismember(¤t->pending.signal, SIGPIPE); |
| 68 | |
| 69 | /* Save pointer to user space and point back to kernel space */ |
| 70 | fs = get_fs(); |
| 71 | set_fs(KERNEL_DS); |
| 72 | |
| 73 | while (bytes && |
| 74 | (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) { |
| 75 | data += wr; |
| 76 | bytes -= wr; |
| 77 | } |
| 78 | |
| 79 | set_fs(fs); |
| 80 | |
| 81 | /* Keep the currently executing process from receiving a |
| 82 | SIGPIPE unless it was already supposed to get one */ |
| 83 | if (wr == -EPIPE && !sigpipe) { |
| 84 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 85 | sigdelset(¤t->pending.signal, SIGPIPE); |
| 86 | recalc_sigpending(); |
| 87 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 88 | } |
| 89 | |
| 90 | return (bytes > 0); |
| 91 | } |
| 92 | |
| 93 | static void autofs4_notify_daemon(struct autofs_sb_info *sbi, |
| 94 | struct autofs_wait_queue *wq, |
| 95 | int type) |
| 96 | { |
Ian Kent | e851447 | 2007-02-20 13:58:09 -0800 | [diff] [blame] | 97 | union { |
| 98 | struct autofs_packet_hdr hdr; |
| 99 | union autofs_packet_union v4_pkt; |
| 100 | union autofs_v5_packet_union v5_pkt; |
| 101 | } pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | size_t pktsz; |
| 103 | |
| 104 | DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d", |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 105 | wq->wait_queue_token, wq->name.len, wq->name.name, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | memset(&pkt,0,sizeof pkt); /* For security reasons */ |
| 108 | |
| 109 | pkt.hdr.proto_version = sbi->version; |
| 110 | pkt.hdr.type = type; |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 111 | switch (type) { |
| 112 | /* Kernel protocol v4 missing and expire packets */ |
| 113 | case autofs_ptype_missing: |
| 114 | { |
Ian Kent | e851447 | 2007-02-20 13:58:09 -0800 | [diff] [blame] | 115 | struct autofs_packet_missing *mp = &pkt.v4_pkt.missing; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | pktsz = sizeof(*mp); |
| 118 | |
| 119 | mp->wait_queue_token = wq->wait_queue_token; |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 120 | mp->len = wq->name.len; |
| 121 | memcpy(mp->name, wq->name.name, wq->name.len); |
| 122 | mp->name[wq->name.len] = '\0'; |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | case autofs_ptype_expire_multi: |
| 126 | { |
Ian Kent | e851447 | 2007-02-20 13:58:09 -0800 | [diff] [blame] | 127 | struct autofs_packet_expire_multi *ep = &pkt.v4_pkt.expire_multi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | pktsz = sizeof(*ep); |
| 130 | |
| 131 | ep->wait_queue_token = wq->wait_queue_token; |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 132 | ep->len = wq->name.len; |
| 133 | memcpy(ep->name, wq->name.name, wq->name.len); |
| 134 | ep->name[wq->name.len] = '\0'; |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | /* |
| 138 | * Kernel protocol v5 packet for handling indirect and direct |
| 139 | * mount missing and expire requests |
| 140 | */ |
| 141 | case autofs_ptype_missing_indirect: |
| 142 | case autofs_ptype_expire_indirect: |
| 143 | case autofs_ptype_missing_direct: |
| 144 | case autofs_ptype_expire_direct: |
| 145 | { |
Ian Kent | e851447 | 2007-02-20 13:58:09 -0800 | [diff] [blame] | 146 | struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet; |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 147 | |
| 148 | pktsz = sizeof(*packet); |
| 149 | |
| 150 | packet->wait_queue_token = wq->wait_queue_token; |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 151 | packet->len = wq->name.len; |
| 152 | memcpy(packet->name, wq->name.name, wq->name.len); |
| 153 | packet->name[wq->name.len] = '\0'; |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 154 | packet->dev = wq->dev; |
| 155 | packet->ino = wq->ino; |
| 156 | packet->uid = wq->uid; |
| 157 | packet->gid = wq->gid; |
| 158 | packet->pid = wq->pid; |
| 159 | packet->tgid = wq->tgid; |
| 160 | break; |
| 161 | } |
| 162 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | printk("autofs4_notify_daemon: bad type %d!\n", type); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | if (autofs4_write(sbi->pipe, &pkt, pktsz)) |
| 168 | autofs4_catatonic_mode(sbi); |
| 169 | } |
| 170 | |
| 171 | static int autofs4_getpath(struct autofs_sb_info *sbi, |
| 172 | struct dentry *dentry, char **name) |
| 173 | { |
| 174 | struct dentry *root = sbi->sb->s_root; |
| 175 | struct dentry *tmp; |
| 176 | char *buf = *name; |
| 177 | char *p; |
| 178 | int len = 0; |
| 179 | |
| 180 | spin_lock(&dcache_lock); |
| 181 | for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent) |
| 182 | len += tmp->d_name.len + 1; |
| 183 | |
Ian Kent | cab0936 | 2008-05-01 04:35:07 -0700 | [diff] [blame] | 184 | if (!len || --len > NAME_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | spin_unlock(&dcache_lock); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | *(buf + len) = '\0'; |
| 190 | p = buf + len - dentry->d_name.len; |
| 191 | strncpy(p, dentry->d_name.name, dentry->d_name.len); |
| 192 | |
| 193 | for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) { |
| 194 | *(--p) = '/'; |
| 195 | p -= tmp->d_name.len; |
| 196 | strncpy(p, tmp->d_name.name, tmp->d_name.len); |
| 197 | } |
| 198 | spin_unlock(&dcache_lock); |
| 199 | |
| 200 | return len; |
| 201 | } |
| 202 | |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 203 | static struct autofs_wait_queue * |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 204 | autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr) |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 205 | { |
| 206 | struct autofs_wait_queue *wq; |
| 207 | |
| 208 | for (wq = sbi->queues; wq; wq = wq->next) { |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 209 | if (wq->name.hash == qstr->hash && |
| 210 | wq->name.len == qstr->len && |
| 211 | wq->name.name && |
| 212 | !memcmp(wq->name.name, qstr->name, qstr->len)) |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | return wq; |
| 216 | } |
| 217 | |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 218 | /* |
| 219 | * Check if we have a valid request. |
| 220 | * Returns |
| 221 | * 1 if the request should continue. |
| 222 | * In this case we can return an autofs_wait_queue entry if one is |
| 223 | * found or NULL to idicate a new wait needs to be created. |
| 224 | * 0 or a negative errno if the request shouldn't continue. |
| 225 | */ |
| 226 | static int validate_request(struct autofs_wait_queue **wait, |
| 227 | struct autofs_sb_info *sbi, |
| 228 | struct qstr *qstr, |
| 229 | struct dentry*dentry, enum autofs_notify notify) |
| 230 | { |
| 231 | struct autofs_wait_queue *wq; |
| 232 | struct autofs_info *ino; |
| 233 | |
| 234 | /* Wait in progress, continue; */ |
| 235 | wq = autofs4_find_wait(sbi, qstr); |
| 236 | if (wq) { |
| 237 | *wait = wq; |
| 238 | return 1; |
| 239 | } |
| 240 | |
| 241 | *wait = NULL; |
| 242 | |
| 243 | /* If we don't yet have any info this is a new request */ |
| 244 | ino = autofs4_dentry_ino(dentry); |
| 245 | if (!ino) |
| 246 | return 1; |
| 247 | |
| 248 | /* |
| 249 | * If we've been asked to wait on an existing expire (NFY_NONE) |
| 250 | * but there is no wait in the queue ... |
| 251 | */ |
| 252 | if (notify == NFY_NONE) { |
| 253 | /* |
| 254 | * Either we've betean the pending expire to post it's |
| 255 | * wait or it finished while we waited on the mutex. |
| 256 | * So we need to wait till either, the wait appears |
| 257 | * or the expire finishes. |
| 258 | */ |
| 259 | |
| 260 | while (ino->flags & AUTOFS_INF_EXPIRING) { |
| 261 | mutex_unlock(&sbi->wq_mutex); |
| 262 | schedule_timeout_interruptible(HZ/10); |
| 263 | if (mutex_lock_interruptible(&sbi->wq_mutex)) |
| 264 | return -EINTR; |
| 265 | |
| 266 | wq = autofs4_find_wait(sbi, qstr); |
| 267 | if (wq) { |
| 268 | *wait = wq; |
| 269 | return 1; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Not ideal but the status has already gone. Of the two |
| 275 | * cases where we wait on NFY_NONE neither depend on the |
| 276 | * return status of the wait. |
| 277 | */ |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * If we've been asked to trigger a mount and the request |
| 283 | * completed while we waited on the mutex ... |
| 284 | */ |
| 285 | if (notify == NFY_MOUNT) { |
| 286 | /* |
| 287 | * If the dentry isn't hashed just go ahead and try the |
| 288 | * mount again with a new wait (not much else we can do). |
| 289 | */ |
| 290 | if (!d_unhashed(dentry)) { |
| 291 | /* |
| 292 | * But if the dentry is hashed, that means that we |
| 293 | * got here through the revalidate path. Thus, we |
| 294 | * need to check if the dentry has been mounted |
| 295 | * while we waited on the wq_mutex. If it has, |
| 296 | * simply return success. |
| 297 | */ |
| 298 | if (d_mountpoint(dentry)) |
| 299 | return 0; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return 1; |
| 304 | } |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, |
| 307 | enum autofs_notify notify) |
| 308 | { |
| 309 | struct autofs_wait_queue *wq; |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 310 | struct qstr qstr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | char *name; |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 312 | int status, ret, type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | /* In catatonic mode, we don't wait for nobody */ |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 315 | if (sbi->catatonic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | return -ENOENT; |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | name = kmalloc(NAME_MAX + 1, GFP_KERNEL); |
| 319 | if (!name) |
| 320 | return -ENOMEM; |
| 321 | |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 322 | /* If this is a direct mount request create a dummy name */ |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 323 | if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT)) |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 324 | qstr.len = sprintf(name, "%p", dentry); |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 325 | else { |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 326 | qstr.len = autofs4_getpath(sbi, dentry, &name); |
| 327 | if (!qstr.len) { |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 328 | kfree(name); |
| 329 | return -ENOENT; |
| 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 332 | qstr.name = name; |
| 333 | qstr.hash = full_name_hash(name, qstr.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 335 | if (mutex_lock_interruptible(&sbi->wq_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 338 | ret = validate_request(&wq, sbi, &qstr, dentry, notify); |
| 339 | if (ret <= 0) { |
| 340 | if (ret == 0) |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 341 | mutex_unlock(&sbi->wq_mutex); |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 342 | kfree(qstr.name); |
| 343 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 346 | if (!wq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* Create a new wait queue */ |
| 348 | wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 349 | if (!wq) { |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 350 | kfree(qstr.name); |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 351 | mutex_unlock(&sbi->wq_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return -ENOMEM; |
| 353 | } |
| 354 | |
| 355 | wq->wait_queue_token = autofs4_next_wait_queue; |
| 356 | if (++autofs4_next_wait_queue == 0) |
| 357 | autofs4_next_wait_queue = 1; |
| 358 | wq->next = sbi->queues; |
| 359 | sbi->queues = wq; |
| 360 | init_waitqueue_head(&wq->queue); |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 361 | memcpy(&wq->name, &qstr, sizeof(struct qstr)); |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 362 | wq->dev = autofs4_get_dev(sbi); |
| 363 | wq->ino = autofs4_get_ino(sbi); |
| 364 | wq->uid = current->uid; |
| 365 | wq->gid = current->gid; |
| 366 | wq->pid = current->pid; |
| 367 | wq->tgid = current->tgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | wq->status = -EINTR; /* Status return if interrupted */ |
| 369 | atomic_set(&wq->wait_ctr, 2); |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 370 | mutex_unlock(&sbi->wq_mutex); |
Ian Kent | 3e7b191 | 2006-03-27 01:14:59 -0800 | [diff] [blame] | 371 | |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 372 | if (sbi->version < 5) { |
| 373 | if (notify == NFY_MOUNT) |
| 374 | type = autofs_ptype_missing; |
| 375 | else |
| 376 | type = autofs_ptype_expire_multi; |
| 377 | } else { |
| 378 | if (notify == NFY_MOUNT) |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 379 | type = (sbi->type & AUTOFS_TYPE_DIRECT) ? |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 380 | autofs_ptype_missing_direct : |
| 381 | autofs_ptype_missing_indirect; |
| 382 | else |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 383 | type = (sbi->type & AUTOFS_TYPE_DIRECT) ? |
Ian Kent | 5c0a32f | 2006-03-27 01:14:55 -0800 | [diff] [blame] | 384 | autofs_ptype_expire_direct : |
| 385 | autofs_ptype_expire_indirect; |
| 386 | } |
Ian Kent | 4dcd00b | 2005-05-01 08:59:16 -0700 | [diff] [blame] | 387 | |
Ian Kent | 682d4fc | 2005-07-07 17:57:02 -0700 | [diff] [blame] | 388 | DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n", |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 389 | (unsigned long) wq->wait_queue_token, wq->name.len, |
| 390 | wq->name.name, notify); |
Ian Kent | 4dcd00b | 2005-05-01 08:59:16 -0700 | [diff] [blame] | 391 | |
| 392 | /* autofs4_notify_daemon() may block */ |
| 393 | autofs4_notify_daemon(sbi, wq, type); |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 394 | } else { |
| 395 | atomic_inc(&wq->wait_ctr); |
| 396 | mutex_unlock(&sbi->wq_mutex); |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 397 | kfree(qstr.name); |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 398 | DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d", |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 399 | (unsigned long) wq->wait_queue_token, wq->name.len, |
| 400 | wq->name.name, notify); |
Ian Kent | 4dcd00b | 2005-05-01 08:59:16 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Ian Kent | 5a11d4d | 2008-07-23 21:30:17 -0700 | [diff] [blame] | 403 | /* |
| 404 | * wq->name.name is NULL iff the lock is already released |
| 405 | * or the mount has been made catatonic. |
| 406 | */ |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 407 | if (wq->name.name) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* Block all but "shutdown" signals while waiting */ |
| 409 | sigset_t oldset; |
| 410 | unsigned long irqflags; |
| 411 | |
| 412 | spin_lock_irqsave(¤t->sighand->siglock, irqflags); |
| 413 | oldset = current->blocked; |
| 414 | siginitsetinv(¤t->blocked, SHUTDOWN_SIGS & ~oldset.sig[0]); |
| 415 | recalc_sigpending(); |
| 416 | spin_unlock_irqrestore(¤t->sighand->siglock, irqflags); |
| 417 | |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 418 | wait_event_interruptible(wq->queue, wq->name.name == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | spin_lock_irqsave(¤t->sighand->siglock, irqflags); |
| 421 | current->blocked = oldset; |
| 422 | recalc_sigpending(); |
| 423 | spin_unlock_irqrestore(¤t->sighand->siglock, irqflags); |
| 424 | } else { |
| 425 | DPRINTK("skipped sleeping"); |
| 426 | } |
| 427 | |
| 428 | status = wq->status; |
| 429 | |
| 430 | /* Are we the last process to need status? */ |
| 431 | if (atomic_dec_and_test(&wq->wait_ctr)) |
| 432 | kfree(wq); |
| 433 | |
| 434 | return status; |
| 435 | } |
| 436 | |
| 437 | |
| 438 | int autofs4_wait_release(struct autofs_sb_info *sbi, autofs_wqt_t wait_queue_token, int status) |
| 439 | { |
| 440 | struct autofs_wait_queue *wq, **wql; |
| 441 | |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 442 | mutex_lock(&sbi->wq_mutex); |
Stephen Hemminger | c80544d | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 443 | for (wql = &sbi->queues; (wq = *wql) != NULL; wql = &wq->next) { |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 444 | if (wq->wait_queue_token == wait_queue_token) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | break; |
| 446 | } |
| 447 | |
Ian Kent | e77fbdd | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 448 | if (!wq) { |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 449 | mutex_unlock(&sbi->wq_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | return -EINVAL; |
| 451 | } |
| 452 | |
| 453 | *wql = wq->next; /* Unlink from chain */ |
Jeff Moyer | 70b52a0 | 2008-07-23 21:30:16 -0700 | [diff] [blame] | 454 | kfree(wq->name.name); |
| 455 | wq->name.name = NULL; /* Do not wait on this queue */ |
Ian Kent | a1362fe | 2008-07-23 21:30:19 -0700 | [diff] [blame^] | 456 | mutex_unlock(&sbi->wq_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | wq->status = status; |
| 459 | |
| 460 | if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */ |
| 461 | kfree(wq); |
| 462 | else |
| 463 | wake_up_interruptible(&wq->queue); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |