Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * per net namespace data structures for nfsd
0004  *
0005  * Copyright (C) 2012, Jeff Layton <jlayton@redhat.com>
0006  */
0007 
0008 #ifndef __NFSD_NETNS_H__
0009 #define __NFSD_NETNS_H__
0010 
0011 #include <net/net_namespace.h>
0012 #include <net/netns/generic.h>
0013 #include <linux/percpu_counter.h>
0014 #include <linux/siphash.h>
0015 
0016 /* Hash tables for nfs4_clientid state */
0017 #define CLIENT_HASH_BITS                 4
0018 #define CLIENT_HASH_SIZE                (1 << CLIENT_HASH_BITS)
0019 #define CLIENT_HASH_MASK                (CLIENT_HASH_SIZE - 1)
0020 
0021 #define SESSION_HASH_SIZE   512
0022 
0023 struct cld_net;
0024 struct nfsd4_client_tracking_ops;
0025 
0026 enum {
0027     /* cache misses due only to checksum comparison failures */
0028     NFSD_NET_PAYLOAD_MISSES,
0029     /* amount of memory (in bytes) currently consumed by the DRC */
0030     NFSD_NET_DRC_MEM_USAGE,
0031     NFSD_NET_COUNTERS_NUM
0032 };
0033 
0034 /*
0035  * Represents a nfsd "container". With respect to nfsv4 state tracking, the
0036  * fields of interest are the *_id_hashtbls and the *_name_tree. These track
0037  * the nfs4_client objects by either short or long form clientid.
0038  *
0039  * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
0040  * up expired clients and delegations within the container.
0041  */
0042 struct nfsd_net {
0043     struct cld_net *cld_net;
0044 
0045     struct cache_detail *svc_expkey_cache;
0046     struct cache_detail *svc_export_cache;
0047 
0048     struct cache_detail *idtoname_cache;
0049     struct cache_detail *nametoid_cache;
0050 
0051     struct lock_manager nfsd4_manager;
0052     bool grace_ended;
0053     time64_t boot_time;
0054 
0055     struct dentry *nfsd_client_dir;
0056 
0057     /*
0058      * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
0059      * used in reboot/reset lease grace period processing
0060      *
0061      * conf_id_hashtbl[], and conf_name_tree hold confirmed
0062      * setclientid_confirmed info.
0063      *
0064      * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
0065      * setclientid info.
0066      */
0067     struct list_head *reclaim_str_hashtbl;
0068     int reclaim_str_hashtbl_size;
0069     struct list_head *conf_id_hashtbl;
0070     struct rb_root conf_name_tree;
0071     struct list_head *unconf_id_hashtbl;
0072     struct rb_root unconf_name_tree;
0073     struct list_head *sessionid_hashtbl;
0074     /*
0075      * client_lru holds client queue ordered by nfs4_client.cl_time
0076      * for lease renewal.
0077      *
0078      * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
0079      * for last close replay.
0080      *
0081      * All of the above fields are protected by the client_mutex.
0082      */
0083     struct list_head client_lru;
0084     struct list_head close_lru;
0085     struct list_head del_recall_lru;
0086 
0087     /* protected by blocked_locks_lock */
0088     struct list_head blocked_locks_lru;
0089 
0090     struct delayed_work laundromat_work;
0091 
0092     /* client_lock protects the client lru list and session hash table */
0093     spinlock_t client_lock;
0094 
0095     /* protects blocked_locks_lru */
0096     spinlock_t blocked_locks_lock;
0097 
0098     struct file *rec_file;
0099     bool in_grace;
0100     const struct nfsd4_client_tracking_ops *client_tracking_ops;
0101 
0102     time64_t nfsd4_lease;
0103     time64_t nfsd4_grace;
0104     bool somebody_reclaimed;
0105 
0106     bool track_reclaim_completes;
0107     atomic_t nr_reclaim_complete;
0108 
0109     bool nfsd_net_up;
0110     bool lockd_up;
0111 
0112     seqlock_t writeverf_lock;
0113     unsigned char writeverf[8];
0114 
0115     /*
0116      * Max number of connections this nfsd container will allow. Defaults
0117      * to '0' which is means that it bases this on the number of threads.
0118      */
0119     unsigned int max_connections;
0120 
0121     u32 clientid_base;
0122     u32 clientid_counter;
0123     u32 clverifier_counter;
0124 
0125     struct svc_serv *nfsd_serv;
0126     /* When a listening socket is added to nfsd, keep_active is set
0127      * and this justifies a reference on nfsd_serv.  This stops
0128      * nfsd_serv from being freed.  When the number of threads is
0129      * set, keep_active is cleared and the reference is dropped.  So
0130      * when the last thread exits, the service will be destroyed.
0131      */
0132     int keep_active;
0133 
0134     /*
0135      * clientid and stateid data for construction of net unique COPY
0136      * stateids.
0137      */
0138     u32     s2s_cp_cl_id;
0139     struct idr  s2s_cp_stateids;
0140     spinlock_t  s2s_cp_lock;
0141 
0142     /*
0143      * Version information
0144      */
0145     bool *nfsd_versions;
0146     bool *nfsd4_minorversions;
0147 
0148     /*
0149      * Duplicate reply cache
0150      */
0151     struct nfsd_drc_bucket   *drc_hashtbl;
0152 
0153     /* max number of entries allowed in the cache */
0154     unsigned int             max_drc_entries;
0155 
0156     /* number of significant bits in the hash value */
0157     unsigned int             maskbits;
0158     unsigned int             drc_hashsize;
0159 
0160     /*
0161      * Stats and other tracking of on the duplicate reply cache.
0162      * The longest_chain* fields are modified with only the per-bucket
0163      * cache lock, which isn't really safe and should be fixed if we want
0164      * these statistics to be completely accurate.
0165      */
0166 
0167     /* total number of entries */
0168     atomic_t                 num_drc_entries;
0169 
0170     /* Per-netns stats counters */
0171     struct percpu_counter    counter[NFSD_NET_COUNTERS_NUM];
0172 
0173     /* longest hash chain seen */
0174     unsigned int             longest_chain;
0175 
0176     /* size of cache when we saw the longest hash chain */
0177     unsigned int             longest_chain_cachesize;
0178 
0179     struct shrinker     nfsd_reply_cache_shrinker;
0180 
0181     /* tracking server-to-server copy mounts */
0182     spinlock_t              nfsd_ssc_lock;
0183     struct list_head        nfsd_ssc_mount_list;
0184     wait_queue_head_t       nfsd_ssc_waitq;
0185 
0186     /* utsname taken from the process that starts the server */
0187     char            nfsd_name[UNX_MAXNODENAME+1];
0188 
0189     struct nfsd_fcache_disposal *fcache_disposal;
0190 
0191     siphash_key_t       siphash_key;
0192 
0193     atomic_t        nfs4_client_count;
0194     int         nfs4_max_clients;
0195 };
0196 
0197 /* Simple check to find out if a given net was properly initialized */
0198 #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
0199 
0200 extern void nfsd_netns_free_versions(struct nfsd_net *nn);
0201 
0202 extern unsigned int nfsd_net_id;
0203 
0204 void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn);
0205 void nfsd_reset_write_verifier(struct nfsd_net *nn);
0206 #endif /* __NFSD_NETNS_H__ */