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