1 /*- 2 * Copyright (c) 2016 Tomohiro Kusumi <kusumi.tomohiro@gmail.com> 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 MALLOC_DECLARE(M_AUTOFS); 58 59 extern struct objcache *autofs_request_objcache; 60 extern struct objcache *autofs_node_objcache; 61 extern struct autofs_softc *autofs_softc; 62 extern struct dev_ops autofs_ops; 63 64 extern struct vop_ops autofs_vnode_vops; 65 66 extern int autofs_debug; 67 //extern int autofs_mount_on_stat; 68 69 #define AUTOFS_DEBUG(X, ...) \ 70 do { \ 71 if (autofs_debug > 1) \ 72 kprintf("%s: " X "\n", \ 73 __func__, ## __VA_ARGS__); \ 74 } while (0) 75 76 #define AUTOFS_WARN(X, ...) \ 77 do { \ 78 if (autofs_debug > 0) { \ 79 kprintf("WARNING: %s: " X "\n", \ 80 __func__, ## __VA_ARGS__); \ 81 } \ 82 } while (0) 83 84 /* 85 * APRINTF is only for debugging. 86 */ 87 #define APRINTF(X, ...) \ 88 kprintf("### %s(%s): " X, \ 89 __func__, curproc->p_comm, ## __VA_ARGS__) 90 91 struct autofs_node { 92 RB_ENTRY(autofs_node) an_link; 93 char *an_name; 94 ino_t an_ino; 95 struct autofs_node *an_parent; 96 RB_HEAD(autofs_node_tree, 97 autofs_node) an_children; 98 struct autofs_mount *an_mount; 99 struct vnode *an_vnode; 100 mtx_t an_vnode_lock; 101 bool an_cached; 102 bool an_wildcards; 103 struct callout an_callout; 104 int an_retries; 105 struct timespec an_ctime; 106 }; 107 108 struct autofs_mount { 109 struct autofs_node *am_root; 110 mtx_t am_lock; 111 char am_from[MAXPATHLEN]; 112 char am_on[MAXPATHLEN]; 113 char am_options[MAXPATHLEN]; 114 char am_prefix[MAXPATHLEN]; 115 ino_t am_last_ino; 116 }; 117 118 struct autofs_request { 119 TAILQ_ENTRY(autofs_request) ar_next; 120 struct autofs_mount *ar_mount; 121 int ar_id; 122 bool ar_done; 123 int ar_error; 124 bool ar_wildcards; 125 bool ar_in_progress; 126 char ar_from[MAXPATHLEN]; 127 char ar_path[MAXPATHLEN]; 128 char ar_prefix[MAXPATHLEN]; 129 char ar_key[MAXPATHLEN]; 130 char ar_options[MAXPATHLEN]; 131 struct timeout_task ar_task; 132 volatile unsigned int ar_refcount; 133 }; 134 135 struct autofs_softc { 136 struct cdev *sc_cdev; 137 struct cv sc_cv; 138 struct mtx sc_lock; 139 TAILQ_HEAD(, autofs_request) sc_requests; 140 bool sc_dev_opened; 141 pid_t sc_dev_sid; 142 int sc_last_request_id; 143 }; 144 145 int autofs_trigger(struct autofs_node *anp, const char *component, 146 int componentlen); 147 bool autofs_cached(struct autofs_node *anp, const char *component, 148 int componentlen); 149 char* autofs_path(struct autofs_node *anp); 150 void autofs_flush(struct autofs_mount *amp); 151 bool autofs_ignore_thread(void); 152 int autofs_node_new(struct autofs_node *parent, struct autofs_mount *amp, 153 const char *name, int namelen, struct autofs_node **anpp); 154 int autofs_node_find(struct autofs_node *parent, 155 const char *name, int namelen, struct autofs_node **anpp); 156 void autofs_node_delete(struct autofs_node *anp); 157 int autofs_node_vn(struct autofs_node *anp, struct mount *mp, 158 int flags, struct vnode **vpp); 159 160 static __inline void 161 autofs_node_cache(struct autofs_node *anp) 162 { 163 anp->an_cached = true; 164 } 165 166 static __inline void 167 autofs_node_uncache(struct autofs_node *anp) 168 { 169 anp->an_cached = false; 170 } 171 172 RB_PROTOTYPE(autofs_node_tree, autofs_node, an_link, autofs_node_cmp); 173 174 #endif /* !AUTOFS_H */ 175