0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifndef FS_NFS_PNFS_H
0031 #define FS_NFS_PNFS_H
0032
0033 #include <linux/refcount.h>
0034 #include <linux/nfs_fs.h>
0035 #include <linux/nfs_page.h>
0036 #include <linux/workqueue.h>
0037
0038 struct nfs4_opendata;
0039
0040 enum {
0041 NFS_LSEG_VALID = 0,
0042 NFS_LSEG_ROC,
0043 NFS_LSEG_LAYOUTCOMMIT,
0044 NFS_LSEG_LAYOUTRETURN,
0045 NFS_LSEG_UNAVAILABLE,
0046 };
0047
0048
0049 struct nfs4_pnfs_ds_addr {
0050 struct sockaddr_storage da_addr;
0051 size_t da_addrlen;
0052 struct list_head da_node;
0053 char *da_remotestr;
0054 const char *da_netid;
0055 int da_transport;
0056 };
0057
0058 struct nfs4_pnfs_ds {
0059 struct list_head ds_node;
0060 char *ds_remotestr;
0061 struct list_head ds_addrs;
0062 struct nfs_client *ds_clp;
0063 refcount_t ds_count;
0064 unsigned long ds_state;
0065 #define NFS4DS_CONNECTING 0
0066 };
0067
0068 struct pnfs_layout_segment {
0069 struct list_head pls_list;
0070 struct list_head pls_lc_list;
0071 struct list_head pls_commits;
0072 struct pnfs_layout_range pls_range;
0073 refcount_t pls_refcount;
0074 u32 pls_seq;
0075 unsigned long pls_flags;
0076 struct pnfs_layout_hdr *pls_layout;
0077 };
0078
0079 enum pnfs_try_status {
0080 PNFS_ATTEMPTED = 0,
0081 PNFS_NOT_ATTEMPTED = 1,
0082 PNFS_TRY_AGAIN = 2,
0083 };
0084
0085 #ifdef CONFIG_NFS_V4_1
0086
0087 #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4"
0088
0089
0090
0091
0092
0093 #define NFS4_DEF_DS_TIMEO 600
0094 #define NFS4_DEF_DS_RETRANS 5
0095 #define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
0096
0097 enum {
0098 NFS_LAYOUT_RO_FAILED = 0,
0099 NFS_LAYOUT_RW_FAILED,
0100 NFS_LAYOUT_BULK_RECALL,
0101 NFS_LAYOUT_RETURN,
0102 NFS_LAYOUT_RETURN_LOCK,
0103 NFS_LAYOUT_RETURN_REQUESTED,
0104 NFS_LAYOUT_INVALID_STID,
0105 NFS_LAYOUT_FIRST_LAYOUTGET,
0106 NFS_LAYOUT_INODE_FREEING,
0107 NFS_LAYOUT_HASHED,
0108 NFS_LAYOUT_DRAIN,
0109 };
0110
0111 enum layoutdriver_policy_flags {
0112
0113
0114 PNFS_LAYOUTRET_ON_SETATTR = 1 << 0,
0115 PNFS_LAYOUTRET_ON_ERROR = 1 << 1,
0116 PNFS_READ_WHOLE_PAGE = 1 << 2,
0117 PNFS_LAYOUTGET_ON_OPEN = 1 << 3,
0118 };
0119
0120 struct nfs4_deviceid_node;
0121
0122
0123 struct pnfs_layoutdriver_type {
0124 struct list_head pnfs_tblid;
0125 const u32 id;
0126 const char *name;
0127 struct module *owner;
0128 unsigned flags;
0129 unsigned max_deviceinfo_size;
0130 unsigned max_layoutget_response;
0131
0132 int (*set_layoutdriver) (struct nfs_server *, const struct nfs_fh *);
0133 int (*clear_layoutdriver) (struct nfs_server *);
0134
0135 struct pnfs_layout_hdr * (*alloc_layout_hdr) (struct inode *inode, gfp_t gfp_flags);
0136 void (*free_layout_hdr) (struct pnfs_layout_hdr *);
0137
0138 struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
0139 void (*free_lseg) (struct pnfs_layout_segment *lseg);
0140 void (*add_lseg) (struct pnfs_layout_hdr *layoutid,
0141 struct pnfs_layout_segment *lseg,
0142 struct list_head *free_me);
0143
0144 void (*return_range) (struct pnfs_layout_hdr *lo,
0145 struct pnfs_layout_range *range);
0146
0147
0148 const struct nfs_pageio_ops *pg_read_ops;
0149 const struct nfs_pageio_ops *pg_write_ops;
0150
0151 struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode);
0152
0153 int (*sync)(struct inode *inode, bool datasync);
0154
0155
0156
0157
0158
0159 enum pnfs_try_status (*read_pagelist)(struct nfs_pgio_header *);
0160 enum pnfs_try_status (*write_pagelist)(struct nfs_pgio_header *, int);
0161
0162 void (*free_deviceid_node) (struct nfs4_deviceid_node *);
0163 struct nfs4_deviceid_node * (*alloc_deviceid_node)
0164 (struct nfs_server *server, struct pnfs_device *pdev,
0165 gfp_t gfp_flags);
0166
0167 int (*prepare_layoutreturn) (struct nfs4_layoutreturn_args *);
0168
0169 void (*cleanup_layoutcommit) (struct nfs4_layoutcommit_data *data);
0170 int (*prepare_layoutcommit) (struct nfs4_layoutcommit_args *args);
0171 int (*prepare_layoutstats) (struct nfs42_layoutstat_args *args);
0172 };
0173
0174 struct pnfs_commit_ops {
0175 void (*setup_ds_info)(struct pnfs_ds_commit_info *,
0176 struct pnfs_layout_segment *);
0177 void (*release_ds_info)(struct pnfs_ds_commit_info *,
0178 struct inode *inode);
0179 int (*commit_pagelist)(struct inode *inode,
0180 struct list_head *mds_pages,
0181 int how,
0182 struct nfs_commit_info *cinfo);
0183 void (*mark_request_commit) (struct nfs_page *req,
0184 struct pnfs_layout_segment *lseg,
0185 struct nfs_commit_info *cinfo,
0186 u32 ds_commit_idx);
0187 void (*clear_request_commit) (struct nfs_page *req,
0188 struct nfs_commit_info *cinfo);
0189 int (*scan_commit_lists) (struct nfs_commit_info *cinfo,
0190 int max);
0191 void (*recover_commit_reqs) (struct list_head *list,
0192 struct nfs_commit_info *cinfo);
0193 struct nfs_page * (*search_commit_reqs)(struct nfs_commit_info *cinfo,
0194 struct page *page);
0195 };
0196
0197 struct pnfs_layout_hdr {
0198 refcount_t plh_refcount;
0199 atomic_t plh_outstanding;
0200 struct list_head plh_layouts;
0201 struct list_head plh_bulk_destroy;
0202 struct list_head plh_segs;
0203 struct list_head plh_return_segs;
0204 unsigned long plh_block_lgets;
0205 unsigned long plh_retry_timestamp;
0206 unsigned long plh_flags;
0207 nfs4_stateid plh_stateid;
0208 u32 plh_barrier;
0209 u32 plh_return_seq;
0210 enum pnfs_iomode plh_return_iomode;
0211 loff_t plh_lwb;
0212 const struct cred *plh_lc_cred;
0213 struct inode *plh_inode;
0214 struct rcu_head plh_rcu;
0215 };
0216
0217 struct pnfs_device {
0218 struct nfs4_deviceid dev_id;
0219 unsigned int layout_type;
0220 unsigned int mincount;
0221 unsigned int maxcount;
0222 struct page **pages;
0223 unsigned int pgbase;
0224 unsigned int pglen;
0225 unsigned char nocache : 1;
0226 };
0227
0228 #define NFS4_PNFS_GETDEVLIST_MAXNUM 16
0229
0230 struct pnfs_devicelist {
0231 unsigned int eof;
0232 unsigned int num_devs;
0233 struct nfs4_deviceid dev_id[NFS4_PNFS_GETDEVLIST_MAXNUM];
0234 };
0235
0236 extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *);
0237 extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
0238 extern const struct pnfs_layoutdriver_type *pnfs_find_layoutdriver(u32 id);
0239 extern void pnfs_put_layoutdriver(const struct pnfs_layoutdriver_type *ld);
0240
0241
0242 extern size_t max_response_pages(struct nfs_server *server);
0243 extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
0244 struct pnfs_device *dev,
0245 const struct cred *cred);
0246 extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout);
0247 extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync);
0248
0249
0250 void pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo);
0251 void pnfs_put_lseg(struct pnfs_layout_segment *lseg);
0252
0253 void set_pnfs_layoutdriver(struct nfs_server *, const struct nfs_fh *, struct nfs_fsinfo *);
0254 void unset_pnfs_layoutdriver(struct nfs_server *);
0255 void pnfs_generic_pg_check_layout(struct nfs_pageio_descriptor *pgio);
0256 void pnfs_generic_pg_check_range(struct nfs_pageio_descriptor *pgio, struct nfs_page *req);
0257 void pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *, struct nfs_page *);
0258 int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc);
0259 void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,
0260 struct nfs_page *req, u64 wb_size);
0261 void pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *);
0262 int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc);
0263 size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
0264 struct nfs_page *prev, struct nfs_page *req);
0265 void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg);
0266 struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp);
0267 void pnfs_layoutget_free(struct nfs4_layoutget *lgp);
0268 void pnfs_free_lseg_list(struct list_head *tmp_list);
0269 void pnfs_destroy_layout(struct nfs_inode *);
0270 void pnfs_destroy_layout_final(struct nfs_inode *);
0271 void pnfs_destroy_all_layouts(struct nfs_client *);
0272 int pnfs_destroy_layouts_byfsid(struct nfs_client *clp,
0273 struct nfs_fsid *fsid,
0274 bool is_recall);
0275 int pnfs_destroy_layouts_byclid(struct nfs_client *clp,
0276 bool is_recall);
0277 bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst,
0278 struct pnfs_layout_range *dst_range,
0279 struct inode *inode);
0280 void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo);
0281 void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo,
0282 const nfs4_stateid *new,
0283 const struct cred *cred,
0284 bool update_barrier);
0285 int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
0286 struct list_head *tmp_list,
0287 const struct pnfs_layout_range *recall_range,
0288 u32 seq);
0289 int pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,
0290 struct list_head *tmp_list,
0291 const struct pnfs_layout_range *recall_range,
0292 u32 seq);
0293 int pnfs_mark_layout_stateid_invalid(struct pnfs_layout_hdr *lo,
0294 struct list_head *lseg_list);
0295 bool pnfs_roc(struct inode *ino,
0296 struct nfs4_layoutreturn_args *args,
0297 struct nfs4_layoutreturn_res *res,
0298 const struct cred *cred);
0299 int pnfs_roc_done(struct rpc_task *task, struct nfs4_layoutreturn_args **argpp,
0300 struct nfs4_layoutreturn_res **respp, int *ret);
0301 void pnfs_roc_release(struct nfs4_layoutreturn_args *args,
0302 struct nfs4_layoutreturn_res *res,
0303 int ret);
0304 bool pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task);
0305 void pnfs_set_layoutcommit(struct inode *, struct pnfs_layout_segment *, loff_t);
0306 void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data);
0307 int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
0308 int pnfs_generic_sync(struct inode *inode, bool datasync);
0309 int pnfs_nfs_generic_sync(struct inode *inode, bool datasync);
0310 int _pnfs_return_layout(struct inode *);
0311 int pnfs_commit_and_return_layout(struct inode *);
0312 void pnfs_ld_write_done(struct nfs_pgio_header *);
0313 void pnfs_ld_read_done(struct nfs_pgio_header *);
0314 void pnfs_read_resend_pnfs(struct nfs_pgio_header *, unsigned int mirror_idx);
0315 struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino,
0316 struct nfs_open_context *ctx,
0317 loff_t pos,
0318 u64 count,
0319 enum pnfs_iomode iomode,
0320 bool strict_iomode,
0321 gfp_t gfp_flags);
0322 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
0323 const nfs4_stateid *arg_stateid,
0324 const struct pnfs_layout_range *range,
0325 const nfs4_stateid *stateid);
0326
0327 void pnfs_generic_layout_insert_lseg(struct pnfs_layout_hdr *lo,
0328 struct pnfs_layout_segment *lseg,
0329 bool (*is_after)(const struct pnfs_layout_range *lseg_range,
0330 const struct pnfs_layout_range *old),
0331 bool (*do_merge)(struct pnfs_layout_segment *lseg,
0332 struct pnfs_layout_segment *old),
0333 struct list_head *free_me);
0334
0335 void nfs4_deviceid_mark_client_invalid(struct nfs_client *clp);
0336 int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *);
0337 int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *);
0338 struct nfs4_threshold *pnfs_mdsthreshold_alloc(void);
0339 void pnfs_error_mark_layout_for_return(struct inode *inode,
0340 struct pnfs_layout_segment *lseg);
0341 void pnfs_layout_return_unused_byclid(struct nfs_client *clp,
0342 enum pnfs_iomode iomode);
0343
0344
0345 enum {
0346 NFS_DEVICEID_INVALID = 0,
0347 NFS_DEVICEID_UNAVAILABLE,
0348 NFS_DEVICEID_NOCACHE,
0349 };
0350
0351
0352 struct nfs4_deviceid_node {
0353 struct hlist_node node;
0354 struct hlist_node tmpnode;
0355 const struct pnfs_layoutdriver_type *ld;
0356 const struct nfs_client *nfs_client;
0357 unsigned long flags;
0358 unsigned long timestamp_unavailable;
0359 struct nfs4_deviceid deviceid;
0360 struct rcu_head rcu;
0361 atomic_t ref;
0362 };
0363
0364 struct nfs4_deviceid_node *
0365 nfs4_find_get_deviceid(struct nfs_server *server,
0366 const struct nfs4_deviceid *id, const struct cred *cred,
0367 gfp_t gfp_mask);
0368 void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
0369 void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, struct nfs_server *,
0370 const struct nfs4_deviceid *);
0371 bool nfs4_put_deviceid_node(struct nfs4_deviceid_node *);
0372 void nfs4_mark_deviceid_available(struct nfs4_deviceid_node *node);
0373 void nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node);
0374 bool nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node);
0375 void nfs4_deviceid_purge_client(const struct nfs_client *);
0376
0377
0378 struct pnfs_commit_array *pnfs_alloc_commit_array(size_t n, gfp_t gfp_flags);
0379 void pnfs_free_commit_array(struct pnfs_commit_array *p);
0380 struct pnfs_commit_array *pnfs_add_commit_array(struct pnfs_ds_commit_info *,
0381 struct pnfs_commit_array *,
0382 struct pnfs_layout_segment *);
0383
0384 void pnfs_generic_ds_cinfo_release_lseg(struct pnfs_ds_commit_info *fl_cinfo,
0385 struct pnfs_layout_segment *lseg);
0386 void pnfs_generic_ds_cinfo_destroy(struct pnfs_ds_commit_info *fl_cinfo);
0387
0388 void pnfs_generic_clear_request_commit(struct nfs_page *req,
0389 struct nfs_commit_info *cinfo);
0390 void pnfs_generic_commit_release(void *calldata);
0391 void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data);
0392 void pnfs_generic_rw_release(void *data);
0393 void pnfs_generic_recover_commit_reqs(struct list_head *dst,
0394 struct nfs_commit_info *cinfo);
0395 struct nfs_page *pnfs_generic_search_commit_reqs(struct nfs_commit_info *cinfo,
0396 struct page *page);
0397 int pnfs_generic_commit_pagelist(struct inode *inode,
0398 struct list_head *mds_pages,
0399 int how,
0400 struct nfs_commit_info *cinfo,
0401 int (*initiate_commit)(struct nfs_commit_data *data,
0402 int how));
0403 int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, int max);
0404 void pnfs_generic_write_commit_done(struct rpc_task *task, void *data);
0405 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds);
0406 struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(struct list_head *dsaddrs,
0407 gfp_t gfp_flags);
0408 void nfs4_pnfs_v3_ds_connect_unload(void);
0409 int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
0410 struct nfs4_deviceid_node *devid, unsigned int timeo,
0411 unsigned int retrans, u32 version, u32 minor_version);
0412 struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net,
0413 struct xdr_stream *xdr,
0414 gfp_t gfp_flags);
0415 void pnfs_layout_mark_request_commit(struct nfs_page *req,
0416 struct pnfs_layout_segment *lseg,
0417 struct nfs_commit_info *cinfo,
0418 u32 ds_commit_idx);
0419 void pnfs_lgopen_prepare(struct nfs4_opendata *data,
0420 struct nfs_open_context *ctx);
0421 void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp,
0422 struct nfs_open_context *ctx);
0423 void nfs4_lgopen_release(struct nfs4_layoutget *lgp);
0424
0425 static inline bool nfs_have_layout(struct inode *inode)
0426 {
0427 return NFS_I(inode)->layout != NULL;
0428 }
0429
0430 static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo)
0431 {
0432 return test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) == 0;
0433 }
0434
0435 static inline struct nfs4_deviceid_node *
0436 nfs4_get_deviceid(struct nfs4_deviceid_node *d)
0437 {
0438 atomic_inc(&d->ref);
0439 return d;
0440 }
0441
0442 static inline struct pnfs_layout_segment *
0443 pnfs_get_lseg(struct pnfs_layout_segment *lseg)
0444 {
0445 if (lseg) {
0446 refcount_inc(&lseg->pls_refcount);
0447 smp_mb__after_atomic();
0448 }
0449 return lseg;
0450 }
0451
0452 static inline bool
0453 pnfs_is_valid_lseg(struct pnfs_layout_segment *lseg)
0454 {
0455 return test_bit(NFS_LSEG_VALID, &lseg->pls_flags) != 0;
0456 }
0457
0458
0459 static inline int pnfs_enabled_sb(struct nfs_server *nfss)
0460 {
0461 return nfss->pnfs_curr_ld != NULL;
0462 }
0463
0464 static inline int
0465 pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how,
0466 struct nfs_commit_info *cinfo)
0467 {
0468 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0469
0470 if (fl_cinfo == NULL || fl_cinfo->ncommitting == 0)
0471 return PNFS_NOT_ATTEMPTED;
0472 return fl_cinfo->ops->commit_pagelist(inode, mds_pages, how, cinfo);
0473 }
0474
0475 static inline struct pnfs_ds_commit_info *
0476 pnfs_get_ds_info(struct inode *inode)
0477 {
0478 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
0479
0480 if (ld == NULL || ld->get_ds_info == NULL)
0481 return NULL;
0482 return ld->get_ds_info(inode);
0483 }
0484
0485 static inline void
0486 pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
0487 {
0488 struct pnfs_ds_commit_info *inode_cinfo = pnfs_get_ds_info(inode);
0489 if (inode_cinfo != NULL)
0490 fl_cinfo->ops = inode_cinfo->ops;
0491 }
0492
0493 static inline void
0494 pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo)
0495 {
0496 INIT_LIST_HEAD(&fl_cinfo->commits);
0497 fl_cinfo->ops = NULL;
0498 }
0499
0500 static inline void
0501 pnfs_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
0502 {
0503 if (fl_cinfo->ops != NULL && fl_cinfo->ops->release_ds_info != NULL)
0504 fl_cinfo->ops->release_ds_info(fl_cinfo, inode);
0505 }
0506
0507 static inline void
0508 pnfs_generic_mark_devid_invalid(struct nfs4_deviceid_node *node)
0509 {
0510 set_bit(NFS_DEVICEID_INVALID, &node->flags);
0511 }
0512
0513 static inline bool
0514 pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
0515 struct nfs_commit_info *cinfo, u32 ds_commit_idx)
0516 {
0517 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0518
0519 if (!lseg || !fl_cinfo->ops || !fl_cinfo->ops->mark_request_commit)
0520 return false;
0521 fl_cinfo->ops->mark_request_commit(req, lseg, cinfo, ds_commit_idx);
0522 return true;
0523 }
0524
0525 static inline bool
0526 pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
0527 {
0528 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0529
0530 if (!fl_cinfo || !fl_cinfo->ops || !fl_cinfo->ops->clear_request_commit)
0531 return false;
0532 fl_cinfo->ops->clear_request_commit(req, cinfo);
0533 return true;
0534 }
0535
0536 static inline int
0537 pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
0538 int max)
0539 {
0540 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0541
0542 if (!fl_cinfo || fl_cinfo->nwritten == 0)
0543 return 0;
0544 return fl_cinfo->ops->scan_commit_lists(cinfo, max);
0545 }
0546
0547 static inline void
0548 pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo)
0549 {
0550 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0551
0552 if (fl_cinfo && fl_cinfo->nwritten != 0)
0553 fl_cinfo->ops->recover_commit_reqs(head, cinfo);
0554 }
0555
0556 static inline struct nfs_page *
0557 pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
0558 struct page *page)
0559 {
0560 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
0561
0562 if (!fl_cinfo->ops || !fl_cinfo->ops->search_commit_reqs)
0563 return NULL;
0564 return fl_cinfo->ops->search_commit_reqs(cinfo, page);
0565 }
0566
0567
0568 static inline bool
0569 pnfs_ld_layoutret_on_setattr(struct inode *inode)
0570 {
0571 if (!pnfs_enabled_sb(NFS_SERVER(inode)))
0572 return false;
0573 return NFS_SERVER(inode)->pnfs_curr_ld->flags &
0574 PNFS_LAYOUTRET_ON_SETATTR;
0575 }
0576
0577 static inline bool
0578 pnfs_ld_read_whole_page(struct inode *inode)
0579 {
0580 if (!pnfs_enabled_sb(NFS_SERVER(inode)))
0581 return false;
0582 return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE;
0583 }
0584
0585 static inline int
0586 pnfs_sync_inode(struct inode *inode, bool datasync)
0587 {
0588 if (!pnfs_enabled_sb(NFS_SERVER(inode)))
0589 return 0;
0590 return NFS_SERVER(inode)->pnfs_curr_ld->sync(inode, datasync);
0591 }
0592
0593 static inline bool
0594 pnfs_layoutcommit_outstanding(struct inode *inode)
0595 {
0596 struct nfs_inode *nfsi = NFS_I(inode);
0597
0598 return test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags) != 0 ||
0599 test_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags) != 0;
0600 }
0601
0602 static inline int pnfs_return_layout(struct inode *ino)
0603 {
0604 struct nfs_inode *nfsi = NFS_I(ino);
0605 struct nfs_server *nfss = NFS_SERVER(ino);
0606
0607 if (pnfs_enabled_sb(nfss) && nfsi->layout) {
0608 set_bit(NFS_LAYOUT_RETURN_REQUESTED, &nfsi->layout->plh_flags);
0609 return _pnfs_return_layout(ino);
0610 }
0611
0612 return 0;
0613 }
0614
0615 static inline bool
0616 pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src,
0617 struct nfs_server *nfss)
0618 {
0619 return (dst && src && src->bm != 0 && nfss->pnfs_curr_ld &&
0620 nfss->pnfs_curr_ld->id == src->l_type);
0621 }
0622
0623 static inline u64
0624 pnfs_calc_offset_end(u64 offset, u64 len)
0625 {
0626 if (len == NFS4_MAX_UINT64 || len >= NFS4_MAX_UINT64 - offset)
0627 return NFS4_MAX_UINT64;
0628 return offset + len - 1;
0629 }
0630
0631 static inline u64
0632 pnfs_calc_offset_length(u64 offset, u64 end)
0633 {
0634 if (end == NFS4_MAX_UINT64 || end <= offset)
0635 return NFS4_MAX_UINT64;
0636 return 1 + end - offset;
0637 }
0638
0639 static inline void
0640 pnfs_copy_range(struct pnfs_layout_range *dst,
0641 const struct pnfs_layout_range *src)
0642 {
0643 memcpy(dst, src, sizeof(*dst));
0644 }
0645
0646 static inline u64
0647 pnfs_end_offset(u64 start, u64 len)
0648 {
0649 if (NFS4_MAX_UINT64 - start <= len)
0650 return NFS4_MAX_UINT64;
0651 return start + len;
0652 }
0653
0654
0655
0656
0657
0658
0659
0660
0661 static inline bool
0662 pnfs_is_range_intersecting(u64 start1, u64 end1, u64 start2, u64 end2)
0663 {
0664 return (end1 == NFS4_MAX_UINT64 || start2 < end1) &&
0665 (end2 == NFS4_MAX_UINT64 || start1 < end2);
0666 }
0667
0668 static inline bool
0669 pnfs_lseg_range_intersecting(const struct pnfs_layout_range *l1,
0670 const struct pnfs_layout_range *l2)
0671 {
0672 u64 end1 = pnfs_end_offset(l1->offset, l1->length);
0673 u64 end2 = pnfs_end_offset(l2->offset, l2->length);
0674
0675 return pnfs_is_range_intersecting(l1->offset, end1, l2->offset, end2);
0676 }
0677
0678 static inline bool
0679 pnfs_lseg_request_intersecting(struct pnfs_layout_segment *lseg, struct nfs_page *req)
0680 {
0681 u64 seg_last = pnfs_end_offset(lseg->pls_range.offset, lseg->pls_range.length);
0682 u64 req_last = req_offset(req) + req->wb_bytes;
0683
0684 return pnfs_is_range_intersecting(lseg->pls_range.offset, seg_last,
0685 req_offset(req), req_last);
0686 }
0687
0688 extern unsigned int layoutstats_timer;
0689
0690 #ifdef NFS_DEBUG
0691 void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
0692 #else
0693 static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id)
0694 {
0695 }
0696
0697 #endif
0698 #else
0699
0700 static inline bool nfs_have_layout(struct inode *inode)
0701 {
0702 return false;
0703 }
0704
0705 static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
0706 {
0707 }
0708
0709 static inline void pnfs_destroy_layout(struct nfs_inode *nfsi)
0710 {
0711 }
0712
0713 static inline void pnfs_destroy_layout_final(struct nfs_inode *nfsi)
0714 {
0715 }
0716
0717 static inline struct pnfs_layout_segment *
0718 pnfs_get_lseg(struct pnfs_layout_segment *lseg)
0719 {
0720 return NULL;
0721 }
0722
0723 static inline void pnfs_put_lseg(struct pnfs_layout_segment *lseg)
0724 {
0725 }
0726
0727 static inline int pnfs_return_layout(struct inode *ino)
0728 {
0729 return 0;
0730 }
0731
0732 static inline int pnfs_commit_and_return_layout(struct inode *inode)
0733 {
0734 return 0;
0735 }
0736
0737 static inline bool
0738 pnfs_ld_layoutret_on_setattr(struct inode *inode)
0739 {
0740 return false;
0741 }
0742
0743 static inline bool
0744 pnfs_ld_read_whole_page(struct inode *inode)
0745 {
0746 return false;
0747 }
0748
0749 static inline int
0750 pnfs_sync_inode(struct inode *inode, bool datasync)
0751 {
0752 return 0;
0753 }
0754
0755 static inline bool
0756 pnfs_layoutcommit_outstanding(struct inode *inode)
0757 {
0758 return false;
0759 }
0760
0761
0762 static inline bool
0763 pnfs_roc(struct inode *ino,
0764 struct nfs4_layoutreturn_args *args,
0765 struct nfs4_layoutreturn_res *res,
0766 const struct cred *cred)
0767 {
0768 return false;
0769 }
0770
0771 static inline int
0772 pnfs_roc_done(struct rpc_task *task,
0773 struct nfs4_layoutreturn_args **argpp,
0774 struct nfs4_layoutreturn_res **respp,
0775 int *ret)
0776 {
0777 return 0;
0778 }
0779
0780 static inline void
0781 pnfs_roc_release(struct nfs4_layoutreturn_args *args,
0782 struct nfs4_layoutreturn_res *res,
0783 int ret)
0784 {
0785 }
0786
0787 static inline bool
0788 pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task)
0789 {
0790 return false;
0791 }
0792
0793 static inline void set_pnfs_layoutdriver(struct nfs_server *s,
0794 const struct nfs_fh *mntfh,
0795 struct nfs_fsinfo *fsinfo)
0796 {
0797 }
0798
0799 static inline void unset_pnfs_layoutdriver(struct nfs_server *s)
0800 {
0801 }
0802
0803 static inline int
0804 pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how,
0805 struct nfs_commit_info *cinfo)
0806 {
0807 return PNFS_NOT_ATTEMPTED;
0808 }
0809
0810 static inline struct pnfs_ds_commit_info *
0811 pnfs_get_ds_info(struct inode *inode)
0812 {
0813 return NULL;
0814 }
0815
0816 static inline void
0817 pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
0818 {
0819 }
0820
0821 static inline void
0822 pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo)
0823 {
0824 }
0825
0826 static inline void
0827 pnfs_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
0828 {
0829 }
0830
0831 static inline bool
0832 pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
0833 struct nfs_commit_info *cinfo, u32 ds_commit_idx)
0834 {
0835 return false;
0836 }
0837
0838 static inline bool
0839 pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
0840 {
0841 return false;
0842 }
0843
0844 static inline int
0845 pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
0846 int max)
0847 {
0848 return 0;
0849 }
0850
0851 static inline void
0852 pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo)
0853 {
0854 }
0855
0856 static inline struct nfs_page *
0857 pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
0858 struct page *page)
0859 {
0860 return NULL;
0861 }
0862
0863 static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
0864 {
0865 return 0;
0866 }
0867
0868 static inline bool
0869 pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src,
0870 struct nfs_server *nfss)
0871 {
0872 return false;
0873 }
0874
0875 static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
0876 {
0877 return NULL;
0878 }
0879
0880 static inline void nfs4_pnfs_v3_ds_connect_unload(void)
0881 {
0882 }
0883
0884 static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst,
0885 struct pnfs_layout_range *dst_range,
0886 struct inode *inode)
0887 {
0888 return false;
0889 }
0890
0891 static inline void pnfs_lgopen_prepare(struct nfs4_opendata *data,
0892 struct nfs_open_context *ctx)
0893 {
0894 }
0895
0896 static inline void pnfs_parse_lgopen(struct inode *ino,
0897 struct nfs4_layoutget *lgp,
0898 struct nfs_open_context *ctx)
0899 {
0900 }
0901
0902 static inline void nfs4_lgopen_release(struct nfs4_layoutget *lgp)
0903 {
0904 }
0905
0906 static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo)
0907 {
0908 return false;
0909 }
0910
0911 #endif
0912
0913 #if IS_ENABLED(CONFIG_NFS_V4_2)
0914 int pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags);
0915 #else
0916 static inline int
0917 pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags)
0918 {
0919 return 0;
0920 }
0921 #endif
0922
0923 #endif