pnfs.h 23 KB

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