autofs.h revision 274236
1/*-
2 * Copyright (c) 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: stable/10/sys/fs/autofs/autofs.h 274236 2014-11-07 15:47:22Z trasz $
30 */
31
32#ifndef AUTOFS_H
33#define	AUTOFS_H
34
35#define VFSTOAUTOFS(mp)    ((struct autofs_mount *)((mp)->mnt_data))
36
37MALLOC_DECLARE(M_AUTOFS);
38
39extern uma_zone_t autofs_request_zone;
40extern uma_zone_t autofs_node_zone;
41
42extern int autofs_debug;
43extern int autofs_mount_on_stat;
44
45#define	AUTOFS_DEBUG(X, ...)						\
46	do {								\
47		if (autofs_debug > 1)					\
48			printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
49	} while (0)
50
51#define	AUTOFS_WARN(X, ...)						\
52	do {								\
53		if (autofs_debug > 0) {					\
54			printf("WARNING: %s: " X "\n",			\
55		    	    __func__, ## __VA_ARGS__);			\
56		}							\
57	} while (0)
58
59#define AUTOFS_SLOCK(X)		sx_slock(&X->am_lock)
60#define AUTOFS_XLOCK(X)		sx_xlock(&X->am_lock)
61#define AUTOFS_SUNLOCK(X)	sx_sunlock(&X->am_lock)
62#define AUTOFS_XUNLOCK(X)	sx_xunlock(&X->am_lock)
63#define AUTOFS_ASSERT_LOCKED(X)		sx_assert(&X->am_lock, SA_LOCKED)
64#define AUTOFS_ASSERT_XLOCKED(X)	sx_assert(&X->am_lock, SA_XLOCKED)
65#define AUTOFS_ASSERT_UNLOCKED(X)	sx_assert(&X->am_lock, SA_UNLOCKED)
66
67struct autofs_node {
68	TAILQ_ENTRY(autofs_node)	an_next;
69	char				*an_name;
70	int				an_fileno;
71	struct autofs_node		*an_parent;
72	TAILQ_HEAD(, autofs_node)	an_children;
73	struct autofs_mount		*an_mount;
74	struct vnode			*an_vnode;
75	struct sx			an_vnode_lock;
76	bool				an_cached;
77	struct callout			an_callout;
78	int				an_retries;
79	struct timespec			an_ctime;
80};
81
82struct autofs_mount {
83	TAILQ_ENTRY(autofs_mount)	am_next;
84	struct autofs_node		*am_root;
85	struct mount			*am_mp;
86	struct sx			am_lock;
87	char				am_from[MAXPATHLEN];
88	char				am_mountpoint[MAXPATHLEN];
89	char				am_options[MAXPATHLEN];
90	char				am_prefix[MAXPATHLEN];
91	int				am_last_fileno;
92};
93
94struct autofs_request {
95	TAILQ_ENTRY(autofs_request)	ar_next;
96	struct autofs_mount		*ar_mount;
97	int				ar_id;
98	bool				ar_done;
99	int				ar_error;
100	bool				ar_in_progress;
101	char				ar_from[MAXPATHLEN];
102	char				ar_path[MAXPATHLEN];
103	char				ar_prefix[MAXPATHLEN];
104	char				ar_key[MAXPATHLEN];
105	char				ar_options[MAXPATHLEN];
106	struct timeout_task		ar_task;
107	volatile u_int			ar_refcount;
108};
109
110struct autofs_softc {
111	device_t			sc_dev;
112	struct cdev			*sc_cdev;
113	struct cv			sc_cv;
114	struct sx			sc_lock;
115	TAILQ_HEAD(, autofs_request)	sc_requests;
116	bool				sc_dev_opened;
117	pid_t				sc_dev_sid;
118	int				sc_last_request_id;
119};
120
121/*
122 * Limits and constants
123 */
124#define AUTOFS_NAMELEN		24
125#define AUTOFS_FSNAMELEN	16	/* equal to MFSNAMELEN */
126#define AUTOFS_DELEN		(8 + AUTOFS_NAMELEN)
127
128int	autofs_init(struct vfsconf *vfsp);
129int	autofs_uninit(struct vfsconf *vfsp);
130int	autofs_trigger(struct autofs_node *anp, const char *component,
131	    int componentlen);
132bool	autofs_cached(struct autofs_node *anp, const char *component,
133	    int componentlen);
134bool	autofs_ignore_thread(const struct thread *td);
135int	autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
136	    const char *name, int namelen, struct autofs_node **anpp);
137int	autofs_node_find(struct autofs_node *parent,
138	    const char *name, int namelen, struct autofs_node **anpp);
139void	autofs_node_delete(struct autofs_node *anp);
140int	autofs_node_vn(struct autofs_node *anp, struct mount *mp,
141	    int flags, struct vnode **vpp);
142
143#endif /* !AUTOFS_H */
144