nfs_fs.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 <uapi/linux/nfs_fs.h>
  11. /*
  12. * Enable dprintk() debugging support for nfs client.
  13. */
  14. #ifdef CONFIG_NFS_DEBUG
  15. # define NFS_DEBUG
  16. #endif
  17. #include <linux/in.h>
  18. #include <linux/mm.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/rbtree.h>
  21. #include <linux/rwsem.h>
  22. #include <linux/wait.h>
  23. #include <linux/sunrpc/debug.h>
  24. #include <linux/sunrpc/auth.h>
  25. #include <linux/sunrpc/clnt.h>
  26. #include <linux/nfs.h>
  27. #include <linux/nfs2.h>
  28. #include <linux/nfs3.h>
  29. #include <linux/nfs4.h>
  30. #include <linux/nfs_xdr.h>
  31. #include <linux/nfs_fs_sb.h>
  32. #include <linux/mempool.h>
  33. /*
  34. * These are the default flags for swap requests
  35. */
  36. #define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
  37. /*
  38. * NFSv3/v4 Access mode cache entry
  39. */
  40. struct nfs_access_entry {
  41. struct rb_node rb_node;
  42. struct list_head lru;
  43. unsigned long jiffies;
  44. struct rpc_cred * cred;
  45. int mask;
  46. struct rcu_head rcu_head;
  47. };
  48. struct nfs_lockowner {
  49. fl_owner_t l_owner;
  50. pid_t l_pid;
  51. };
  52. #define NFS_IO_INPROGRESS 0
  53. struct nfs_io_counter {
  54. unsigned long flags;
  55. atomic_t io_count;
  56. };
  57. struct nfs_lock_context {
  58. atomic_t count;
  59. struct list_head list;
  60. struct nfs_open_context *open_context;
  61. struct nfs_lockowner lockowner;
  62. struct nfs_io_counter io_count;
  63. };
  64. struct nfs4_state;
  65. struct nfs_open_context {
  66. struct nfs_lock_context lock_context;
  67. struct dentry *dentry;
  68. struct rpc_cred *cred;
  69. struct nfs4_state *state;
  70. fmode_t mode;
  71. unsigned long flags;
  72. #define NFS_CONTEXT_ERROR_WRITE (0)
  73. #define NFS_CONTEXT_RESEND_WRITES (1)
  74. #define NFS_CONTEXT_BAD (2)
  75. int error;
  76. struct list_head list;
  77. struct nfs4_threshold *mdsthreshold;
  78. };
  79. struct nfs_open_dir_context {
  80. struct list_head list;
  81. struct rpc_cred *cred;
  82. unsigned long attr_gencount;
  83. __u64 dir_cookie;
  84. __u64 dup_cookie;
  85. signed char duped;
  86. };
  87. /*
  88. * NFSv4 delegation
  89. */
  90. struct nfs_delegation;
  91. struct posix_acl;
  92. /*
  93. * nfs fs inode data in memory
  94. */
  95. struct nfs_inode {
  96. /*
  97. * The 64bit 'inode number'
  98. */
  99. __u64 fileid;
  100. /*
  101. * NFS file handle
  102. */
  103. struct nfs_fh fh;
  104. /*
  105. * Various flags
  106. */
  107. unsigned long flags; /* atomic bit ops */
  108. unsigned long cache_validity; /* bit mask */
  109. /*
  110. * read_cache_jiffies is when we started read-caching this inode.
  111. * attrtimeo is for how long the cached information is assumed
  112. * to be valid. A successful attribute revalidation doubles
  113. * attrtimeo (up to acregmax/acdirmax), a failure resets it to
  114. * acregmin/acdirmin.
  115. *
  116. * We need to revalidate the cached attrs for this inode if
  117. *
  118. * jiffies - read_cache_jiffies >= attrtimeo
  119. *
  120. * Please note the comparison is greater than or equal
  121. * so that zero timeout values can be specified.
  122. */
  123. unsigned long read_cache_jiffies;
  124. unsigned long attrtimeo;
  125. unsigned long attrtimeo_timestamp;
  126. unsigned long attr_gencount;
  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. struct rb_root access_cache;
  133. struct list_head access_cache_entry_lru;
  134. struct list_head access_cache_inode_lru;
  135. /*
  136. * This is the cookie verifier used for NFSv3 readdir
  137. * operations
  138. */
  139. __be32 cookieverf[2];
  140. unsigned long nrequests;
  141. struct nfs_mds_commit_info commit_info;
  142. /* Open contexts for shared mmap writes */
  143. struct list_head open_files;
  144. /* Number of in-flight sillydelete RPC calls */
  145. atomic_t silly_count;
  146. /* List of deferred sillydelete requests */
  147. struct hlist_head silly_list;
  148. wait_queue_head_t waitqueue;
  149. #if IS_ENABLED(CONFIG_NFS_V4)
  150. struct nfs4_cached_acl *nfs4_acl;
  151. /* NFSv4 state */
  152. struct list_head open_states;
  153. struct nfs_delegation __rcu *delegation;
  154. struct rw_semaphore rwsem;
  155. /* pNFS layout information */
  156. struct pnfs_layout_hdr *layout;
  157. #endif /* CONFIG_NFS_V4*/
  158. /* how many bytes have been written/read and how many bytes queued up */
  159. __u64 write_io;
  160. __u64 read_io;
  161. #ifdef CONFIG_NFS_FSCACHE
  162. struct fscache_cookie *fscache;
  163. #endif
  164. struct inode vfs_inode;
  165. };
  166. /*
  167. * Cache validity bit flags
  168. */
  169. #define NFS_INO_INVALID_ATTR 0x0001 /* cached attrs are invalid */
  170. #define NFS_INO_INVALID_DATA 0x0002 /* cached data is invalid */
  171. #define NFS_INO_INVALID_ATIME 0x0004 /* cached atime is invalid */
  172. #define NFS_INO_INVALID_ACCESS 0x0008 /* cached access cred invalid */
  173. #define NFS_INO_INVALID_ACL 0x0010 /* cached acls are invalid */
  174. #define NFS_INO_REVAL_PAGECACHE 0x0020 /* must revalidate pagecache */
  175. #define NFS_INO_REVAL_FORCED 0x0040 /* force revalidation ignoring a delegation */
  176. #define NFS_INO_INVALID_LABEL 0x0080 /* cached label is invalid */
  177. /*
  178. * Bit offsets in flags field
  179. */
  180. #define NFS_INO_ADVISE_RDPLUS (0) /* advise readdirplus */
  181. #define NFS_INO_STALE (1) /* possible stale inode */
  182. #define NFS_INO_ACL_LRU_SET (2) /* Inode is on the LRU list */
  183. #define NFS_INO_INVALIDATING (3) /* inode is being invalidated */
  184. #define NFS_INO_FLUSHING (4) /* inode is flushing out data */
  185. #define NFS_INO_FSCACHE (5) /* inode can be cached by FS-Cache */
  186. #define NFS_INO_FSCACHE_LOCK (6) /* FS-Cache cookie management lock */
  187. #define NFS_INO_COMMIT (7) /* inode is committing unstable writes */
  188. #define NFS_INO_LAYOUTCOMMIT (9) /* layoutcommit required */
  189. #define NFS_INO_LAYOUTCOMMITTING (10) /* layoutcommit inflight */
  190. #define NFS_INO_LAYOUTSTATS (11) /* layoutstats inflight */
  191. static inline struct nfs_inode *NFS_I(const struct inode *inode)
  192. {
  193. return container_of(inode, struct nfs_inode, vfs_inode);
  194. }
  195. static inline struct nfs_server *NFS_SB(const struct super_block *s)
  196. {
  197. return (struct nfs_server *)(s->s_fs_info);
  198. }
  199. static inline struct nfs_fh *NFS_FH(const struct inode *inode)
  200. {
  201. return &NFS_I(inode)->fh;
  202. }
  203. static inline struct nfs_server *NFS_SERVER(const struct inode *inode)
  204. {
  205. return NFS_SB(inode->i_sb);
  206. }
  207. static inline struct rpc_clnt *NFS_CLIENT(const struct inode *inode)
  208. {
  209. return NFS_SERVER(inode)->client;
  210. }
  211. static inline const struct nfs_rpc_ops *NFS_PROTO(const struct inode *inode)
  212. {
  213. return NFS_SERVER(inode)->nfs_client->rpc_ops;
  214. }
  215. static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode)
  216. {
  217. struct nfs_server *nfss = NFS_SERVER(inode);
  218. return S_ISDIR(inode->i_mode) ? nfss->acdirmin : nfss->acregmin;
  219. }
  220. static inline unsigned NFS_MAXATTRTIMEO(const struct inode *inode)
  221. {
  222. struct nfs_server *nfss = NFS_SERVER(inode);
  223. return S_ISDIR(inode->i_mode) ? nfss->acdirmax : nfss->acregmax;
  224. }
  225. static inline int NFS_STALE(const struct inode *inode)
  226. {
  227. return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
  228. }
  229. static inline struct fscache_cookie *nfs_i_fscache(struct inode *inode)
  230. {
  231. #ifdef CONFIG_NFS_FSCACHE
  232. return NFS_I(inode)->fscache;
  233. #else
  234. return NULL;
  235. #endif
  236. }
  237. static inline __u64 NFS_FILEID(const struct inode *inode)
  238. {
  239. return NFS_I(inode)->fileid;
  240. }
  241. static inline void set_nfs_fileid(struct inode *inode, __u64 fileid)
  242. {
  243. NFS_I(inode)->fileid = fileid;
  244. }
  245. static inline void nfs_mark_for_revalidate(struct inode *inode)
  246. {
  247. struct nfs_inode *nfsi = NFS_I(inode);
  248. spin_lock(&inode->i_lock);
  249. nfsi->cache_validity |= NFS_INO_INVALID_ATTR |
  250. NFS_INO_REVAL_PAGECACHE |
  251. NFS_INO_INVALID_ACCESS |
  252. NFS_INO_INVALID_ACL;
  253. if (S_ISDIR(inode->i_mode))
  254. nfsi->cache_validity |= NFS_INO_INVALID_DATA;
  255. spin_unlock(&inode->i_lock);
  256. }
  257. static inline int nfs_server_capable(struct inode *inode, int cap)
  258. {
  259. return NFS_SERVER(inode)->caps & cap;
  260. }
  261. static inline void nfs_set_verifier(struct dentry * dentry, unsigned long verf)
  262. {
  263. dentry->d_time = verf;
  264. }
  265. /**
  266. * nfs_save_change_attribute - Returns the inode attribute change cookie
  267. * @dir - pointer to parent directory inode
  268. * The "change attribute" is updated every time we finish an operation
  269. * that will result in a metadata change on the server.
  270. */
  271. static inline unsigned long nfs_save_change_attribute(struct inode *dir)
  272. {
  273. return NFS_I(dir)->cache_change_attribute;
  274. }
  275. /**
  276. * nfs_verify_change_attribute - Detects NFS remote directory changes
  277. * @dir - pointer to parent directory inode
  278. * @chattr - previously saved change attribute
  279. * Return "false" if the verifiers doesn't match the change attribute.
  280. * This would usually indicate that the directory contents have changed on
  281. * the server, and that any dentries need revalidating.
  282. */
  283. static inline int nfs_verify_change_attribute(struct inode *dir, unsigned long chattr)
  284. {
  285. return chattr == NFS_I(dir)->cache_change_attribute;
  286. }
  287. /*
  288. * linux/fs/nfs/inode.c
  289. */
  290. extern int nfs_sync_mapping(struct address_space *mapping);
  291. extern void nfs_zap_mapping(struct inode *inode, struct address_space *mapping);
  292. extern void nfs_zap_caches(struct inode *);
  293. extern void nfs_invalidate_atime(struct inode *);
  294. extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
  295. struct nfs_fattr *, struct nfs4_label *);
  296. extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
  297. extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
  298. extern int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr);
  299. extern int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr);
  300. extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  301. extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *);
  302. extern void nfs_access_set_mask(struct nfs_access_entry *, u32);
  303. extern int nfs_permission(struct inode *, int);
  304. extern int nfs_open(struct inode *, struct file *);
  305. extern int nfs_attribute_timeout(struct inode *inode);
  306. extern int nfs_attribute_cache_expired(struct inode *inode);
  307. extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);
  308. extern int nfs_revalidate_inode_rcu(struct nfs_server *server, struct inode *inode);
  309. extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
  310. extern int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
  311. extern int nfs_revalidate_mapping_protected(struct inode *inode, struct address_space *mapping);
  312. extern int nfs_setattr(struct dentry *, struct iattr *);
  313. extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, struct nfs_fattr *);
  314. extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
  315. struct nfs4_label *label);
  316. extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
  317. extern void put_nfs_open_context(struct nfs_open_context *ctx);
  318. extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode);
  319. extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode);
  320. extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx);
  321. extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
  322. extern void nfs_file_clear_open_context(struct file *flip);
  323. extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx);
  324. extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx);
  325. extern u64 nfs_compat_user_ino64(u64 fileid);
  326. extern void nfs_fattr_init(struct nfs_fattr *fattr);
  327. extern void nfs_fattr_set_barrier(struct nfs_fattr *fattr);
  328. extern unsigned long nfs_inc_attr_generation_counter(void);
  329. extern struct nfs_fattr *nfs_alloc_fattr(void);
  330. static inline void nfs_free_fattr(const struct nfs_fattr *fattr)
  331. {
  332. kfree(fattr);
  333. }
  334. extern struct nfs_fh *nfs_alloc_fhandle(void);
  335. static inline void nfs_free_fhandle(const struct nfs_fh *fh)
  336. {
  337. kfree(fh);
  338. }
  339. #ifdef NFS_DEBUG
  340. extern u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh);
  341. static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
  342. {
  343. return _nfs_display_fhandle_hash(fh);
  344. }
  345. extern void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption);
  346. #define nfs_display_fhandle(fh, caption) \
  347. do { \
  348. if (unlikely(nfs_debug & NFSDBG_FACILITY)) \
  349. _nfs_display_fhandle(fh, caption); \
  350. } while (0)
  351. #else
  352. static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
  353. {
  354. return 0;
  355. }
  356. static inline void nfs_display_fhandle(const struct nfs_fh *fh,
  357. const char *caption)
  358. {
  359. }
  360. #endif
  361. /*
  362. * linux/fs/nfs/nfsroot.c
  363. */
  364. extern int nfs_root_data(char **root_device, char **root_data); /*__init*/
  365. /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
  366. extern __be32 root_nfs_parse_addr(char *name); /*__init*/
  367. /*
  368. * linux/fs/nfs/file.c
  369. */
  370. extern const struct file_operations nfs_file_operations;
  371. #if IS_ENABLED(CONFIG_NFS_V4)
  372. extern const struct file_operations nfs4_file_operations;
  373. #endif /* CONFIG_NFS_V4 */
  374. extern const struct address_space_operations nfs_file_aops;
  375. extern const struct address_space_operations nfs_dir_aops;
  376. static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
  377. {
  378. return filp->private_data;
  379. }
  380. static inline struct rpc_cred *nfs_file_cred(struct file *file)
  381. {
  382. if (file != NULL) {
  383. struct nfs_open_context *ctx =
  384. nfs_file_open_context(file);
  385. if (ctx)
  386. return ctx->cred;
  387. }
  388. return NULL;
  389. }
  390. /*
  391. * linux/fs/nfs/direct.c
  392. */
  393. extern ssize_t nfs_direct_IO(struct kiocb *, struct iov_iter *, loff_t);
  394. extern ssize_t nfs_file_direct_read(struct kiocb *iocb,
  395. struct iov_iter *iter,
  396. loff_t pos);
  397. extern ssize_t nfs_file_direct_write(struct kiocb *iocb,
  398. struct iov_iter *iter);
  399. /*
  400. * linux/fs/nfs/dir.c
  401. */
  402. extern const struct file_operations nfs_dir_operations;
  403. extern const struct dentry_operations nfs_dentry_operations;
  404. extern void nfs_force_lookup_revalidate(struct inode *dir);
  405. extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh,
  406. struct nfs_fattr *fattr, struct nfs4_label *label);
  407. extern int nfs_may_open(struct inode *inode, struct rpc_cred *cred, int openflags);
  408. extern void nfs_access_zap_cache(struct inode *inode);
  409. /*
  410. * linux/fs/nfs/symlink.c
  411. */
  412. extern const struct inode_operations nfs_symlink_inode_operations;
  413. /*
  414. * linux/fs/nfs/sysctl.c
  415. */
  416. #ifdef CONFIG_SYSCTL
  417. extern int nfs_register_sysctl(void);
  418. extern void nfs_unregister_sysctl(void);
  419. #else
  420. #define nfs_register_sysctl() 0
  421. #define nfs_unregister_sysctl() do { } while(0)
  422. #endif
  423. /*
  424. * linux/fs/nfs/namespace.c
  425. */
  426. extern const struct inode_operations nfs_mountpoint_inode_operations;
  427. extern const struct inode_operations nfs_referral_inode_operations;
  428. extern int nfs_mountpoint_expiry_timeout;
  429. extern void nfs_release_automount_timer(void);
  430. /*
  431. * linux/fs/nfs/unlink.c
  432. */
  433. extern void nfs_complete_unlink(struct dentry *dentry, struct inode *);
  434. extern void nfs_wait_on_sillyrename(struct dentry *dentry);
  435. extern void nfs_block_sillyrename(struct dentry *dentry);
  436. extern void nfs_unblock_sillyrename(struct dentry *dentry);
  437. /*
  438. * linux/fs/nfs/write.c
  439. */
  440. extern int nfs_congestion_kb;
  441. extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
  442. extern int nfs_writepages(struct address_space *, struct writeback_control *);
  443. extern int nfs_flush_incompatible(struct file *file, struct page *page);
  444. extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
  445. /*
  446. * Try to write back everything synchronously (but check the
  447. * return value!)
  448. */
  449. extern int nfs_sync_inode(struct inode *inode);
  450. extern int nfs_wb_all(struct inode *inode);
  451. extern int nfs_wb_page(struct inode *inode, struct page* page);
  452. extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
  453. extern int nfs_commit_inode(struct inode *, int);
  454. extern struct nfs_commit_data *nfs_commitdata_alloc(void);
  455. extern void nfs_commit_free(struct nfs_commit_data *data);
  456. static inline int
  457. nfs_have_writebacks(struct inode *inode)
  458. {
  459. return NFS_I(inode)->nrequests != 0;
  460. }
  461. /*
  462. * linux/fs/nfs/read.c
  463. */
  464. extern int nfs_readpage(struct file *, struct page *);
  465. extern int nfs_readpages(struct file *, struct address_space *,
  466. struct list_head *, unsigned);
  467. extern int nfs_readpage_async(struct nfs_open_context *, struct inode *,
  468. struct page *);
  469. /*
  470. * inline functions
  471. */
  472. static inline loff_t nfs_size_to_loff_t(__u64 size)
  473. {
  474. return min_t(u64, size, OFFSET_MAX);
  475. }
  476. static inline ino_t
  477. nfs_fileid_to_ino_t(u64 fileid)
  478. {
  479. ino_t ino = (ino_t) fileid;
  480. if (sizeof(ino_t) < sizeof(u64))
  481. ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
  482. return ino;
  483. }
  484. #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
  485. # undef ifdebug
  486. # ifdef NFS_DEBUG
  487. # define ifdebug(fac) if (unlikely(nfs_debug & NFSDBG_##fac))
  488. # define NFS_IFDEBUG(x) x
  489. # else
  490. # define ifdebug(fac) if (0)
  491. # define NFS_IFDEBUG(x)
  492. # endif
  493. #endif