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