Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/autofs/auto_vfsops.c
+++ new/usr/src/uts/common/fs/autofs/auto_vfsops.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
24 24 */
25 25
26 26 #include <sys/param.h>
27 27 #include <sys/errno.h>
28 28 #include <sys/proc.h>
29 29 #include <sys/disp.h>
30 30 #include <sys/vfs.h>
31 31 #include <sys/vfs_opreg.h>
32 32 #include <sys/vnode.h>
33 33 #include <sys/uio.h>
34 34 #include <sys/kmem.h>
35 35 #include <sys/cred.h>
36 36 #include <sys/statvfs.h>
37 37 #include <sys/mount.h>
38 38 #include <sys/tiuser.h>
39 39 #include <sys/cmn_err.h>
40 40 #include <sys/debug.h>
41 41 #include <sys/systm.h>
42 42 #include <sys/sysmacros.h>
43 43 #include <sys/pathname.h>
44 44 #include <rpc/types.h>
45 45 #include <rpc/auth.h>
46 46 #include <rpc/clnt.h>
47 47 #include <fs/fs_subr.h>
48 48 #include <sys/fs/autofs.h>
49 49 #include <sys/modctl.h>
50 50 #include <sys/mntent.h>
51 51 #include <sys/policy.h>
52 52 #include <sys/zone.h>
53 53
54 54 static int autofs_init(int, char *);
55 55
56 56 static major_t autofs_major;
57 57 static minor_t autofs_minor;
58 58
59 59 kmutex_t autofs_minor_lock;
60 60 zone_key_t autofs_key;
61 61
62 62 static mntopts_t auto_mntopts;
63 63
64 64 /*
65 65 * The AUTOFS system call.
66 66 */
67 67 static struct sysent autofssysent = {
68 68 2,
69 69 SE_32RVAL1 | SE_ARGC | SE_NOUNLOAD,
70 70 autofssys
71 71 };
72 72
73 73 static struct modlsys modlsys = {
74 74 &mod_syscallops,
75 75 "AUTOFS syscall",
76 76 &autofssysent
77 77 };
78 78
79 79 #ifdef _SYSCALL32_IMPL
80 80 static struct modlsys modlsys32 = {
81 81 &mod_syscallops32,
82 82 "AUTOFS syscall (32-bit)",
83 83 &autofssysent
84 84 };
85 85 #endif /* _SYSCALL32_IMPL */
86 86
87 87 static vfsdef_t vfw = {
88 88 VFSDEF_VERSION,
89 89 "autofs",
90 90 autofs_init,
91 91 VSW_HASPROTO|VSW_CANRWRO|VSW_CANREMOUNT|VSW_STATS|VSW_ZMOUNT,
92 92 &auto_mntopts
93 93 };
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
94 94
95 95 /*
96 96 * Module linkage information for the kernel.
97 97 */
98 98 static struct modlfs modlfs = {
99 99 &mod_fsops, "filesystem for autofs", &vfw
100 100 };
101 101
102 102 static struct modlinkage modlinkage = {
103 103 MODREV_1,
104 - &modlfs,
105 - &modlsys,
104 + { &modlfs,
105 + &modlsys,
106 106 #ifdef _SYSCALL32_IMPL
107 - &modlsys32,
107 + &modlsys32,
108 108 #endif
109 - NULL
109 + NULL
110 + }
110 111 };
111 112
112 113 /*
113 114 * This is the module initialization routine.
114 115 */
115 116 int
116 117 _init(void)
117 118 {
118 119 return (mod_install(&modlinkage));
119 120 }
120 121
121 122 int
122 123 _fini(void)
123 124 {
124 125 /*
125 126 * Don't allow the autofs module to be unloaded for now.
126 127 */
127 128 return (EBUSY);
128 129 }
129 130
130 131 int
131 132 _info(struct modinfo *modinfop)
132 133 {
133 134 return (mod_info(&modlinkage, modinfop));
134 135 }
135 136
136 137 static int autofs_fstype;
137 138
138 139 /*
139 140 * autofs VFS operations
140 141 */
141 142 static int auto_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
142 143 static int auto_unmount(vfs_t *, int, cred_t *);
143 144 static int auto_root(vfs_t *, vnode_t **);
144 145 static int auto_statvfs(vfs_t *, struct statvfs64 *);
145 146
146 147 /*
147 148 * Auto Mount options table
148 149 */
149 150
150 151 static char *direct_cancel[] = { MNTOPT_INDIRECT, NULL };
151 152 static char *indirect_cancel[] = { MNTOPT_DIRECT, NULL };
152 153 static char *browse_cancel[] = { MNTOPT_NOBROWSE, NULL };
153 154 static char *nobrowse_cancel[] = { MNTOPT_BROWSE, NULL };
154 155
155 156 static mntopt_t mntopts[] = {
156 157 /*
157 158 * option name cancel options default arg flags
158 159 */
159 160 { MNTOPT_DIRECT, direct_cancel, NULL, 0,
160 161 NULL },
161 162 { MNTOPT_INDIRECT, indirect_cancel, NULL, 0,
162 163 NULL },
163 164 { MNTOPT_IGNORE, NULL, NULL,
164 165 MO_DEFAULT|MO_TAG, NULL },
165 166 { "nest", NULL, NULL, MO_TAG,
166 167 NULL },
167 168 { MNTOPT_BROWSE, browse_cancel, NULL, MO_TAG,
168 169 NULL },
169 170 { MNTOPT_NOBROWSE, nobrowse_cancel, NULL, MO_TAG,
170 171 NULL },
171 172 { MNTOPT_RESTRICT, NULL, NULL, MO_TAG,
172 173 NULL },
173 174 };
174 175
175 176 static mntopts_t auto_mntopts = {
176 177 sizeof (mntopts) / sizeof (mntopt_t),
177 178 mntopts
178 179 };
179 180
180 181 /*ARGSUSED*/
181 182 static void
182 183 autofs_zone_destructor(zoneid_t zoneid, void *arg)
183 184 {
184 185 struct autofs_globals *fngp = arg;
185 186 vnode_t *vp;
186 187
187 188 if (fngp == NULL)
188 189 return;
189 190 ASSERT(fngp->fng_fnnode_count == 1);
190 191 ASSERT(fngp->fng_unmount_threads == 0);
191 192
192 193 if (fngp->fng_autofs_daemon_dh != NULL)
193 194 door_ki_rele(fngp->fng_autofs_daemon_dh);
194 195 /*
195 196 * vn_alloc() initialized the rootnode with a count of 1; we need to
196 197 * make this 0 to placate auto_freefnnode().
197 198 */
198 199 vp = fntovn(fngp->fng_rootfnnodep);
199 200 ASSERT(vp->v_count == 1);
200 201 vp->v_count--;
201 202 auto_freefnnode(fngp->fng_rootfnnodep);
202 203 mutex_destroy(&fngp->fng_unmount_threads_lock);
203 204 kmem_free(fngp, sizeof (*fngp));
204 205 }
205 206
206 207 /*
207 208 * rootfnnodep is allocated here. Its sole purpose is to provide
208 209 * read/write locking for top level fnnodes. This object is
209 210 * persistent and will not be deallocated until the zone is destroyed.
210 211 *
211 212 * The current zone is implied as the zone of interest, since we will be
212 213 * calling zthread_create() which must be called from the correct zone.
213 214 */
214 215 struct autofs_globals *
215 216 autofs_zone_init(void)
216 217 {
217 218 char rootname[sizeof ("root_fnnode_zone_") + ZONEID_WIDTH];
218 219 struct autofs_globals *fngp;
219 220 zoneid_t zoneid = getzoneid();
220 221
221 222 fngp = kmem_zalloc(sizeof (*fngp), KM_SLEEP);
222 223 (void) snprintf(rootname, sizeof (rootname), "root_fnnode_zone_%d",
223 224 zoneid);
224 225 fngp->fng_rootfnnodep = auto_makefnnode(VNON, NULL, rootname, CRED(),
225 226 fngp);
226 227 /*
227 228 * Don't need to hold fng_rootfnnodep as it's never really used for
228 229 * anything.
229 230 */
230 231 fngp->fng_fnnode_count = 1;
231 232 fngp->fng_printed_not_running_msg = 0;
232 233 fngp->fng_zoneid = zoneid;
233 234 mutex_init(&fngp->fng_unmount_threads_lock, NULL, MUTEX_DEFAULT,
234 235 NULL);
235 236 fngp->fng_unmount_threads = 0;
236 237
237 238 mutex_init(&fngp->fng_autofs_daemon_lock, NULL, MUTEX_DEFAULT, NULL);
238 239
239 240 /*
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
240 241 * Start the unmounter thread for this zone.
241 242 */
242 243 (void) zthread_create(NULL, 0, auto_do_unmount, fngp, 0, minclsyspri);
243 244 return (fngp);
244 245 }
245 246
246 247 int
247 248 autofs_init(int fstype, char *name)
248 249 {
249 250 static const fs_operation_def_t auto_vfsops_template[] = {
250 - VFSNAME_MOUNT, { .vfs_mount = auto_mount },
251 - VFSNAME_UNMOUNT, { .vfs_unmount = auto_unmount },
252 - VFSNAME_ROOT, { .vfs_root = auto_root },
253 - VFSNAME_STATVFS, { .vfs_statvfs = auto_statvfs },
254 - NULL, NULL
251 + { VFSNAME_MOUNT, { .vfs_mount = auto_mount } },
252 + { VFSNAME_UNMOUNT, { .vfs_unmount = auto_unmount } },
253 + { VFSNAME_ROOT, { .vfs_root = auto_root } },
254 + { VFSNAME_STATVFS, { .vfs_statvfs = auto_statvfs } },
255 + { NULL, { NULL } }
255 256 };
256 257 int error;
257 258
258 259 autofs_fstype = fstype;
259 260 ASSERT(autofs_fstype != 0);
260 261 /*
261 262 * Associate VFS ops vector with this fstype
262 263 */
263 264 error = vfs_setfsops(fstype, auto_vfsops_template, NULL);
264 265 if (error != 0) {
265 266 cmn_err(CE_WARN, "autofs_init: bad vfs ops template");
266 267 return (error);
267 268 }
268 269
269 270 error = vn_make_ops(name, auto_vnodeops_template, &auto_vnodeops);
270 271 if (error != 0) {
271 272 (void) vfs_freevfsops_by_type(fstype);
272 273 cmn_err(CE_WARN, "autofs_init: bad vnode ops template");
273 274 return (error);
274 275 }
275 276
276 277 mutex_init(&autofs_minor_lock, NULL, MUTEX_DEFAULT, NULL);
277 278 /*
278 279 * Assign unique major number for all autofs mounts
279 280 */
280 281 if ((autofs_major = getudev()) == (major_t)-1) {
281 282 cmn_err(CE_WARN,
282 283 "autofs: autofs_init: can't get unique device number");
283 284 mutex_destroy(&autofs_minor_lock);
284 285 return (1);
285 286 }
286 287
287 288 /*
288 289 * We'd like to be able to provide a constructor here, but we can't
289 290 * since it wants to zthread_create(), something it can't do in a ZSD
290 291 * constructor.
291 292 */
292 293 zone_key_create(&autofs_key, NULL, NULL, autofs_zone_destructor);
293 294
294 295 return (0);
295 296 }
296 297
297 298 static char *restropts[] = {
298 299 RESTRICTED_MNTOPTS
299 300 };
300 301
301 302 /*
302 303 * This routine adds those options to the option string `buf' which are
303 304 * forced by secpolicy_fs_mount. If the automatic "security" options
304 305 * are set, the option string gets them added if they aren't already
305 306 * there. We search the string with "strstr" and make sure that
306 307 * the string we find is bracketed with <start|",">MNTOPT<","|"\0">
307 308 *
308 309 * This is one half of the option inheritence algorithm which
309 310 * implements the "restrict" option. The other half is implemented
310 311 * in automountd; it takes its cue from the options we add here.
311 312 */
312 313 static int
313 314 autofs_restrict_opts(struct vfs *vfsp, char *buf, size_t maxlen, size_t *curlen)
314 315 {
315 316 int i;
316 317 char *p;
317 318 size_t len = *curlen - 1;
318 319
319 320 /* Unrestricted */
320 321 if (!vfs_optionisset(vfsp, restropts[0], NULL))
321 322 return (0);
322 323
323 324 for (i = 0; i < sizeof (restropts)/sizeof (restropts[0]); i++) {
324 325 size_t olen = strlen(restropts[i]);
325 326
326 327 /* Add "restrict" always and the others insofar set */
327 328 if ((i == 0 || vfs_optionisset(vfsp, restropts[i], NULL)) &&
328 329 ((p = strstr(buf, restropts[i])) == NULL ||
329 330 !((p == buf || p[-1] == ',') &&
330 331 (p[olen] == '\0' || p[olen] == ',')))) {
331 332
332 333 if (len + olen + 1 > maxlen)
333 334 return (-1);
334 335
335 336 if (*buf != '\0')
336 337 buf[len++] = ',';
337 338 (void) strcpy(&buf[len], restropts[i]);
338 339 len += olen;
339 340 }
340 341 }
341 342 *curlen = len + 1;
342 343 return (0);
343 344 }
344 345
345 346 /* ARGSUSED */
346 347 static int
347 348 auto_mount(vfs_t *vfsp, vnode_t *vp, struct mounta *uap, cred_t *cr)
348 349 {
349 350 int error;
350 351 size_t len = 0;
351 352 autofs_args args;
352 353 fninfo_t *fnip = NULL;
353 354 vnode_t *rootvp = NULL;
354 355 fnnode_t *rootfnp = NULL;
355 356 char *data = uap->dataptr;
356 357 char datalen = uap->datalen;
357 358 dev_t autofs_dev;
358 359 char strbuff[MAXPATHLEN + 1];
359 360 vnode_t *kkvp;
360 361 struct autofs_globals *fngp;
361 362 zone_t *zone = curproc->p_zone;
362 363
363 364 AUTOFS_DPRINT((4, "auto_mount: vfs %p vp %p\n", (void *)vfsp,
364 365 (void *)vp));
365 366
366 367 if ((error = secpolicy_fs_mount(cr, vp, vfsp)) != 0)
367 368 return (EPERM);
368 369
369 370 if (zone == global_zone) {
370 371 zone_t *mntzone;
371 372
372 373 mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt));
373 374 ASSERT(mntzone != NULL);
374 375 zone_rele(mntzone);
375 376 if (mntzone != zone) {
376 377 return (EBUSY);
377 378 }
378 379 }
379 380
380 381 /*
381 382 * Stop the mount from going any further if the zone is going away.
382 383 */
383 384 if (zone_status_get(zone) >= ZONE_IS_SHUTTING_DOWN)
384 385 return (EBUSY);
385 386
386 387 /*
387 388 * We need a lock to serialize this; minor_lock is as good as any.
388 389 */
389 390 mutex_enter(&autofs_minor_lock);
390 391 if ((fngp = zone_getspecific(autofs_key, zone)) == NULL) {
391 392 fngp = autofs_zone_init();
392 393 (void) zone_setspecific(autofs_key, zone, fngp);
393 394 }
394 395 mutex_exit(&autofs_minor_lock);
395 396 ASSERT(fngp != NULL);
396 397
397 398 /*
398 399 * Get arguments
399 400 */
400 401 if (uap->flags & MS_SYSSPACE) {
401 402 if (datalen != sizeof (args))
402 403 return (EINVAL);
403 404 error = kcopy(data, &args, sizeof (args));
404 405 } else {
405 406 if (get_udatamodel() == DATAMODEL_NATIVE) {
406 407 if (datalen != sizeof (args))
407 408 return (EINVAL);
408 409 error = copyin(data, &args, sizeof (args));
409 410 } else {
410 411 struct autofs_args32 args32;
411 412
412 413 if (datalen != sizeof (args32))
413 414 return (EINVAL);
414 415 error = copyin(data, &args32, sizeof (args32));
415 416
416 417 args.addr.maxlen = args32.addr.maxlen;
417 418 args.addr.len = args32.addr.len;
418 419 args.addr.buf = (char *)(uintptr_t)args32.addr.buf;
419 420 args.path = (char *)(uintptr_t)args32.path;
420 421 args.opts = (char *)(uintptr_t)args32.opts;
421 422 args.map = (char *)(uintptr_t)args32.map;
422 423 args.subdir = (char *)(uintptr_t)args32.subdir;
423 424 args.key = (char *)(uintptr_t)args32.key;
424 425 args.mount_to = args32.mount_to;
425 426 args.rpc_to = args32.rpc_to;
426 427 args.direct = args32.direct;
427 428 }
428 429 }
429 430 if (error)
430 431 return (EFAULT);
431 432
432 433 /*
433 434 * For a remount, only update mount information
434 435 * i.e. default mount options, map name, etc.
435 436 */
436 437 if (uap->flags & MS_REMOUNT) {
437 438 fnip = vfstofni(vfsp);
438 439 if (fnip == NULL)
439 440 return (EINVAL);
440 441
441 442 if (args.direct == 1)
442 443 fnip->fi_flags |= MF_DIRECT;
443 444 else
444 445 fnip->fi_flags &= ~MF_DIRECT;
445 446 fnip->fi_mount_to = args.mount_to;
446 447 fnip->fi_rpc_to = args.rpc_to;
447 448
448 449 /*
449 450 * Get default options
450 451 */
451 452 if (uap->flags & MS_SYSSPACE)
452 453 error = copystr(args.opts, strbuff, sizeof (strbuff),
453 454 &len);
454 455 else
455 456 error = copyinstr(args.opts, strbuff, sizeof (strbuff),
456 457 &len);
457 458 if (error)
458 459 return (EFAULT);
459 460
460 461 if (autofs_restrict_opts(vfsp, strbuff, sizeof (strbuff), &len)
461 462 != 0) {
462 463 return (EFAULT);
463 464 }
464 465
465 466 kmem_free(fnip->fi_opts, fnip->fi_optslen);
466 467 fnip->fi_opts = kmem_alloc(len, KM_SLEEP);
467 468 fnip->fi_optslen = (int)len;
468 469 bcopy(strbuff, fnip->fi_opts, len);
469 470
470 471 /*
471 472 * Get context/map name
472 473 */
473 474 if (uap->flags & MS_SYSSPACE)
474 475 error = copystr(args.map, strbuff, sizeof (strbuff),
475 476 &len);
476 477 else
477 478 error = copyinstr(args.map, strbuff, sizeof (strbuff),
478 479 &len);
479 480 if (error)
480 481 return (EFAULT);
481 482
482 483 kmem_free(fnip->fi_map, fnip->fi_maplen);
483 484 fnip->fi_map = kmem_alloc(len, KM_SLEEP);
484 485 fnip->fi_maplen = (int)len;
485 486 bcopy(strbuff, fnip->fi_map, len);
486 487
487 488 return (0);
488 489 }
489 490
490 491 /*
491 492 * Allocate fninfo struct and attach it to vfs
492 493 */
493 494 fnip = kmem_zalloc(sizeof (*fnip), KM_SLEEP);
494 495 fnip->fi_mountvfs = vfsp;
495 496
496 497 fnip->fi_mount_to = args.mount_to;
497 498 fnip->fi_rpc_to = args.rpc_to;
498 499 fnip->fi_refcnt = 0;
499 500 vfsp->vfs_bsize = AUTOFS_BLOCKSIZE;
500 501 vfsp->vfs_fstype = autofs_fstype;
501 502
502 503 /*
503 504 * Assign a unique device id to the mount
504 505 */
505 506 mutex_enter(&autofs_minor_lock);
506 507 do {
507 508 autofs_minor = (autofs_minor + 1) & L_MAXMIN32;
508 509 autofs_dev = makedevice(autofs_major, autofs_minor);
509 510 } while (vfs_devismounted(autofs_dev));
510 511 mutex_exit(&autofs_minor_lock);
511 512 vfsp->vfs_dev = autofs_dev;
512 513 vfs_make_fsid(&vfsp->vfs_fsid, autofs_dev, autofs_fstype);
513 514 vfsp->vfs_data = (void *)fnip;
514 515 vfsp->vfs_bcount = 0;
515 516
516 517 /*
517 518 * Get daemon address
518 519 */
519 520 fnip->fi_addr.len = args.addr.len;
520 521 fnip->fi_addr.maxlen = fnip->fi_addr.len;
521 522 fnip->fi_addr.buf = kmem_alloc(args.addr.len, KM_SLEEP);
522 523 if (uap->flags & MS_SYSSPACE)
523 524 error = kcopy(args.addr.buf, fnip->fi_addr.buf, args.addr.len);
524 525 else
525 526 error = copyin(args.addr.buf, fnip->fi_addr.buf, args.addr.len);
526 527 if (error) {
527 528 error = EFAULT;
528 529 goto errout;
529 530 }
530 531
531 532 fnip->fi_zoneid = getzoneid();
532 533 /*
533 534 * Get path for mountpoint
534 535 */
535 536 if (uap->flags & MS_SYSSPACE)
536 537 error = copystr(args.path, strbuff, sizeof (strbuff), &len);
537 538 else
538 539 error = copyinstr(args.path, strbuff, sizeof (strbuff), &len);
539 540 if (error) {
540 541 error = EFAULT;
541 542 goto errout;
542 543 }
543 544 fnip->fi_path = kmem_alloc(len, KM_SLEEP);
544 545 fnip->fi_pathlen = (int)len;
545 546 bcopy(strbuff, fnip->fi_path, len);
546 547
547 548 /*
548 549 * Get default options
549 550 */
550 551 if (uap->flags & MS_SYSSPACE)
551 552 error = copystr(args.opts, strbuff, sizeof (strbuff), &len);
552 553 else
553 554 error = copyinstr(args.opts, strbuff, sizeof (strbuff), &len);
554 555
555 556 if (error != 0 ||
556 557 autofs_restrict_opts(vfsp, strbuff, sizeof (strbuff), &len) != 0) {
557 558 error = EFAULT;
558 559 goto errout;
559 560 }
560 561 fnip->fi_opts = kmem_alloc(len, KM_SLEEP);
561 562 fnip->fi_optslen = (int)len;
562 563 bcopy(strbuff, fnip->fi_opts, len);
563 564
564 565 /*
565 566 * Get context/map name
566 567 */
567 568 if (uap->flags & MS_SYSSPACE)
568 569 error = copystr(args.map, strbuff, sizeof (strbuff), &len);
569 570 else
570 571 error = copyinstr(args.map, strbuff, sizeof (strbuff), &len);
571 572 if (error) {
572 573 error = EFAULT;
573 574 goto errout;
574 575 }
575 576 fnip->fi_map = kmem_alloc(len, KM_SLEEP);
576 577 fnip->fi_maplen = (int)len;
577 578 bcopy(strbuff, fnip->fi_map, len);
578 579
579 580 /*
580 581 * Get subdirectory within map
581 582 */
582 583 if (uap->flags & MS_SYSSPACE)
583 584 error = copystr(args.subdir, strbuff, sizeof (strbuff), &len);
584 585 else
585 586 error = copyinstr(args.subdir, strbuff, sizeof (strbuff), &len);
586 587 if (error) {
587 588 error = EFAULT;
588 589 goto errout;
589 590 }
590 591 fnip->fi_subdir = kmem_alloc(len, KM_SLEEP);
591 592 fnip->fi_subdirlen = (int)len;
592 593 bcopy(strbuff, fnip->fi_subdir, len);
593 594
594 595 /*
595 596 * Get the key
596 597 */
597 598 if (uap->flags & MS_SYSSPACE)
598 599 error = copystr(args.key, strbuff, sizeof (strbuff), &len);
599 600 else
600 601 error = copyinstr(args.key, strbuff, sizeof (strbuff), &len);
601 602 if (error) {
602 603 error = EFAULT;
603 604 goto errout;
604 605 }
605 606 fnip->fi_key = kmem_alloc(len, KM_SLEEP);
606 607 fnip->fi_keylen = (int)len;
607 608 bcopy(strbuff, fnip->fi_key, len);
608 609
609 610 /*
610 611 * Is this a direct mount?
611 612 */
612 613 if (args.direct == 1)
613 614 fnip->fi_flags |= MF_DIRECT;
614 615
615 616 /*
616 617 * Setup netconfig.
617 618 * Can I pass in knconf as mount argument? what
618 619 * happens when the daemon gets restarted?
619 620 */
620 621 if ((error = lookupname("/dev/ticotsord", UIO_SYSSPACE, FOLLOW,
621 622 NULLVPP, &kkvp)) != 0) {
622 623 cmn_err(CE_WARN, "autofs: lookupname: %d", error);
623 624 goto errout;
624 625 }
625 626
626 627 fnip->fi_knconf.knc_rdev = kkvp->v_rdev;
627 628 fnip->fi_knconf.knc_protofmly = NC_LOOPBACK;
628 629 fnip->fi_knconf.knc_semantics = NC_TPI_COTS_ORD;
629 630 VN_RELE(kkvp);
630 631
631 632 /*
632 633 * Make the root vnode
633 634 */
634 635 rootfnp = auto_makefnnode(VDIR, vfsp, fnip->fi_path, cr, fngp);
635 636 if (rootfnp == NULL) {
636 637 error = ENOMEM;
637 638 goto errout;
638 639 }
639 640 rootvp = fntovn(rootfnp);
640 641
641 642 rootvp->v_flag |= VROOT;
642 643 rootfnp->fn_mode = AUTOFS_MODE;
643 644 rootfnp->fn_parent = rootfnp;
644 645 /* account for ".." entry */
645 646 rootfnp->fn_linkcnt = rootfnp->fn_size = 1;
646 647 fnip->fi_rootvp = rootvp;
647 648
648 649 /*
649 650 * Add to list of top level AUTOFS' if it is being mounted by
650 651 * a user level process.
651 652 */
652 653 if (!(uap->flags & MS_SYSSPACE)) {
653 654 rw_enter(&fngp->fng_rootfnnodep->fn_rwlock, RW_WRITER);
654 655 rootfnp->fn_parent = fngp->fng_rootfnnodep;
655 656 rootfnp->fn_next = fngp->fng_rootfnnodep->fn_dirents;
656 657 fngp->fng_rootfnnodep->fn_dirents = rootfnp;
657 658 rw_exit(&fngp->fng_rootfnnodep->fn_rwlock);
658 659 }
659 660
660 661 AUTOFS_DPRINT((5, "auto_mount: vfs %p root %p fnip %p return %d\n",
661 662 (void *)vfsp, (void *)rootvp, (void *)fnip, error));
662 663
663 664 return (0);
664 665
665 666 errout:
666 667 ASSERT(fnip != NULL);
667 668 ASSERT((uap->flags & MS_REMOUNT) == 0);
668 669
669 670 if (fnip->fi_addr.buf != NULL)
670 671 kmem_free(fnip->fi_addr.buf, fnip->fi_addr.len);
671 672 if (fnip->fi_path != NULL)
672 673 kmem_free(fnip->fi_path, fnip->fi_pathlen);
673 674 if (fnip->fi_opts != NULL)
674 675 kmem_free(fnip->fi_opts, fnip->fi_optslen);
675 676 if (fnip->fi_map != NULL)
676 677 kmem_free(fnip->fi_map, fnip->fi_maplen);
677 678 if (fnip->fi_subdir != NULL)
678 679 kmem_free(fnip->fi_subdir, fnip->fi_subdirlen);
679 680 if (fnip->fi_key != NULL)
680 681 kmem_free(fnip->fi_key, fnip->fi_keylen);
681 682 kmem_free(fnip, sizeof (*fnip));
682 683
683 684 AUTOFS_DPRINT((5, "auto_mount: vfs %p root %p fnip %p return %d\n",
684 685 (void *)vfsp, (void *)rootvp, (void *)fnip, error));
685 686
686 687 return (error);
687 688 }
688 689
689 690 /* ARGSUSED */
690 691 static int
691 692 auto_unmount(vfs_t *vfsp, int flag, cred_t *cr)
692 693 {
693 694 fninfo_t *fnip;
694 695 vnode_t *rvp;
695 696 fnnode_t *rfnp, *fnp, *pfnp;
696 697 fnnode_t *myrootfnnodep;
697 698
698 699 fnip = vfstofni(vfsp);
699 700 AUTOFS_DPRINT((4, "auto_unmount vfsp %p fnip %p\n", (void *)vfsp,
700 701 (void *)fnip));
701 702
702 703 if (secpolicy_fs_unmount(cr, vfsp) != 0)
703 704 return (EPERM);
704 705 /*
705 706 * forced unmount is not supported by this file system
706 707 * and thus, ENOTSUP, is being returned.
707 708 */
708 709 if (flag & MS_FORCE)
709 710 return (ENOTSUP);
710 711
711 712 ASSERT(vn_vfswlock_held(vfsp->vfs_vnodecovered));
712 713 rvp = fnip->fi_rootvp;
713 714 rfnp = vntofn(rvp);
714 715
715 716 if (rvp->v_count > 1 || rfnp->fn_dirents != NULL)
716 717 return (EBUSY);
717 718
718 719 /*
719 720 * The root vnode is on the linked list of root fnnodes only if
720 721 * this was not a trigger node. Since we have no way of knowing,
721 722 * if we don't find it, then we assume it was a trigger node.
722 723 */
723 724 myrootfnnodep = rfnp->fn_globals->fng_rootfnnodep;
724 725 pfnp = NULL;
725 726 rw_enter(&myrootfnnodep->fn_rwlock, RW_WRITER);
726 727 fnp = myrootfnnodep->fn_dirents;
727 728 while (fnp != NULL) {
728 729 if (fnp == rfnp) {
729 730 /*
730 731 * A check here is made to see if rvp is busy. If
731 732 * so, return EBUSY. Otherwise proceed with
732 733 * disconnecting it from the list.
733 734 */
734 735 if (rvp->v_count > 1 || rfnp->fn_dirents != NULL) {
735 736 rw_exit(&myrootfnnodep->fn_rwlock);
736 737 return (EBUSY);
737 738 }
738 739 if (pfnp)
739 740 pfnp->fn_next = fnp->fn_next;
740 741 else
741 742 myrootfnnodep->fn_dirents = fnp->fn_next;
742 743 fnp->fn_next = NULL;
743 744 break;
744 745 }
745 746 pfnp = fnp;
746 747 fnp = fnp->fn_next;
747 748 }
748 749 rw_exit(&myrootfnnodep->fn_rwlock);
749 750
750 751 ASSERT(rvp->v_count == 1);
751 752 ASSERT(rfnp->fn_size == 1);
752 753 ASSERT(rfnp->fn_linkcnt == 1);
753 754 /*
754 755 * The following drops linkcnt to 0, therefore the disconnect is
755 756 * not attempted when auto_inactive() is called by
756 757 * vn_rele(). This is necessary because we have nothing to get
757 758 * disconnected from since we're the root of the filesystem. As a
758 759 * side effect the node is not freed, therefore I should free the
759 760 * node here.
760 761 *
761 762 * XXX - I really need to think of a better way of doing this.
762 763 */
763 764 rfnp->fn_size--;
764 765 rfnp->fn_linkcnt--;
765 766
766 767 /*
767 768 * release of last reference causes node
768 769 * to be freed
769 770 */
770 771 VN_RELE(rvp);
771 772 rfnp->fn_parent = NULL;
772 773
773 774 auto_freefnnode(rfnp);
774 775
775 776 kmem_free(fnip->fi_addr.buf, fnip->fi_addr.len);
776 777 kmem_free(fnip->fi_path, fnip->fi_pathlen);
777 778 kmem_free(fnip->fi_map, fnip->fi_maplen);
778 779 kmem_free(fnip->fi_subdir, fnip->fi_subdirlen);
779 780 kmem_free(fnip->fi_key, fnip->fi_keylen);
780 781 kmem_free(fnip->fi_opts, fnip->fi_optslen);
781 782 kmem_free(fnip, sizeof (*fnip));
782 783 AUTOFS_DPRINT((5, "auto_unmount: return=0\n"));
783 784
784 785 return (0);
785 786 }
786 787
787 788
788 789 /*
789 790 * find root of autofs
790 791 */
791 792 static int
792 793 auto_root(vfs_t *vfsp, vnode_t **vpp)
793 794 {
794 795 *vpp = (vnode_t *)vfstofni(vfsp)->fi_rootvp;
795 796 VN_HOLD(*vpp);
796 797
797 798 AUTOFS_DPRINT((5, "auto_root: vfs %p, *vpp %p\n", (void *)vfsp,
798 799 (void *)*vpp));
799 800 return (0);
800 801 }
801 802
802 803 /*
803 804 * Get file system statistics.
804 805 */
805 806 static int
806 807 auto_statvfs(vfs_t *vfsp, struct statvfs64 *sbp)
807 808 {
808 809 dev32_t d32;
809 810
810 811 AUTOFS_DPRINT((4, "auto_statvfs %p\n", (void *)vfsp));
811 812
812 813 bzero(sbp, sizeof (*sbp));
813 814 sbp->f_bsize = vfsp->vfs_bsize;
814 815 sbp->f_frsize = sbp->f_bsize;
815 816 sbp->f_blocks = (fsblkcnt64_t)0;
816 817 sbp->f_bfree = (fsblkcnt64_t)0;
817 818 sbp->f_bavail = (fsblkcnt64_t)0;
818 819 sbp->f_files = (fsfilcnt64_t)0;
819 820 sbp->f_ffree = (fsfilcnt64_t)0;
820 821 sbp->f_favail = (fsfilcnt64_t)0;
821 822 (void) cmpldev(&d32, vfsp->vfs_dev);
822 823 sbp->f_fsid = d32;
823 824 (void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
824 825 sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
825 826 sbp->f_namemax = MAXNAMELEN;
826 827 (void) strcpy(sbp->f_fstr, MNTTYPE_AUTOFS);
827 828
828 829 return (0);
829 830 }
↓ open down ↓ |
565 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX