2 * Copyright (c) 2016 The DragonFly Project
3 * Copyright (c) 2014 The FreeBSD Foundation
6 * This software was developed by Edward Tomasz Napierala under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/types.h>
39 #include <sys/systm.h>
40 #include <sys/stdbool.h>
41 #include <sys/malloc.h>
42 #include <sys/objcache.h>
45 #include <sys/condvar.h>
46 #include <sys/mount.h>
47 #include <sys/vnode.h>
48 #include <sys/timespec.h>
49 #include <sys/callout.h>
50 #include <sys/taskqueue.h>
54 #define AUTOFS_ROOTINO ((ino_t)1)
55 #define VFSTOAUTOFS(mp) ((struct autofs_mount *)((mp)->mnt_data))
56 #define VTOI(vp) ((struct autofs_node *)((vp)->v_data))
58 MALLOC_DECLARE(M_AUTOFS);
60 extern struct objcache *autofs_request_objcache;
61 extern struct objcache *autofs_node_objcache;
63 extern struct vop_ops autofs_vnode_vops;
65 extern int autofs_debug;
66 extern int autofs_mount_on_stat;
69 * APRINTF is only for debugging.
71 #define APRINTF(A, B, ...) \
72 kprintf(A " %s(%s): " B, __func__, curthread->td_comm, ## __VA_ARGS__)
74 #define AUTOFS_DEBUG(X, ...) \
76 if (autofs_debug > 1) \
77 kprintf("%s: " X "\n", \
78 __func__, ## __VA_ARGS__); \
81 #define AUTOFS_WARN(X, ...) \
83 if (autofs_debug > 0) { \
84 kprintf("WARNING: %s: " X "\n", \
85 __func__, ## __VA_ARGS__); \
89 #define AUTOFS_FATAL(X, ...) \
90 kprintf("FATAL: %s: " X "\n", __func__, ## __VA_ARGS__)
92 #define AUTOFS_LOCK_STATUS(lock) (lockstatus((lock), curthread))
93 #define AUTOFS_ASSERT_LOCKED(X) \
94 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) & (LK_EXCLUSIVE | LK_SHARED))
95 #define AUTOFS_ASSERT_XLOCKED(X) \
96 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) == LK_EXCLUSIVE)
97 #define AUTOFS_ASSERT_UNLOCKED(X) \
98 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) == 0)
101 RB_ENTRY(autofs_node) an_link;
104 struct autofs_node *an_parent;
105 RB_HEAD(autofs_node_tree,
106 autofs_node) an_children;
107 struct autofs_mount *an_mount;
108 struct vnode *an_vnode;
109 struct lock an_vnode_lock;
112 struct callout an_callout;
114 struct timespec an_ctime;
117 struct autofs_mount {
118 TAILQ_ENTRY(autofs_mount) am_next;
119 struct autofs_node *am_root;
122 char am_from[MAXPATHLEN];
123 char am_on[MAXPATHLEN];
124 char am_options[MAXPATHLEN];
125 char am_prefix[MAXPATHLEN];
128 struct netexport am_export;
132 struct autofs_request {
133 TAILQ_ENTRY(autofs_request) ar_next;
134 struct autofs_mount *ar_mount;
140 char ar_from[MAXPATHLEN];
141 char ar_path[MAXPATHLEN];
142 char ar_prefix[MAXPATHLEN];
143 char ar_key[MAXPATHLEN];
144 char ar_options[MAXPATHLEN];
145 struct timeout_task ar_task;
146 volatile u_int ar_refcount;
149 struct autofs_softc {
151 struct cdev *sc_cdev;
154 TAILQ_HEAD(, autofs_request) sc_requests;
157 int sc_last_request_id;
160 int autofs_init(struct vfsconf *vfsp);
161 int autofs_uninit(struct vfsconf *vfsp);
162 int autofs_trigger(struct autofs_node *anp, const char *component,
164 bool autofs_cached(struct autofs_node *anp, const char *component,
166 char* autofs_path(struct autofs_node *anp);
167 void autofs_flush(struct autofs_mount *amp);
168 bool autofs_ignore_thread(void);
169 int autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
170 const char *name, int namelen, struct autofs_node **anpp);
171 int autofs_node_find(struct autofs_node *parent,
172 const char *name, int namelen, struct autofs_node **anpp);
173 void autofs_node_delete(struct autofs_node *anp);
174 int autofs_node_vn(struct autofs_node *anp, struct mount *mp,
175 int flags, struct vnode **vpp);
178 autofs_node_cache(struct autofs_node *anp)
180 anp->an_cached = true;
184 autofs_node_uncache(struct autofs_node *anp)
186 anp->an_cached = false;
189 RB_PROTOTYPE(autofs_node_tree, autofs_node, an_link, autofs_node_cmp);
191 #endif /* !AUTOFS_H */