1240616Sjimharris/*- 2240616Sjimharris * SPDX-License-Identifier: BSD-2-Clause 3240616Sjimharris * 4240616Sjimharris * Copyright (c) 2009 Rick Macklem, University of Guelph 5240616Sjimharris * All rights reserved. 6240616Sjimharris * 7240616Sjimharris * Redistribution and use in source and binary forms, with or without 8240616Sjimharris * modification, are permitted provided that the following conditions 9240616Sjimharris * are met: 10240616Sjimharris * 1. Redistributions of source code must retain the above copyright 11240616Sjimharris * notice, this list of conditions and the following disclaimer. 12240616Sjimharris * 2. Redistributions in binary form must reproduce the above copyright 13240616Sjimharris * notice, this list of conditions and the following disclaimer in the 14240616Sjimharris * documentation and/or other materials provided with the distribution. 15240616Sjimharris * 16240616Sjimharris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17240616Sjimharris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18240616Sjimharris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19240616Sjimharris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20240616Sjimharris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21240616Sjimharris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22240616Sjimharris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23240616Sjimharris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24240616Sjimharris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25240616Sjimharris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26240616Sjimharris * SUCH DAMAGE. 27240616Sjimharris */ 28240616Sjimharris 29240616Sjimharris/* 30240616Sjimharris * These macros handle nfsvattr fields. They look a bit silly here, but 31240616Sjimharris * are quite different for the Darwin port. 32240616Sjimharris */ 33240616Sjimharris#define NFSVNO_ATTRINIT(n) (VATTR_NULL(&((n)->na_vattr))) 34240616Sjimharris#define NFSVNO_SETATTRVAL(n, f, v) ((n)->na_##f = (v)) 35240616Sjimharris#define NFSVNO_SETACTIVE(n, f) 36240616Sjimharris#define NFSVNO_UNSET(n, f) ((n)->na_##f = VNOVAL) 37240616Sjimharris#define NFSVNO_NOTSETMODE(n) ((n)->na_mode == ((mode_t)VNOVAL)) 38240616Sjimharris#define NFSVNO_ISSETMODE(n) ((n)->na_mode != ((mode_t)VNOVAL)) 39240616Sjimharris#define NFSVNO_NOTSETUID(n) ((n)->na_uid == ((uid_t)VNOVAL)) 40240616Sjimharris#define NFSVNO_ISSETUID(n) ((n)->na_uid != ((uid_t)VNOVAL)) 41240616Sjimharris#define NFSVNO_NOTSETGID(n) ((n)->na_gid == ((gid_t)VNOVAL)) 42240616Sjimharris#define NFSVNO_ISSETGID(n) ((n)->na_gid != ((gid_t)VNOVAL)) 43240616Sjimharris#define NFSVNO_NOTSETSIZE(n) ((n)->na_size == VNOVAL) 44240616Sjimharris#define NFSVNO_ISSETSIZE(n) ((n)->na_size != VNOVAL) 45240616Sjimharris#define NFSVNO_NOTSETATIME(n) ((n)->na_atime.tv_sec == VNOVAL) 46240616Sjimharris#define NFSVNO_ISSETATIME(n) ((n)->na_atime.tv_sec != VNOVAL) 47240616Sjimharris#define NFSVNO_NOTSETMTIME(n) ((n)->na_mtime.tv_sec == VNOVAL) 48240616Sjimharris#define NFSVNO_ISSETMTIME(n) ((n)->na_mtime.tv_sec != VNOVAL) 49240616Sjimharris 50240616Sjimharris/* 51240616Sjimharris * This structure acts as a "catch-all" for information that 52240616Sjimharris * needs to be returned by nfsd_fhtovp(). 53240616Sjimharris */ 54240616Sjimharrisstruct nfsexstuff { 55240616Sjimharris uint64_t nes_exflag; /* export flags */ 56240616Sjimharris int nes_numsecflavor; /* # of security flavors */ 57240616Sjimharris int nes_secflavors[MAXSECFLAVORS]; /* and the flavors */ 58240616Sjimharris}; 59240616Sjimharris 60240616Sjimharris/* 61240616Sjimharris * These are NO-OPS for BSD until Isilon upstreams EXITCODE support. 62240616Sjimharris * EXITCODE is an in-memory ring buffer that holds the routines failing status. 63240616Sjimharris * This is a valuable tool to use when debugging and analyzing issues. 64240616Sjimharris * In addition to recording a routine's failing status, it offers 65240616Sjimharris * logging of routines for call stack tracing. 66240616Sjimharris * EXITCODE should be used only in routines that return a true errno value, as 67240616Sjimharris * that value will be formatted to a displayable errno string. Routines that 68240616Sjimharris * return regular int status that are not true errno should not set EXITCODE. 69240616Sjimharris * If you want to log routine tracing, you can add EXITCODE(0) to any routine. 70240616Sjimharris * NFS extended the EXITCODE with EXITCODE2 to record either the routine's 71240616Sjimharris * exit errno status or the nd_repstat. 72240616Sjimharris */ 73240616Sjimharris#define NFSEXITCODE(error) 74240616Sjimharris#define NFSEXITCODE2(error, nd) 75240616Sjimharris 76240616Sjimharris#define NFSVNO_EXINIT(e) ((e)->nes_exflag = 0) 77240616Sjimharris#define NFSVNO_EXPORTED(e) ((e)->nes_exflag & MNT_EXPORTED) 78240616Sjimharris#define NFSVNO_EXRDONLY(e) ((e)->nes_exflag & MNT_EXRDONLY) 79240616Sjimharris#define NFSVNO_EXPORTANON(e) ((e)->nes_exflag & MNT_EXPORTANON) 80240616Sjimharris#define NFSVNO_EXSTRICTACCESS(e) ((e)->nes_exflag & MNT_EXSTRICTACCESS) 81240616Sjimharris#define NFSVNO_EXV4ONLY(e) ((e)->nes_exflag & MNT_EXV4ONLY) 82240616Sjimharris#define NFSVNO_EXTLS(e) ((e)->nes_exflag & MNT_EXTLS) 83240616Sjimharris#define NFSVNO_EXTLSCERT(e) ((e)->nes_exflag & MNT_EXTLSCERT) 84240616Sjimharris#define NFSVNO_EXTLSCERTUSER(e) ((e)->nes_exflag & MNT_EXTLSCERTUSER) 85240616Sjimharris 86240616Sjimharris#define NFSVNO_SETEXRDONLY(e) ((e)->nes_exflag = (MNT_EXPORTED|MNT_EXRDONLY)) 87240616Sjimharris 88240616Sjimharris#define NFSVNO_CMPFH(f1, f2) \ 89240616Sjimharris (fsidcmp(&(f1)->fh_fsid, &(f2)->fh_fsid) == 0 && \ 90240616Sjimharris bcmp(&(f1)->fh_fid, &(f2)->fh_fid, sizeof(struct fid)) == 0) 91240616Sjimharris 92240616Sjimharris#define NFSLOCKHASH(f) \ 93240616Sjimharris (&NFSD_VNET(nfslockhash)[nfsrv_hashfh(f) % nfsrv_lockhashsize]) 94240616Sjimharris 95240616Sjimharris#define NFSFPVNODE(f) ((f)->f_vnode) 96240616Sjimharris#define NFSFPCRED(f) ((f)->f_cred) 97240616Sjimharris#define NFSFPFLAG(f) ((f)->f_flag) 98240616Sjimharris 99240616Sjimharris#define NFSNAMEICNDSET(n, c, o, f) do { \ 100240616Sjimharris (n)->cn_cred = (c); \ 101240616Sjimharris (n)->cn_nameiop = (o); \ 102240616Sjimharris (n)->cn_flags = (f); \ 103240616Sjimharris } while (0) 104240616Sjimharris 105240616Sjimharris#define NFSPATHLEN_T size_t 106240616Sjimharris 107240616Sjimharris/* 108240616Sjimharris * These are set to the minimum and maximum size of a server file 109240616Sjimharris * handle. 110240616Sjimharris */ 111240616Sjimharris#define NFSRV_MINFH (sizeof (fhandle_t)) 112240616Sjimharris#define NFSRV_MAXFH (sizeof (fhandle_t)) 113240616Sjimharris 114240616Sjimharris/* Use this macro for debug printfs. */ 115240616Sjimharris#define NFSD_DEBUG(level, ...) do { \ 116240616Sjimharris if (nfsd_debuglevel >= (level)) \ 117240616Sjimharris printf(__VA_ARGS__); \ 118240616Sjimharris } while (0) 119240616Sjimharris