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