/* $NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $ */
/*-
* Copyright (c) 2009 Rick Macklem, University of Guelph
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* FreeBSD: head/sys/fs/nfs/nfsclstate.h 268115 2014-07-01 20:47:16Z rmacklem
* $NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $
*/
/* Structure for NFSv4.1 session stuff. */
struct nfsclsession {
kmutex_t nfsess_mtx;
struct nfsslot nfsess_cbslots[NFSV4_CBSLOTS];
nfsquad_t nfsess_clientid;
SVCXPRT *nfsess_xprt; /* For backchannel callback */
uint32_t nfsess_slotseq[64]; /* Max for 64bit nm_slots */
uint64_t nfsess_slots;
uint32_t nfsess_sequenceid;
uint32_t nfsess_maxcache; /* Max size for cached reply. */
uint16_t nfsess_foreslots;
uint16_t nfsess_backslots;
uint8_t nfsess_sessionid[NFSX_V4SESSIONID];
};
/*
* This structure holds the session, clientid and related information
* needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS).
* It is malloc'd to the correct length.
*/
struct nfsclds {
TAILQ_ENTRY(nfsclds) nfsclds_list;
struct nfsclsession nfsclds_sess;
kmutex_t nfsclds_mtx;
struct nfssockreq *nfsclds_sockp;
time_t nfsclds_expire;
uint16_t nfsclds_flags;
uint16_t nfsclds_servownlen;
uint8_t nfsclds_verf[NFSX_VERF];
uint8_t nfsclds_serverown[0];
};
/*
* MALLOC'd to the correct length to accommodate the file handle.
*/
struct nfsclopen {
LIST_ENTRY(nfsclopen) nfso_list;
struct nfscllockownerhead nfso_lock;
nfsv4stateid_t nfso_stateid;
struct nfsclowner *nfso_own;
struct nfscred nfso_cred; /* Cred. used for Open */
u_int32_t nfso_mode;
u_int32_t nfso_opencnt;
u_int16_t nfso_fhlen;
u_int8_t nfso_posixlock; /* 1 for POSIX type locking */
u_int8_t nfso_fh[1]; /* must be last */
};
/*
* Byte range entry for the above lock owner.
*/
struct nfscllock {
LIST_ENTRY(nfscllock) nfslo_list;
u_int64_t nfslo_first;
u_int64_t nfslo_end;
short nfslo_type;
};
/* This structure is used to collect a list of lockowners to free up. */
struct nfscllockownerfh {
SLIST_ENTRY(nfscllockownerfh) nfslfh_list;
struct nfscllockownerhead nfslfh_lock;
int nfslfh_len;
uint8_t nfslfh_fh[NFSX_V4FHMAX];
};
/*
* Flags for nfsly_flags.
*/
#define NFSLY_FILES 0x0001
#define NFSLY_BLOCK 0x0002
#define NFSLY_OBJECT 0x0004
#define NFSLY_RECALL 0x0008
#define NFSLY_RECALLFILE 0x0010
#define NFSLY_RECALLFSID 0x0020
#define NFSLY_RECALLALL 0x0040
#define NFSLY_RETONCLOSE 0x0080
#define NFSLY_WRITTEN 0x0100 /* Has been used to write to a DS. */
/*
* MALLOC'd to the correct length to accommodate the file handle list.
* These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing
* offset order.
* The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ,
* whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW.
*/
struct nfsclflayout {
LIST_ENTRY(nfsclflayout) nfsfl_list;
uint8_t nfsfl_dev[NFSX_V4DEVICEID];
uint64_t nfsfl_off;
uint64_t nfsfl_end;
uint64_t nfsfl_patoff;
struct nfscldevinfo *nfsfl_devp;
uint32_t nfsfl_iomode;
uint32_t nfsfl_util;
uint32_t nfsfl_stripe1;
uint16_t nfsfl_flags;
uint16_t nfsfl_fhcnt;
struct nfsfh *nfsfl_fh[1]; /* FH list for DS */
};
/*
* Flags for nfsfl_flags.
*/
#define NFSFL_RECALL 0x0001 /* File layout has been recalled */
/*
* Structure that is used to store a LAYOUTRECALL.
*/
struct nfsclrecalllayout {
LIST_ENTRY(nfsclrecalllayout) nfsrecly_list;
uint64_t nfsrecly_off;
uint64_t nfsrecly_len;
int nfsrecly_recalltype;
uint32_t nfsrecly_iomode;
uint32_t nfsrecly_stateseqid;
};
/*
* Stores the NFSv4.1 Device Info. Malloc'd to the correct length to
* store the list of network connections and list of indices.
* nfsdi_data[] is allocated the following way:
* - nfsdi_addrcnt * struct nfsclds
* - stripe indices, each stored as one byte, since there can be many
* of them. (This implies a limit of 256 on nfsdi_addrcnt, since the
* indices select which address.)
*/
struct nfscldevinfo {
LIST_ENTRY(nfscldevinfo) nfsdi_list;
uint8_t nfsdi_deviceid[NFSX_V4DEVICEID];
struct nfsclclient *nfsdi_clp;
uint32_t nfsdi_refcnt;
uint32_t nfsdi_layoutrefs;
uint16_t nfsdi_stripecnt;
uint16_t nfsdi_addrcnt;
struct nfsclds *nfsdi_data[0];
};
/* These inline functions return values from nfsdi_data[]. */
/*
* Return a pointer to the address at "pos".
*/
static __inline struct nfsclds **
nfsfldi_addr(struct nfscldevinfo *ndi, int pos)
{
if (pos >= ndi->nfsdi_addrcnt)
return (NULL);
return (&ndi->nfsdi_data[pos]);
}
/*
* Return the Nth ("pos") stripe index.
*/
static __inline int
nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos)
{
uint8_t *valp;
/*
* Set the Nth ("pos") stripe index to "val".
*/
static __inline void
nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val)
{
uint8_t *valp;