pnfs.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * pNFS client data structures.
  3. *
  4. * Copyright (c) 2002
  5. * The Regents of the University of Michigan
  6. * All Rights Reserved
  7. *
  8. * Dean Hildebrand <dhildebz@umich.edu>
  9. *
  10. * Permission is granted to use, copy, create derivative works, and
  11. * redistribute this software and such derivative works for any purpose,
  12. * so long as the name of the University of Michigan is not used in
  13. * any advertising or publicity pertaining to the use or distribution
  14. * of this software without specific, written prior authorization. If
  15. * the above copyright notice or any other identification of the
  16. * University of Michigan is included in any copy of any portion of
  17. * this software, then the disclaimer below must also be included.
  18. *
  19. * This software is provided as is, without representation or warranty
  20. * of any kind either express or implied, including without limitation
  21. * the implied warranties of merchantability, fitness for a particular
  22. * purpose, or noninfringement. The Regents of the University of
  23. * Michigan shall not be liable for any damages, including special,
  24. * indirect, incidental, or consequential damages, with respect to any
  25. * claim arising out of or in connection with the use of the software,
  26. * even if it has been or is hereafter advised of the possibility of
  27. * such damages.
  28. */
  29. #ifndef FS_NFS_PNFS_H
  30. #define FS_NFS_PNFS_H
  31. #include <linux/refcount.h>
  32. #include <linux/nfs_fs.h>
  33. #include <linux/nfs_page.h>
  34. #include <linux/workqueue.h>
  35. struct nfs4_opendata;
  36. enum {
  37. NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */
  38. NFS_LSEG_ROC, /* roc bit received from server */
  39. NFS_LSEG_LAYOUTCOMMIT, /* layoutcommit bit set for layoutcommit */
  40. NFS_LSEG_LAYOUTRETURN, /* layoutreturn bit set for layoutreturn */
  41. NFS_LSEG_UNAVAILABLE, /* unavailable bit set for temporary problem */
  42. };
  43. /* Individual ip address */
  44. struct nfs4_pnfs_ds_addr {
  45. struct sockaddr_storage da_addr;
  46. size_t da_addrlen;
  47. struct list_head da_node; /* nfs4_pnfs_dev_hlist dev_dslist */
  48. char *da_remotestr; /* human readable addr+port */
  49. };
  50. struct nfs4_pnfs_ds {
  51. struct list_head ds_node; /* nfs4_pnfs_dev_hlist dev_dslist */
  52. char *ds_remotestr; /* comma sep list of addrs */
  53. struct list_head ds_addrs;
  54. struct nfs_client *ds_clp;
  55. refcount_t ds_count;
  56. unsigned long ds_state;
  57. #define NFS4DS_CONNECTING 0 /* ds is establishing connection */
  58. };
  59. struct pnfs_layout_segment {
  60. struct list_head pls_list;
  61. struct list_head pls_lc_list;
  62. struct pnfs_layout_range pls_range;
  63. refcount_t pls_refcount;
  64. u32 pls_seq;
  65. unsigned long pls_flags;
  66. struct pnfs_layout_hdr *pls_layout;
  67. };
  68. enum pnfs_try_status {
  69. PNFS_ATTEMPTED = 0,
  70. PNFS_NOT_ATTEMPTED = 1,
  71. PNFS_TRY_AGAIN = 2,
  72. };
  73. #ifdef CONFIG_NFS_V4_1
  74. #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4"
  75. /*
  76. * Default data server connection timeout and retrans vaules.
  77. * Set by module parameters dataserver_timeo and dataserver_retrans.
  78. */
  79. #define NFS4_DEF_DS_TIMEO 600 /* in tenths of a second */
  80. #define NFS4_DEF_DS_RETRANS 5
  81. #define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
  82. /* error codes for internal use */
  83. #define NFS4ERR_RESET_TO_MDS 12001
  84. #define NFS4ERR_RESET_TO_PNFS 12002
  85. enum {
  86. NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */
  87. NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */
  88. NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */
  89. NFS_LAYOUT_RETURN, /* layoutreturn in progress */
  90. NFS_LAYOUT_RETURN_LOCK, /* Serialise layoutreturn */
  91. NFS_LAYOUT_RETURN_REQUESTED, /* Return this layout ASAP */
  92. NFS_LAYOUT_INVALID_STID, /* layout stateid id is invalid */
  93. NFS_LAYOUT_FIRST_LAYOUTGET, /* Serialize first layoutget */
  94. NFS_LAYOUT_INODE_FREEING, /* The inode is being freed */
  95. };
  96. enum layoutdriver_policy_flags {
  97. /* Should the pNFS client commit and return the layout upon truncate to
  98. * a smaller size */
  99. PNFS_LAYOUTRET_ON_SETATTR = 1 << 0,
  100. PNFS_LAYOUTRET_ON_ERROR = 1 << 1,
  101. PNFS_READ_WHOLE_PAGE = 1 << 2,
  102. PNFS_LAYOUTGET_ON_OPEN = 1 << 3,
  103. };
  104. struct nfs4_deviceid_node;
  105. /* Per-layout driver specific registration structure */
  106. struct pnfs_layoutdriver_type {
  107. struct list_head pnfs_tblid;
  108. const u32 id;
  109. const char *name;
  110. struct module *owner;
  111. unsigned flags;
  112. unsigned max_deviceinfo_size;
  113. int (*set_layoutdriver) (struct nfs_server *, const struct nfs_fh *);
  114. int (*clear_layoutdriver) (struct nfs_server *);
  115. struct pnfs_layout_hdr * (*alloc_layout_hdr) (struct inode *inode, gfp_t gfp_flags);
  116. void (*free_layout_hdr) (struct pnfs_layout_hdr *);
  117. struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
  118. void (*free_lseg) (struct pnfs_layout_segment *lseg);
  119. void (*add_lseg) (struct pnfs_layout_hdr *layoutid,
  120. struct pnfs_layout_segment *lseg,
  121. struct list_head *free_me);
  122. void (*return_range) (struct pnfs_layout_hdr *lo,
  123. struct pnfs_layout_range *range);
  124. /* test for nfs page cache coalescing */
  125. const struct nfs_pageio_ops *pg_read_ops;
  126. const struct nfs_pageio_ops *pg_write_ops;
  127. struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode);
  128. void (*mark_request_commit) (struct nfs_page *req,
  129. struct pnfs_layout_segment *lseg,
  130. struct nfs_commit_info *cinfo,
  131. u32 ds_commit_idx);
  132. void (*clear_request_commit) (struct nfs_page *req,
  133. struct nfs_commit_info *cinfo);
  134. int (*scan_commit_lists) (struct nfs_commit_info *cinfo,
  135. int max);
  136. void (*recover_commit_reqs) (struct list_head *list,
  137. struct nfs_commit_info *cinfo);
  138. struct nfs_page * (*search_commit_reqs)(struct nfs_commit_info *cinfo,
  139. struct page *page);
  140. int (*commit_pagelist)(struct inode *inode,
  141. struct list_head *mds_pages,
  142. int how,
  143. struct nfs_commit_info *cinfo);
  144. int (*sync)(struct inode *inode, bool datasync);
  145. /*
  146. * Return PNFS_ATTEMPTED to indicate the layout code has attempted
  147. * I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS
  148. */
  149. enum pnfs_try_status (*read_pagelist)(struct nfs_pgio_header *);
  150. enum pnfs_try_status (*write_pagelist)(struct nfs_pgio_header *, int);
  151. void (*free_deviceid_node) (struct nfs4_deviceid_node *);
  152. struct nfs4_deviceid_node * (*alloc_deviceid_node)
  153. (struct nfs_server *server, struct pnfs_device *pdev,
  154. gfp_t gfp_flags);
  155. int (*prepare_layoutreturn) (struct nfs4_layoutreturn_args *);
  156. void (*cleanup_layoutcommit) (struct nfs4_layoutcommit_data *data);
  157. int (*prepare_layoutcommit) (struct nfs4_layoutcommit_args *args);
  158. int (*prepare_layoutstats) (struct nfs42_layoutstat_args *args);
  159. };
  160. struct pnfs_layout_hdr {
  161. refcount_t plh_refcount;
  162. atomic_t plh_outstanding; /* number of RPCs out */
  163. struct list_head plh_layouts; /* other client layouts */
  164. struct list_head plh_bulk_destroy;
  165. struct list_head plh_segs; /* layout segments list */
  166. struct list_head plh_return_segs; /* invalid layout segments */
  167. unsigned long plh_block_lgets; /* block LAYOUTGET if >0 */
  168. unsigned long plh_retry_timestamp;
  169. unsigned long plh_flags;
  170. nfs4_stateid plh_stateid;
  171. u32 plh_barrier; /* ignore lower seqids */
  172. u32 plh_return_seq;
  173. enum pnfs_iomode plh_return_iomode;
  174. loff_t plh_lwb; /* last write byte for layoutcommit */
  175. struct rpc_cred *plh_lc_cred; /* layoutcommit cred */
  176. struct inode *plh_inode;
  177. };
  178. struct pnfs_device {
  179. struct nfs4_deviceid dev_id;
  180. unsigned int layout_type;
  181. unsigned int mincount;
  182. unsigned int maxcount; /* gdia_maxcount */
  183. struct page **pages;
  184. unsigned int pgbase;
  185. unsigned int pglen; /* reply buffer length */
  186. unsigned char nocache : 1;/* May not be cached */
  187. };
  188. #define NFS4_PNFS_GETDEVLIST_MAXNUM 16
  189. struct pnfs_devicelist {
  190. unsigned int eof;
  191. unsigned int num_devs;
  192. struct nfs4_deviceid dev_id[NFS4_PNFS_GETDEVLIST_MAXNUM];
  193. };
  194. extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *);
  195. extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
  196. /* nfs4proc.c */
  197. extern size_t max_response_pages(struct nfs_server *server);
  198. extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
  199. struct pnfs_device *dev,
  200. struct rpc_cred *cred);
  201. extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout);
  202. extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync);
  203. /* pnfs.c */
  204. void pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo);
  205. void pnfs_put_lseg(struct pnfs_layout_segment *lseg);
  206. void set_pnfs_layoutdriver(struct nfs_server *, const struct nfs_fh *, struct nfs_fsinfo *);
  207. void unset_pnfs_layoutdriver(struct nfs_server *);
  208. void pnfs_generic_pg_check_layout(struct nfs_pageio_descriptor *pgio);
  209. void pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *, struct nfs_page *);
  210. int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc);
  211. void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,
  212. struct nfs_page *req, u64 wb_size);
  213. void pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *);
  214. int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc);
  215. size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
  216. struct nfs_page *prev, struct nfs_page *req);
  217. void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg);
  218. struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp);
  219. void pnfs_layoutget_free(struct nfs4_layoutget *lgp);
  220. void pnfs_free_lseg_list(struct list_head *tmp_list);
  221. void pnfs_destroy_layout(struct nfs_inode *);
  222. void pnfs_destroy_layout_final(struct nfs_inode *);
  223. void pnfs_destroy_all_layouts(struct nfs_client *);
  224. int pnfs_destroy_layouts_byfsid(struct nfs_client *clp,
  225. struct nfs_fsid *fsid,
  226. bool is_recall);
  227. int pnfs_destroy_layouts_byclid(struct nfs_client *clp,
  228. bool is_recall);
  229. bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst,
  230. struct pnfs_layout_range *dst_range,
  231. struct inode *inode);
  232. void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo);
  233. void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo,
  234. const nfs4_stateid *new,
  235. bool update_barrier);
  236. int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
  237. struct list_head *tmp_list,
  238. const struct pnfs_layout_range *recall_range,
  239. u32 seq);
  240. int pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,
  241. struct list_head *tmp_list,
  242. const struct pnfs_layout_range *recall_range,
  243. u32 seq);
  244. int pnfs_mark_layout_stateid_invalid(struct pnfs_layout_hdr *lo,
  245. struct list_head *lseg_list);
  246. bool pnfs_roc(struct inode *ino,
  247. struct nfs4_layoutreturn_args *args,
  248. struct nfs4_layoutreturn_res *res,
  249. const struct rpc_cred *cred);
  250. void pnfs_roc_release(struct nfs4_layoutreturn_args *args,
  251. struct nfs4_layoutreturn_res *res,
  252. int ret);
  253. bool pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task);
  254. void pnfs_set_layoutcommit(struct inode *, struct pnfs_layout_segment *, loff_t);
  255. void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data);
  256. int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
  257. int pnfs_generic_sync(struct inode *inode, bool datasync);
  258. int pnfs_nfs_generic_sync(struct inode *inode, bool datasync);
  259. int _pnfs_return_layout(struct inode *);
  260. int pnfs_commit_and_return_layout(struct inode *);
  261. void pnfs_ld_write_done(struct nfs_pgio_header *);
  262. void pnfs_ld_read_done(struct nfs_pgio_header *);
  263. void pnfs_read_resend_pnfs(struct nfs_pgio_header *);
  264. struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino,
  265. struct nfs_open_context *ctx,
  266. loff_t pos,
  267. u64 count,
  268. enum pnfs_iomode iomode,
  269. bool strict_iomode,
  270. gfp_t gfp_flags);
  271. void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
  272. const nfs4_stateid *arg_stateid,
  273. const struct pnfs_layout_range *range,
  274. const nfs4_stateid *stateid);
  275. void pnfs_generic_layout_insert_lseg(struct pnfs_layout_hdr *lo,
  276. struct pnfs_layout_segment *lseg,
  277. bool (*is_after)(const struct pnfs_layout_range *lseg_range,
  278. const struct pnfs_layout_range *old),
  279. bool (*do_merge)(struct pnfs_layout_segment *lseg,
  280. struct pnfs_layout_segment *old),
  281. struct list_head *free_me);
  282. void nfs4_deviceid_mark_client_invalid(struct nfs_client *clp);
  283. int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *);
  284. int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *);
  285. struct nfs4_threshold *pnfs_mdsthreshold_alloc(void);
  286. void pnfs_error_mark_layout_for_return(struct inode *inode,
  287. struct pnfs_layout_segment *lseg);
  288. /* nfs4_deviceid_flags */
  289. enum {
  290. NFS_DEVICEID_INVALID = 0, /* set when MDS clientid recalled */
  291. NFS_DEVICEID_UNAVAILABLE, /* device temporarily unavailable */
  292. NFS_DEVICEID_NOCACHE, /* device may not be cached */
  293. };
  294. /* pnfs_dev.c */
  295. struct nfs4_deviceid_node {
  296. struct hlist_node node;
  297. struct hlist_node tmpnode;
  298. const struct pnfs_layoutdriver_type *ld;
  299. const struct nfs_client *nfs_client;
  300. unsigned long flags;
  301. unsigned long timestamp_unavailable;
  302. struct nfs4_deviceid deviceid;
  303. struct rcu_head rcu;
  304. atomic_t ref;
  305. };
  306. struct nfs4_deviceid_node *
  307. nfs4_find_get_deviceid(struct nfs_server *server,
  308. const struct nfs4_deviceid *id, struct rpc_cred *cred,
  309. gfp_t gfp_mask);
  310. void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
  311. void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, struct nfs_server *,
  312. const struct nfs4_deviceid *);
  313. bool nfs4_put_deviceid_node(struct nfs4_deviceid_node *);
  314. void nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node);
  315. bool nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node);
  316. void nfs4_deviceid_purge_client(const struct nfs_client *);
  317. /* pnfs_nfs.c */
  318. void pnfs_generic_clear_request_commit(struct nfs_page *req,
  319. struct nfs_commit_info *cinfo);
  320. void pnfs_generic_commit_release(void *calldata);
  321. void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data);
  322. void pnfs_generic_rw_release(void *data);
  323. void pnfs_generic_recover_commit_reqs(struct list_head *dst,
  324. struct nfs_commit_info *cinfo);
  325. int pnfs_generic_commit_pagelist(struct inode *inode,
  326. struct list_head *mds_pages,
  327. int how,
  328. struct nfs_commit_info *cinfo,
  329. int (*initiate_commit)(struct nfs_commit_data *data,
  330. int how));
  331. int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, int max);
  332. void pnfs_generic_write_commit_done(struct rpc_task *task, void *data);
  333. void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds);
  334. struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(struct list_head *dsaddrs,
  335. gfp_t gfp_flags);
  336. void nfs4_pnfs_v3_ds_connect_unload(void);
  337. int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
  338. struct nfs4_deviceid_node *devid, unsigned int timeo,
  339. unsigned int retrans, u32 version, u32 minor_version);
  340. struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net,
  341. struct xdr_stream *xdr,
  342. gfp_t gfp_flags);
  343. void pnfs_layout_mark_request_commit(struct nfs_page *req,
  344. struct pnfs_layout_segment *lseg,
  345. struct nfs_commit_info *cinfo,
  346. u32 ds_commit_idx);
  347. void pnfs_lgopen_prepare(struct nfs4_opendata *data,
  348. struct nfs_open_context *ctx);
  349. void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp,
  350. struct nfs_open_context *ctx);
  351. void nfs4_lgopen_release(struct nfs4_layoutget *lgp);
  352. static inline bool nfs_have_layout(struct inode *inode)
  353. {
  354. return NFS_I(inode)->layout != NULL;
  355. }
  356. static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo)
  357. {
  358. return test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) == 0;
  359. }
  360. static inline struct nfs4_deviceid_node *
  361. nfs4_get_deviceid(struct nfs4_deviceid_node *d)
  362. {
  363. atomic_inc(&d->ref);
  364. return d;
  365. }
  366. static inline struct pnfs_layout_segment *
  367. pnfs_get_lseg(struct pnfs_layout_segment *lseg)
  368. {
  369. if (lseg) {
  370. refcount_inc(&lseg->pls_refcount);
  371. smp_mb__after_atomic();
  372. }
  373. return lseg;
  374. }
  375. static inline bool
  376. pnfs_is_valid_lseg(struct pnfs_layout_segment *lseg)
  377. {
  378. return test_bit(NFS_LSEG_VALID, &lseg->pls_flags) != 0;
  379. }
  380. /* Return true if a layout driver is being used for this mountpoint */
  381. static inline int pnfs_enabled_sb(struct nfs_server *nfss)
  382. {
  383. return nfss->pnfs_curr_ld != NULL;
  384. }
  385. static inline int
  386. pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how,
  387. struct nfs_commit_info *cinfo)
  388. {
  389. if (cinfo->ds == NULL || cinfo->ds->ncommitting == 0)
  390. return PNFS_NOT_ATTEMPTED;
  391. return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how, cinfo);
  392. }
  393. static inline struct pnfs_ds_commit_info *
  394. pnfs_get_ds_info(struct inode *inode)
  395. {
  396. struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
  397. if (ld == NULL || ld->get_ds_info == NULL)
  398. return NULL;
  399. return ld->get_ds_info(inode);
  400. }
  401. static inline void
  402. pnfs_generic_mark_devid_invalid(struct nfs4_deviceid_node *node)
  403. {
  404. set_bit(NFS_DEVICEID_INVALID, &node->flags);
  405. }
  406. static inline bool
  407. pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
  408. struct nfs_commit_info *cinfo, u32 ds_commit_idx)
  409. {
  410. struct inode *inode = d_inode(req->wb_context->dentry);
  411. struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
  412. if (lseg == NULL || ld->mark_request_commit == NULL)
  413. return false;
  414. ld->mark_request_commit(req, lseg, cinfo, ds_commit_idx);
  415. return true;
  416. }
  417. static inline bool
  418. pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
  419. {
  420. struct inode *inode = d_inode(req->wb_context->dentry);
  421. struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
  422. if (ld == NULL || ld->clear_request_commit == NULL)
  423. return false;
  424. ld->clear_request_commit(req, cinfo);
  425. return true;
  426. }
  427. static inline int
  428. pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
  429. int max)
  430. {
  431. if (cinfo->ds == NULL || cinfo->ds->nwritten == 0)
  432. return 0;
  433. else
  434. return NFS_SERVER(inode)->pnfs_curr_ld->scan_commit_lists(cinfo, max);
  435. }
  436. static inline struct nfs_page *
  437. pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
  438. struct page *page)
  439. {
  440. struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
  441. if (ld == NULL || ld->search_commit_reqs == NULL)
  442. return NULL;
  443. return ld->search_commit_reqs(cinfo, page);
  444. }
  445. /* Should the pNFS client commit and return the layout upon a setattr */
  446. static inline bool
  447. pnfs_ld_layoutret_on_setattr(struct inode *inode)
  448. {
  449. if (!pnfs_enabled_sb(NFS_SERVER(inode)))
  450. return false;
  451. return NFS_SERVER(inode)->pnfs_curr_ld->flags &
  452. PNFS_LAYOUTRET_ON_SETATTR;
  453. }
  454. static inline bool
  455. pnfs_ld_read_whole_page(struct inode *inode)
  456. {
  457. if (!pnfs_enabled_sb(NFS_SERVER(inode)))
  458. return false;
  459. return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE;
  460. }
  461. static inline int
  462. pnfs_sync_inode(struct inode *inode, bool datasync)
  463. {
  464. if (!pnfs_enabled_sb(NFS_SERVER(inode)))
  465. return 0;
  466. return NFS_SERVER(inode)->pnfs_curr_ld->sync(inode, datasync);
  467. }
  468. static inline bool
  469. pnfs_layoutcommit_outstanding(struct inode *inode)
  470. {
  471. struct nfs_inode *nfsi = NFS_I(inode);
  472. return test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags) != 0 ||
  473. test_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags) != 0;
  474. }
  475. static inline int pnfs_return_layout(struct inode *ino)
  476. {
  477. struct nfs_inode *nfsi = NFS_I(ino);
  478. struct nfs_server *nfss = NFS_SERVER(ino);
  479. if (pnfs_enabled_sb(nfss) && nfsi->layout) {
  480. set_bit(NFS_LAYOUT_RETURN_REQUESTED, &nfsi->layout->plh_flags);
  481. return _pnfs_return_layout(ino);
  482. }
  483. return 0;
  484. }
  485. static inline bool
  486. pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src,
  487. struct nfs_server *nfss)
  488. {
  489. return (dst && src && src->bm != 0 && nfss->pnfs_curr_ld &&
  490. nfss->pnfs_curr_ld->id == src->l_type);
  491. }
  492. static inline u64
  493. pnfs_calc_offset_end(u64 offset, u64 len)
  494. {
  495. if (len == NFS4_MAX_UINT64 || len >= NFS4_MAX_UINT64 - offset)
  496. return NFS4_MAX_UINT64;
  497. return offset + len - 1;
  498. }
  499. static inline u64
  500. pnfs_calc_offset_length(u64 offset, u64 end)
  501. {
  502. if (end == NFS4_MAX_UINT64 || end <= offset)
  503. return NFS4_MAX_UINT64;
  504. return 1 + end - offset;
  505. }
  506. static inline void
  507. pnfs_copy_range(struct pnfs_layout_range *dst,
  508. const struct pnfs_layout_range *src)
  509. {
  510. memcpy(dst, src, sizeof(*dst));
  511. }
  512. static inline u64
  513. pnfs_end_offset(u64 start, u64 len)
  514. {
  515. if (NFS4_MAX_UINT64 - start <= len)
  516. return NFS4_MAX_UINT64;
  517. return start + len;
  518. }
  519. /*
  520. * Are 2 ranges intersecting?
  521. * start1 end1
  522. * [----------------------------------)
  523. * start2 end2
  524. * [----------------)
  525. */
  526. static inline bool
  527. pnfs_is_range_intersecting(u64 start1, u64 end1, u64 start2, u64 end2)
  528. {
  529. return (end1 == NFS4_MAX_UINT64 || start2 < end1) &&
  530. (end2 == NFS4_MAX_UINT64 || start1 < end2);
  531. }
  532. static inline bool
  533. pnfs_lseg_range_intersecting(const struct pnfs_layout_range *l1,
  534. const struct pnfs_layout_range *l2)
  535. {
  536. u64 end1 = pnfs_end_offset(l1->offset, l1->length);
  537. u64 end2 = pnfs_end_offset(l2->offset, l2->length);
  538. return pnfs_is_range_intersecting(l1->offset, end1, l2->offset, end2);
  539. }
  540. static inline bool
  541. pnfs_lseg_request_intersecting(struct pnfs_layout_segment *lseg, struct nfs_page *req)
  542. {
  543. u64 seg_last = pnfs_end_offset(lseg->pls_range.offset, lseg->pls_range.length);
  544. u64 req_last = req_offset(req) + req->wb_bytes;
  545. return pnfs_is_range_intersecting(lseg->pls_range.offset, seg_last,
  546. req_offset(req), req_last);
  547. }
  548. extern unsigned int layoutstats_timer;
  549. #ifdef NFS_DEBUG
  550. void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
  551. #else
  552. static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id)
  553. {
  554. }
  555. #endif /* NFS_DEBUG */
  556. #else /* CONFIG_NFS_V4_1 */
  557. static inline bool nfs_have_layout(struct inode *inode)
  558. {
  559. return false;
  560. }
  561. static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
  562. {
  563. }
  564. static inline void pnfs_destroy_layout(struct nfs_inode *nfsi)
  565. {
  566. }
  567. static inline void pnfs_destroy_layout_final(struct nfs_inode *nfsi)
  568. {
  569. }
  570. static inline struct pnfs_layout_segment *
  571. pnfs_get_lseg(struct pnfs_layout_segment *lseg)
  572. {
  573. return NULL;
  574. }
  575. static inline void pnfs_put_lseg(struct pnfs_layout_segment *lseg)
  576. {
  577. }
  578. static inline int pnfs_return_layout(struct inode *ino)
  579. {
  580. return 0;
  581. }
  582. static inline int pnfs_commit_and_return_layout(struct inode *inode)
  583. {
  584. return 0;
  585. }
  586. static inline bool
  587. pnfs_ld_layoutret_on_setattr(struct inode *inode)
  588. {
  589. return false;
  590. }
  591. static inline bool
  592. pnfs_ld_read_whole_page(struct inode *inode)
  593. {
  594. return false;
  595. }
  596. static inline int
  597. pnfs_sync_inode(struct inode *inode, bool datasync)
  598. {
  599. return 0;
  600. }
  601. static inline bool
  602. pnfs_layoutcommit_outstanding(struct inode *inode)
  603. {
  604. return false;
  605. }
  606. static inline bool
  607. pnfs_roc(struct inode *ino,
  608. struct nfs4_layoutreturn_args *args,
  609. struct nfs4_layoutreturn_res *res,
  610. const struct rpc_cred *cred)
  611. {
  612. return false;
  613. }
  614. static inline void
  615. pnfs_roc_release(struct nfs4_layoutreturn_args *args,
  616. struct nfs4_layoutreturn_res *res,
  617. int ret)
  618. {
  619. }
  620. static inline bool
  621. pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task)
  622. {
  623. return false;
  624. }
  625. static inline void set_pnfs_layoutdriver(struct nfs_server *s,
  626. const struct nfs_fh *mntfh,
  627. struct nfs_fsinfo *fsinfo)
  628. {
  629. }
  630. static inline void unset_pnfs_layoutdriver(struct nfs_server *s)
  631. {
  632. }
  633. static inline int
  634. pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how,
  635. struct nfs_commit_info *cinfo)
  636. {
  637. return PNFS_NOT_ATTEMPTED;
  638. }
  639. static inline struct pnfs_ds_commit_info *
  640. pnfs_get_ds_info(struct inode *inode)
  641. {
  642. return NULL;
  643. }
  644. static inline bool
  645. pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
  646. struct nfs_commit_info *cinfo, u32 ds_commit_idx)
  647. {
  648. return false;
  649. }
  650. static inline bool
  651. pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
  652. {
  653. return false;
  654. }
  655. static inline int
  656. pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
  657. int max)
  658. {
  659. return 0;
  660. }
  661. static inline struct nfs_page *
  662. pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
  663. struct page *page)
  664. {
  665. return NULL;
  666. }
  667. static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
  668. {
  669. return 0;
  670. }
  671. static inline bool
  672. pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src,
  673. struct nfs_server *nfss)
  674. {
  675. return false;
  676. }
  677. static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
  678. {
  679. return NULL;
  680. }
  681. static inline void nfs4_pnfs_v3_ds_connect_unload(void)
  682. {
  683. }
  684. static inline bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst,
  685. struct pnfs_layout_range *dst_range,
  686. struct inode *inode)
  687. {
  688. return false;
  689. }
  690. static inline void pnfs_lgopen_prepare(struct nfs4_opendata *data,
  691. struct nfs_open_context *ctx)
  692. {
  693. }
  694. static inline void pnfs_parse_lgopen(struct inode *ino,
  695. struct nfs4_layoutget *lgp,
  696. struct nfs_open_context *ctx)
  697. {
  698. }
  699. static inline void nfs4_lgopen_release(struct nfs4_layoutget *lgp)
  700. {
  701. }
  702. static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo)
  703. {
  704. return false;
  705. }
  706. #endif /* CONFIG_NFS_V4_1 */
  707. #if IS_ENABLED(CONFIG_NFS_V4_2)
  708. int pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags);
  709. #else
  710. static inline int
  711. pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags)
  712. {
  713. return 0;
  714. }
  715. #endif
  716. #endif /* FS_NFS_PNFS_H */