diff options
Diffstat (limited to 'fs/autofs4/waitq.c')
-rw-r--r-- | fs/autofs4/waitq.c | 111 |
1 files changed, 87 insertions, 24 deletions
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c index be78e9378c0..142ab6aa2aa 100644 --- a/fs/autofs4/waitq.c +++ b/fs/autofs4/waitq.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * linux/fs/autofs/waitq.c | 3 | * linux/fs/autofs/waitq.c |
4 | * | 4 | * |
5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved | 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved |
6 | * Copyright 2001-2003 Ian Kent <raven@themaw.net> | 6 | * Copyright 2001-2006 Ian Kent <raven@themaw.net> |
7 | * | 7 | * |
8 | * This file is part of the Linux kernel and is made available under | 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 | 9 | * the terms of the GNU General Public License, version 2, or at your |
@@ -33,7 +33,7 @@ void autofs4_catatonic_mode(struct autofs_sb_info *sbi) | |||
33 | sbi->catatonic = 1; | 33 | sbi->catatonic = 1; |
34 | wq = sbi->queues; | 34 | wq = sbi->queues; |
35 | sbi->queues = NULL; /* Erase all wait queues */ | 35 | sbi->queues = NULL; /* Erase all wait queues */ |
36 | while ( wq ) { | 36 | while (wq) { |
37 | nwq = wq->next; | 37 | nwq = wq->next; |
38 | wq->status = -ENOENT; /* Magic is gone - report failure */ | 38 | wq->status = -ENOENT; /* Magic is gone - report failure */ |
39 | kfree(wq->name); | 39 | kfree(wq->name); |
@@ -45,7 +45,6 @@ void autofs4_catatonic_mode(struct autofs_sb_info *sbi) | |||
45 | fput(sbi->pipe); /* Close the pipe */ | 45 | fput(sbi->pipe); /* Close the pipe */ |
46 | sbi->pipe = NULL; | 46 | sbi->pipe = NULL; |
47 | } | 47 | } |
48 | |||
49 | shrink_dcache_sb(sbi->sb); | 48 | shrink_dcache_sb(sbi->sb); |
50 | } | 49 | } |
51 | 50 | ||
@@ -98,7 +97,10 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, | |||
98 | 97 | ||
99 | pkt.hdr.proto_version = sbi->version; | 98 | pkt.hdr.proto_version = sbi->version; |
100 | pkt.hdr.type = type; | 99 | pkt.hdr.type = type; |
101 | if (type == autofs_ptype_missing) { | 100 | switch (type) { |
101 | /* Kernel protocol v4 missing and expire packets */ | ||
102 | case autofs_ptype_missing: | ||
103 | { | ||
102 | struct autofs_packet_missing *mp = &pkt.missing; | 104 | struct autofs_packet_missing *mp = &pkt.missing; |
103 | 105 | ||
104 | pktsz = sizeof(*mp); | 106 | pktsz = sizeof(*mp); |
@@ -107,7 +109,10 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, | |||
107 | mp->len = wq->len; | 109 | mp->len = wq->len; |
108 | memcpy(mp->name, wq->name, wq->len); | 110 | memcpy(mp->name, wq->name, wq->len); |
109 | mp->name[wq->len] = '\0'; | 111 | mp->name[wq->len] = '\0'; |
110 | } else if (type == autofs_ptype_expire_multi) { | 112 | break; |
113 | } | ||
114 | case autofs_ptype_expire_multi: | ||
115 | { | ||
111 | struct autofs_packet_expire_multi *ep = &pkt.expire_multi; | 116 | struct autofs_packet_expire_multi *ep = &pkt.expire_multi; |
112 | 117 | ||
113 | pktsz = sizeof(*ep); | 118 | pktsz = sizeof(*ep); |
@@ -116,7 +121,34 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, | |||
116 | ep->len = wq->len; | 121 | ep->len = wq->len; |
117 | memcpy(ep->name, wq->name, wq->len); | 122 | memcpy(ep->name, wq->name, wq->len); |
118 | ep->name[wq->len] = '\0'; | 123 | ep->name[wq->len] = '\0'; |
119 | } else { | 124 | break; |
125 | } | ||
126 | /* | ||
127 | * Kernel protocol v5 packet for handling indirect and direct | ||
128 | * mount missing and expire requests | ||
129 | */ | ||
130 | case autofs_ptype_missing_indirect: | ||
131 | case autofs_ptype_expire_indirect: | ||
132 | case autofs_ptype_missing_direct: | ||
133 | case autofs_ptype_expire_direct: | ||
134 | { | ||
135 | struct autofs_v5_packet *packet = &pkt.v5_packet; | ||
136 | |||
137 | pktsz = sizeof(*packet); | ||
138 | |||
139 | packet->wait_queue_token = wq->wait_queue_token; | ||
140 | packet->len = wq->len; | ||
141 | memcpy(packet->name, wq->name, wq->len); | ||
142 | packet->name[wq->len] = '\0'; | ||
143 | packet->dev = wq->dev; | ||
144 | packet->ino = wq->ino; | ||
145 | packet->uid = wq->uid; | ||
146 | packet->gid = wq->gid; | ||
147 | packet->pid = wq->pid; | ||
148 | packet->tgid = wq->tgid; | ||
149 | break; | ||
150 | } | ||
151 | default: | ||
120 | printk("autofs4_notify_daemon: bad type %d!\n", type); | 152 | printk("autofs4_notify_daemon: bad type %d!\n", type); |
121 | return; | 153 | return; |
122 | } | 154 | } |
@@ -162,21 +194,29 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
162 | { | 194 | { |
163 | struct autofs_wait_queue *wq; | 195 | struct autofs_wait_queue *wq; |
164 | char *name; | 196 | char *name; |
165 | int len, status; | 197 | unsigned int len = 0; |
198 | unsigned int hash = 0; | ||
199 | int status; | ||
166 | 200 | ||
167 | /* In catatonic mode, we don't wait for nobody */ | 201 | /* In catatonic mode, we don't wait for nobody */ |
168 | if ( sbi->catatonic ) | 202 | if (sbi->catatonic) |
169 | return -ENOENT; | 203 | return -ENOENT; |
170 | 204 | ||
171 | name = kmalloc(NAME_MAX + 1, GFP_KERNEL); | 205 | name = kmalloc(NAME_MAX + 1, GFP_KERNEL); |
172 | if (!name) | 206 | if (!name) |
173 | return -ENOMEM; | 207 | return -ENOMEM; |
174 | 208 | ||
175 | len = autofs4_getpath(sbi, dentry, &name); | 209 | /* If this is a direct mount request create a dummy name */ |
176 | if (!len) { | 210 | if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT)) |
177 | kfree(name); | 211 | len = sprintf(name, "%p", dentry); |
178 | return -ENOENT; | 212 | else { |
213 | len = autofs4_getpath(sbi, dentry, &name); | ||
214 | if (!len) { | ||
215 | kfree(name); | ||
216 | return -ENOENT; | ||
217 | } | ||
179 | } | 218 | } |
219 | hash = full_name_hash(name, len); | ||
180 | 220 | ||
181 | if (mutex_lock_interruptible(&sbi->wq_mutex)) { | 221 | if (mutex_lock_interruptible(&sbi->wq_mutex)) { |
182 | kfree(name); | 222 | kfree(name); |
@@ -190,7 +230,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
190 | break; | 230 | break; |
191 | } | 231 | } |
192 | 232 | ||
193 | if ( !wq ) { | 233 | if (!wq) { |
194 | /* Can't wait for an expire if there's no mount */ | 234 | /* Can't wait for an expire if there's no mount */ |
195 | if (notify == NFY_NONE && !d_mountpoint(dentry)) { | 235 | if (notify == NFY_NONE && !d_mountpoint(dentry)) { |
196 | kfree(name); | 236 | kfree(name); |
@@ -200,7 +240,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
200 | 240 | ||
201 | /* Create a new wait queue */ | 241 | /* Create a new wait queue */ |
202 | wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); | 242 | wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); |
203 | if ( !wq ) { | 243 | if (!wq) { |
204 | kfree(name); | 244 | kfree(name); |
205 | mutex_unlock(&sbi->wq_mutex); | 245 | mutex_unlock(&sbi->wq_mutex); |
206 | return -ENOMEM; | 246 | return -ENOMEM; |
@@ -212,12 +252,18 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
212 | wq->next = sbi->queues; | 252 | wq->next = sbi->queues; |
213 | sbi->queues = wq; | 253 | sbi->queues = wq; |
214 | init_waitqueue_head(&wq->queue); | 254 | init_waitqueue_head(&wq->queue); |
215 | wq->hash = dentry->d_name.hash; | 255 | wq->hash = hash; |
216 | wq->name = name; | 256 | wq->name = name; |
217 | wq->len = len; | 257 | wq->len = len; |
258 | wq->dev = autofs4_get_dev(sbi); | ||
259 | wq->ino = autofs4_get_ino(sbi); | ||
260 | wq->uid = current->uid; | ||
261 | wq->gid = current->gid; | ||
262 | wq->pid = current->pid; | ||
263 | wq->tgid = current->tgid; | ||
218 | wq->status = -EINTR; /* Status return if interrupted */ | 264 | wq->status = -EINTR; /* Status return if interrupted */ |
219 | atomic_set(&wq->wait_ctr, 2); | 265 | atomic_set(&wq->wait_ctr, 2); |
220 | atomic_set(&wq->notified, 1); | 266 | atomic_set(&wq->notify, 1); |
221 | mutex_unlock(&sbi->wq_mutex); | 267 | mutex_unlock(&sbi->wq_mutex); |
222 | } else { | 268 | } else { |
223 | atomic_inc(&wq->wait_ctr); | 269 | atomic_inc(&wq->wait_ctr); |
@@ -227,9 +273,26 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
227 | (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify); | 273 | (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify); |
228 | } | 274 | } |
229 | 275 | ||
230 | if (notify != NFY_NONE && atomic_dec_and_test(&wq->notified)) { | 276 | if (notify != NFY_NONE && atomic_read(&wq->notify)) { |
231 | int type = (notify == NFY_MOUNT ? | 277 | int type; |
232 | autofs_ptype_missing : autofs_ptype_expire_multi); | 278 | |
279 | atomic_dec(&wq->notify); | ||
280 | |||
281 | if (sbi->version < 5) { | ||
282 | if (notify == NFY_MOUNT) | ||
283 | type = autofs_ptype_missing; | ||
284 | else | ||
285 | type = autofs_ptype_expire_multi; | ||
286 | } else { | ||
287 | if (notify == NFY_MOUNT) | ||
288 | type = (sbi->type & AUTOFS_TYPE_DIRECT) ? | ||
289 | autofs_ptype_missing_direct : | ||
290 | autofs_ptype_missing_indirect; | ||
291 | else | ||
292 | type = (sbi->type & AUTOFS_TYPE_DIRECT) ? | ||
293 | autofs_ptype_expire_direct : | ||
294 | autofs_ptype_expire_indirect; | ||
295 | } | ||
233 | 296 | ||
234 | DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n", | 297 | DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n", |
235 | (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify); | 298 | (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify); |
@@ -240,14 +303,14 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, | |||
240 | 303 | ||
241 | /* wq->name is NULL if and only if the lock is already released */ | 304 | /* wq->name is NULL if and only if the lock is already released */ |
242 | 305 | ||
243 | if ( sbi->catatonic ) { | 306 | if (sbi->catatonic) { |
244 | /* We might have slept, so check again for catatonic mode */ | 307 | /* We might have slept, so check again for catatonic mode */ |
245 | wq->status = -ENOENT; | 308 | wq->status = -ENOENT; |
246 | kfree(wq->name); | 309 | kfree(wq->name); |
247 | wq->name = NULL; | 310 | wq->name = NULL; |
248 | } | 311 | } |
249 | 312 | ||
250 | if ( wq->name ) { | 313 | if (wq->name) { |
251 | /* Block all but "shutdown" signals while waiting */ | 314 | /* Block all but "shutdown" signals while waiting */ |
252 | sigset_t oldset; | 315 | sigset_t oldset; |
253 | unsigned long irqflags; | 316 | unsigned long irqflags; |
@@ -283,12 +346,12 @@ int autofs4_wait_release(struct autofs_sb_info *sbi, autofs_wqt_t wait_queue_tok | |||
283 | struct autofs_wait_queue *wq, **wql; | 346 | struct autofs_wait_queue *wq, **wql; |
284 | 347 | ||
285 | mutex_lock(&sbi->wq_mutex); | 348 | mutex_lock(&sbi->wq_mutex); |
286 | for ( wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next ) { | 349 | for (wql = &sbi->queues ; (wq = *wql) != 0 ; wql = &wq->next) { |
287 | if ( wq->wait_queue_token == wait_queue_token ) | 350 | if (wq->wait_queue_token == wait_queue_token) |
288 | break; | 351 | break; |
289 | } | 352 | } |
290 | 353 | ||
291 | if ( !wq ) { | 354 | if (!wq) { |
292 | mutex_unlock(&sbi->wq_mutex); | 355 | mutex_unlock(&sbi->wq_mutex); |
293 | return -EINVAL; | 356 | return -EINVAL; |
294 | } | 357 | } |