Path: blob/main/sys/fs/pseudofs/pseudofs_internal.h
39483 views
/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2001 Dag-Erling Smørgrav4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer11* in this position and unchanged.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. The name of the author may not be used to endorse or promote products16* derived from this software without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#ifndef _PSEUDOFS_INTERNAL_H_INCLUDED31#define _PSEUDOFS_INTERNAL_H_INCLUDED3233/*34* Sysctl subtree35*/36SYSCTL_DECL(_vfs_pfs);3738/*39* Vnode data40*/41struct pfs_vdata {42struct pfs_node *pvd_pn;43pid_t pvd_pid;44struct vnode *pvd_vnode;45SLIST_ENTRY(pfs_vdata) pvd_hash;46};4748/*49* Vnode cache50*/51void pfs_vncache_load (void);52void pfs_vncache_unload (void);53int pfs_vncache_alloc (struct mount *, struct vnode **,54struct pfs_node *, pid_t pid);55int pfs_vncache_free (struct vnode *);5657/*58* File number bitmap59*/60void pfs_fileno_init (struct pfs_info *);61void pfs_fileno_uninit (struct pfs_info *);62void pfs_fileno_alloc (struct pfs_node *);63void pfs_fileno_free (struct pfs_node *);6465/*66* Debugging67*/68#ifdef PSEUDOFS_TRACE69extern int pfs_trace;7071#define PFS_TRACE(foo) \72do { \73if (pfs_trace) { \74printf("%s(): line %d: ", __func__, __LINE__); \75printf foo ; \76printf("\n"); \77} \78} while (0)79#define PFS_RETURN(err) \80do { \81if (pfs_trace) { \82printf("%s(): line %d: returning %d\n", \83__func__, __LINE__, err); \84} \85return (err); \86} while (0)87#else88#define PFS_TRACE(foo) \89do { /* nothing */ } while (0)90#define PFS_RETURN(err) \91return (err)92#endif9394/*95* Inline helpers for locking96*/97static inline void98pfs_lock(struct pfs_node *pn)99{100101mtx_lock(&pn->pn_mutex);102}103104static inline void105pfs_unlock(struct pfs_node *pn)106{107108mtx_unlock(&pn->pn_mutex);109}110111static inline void112pfs_assert_owned(struct pfs_node *pn)113{114115mtx_assert(&pn->pn_mutex, MA_OWNED);116}117118static inline void119pfs_assert_not_owned(struct pfs_node *pn)120{121122mtx_assert(&pn->pn_mutex, MA_NOTOWNED);123}124125static inline int126pn_fill(PFS_FILL_ARGS)127{128129PFS_TRACE(("%s", pn->pn_name));130KASSERT(pn->pn_fill != NULL, ("%s(): no callback", __func__));131if (p != NULL) {132PROC_LOCK_ASSERT(p, MA_NOTOWNED);133PROC_ASSERT_HELD(p);134}135pfs_assert_not_owned(pn);136return ((pn->pn_fill)(PFS_FILL_ARGNAMES));137}138139static inline int140pn_attr(PFS_ATTR_ARGS)141{142143PFS_TRACE(("%s", pn->pn_name));144KASSERT(pn->pn_attr != NULL, ("%s(): no callback", __func__));145if (p != NULL)146PROC_LOCK_ASSERT(p, MA_OWNED);147pfs_assert_not_owned(pn);148return ((pn->pn_attr)(PFS_ATTR_ARGNAMES));149}150151static inline int152pn_vis(PFS_VIS_ARGS)153{154155PFS_TRACE(("%s", pn->pn_name));156if (pn->pn_vis == NULL)157return (1);158if (p != NULL)159PROC_LOCK_ASSERT(p, MA_OWNED);160pfs_assert_not_owned(pn);161return ((pn->pn_vis)(PFS_VIS_ARGNAMES));162}163164static inline int165pn_ioctl(PFS_IOCTL_ARGS)166{167168PFS_TRACE(("%s", pn->pn_name));169KASSERT(pn->pn_ioctl != NULL, ("%s(): no callback", __func__));170if (p != NULL)171PROC_LOCK_ASSERT(p, MA_OWNED);172pfs_assert_not_owned(pn);173return ((pn->pn_ioctl)(PFS_IOCTL_ARGNAMES));174}175176static inline int177pn_getextattr(PFS_GETEXTATTR_ARGS)178{179180PFS_TRACE(("%s", pn->pn_name));181KASSERT(pn->pn_getextattr != NULL, ("%s(): no callback", __func__));182if (p != NULL)183PROC_LOCK_ASSERT(p, MA_OWNED);184pfs_assert_not_owned(pn);185return ((pn->pn_getextattr)(PFS_GETEXTATTR_ARGNAMES));186}187188static inline int189pn_close(PFS_CLOSE_ARGS)190{191192PFS_TRACE(("%s", pn->pn_name));193KASSERT(pn->pn_close != NULL, ("%s(): no callback", __func__));194if (p != NULL)195PROC_LOCK_ASSERT(p, MA_OWNED);196pfs_assert_not_owned(pn);197return ((pn->pn_close)(PFS_CLOSE_ARGNAMES));198}199200static inline int201pn_destroy(PFS_DESTROY_ARGS)202{203204PFS_TRACE(("%s", pn->pn_name));205KASSERT(pn->pn_destroy != NULL, ("%s(): no callback", __func__));206pfs_assert_not_owned(pn);207return ((pn->pn_destroy)(PFS_DESTROY_ARGNAMES));208}209210#endif211212213