pnfs.h 23 KB

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