int autofs_wait(struct autofs_sb_info *sbi, struct qstr *name) { struct autofs_wait_queue *wq; int status; /* In catatonic mode, we don't wait for nobody */ if ( sbi->catatonic ) return -ENOENT; /* We shouldn't be able to get here, but just in case */ if ( name->len > NAME_MAX ) return -ENOENT; for ( wq = sbi->queues ; wq ; wq = wq->next ) { if ( wq->hash == name->hash && wq->len == name->len && wq->name && !memcmp(wq->name,name->name,name->len) ) break; } if ( !wq ) { /* Create a new wait queue */ wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); if ( !wq ) return -ENOMEM; wq->name = kmalloc(name->len,GFP_KERNEL); if ( !wq->name ) { kfree(wq); return -ENOMEM; } wq->wait_queue_token = autofs_next_wait_queue++; init_waitqueue_head(&wq->queue); wq->hash = name->hash; wq->len = name->len; wq->status = -EINTR; /* Status return if interrupted */ memcpy(wq->name, name->name, name->len); wq->next = sbi->queues; sbi->queues = wq; /* autofs_notify_daemon() may block */ wq->wait_ctr = 2; autofs_notify_daemon(sbi,wq); } else wq->wait_ctr++; /* wq->name is NULL if and only if the lock is already released */ if ( sbi->catatonic ) { /* We might have slept, so check again for catatonic mode */ wq->status = -ENOENT; kfree(wq->name); wq->name = NULL; } if ( wq->name ) { /* Block all but "shutdown" signals while waiting */ sigset_t sigmask; siginitsetinv(&sigmask, SHUTDOWN_SIGS); sigprocmask(SIG_BLOCK, &sigmask, &sigmask); interruptible_sleep_on(&wq->queue); sigprocmask(SIG_SETMASK, &sigmask, NULL); } else { DPRINTK(("autofs_wait: skipped sleeping\n")); } status = wq->status; if ( ! --wq->wait_ctr ) /* Are we the last process to need status? */ kfree(wq); return status; }
int autofs_wait(struct autofs_sb_info *sbi, struct qstr * name) { struct autofs_wait_queue *wq; int status; /* In catatonic mode, we don't wait for nobody */ if ( sbi->catatonic ) return -ENOENT; for ( wq = sbi->queues ; wq ; wq = wq->next ) { if ( wq->hash == name->hash && wq->len == name->len && wq->name && !memcmp(wq->name,name->name,name->len) ) break; } if ( !wq ) { /* Create a new wait queue */ wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); if ( !wq ) return -ENOMEM; wq->name = kmalloc(name->len,GFP_KERNEL); if ( !wq->name ) { kfree(wq); return -ENOMEM; } wq->wait_queue_token = autofs_next_wait_queue++; init_waitqueue(&wq->queue); wq->hash = name->hash; wq->len = name->len; wq->status = -EINTR; /* Status return if interrupted */ memcpy(wq->name, name->name, name->len); wq->next = sbi->queues; sbi->queues = wq; /* autofs_notify_daemon() may block */ wq->wait_ctr = 2; autofs_notify_daemon(sbi,wq); } else wq->wait_ctr++; /* wq->name is NULL if and only if the lock is already released */ if ( sbi->catatonic ) { /* We might have slept, so check again for catatonic mode */ wq->status = -ENOENT; if ( wq->name ) { kfree(wq->name); wq->name = NULL; } } if ( wq->name ) { /* Block all but "shutdown" signals while waiting */ sigset_t oldset; unsigned long irqflags; spin_lock_irqsave(¤t->sigmask_lock, irqflags); oldset = current->blocked; siginitsetinv(¤t->blocked, SHUTDOWN_SIGS & ~oldset.sig[0]); recalc_sigpending(current); spin_unlock_irqrestore(¤t->sigmask_lock, irqflags); interruptible_sleep_on(&wq->queue); spin_lock_irqsave(¤t->sigmask_lock, irqflags); current->blocked = oldset; recalc_sigpending(current); spin_unlock_irqrestore(¤t->sigmask_lock, irqflags); } else { DPRINTK(("autofs_wait: skipped sleeping\n")); } status = wq->status; if ( ! --wq->wait_ctr ) /* Are we the last process to need status? */ kfree(wq); return status; }