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