xref: /dflybsd-src/sys/vfs/autofs/autofs.h (revision add630f0972670974657514385cc9a70e241cdff)
1e2950f41STomohiro Kusumi /*-
2e2950f41STomohiro Kusumi  * Copyright (c) 2016 The DragonFly Project
3e2950f41STomohiro Kusumi  * Copyright (c) 2014 The FreeBSD Foundation
4e2950f41STomohiro Kusumi  * All rights reserved.
5e2950f41STomohiro Kusumi  *
6e2950f41STomohiro Kusumi  * This software was developed by Edward Tomasz Napierala under sponsorship
7e2950f41STomohiro Kusumi  * from the FreeBSD Foundation.
8e2950f41STomohiro Kusumi  *
9e2950f41STomohiro Kusumi  * Redistribution and use in source and binary forms, with or without
10e2950f41STomohiro Kusumi  * modification, are permitted provided that the following conditions
11e2950f41STomohiro Kusumi  * are met:
12e2950f41STomohiro Kusumi  * 1. Redistributions of source code must retain the above copyright
13e2950f41STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer.
14e2950f41STomohiro Kusumi  * 2. Redistributions in binary form must reproduce the above copyright
15e2950f41STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer in the
16e2950f41STomohiro Kusumi  *    documentation and/or other materials provided with the distribution.
17e2950f41STomohiro Kusumi  *
18e2950f41STomohiro Kusumi  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19e2950f41STomohiro Kusumi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20e2950f41STomohiro Kusumi  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21e2950f41STomohiro Kusumi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22e2950f41STomohiro Kusumi  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23e2950f41STomohiro Kusumi  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24e2950f41STomohiro Kusumi  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25e2950f41STomohiro Kusumi  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26e2950f41STomohiro Kusumi  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27e2950f41STomohiro Kusumi  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28e2950f41STomohiro Kusumi  * SUCH DAMAGE.
29e2950f41STomohiro Kusumi  *
30e2950f41STomohiro Kusumi  * $FreeBSD$
31e2950f41STomohiro Kusumi  */
32e2950f41STomohiro Kusumi 
33e2950f41STomohiro Kusumi #ifndef AUTOFS_H
34e2950f41STomohiro Kusumi #define	AUTOFS_H
35e2950f41STomohiro Kusumi 
36e2950f41STomohiro Kusumi #include <sys/kernel.h>
37e2950f41STomohiro Kusumi #include <sys/module.h>
38e2950f41STomohiro Kusumi #include <sys/types.h>
39e2950f41STomohiro Kusumi #include <sys/systm.h>
40e2950f41STomohiro Kusumi #include <sys/malloc.h>
41e2950f41STomohiro Kusumi #include <sys/objcache.h>
42e2950f41STomohiro Kusumi #include <sys/tree.h>
43e2950f41STomohiro Kusumi #include <sys/lock.h>
44bfccbb76STomohiro Kusumi #include <sys/mutex2.h>
45e2950f41STomohiro Kusumi #include <sys/condvar.h>
46e2950f41STomohiro Kusumi #include <sys/mount.h>
47e2950f41STomohiro Kusumi #include <sys/vnode.h>
48e2950f41STomohiro Kusumi #include <sys/timespec.h>
49e2950f41STomohiro Kusumi #include <sys/callout.h>
50e2950f41STomohiro Kusumi #include <sys/taskqueue.h>
51e2950f41STomohiro Kusumi #include <sys/conf.h>
52e2950f41STomohiro Kusumi #include <sys/bus.h>
53e2950f41STomohiro Kusumi 
54e2950f41STomohiro Kusumi #define AUTOFS_ROOTINO	((ino_t)1)
55e2950f41STomohiro Kusumi #define VFSTOAUTOFS(mp)	((struct autofs_mount *)((mp)->mnt_data))
56e2950f41STomohiro Kusumi #define VTOI(vp)	((struct autofs_node *)((vp)->v_data))
57e2950f41STomohiro Kusumi 
58e2950f41STomohiro Kusumi MALLOC_DECLARE(M_AUTOFS);
59e2950f41STomohiro Kusumi 
60e2950f41STomohiro Kusumi extern struct objcache *autofs_request_objcache;
61e2950f41STomohiro Kusumi extern struct objcache *autofs_node_objcache;
62*add630f0STomohiro Kusumi extern struct autofs_softc *autofs_softc;
63*add630f0STomohiro Kusumi extern struct dev_ops autofs_ops;
64e2950f41STomohiro Kusumi 
65e2950f41STomohiro Kusumi extern struct vop_ops autofs_vnode_vops;
66e2950f41STomohiro Kusumi 
67e2950f41STomohiro Kusumi extern int autofs_debug;
68e2950f41STomohiro Kusumi extern int autofs_mount_on_stat;
69e2950f41STomohiro Kusumi 
70e2950f41STomohiro Kusumi #define	AUTOFS_DEBUG(X, ...)				\
71e2950f41STomohiro Kusumi 	do {						\
72e2950f41STomohiro Kusumi 		if (autofs_debug > 1)			\
73e2950f41STomohiro Kusumi 			kprintf("%s: " X "\n",		\
74e2950f41STomohiro Kusumi 			    __func__, ## __VA_ARGS__);	\
75e2950f41STomohiro Kusumi 	} while (0)
76e2950f41STomohiro Kusumi 
77e2950f41STomohiro Kusumi #define	AUTOFS_WARN(X, ...)				\
78e2950f41STomohiro Kusumi 	do {						\
79e2950f41STomohiro Kusumi 		if (autofs_debug > 0) {			\
80e2950f41STomohiro Kusumi 			kprintf("WARNING: %s: " X "\n",	\
81e2950f41STomohiro Kusumi 			    __func__, ## __VA_ARGS__);	\
82e2950f41STomohiro Kusumi 		}					\
83e2950f41STomohiro Kusumi 	} while (0)
84e2950f41STomohiro Kusumi 
85e2950f41STomohiro Kusumi #define	AUTOFS_FATAL(X, ...)				\
86e2950f41STomohiro Kusumi 	kprintf("FATAL: %s: " X "\n", __func__, ## __VA_ARGS__)
87e2950f41STomohiro Kusumi 
88caaec4e3STomohiro Kusumi /*
89caaec4e3STomohiro Kusumi  * APRINTF is only for debugging.
90caaec4e3STomohiro Kusumi  */
91caaec4e3STomohiro Kusumi #define APRINTF(X, ...)					\
92caaec4e3STomohiro Kusumi 	kprintf("### %s(%s): " X,			\
93caaec4e3STomohiro Kusumi 	    __func__, curproc->p_comm, ## __VA_ARGS__)
94caaec4e3STomohiro Kusumi 
95e2950f41STomohiro Kusumi struct autofs_node {
96e2950f41STomohiro Kusumi 	RB_ENTRY(autofs_node)		an_link;
97e2950f41STomohiro Kusumi 	char				*an_name;
98e2950f41STomohiro Kusumi 	ino_t				an_ino;
99e2950f41STomohiro Kusumi 	struct autofs_node		*an_parent;
100e2950f41STomohiro Kusumi 	RB_HEAD(autofs_node_tree,
101e2950f41STomohiro Kusumi 	    autofs_node)		an_children;
102e2950f41STomohiro Kusumi 	struct autofs_mount		*an_mount;
103e2950f41STomohiro Kusumi 	struct vnode			*an_vnode;
104bfccbb76STomohiro Kusumi 	mtx_t				an_vnode_lock;
105e2950f41STomohiro Kusumi 	bool				an_cached;
106e2950f41STomohiro Kusumi 	bool				an_wildcards;
107e2950f41STomohiro Kusumi 	struct callout			an_callout;
108e2950f41STomohiro Kusumi 	int				an_retries;
109e2950f41STomohiro Kusumi 	struct timespec			an_ctime;
110e2950f41STomohiro Kusumi };
111e2950f41STomohiro Kusumi 
112e2950f41STomohiro Kusumi struct autofs_mount {
113e2950f41STomohiro Kusumi 	TAILQ_ENTRY(autofs_mount)	am_next;
114e2950f41STomohiro Kusumi 	struct autofs_node		*am_root;
115e2950f41STomohiro Kusumi 	struct mount			*am_mp;
116bc6139d4STomohiro Kusumi 	mtx_t				am_lock;
117e2950f41STomohiro Kusumi 	char				am_from[MAXPATHLEN];
118e2950f41STomohiro Kusumi 	char				am_on[MAXPATHLEN];
119e2950f41STomohiro Kusumi 	char				am_options[MAXPATHLEN];
120e2950f41STomohiro Kusumi 	char				am_prefix[MAXPATHLEN];
121e2950f41STomohiro Kusumi 	ino_t				am_last_ino;
122e2950f41STomohiro Kusumi };
123e2950f41STomohiro Kusumi 
124e2950f41STomohiro Kusumi struct autofs_request {
125e2950f41STomohiro Kusumi 	TAILQ_ENTRY(autofs_request)	ar_next;
126e2950f41STomohiro Kusumi 	struct autofs_mount		*ar_mount;
127e2950f41STomohiro Kusumi 	int				ar_id;
128e2950f41STomohiro Kusumi 	bool				ar_done;
129e2950f41STomohiro Kusumi 	int				ar_error;
130e2950f41STomohiro Kusumi 	bool				ar_wildcards;
131e2950f41STomohiro Kusumi 	bool				ar_in_progress;
132e2950f41STomohiro Kusumi 	char				ar_from[MAXPATHLEN];
133e2950f41STomohiro Kusumi 	char				ar_path[MAXPATHLEN];
134e2950f41STomohiro Kusumi 	char				ar_prefix[MAXPATHLEN];
135e2950f41STomohiro Kusumi 	char				ar_key[MAXPATHLEN];
136e2950f41STomohiro Kusumi 	char				ar_options[MAXPATHLEN];
137e2950f41STomohiro Kusumi 	struct timeout_task		ar_task;
138e2950f41STomohiro Kusumi 	volatile u_int			ar_refcount;
139e2950f41STomohiro Kusumi };
140e2950f41STomohiro Kusumi 
141e2950f41STomohiro Kusumi struct autofs_softc {
142e2950f41STomohiro Kusumi 	device_t			sc_dev;
143e2950f41STomohiro Kusumi 	struct cdev			*sc_cdev;
144e2950f41STomohiro Kusumi 	struct cv			sc_cv;
145e2950f41STomohiro Kusumi 	struct lock			sc_lock;
146e2950f41STomohiro Kusumi 	TAILQ_HEAD(, autofs_request)	sc_requests;
147e2950f41STomohiro Kusumi 	bool				sc_dev_opened;
148e2950f41STomohiro Kusumi 	pid_t				sc_dev_sid;
149e2950f41STomohiro Kusumi 	int				sc_last_request_id;
150e2950f41STomohiro Kusumi };
151e2950f41STomohiro Kusumi 
152e2950f41STomohiro Kusumi int	autofs_trigger(struct autofs_node *anp, const char *component,
153e2950f41STomohiro Kusumi 	    int componentlen);
154e2950f41STomohiro Kusumi bool	autofs_cached(struct autofs_node *anp, const char *component,
155e2950f41STomohiro Kusumi 	    int componentlen);
156e2950f41STomohiro Kusumi char*	autofs_path(struct autofs_node *anp);
157e2950f41STomohiro Kusumi void	autofs_flush(struct autofs_mount *amp);
158e2950f41STomohiro Kusumi bool	autofs_ignore_thread(void);
159e2950f41STomohiro Kusumi int	autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
160e2950f41STomohiro Kusumi 	    const char *name, int namelen, struct autofs_node **anpp);
161e2950f41STomohiro Kusumi int	autofs_node_find(struct autofs_node *parent,
162e2950f41STomohiro Kusumi 	    const char *name, int namelen, struct autofs_node **anpp);
163e2950f41STomohiro Kusumi void	autofs_node_delete(struct autofs_node *anp);
164e2950f41STomohiro Kusumi int	autofs_node_vn(struct autofs_node *anp, struct mount *mp,
165e2950f41STomohiro Kusumi 	    int flags, struct vnode **vpp);
166e2950f41STomohiro Kusumi 
167e2950f41STomohiro Kusumi static __inline void
168e2950f41STomohiro Kusumi autofs_node_cache(struct autofs_node *anp)
169e2950f41STomohiro Kusumi {
170e2950f41STomohiro Kusumi 	anp->an_cached = true;
171e2950f41STomohiro Kusumi }
172e2950f41STomohiro Kusumi 
173e2950f41STomohiro Kusumi static __inline void
174e2950f41STomohiro Kusumi autofs_node_uncache(struct autofs_node *anp)
175e2950f41STomohiro Kusumi {
176e2950f41STomohiro Kusumi 	anp->an_cached = false;
177e2950f41STomohiro Kusumi }
178e2950f41STomohiro Kusumi 
179e2950f41STomohiro Kusumi RB_PROTOTYPE(autofs_node_tree, autofs_node, an_link, autofs_node_cmp);
180e2950f41STomohiro Kusumi 
181e2950f41STomohiro Kusumi #endif /* !AUTOFS_H */
182