Home | History | Annotate | Line # | Download | only in nfs
      1 /*	$NetBSD: nfs_var.h,v 1.97 2024/12/07 02:05:55 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _NFS_NFS_VAR_H_
     33 #define	_NFS_NFS_VAR_H_
     34 
     35 #ifdef _KERNEL
     36 
     37 #include <sys/mallocvar.h>
     38 #include <sys/pool.h>
     39 
     40 #include <nfs/nfsproto.h>
     41 #include <nfs/rpcv2.h>
     42 
     43 struct vnode;
     44 struct uio;
     45 struct proc;
     46 struct buf;
     47 struct nfs_diskless;
     48 struct sockaddr_in;
     49 struct nfs_dlmount;
     50 struct vnode;
     51 struct nfsd;
     52 struct mbuf;
     53 struct file;
     54 struct nfssvc_sock;
     55 struct nfsmount;
     56 struct socket;
     57 struct nfsreq;
     58 struct vattr;
     59 struct nameidata;
     60 struct nfsnode;
     61 struct sillyrename;
     62 struct componentname;
     63 struct nfsd_srvargs;
     64 struct nfsrv_descript;
     65 struct nfs_fattr;
     66 struct nfsdircache;
     67 union nethostaddr;
     68 
     69 /* nfs_bio.c */
     70 int nfs_bioread(struct vnode *, struct uio *, int, kauth_cred_t, int);
     71 struct buf *nfs_getcacheblk(struct vnode *, daddr_t, int, struct lwp *);
     72 int nfs_vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, int);
     73 int nfs_flushstalebuf(struct vnode *, kauth_cred_t, struct lwp *, int);
     74 #define	NFS_FLUSHSTALEBUF_MYWRITE	1	/* assume writes are ours */
     75 int nfs_asyncio(struct buf *);
     76 int nfs_doio(struct buf *);
     77 
     78 /* nfs_boot.c */
     79 /* see nfsdiskless.h */
     80 
     81 /* nfs_kq.c */
     82 void nfs_kqinit(void);
     83 void nfs_kqfini(void);
     84 
     85 /* nfs_node.c */
     86 void nfs_node_init(void);
     87 void nfs_node_done(void);
     88 
     89 int nfs_nget1(struct mount *, nfsfh_t *, int, struct nfsnode **, int);
     90 #define	nfs_nget(mp, fhp, fhsize, npp) \
     91 	nfs_nget1((mp), (fhp), (fhsize), (npp), 0)
     92 
     93 /* nfs_vnops.c */
     94 int nfs_null(struct vnode *, kauth_cred_t, struct lwp *);
     95 int nfs_setattrrpc(struct vnode *, struct vattr *, kauth_cred_t, struct lwp *);
     96 int nfs_readlinkrpc(struct vnode *, struct uio *, kauth_cred_t);
     97 int nfs_readrpc(struct vnode *, struct uio *);
     98 int nfs_writerpc(struct vnode *, struct uio *, int *, bool, bool *);
     99 int nfs_mknodrpc(struct vnode *, struct vnode **, struct componentname *,
    100 	struct vattr *);
    101 int nfs_removeit(struct sillyrename *);
    102 int nfs_removerpc(struct vnode *, const char *, int, kauth_cred_t,
    103 	struct lwp *);
    104 int nfs_renameit(struct vnode *, struct componentname *, struct sillyrename *);
    105 int nfs_renamerpc(struct vnode *, const char *, int, struct vnode *,
    106 	const char *, int, kauth_cred_t, struct lwp *);
    107 int nfs_readdirrpc(struct vnode *, struct uio *, kauth_cred_t);
    108 int nfs_readdirplusrpc(struct vnode *, struct uio *, kauth_cred_t);
    109 int nfs_sillyrename(struct vnode *, struct vnode *, struct componentname *,
    110 	bool);
    111 int nfs_lookitup(struct vnode *, const char *, int, kauth_cred_t,
    112 	struct lwp *, struct nfsnode **);
    113 int nfs_commit(struct vnode *, off_t, uint32_t, struct lwp *);
    114 int nfs_flush(struct vnode *, kauth_cred_t, int, struct lwp *, int);
    115 
    116 /* nfs_serv.c */
    117 int nfsrv3_access(struct nfsrv_descript *, struct nfssvc_sock *,
    118 	struct lwp *, struct mbuf **);
    119 int nfsrv_getattr(struct nfsrv_descript *, struct nfssvc_sock *,
    120 	struct lwp *, struct mbuf **);
    121 int nfsrv_setattr(struct nfsrv_descript *, struct nfssvc_sock *,
    122 	struct lwp *, struct mbuf **);
    123 int nfsrv_lookup(struct nfsrv_descript *, struct nfssvc_sock *,
    124 	struct lwp *, struct mbuf **);
    125 int nfsrv_readlink(struct nfsrv_descript *, struct nfssvc_sock *,
    126 	struct lwp *, struct mbuf **);
    127 int nfsrv_read(struct nfsrv_descript *, struct nfssvc_sock *,
    128 	struct lwp *, struct mbuf **);
    129 int nfsrv_write(struct nfsrv_descript *, struct nfssvc_sock *,
    130 	struct lwp *, struct mbuf **);
    131 int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
    132 	struct lwp *, struct mbuf **);
    133 void nfsrvw_coalesce(struct nfsrv_descript *, struct nfsrv_descript *);
    134 int nfsrv_create(struct nfsrv_descript *, struct nfssvc_sock *,
    135 	struct lwp *, struct mbuf **);
    136 int nfsrv_mknod(struct nfsrv_descript *, struct nfssvc_sock *,
    137 	struct lwp *, struct mbuf **);
    138 int nfsrv_remove(struct nfsrv_descript *, struct nfssvc_sock *,
    139 	struct lwp *, struct mbuf **);
    140 int nfsrv_rename(struct nfsrv_descript *, struct nfssvc_sock *,
    141 	struct lwp *, struct mbuf **);
    142 int nfsrv_link(struct nfsrv_descript *, struct nfssvc_sock *,
    143 	struct lwp *, struct mbuf **);
    144 int nfsrv_symlink(struct nfsrv_descript *, struct nfssvc_sock *,
    145 	struct lwp *, struct mbuf **);
    146 int nfsrv_mkdir(struct nfsrv_descript *, struct nfssvc_sock *,
    147 	struct lwp *, struct mbuf **);
    148 int nfsrv_rmdir(struct nfsrv_descript *, struct nfssvc_sock *,
    149 	struct lwp *, struct mbuf **);
    150 int nfsrv_readdir(struct nfsrv_descript *, struct nfssvc_sock *,
    151 	struct lwp *, struct mbuf **);
    152 int nfsrv_readdirplus(struct nfsrv_descript *, struct nfssvc_sock *,
    153 	struct lwp *, struct mbuf **);
    154 int nfsrv_commit(struct nfsrv_descript *, struct nfssvc_sock *,
    155 	struct lwp *, struct mbuf **);
    156 int nfsrv_statfs(struct nfsrv_descript *, struct nfssvc_sock *,
    157 	struct lwp *, struct mbuf **);
    158 int nfsrv_fsinfo(struct nfsrv_descript *, struct nfssvc_sock *,
    159 	struct lwp *, struct mbuf **);
    160 int nfsrv_pathconf(struct nfsrv_descript *, struct nfssvc_sock *,
    161 	struct lwp *, struct mbuf **);
    162 int nfsrv_null(struct nfsrv_descript *, struct nfssvc_sock *,
    163 	struct lwp *, struct mbuf **);
    164 int nfsrv_noop(struct nfsrv_descript *, struct nfssvc_sock *,
    165 	struct lwp *, struct mbuf **);
    166 int nfsrv_access(struct vnode *, int, kauth_cred_t, int, struct lwp *, int);
    167 
    168 /* nfs_socket.c */
    169 int nfs_connect(struct nfsmount *, struct nfsreq *, struct lwp *);
    170 int nfs_reconnect(struct nfsreq *);
    171 void nfs_disconnect(struct nfsmount *);
    172 void nfs_safedisconnect(struct nfsmount *);
    173 int nfs_send(struct socket *, struct mbuf *, struct mbuf *, struct nfsreq *,
    174 	struct lwp *);
    175 int nfs_request(struct nfsnode *, struct mbuf *, int, struct lwp *,
    176 	kauth_cred_t, struct mbuf **, struct mbuf **, char **, int *);
    177 int nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
    178 	int, int, u_quad_t *, struct mbuf **, struct mbuf **, char **);
    179 void nfs_timer(void *);
    180 void nfs_timer_init(void);
    181 void nfs_timer_fini(void);
    182 void nfs_timer_start(void);
    183 void nfs_timer_srvinit(bool (*)(void));
    184 void nfs_timer_srvfini(void);
    185 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct lwp *);
    186 int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
    187 int nfs_msg(struct lwp *, const char *, const char *);
    188 void nfsrv_soupcall(struct socket *, void *, int, int);
    189 void nfsrv_rcv(struct nfssvc_sock *);
    190 int nfsrv_getstream(struct nfssvc_sock *, int);
    191 int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, struct nfsrv_descript **,
    192     bool *);
    193 void nfsrv_wakenfsd(struct nfssvc_sock *);
    194 int nfsdsock_lock(struct nfssvc_sock *, bool);
    195 void nfsdsock_unlock(struct nfssvc_sock *);
    196 int nfsdsock_drain(struct nfssvc_sock *);
    197 int nfsdsock_sendreply(struct nfssvc_sock *, struct nfsrv_descript *);
    198 void nfsdreq_init(void);
    199 void nfsdreq_fini(void);
    200 struct nfsrv_descript *nfsdreq_alloc(void);
    201 void nfsdreq_free(struct nfsrv_descript *);
    202 bool nfsrv_timer(void);
    203 int nfs_rcvlock(struct nfsmount *, struct nfsreq *);
    204 void nfs_rcvunlock(struct nfsmount *);
    205 
    206 void nfsdsock_setbits(struct nfssvc_sock *, int);
    207 void nfsdsock_clearbits(struct nfssvc_sock *, int);
    208 bool nfsdsock_testbits(struct nfssvc_sock *, int);
    209 
    210 /*
    211  * Estimate rto for an nfs rpc sent via. an unreliable datagram.
    212  * Use the mean and mean deviation of rtt for the appropriate type of rpc
    213  * for the frequent rpcs and a default for the others.
    214  * The justification for doing "other" this way is that these rpcs
    215  * happen so infrequently that timer est. would probably be stale.
    216  * Also, since many of these rpcs are
    217  * non-idempotent, a conservative timeout is desired.
    218  * getattr, lookup - A+2D
    219  * read, write     - A+4D
    220  * other           - nm_timeo
    221  */
    222 #define	NFS_RTO(n, t) \
    223 	((t) == 0 ? (n)->nm_timeo : \
    224 	 ((t) < 3 ? \
    225 	  (((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
    226 	  ((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
    227 #define	NFS_SRTT(r)	(r)->r_nmp->nm_srtt[nfs_proct[(r)->r_procnum] - 1]
    228 #define	NFS_SDRTT(r)	(r)->r_nmp->nm_sdrtt[nfs_proct[(r)->r_procnum] - 1]
    229 
    230 extern int nfsrtton;
    231 extern struct nfsrtt nfsrtt;
    232 extern const int nfs_proct[];
    233 
    234 extern const struct timeval nfs_err_interval;
    235 extern struct timeval nfs_reply_last_err_time;
    236 extern struct timeval nfs_timer_last_err_time;
    237 
    238 
    239 /* nfs_srvcache.c */
    240 void nfsrv_initcache(void);
    241 void nfsrv_finicache(void);
    242 int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
    243 	struct mbuf **);
    244 void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
    245 void nfsrv_cleancache(void);
    246 
    247 /* nfs_subs.c */
    248 struct mbuf *nfsm_reqh(struct nfsnode *, u_long, int, char **);
    249 struct mbuf *nfsm_rpchead(kauth_cred_t, int, int, int, int, char *, int,
    250 	char *, struct mbuf *, int, struct mbuf **, u_int32_t *);
    251 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, char **);
    252 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, char **);
    253 int nfsm_disct(struct mbuf **, char **, int, int, char **);
    254 int nfs_adv(struct mbuf **, char **, int, int);
    255 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
    256 u_long nfs_dirhash(off_t);
    257 void nfs_initdircache(struct vnode *);
    258 void nfs_initdirxlatecookie(struct vnode *);
    259 struct nfsdircache *nfs_searchdircache(struct vnode *, off_t, int, int *);
    260 struct nfsdircache *nfs_enterdircache(struct vnode *, off_t, off_t, int,
    261 	daddr_t);
    262 void nfs_putdircache(struct nfsnode *, struct nfsdircache *);
    263 void nfs_invaldircache(struct vnode *, int);
    264 #define	NFS_INVALDIRCACHE_FORCE		1
    265 #define	NFS_INVALDIRCACHE_KEEPEOF	2
    266 void nfs_init(void);
    267 void nfs_fini(void);
    268 int nfsm_loadattrcache(struct vnode **, struct mbuf **, char **,
    269 	struct vattr *, int flags);
    270 int nfs_loadattrcache(struct vnode **, struct nfs_fattr *, struct vattr *,
    271 	int flags);
    272 int nfs_getattrcache(struct vnode *, struct vattr *);
    273 void nfs_delayedtruncate(struct vnode *);
    274 int nfs_check_wccdata(struct nfsnode *, const struct timespec *,
    275 	struct timespec *, bool);
    276 int nfs_namei(struct nameidata *, nfsrvfh_t *, uint32_t, struct nfssvc_sock *,
    277 	struct mbuf *, struct mbuf **, char **, struct vnode **,
    278 	int *, struct vattr *, struct lwp *, int, int);
    279 void nfs_zeropad(struct mbuf *, int, int);
    280 void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
    281 	struct vattr *, struct mbuf **, char **);
    282 void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
    283 	struct mbuf **, char **);
    284 void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, struct nfs_fattr *);
    285 int nfsrv_fhtovp(nfsrvfh_t *, int, struct vnode **, kauth_cred_t,
    286 	struct nfssvc_sock *, struct mbuf *, int *, int, int);
    287 int nfs_ispublicfh(const nfsrvfh_t *);
    288 int netaddr_match(int, union nethostaddr *, struct mbuf *);
    289 time_t nfs_attrtimeo(struct nfsmount *, struct nfsnode *);
    290 
    291 /* flags for nfs_loadattrcache and friends */
    292 #define	NAC_NOTRUNC	1	/* don't truncate file size */
    293 
    294 void nfs_clearcommit(struct mount *);
    295 void nfs_merge_commit_ranges(struct vnode *);
    296 int nfs_in_committed_range(struct vnode *, off_t, off_t);
    297 int nfs_in_tobecommitted_range(struct vnode *, off_t, off_t);
    298 void nfs_add_committed_range(struct vnode *, off_t, off_t);
    299 void nfs_del_committed_range(struct vnode *, off_t, off_t);
    300 void nfs_add_tobecommitted_range(struct vnode *, off_t, off_t);
    301 void nfs_del_tobecommitted_range(struct vnode *, off_t, off_t);
    302 
    303 int nfsrv_errmap(struct nfsrv_descript *, int);
    304 void nfs_cookieheuristic(struct vnode *, int *, struct lwp *, kauth_cred_t);
    305 
    306 u_int32_t nfs_getxid(void);
    307 void nfs_renewxid(struct nfsreq *);
    308 
    309 int nfsrv_composefh(struct vnode *, nfsrvfh_t *, bool);
    310 int nfsrv_comparefh(const nfsrvfh_t *, const nfsrvfh_t *);
    311 void nfsrv_copyfh(nfsrvfh_t *, const nfsrvfh_t *);
    312 
    313 extern const enum vtype nv2tov_type[8];
    314 extern const enum vtype nv3tov_type[8];
    315 
    316 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers,
    317         rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr,
    318 	rpc_auth_kerb;
    319 extern u_int32_t nfs_prog;
    320 extern const int nfsv3_procid[NFS_NPROCS];
    321 extern int nfs_ticks;
    322 
    323 /* nfs_syscalls.c */
    324 struct sys_getfh_args;
    325 struct sys_nfssvc_args;
    326 int sys_getfh(struct lwp *, const struct sys_getfh_args *, register_t *);
    327 int sys_nfssvc(struct lwp *, const struct sys_nfssvc_args *, register_t *);
    328 int nfssvc_addsock(struct file *, struct mbuf *);
    329 void nfsrv_zapsock(struct nfssvc_sock *);
    330 void nfsrv_slpderef(struct nfssvc_sock *);
    331 void nfsrv_init(int);
    332 void nfsrv_fini(void);
    333 void nfs_iodinit(void);
    334 void nfs_iodfini(void);
    335 int nfs_iodbusy(struct nfsmount *);
    336 int nfs_set_niothreads(int);
    337 int nfs_getauth(struct nfsmount *, struct nfsreq *, kauth_cred_t, char **,
    338 	int *, char *, int *, NFSKERBKEY_T);
    339 int nfs_getnickauth(struct nfsmount *, kauth_cred_t, char **, int *, char *,
    340 	int);
    341 int nfs_savenickauth(struct nfsmount *, kauth_cred_t, int, NFSKERBKEY_T,
    342 	struct mbuf **, char **, struct mbuf *);
    343 /*
    344  * Backend copyin/out functions for nfssvc(2), so that netbsd32 can
    345  * easily access NFS.  Each operation either must perform a copyin or
    346  * copyout of the right data for the emulation.  exp_in() takes a count
    347  * of the number of export_args to copyin, and order arguments for
    348  * func(dst, src).
    349  */
    350 struct nfssvc_copy_ops {
    351 	int (*addsock_in)(struct nfsd_args *, const void *);
    352 	int (*setexports_in)(struct mountd_exports_list *, const void *);
    353 	int (*nsd_in)(struct nfsd_srvargs *, const void *);
    354 	int (*nsd_out)(void *, const struct nfsd_srvargs *);
    355 	int (*exp_in)(struct export_args *, const void *, size_t);
    356 };
    357 int do_nfssvc(struct nfssvc_copy_ops *, struct lwp *, int, void *, register_t *);
    358 
    359 /* nfs_export.c */
    360 extern struct nfs_public nfs_pub;
    361 int mountd_set_exports_list(const struct mountd_exports_list *, struct lwp *,
    362     struct mount *, int);
    363 int netexport_check(const fsid_t *, struct mbuf *, struct mount **, int *,
    364     kauth_cred_t *);
    365 void netexport_rdlock(void);
    366 void netexport_rdunlock(void);
    367 void netexport_init(void);
    368 void netexport_fini(void);
    369 bool netexport_hasexports(void);
    370 
    371 #endif /* _KERNEL */
    372 
    373 #endif	/* _NFS_NFS_VAR_H_ */
    374