nightly: use make -de
[unleashed.git] / kernel / fs / autofs / auto_sys.c
blobe4678dc9c1f1eb29c4cf392a22704600cf5a6a01
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
26 #include <sys/systm.h>
27 #include <sys/zone.h>
28 #include <sys/errno.h>
29 #include <sys/cred.h>
30 #include <sys/policy.h>
32 #include <sys/fs/autofs.h>
34 extern struct autofs_globals *autofs_zone_init(void);
36 int
37 autofssys(enum autofssys_op opcode, uintptr_t arg)
39 int error = 0;
41 switch (opcode) {
42 case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */
43 zone_t *zone;
44 zoneid_t zoneid;
45 struct autofs_globals *fngp;
47 zoneid = (zoneid_t)arg;
48 if (secpolicy_fs_unmount(CRED(), NULL) != 0 ||
49 crgetzoneid(CRED()) != GLOBAL_ZONEID)
50 return (set_errno(EPERM));
51 if ((zone = zone_find_by_id(zoneid)) == NULL)
52 return (set_errno(EINVAL));
53 mutex_enter(&autofs_minor_lock);
54 fngp = zone_getspecific(autofs_key, zone);
55 if (fngp == NULL) {
56 mutex_exit(&autofs_minor_lock);
57 zone_rele(zone);
59 * There were no mounts, so no work to do. Success.
61 return (0);
63 mutex_exit(&autofs_minor_lock);
64 unmount_tree(fngp, B_TRUE);
65 zone_rele(zone);
66 break;
68 case AUTOFS_SETDOOR: { /* set door handle for zone */
69 uint_t did;
70 struct autofs_globals *fngp;
73 * We need to use the minor_lock to serialize setting this.
75 mutex_enter(&autofs_minor_lock);
76 fngp = zone_getspecific(autofs_key, curproc->p_zone);
77 if (fngp == NULL) {
78 fngp = autofs_zone_init();
79 (void) zone_setspecific(autofs_key,
80 curproc->p_zone, fngp);
82 mutex_exit(&autofs_minor_lock);
83 ASSERT(fngp != NULL);
85 if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
86 return (set_errno(EFAULT));
88 mutex_enter(&fngp->fng_autofs_daemon_lock);
89 if (fngp->fng_autofs_daemon_dh)
90 door_ki_rele(fngp->fng_autofs_daemon_dh);
91 fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
92 fngp->fng_autofs_pid = curproc->p_pid;
93 mutex_exit(&fngp->fng_autofs_daemon_lock);
94 break;
96 default:
97 error = EINVAL;
98 break;
100 return (error ? set_errno(error) : 0);