Home | History | Annotate | Line # | Download | only in autofs
autofs.h revision 1.5
      1  1.5   tkusumi /*	$NetBSD: autofs.h,v 1.5 2023/05/17 06:44:38 tkusumi Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 2017 The NetBSD Foundation, Inc.
      5  1.1  christos  * Copyright (c) 2016 The DragonFly Project
      6  1.1  christos  * Copyright (c) 2014 The FreeBSD Foundation
      7  1.1  christos  * All rights reserved.
      8  1.1  christos  *
      9  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
     10  1.1  christos  * by Tomohiro Kusumi <kusumi.tomohiro (at) gmail.com>.
     11  1.1  christos  *
     12  1.1  christos  * This software was developed by Edward Tomasz Napierala under sponsorship
     13  1.1  christos  * from the FreeBSD Foundation.
     14  1.1  christos  *
     15  1.1  christos  * Redistribution and use in source and binary forms, with or without
     16  1.1  christos  * modification, are permitted provided that the following conditions
     17  1.1  christos  * are met:
     18  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     19  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     20  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     21  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     22  1.1  christos  *    documentation and/or other materials provided with the distribution.
     23  1.1  christos  *
     24  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     28  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  christos  * SUCH DAMAGE.
     35  1.1  christos  *
     36  1.1  christos  * $FreeBSD$
     37  1.1  christos  */
     38  1.1  christos 
     39  1.1  christos #ifndef _SYS_FS_AUTOFS_AUTOFS_H_
     40  1.1  christos #define	_SYS_FS_AUTOFS_AUTOFS_H_
     41  1.1  christos 
     42  1.1  christos #include <sys/param.h>
     43  1.1  christos #include <sys/kernel.h>
     44  1.1  christos #include <sys/module.h>
     45  1.1  christos #include <sys/types.h>
     46  1.1  christos #include <sys/systm.h>
     47  1.1  christos #include <sys/kmem.h>
     48  1.1  christos #include <sys/tree.h>
     49  1.1  christos #include <sys/mutex.h>
     50  1.1  christos #include <sys/condvar.h>
     51  1.1  christos #include <sys/mount.h>
     52  1.1  christos #include <sys/vnode.h>
     53  1.1  christos #include <sys/timespec.h>
     54  1.1  christos #include <sys/callout.h>
     55  1.1  christos #include <sys/workqueue.h>
     56  1.1  christos #include <sys/conf.h>
     57  1.1  christos #include <sys/proc.h>
     58  1.1  christos 
     59  1.1  christos #include "autofs_ioctl.h"
     60  1.1  christos 
     61  1.1  christos #define AUTOFS_ROOTINO	((ino_t)1)
     62  1.1  christos #define VFSTOAUTOFS(mp)	((struct autofs_mount *)((mp)->mnt_data))
     63  1.1  christos #define VTOI(vp)	((struct autofs_node *)((vp)->v_data))
     64  1.1  christos 
     65  1.1  christos extern int (**autofs_vnodeop_p)(void *);
     66  1.1  christos extern const struct vnodeopv_desc autofs_vnodeop_opv_desc;
     67  1.1  christos 
     68  1.1  christos extern struct cdevsw autofs_ops;
     69  1.1  christos 
     70  1.1  christos extern struct pool autofs_request_pool;
     71  1.1  christos extern struct pool autofs_node_pool;
     72  1.1  christos extern struct autofs_softc *autofs_softc;
     73  1.1  christos extern struct workqueue	*autofs_tmo_wq;
     74  1.1  christos 
     75  1.1  christos extern int autofs_debug;
     76  1.1  christos extern int autofs_mount_on_stat;
     77  1.1  christos extern int autofs_timeout;
     78  1.1  christos extern int autofs_cache;
     79  1.1  christos extern int autofs_retry_attempts;
     80  1.1  christos extern int autofs_retry_delay;
     81  1.1  christos extern int autofs_interruptible;
     82  1.1  christos 
     83  1.1  christos #define	AUTOFS_DEBUG(X, ...)				\
     84  1.1  christos 	do {						\
     85  1.1  christos 		if (autofs_debug > 1)			\
     86  1.1  christos 			printf("%s: " X "\n",		\
     87  1.1  christos 			    __func__, ## __VA_ARGS__);	\
     88  1.1  christos 	} while (0)
     89  1.1  christos 
     90  1.1  christos #define	AUTOFS_WARN(X, ...)				\
     91  1.1  christos 	do {						\
     92  1.1  christos 		if (autofs_debug > 0) {			\
     93  1.1  christos 			printf("WARNING: %s: " X "\n",	\
     94  1.1  christos 			    __func__, ## __VA_ARGS__);	\
     95  1.1  christos 		}					\
     96  1.1  christos 	} while (0)
     97  1.1  christos 
     98  1.1  christos struct autofs_node {
     99  1.1  christos 	RB_ENTRY(autofs_node)		an_entry;
    100  1.1  christos 	char				*an_name;
    101  1.1  christos 	ino_t				an_ino;
    102  1.1  christos 	struct autofs_node		*an_parent;
    103  1.1  christos 	RB_HEAD(autofs_node_tree,
    104  1.1  christos 	    autofs_node)		an_children;
    105  1.1  christos 	struct autofs_mount		*an_mount;
    106  1.1  christos 	struct vnode			*an_vnode;
    107  1.1  christos 	bool				an_cached;
    108  1.1  christos 	bool				an_wildcards;
    109  1.1  christos 	struct callout			an_callout;
    110  1.1  christos 	int				an_retries;
    111  1.1  christos 	struct timespec			an_ctime;
    112  1.1  christos };
    113  1.1  christos 
    114  1.1  christos struct autofs_mount {
    115  1.1  christos 	struct autofs_node		*am_root;
    116  1.1  christos 	struct mount			*am_mp;
    117  1.1  christos 	kmutex_t			am_lock;
    118  1.1  christos 	char				am_from[AUTOFS_MAXPATHLEN];
    119  1.1  christos 	char				am_on[AUTOFS_MAXPATHLEN];
    120  1.1  christos 	char				am_options[AUTOFS_MAXPATHLEN];
    121  1.1  christos 	char				am_prefix[AUTOFS_MAXPATHLEN];
    122  1.1  christos 	ino_t				am_last_ino;
    123  1.1  christos };
    124  1.1  christos 
    125  1.1  christos struct autofs_request {
    126  1.1  christos 	struct work			ar_wk; /* must be first */
    127  1.1  christos 	TAILQ_ENTRY(autofs_request)	ar_next;
    128  1.1  christos 	struct autofs_mount		*ar_mount;
    129  1.1  christos 	int				ar_id;
    130  1.1  christos 	bool				ar_done;
    131  1.1  christos 	int				ar_error;
    132  1.1  christos 	bool				ar_wildcards;
    133  1.1  christos 	bool				ar_in_progress;
    134  1.1  christos 	char				ar_from[AUTOFS_MAXPATHLEN];
    135  1.1  christos 	char				ar_path[AUTOFS_MAXPATHLEN];
    136  1.1  christos 	char				ar_prefix[AUTOFS_MAXPATHLEN];
    137  1.1  christos 	char				ar_key[AUTOFS_MAXPATHLEN];
    138  1.1  christos 	char				ar_options[AUTOFS_MAXPATHLEN];
    139  1.1  christos 	struct callout			ar_callout;
    140  1.3   tkusumi 	volatile unsigned int		ar_refcount;
    141  1.1  christos };
    142  1.1  christos 
    143  1.1  christos struct autofs_softc {
    144  1.1  christos 	kcondvar_t			sc_cv;
    145  1.1  christos 	kmutex_t			sc_lock;
    146  1.1  christos 	TAILQ_HEAD(, autofs_request)	sc_requests;
    147  1.1  christos 	bool				sc_dev_opened;
    148  1.1  christos 	pid_t				sc_dev_sid;
    149  1.1  christos 	int				sc_last_request_id;
    150  1.1  christos };
    151  1.1  christos 
    152  1.1  christos int	autofs_trigger(struct autofs_node *anp, const char *component,
    153  1.1  christos 	    int componentlen);
    154  1.1  christos bool	autofs_cached(struct autofs_node *anp, const char *component,
    155  1.1  christos 	    int componentlen);
    156  1.1  christos void	autofs_flush(struct autofs_mount *amp);
    157  1.1  christos bool	autofs_ignore_thread(void);
    158  1.1  christos void	autofs_timeout_wq(struct work *wk, void *arg);
    159  1.1  christos int	autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp,
    160  1.1  christos 	    const char *name, int namelen, struct autofs_node **anpp);
    161  1.1  christos int	autofs_node_find(struct autofs_node *parent,
    162  1.1  christos 	    const char *name, int namelen, struct autofs_node **anpp);
    163  1.1  christos void	autofs_node_delete(struct autofs_node *anp);
    164  1.1  christos 
    165  1.1  christos static __inline void
    166  1.1  christos autofs_node_cache(struct autofs_node *anp)
    167  1.1  christos {
    168  1.1  christos 
    169  1.1  christos 	anp->an_cached = true;
    170  1.1  christos }
    171  1.1  christos 
    172  1.1  christos static __inline void
    173  1.1  christos autofs_node_uncache(struct autofs_node *anp)
    174  1.1  christos {
    175  1.1  christos 
    176  1.1  christos 	anp->an_cached = false;
    177  1.1  christos }
    178  1.1  christos 
    179  1.1  christos static __inline char *
    180  1.1  christos autofs_strndup(const char *name, int nlen, km_flag_t fl)
    181  1.1  christos {
    182  1.1  christos 	return nlen > 0 ? kmem_strndup(name, nlen, fl) : kmem_strdup(name, fl);
    183  1.1  christos }
    184  1.1  christos 
    185  1.1  christos RB_PROTOTYPE(autofs_node_tree, autofs_node, an_entry, autofs_node_cmp);
    186  1.1  christos 
    187  1.1  christos #endif /* !_SYS_FS_AUTOFS_AUTOFS_H_ */
    188