175295Sdes/*- 2230132Suqs * Copyright (c) 2001 Dag-Erling Co��dan Sm��rgrav 375295Sdes * All rights reserved. 475295Sdes * 575295Sdes * Redistribution and use in source and binary forms, with or without 675295Sdes * modification, are permitted provided that the following conditions 775295Sdes * are met: 875295Sdes * 1. Redistributions of source code must retain the above copyright 975295Sdes * notice, this list of conditions and the following disclaimer 1075295Sdes * in this position and unchanged. 1175295Sdes * 2. Redistributions in binary form must reproduce the above copyright 1275295Sdes * notice, this list of conditions and the following disclaimer in the 1375295Sdes * documentation and/or other materials provided with the distribution. 1475295Sdes * 3. The name of the author may not be used to endorse or promote products 1575295Sdes * derived from this software without specific prior written permission. 1675295Sdes * 1775295Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1875295Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1975295Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2075295Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2175295Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2275295Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2375295Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2475295Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2575295Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2675295Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2775295Sdes * 2875295Sdes * $FreeBSD: releng/10.2/sys/fs/pseudofs/pseudofs_internal.h 230132 2012-01-15 13:23:18Z uqs $ 2975295Sdes */ 3075295Sdes 3175295Sdes#ifndef _PSEUDOFS_INTERNAL_H_INCLUDED 3275295Sdes#define _PSEUDOFS_INTERNAL_H_INCLUDED 3375295Sdes 3475295Sdes/* 3575295Sdes * Sysctl subtree 3675295Sdes */ 3775295SdesSYSCTL_DECL(_vfs_pfs); 3875295Sdes 3975295Sdes/* 4077998Sdes * Vnode data 4177998Sdes */ 4277998Sdesstruct pfs_vdata { 4377998Sdes struct pfs_node *pvd_pn; 4477998Sdes pid_t pvd_pid; 4584247Sdes struct vnode *pvd_vnode; 4684247Sdes struct pfs_vdata*pvd_prev, *pvd_next; 47168637Sdes int pvd_dead:1; 4877998Sdes}; 4977998Sdes 5077998Sdes/* 5175295Sdes * Vnode cache 5275295Sdes */ 5375295Sdesvoid pfs_vncache_load (void); 5475295Sdesvoid pfs_vncache_unload (void); 5575295Sdesint pfs_vncache_alloc (struct mount *, struct vnode **, 5677998Sdes struct pfs_node *, pid_t pid); 5775295Sdesint pfs_vncache_free (struct vnode *); 5875295Sdes 5975295Sdes/* 6075295Sdes * File number bitmap 6175295Sdes */ 6275295Sdesvoid pfs_fileno_init (struct pfs_info *); 6375295Sdesvoid pfs_fileno_uninit (struct pfs_info *); 64168720Sdesvoid pfs_fileno_alloc (struct pfs_node *); 65168720Sdesvoid pfs_fileno_free (struct pfs_node *); 6675295Sdes 67168764Sdes/* 68168764Sdes * Debugging 69168764Sdes */ 70168764Sdes#ifdef PSEUDOFS_TRACE 71168764Sdesextern int pfs_trace; 72168764Sdes 73168764Sdes#define PFS_TRACE(foo) \ 74168764Sdes do { \ 75168764Sdes if (pfs_trace) { \ 76168764Sdes printf("%s(): line %d: ", __func__, __LINE__); \ 77168764Sdes printf foo ; \ 78168764Sdes printf("\n"); \ 79168764Sdes } \ 80168764Sdes } while (0) 81168764Sdes#define PFS_RETURN(err) \ 82168764Sdes do { \ 83168764Sdes if (pfs_trace) { \ 84168764Sdes printf("%s(): line %d: returning %d\n", \ 85168764Sdes __func__, __LINE__, err); \ 86168764Sdes } \ 87168764Sdes return (err); \ 88168764Sdes } while (0) 89168764Sdes#else 90168764Sdes#define PFS_TRACE(foo) \ 91168764Sdes do { /* nothing */ } while (0) 92168764Sdes#define PFS_RETURN(err) \ 93168764Sdes return (err) 9475295Sdes#endif 95168764Sdes 96168764Sdes/* 97168764Sdes * Inline helpers for locking 98168764Sdes */ 99168764Sdesstatic inline void 100168764Sdespfs_lock(struct pfs_node *pn) 101168764Sdes{ 102168764Sdes 103168764Sdes mtx_lock(&pn->pn_mutex); 104168764Sdes} 105168764Sdes 106168764Sdesstatic inline void 107168764Sdespfs_unlock(struct pfs_node *pn) 108168764Sdes{ 109168764Sdes 110168764Sdes mtx_unlock(&pn->pn_mutex); 111168764Sdes} 112168764Sdes 113168764Sdesstatic inline void 114168764Sdespfs_assert_owned(struct pfs_node *pn) 115168764Sdes{ 116168764Sdes 117168764Sdes mtx_assert(&pn->pn_mutex, MA_OWNED); 118168764Sdes} 119168764Sdes 120168764Sdesstatic inline void 121168764Sdespfs_assert_not_owned(struct pfs_node *pn) 122168764Sdes{ 123168764Sdes 124168764Sdes mtx_assert(&pn->pn_mutex, MA_NOTOWNED); 125168764Sdes} 126168764Sdes 127168764Sdesstatic inline int 128168764Sdespn_fill(PFS_FILL_ARGS) 129168764Sdes{ 130168764Sdes 131168764Sdes PFS_TRACE(("%s", pn->pn_name)); 132168764Sdes KASSERT(pn->pn_fill != NULL, ("%s(): no callback", __func__)); 133168764Sdes if (p != NULL) { 134168764Sdes PROC_LOCK_ASSERT(p, MA_NOTOWNED); 135168764Sdes PROC_ASSERT_HELD(p); 136168764Sdes } 137168764Sdes pfs_assert_not_owned(pn); 138168764Sdes return ((pn->pn_fill)(PFS_FILL_ARGNAMES)); 139168764Sdes} 140168764Sdes 141168764Sdesstatic inline int 142168764Sdespn_attr(PFS_ATTR_ARGS) 143168764Sdes{ 144168764Sdes 145168764Sdes PFS_TRACE(("%s", pn->pn_name)); 146168764Sdes KASSERT(pn->pn_attr != NULL, ("%s(): no callback", __func__)); 147168764Sdes if (p != NULL) 148168764Sdes PROC_LOCK_ASSERT(p, MA_OWNED); 149168764Sdes pfs_assert_not_owned(pn); 150168764Sdes return ((pn->pn_attr)(PFS_ATTR_ARGNAMES)); 151168764Sdes} 152168764Sdes 153168764Sdesstatic inline int 154168764Sdespn_vis(PFS_VIS_ARGS) 155168764Sdes{ 156168764Sdes 157168764Sdes PFS_TRACE(("%s", pn->pn_name)); 158168764Sdes KASSERT(pn->pn_vis != NULL, ("%s(): no callback", __func__)); 159168764Sdes KASSERT(p != NULL, ("%s(): no process", __func__)); 160168764Sdes PROC_LOCK_ASSERT(p, MA_OWNED); 161168764Sdes pfs_assert_not_owned(pn); 162168764Sdes return ((pn->pn_vis)(PFS_VIS_ARGNAMES)); 163168764Sdes} 164168764Sdes 165168764Sdesstatic inline int 166168764Sdespn_ioctl(PFS_IOCTL_ARGS) 167168764Sdes{ 168168764Sdes 169168764Sdes PFS_TRACE(("%s", pn->pn_name)); 170168764Sdes KASSERT(pn->pn_ioctl != NULL, ("%s(): no callback", __func__)); 171168764Sdes if (p != NULL) 172168764Sdes PROC_LOCK_ASSERT(p, MA_OWNED); 173168764Sdes pfs_assert_not_owned(pn); 174168764Sdes return ((pn->pn_ioctl)(PFS_IOCTL_ARGNAMES)); 175168764Sdes} 176168764Sdes 177168764Sdesstatic inline int 178168764Sdespn_getextattr(PFS_GETEXTATTR_ARGS) 179168764Sdes{ 180168764Sdes 181168764Sdes PFS_TRACE(("%s", pn->pn_name)); 182168764Sdes KASSERT(pn->pn_getextattr != NULL, ("%s(): no callback", __func__)); 183168764Sdes if (p != NULL) 184168764Sdes PROC_LOCK_ASSERT(p, MA_OWNED); 185168764Sdes pfs_assert_not_owned(pn); 186168764Sdes return ((pn->pn_getextattr)(PFS_GETEXTATTR_ARGNAMES)); 187168764Sdes} 188168764Sdes 189168764Sdesstatic inline int 190168764Sdespn_close(PFS_CLOSE_ARGS) 191168764Sdes{ 192168764Sdes 193168764Sdes PFS_TRACE(("%s", pn->pn_name)); 194168764Sdes KASSERT(pn->pn_close != NULL, ("%s(): no callback", __func__)); 195168764Sdes if (p != NULL) 196168764Sdes PROC_LOCK_ASSERT(p, MA_OWNED); 197168764Sdes pfs_assert_not_owned(pn); 198168764Sdes return ((pn->pn_close)(PFS_CLOSE_ARGNAMES)); 199168764Sdes} 200168764Sdes 201168764Sdesstatic inline int 202168764Sdespn_destroy(PFS_DESTROY_ARGS) 203168764Sdes{ 204168764Sdes 205168764Sdes PFS_TRACE(("%s", pn->pn_name)); 206168764Sdes KASSERT(pn->pn_destroy != NULL, ("%s(): no callback", __func__)); 207168764Sdes pfs_assert_not_owned(pn); 208168764Sdes return ((pn->pn_destroy)(PFS_DESTROY_ARGNAMES)); 209168764Sdes} 210168764Sdes 211168764Sdes#endif 212