Lines Matching +full:wait +full:- +full:queue

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
4 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
19 mutex_lock(&sbi->wq_mutex); in autofs_catatonic_mode()
20 if (sbi->flags & AUTOFS_SBI_CATATONIC) { in autofs_catatonic_mode()
21 mutex_unlock(&sbi->wq_mutex); in autofs_catatonic_mode()
27 sbi->flags |= AUTOFS_SBI_CATATONIC; in autofs_catatonic_mode()
28 wq = sbi->queues; in autofs_catatonic_mode()
29 sbi->queues = NULL; /* Erase all wait queues */ in autofs_catatonic_mode()
31 nwq = wq->next; in autofs_catatonic_mode()
32 wq->status = -ENOENT; /* Magic is gone - report failure */ in autofs_catatonic_mode()
33 kfree(wq->name.name - wq->offset); in autofs_catatonic_mode()
34 wq->name.name = NULL; in autofs_catatonic_mode()
35 wake_up(&wq->queue); in autofs_catatonic_mode()
36 if (!--wq->wait_ctr) in autofs_catatonic_mode()
40 fput(sbi->pipe); /* Close the pipe */ in autofs_catatonic_mode()
41 sbi->pipe = NULL; in autofs_catatonic_mode()
42 sbi->pipefd = -1; in autofs_catatonic_mode()
43 mutex_unlock(&sbi->wq_mutex); in autofs_catatonic_mode()
53 sigpipe = sigismember(&current->pending.signal, SIGPIPE); in autofs_write()
55 mutex_lock(&sbi->pipe_mutex); in autofs_write()
61 bytes -= wr; in autofs_write()
63 mutex_unlock(&sbi->pipe_mutex); in autofs_write()
68 if (wr == -EPIPE && !sigpipe) { in autofs_write()
69 spin_lock_irqsave(&current->sighand->siglock, flags); in autofs_write()
70 sigdelset(&current->pending.signal, SIGPIPE); in autofs_write()
72 spin_unlock_irqrestore(&current->sighand->siglock, flags); in autofs_write()
75 /* if 'wr' returned 0 (impossible) we assume -EIO (safe) */ in autofs_write()
76 return bytes == 0 ? 0 : wr < 0 ? wr : -EIO; in autofs_write()
92 pr_debug("wait id = 0x%08lx, name = %.*s, type=%d\n", in autofs_notify_daemon()
93 (unsigned long) wq->wait_queue_token, in autofs_notify_daemon()
94 wq->name.len, wq->name.name, type); in autofs_notify_daemon()
98 pkt.hdr.proto_version = sbi->version; in autofs_notify_daemon()
109 mp->wait_queue_token = wq->wait_queue_token; in autofs_notify_daemon()
110 mp->len = wq->name.len; in autofs_notify_daemon()
111 memcpy(mp->name, wq->name.name, wq->name.len); in autofs_notify_daemon()
112 mp->name[wq->name.len] = '\0'; in autofs_notify_daemon()
122 ep->wait_queue_token = wq->wait_queue_token; in autofs_notify_daemon()
123 ep->len = wq->name.len; in autofs_notify_daemon()
124 memcpy(ep->name, wq->name.name, wq->name.len); in autofs_notify_daemon()
125 ep->name[wq->name.len] = '\0'; in autofs_notify_daemon()
138 struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns; in autofs_notify_daemon()
142 packet->wait_queue_token = wq->wait_queue_token; in autofs_notify_daemon()
143 packet->len = wq->name.len; in autofs_notify_daemon()
144 memcpy(packet->name, wq->name.name, wq->name.len); in autofs_notify_daemon()
145 packet->name[wq->name.len] = '\0'; in autofs_notify_daemon()
146 packet->dev = wq->dev; in autofs_notify_daemon()
147 packet->ino = wq->ino; in autofs_notify_daemon()
148 packet->uid = from_kuid_munged(user_ns, wq->uid); in autofs_notify_daemon()
149 packet->gid = from_kgid_munged(user_ns, wq->gid); in autofs_notify_daemon()
150 packet->pid = wq->pid; in autofs_notify_daemon()
151 packet->tgid = wq->tgid; in autofs_notify_daemon()
156 mutex_unlock(&sbi->wq_mutex); in autofs_notify_daemon()
160 pipe = get_file(sbi->pipe); in autofs_notify_daemon()
162 mutex_unlock(&sbi->wq_mutex); in autofs_notify_daemon()
167 case -ENOMEM: in autofs_notify_daemon()
168 case -ERESTARTSYS: in autofs_notify_daemon()
170 autofs_wait_release(sbi, wq->wait_queue_token, ret); in autofs_notify_daemon()
184 for (wq = sbi->queues; wq; wq = wq->next) { in autofs_find_wait()
185 if (wq->name.hash == qstr->hash && in autofs_find_wait()
186 wq->name.len == qstr->len && in autofs_find_wait()
187 wq->name.name && in autofs_find_wait()
188 !memcmp(wq->name.name, qstr->name, qstr->len)) in autofs_find_wait()
199 * found or NULL to idicate a new wait needs to be created.
202 static int validate_request(struct autofs_wait_queue **wait, in validate_request() argument
207 struct dentry *dentry = path->dentry; in validate_request()
211 if (sbi->flags & AUTOFS_SBI_CATATONIC) in validate_request()
212 return -ENOENT; in validate_request()
214 /* Wait in progress, continue; */ in validate_request()
217 *wait = wq; in validate_request()
221 *wait = NULL; in validate_request()
229 * If we've been asked to wait on an existing expire (NFY_NONE) in validate_request()
230 * but there is no wait in the queue ... in validate_request()
235 * wait or it finished while we waited on the mutex. in validate_request()
236 * So we need to wait till either, the wait appears in validate_request()
240 while (ino->flags & AUTOFS_INF_EXPIRING) { in validate_request()
241 mutex_unlock(&sbi->wq_mutex); in validate_request()
243 if (mutex_lock_interruptible(&sbi->wq_mutex)) in validate_request()
244 return -EINTR; in validate_request()
246 if (sbi->flags & AUTOFS_SBI_CATATONIC) in validate_request()
247 return -ENOENT; in validate_request()
251 *wait = wq; in validate_request()
258 * cases where we wait on NFY_NONE neither depend on the in validate_request()
259 * return status of the wait. in validate_request()
275 * on the wait queue mutex we can return success. If it in validate_request()
277 * a multi-mount with no mount at it's base) we can in validate_request()
283 struct dentry *parent = dentry->d_parent; in validate_request()
285 new = d_lookup(parent, &dentry->d_name); in validate_request()
290 this.mnt = path->mnt; in validate_request()
306 struct dentry *dentry = path->dentry; in autofs_wait()
315 /* In catatonic mode, we don't wait for nobody */ in autofs_wait()
316 if (sbi->flags & AUTOFS_SBI_CATATONIC) in autofs_wait()
317 return -ENOENT; in autofs_wait()
324 pid = task_pid_nr_ns(current, ns_of_pid(sbi->oz_pgrp)); in autofs_wait()
325 tgid = task_tgid_nr_ns(current, ns_of_pid(sbi->oz_pgrp)); in autofs_wait()
327 return -ENOENT; in autofs_wait()
331 * A wait for a negative dentry is invalid for certain in autofs_wait()
338 if (autofs_type_trigger(sbi->type)) in autofs_wait()
339 return -ENOENT; in autofs_wait()
340 else if (!IS_ROOT(dentry->d_parent)) in autofs_wait()
341 return -ENOENT; in autofs_wait()
346 return -ENOMEM; in autofs_wait()
349 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) { in autofs_wait()
356 return -ENOENT; in autofs_wait()
360 offset = p - name; in autofs_wait()
364 if (mutex_lock_interruptible(&sbi->wq_mutex)) { in autofs_wait()
366 return -EINTR; in autofs_wait()
371 if (ret != -EINTR) in autofs_wait()
372 mutex_unlock(&sbi->wq_mutex); in autofs_wait()
378 /* Create a new wait queue */ in autofs_wait()
382 mutex_unlock(&sbi->wq_mutex); in autofs_wait()
383 return -ENOMEM; in autofs_wait()
386 wq->wait_queue_token = autofs_next_wait_queue; in autofs_wait()
389 wq->next = sbi->queues; in autofs_wait()
390 sbi->queues = wq; in autofs_wait()
391 init_waitqueue_head(&wq->queue); in autofs_wait()
392 memcpy(&wq->name, &qstr, sizeof(struct qstr)); in autofs_wait()
393 wq->offset = offset; in autofs_wait()
394 wq->dev = autofs_get_dev(sbi); in autofs_wait()
395 wq->ino = autofs_get_ino(sbi); in autofs_wait()
396 wq->uid = current_uid(); in autofs_wait()
397 wq->gid = current_gid(); in autofs_wait()
398 wq->pid = pid; in autofs_wait()
399 wq->tgid = tgid; in autofs_wait()
400 wq->status = -EINTR; /* Status return if interrupted */ in autofs_wait()
401 wq->wait_ctr = 2; in autofs_wait()
403 if (sbi->version < 5) { in autofs_wait()
410 type = autofs_type_trigger(sbi->type) ? in autofs_wait()
414 type = autofs_type_trigger(sbi->type) ? in autofs_wait()
419 pr_debug("new wait id = 0x%08lx, name = %.*s, nfy=%d\n", in autofs_wait()
420 (unsigned long) wq->wait_queue_token, wq->name.len, in autofs_wait()
421 wq->name.name, notify); in autofs_wait()
424 * autofs_notify_daemon() may block; it will unlock ->wq_mutex in autofs_wait()
428 wq->wait_ctr++; in autofs_wait()
429 pr_debug("existing wait id = 0x%08lx, name = %.*s, nfy=%d\n", in autofs_wait()
430 (unsigned long) wq->wait_queue_token, wq->name.len, in autofs_wait()
431 wq->name.name, notify); in autofs_wait()
432 mutex_unlock(&sbi->wq_mutex); in autofs_wait()
437 * wq->name.name is NULL iff the lock is already released in autofs_wait()
440 wait_event_killable(wq->queue, wq->name.name == NULL); in autofs_wait()
441 status = wq->status; in autofs_wait()
460 de = d_lookup(dentry->d_parent, &dentry->d_name); in autofs_wait()
467 spin_lock(&sbi->fs_lock); in autofs_wait()
468 ino->uid = wq->uid; in autofs_wait()
469 ino->gid = wq->gid; in autofs_wait()
470 spin_unlock(&sbi->fs_lock); in autofs_wait()
478 mutex_lock(&sbi->wq_mutex); in autofs_wait()
479 if (!--wq->wait_ctr) in autofs_wait()
481 mutex_unlock(&sbi->wq_mutex); in autofs_wait()
492 mutex_lock(&sbi->wq_mutex); in autofs_wait_release()
493 for (wql = &sbi->queues; (wq = *wql) != NULL; wql = &wq->next) { in autofs_wait_release()
494 if (wq->wait_queue_token == wait_queue_token) in autofs_wait_release()
499 mutex_unlock(&sbi->wq_mutex); in autofs_wait_release()
500 return -EINVAL; in autofs_wait_release()
503 *wql = wq->next; /* Unlink from chain */ in autofs_wait_release()
504 kfree(wq->name.name - wq->offset); in autofs_wait_release()
505 wq->name.name = NULL; /* Do not wait on this queue */ in autofs_wait_release()
506 wq->status = status; in autofs_wait_release()
507 wake_up(&wq->queue); in autofs_wait_release()
508 if (!--wq->wait_ctr) in autofs_wait_release()
510 mutex_unlock(&sbi->wq_mutex); in autofs_wait_release()