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