1270096Strasz/*-
2332596Strasz * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3332596Strasz *
4270096Strasz * Copyright (c) 2014 The FreeBSD Foundation
5270096Strasz * All rights reserved.
6270096Strasz *
7270096Strasz * This software was developed by Edward Tomasz Napierala under sponsorship
8270096Strasz * from the FreeBSD Foundation.
9270096Strasz *
10270096Strasz * Redistribution and use in source and binary forms, with or without
11270096Strasz * modification, are permitted provided that the following conditions
12270096Strasz * are met:
13270096Strasz * 1. Redistributions of source code must retain the above copyright
14270096Strasz *    notice, this list of conditions and the following disclaimer.
15270096Strasz * 2. Redistributions in binary form must reproduce the above copyright
16270096Strasz *    notice, this list of conditions and the following disclaimer in the
17270096Strasz *    documentation and/or other materials provided with the distribution.
18270096Strasz *
19270096Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20270096Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21270096Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22270096Strasz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23270096Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24270096Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25270096Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26270096Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27270096Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28270096Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29270096Strasz * SUCH DAMAGE.
30270096Strasz *
31270096Strasz * $FreeBSD: stable/11/sys/fs/autofs/autofs.h 332596 2018-04-16 16:15:31Z trasz $
32270096Strasz */
33270096Strasz
34270096Strasz#ifndef AUTOFS_H
35270096Strasz#define	AUTOFS_H
36270096Strasz
37270096Strasz#define VFSTOAUTOFS(mp)    ((struct autofs_mount *)((mp)->mnt_data))
38270096Strasz
39270096StraszMALLOC_DECLARE(M_AUTOFS);
40270096Strasz
41270096Straszextern uma_zone_t autofs_request_zone;
42270096Straszextern uma_zone_t autofs_node_zone;
43270096Strasz
44270096Straszextern int autofs_debug;
45270096Straszextern int autofs_mount_on_stat;
46270096Strasz
47272471Strasz#define	AUTOFS_DEBUG(X, ...)						\
48272471Strasz	do {								\
49272471Strasz		if (autofs_debug > 1)					\
50272471Strasz			printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
51270096Strasz	} while (0)
52270096Strasz
53272471Strasz#define	AUTOFS_WARN(X, ...)						\
54272471Strasz	do {								\
55272471Strasz		if (autofs_debug > 0) {					\
56272471Strasz			printf("WARNING: %s: " X "\n",			\
57272471Strasz		    	    __func__, ## __VA_ARGS__);			\
58272471Strasz		}							\
59270096Strasz	} while (0)
60270096Strasz
61272470Strasz#define AUTOFS_SLOCK(X)		sx_slock(&X->am_lock)
62272470Strasz#define AUTOFS_XLOCK(X)		sx_xlock(&X->am_lock)
63272470Strasz#define AUTOFS_SUNLOCK(X)	sx_sunlock(&X->am_lock)
64272470Strasz#define AUTOFS_XUNLOCK(X)	sx_xunlock(&X->am_lock)
65272470Strasz#define AUTOFS_ASSERT_LOCKED(X)		sx_assert(&X->am_lock, SA_LOCKED)
66272470Strasz#define AUTOFS_ASSERT_XLOCKED(X)	sx_assert(&X->am_lock, SA_XLOCKED)
67270096Strasz#define AUTOFS_ASSERT_UNLOCKED(X)	sx_assert(&X->am_lock, SA_UNLOCKED)
68270096Strasz
69270096Straszstruct autofs_node {
70297236Strasz	RB_ENTRY(autofs_node)		an_link;
71270096Strasz	char				*an_name;
72270096Strasz	int				an_fileno;
73270096Strasz	struct autofs_node		*an_parent;
74297236Strasz	RB_HEAD(autofs_node_tree,
75297236Strasz	    autofs_node)		an_children;
76270096Strasz	struct autofs_mount		*an_mount;
77270096Strasz	struct vnode			*an_vnode;
78270096Strasz	struct sx			an_vnode_lock;
79270096Strasz	bool				an_cached;
80273127Strasz	bool				an_wildcards;
81270096Strasz	struct callout			an_callout;
82270096Strasz	int				an_retries;
83270096Strasz	struct timespec			an_ctime;
84270096Strasz};
85270096Strasz
86270096Straszstruct autofs_mount {
87270096Strasz	TAILQ_ENTRY(autofs_mount)	am_next;
88270096Strasz	struct autofs_node		*am_root;
89270096Strasz	struct mount			*am_mp;
90270096Strasz	struct sx			am_lock;
91270096Strasz	char				am_from[MAXPATHLEN];
92270096Strasz	char				am_mountpoint[MAXPATHLEN];
93270096Strasz	char				am_options[MAXPATHLEN];
94270096Strasz	char				am_prefix[MAXPATHLEN];
95270096Strasz	int				am_last_fileno;
96270096Strasz};
97270096Strasz
98270096Straszstruct autofs_request {
99270096Strasz	TAILQ_ENTRY(autofs_request)	ar_next;
100270096Strasz	struct autofs_mount		*ar_mount;
101270096Strasz	int				ar_id;
102270096Strasz	bool				ar_done;
103270096Strasz	int				ar_error;
104273127Strasz	bool				ar_wildcards;
105270096Strasz	bool				ar_in_progress;
106270096Strasz	char				ar_from[MAXPATHLEN];
107270096Strasz	char				ar_path[MAXPATHLEN];
108270096Strasz	char				ar_prefix[MAXPATHLEN];
109270096Strasz	char				ar_key[MAXPATHLEN];
110270096Strasz	char				ar_options[MAXPATHLEN];
111272403Strasz	struct timeout_task		ar_task;
112270096Strasz	volatile u_int			ar_refcount;
113270096Strasz};
114270096Strasz
115270096Straszstruct autofs_softc {
116270096Strasz	device_t			sc_dev;
117270096Strasz	struct cdev			*sc_cdev;
118270096Strasz	struct cv			sc_cv;
119270096Strasz	struct sx			sc_lock;
120270096Strasz	TAILQ_HEAD(, autofs_request)	sc_requests;
121270096Strasz	bool				sc_dev_opened;
122270096Strasz	pid_t				sc_dev_sid;
123270096Strasz	int				sc_last_request_id;
124270096Strasz};
125270096Strasz
126270096Straszint	autofs_init(struct vfsconf *vfsp);
127270096Straszint	autofs_uninit(struct vfsconf *vfsp);
128270096Straszint	autofs_trigger(struct autofs_node *anp, const char *component,
129270096Strasz	    int componentlen);
130270096Straszbool	autofs_cached(struct autofs_node *anp, const char *component,
131270096Strasz	    int componentlen);
132274859Straszvoid	autofs_flush(struct autofs_mount *amp);
133270096Straszbool	autofs_ignore_thread(const struct thread *td);
134270096Straszint	autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
135270096Strasz	    const char *name, int namelen, struct autofs_node **anpp);
136270096Straszint	autofs_node_find(struct autofs_node *parent,
137270096Strasz	    const char *name, int namelen, struct autofs_node **anpp);
138270096Straszvoid	autofs_node_delete(struct autofs_node *anp);
139270096Straszint	autofs_node_vn(struct autofs_node *anp, struct mount *mp,
140272512Strasz	    int flags, struct vnode **vpp);
141270096Strasz
142297236StraszRB_PROTOTYPE(autofs_node_tree, autofs_node, an_link, autofs_node_cmp);
143297236Strasz
144270096Strasz#endif /* !AUTOFS_H */
145