The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/nfs/nfsclstate.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2009 Rick Macklem, University of Guelph
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  * $FreeBSD$
   29  */
   30 
   31 #ifndef _NFS_NFSCLSTATE_H_
   32 #define _NFS_NFSCLSTATE_H_
   33 
   34 /*
   35  * Definitions for NFS V4 client state handling.
   36  */
   37 LIST_HEAD(nfsclopenhead, nfsclopen);
   38 LIST_HEAD(nfscllockownerhead, nfscllockowner);
   39 SLIST_HEAD(nfscllockownerfhhead, nfscllockownerfh);
   40 LIST_HEAD(nfscllockhead, nfscllock);
   41 LIST_HEAD(nfsclhead, nfsclclient);
   42 LIST_HEAD(nfsclownerhead, nfsclowner);
   43 TAILQ_HEAD(nfscldeleghead, nfscldeleg);
   44 LIST_HEAD(nfscldeleghash, nfscldeleg);
   45 TAILQ_HEAD(nfscllayouthead, nfscllayout);
   46 LIST_HEAD(nfscllayouthash, nfscllayout);
   47 LIST_HEAD(nfsclflayouthead, nfsclflayout);
   48 LIST_HEAD(nfscldevinfohead, nfscldevinfo);
   49 LIST_HEAD(nfsclrecalllayouthead, nfsclrecalllayout);
   50 #define NFSCLDELEGHASHSIZE      256
   51 #define NFSCLDELEGHASH(c, f, l)                                                 \
   52         (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE]))
   53 #define NFSCLLAYOUTHASHSIZE     256
   54 #define NFSCLLAYOUTHASH(c, f, l)                                                \
   55         (&((c)->nfsc_layouthash[ncl_hash((f), (l)) % NFSCLLAYOUTHASHSIZE]))
   56 
   57 /* Structure for NFSv4.1 session stuff. */
   58 struct nfsclsession {
   59         struct mtx      nfsess_mtx;
   60         struct nfsslot  nfsess_cbslots[NFSV4_CBSLOTS];
   61         nfsquad_t       nfsess_clientid;
   62         SVCXPRT         *nfsess_xprt;           /* For backchannel callback */
   63         uint32_t        nfsess_slotseq[64];     /* Max for 64bit nm_slots */
   64         uint64_t        nfsess_slots;
   65         uint32_t        nfsess_sequenceid;
   66         uint32_t        nfsess_maxcache;        /* Max size for cached reply. */
   67         uint16_t        nfsess_foreslots;
   68         uint16_t        nfsess_backslots;
   69         uint8_t         nfsess_sessionid[NFSX_V4SESSIONID];
   70         uint8_t         nfsess_defunct;         /* Non-zero for old sessions */
   71 };
   72 
   73 /*
   74  * This structure holds the session, clientid and related information
   75  * needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS).
   76  * It is malloc'd to the correct length.
   77  */
   78 struct nfsclds {
   79         TAILQ_ENTRY(nfsclds)    nfsclds_list;
   80         struct nfsclsession     nfsclds_sess;
   81         struct mtx              nfsclds_mtx;
   82         struct nfssockreq       *nfsclds_sockp;
   83         time_t                  nfsclds_expire;
   84         uint16_t                nfsclds_flags;
   85         uint16_t                nfsclds_servownlen;
   86         uint8_t                 nfsclds_verf[NFSX_VERF];
   87         uint8_t                 nfsclds_serverown[0];
   88 };
   89 
   90 /*
   91  * Flags for nfsclds_flags.
   92  */
   93 #define NFSCLDS_HASWRITEVERF    0x0001
   94 #define NFSCLDS_MDS             0x0002
   95 #define NFSCLDS_DS              0x0004
   96 #define NFSCLDS_CLOSED          0x0008
   97 #define NFSCLDS_SAMECONN        0x0010
   98 
   99 struct nfsclclient {
  100         LIST_ENTRY(nfsclclient) nfsc_list;
  101         struct nfsclownerhead   nfsc_owner;
  102         struct nfscldeleghead   nfsc_deleg;
  103         struct nfscldeleghash   nfsc_deleghash[NFSCLDELEGHASHSIZE];
  104         struct nfscllayouthead  nfsc_layout;
  105         struct nfscllayouthash  nfsc_layouthash[NFSCLLAYOUTHASHSIZE];
  106         struct nfscldevinfohead nfsc_devinfo;
  107         struct nfsv4lock        nfsc_lock;
  108         struct proc             *nfsc_renewthread;
  109         struct nfsmount         *nfsc_nmp;
  110         time_t                  nfsc_expire;
  111         u_int32_t               nfsc_clientidrev;
  112         u_int32_t               nfsc_rev;
  113         u_int32_t               nfsc_renew;
  114         u_int32_t               nfsc_cbident;
  115         u_int16_t               nfsc_flags;
  116         u_int16_t               nfsc_idlen;
  117         u_int8_t                nfsc_id[1];     /* Malloc'd to correct length */
  118 };
  119 
  120 /*
  121  * Bits for nfsc_flags.
  122  */
  123 #define NFSCLFLAGS_INITED       0x0001
  124 #define NFSCLFLAGS_HASCLIENTID  0x0002
  125 #define NFSCLFLAGS_RECOVER      0x0004
  126 #define NFSCLFLAGS_UMOUNT       0x0008
  127 #define NFSCLFLAGS_HASTHREAD    0x0010
  128 #define NFSCLFLAGS_AFINET6      0x0020
  129 #define NFSCLFLAGS_EXPIREIT     0x0040
  130 #define NFSCLFLAGS_FIRSTDELEG   0x0080
  131 #define NFSCLFLAGS_GOTDELEG     0x0100
  132 #define NFSCLFLAGS_RECVRINPROG  0x0200
  133 
  134 struct nfsclowner {
  135         LIST_ENTRY(nfsclowner)  nfsow_list;
  136         struct nfsclopenhead    nfsow_open;
  137         struct nfsclclient      *nfsow_clp;
  138         u_int32_t               nfsow_seqid;
  139         u_int32_t               nfsow_defunct;
  140         struct nfsv4lock        nfsow_rwlock;
  141         u_int8_t                nfsow_owner[NFSV4CL_LOCKNAMELEN];
  142 };
  143 
  144 /*
  145  * MALLOC'd to the correct length to accommodate the file handle.
  146  */
  147 struct nfscldeleg {
  148         TAILQ_ENTRY(nfscldeleg) nfsdl_list;
  149         LIST_ENTRY(nfscldeleg)  nfsdl_hash;
  150         struct nfsclownerhead   nfsdl_owner;    /* locally issued state */
  151         struct nfscllockownerhead nfsdl_lock;
  152         nfsv4stateid_t          nfsdl_stateid;
  153         struct acl_entry        nfsdl_ace;      /* Delegation ace */
  154         struct nfsclclient      *nfsdl_clp;
  155         struct nfsv4lock        nfsdl_rwlock;   /* for active I/O ops */
  156         struct nfscred          nfsdl_cred;     /* Cred. used for Open */
  157         time_t                  nfsdl_timestamp; /* used for stale cleanup */
  158         u_int64_t               nfsdl_sizelimit; /* Limit for file growth */
  159         u_int64_t               nfsdl_size;     /* saved copy of file size */
  160         u_int64_t               nfsdl_change;   /* and change attribute */
  161         struct timespec         nfsdl_modtime;  /* local modify time */
  162         u_int16_t               nfsdl_fhlen;
  163         u_int8_t                nfsdl_flags;
  164         u_int8_t                nfsdl_fh[1];    /* must be last */
  165 };
  166 
  167 /*
  168  * nfsdl_flags bits.
  169  */
  170 #define NFSCLDL_READ            0x01
  171 #define NFSCLDL_WRITE           0x02
  172 #define NFSCLDL_RECALL          0x04
  173 #define NFSCLDL_NEEDRECLAIM     0x08
  174 #define NFSCLDL_ZAPPED          0x10
  175 #define NFSCLDL_MODTIMESET      0x20
  176 #define NFSCLDL_DELEGRET        0x40
  177 
  178 /*
  179  * MALLOC'd to the correct length to accommodate the file handle.
  180  */
  181 struct nfsclopen {
  182         LIST_ENTRY(nfsclopen)   nfso_list;
  183         struct nfscllockownerhead nfso_lock;
  184         nfsv4stateid_t          nfso_stateid;
  185         struct nfsclowner       *nfso_own;
  186         struct nfscred          nfso_cred;      /* Cred. used for Open */
  187         u_int32_t               nfso_mode;
  188         u_int32_t               nfso_opencnt;
  189         u_int16_t               nfso_fhlen;
  190         u_int8_t                nfso_posixlock; /* 1 for POSIX type locking */
  191         u_int8_t                nfso_fh[1];     /* must be last */
  192 };
  193 
  194 /*
  195  * Return values for nfscl_open(). NFSCLOPEN_OK must == 0.
  196  */
  197 #define NFSCLOPEN_OK            0
  198 #define NFSCLOPEN_DOOPEN        1
  199 #define NFSCLOPEN_DOOPENDOWNGRADE 2
  200 #define NFSCLOPEN_SETCRED       3
  201 
  202 struct nfscllockowner {
  203         LIST_ENTRY(nfscllockowner) nfsl_list;
  204         struct nfscllockhead    nfsl_lock;
  205         struct nfsclopen        *nfsl_open;
  206         NFSPROC_T               *nfsl_inprog;
  207         nfsv4stateid_t          nfsl_stateid;
  208         int                     nfsl_lockflags;
  209         u_int32_t               nfsl_seqid;
  210         struct nfsv4lock        nfsl_rwlock;
  211         u_int8_t                nfsl_owner[NFSV4CL_LOCKNAMELEN];
  212         u_int8_t                nfsl_openowner[NFSV4CL_LOCKNAMELEN];
  213 };
  214 
  215 /*
  216  * Byte range entry for the above lock owner.
  217  */
  218 struct nfscllock {
  219         LIST_ENTRY(nfscllock)   nfslo_list;
  220         u_int64_t               nfslo_first;
  221         u_int64_t               nfslo_end;
  222         short                   nfslo_type;
  223 };
  224 
  225 /* This structure is used to collect a list of lockowners to free up. */
  226 struct nfscllockownerfh {
  227         SLIST_ENTRY(nfscllockownerfh)   nfslfh_list;
  228         struct nfscllockownerhead       nfslfh_lock;
  229         int                             nfslfh_len;
  230         uint8_t                         nfslfh_fh[NFSX_V4FHMAX];
  231 };
  232 
  233 /*
  234  * MALLOC'd to the correct length to accommodate the file handle.
  235  */
  236 struct nfscllayout {
  237         TAILQ_ENTRY(nfscllayout)        nfsly_list;
  238         LIST_ENTRY(nfscllayout)         nfsly_hash;
  239         nfsv4stateid_t                  nfsly_stateid;
  240         struct nfsv4lock                nfsly_lock;
  241         uint64_t                        nfsly_filesid[2];
  242         uint64_t                        nfsly_lastbyte;
  243         struct nfsclflayouthead         nfsly_flayread;
  244         struct nfsclflayouthead         nfsly_flayrw;
  245         struct nfsclrecalllayouthead    nfsly_recall;
  246         time_t                          nfsly_timestamp;
  247         struct nfsclclient              *nfsly_clp;
  248         uint16_t                        nfsly_flags;
  249         uint16_t                        nfsly_fhlen;
  250         uint8_t                         nfsly_fh[1];
  251 };
  252 
  253 /*
  254  * Flags for nfsly_flags.
  255  */
  256 #define NFSLY_FILES             0x0001
  257 #define NFSLY_BLOCK             0x0002
  258 #define NFSLY_OBJECT            0x0004
  259 #define NFSLY_RECALL            0x0008
  260 #define NFSLY_RECALLFILE        0x0010
  261 #define NFSLY_RECALLFSID        0x0020
  262 #define NFSLY_RECALLALL         0x0040
  263 #define NFSLY_RETONCLOSE        0x0080
  264 #define NFSLY_WRITTEN           0x0100  /* Has been used to write to a DS. */
  265 #define NFSLY_FLEXFILE          0x0200
  266 #define NFSLY_RETURNED          0x0400
  267 
  268 /*
  269  * Flex file layout mirror specific stuff for nfsclflayout.
  270  */
  271 struct nfsffm {
  272         nfsv4stateid_t          st;
  273         struct nfscldevinfo     *devp;
  274         char                    dev[NFSX_V4DEVICEID];
  275         uint32_t                eff;
  276         uid_t                   user;
  277         gid_t                   group;
  278         struct nfsfh            *fh[NFSDEV_MAXVERS];
  279         uint16_t                fhcnt;
  280 };
  281 
  282 /*
  283  * MALLOC'd to the correct length to accommodate the file handle list for File
  284  * layout and the list of mirrors for the Flex File Layout.
  285  * These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing
  286  * offset order.
  287  * The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ,
  288  * whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW.
  289  */
  290 struct nfsclflayout {
  291         LIST_ENTRY(nfsclflayout)        nfsfl_list;
  292         uint64_t                        nfsfl_off;
  293         uint64_t                        nfsfl_end;
  294         uint32_t                        nfsfl_iomode;
  295         uint16_t                        nfsfl_flags;
  296         union {
  297                 struct {
  298                         uint64_t        patoff;
  299                         uint32_t        util;
  300                         uint32_t        stripe1;
  301                         uint8_t         dev[NFSX_V4DEVICEID];
  302                         uint16_t        fhcnt;
  303                         struct nfscldevinfo *devp;
  304                 } fl;
  305                 struct {
  306                         uint64_t        stripeunit;
  307                         uint32_t        fflags;
  308                         uint32_t        statshint;
  309                         uint16_t        mirrorcnt;
  310                 } ff;
  311         } nfsfl_un;
  312         union {
  313                 struct nfsfh            *fh[0]; /* FH list for DS File layout */
  314                 struct nfsffm           ffm[0]; /* Mirror list for Flex File */
  315         } nfsfl_un2;    /* Must be last. Malloc'd to correct array length */
  316 };
  317 #define nfsfl_patoff            nfsfl_un.fl.patoff
  318 #define nfsfl_util              nfsfl_un.fl.util
  319 #define nfsfl_stripe1           nfsfl_un.fl.stripe1
  320 #define nfsfl_dev               nfsfl_un.fl.dev
  321 #define nfsfl_fhcnt             nfsfl_un.fl.fhcnt
  322 #define nfsfl_devp              nfsfl_un.fl.devp
  323 #define nfsfl_stripeunit        nfsfl_un.ff.stripeunit
  324 #define nfsfl_fflags            nfsfl_un.ff.fflags
  325 #define nfsfl_statshint         nfsfl_un.ff.statshint
  326 #define nfsfl_mirrorcnt         nfsfl_un.ff.mirrorcnt
  327 #define nfsfl_fh                nfsfl_un2.fh
  328 #define nfsfl_ffm               nfsfl_un2.ffm
  329 
  330 /*
  331  * Flags for nfsfl_flags.
  332  */
  333 #define NFSFL_RECALL    0x0001          /* File layout has been recalled */
  334 #define NFSFL_FILE      0x0002          /* File layout */
  335 #define NFSFL_FLEXFILE  0x0004          /* Flex File layout */
  336 
  337 /*
  338  * Structure that is used to store a LAYOUTRECALL.
  339  */
  340 struct nfsclrecalllayout {
  341         LIST_ENTRY(nfsclrecalllayout)   nfsrecly_list;
  342         uint64_t                        nfsrecly_off;
  343         uint64_t                        nfsrecly_len;
  344         int                             nfsrecly_recalltype;
  345         uint32_t                        nfsrecly_iomode;
  346         uint32_t                        nfsrecly_stateseqid;
  347         uint32_t                        nfsrecly_stat;
  348         uint32_t                        nfsrecly_op;
  349         char                            nfsrecly_devid[NFSX_V4DEVICEID];
  350 };
  351 
  352 /*
  353  * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to
  354  * store the list of network connections and list of indices.
  355  * nfsdi_data[] is allocated the following way:
  356  * - nfsdi_addrcnt * struct nfsclds
  357  * - stripe indices, each stored as one byte, since there can be many
  358  *   of them. (This implies a limit of 256 on nfsdi_addrcnt, since the
  359  *   indices select which address.)
  360  * For Flex File, the addrcnt is always one and no stripe indices exist.
  361  */
  362 struct nfscldevinfo {
  363         LIST_ENTRY(nfscldevinfo)        nfsdi_list;
  364         uint8_t                         nfsdi_deviceid[NFSX_V4DEVICEID];
  365         struct nfsclclient              *nfsdi_clp;
  366         uint32_t                        nfsdi_refcnt;
  367         uint32_t                        nfsdi_layoutrefs;
  368         union {
  369                 struct {
  370                         uint16_t        stripecnt;
  371                 } fl;
  372                 struct {
  373                         int             versindex;
  374                         uint32_t        vers;
  375                         uint32_t        minorvers;
  376                         uint32_t        rsize;
  377                         uint32_t        wsize;
  378                 } ff;
  379         } nfsdi_un;
  380         uint16_t                        nfsdi_addrcnt;
  381         uint16_t                        nfsdi_flags;
  382         struct nfsclds                  *nfsdi_data[0];
  383 };
  384 #define nfsdi_stripecnt nfsdi_un.fl.stripecnt
  385 #define nfsdi_versindex nfsdi_un.ff.versindex
  386 #define nfsdi_vers      nfsdi_un.ff.vers
  387 #define nfsdi_minorvers nfsdi_un.ff.minorvers
  388 #define nfsdi_rsize     nfsdi_un.ff.rsize
  389 #define nfsdi_wsize     nfsdi_un.ff.wsize
  390 
  391 /* Flags for nfsdi_flags. */
  392 #define NFSDI_FILELAYOUT        0x0001
  393 #define NFSDI_FLEXFILE          0x0002
  394 #define NFSDI_TIGHTCOUPLED      0X0004
  395 
  396 /* These inline functions return values from nfsdi_data[]. */
  397 /*
  398  * Return a pointer to the address at "pos".
  399  */
  400 static __inline struct nfsclds **
  401 nfsfldi_addr(struct nfscldevinfo *ndi, int pos)
  402 {
  403 
  404         if (pos >= ndi->nfsdi_addrcnt)
  405                 return (NULL);
  406         return (&ndi->nfsdi_data[pos]);
  407 }
  408 
  409 /*
  410  * Return the Nth ("pos") stripe index.
  411  */
  412 static __inline int
  413 nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos)
  414 {
  415         uint8_t *valp;
  416 
  417         if (pos >= ndi->nfsdi_stripecnt)
  418                 return (-1);
  419         valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
  420         valp += pos;
  421         return ((int)*valp);
  422 }
  423 
  424 /*
  425  * Set the Nth ("pos") stripe index to "val".
  426  */
  427 static __inline void
  428 nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val)
  429 {
  430         uint8_t *valp;
  431 
  432         if (pos >= ndi->nfsdi_stripecnt)
  433                 return;
  434         valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
  435         valp += pos;
  436         *valp = val;
  437 }
  438 
  439 /*
  440  * Macro for incrementing the seqid#.
  441  */
  442 #define NFSCL_INCRSEQID(s, n)   do {                                    \
  443             if (((n)->nd_flag & ND_INCRSEQID))                          \
  444                 (s)++;                                                  \
  445         } while (0)
  446 
  447 #endif  /* _NFS_NFSCLSTATE_H_ */

Cache object: 65771bf06c293ab71145433a1f6f13af


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.