kernel - Fix races created by a comedy of circumstansces (3)
[dragonfly.git] / sys / vfs / autofs / autofs.h
blob0b9562b8f643b84673b4c6c73ac6e59811ef33b2
1 /*-
2 * Copyright (c) 2016 The DragonFly Project
3 * Copyright (c) 2014 The FreeBSD Foundation
4 * All rights reserved.
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
11 * are met:
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
28 * SUCH DAMAGE.
30 * $FreeBSD$
33 #ifndef AUTOFS_H
34 #define AUTOFS_H
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/types.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/objcache.h>
42 #include <sys/tree.h>
43 #include <sys/lock.h>
44 #include <sys/condvar.h>
45 #include <sys/mount.h>
46 #include <sys/vnode.h>
47 #include <sys/timespec.h>
48 #include <sys/callout.h>
49 #include <sys/taskqueue.h>
50 #include <sys/conf.h>
51 #include <sys/bus.h>
53 #define AUTOFS_ROOTINO ((ino_t)1)
54 #define VFSTOAUTOFS(mp) ((struct autofs_mount *)((mp)->mnt_data))
55 #define VTOI(vp) ((struct autofs_node *)((vp)->v_data))
57 MALLOC_DECLARE(M_AUTOFS);
59 extern struct objcache *autofs_request_objcache;
60 extern struct objcache *autofs_node_objcache;
62 extern struct vop_ops autofs_vnode_vops;
64 extern int autofs_debug;
65 extern int autofs_mount_on_stat;
68 * APRINTF is only for debugging.
70 #define APRINTF(A, B, ...) \
71 kprintf(A " %s(%s): " B, __func__, curthread->td_comm, ## __VA_ARGS__)
73 #define AUTOFS_DEBUG(X, ...) \
74 do { \
75 if (autofs_debug > 1) \
76 kprintf("%s: " X "\n", \
77 __func__, ## __VA_ARGS__); \
78 } while (0)
80 #define AUTOFS_WARN(X, ...) \
81 do { \
82 if (autofs_debug > 0) { \
83 kprintf("WARNING: %s: " X "\n", \
84 __func__, ## __VA_ARGS__); \
85 } \
86 } while (0)
88 #define AUTOFS_FATAL(X, ...) \
89 kprintf("FATAL: %s: " X "\n", __func__, ## __VA_ARGS__)
91 #define AUTOFS_LOCK_STATUS(lock) (lockstatus((lock), curthread))
92 #define AUTOFS_ASSERT_LOCKED(X) \
93 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) & (LK_EXCLUSIVE | LK_SHARED))
94 #define AUTOFS_ASSERT_XLOCKED(X) \
95 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) == LK_EXCLUSIVE)
96 #define AUTOFS_ASSERT_UNLOCKED(X) \
97 KKASSERT(AUTOFS_LOCK_STATUS(&(X)->am_lock) == 0)
99 struct autofs_node {
100 RB_ENTRY(autofs_node) an_link;
101 char *an_name;
102 ino_t an_ino;
103 struct autofs_node *an_parent;
104 RB_HEAD(autofs_node_tree,
105 autofs_node) an_children;
106 struct autofs_mount *an_mount;
107 struct vnode *an_vnode;
108 struct lock an_vnode_lock;
109 bool an_cached;
110 bool an_wildcards;
111 struct callout an_callout;
112 int an_retries;
113 struct timespec an_ctime;
116 struct autofs_mount {
117 TAILQ_ENTRY(autofs_mount) am_next;
118 struct autofs_node *am_root;
119 struct mount *am_mp;
120 struct lock am_lock;
121 char am_from[MAXPATHLEN];
122 char am_on[MAXPATHLEN];
123 char am_options[MAXPATHLEN];
124 char am_prefix[MAXPATHLEN];
125 ino_t am_last_ino;
126 #if 0
127 struct netexport am_export;
128 #endif
131 struct autofs_request {
132 TAILQ_ENTRY(autofs_request) ar_next;
133 struct autofs_mount *ar_mount;
134 int ar_id;
135 bool ar_done;
136 int ar_error;
137 bool ar_wildcards;
138 bool ar_in_progress;
139 char ar_from[MAXPATHLEN];
140 char ar_path[MAXPATHLEN];
141 char ar_prefix[MAXPATHLEN];
142 char ar_key[MAXPATHLEN];
143 char ar_options[MAXPATHLEN];
144 struct timeout_task ar_task;
145 volatile u_int ar_refcount;
148 struct autofs_softc {
149 device_t sc_dev;
150 struct cdev *sc_cdev;
151 struct cv sc_cv;
152 struct lock sc_lock;
153 TAILQ_HEAD(, autofs_request) sc_requests;
154 bool sc_dev_opened;
155 pid_t sc_dev_sid;
156 int sc_last_request_id;
159 int autofs_init(struct vfsconf *vfsp);
160 int autofs_uninit(struct vfsconf *vfsp);
161 int autofs_trigger(struct autofs_node *anp, const char *component,
162 int componentlen);
163 bool autofs_cached(struct autofs_node *anp, const char *component,
164 int componentlen);
165 char* autofs_path(struct autofs_node *anp);
166 void autofs_flush(struct autofs_mount *amp);
167 bool autofs_ignore_thread(void);
168 int autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
169 const char *name, int namelen, struct autofs_node **anpp);
170 int autofs_node_find(struct autofs_node *parent,
171 const char *name, int namelen, struct autofs_node **anpp);
172 void autofs_node_delete(struct autofs_node *anp);
173 int autofs_node_vn(struct autofs_node *anp, struct mount *mp,
174 int flags, struct vnode **vpp);
176 static __inline void
177 autofs_node_cache(struct autofs_node *anp)
179 anp->an_cached = true;
182 static __inline void
183 autofs_node_uncache(struct autofs_node *anp)
185 anp->an_cached = false;
188 RB_PROTOTYPE(autofs_node_tree, autofs_node, an_link, autofs_node_cmp);
190 #endif /* !AUTOFS_H */