pnfs.h 28 KB

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