Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright 2001-2006 Ian Kent <raven@themaw.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "autofs_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /* We make this a static variable rather than a part of the superblock; it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * is better if we don't reassign numbers easily even across filesystems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static autofs_wqt_t autofs_next_wait_queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) void autofs_catatonic_mode(struct autofs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct autofs_wait_queue *wq, *nwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	mutex_lock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (sbi->flags & AUTOFS_SBI_CATATONIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	pr_debug("entering catatonic mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	sbi->flags |= AUTOFS_SBI_CATATONIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	wq = sbi->queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	sbi->queues = NULL;	/* Erase all wait queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	while (wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		nwq = wq->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		wq->status = -ENOENT; /* Magic is gone - report failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		kfree(wq->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		wq->name.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		wq->wait_ctr--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		wake_up_interruptible(&wq->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		wq = nwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	fput(sbi->pipe);	/* Close the pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	sbi->pipe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	sbi->pipefd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int autofs_write(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			struct file *file, const void *addr, int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	unsigned long sigpipe, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	const char *data = (const char *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ssize_t wr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	sigpipe = sigismember(&current->pending.signal, SIGPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	mutex_lock(&sbi->pipe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	while (bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		wr = __kernel_write(file, data, bytes, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (wr <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		data += wr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		bytes -= wr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	mutex_unlock(&sbi->pipe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* Keep the currently executing process from receiving a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * SIGPIPE unless it was already supposed to get one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (wr == -EPIPE && !sigpipe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		spin_lock_irqsave(&current->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		sigdelset(&current->pending.signal, SIGPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		recalc_sigpending();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		spin_unlock_irqrestore(&current->sighand->siglock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* if 'wr' returned 0 (impossible) we assume -EIO (safe) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return bytes == 0 ? 0 : wr < 0 ? wr : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static void autofs_notify_daemon(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				 struct autofs_wait_queue *wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				 int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		struct autofs_packet_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		union autofs_packet_union v4_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		union autofs_v5_packet_union v5_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	} pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct file *pipe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	size_t pktsz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	pr_debug("wait id = 0x%08lx, name = %.*s, type=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		 (unsigned long) wq->wait_queue_token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		 wq->name.len, wq->name.name, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	memset(&pkt, 0, sizeof(pkt)); /* For security reasons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	pkt.hdr.proto_version = sbi->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	pkt.hdr.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* Kernel protocol v4 missing and expire packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case autofs_ptype_missing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		pktsz = sizeof(*mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		mp->wait_queue_token = wq->wait_queue_token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		mp->len = wq->name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		memcpy(mp->name, wq->name.name, wq->name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		mp->name[wq->name.len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case autofs_ptype_expire_multi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		struct autofs_packet_expire_multi *ep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					&pkt.v4_pkt.expire_multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		pktsz = sizeof(*ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ep->wait_queue_token = wq->wait_queue_token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		ep->len = wq->name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		memcpy(ep->name, wq->name.name, wq->name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ep->name[wq->name.len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * Kernel protocol v5 packet for handling indirect and direct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * mount missing and expire requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	case autofs_ptype_missing_indirect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	case autofs_ptype_expire_indirect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	case autofs_ptype_missing_direct:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	case autofs_ptype_expire_direct:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		pktsz = sizeof(*packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		packet->wait_queue_token = wq->wait_queue_token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		packet->len = wq->name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		memcpy(packet->name, wq->name.name, wq->name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		packet->name[wq->name.len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		packet->dev = wq->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		packet->ino = wq->ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		packet->uid = from_kuid_munged(user_ns, wq->uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		packet->gid = from_kgid_munged(user_ns, wq->gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		packet->pid = wq->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		packet->tgid = wq->tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		pr_warn("bad type %d!\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	pipe = get_file(sbi->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	switch (ret = autofs_write(sbi, pipe, &pkt, pktsz)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case -ENOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		/* Just fail this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		autofs_wait_release(sbi, wq->wait_queue_token, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		autofs_catatonic_mode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	fput(pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int autofs_getpath(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			  struct dentry *dentry, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct dentry *root = sbi->sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct dentry *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) rename_retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	buf = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	seq = read_seqbegin(&rename_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	spin_lock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		len += tmp->d_name.len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (!len || --len > NAME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (read_seqretry(&rename_lock, seq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			goto rename_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	*(buf + len) = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	p = buf + len - dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	strncpy(p, dentry->d_name.name, dentry->d_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		*(--p) = '/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		p -= tmp->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		strncpy(p, tmp->d_name.name, tmp->d_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (read_seqretry(&rename_lock, seq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		goto rename_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static struct autofs_wait_queue *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) autofs_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct autofs_wait_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	for (wq = sbi->queues; wq; wq = wq->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (wq->name.hash == qstr->hash &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		    wq->name.len == qstr->len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		    wq->name.name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		    !memcmp(wq->name.name, qstr->name, qstr->len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * Check if we have a valid request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * 1 if the request should continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  *   In this case we can return an autofs_wait_queue entry if one is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *   found or NULL to idicate a new wait needs to be created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * 0 or a negative errno if the request shouldn't continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int validate_request(struct autofs_wait_queue **wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			    struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			    const struct qstr *qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			    const struct path *path, enum autofs_notify notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct autofs_wait_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* Wait in progress, continue; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	wq = autofs_find_wait(sbi, qstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		*wait = wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	*wait = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	/* If we don't yet have any info this is a new request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (!ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 * If we've been asked to wait on an existing expire (NFY_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * but there is no wait in the queue ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (notify == NFY_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		 * Either we've betean the pending expire to post it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		 * wait or it finished while we waited on the mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		 * So we need to wait till either, the wait appears
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		 * or the expire finishes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		while (ino->flags & AUTOFS_INF_EXPIRING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			schedule_timeout_interruptible(HZ/10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			if (mutex_lock_interruptible(&sbi->wq_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			wq = autofs_find_wait(sbi, qstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			if (wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				*wait = wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		 * Not ideal but the status has already gone. Of the two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		 * cases where we wait on NFY_NONE neither depend on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		 * return status of the wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 * If we've been asked to trigger a mount and the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	 * completed while we waited on the mutex ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (notify == NFY_MOUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		struct dentry *new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		struct path this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		int valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		 * If the dentry was successfully mounted while we slept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		 * on the wait queue mutex we can return success. If it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		 * isn't mounted (doesn't have submounts for the case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		 * a multi-mount with no mount at it's base) we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		 * continue on and create a new request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (!IS_ROOT(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			if (d_unhashed(dentry) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			    d_really_is_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				struct dentry *parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				new = d_lookup(parent, &dentry->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					dentry = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		this.mnt = path->mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		this.dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		if (path_has_submounts(&this))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			dput(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int autofs_wait(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		 const struct path *path, enum autofs_notify notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct autofs_wait_queue *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct qstr qstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int status, ret, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	pid_t pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	pid_t tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	/* In catatonic mode, we don't wait for nobody */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	 * Try translating pids to the namespace of the daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	 * Zero means failure: we are in an unrelated pid namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	pid = task_pid_nr_ns(current, ns_of_pid(sbi->oz_pgrp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	tgid = task_tgid_nr_ns(current, ns_of_pid(sbi->oz_pgrp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (pid == 0 || tgid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (d_really_is_negative(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		 * A wait for a negative dentry is invalid for certain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		 * cases. A direct or offset mount "always" has its mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		 * point directory created and so the request dentry must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		 * be positive or the map key doesn't exist. The situation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		 * is very similar for indirect mounts except only dentrys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		 * in the root of the autofs file system may be negative.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		if (autofs_type_trigger(sbi->type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		else if (!IS_ROOT(dentry->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	/* If this is a direct mount request create a dummy name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		qstr.len = sprintf(name, "%p", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		qstr.len = autofs_getpath(sbi, dentry, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		if (!qstr.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	qstr.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	qstr.hash = full_name_hash(dentry, name, qstr.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (mutex_lock_interruptible(&sbi->wq_mutex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		kfree(qstr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	ret = validate_request(&wq, sbi, &qstr, path, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (ret != -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		kfree(qstr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (!wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		/* Create a new wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		wq = kmalloc(sizeof(struct autofs_wait_queue), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		if (!wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			kfree(qstr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		wq->wait_queue_token = autofs_next_wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		if (++autofs_next_wait_queue == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			autofs_next_wait_queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		wq->next = sbi->queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		sbi->queues = wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		init_waitqueue_head(&wq->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		memcpy(&wq->name, &qstr, sizeof(struct qstr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		wq->dev = autofs_get_dev(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		wq->ino = autofs_get_ino(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		wq->uid = current_uid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		wq->gid = current_gid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		wq->pid = pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		wq->tgid = tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		wq->status = -EINTR; /* Status return if interrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		wq->wait_ctr = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		if (sbi->version < 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			if (notify == NFY_MOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 				type = autofs_ptype_missing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				type = autofs_ptype_expire_multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			if (notify == NFY_MOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				type = autofs_type_trigger(sbi->type) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 					autofs_ptype_missing_direct :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 					 autofs_ptype_missing_indirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 				type = autofs_type_trigger(sbi->type) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 					autofs_ptype_expire_direct :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 					autofs_ptype_expire_indirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		pr_debug("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			 (unsigned long) wq->wait_queue_token, wq->name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			 wq->name.name, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		 * autofs_notify_daemon() may block; it will unlock ->wq_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		autofs_notify_daemon(sbi, wq, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		wq->wait_ctr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		pr_debug("existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			 (unsigned long) wq->wait_queue_token, wq->name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			 wq->name.name, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		kfree(qstr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * wq->name.name is NULL iff the lock is already released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 * or the mount has been made catatonic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	wait_event_killable(wq->queue, wq->name.name == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	status = wq->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	 * For direct and offset mounts we need to track the requester's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	 * uid and gid in the dentry info struct. This is so it can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	 * supplied, on request, by the misc device ioctl interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	 * This is needed during daemon resatart when reconnecting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	 * to existing, active, autofs mounts. The uid and gid (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	 * related string values) may be used for macro substitution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	 * in autofs mount maps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		struct dentry *de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		/* direct mount or browsable map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		if (!ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			/* If not lookup actual dentry used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			de = d_lookup(dentry->d_parent, &dentry->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			if (de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 				ino = autofs_dentry_ino(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		/* Set mount requester */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		if (ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			spin_lock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			ino->uid = wq->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			ino->gid = wq->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		if (de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			dput(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* Are we the last process to need status? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	mutex_lock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (!--wq->wait_ctr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		kfree(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int autofs_wait_release(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 			autofs_wqt_t wait_queue_token, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct autofs_wait_queue *wq, **wql;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	mutex_lock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	for (wql = &sbi->queues; (wq = *wql) != NULL; wql = &wq->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		if (wq->wait_queue_token == wait_queue_token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (!wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	*wql = wq->next;	/* Unlink from chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	kfree(wq->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	wq->name.name = NULL;	/* Do not wait on this queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	wq->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	wake_up(&wq->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	if (!--wq->wait_ctr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		kfree(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	mutex_unlock(&sbi->wq_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }