state.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Copyright (c) 2001 The Regents of the University of Michigan.
  3. * All rights reserved.
  4. *
  5. * Kendrick Smith <[email protected]>
  6. * Andy Adamson <[email protected]>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  28. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #ifndef _NFSD4_STATE_H
  35. #define _NFSD4_STATE_H
  36. #include <linux/idr.h>
  37. #include <linux/refcount.h>
  38. #include <linux/sunrpc/svc_xprt.h>
  39. #include "nfsfh.h"
  40. #include "nfsd.h"
  41. typedef struct {
  42. u32 cl_boot;
  43. u32 cl_id;
  44. } clientid_t;
  45. typedef struct {
  46. clientid_t so_clid;
  47. u32 so_id;
  48. } stateid_opaque_t;
  49. typedef struct {
  50. u32 si_generation;
  51. stateid_opaque_t si_opaque;
  52. } stateid_t;
  53. typedef struct {
  54. stateid_t cs_stid;
  55. #define NFS4_COPY_STID 1
  56. #define NFS4_COPYNOTIFY_STID 2
  57. unsigned char cs_type;
  58. refcount_t cs_count;
  59. } copy_stateid_t;
  60. struct nfsd4_callback {
  61. struct nfs4_client *cb_clp;
  62. struct rpc_message cb_msg;
  63. const struct nfsd4_callback_ops *cb_ops;
  64. struct work_struct cb_work;
  65. int cb_seq_status;
  66. int cb_status;
  67. bool cb_need_restart;
  68. bool cb_holds_slot;
  69. };
  70. struct nfsd4_callback_ops {
  71. void (*prepare)(struct nfsd4_callback *);
  72. int (*done)(struct nfsd4_callback *, struct rpc_task *);
  73. void (*release)(struct nfsd4_callback *);
  74. };
  75. /*
  76. * A core object that represents a "common" stateid. These are generally
  77. * embedded within the different (more specific) stateid objects and contain
  78. * fields that are of general use to any stateid.
  79. */
  80. struct nfs4_stid {
  81. refcount_t sc_count;
  82. #define NFS4_OPEN_STID 1
  83. #define NFS4_LOCK_STID 2
  84. #define NFS4_DELEG_STID 4
  85. /* For an open stateid kept around *only* to process close replays: */
  86. #define NFS4_CLOSED_STID 8
  87. /* For a deleg stateid kept around only to process free_stateid's: */
  88. #define NFS4_REVOKED_DELEG_STID 16
  89. #define NFS4_CLOSED_DELEG_STID 32
  90. #define NFS4_LAYOUT_STID 64
  91. struct list_head sc_cp_list;
  92. unsigned char sc_type;
  93. stateid_t sc_stateid;
  94. spinlock_t sc_lock;
  95. struct nfs4_client *sc_client;
  96. struct nfs4_file *sc_file;
  97. void (*sc_free)(struct nfs4_stid *);
  98. };
  99. /* Keep a list of stateids issued by the COPY_NOTIFY, associate it with the
  100. * parent OPEN/LOCK/DELEG stateid.
  101. */
  102. struct nfs4_cpntf_state {
  103. copy_stateid_t cp_stateid;
  104. struct list_head cp_list; /* per parent nfs4_stid */
  105. stateid_t cp_p_stateid; /* copy of parent's stateid */
  106. clientid_t cp_p_clid; /* copy of parent's clid */
  107. time64_t cpntf_time; /* last time stateid used */
  108. };
  109. /*
  110. * Represents a delegation stateid. The nfs4_client holds references to these
  111. * and they are put when it is being destroyed or when the delegation is
  112. * returned by the client:
  113. *
  114. * o 1 reference as long as a delegation is still in force (taken when it's
  115. * alloc'd, put when it's returned or revoked)
  116. *
  117. * o 1 reference as long as a recall rpc is in progress (taken when the lease
  118. * is broken, put when the rpc exits)
  119. *
  120. * o 1 more ephemeral reference for each nfsd thread currently doing something
  121. * with that delegation without holding the cl_lock
  122. *
  123. * If the server attempts to recall a delegation and the client doesn't do so
  124. * before a timeout, the server may also revoke the delegation. In that case,
  125. * the object will either be destroyed (v4.0) or moved to a per-client list of
  126. * revoked delegations (v4.1+).
  127. *
  128. * This object is a superset of the nfs4_stid.
  129. */
  130. struct nfs4_delegation {
  131. struct nfs4_stid dl_stid; /* must be first field */
  132. struct list_head dl_perfile;
  133. struct list_head dl_perclnt;
  134. struct list_head dl_recall_lru; /* delegation recalled */
  135. struct nfs4_clnt_odstate *dl_clnt_odstate;
  136. u32 dl_type;
  137. time64_t dl_time;
  138. /* For recall: */
  139. int dl_retries;
  140. struct nfsd4_callback dl_recall;
  141. bool dl_recalled;
  142. };
  143. #define cb_to_delegation(cb) \
  144. container_of(cb, struct nfs4_delegation, dl_recall)
  145. /* client delegation callback info */
  146. struct nfs4_cb_conn {
  147. /* SETCLIENTID info */
  148. struct sockaddr_storage cb_addr;
  149. struct sockaddr_storage cb_saddr;
  150. size_t cb_addrlen;
  151. u32 cb_prog; /* used only in 4.0 case;
  152. per-session otherwise */
  153. u32 cb_ident; /* minorversion 0 only */
  154. struct svc_xprt *cb_xprt; /* minorversion 1 only */
  155. };
  156. static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
  157. {
  158. return container_of(s, struct nfs4_delegation, dl_stid);
  159. }
  160. /* Maximum number of slots per session. 160 is useful for long haul TCP */
  161. #define NFSD_MAX_SLOTS_PER_SESSION 160
  162. /* Maximum number of operations per session compound */
  163. #define NFSD_MAX_OPS_PER_COMPOUND 50
  164. /* Maximum session per slot cache size */
  165. #define NFSD_SLOT_CACHE_SIZE 2048
  166. /* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */
  167. #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32
  168. #define NFSD_MAX_MEM_PER_SESSION \
  169. (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
  170. struct nfsd4_slot {
  171. u32 sl_seqid;
  172. __be32 sl_status;
  173. struct svc_cred sl_cred;
  174. u32 sl_datalen;
  175. u16 sl_opcnt;
  176. #define NFSD4_SLOT_INUSE (1 << 0)
  177. #define NFSD4_SLOT_CACHETHIS (1 << 1)
  178. #define NFSD4_SLOT_INITIALIZED (1 << 2)
  179. #define NFSD4_SLOT_CACHED (1 << 3)
  180. u8 sl_flags;
  181. char sl_data[];
  182. };
  183. struct nfsd4_channel_attrs {
  184. u32 headerpadsz;
  185. u32 maxreq_sz;
  186. u32 maxresp_sz;
  187. u32 maxresp_cached;
  188. u32 maxops;
  189. u32 maxreqs;
  190. u32 nr_rdma_attrs;
  191. u32 rdma_attrs;
  192. };
  193. struct nfsd4_cb_sec {
  194. u32 flavor; /* (u32)(-1) used to mean "no valid flavor" */
  195. kuid_t uid;
  196. kgid_t gid;
  197. };
  198. struct nfsd4_create_session {
  199. clientid_t clientid;
  200. struct nfs4_sessionid sessionid;
  201. u32 seqid;
  202. u32 flags;
  203. struct nfsd4_channel_attrs fore_channel;
  204. struct nfsd4_channel_attrs back_channel;
  205. u32 callback_prog;
  206. struct nfsd4_cb_sec cb_sec;
  207. };
  208. struct nfsd4_backchannel_ctl {
  209. u32 bc_cb_program;
  210. struct nfsd4_cb_sec bc_cb_sec;
  211. };
  212. struct nfsd4_bind_conn_to_session {
  213. struct nfs4_sessionid sessionid;
  214. u32 dir;
  215. };
  216. /* The single slot clientid cache structure */
  217. struct nfsd4_clid_slot {
  218. u32 sl_seqid;
  219. __be32 sl_status;
  220. struct nfsd4_create_session sl_cr_ses;
  221. };
  222. struct nfsd4_conn {
  223. struct list_head cn_persession;
  224. struct svc_xprt *cn_xprt;
  225. struct svc_xpt_user cn_xpt_user;
  226. struct nfsd4_session *cn_session;
  227. /* CDFC4_FORE, CDFC4_BACK: */
  228. unsigned char cn_flags;
  229. };
  230. /*
  231. * Representation of a v4.1+ session. These are refcounted in a similar fashion
  232. * to the nfs4_client. References are only taken when the server is actively
  233. * working on the object (primarily during the processing of compounds).
  234. */
  235. struct nfsd4_session {
  236. atomic_t se_ref;
  237. struct list_head se_hash; /* hash by sessionid */
  238. struct list_head se_perclnt;
  239. /* See SESSION4_PERSIST, etc. for standard flags; this is internal-only: */
  240. #define NFS4_SESSION_DEAD 0x010
  241. u32 se_flags;
  242. struct nfs4_client *se_client;
  243. struct nfs4_sessionid se_sessionid;
  244. struct nfsd4_channel_attrs se_fchannel;
  245. struct nfsd4_channel_attrs se_bchannel;
  246. struct nfsd4_cb_sec se_cb_sec;
  247. struct list_head se_conns;
  248. u32 se_cb_prog;
  249. u32 se_cb_seq_nr;
  250. struct nfsd4_slot *se_slots[]; /* forward channel slots */
  251. };
  252. /* formatted contents of nfs4_sessionid */
  253. struct nfsd4_sessionid {
  254. clientid_t clientid;
  255. u32 sequence;
  256. u32 reserved;
  257. };
  258. #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
  259. /*
  260. * State Meaning Where set
  261. * --------------------------------------------------------------------------
  262. * | NFSD4_ACTIVE | Confirmed, active | Default |
  263. * |------------------- ----------------------------------------------------|
  264. * | NFSD4_COURTESY | Courtesy state. | nfs4_get_client_reaplist |
  265. * | | Lease/lock/share | |
  266. * | | reservation conflict | |
  267. * | | can cause Courtesy | |
  268. * | | client to be expired | |
  269. * |------------------------------------------------------------------------|
  270. * | NFSD4_EXPIRABLE | Courtesy client to be| nfs4_laundromat |
  271. * | | expired by Laundromat| try_to_expire_client |
  272. * | | due to conflict | |
  273. * |------------------------------------------------------------------------|
  274. */
  275. enum {
  276. NFSD4_ACTIVE = 0,
  277. NFSD4_COURTESY,
  278. NFSD4_EXPIRABLE,
  279. };
  280. /*
  281. * struct nfs4_client - one per client. Clientids live here.
  282. *
  283. * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
  284. * or EXCHANGE_ID (for NFSv4.1+). These objects are refcounted and timestamped.
  285. * Each nfsd_net_ns object contains a set of these and they are tracked via
  286. * short and long form clientid. They are hashed and searched for under the
  287. * per-nfsd_net client_lock spinlock.
  288. *
  289. * References to it are only held during the processing of compounds, and in
  290. * certain other operations. In their "resting state" they have a refcount of
  291. * 0. If they are not renewed within a lease period, they become eligible for
  292. * destruction by the laundromat.
  293. *
  294. * These objects can also be destroyed prematurely by the fault injection code,
  295. * or if the client sends certain forms of SETCLIENTID or EXCHANGE_ID updates.
  296. * Care is taken *not* to do this however when the objects have an elevated
  297. * refcount.
  298. *
  299. * o Each nfs4_client is hashed by clientid
  300. *
  301. * o Each nfs4_clients is also hashed by name (the opaque quantity initially
  302. * sent by the client to identify itself).
  303. *
  304. * o cl_perclient list is used to ensure no dangling stateowner references
  305. * when we expire the nfs4_client
  306. */
  307. struct nfs4_client {
  308. struct list_head cl_idhash; /* hash by cl_clientid.id */
  309. struct rb_node cl_namenode; /* link into by-name trees */
  310. struct list_head *cl_ownerstr_hashtbl;
  311. struct list_head cl_openowners;
  312. struct idr cl_stateids; /* stateid lookup */
  313. struct list_head cl_delegations;
  314. struct list_head cl_revoked; /* unacknowledged, revoked 4.1 state */
  315. struct list_head cl_lru; /* tail queue */
  316. #ifdef CONFIG_NFSD_PNFS
  317. struct list_head cl_lo_states; /* outstanding layout states */
  318. #endif
  319. struct xdr_netobj cl_name; /* id generated by client */
  320. nfs4_verifier cl_verifier; /* generated by client */
  321. time64_t cl_time; /* time of last lease renewal */
  322. struct sockaddr_storage cl_addr; /* client ipaddress */
  323. bool cl_mach_cred; /* SP4_MACH_CRED in force */
  324. struct svc_cred cl_cred; /* setclientid principal */
  325. clientid_t cl_clientid; /* generated by server */
  326. nfs4_verifier cl_confirm; /* generated by server */
  327. u32 cl_minorversion;
  328. /* NFSv4.1 client implementation id: */
  329. struct xdr_netobj cl_nii_domain;
  330. struct xdr_netobj cl_nii_name;
  331. struct timespec64 cl_nii_time;
  332. /* for v4.0 and v4.1 callbacks: */
  333. struct nfs4_cb_conn cl_cb_conn;
  334. #define NFSD4_CLIENT_CB_UPDATE (0)
  335. #define NFSD4_CLIENT_CB_KILL (1)
  336. #define NFSD4_CLIENT_STABLE (2) /* client on stable storage */
  337. #define NFSD4_CLIENT_RECLAIM_COMPLETE (3) /* reclaim_complete done */
  338. #define NFSD4_CLIENT_CONFIRMED (4) /* client is confirmed */
  339. #define NFSD4_CLIENT_UPCALL_LOCK (5) /* upcall serialization */
  340. #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
  341. 1 << NFSD4_CLIENT_CB_KILL)
  342. unsigned long cl_flags;
  343. const struct cred *cl_cb_cred;
  344. struct rpc_clnt *cl_cb_client;
  345. u32 cl_cb_ident;
  346. #define NFSD4_CB_UP 0
  347. #define NFSD4_CB_UNKNOWN 1
  348. #define NFSD4_CB_DOWN 2
  349. #define NFSD4_CB_FAULT 3
  350. int cl_cb_state;
  351. struct nfsd4_callback cl_cb_null;
  352. struct nfsd4_session *cl_cb_session;
  353. /* for all client information that callback code might need: */
  354. spinlock_t cl_lock;
  355. /* for nfs41 */
  356. struct list_head cl_sessions;
  357. struct nfsd4_clid_slot cl_cs_slot; /* create_session slot */
  358. u32 cl_exchange_flags;
  359. /* number of rpc's in progress over an associated session: */
  360. atomic_t cl_rpc_users;
  361. struct nfsdfs_client cl_nfsdfs;
  362. struct nfs4_op_map cl_spo_must_allow;
  363. /* debugging info directory under nfsd/clients/ : */
  364. struct dentry *cl_nfsd_dentry;
  365. /* 'info' file within that directory. Ref is not counted,
  366. * but will remain valid iff cl_nfsd_dentry != NULL
  367. */
  368. struct dentry *cl_nfsd_info_dentry;
  369. /* for nfs41 callbacks */
  370. /* We currently support a single back channel with a single slot */
  371. unsigned long cl_cb_slot_busy;
  372. struct rpc_wait_queue cl_cb_waitq; /* backchannel callers may */
  373. /* wait here for slots */
  374. struct net *net;
  375. struct list_head async_copies; /* list of async copies */
  376. spinlock_t async_lock; /* lock for async copies */
  377. atomic_t cl_cb_inflight; /* Outstanding callbacks */
  378. unsigned int cl_state;
  379. atomic_t cl_delegs_in_recall;
  380. };
  381. /* struct nfs4_client_reset
  382. * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
  383. * upon lease reset, or from upcall to state_daemon (to read in state
  384. * from non-volitile storage) upon reboot.
  385. */
  386. struct nfs4_client_reclaim {
  387. struct list_head cr_strhash; /* hash by cr_name */
  388. struct nfs4_client *cr_clp; /* pointer to associated clp */
  389. struct xdr_netobj cr_name; /* recovery dir name */
  390. struct xdr_netobj cr_princhash;
  391. };
  392. /* A reasonable value for REPLAY_ISIZE was estimated as follows:
  393. * The OPEN response, typically the largest, requires
  394. * 4(status) + 8(stateid) + 20(changeinfo) + 4(rflags) + 8(verifier) +
  395. * 4(deleg. type) + 8(deleg. stateid) + 4(deleg. recall flag) +
  396. * 20(deleg. space limit) + ~32(deleg. ace) = 112 bytes
  397. */
  398. #define NFSD4_REPLAY_ISIZE 112
  399. /*
  400. * Replay buffer, where the result of the last seqid-mutating operation
  401. * is cached.
  402. */
  403. struct nfs4_replay {
  404. __be32 rp_status;
  405. unsigned int rp_buflen;
  406. char *rp_buf;
  407. struct knfsd_fh rp_openfh;
  408. struct mutex rp_mutex;
  409. char rp_ibuf[NFSD4_REPLAY_ISIZE];
  410. };
  411. struct nfs4_stateowner;
  412. struct nfs4_stateowner_operations {
  413. void (*so_unhash)(struct nfs4_stateowner *);
  414. void (*so_free)(struct nfs4_stateowner *);
  415. };
  416. /*
  417. * A core object that represents either an open or lock owner. The object and
  418. * lock owner objects have one of these embedded within them. Refcounts and
  419. * other fields common to both owner types are contained within these
  420. * structures.
  421. */
  422. struct nfs4_stateowner {
  423. struct list_head so_strhash;
  424. struct list_head so_stateids;
  425. struct nfs4_client *so_client;
  426. const struct nfs4_stateowner_operations *so_ops;
  427. /* after increment in nfsd4_bump_seqid, represents the next
  428. * sequence id expected from the client: */
  429. atomic_t so_count;
  430. u32 so_seqid;
  431. struct xdr_netobj so_owner; /* open owner name */
  432. struct nfs4_replay so_replay;
  433. bool so_is_open_owner;
  434. };
  435. /*
  436. * When a file is opened, the client provides an open state owner opaque string
  437. * that indicates the "owner" of that open. These objects are refcounted.
  438. * References to it are held by each open state associated with it. This object
  439. * is a superset of the nfs4_stateowner struct.
  440. */
  441. struct nfs4_openowner {
  442. struct nfs4_stateowner oo_owner; /* must be first field */
  443. struct list_head oo_perclient;
  444. /*
  445. * We keep around openowners a little while after last close,
  446. * which saves clients from having to confirm, and allows us to
  447. * handle close replays if they come soon enough. The close_lru
  448. * is a list of such openowners, to be reaped by the laundromat
  449. * thread eventually if they remain unused:
  450. */
  451. struct list_head oo_close_lru;
  452. struct nfs4_ol_stateid *oo_last_closed_stid;
  453. time64_t oo_time; /* time of placement on so_close_lru */
  454. #define NFS4_OO_CONFIRMED 1
  455. unsigned char oo_flags;
  456. };
  457. /*
  458. * Represents a generic "lockowner". Similar to an openowner. References to it
  459. * are held by the lock stateids that are created on its behalf. This object is
  460. * a superset of the nfs4_stateowner struct.
  461. */
  462. struct nfs4_lockowner {
  463. struct nfs4_stateowner lo_owner; /* must be first element */
  464. struct list_head lo_blocked; /* blocked file_locks */
  465. };
  466. static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
  467. {
  468. return container_of(so, struct nfs4_openowner, oo_owner);
  469. }
  470. static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
  471. {
  472. return container_of(so, struct nfs4_lockowner, lo_owner);
  473. }
  474. /*
  475. * Per-client state indicating no. of opens and outstanding delegations
  476. * on a file from a particular client.'od' stands for 'open & delegation'
  477. */
  478. struct nfs4_clnt_odstate {
  479. struct nfs4_client *co_client;
  480. struct nfs4_file *co_file;
  481. struct list_head co_perfile;
  482. refcount_t co_odcount;
  483. };
  484. /*
  485. * nfs4_file: a file opened by some number of (open) nfs4_stateowners.
  486. *
  487. * These objects are global. nfsd keeps one instance of a nfs4_file per
  488. * filehandle (though it may keep multiple file descriptors for each). Each
  489. * inode can have multiple filehandles associated with it, so there is
  490. * (potentially) a many to one relationship between this struct and struct
  491. * inode.
  492. *
  493. * These are hashed by filehandle in the file_hashtbl, which is protected by
  494. * the global state_lock spinlock.
  495. */
  496. struct nfs4_file {
  497. refcount_t fi_ref;
  498. struct inode * fi_inode;
  499. bool fi_aliased;
  500. spinlock_t fi_lock;
  501. struct hlist_node fi_hash; /* hash on fi_fhandle */
  502. struct list_head fi_stateids;
  503. union {
  504. struct list_head fi_delegations;
  505. struct rcu_head fi_rcu;
  506. };
  507. struct list_head fi_clnt_odstate;
  508. /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
  509. struct nfsd_file *fi_fds[3];
  510. /*
  511. * Each open or lock stateid contributes 0-4 to the counts
  512. * below depending on which bits are set in st_access_bitmap:
  513. * 1 to fi_access[O_RDONLY] if NFS4_SHARE_ACCES_READ is set
  514. * + 1 to fi_access[O_WRONLY] if NFS4_SHARE_ACCESS_WRITE is set
  515. * + 1 to both of the above if NFS4_SHARE_ACCESS_BOTH is set.
  516. */
  517. atomic_t fi_access[2];
  518. u32 fi_share_deny;
  519. struct nfsd_file *fi_deleg_file;
  520. int fi_delegees;
  521. struct knfsd_fh fi_fhandle;
  522. bool fi_had_conflict;
  523. #ifdef CONFIG_NFSD_PNFS
  524. struct list_head fi_lo_states;
  525. atomic_t fi_lo_recalls;
  526. #endif
  527. };
  528. /*
  529. * A generic struct representing either a open or lock stateid. The nfs4_client
  530. * holds a reference to each of these objects, and they in turn hold a
  531. * reference to their respective stateowners. The client's reference is
  532. * released in response to a close or unlock (depending on whether it's an open
  533. * or lock stateid) or when the client is being destroyed.
  534. *
  535. * In the case of v4.0 open stateids, these objects are preserved for a little
  536. * while after close in order to handle CLOSE replays. Those are eventually
  537. * reclaimed via a LRU scheme by the laundromat.
  538. *
  539. * This object is a superset of the nfs4_stid. "ol" stands for "Open or Lock".
  540. * Better suggestions welcome.
  541. */
  542. struct nfs4_ol_stateid {
  543. struct nfs4_stid st_stid;
  544. struct list_head st_perfile;
  545. struct list_head st_perstateowner;
  546. struct list_head st_locks;
  547. struct nfs4_stateowner *st_stateowner;
  548. struct nfs4_clnt_odstate *st_clnt_odstate;
  549. /*
  550. * These bitmasks use 3 separate bits for READ, ALLOW, and BOTH; see the
  551. * comment above bmap_to_share_mode() for explanation:
  552. */
  553. unsigned char st_access_bmap;
  554. unsigned char st_deny_bmap;
  555. struct nfs4_ol_stateid *st_openstp;
  556. struct mutex st_mutex;
  557. };
  558. static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
  559. {
  560. return container_of(s, struct nfs4_ol_stateid, st_stid);
  561. }
  562. struct nfs4_layout_stateid {
  563. struct nfs4_stid ls_stid;
  564. struct list_head ls_perclnt;
  565. struct list_head ls_perfile;
  566. spinlock_t ls_lock;
  567. struct list_head ls_layouts;
  568. u32 ls_layout_type;
  569. struct nfsd_file *ls_file;
  570. struct nfsd4_callback ls_recall;
  571. stateid_t ls_recall_sid;
  572. bool ls_recalled;
  573. struct mutex ls_mutex;
  574. };
  575. static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
  576. {
  577. return container_of(s, struct nfs4_layout_stateid, ls_stid);
  578. }
  579. /* flags for preprocess_seqid_op() */
  580. #define RD_STATE 0x00000010
  581. #define WR_STATE 0x00000020
  582. enum nfsd4_cb_op {
  583. NFSPROC4_CLNT_CB_NULL = 0,
  584. NFSPROC4_CLNT_CB_RECALL,
  585. NFSPROC4_CLNT_CB_LAYOUT,
  586. NFSPROC4_CLNT_CB_OFFLOAD,
  587. NFSPROC4_CLNT_CB_SEQUENCE,
  588. NFSPROC4_CLNT_CB_NOTIFY_LOCK,
  589. };
  590. /* Returns true iff a is later than b: */
  591. static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
  592. {
  593. return (s32)(a->si_generation - b->si_generation) > 0;
  594. }
  595. /*
  596. * When a client tries to get a lock on a file, we set one of these objects
  597. * on the blocking lock. When the lock becomes free, we can then issue a
  598. * CB_NOTIFY_LOCK to the server.
  599. */
  600. struct nfsd4_blocked_lock {
  601. struct list_head nbl_list;
  602. struct list_head nbl_lru;
  603. time64_t nbl_time;
  604. struct file_lock nbl_lock;
  605. struct knfsd_fh nbl_fh;
  606. struct nfsd4_callback nbl_cb;
  607. struct kref nbl_kref;
  608. };
  609. struct nfsd4_compound_state;
  610. struct nfsd_net;
  611. struct nfsd4_copy;
  612. extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
  613. struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
  614. stateid_t *stateid, int flags, struct nfsd_file **filp,
  615. struct nfs4_stid **cstid);
  616. __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
  617. stateid_t *stateid, unsigned char typemask,
  618. struct nfs4_stid **s, struct nfsd_net *nn);
  619. struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
  620. void (*sc_free)(struct nfs4_stid *));
  621. int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
  622. void nfs4_free_copy_state(struct nfsd4_copy *copy);
  623. struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
  624. struct nfs4_stid *p_stid);
  625. void nfs4_unhash_stid(struct nfs4_stid *s);
  626. void nfs4_put_stid(struct nfs4_stid *s);
  627. void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
  628. void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
  629. extern void nfs4_release_reclaim(struct nfsd_net *);
  630. extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
  631. struct nfsd_net *nn);
  632. extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
  633. extern void nfsd4_probe_callback(struct nfs4_client *clp);
  634. extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
  635. extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
  636. extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
  637. const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
  638. extern bool nfsd4_run_cb(struct nfsd4_callback *cb);
  639. extern int nfsd4_create_callback_queue(void);
  640. extern void nfsd4_destroy_callback_queue(void);
  641. extern void nfsd4_shutdown_callback(struct nfs4_client *);
  642. extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
  643. extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
  644. struct xdr_netobj princhash, struct nfsd_net *nn);
  645. extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
  646. void put_nfs4_file(struct nfs4_file *fi);
  647. extern struct nfsd4_copy *
  648. find_async_copy(struct nfs4_client *clp, stateid_t *staetid);
  649. extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
  650. struct nfs4_cpntf_state *cps);
  651. extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
  652. struct nfs4_client *clp,
  653. struct nfs4_cpntf_state **cps);
  654. static inline void get_nfs4_file(struct nfs4_file *fi)
  655. {
  656. refcount_inc(&fi->fi_ref);
  657. }
  658. struct nfsd_file *find_any_file(struct nfs4_file *f);
  659. /* grace period management */
  660. void nfsd4_end_grace(struct nfsd_net *nn);
  661. /* nfs4recover operations */
  662. extern int nfsd4_client_tracking_init(struct net *net);
  663. extern void nfsd4_client_tracking_exit(struct net *net);
  664. extern void nfsd4_client_record_create(struct nfs4_client *clp);
  665. extern void nfsd4_client_record_remove(struct nfs4_client *clp);
  666. extern int nfsd4_client_record_check(struct nfs4_client *clp);
  667. extern void nfsd4_record_grace_done(struct nfsd_net *nn);
  668. static inline bool try_to_expire_client(struct nfs4_client *clp)
  669. {
  670. cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
  671. return clp->cl_state == NFSD4_EXPIRABLE;
  672. }
  673. #endif /* NFSD4_STATE_H */