nfs_fs.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /*
  2. * linux/include/linux/nfs_fs.h
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * OS-specific nfs filesystem definitions and declarations
  7. */
  8. #ifndef _LINUX_NFS_FS_H
  9. #define _LINUX_NFS_FS_H
  10. #include <linux/config.h>
  11. #include <linux/in.h>
  12. #include <linux/mm.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/rwsem.h>
  15. #include <linux/wait.h>
  16. #include <linux/uio.h>
  17. #include <linux/nfs_fs_sb.h>
  18. #include <linux/sunrpc/debug.h>
  19. #include <linux/sunrpc/auth.h>
  20. #include <linux/sunrpc/clnt.h>
  21. #include <linux/nfs.h>
  22. #include <linux/nfs2.h>
  23. #include <linux/nfs3.h>
  24. #include <linux/nfs4.h>
  25. #include <linux/nfs_xdr.h>
  26. #include <linux/rwsem.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/mempool.h>
  29. /*
  30. * Enable debugging support for nfs client.
  31. * Requires RPC_DEBUG.
  32. */
  33. #ifdef RPC_DEBUG
  34. # define NFS_DEBUG
  35. #endif
  36. #define NFS_MAX_FILE_IO_BUFFER_SIZE 32768
  37. #define NFS_DEF_FILE_IO_BUFFER_SIZE 4096
  38. /*
  39. * The upper limit on timeouts for the exponential backoff algorithm.
  40. */
  41. #define NFS_WRITEBACK_DELAY (5*HZ)
  42. #define NFS_WRITEBACK_LOCKDELAY (60*HZ)
  43. #define NFS_COMMIT_DELAY (5*HZ)
  44. /*
  45. * superblock magic number for NFS
  46. */
  47. #define NFS_SUPER_MAGIC 0x6969
  48. /*
  49. * These are the default flags for swap requests
  50. */
  51. #define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
  52. #define NFS_RW_SYNC 0x0001 /* O_SYNC handling */
  53. #define NFS_RW_SWAP 0x0002 /* This is a swap request */
  54. /*
  55. * When flushing a cluster of dirty pages, there can be different
  56. * strategies:
  57. */
  58. #define FLUSH_AGING 0 /* only flush old buffers */
  59. #define FLUSH_SYNC 1 /* file being synced, or contention */
  60. #define FLUSH_WAIT 2 /* wait for completion */
  61. #define FLUSH_STABLE 4 /* commit to stable storage */
  62. #define FLUSH_LOWPRI 8 /* low priority background flush */
  63. #define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
  64. #ifdef __KERNEL__
  65. /*
  66. * NFSv3/v4 Access mode cache entry
  67. */
  68. struct nfs_access_entry {
  69. unsigned long jiffies;
  70. struct rpc_cred * cred;
  71. int mask;
  72. };
  73. struct nfs4_state;
  74. struct nfs_open_context {
  75. atomic_t count;
  76. struct dentry *dentry;
  77. struct rpc_cred *cred;
  78. struct nfs4_state *state;
  79. fl_owner_t lockowner;
  80. int mode;
  81. int error;
  82. struct list_head list;
  83. wait_queue_head_t waitq;
  84. };
  85. /*
  86. * NFSv4 delegation
  87. */
  88. struct nfs_delegation;
  89. /*
  90. * nfs fs inode data in memory
  91. */
  92. struct nfs_inode {
  93. /*
  94. * The 64bit 'inode number'
  95. */
  96. __u64 fileid;
  97. /*
  98. * NFS file handle
  99. */
  100. struct nfs_fh fh;
  101. /*
  102. * Various flags
  103. */
  104. unsigned int flags;
  105. /*
  106. * read_cache_jiffies is when we started read-caching this inode,
  107. * and read_cache_mtime is the mtime of the inode at that time.
  108. * attrtimeo is for how long the cached information is assumed
  109. * to be valid. A successful attribute revalidation doubles
  110. * attrtimeo (up to acregmax/acdirmax), a failure resets it to
  111. * acregmin/acdirmin.
  112. *
  113. * We need to revalidate the cached attrs for this inode if
  114. *
  115. * jiffies - read_cache_jiffies > attrtimeo
  116. *
  117. * and invalidate any cached data/flush out any dirty pages if
  118. * we find that
  119. *
  120. * mtime != read_cache_mtime
  121. */
  122. unsigned long readdir_timestamp;
  123. unsigned long read_cache_jiffies;
  124. unsigned long attrtimeo;
  125. unsigned long attrtimeo_timestamp;
  126. __u64 change_attr; /* v4 only */
  127. /* "Generation counter" for the attribute cache. This is
  128. * bumped whenever we update the metadata on the
  129. * server.
  130. */
  131. unsigned long cache_change_attribute;
  132. /*
  133. * Counter indicating the number of outstanding requests that
  134. * will cause a file data update.
  135. */
  136. atomic_t data_updates;
  137. struct nfs_access_entry cache_access;
  138. /*
  139. * This is the cookie verifier used for NFSv3 readdir
  140. * operations
  141. */
  142. __u32 cookieverf[2];
  143. /*
  144. * This is the list of dirty unwritten pages.
  145. */
  146. spinlock_t req_lock;
  147. struct list_head dirty;
  148. struct list_head commit;
  149. struct radix_tree_root nfs_page_tree;
  150. unsigned int ndirty,
  151. ncommit,
  152. npages;
  153. /* Open contexts for shared mmap writes */
  154. struct list_head open_files;
  155. wait_queue_head_t nfs_i_wait;
  156. #ifdef CONFIG_NFS_V4
  157. /* NFSv4 state */
  158. struct list_head open_states;
  159. struct nfs_delegation *delegation;
  160. int delegation_state;
  161. struct rw_semaphore rwsem;
  162. #endif /* CONFIG_NFS_V4*/
  163. struct inode vfs_inode;
  164. };
  165. /*
  166. * Legal inode flag values
  167. */
  168. #define NFS_INO_STALE 0x0001 /* possible stale inode */
  169. #define NFS_INO_ADVISE_RDPLUS 0x0002 /* advise readdirplus */
  170. #define NFS_INO_REVALIDATING 0x0004 /* revalidating attrs */
  171. #define NFS_INO_INVALID_ATTR 0x0008 /* cached attrs are invalid */
  172. #define NFS_INO_INVALID_DATA 0x0010 /* cached data is invalid */
  173. #define NFS_INO_INVALID_ATIME 0x0020 /* cached atime is invalid */
  174. #define NFS_INO_INVALID_ACCESS 0x0040 /* cached access cred invalid */
  175. static inline struct nfs_inode *NFS_I(struct inode *inode)
  176. {
  177. return container_of(inode, struct nfs_inode, vfs_inode);
  178. }
  179. #define NFS_SB(s) ((struct nfs_server *)(s->s_fs_info))
  180. #define NFS_FH(inode) (&NFS_I(inode)->fh)
  181. #define NFS_SERVER(inode) (NFS_SB(inode->i_sb))
  182. #define NFS_CLIENT(inode) (NFS_SERVER(inode)->client)
  183. #define NFS_PROTO(inode) (NFS_SERVER(inode)->rpc_ops)
  184. #define NFS_ADDR(inode) (RPC_PEERADDR(NFS_CLIENT(inode)))
  185. #define NFS_COOKIEVERF(inode) (NFS_I(inode)->cookieverf)
  186. #define NFS_READTIME(inode) (NFS_I(inode)->read_cache_jiffies)
  187. #define NFS_CHANGE_ATTR(inode) (NFS_I(inode)->change_attr)
  188. #define NFS_ATTRTIMEO(inode) (NFS_I(inode)->attrtimeo)
  189. #define NFS_MINATTRTIMEO(inode) \
  190. (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmin \
  191. : NFS_SERVER(inode)->acregmin)
  192. #define NFS_MAXATTRTIMEO(inode) \
  193. (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmax \
  194. : NFS_SERVER(inode)->acregmax)
  195. #define NFS_ATTRTIMEO_UPDATE(inode) (NFS_I(inode)->attrtimeo_timestamp)
  196. #define NFS_FLAGS(inode) (NFS_I(inode)->flags)
  197. #define NFS_REVALIDATING(inode) (NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
  198. #define NFS_STALE(inode) (NFS_FLAGS(inode) & NFS_INO_STALE)
  199. #define NFS_FILEID(inode) (NFS_I(inode)->fileid)
  200. static inline int nfs_caches_unstable(struct inode *inode)
  201. {
  202. return atomic_read(&NFS_I(inode)->data_updates) != 0;
  203. }
  204. static inline void NFS_CACHEINV(struct inode *inode)
  205. {
  206. if (!nfs_caches_unstable(inode))
  207. NFS_FLAGS(inode) |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
  208. }
  209. static inline int nfs_server_capable(struct inode *inode, int cap)
  210. {
  211. return NFS_SERVER(inode)->caps & cap;
  212. }
  213. static inline int NFS_USE_READDIRPLUS(struct inode *inode)
  214. {
  215. return NFS_FLAGS(inode) & NFS_INO_ADVISE_RDPLUS;
  216. }
  217. /**
  218. * nfs_save_change_attribute - Returns the inode attribute change cookie
  219. * @inode - pointer to inode
  220. * The "change attribute" is updated every time we finish an operation
  221. * that will result in a metadata change on the server.
  222. */
  223. static inline long nfs_save_change_attribute(struct inode *inode)
  224. {
  225. return NFS_I(inode)->cache_change_attribute;
  226. }
  227. /**
  228. * nfs_verify_change_attribute - Detects NFS inode cache updates
  229. * @inode - pointer to inode
  230. * @chattr - previously saved change attribute
  231. * Return "false" if metadata has been updated (or is in the process of
  232. * being updated) since the change attribute was saved.
  233. */
  234. static inline int nfs_verify_change_attribute(struct inode *inode, unsigned long chattr)
  235. {
  236. return !nfs_caches_unstable(inode)
  237. && chattr == NFS_I(inode)->cache_change_attribute;
  238. }
  239. /*
  240. * linux/fs/nfs/inode.c
  241. */
  242. extern void nfs_zap_caches(struct inode *);
  243. extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
  244. struct nfs_fattr *);
  245. extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
  246. extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  247. extern int nfs_permission(struct inode *, int, struct nameidata *);
  248. extern int nfs_access_get_cached(struct inode *, struct rpc_cred *, struct nfs_access_entry *);
  249. extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *);
  250. extern int nfs_open(struct inode *, struct file *);
  251. extern int nfs_release(struct inode *, struct file *);
  252. extern int nfs_attribute_timeout(struct inode *inode);
  253. extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);
  254. extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
  255. extern int nfs_setattr(struct dentry *, struct iattr *);
  256. extern void nfs_begin_attr_update(struct inode *);
  257. extern void nfs_end_attr_update(struct inode *);
  258. extern void nfs_begin_data_update(struct inode *);
  259. extern void nfs_end_data_update(struct inode *);
  260. extern void nfs_end_data_update_defer(struct inode *);
  261. extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred);
  262. extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
  263. extern void put_nfs_open_context(struct nfs_open_context *ctx);
  264. extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
  265. extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, int mode);
  266. extern void nfs_file_clear_open_context(struct file *filp);
  267. /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
  268. extern u32 root_nfs_parse_addr(char *name); /*__init*/
  269. /*
  270. * linux/fs/nfs/file.c
  271. */
  272. extern struct inode_operations nfs_file_inode_operations;
  273. extern struct file_operations nfs_file_operations;
  274. extern struct address_space_operations nfs_file_aops;
  275. static inline struct rpc_cred *nfs_file_cred(struct file *file)
  276. {
  277. if (file != NULL) {
  278. struct nfs_open_context *ctx;
  279. ctx = (struct nfs_open_context*)file->private_data;
  280. return ctx->cred;
  281. }
  282. return NULL;
  283. }
  284. /*
  285. * linux/fs/nfs/direct.c
  286. */
  287. extern ssize_t nfs_direct_IO(int, struct kiocb *, const struct iovec *, loff_t,
  288. unsigned long);
  289. extern ssize_t nfs_file_direct_read(struct kiocb *iocb, char __user *buf,
  290. size_t count, loff_t pos);
  291. extern ssize_t nfs_file_direct_write(struct kiocb *iocb, const char __user *buf,
  292. size_t count, loff_t pos);
  293. /*
  294. * linux/fs/nfs/dir.c
  295. */
  296. extern struct inode_operations nfs_dir_inode_operations;
  297. extern struct file_operations nfs_dir_operations;
  298. extern struct dentry_operations nfs_dentry_operations;
  299. extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr);
  300. /*
  301. * linux/fs/nfs/symlink.c
  302. */
  303. extern struct inode_operations nfs_symlink_inode_operations;
  304. /*
  305. * linux/fs/nfs/unlink.c
  306. */
  307. extern int nfs_async_unlink(struct dentry *);
  308. extern void nfs_complete_unlink(struct dentry *);
  309. /*
  310. * linux/fs/nfs/write.c
  311. */
  312. extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
  313. extern int nfs_writepages(struct address_space *, struct writeback_control *);
  314. extern int nfs_flush_incompatible(struct file *file, struct page *page);
  315. extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
  316. extern void nfs_writeback_done(struct rpc_task *task);
  317. #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
  318. extern void nfs_commit_done(struct rpc_task *);
  319. #endif
  320. /*
  321. * Try to write back everything synchronously (but check the
  322. * return value!)
  323. */
  324. extern int nfs_sync_inode(struct inode *, unsigned long, unsigned int, int);
  325. #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
  326. extern int nfs_commit_inode(struct inode *, unsigned long, unsigned int, int);
  327. #else
  328. static inline int
  329. nfs_commit_inode(struct inode *inode, unsigned long idx_start, unsigned int npages, int how)
  330. {
  331. return 0;
  332. }
  333. #endif
  334. static inline int
  335. nfs_have_writebacks(struct inode *inode)
  336. {
  337. return NFS_I(inode)->npages != 0;
  338. }
  339. static inline int
  340. nfs_wb_all(struct inode *inode)
  341. {
  342. int error = nfs_sync_inode(inode, 0, 0, FLUSH_WAIT);
  343. return (error < 0) ? error : 0;
  344. }
  345. /*
  346. * Write back all requests on one page - we do this before reading it.
  347. */
  348. static inline int nfs_wb_page_priority(struct inode *inode, struct page* page, int how)
  349. {
  350. int error = nfs_sync_inode(inode, page->index, 1,
  351. how | FLUSH_WAIT | FLUSH_STABLE);
  352. return (error < 0) ? error : 0;
  353. }
  354. static inline int nfs_wb_page(struct inode *inode, struct page* page)
  355. {
  356. return nfs_wb_page_priority(inode, page, 0);
  357. }
  358. /*
  359. * Allocate and free nfs_write_data structures
  360. */
  361. extern mempool_t *nfs_wdata_mempool;
  362. static inline struct nfs_write_data *nfs_writedata_alloc(void)
  363. {
  364. struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, SLAB_NOFS);
  365. if (p) {
  366. memset(p, 0, sizeof(*p));
  367. INIT_LIST_HEAD(&p->pages);
  368. }
  369. return p;
  370. }
  371. static inline void nfs_writedata_free(struct nfs_write_data *p)
  372. {
  373. mempool_free(p, nfs_wdata_mempool);
  374. }
  375. /* Hack for future NFS swap support */
  376. #ifndef IS_SWAPFILE
  377. # define IS_SWAPFILE(inode) (0)
  378. #endif
  379. /*
  380. * linux/fs/nfs/read.c
  381. */
  382. extern int nfs_readpage(struct file *, struct page *);
  383. extern int nfs_readpages(struct file *, struct address_space *,
  384. struct list_head *, unsigned);
  385. extern void nfs_readpage_result(struct rpc_task *);
  386. /*
  387. * Allocate and free nfs_read_data structures
  388. */
  389. extern mempool_t *nfs_rdata_mempool;
  390. static inline struct nfs_read_data *nfs_readdata_alloc(void)
  391. {
  392. struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, SLAB_NOFS);
  393. if (p)
  394. memset(p, 0, sizeof(*p));
  395. return p;
  396. }
  397. static inline void nfs_readdata_free(struct nfs_read_data *p)
  398. {
  399. mempool_free(p, nfs_rdata_mempool);
  400. }
  401. extern void nfs_readdata_release(struct rpc_task *task);
  402. /*
  403. * linux/fs/mount_clnt.c
  404. * (Used only by nfsroot module)
  405. */
  406. extern int nfsroot_mount(struct sockaddr_in *, char *, struct nfs_fh *,
  407. int, int);
  408. /*
  409. * inline functions
  410. */
  411. static inline loff_t
  412. nfs_size_to_loff_t(__u64 size)
  413. {
  414. loff_t maxsz = (((loff_t) ULONG_MAX) << PAGE_CACHE_SHIFT) + PAGE_CACHE_SIZE - 1;
  415. if (size > maxsz)
  416. return maxsz;
  417. return (loff_t) size;
  418. }
  419. static inline ino_t
  420. nfs_fileid_to_ino_t(u64 fileid)
  421. {
  422. ino_t ino = (ino_t) fileid;
  423. if (sizeof(ino_t) < sizeof(u64))
  424. ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
  425. return ino;
  426. }
  427. /* NFS root */
  428. extern void * nfs_root_data(void);
  429. #define nfs_wait_event(clnt, wq, condition) \
  430. ({ \
  431. int __retval = 0; \
  432. if (clnt->cl_intr) { \
  433. sigset_t oldmask; \
  434. rpc_clnt_sigmask(clnt, &oldmask); \
  435. __retval = wait_event_interruptible(wq, condition); \
  436. rpc_clnt_sigunmask(clnt, &oldmask); \
  437. } else \
  438. wait_event(wq, condition); \
  439. __retval; \
  440. })
  441. #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
  442. #ifdef CONFIG_NFS_V4
  443. struct idmap;
  444. /*
  445. * In a seqid-mutating op, this macro controls which error return
  446. * values trigger incrementation of the seqid.
  447. *
  448. * from rfc 3010:
  449. * The client MUST monotonically increment the sequence number for the
  450. * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
  451. * operations. This is true even in the event that the previous
  452. * operation that used the sequence number received an error. The only
  453. * exception to this rule is if the previous operation received one of
  454. * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
  455. * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
  456. * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
  457. *
  458. */
  459. #define seqid_mutating_err(err) \
  460. (((err) != NFSERR_STALE_CLIENTID) && \
  461. ((err) != NFSERR_STALE_STATEID) && \
  462. ((err) != NFSERR_BAD_STATEID) && \
  463. ((err) != NFSERR_BAD_SEQID) && \
  464. ((err) != NFSERR_BAD_XDR) && \
  465. ((err) != NFSERR_RESOURCE) && \
  466. ((err) != NFSERR_NOFILEHANDLE))
  467. enum nfs4_client_state {
  468. NFS4CLNT_OK = 0,
  469. };
  470. /*
  471. * The nfs4_client identifies our client state to the server.
  472. */
  473. struct nfs4_client {
  474. struct list_head cl_servers; /* Global list of servers */
  475. struct in_addr cl_addr; /* Server identifier */
  476. u64 cl_clientid; /* constant */
  477. nfs4_verifier cl_confirm;
  478. unsigned long cl_state;
  479. u32 cl_lockowner_id;
  480. /*
  481. * The following rwsem ensures exclusive access to the server
  482. * while we recover the state following a lease expiration.
  483. */
  484. struct rw_semaphore cl_sem;
  485. struct list_head cl_delegations;
  486. struct list_head cl_state_owners;
  487. struct list_head cl_unused;
  488. int cl_nunused;
  489. spinlock_t cl_lock;
  490. atomic_t cl_count;
  491. struct rpc_clnt * cl_rpcclient;
  492. struct rpc_cred * cl_cred;
  493. struct list_head cl_superblocks; /* List of nfs_server structs */
  494. unsigned long cl_lease_time;
  495. unsigned long cl_last_renewal;
  496. struct work_struct cl_renewd;
  497. struct work_struct cl_recoverd;
  498. wait_queue_head_t cl_waitq;
  499. struct rpc_wait_queue cl_rpcwaitq;
  500. /* used for the setclientid verifier */
  501. struct timespec cl_boot_time;
  502. /* idmapper */
  503. struct idmap * cl_idmap;
  504. /* Our own IP address, as a null-terminated string.
  505. * This is used to generate the clientid, and the callback address.
  506. */
  507. char cl_ipaddr[16];
  508. unsigned char cl_id_uniquifier;
  509. };
  510. /*
  511. * NFS4 state_owners and lock_owners are simply labels for ordered
  512. * sequences of RPC calls. Their sole purpose is to provide once-only
  513. * semantics by allowing the server to identify replayed requests.
  514. *
  515. * The ->so_sema is held during all state_owner seqid-mutating operations:
  516. * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
  517. * so_seqid.
  518. */
  519. struct nfs4_state_owner {
  520. struct list_head so_list; /* per-clientid list of state_owners */
  521. struct nfs4_client *so_client;
  522. u32 so_id; /* 32-bit identifier, unique */
  523. struct semaphore so_sema;
  524. u32 so_seqid; /* protected by so_sema */
  525. atomic_t so_count;
  526. struct rpc_cred *so_cred; /* Associated cred */
  527. struct list_head so_states;
  528. struct list_head so_delegations;
  529. };
  530. /*
  531. * struct nfs4_state maintains the client-side state for a given
  532. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  533. *
  534. * OPEN:
  535. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  536. * we need to know how many files are open for reading or writing on a
  537. * given inode. This information too is stored here.
  538. *
  539. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  540. */
  541. struct nfs4_lock_state {
  542. struct list_head ls_locks; /* Other lock stateids */
  543. fl_owner_t ls_owner; /* POSIX lock owner */
  544. #define NFS_LOCK_INITIALIZED 1
  545. int ls_flags;
  546. u32 ls_seqid;
  547. u32 ls_id;
  548. nfs4_stateid ls_stateid;
  549. atomic_t ls_count;
  550. };
  551. /* bits for nfs4_state->flags */
  552. enum {
  553. LK_STATE_IN_USE,
  554. NFS_DELEGATED_STATE,
  555. };
  556. struct nfs4_state {
  557. struct list_head open_states; /* List of states for the same state_owner */
  558. struct list_head inode_states; /* List of states for the same inode */
  559. struct list_head lock_states; /* List of subservient lock stateids */
  560. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  561. struct inode *inode; /* Pointer to the inode */
  562. unsigned long flags; /* Do we hold any locks? */
  563. struct semaphore lock_sema; /* Serializes file locking operations */
  564. rwlock_t state_lock; /* Protects the lock_states list */
  565. nfs4_stateid stateid;
  566. unsigned int nreaders;
  567. unsigned int nwriters;
  568. int state; /* State on the server (R,W, or RW) */
  569. atomic_t count;
  570. };
  571. struct nfs4_exception {
  572. long timeout;
  573. int retry;
  574. };
  575. struct nfs4_state_recovery_ops {
  576. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  577. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  578. };
  579. extern struct dentry_operations nfs4_dentry_operations;
  580. extern struct inode_operations nfs4_dir_inode_operations;
  581. /* nfs4proc.c */
  582. extern int nfs4_map_errors(int err);
  583. extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
  584. extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
  585. extern int nfs4_proc_async_renew(struct nfs4_client *);
  586. extern int nfs4_proc_renew(struct nfs4_client *);
  587. extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode);
  588. extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
  589. extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
  590. extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
  591. extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
  592. /* nfs4renewd.c */
  593. extern void nfs4_schedule_state_renewal(struct nfs4_client *);
  594. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  595. extern void nfs4_kill_renewd(struct nfs4_client *);
  596. /* nfs4state.c */
  597. extern void init_nfsv4_state(struct nfs_server *);
  598. extern void destroy_nfsv4_state(struct nfs_server *);
  599. extern struct nfs4_client *nfs4_get_client(struct in_addr *);
  600. extern void nfs4_put_client(struct nfs4_client *clp);
  601. extern int nfs4_init_client(struct nfs4_client *clp);
  602. extern struct nfs4_client *nfs4_find_client(struct in_addr *);
  603. extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
  604. extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
  605. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  606. extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
  607. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  608. extern void nfs4_put_open_state(struct nfs4_state *);
  609. extern void nfs4_close_state(struct nfs4_state *, mode_t);
  610. extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
  611. extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp);
  612. extern void nfs4_schedule_state_recovery(struct nfs4_client *);
  613. extern struct nfs4_lock_state *nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t);
  614. extern struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t);
  615. extern void nfs4_put_lock_state(struct nfs4_lock_state *state);
  616. extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls);
  617. extern void nfs4_notify_setlk(struct nfs4_state *, struct file_lock *, struct nfs4_lock_state *);
  618. extern void nfs4_notify_unlck(struct nfs4_state *, struct file_lock *, struct nfs4_lock_state *);
  619. extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
  620. struct nfs4_mount_data;
  621. #else
  622. #define init_nfsv4_state(server) do { } while (0)
  623. #define destroy_nfsv4_state(server) do { } while (0)
  624. #define nfs4_put_state_owner(inode, owner) do { } while (0)
  625. #define nfs4_put_open_state(state) do { } while (0)
  626. #define nfs4_close_state(a, b) do { } while (0)
  627. #define nfs4_renewd_prepare_shutdown(server) do { } while (0)
  628. #endif
  629. #endif /* __KERNEL__ */
  630. /*
  631. * NFS debug flags
  632. */
  633. #define NFSDBG_VFS 0x0001
  634. #define NFSDBG_DIRCACHE 0x0002
  635. #define NFSDBG_LOOKUPCACHE 0x0004
  636. #define NFSDBG_PAGECACHE 0x0008
  637. #define NFSDBG_PROC 0x0010
  638. #define NFSDBG_XDR 0x0020
  639. #define NFSDBG_FILE 0x0040
  640. #define NFSDBG_ROOT 0x0080
  641. #define NFSDBG_CALLBACK 0x0100
  642. #define NFSDBG_ALL 0xFFFF
  643. #ifdef __KERNEL__
  644. # undef ifdebug
  645. # ifdef NFS_DEBUG
  646. # define ifdebug(fac) if (unlikely(nfs_debug & NFSDBG_##fac))
  647. # else
  648. # define ifdebug(fac) if (0)
  649. # endif
  650. #endif /* __KERNEL */
  651. #endif