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 30 #ifndef FS_NFS_PNFS_H 31 #define FS_NFS_PNFS_H 32 33 #include <linux/refcount.h> 34 #include <linux/nfs_fs.h> 35 #include <linux/nfs_page.h> 36 #include <linux/workqueue.h> 37 38 struct nfs4_exception; 39 struct nfs4_opendata; 40 41 enum { 42 NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */ 43 NFS_LSEG_ROC, /* roc bit received from server */ 44 NFS_LSEG_LAYOUTCOMMIT, /* layoutcommit bit set for layoutcommit */ 45 NFS_LSEG_LAYOUTRETURN, /* layoutreturn bit set for layoutreturn */ 46 NFS_LSEG_UNAVAILABLE, /* unavailable bit set for temporary problem */ 47 }; 48 49 /* Individual ip address */ 50 struct nfs4_pnfs_ds_addr { 51 struct sockaddr_storage da_addr; 52 size_t da_addrlen; 53 struct list_head da_node; /* nfs4_pnfs_dev_hlist dev_dslist */ 54 char *da_remotestr; /* human readable addr+port */ 55 const char *da_netid; 56 int da_transport; 57 }; 58 59 struct nfs4_pnfs_ds { 60 struct hlist_node ds_node; /* nfs_net nfs4_data_server_cache */ 61 char *ds_remotestr; /* comma sep list of addrs */ 62 struct list_head ds_addrs; 63 const struct net *ds_net; 64 struct nfs_client *ds_clp; 65 refcount_t ds_count; 66 u32 ds_version; /* cache key, with ds_addrs */ 67 unsigned long ds_state; 68 #define NFS4DS_CONNECTING 0 /* ds is establishing connection */ 69 }; 70 71 struct pnfs_layout_segment { 72 struct list_head pls_list; 73 struct list_head pls_lc_list; 74 struct list_head pls_commits; 75 struct pnfs_layout_range pls_range; 76 refcount_t pls_refcount; 77 u32 pls_seq; 78 unsigned long pls_flags; 79 struct pnfs_layout_hdr *pls_layout; 80 }; 81 82 enum pnfs_try_status { 83 PNFS_ATTEMPTED = 0, 84 PNFS_NOT_ATTEMPTED = 1, 85 PNFS_TRY_AGAIN = 2, 86 }; 87 88 #if IS_ENABLED(CONFIG_NFS_V4) 89 90 #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4" 91 92 /* 93 * Default data server connection timeout and retrans vaules. 94 * Set by module parameters dataserver_timeo and dataserver_retrans. 95 */ 96 #define NFS4_DEF_DS_TIMEO 600 /* in tenths of a second */ 97 #define NFS4_DEF_DS_RETRANS 5 98 #define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ) 99 100 enum { 101 NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */ 102 NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */ 103 NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */ 104 NFS_LAYOUT_RETURN, /* layoutreturn in progress */ 105 NFS_LAYOUT_RETURN_LOCK, /* Serialise layoutreturn */ 106 NFS_LAYOUT_RETURN_REQUESTED, /* Return this layout ASAP */ 107 NFS_LAYOUT_INVALID_STID, /* layout stateid id is invalid */ 108 NFS_LAYOUT_FIRST_LAYOUTGET, /* Serialize first layoutget */ 109 NFS_LAYOUT_INODE_FREEING, /* The inode is being freed */ 110 NFS_LAYOUT_HASHED, /* The layout visible */ 111 NFS_LAYOUT_DRAIN, 112 }; 113 114 enum layoutdriver_policy_flags { 115 /* Should the pNFS client commit and return the layout upon truncate to 116 * a smaller size */ 117 PNFS_LAYOUTRET_ON_SETATTR = 1 << 0, 118 PNFS_LAYOUTRET_ON_ERROR = 1 << 1, 119 PNFS_READ_WHOLE_PAGE = 1 << 2, 120 PNFS_LAYOUTGET_ON_OPEN = 1 << 3, 121 }; 122 123 enum pnfs_layout_destroy_mode { 124 PNFS_LAYOUT_INVALIDATE = 0, 125 PNFS_LAYOUT_BULK_RETURN, 126 PNFS_LAYOUT_FILE_BULK_RETURN, 127 }; 128 129 struct nfs4_deviceid_node; 130 131 /* Per-layout driver specific registration structure */ 132 struct pnfs_layoutdriver_type { 133 struct list_head pnfs_tblid; 134 const u32 id; 135 const char *name; 136 struct module *owner; 137 unsigned flags; 138 unsigned max_layoutget_response; 139 140 int (*set_layoutdriver) (struct nfs_server *, const struct nfs_fh *); 141 int (*clear_layoutdriver) (struct nfs_server *); 142 143 struct pnfs_layout_hdr * (*alloc_layout_hdr) (struct inode *inode, gfp_t gfp_flags); 144 void (*free_layout_hdr) (struct pnfs_layout_hdr *); 145 146 struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr, gfp_t gfp_flags); 147 void (*free_lseg) (struct pnfs_layout_segment *lseg); 148 void (*add_lseg) (struct pnfs_layout_hdr *layoutid, 149 struct pnfs_layout_segment *lseg, 150 struct list_head *free_me); 151 152 void (*return_range) (struct pnfs_layout_hdr *lo, 153 struct pnfs_layout_range *range); 154 155 /* test for nfs page cache coalescing */ 156 const struct nfs_pageio_ops *pg_read_ops; 157 const struct nfs_pageio_ops *pg_write_ops; 158 159 struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode); 160 161 int (*sync)(struct inode *inode, bool datasync); 162 163 /* 164 * Return PNFS_ATTEMPTED to indicate the layout code has attempted 165 * I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS 166 */ 167 enum pnfs_try_status (*read_pagelist)(struct nfs_pgio_header *); 168 enum pnfs_try_status (*write_pagelist)(struct nfs_pgio_header *, int); 169 170 void (*free_deviceid_node) (struct nfs4_deviceid_node *); 171 struct nfs4_deviceid_node * (*alloc_deviceid_node) 172 (struct nfs_server *server, struct pnfs_device *pdev, 173 gfp_t gfp_flags); 174 /* 175 * Re-resolve @lo's references to the changed deviceid @id. Called 176 * under @lo's inode i_lock inside an RCU read-side critical section: 177 * must not sleep, allocations are GFP_ATOMIC. Rather than put the 178 * references it gives up (the final put can sleep), the hook 179 * allocates an nfs4_deviceid_put per reference and queues it on 180 * @put_list for the caller to put and free. On allocation failure 181 * it must leave the reference in place. 182 */ 183 void (*reresolve_deviceid)(struct pnfs_layout_hdr *lo, 184 const struct nfs4_deviceid *id, 185 bool immediate, 186 struct list_head *put_list); 187 /* 188 * Does @lo hold any reference to deviceid @id? Called under 189 * @lo's inode i_lock; must not sleep. 190 */ 191 bool (*layout_references_deviceid)(struct pnfs_layout_hdr *lo, 192 const struct nfs4_deviceid *id); 193 194 int (*prepare_layoutreturn) (struct nfs4_layoutreturn_args *); 195 196 void (*cleanup_layoutcommit) (struct nfs4_layoutcommit_data *data); 197 int (*prepare_layoutcommit) (struct nfs4_layoutcommit_args *args); 198 int (*prepare_layoutstats) (struct nfs42_layoutstat_args *args); 199 200 void (*cancel_io)(struct pnfs_layout_segment *lseg, 201 const struct nfs4_deviceid *devid); 202 }; 203 204 struct pnfs_commit_ops { 205 void (*setup_ds_info)(struct pnfs_ds_commit_info *, 206 struct pnfs_layout_segment *); 207 void (*release_ds_info)(struct pnfs_ds_commit_info *, 208 struct inode *inode); 209 int (*commit_pagelist)(struct inode *inode, 210 struct list_head *mds_pages, 211 int how, 212 struct nfs_commit_info *cinfo); 213 void (*mark_request_commit) (struct nfs_page *req, 214 struct pnfs_layout_segment *lseg, 215 struct nfs_commit_info *cinfo, 216 u32 ds_commit_idx); 217 void (*clear_request_commit) (struct nfs_page *req, 218 struct nfs_commit_info *cinfo); 219 int (*scan_commit_lists) (struct nfs_commit_info *cinfo, 220 int max); 221 void (*recover_commit_reqs) (struct list_head *list, 222 struct nfs_commit_info *cinfo); 223 }; 224 225 struct pnfs_layout_hdr { 226 refcount_t plh_refcount; 227 atomic_t plh_outstanding; /* number of RPCs out */ 228 struct list_head plh_layouts; /* other client layouts */ 229 struct list_head plh_bulk_destroy; 230 struct list_head plh_segs; /* layout segments list */ 231 struct list_head plh_return_segs; /* invalid layout segments */ 232 unsigned long plh_block_lgets; /* block LAYOUTGET if >0 */ 233 unsigned long plh_retry_timestamp; 234 unsigned long plh_flags; 235 nfs4_stateid plh_stateid; 236 u32 plh_barrier; /* ignore lower seqids */ 237 u32 plh_return_seq; 238 enum pnfs_iomode plh_return_iomode; 239 loff_t plh_lwb; /* last write byte for layoutcommit */ 240 const struct cred *plh_lc_cred; /* layoutcommit cred */ 241 struct inode *plh_inode; 242 struct rcu_head plh_rcu; 243 }; 244 245 struct pnfs_device { 246 struct nfs4_deviceid dev_id; 247 unsigned int layout_type; 248 unsigned int mincount; 249 unsigned int maxcount; /* gdia_maxcount */ 250 struct page **pages; 251 unsigned int pgbase; 252 unsigned int pglen; /* reply buffer length */ 253 unsigned char nocache : 1;/* May not be cached */ 254 }; 255 256 #define NFS4_PNFS_GETDEVLIST_MAXNUM 16 257 258 struct pnfs_devicelist { 259 unsigned int eof; 260 unsigned int num_devs; 261 struct nfs4_deviceid dev_id[NFS4_PNFS_GETDEVLIST_MAXNUM]; 262 }; 263 264 extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *); 265 extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *); 266 extern const struct pnfs_layoutdriver_type *pnfs_find_layoutdriver(u32 id); 267 extern void pnfs_put_layoutdriver(const struct pnfs_layoutdriver_type *ld); 268 269 /* nfs4proc.c */ 270 #define PNFS_FL_LAYOUTRETURN_ASYNC (1U << 0) 271 #define PNFS_FL_LAYOUTRETURN_PRIVILEGED (1U << 1) 272 273 extern size_t max_response_pages(struct nfs_server *server); 274 extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, 275 struct pnfs_device *dev, 276 const struct cred *cred); 277 extern struct pnfs_layout_segment * 278 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, 279 struct nfs4_exception *exception); 280 extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, 281 unsigned int flags); 282 283 /* pnfs.c */ 284 void pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo); 285 void pnfs_put_lseg(struct pnfs_layout_segment *lseg); 286 287 void set_pnfs_layoutdriver(struct nfs_server *, const struct nfs_fh *, struct nfs_fsinfo *); 288 void unset_pnfs_layoutdriver(struct nfs_server *); 289 void pnfs_generic_pg_check_layout(struct nfs_pageio_descriptor *pgio, struct nfs_page *req); 290 void pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *, struct nfs_page *); 291 int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc); 292 void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, 293 struct nfs_page *req, u64 wb_size); 294 void pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *); 295 int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc); 296 size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, 297 struct nfs_page *prev, struct nfs_page *req); 298 void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg); 299 struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp); 300 void pnfs_layoutget_free(struct nfs4_layoutget *lgp); 301 void pnfs_free_lseg_list(struct list_head *tmp_list); 302 void pnfs_destroy_layout(struct nfs_inode *); 303 void pnfs_destroy_layout_final(struct nfs_inode *); 304 void pnfs_destroy_all_layouts(struct nfs_client *); 305 int pnfs_layout_destroy_byfsid(struct nfs_client *clp, struct nfs_fsid *fsid, 306 enum pnfs_layout_destroy_mode mode); 307 int pnfs_layout_destroy_byclid(struct nfs_client *clp, 308 enum pnfs_layout_destroy_mode mode); 309 bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, 310 struct pnfs_layout_range *dst_range, 311 struct inode *inode); 312 void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo); 313 void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, 314 const nfs4_stateid *new, 315 const struct cred *cred, 316 bool update_barrier); 317 int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, 318 struct list_head *tmp_list, 319 const struct pnfs_layout_range *recall_range, 320 u32 seq); 321 int pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo, 322 struct list_head *tmp_list, 323 const struct pnfs_layout_range *recall_range, 324 u32 seq, bool cancel_io, 325 const struct nfs4_deviceid *devid); 326 int pnfs_mark_layout_stateid_invalid(struct pnfs_layout_hdr *lo, 327 struct list_head *lseg_list); 328 bool pnfs_roc(struct inode *ino, struct nfs4_layoutreturn_args *args, 329 struct nfs4_layoutreturn_res *res, const struct cred *cred, 330 bool sync); 331 int pnfs_roc_done(struct rpc_task *task, struct nfs4_layoutreturn_args **argpp, 332 struct nfs4_layoutreturn_res **respp, int *ret); 333 void pnfs_roc_release(struct nfs4_layoutreturn_args *args, 334 struct nfs4_layoutreturn_res *res, 335 int ret); 336 bool pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task); 337 void pnfs_set_layoutcommit(struct inode *, struct pnfs_layout_segment *, loff_t); 338 void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data); 339 int pnfs_layoutcommit_inode(struct inode *inode, bool sync); 340 int pnfs_generic_sync(struct inode *inode, bool datasync); 341 int pnfs_nfs_generic_sync(struct inode *inode, bool datasync); 342 int _pnfs_return_layout(struct inode *); 343 int pnfs_commit_and_return_layout(struct inode *); 344 void pnfs_ld_write_done(struct nfs_pgio_header *); 345 void pnfs_ld_read_done(struct nfs_pgio_header *); 346 void pnfs_read_resend_pnfs(struct nfs_pgio_header *, unsigned int mirror_idx); 347 struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino, 348 struct nfs_open_context *ctx, 349 loff_t pos, 350 u64 count, 351 enum pnfs_iomode iomode, 352 bool strict_iomode, 353 gfp_t gfp_flags); 354 void pnfs_layoutreturn_retry_later(struct pnfs_layout_hdr *lo, 355 const nfs4_stateid *arg_stateid, 356 const struct pnfs_layout_range *range); 357 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo, 358 const nfs4_stateid *arg_stateid, 359 const struct pnfs_layout_range *range, 360 const nfs4_stateid *stateid); 361 362 void pnfs_generic_layout_insert_lseg(struct pnfs_layout_hdr *lo, 363 struct pnfs_layout_segment *lseg, 364 bool (*is_after)(const struct pnfs_layout_range *lseg_range, 365 const struct pnfs_layout_range *old), 366 bool (*do_merge)(struct pnfs_layout_segment *lseg, 367 struct pnfs_layout_segment *old), 368 struct list_head *free_me); 369 370 void nfs4_deviceid_mark_client_invalid(struct nfs_client *clp); 371 int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *); 372 int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *); 373 struct nfs4_threshold *pnfs_mdsthreshold_alloc(void); 374 void pnfs_error_mark_layout_for_return(struct inode *inode, 375 struct pnfs_layout_segment *lseg, 376 const struct nfs4_deviceid *devid); 377 void pnfs_layout_return_unused_byclid(struct nfs_client *clp, 378 enum pnfs_iomode iomode); 379 void pnfs_layout_reresolve_deviceid_byclid(struct nfs_client *clp, 380 const struct pnfs_layoutdriver_type *ld, 381 const struct nfs4_deviceid *devid, 382 bool immediate); 383 bool pnfs_layout_deviceid_referenced_byclid(struct nfs_client *clp, 384 const struct pnfs_layoutdriver_type *ld, 385 const struct nfs4_deviceid *devid); 386 387 /* 388 * One live layout referencing a deviceID, collected for the 389 * CB_NOTIFY_DEVICEID DELETE recovery: the hdr is pinned, the inode 390 * igrab'd with its superblock active, and the layout stateid and 391 * cred snapshotted for TEST_STATEID. 392 */ 393 struct nfs4_deviceid_ref { 394 struct list_head node; 395 struct pnfs_layout_hdr *lo; 396 struct inode *inode; 397 nfs4_stateid stateid; 398 const struct cred *cred; 399 }; 400 401 int pnfs_layout_collect_deviceid_refs(struct nfs_client *clp, 402 const struct pnfs_layoutdriver_type *ld, 403 const struct nfs4_deviceid *devid, 404 struct list_head *result); 405 void pnfs_layout_put_deviceid_refs(struct list_head *result); 406 407 /* 408 * A CB_NOTIFY_DEVICEID DELETE naming a deviceID that live layouts 409 * still reference (RFC 8881 Section 18.40.4). Queued on 410 * nfs_client.cl_deviceid_deletes under cl_lock for the state manager 411 * to resolve; holds a layoutdriver reference. 412 */ 413 struct nfs4_deviceid_delete { 414 struct list_head list; 415 const struct pnfs_layoutdriver_type *ld; 416 struct nfs4_deviceid id; 417 }; 418 419 void pnfs_deviceid_delete_mark(struct nfs_client *clp, 420 const struct pnfs_layoutdriver_type *ld, 421 const struct nfs4_deviceid *id); 422 struct nfs4_deviceid_delete *pnfs_deviceid_delete_dequeue( 423 struct nfs_client *clp); 424 void pnfs_deviceid_delete_queue_free(struct nfs_client *clp); 425 int pnfs_layout_handle_reboot(struct nfs_client *clp); 426 427 /* nfs4_deviceid_flags */ 428 enum { 429 NFS_DEVICEID_INVALID = 0, /* set when MDS clientid recalled */ 430 NFS_DEVICEID_UNAVAILABLE, /* device temporarily unavailable */ 431 NFS_DEVICEID_NOCACHE, /* device may not be cached */ 432 }; 433 434 /* pnfs_dev.c */ 435 struct nfs4_deviceid_node { 436 struct hlist_node node; 437 struct hlist_node tmpnode; 438 const struct pnfs_layoutdriver_type *ld; 439 const struct nfs_client *nfs_client; 440 unsigned long flags; 441 unsigned long timestamp_unavailable; 442 struct nfs4_deviceid deviceid; 443 struct rcu_head rcu; 444 atomic_t ref; 445 }; 446 447 /* One reference given up by reresolve_deviceid; nodes are shared, so a 448 * single pass can unpin the same node more than once. 449 */ 450 struct nfs4_deviceid_put { 451 struct list_head node; 452 struct nfs4_deviceid_node *dev; 453 }; 454 455 struct nfs4_deviceid_node * 456 nfs4_find_get_deviceid(struct nfs_server *server, 457 const struct nfs4_deviceid *id, const struct cred *cred, 458 gfp_t gfp_mask); 459 void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 460 void nfs4_deviceid_bump_change_epoch(struct nfs_client *clp); 461 void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, struct nfs_server *, 462 const struct nfs4_deviceid *); 463 bool nfs4_put_deviceid_node(struct nfs4_deviceid_node *); 464 void nfs4_mark_deviceid_available(struct nfs4_deviceid_node *node); 465 466 /* Put the device node reference carried by an in-flight I/O, if any */ 467 static inline void pnfs_put_ds_dev(struct nfs4_deviceid_node *dev) 468 { 469 if (dev) 470 nfs4_put_deviceid_node(dev); 471 } 472 473 void nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node); 474 bool nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node); 475 void nfs4_deviceid_purge_client(const struct nfs_client *); 476 477 /* pnfs_nfs.c */ 478 struct pnfs_commit_array *pnfs_alloc_commit_array(size_t n, gfp_t gfp_flags); 479 void pnfs_free_commit_array(struct pnfs_commit_array *p); 480 struct pnfs_commit_array *pnfs_add_commit_array(struct pnfs_ds_commit_info *, 481 struct pnfs_commit_array *, 482 struct pnfs_layout_segment *); 483 484 void pnfs_generic_ds_cinfo_release_lseg(struct pnfs_ds_commit_info *fl_cinfo, 485 struct pnfs_layout_segment *lseg); 486 void pnfs_generic_ds_cinfo_destroy(struct pnfs_ds_commit_info *fl_cinfo); 487 488 void pnfs_generic_clear_request_commit(struct nfs_page *req, 489 struct nfs_commit_info *cinfo); 490 void pnfs_generic_commit_release(void *calldata); 491 void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data); 492 void pnfs_generic_rw_release(void *data); 493 void pnfs_generic_recover_commit_reqs(struct list_head *dst, 494 struct nfs_commit_info *cinfo); 495 int pnfs_generic_commit_pagelist(struct inode *inode, 496 struct list_head *mds_pages, 497 int how, 498 struct nfs_commit_info *cinfo, 499 int (*initiate_commit)(struct nfs_commit_data *data, 500 int how)); 501 int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, int max); 502 void pnfs_generic_write_commit_done(struct rpc_task *task, void *data); 503 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds); 504 struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(const struct net *net, 505 struct list_head *dsaddrs, 506 u32 version, gfp_t gfp_flags); 507 void nfs4_pnfs_v3_ds_connect_unload(void); 508 int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds, 509 struct nfs4_deviceid_node *devid, unsigned int timeo, 510 unsigned int retrans, unsigned int nconnect, 511 u32 version, u32 minor_version, 512 bool tightly_coupled); 513 struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net, 514 struct xdr_stream *xdr, 515 gfp_t gfp_flags); 516 void nfs4_pnfs_ds_addr_list_free(struct list_head *dsaddrs); 517 void pnfs_layout_mark_request_commit(struct nfs_page *req, 518 struct pnfs_layout_segment *lseg, 519 struct nfs_commit_info *cinfo, 520 u32 ds_commit_idx); 521 void pnfs_lgopen_prepare(struct nfs4_opendata *data, 522 struct nfs_open_context *ctx); 523 void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, 524 struct nfs_open_context *ctx); 525 void nfs4_lgopen_release(struct nfs4_layoutget *lgp); 526 527 static inline bool nfs_have_layout(struct inode *inode) 528 { 529 return NFS_I(inode)->layout != NULL; 530 } 531 532 static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo) 533 { 534 return test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) == 0; 535 } 536 537 static inline struct nfs4_deviceid_node * 538 nfs4_get_deviceid(struct nfs4_deviceid_node *d) 539 { 540 atomic_inc(&d->ref); 541 return d; 542 } 543 544 static inline struct pnfs_layout_segment * 545 pnfs_get_lseg(struct pnfs_layout_segment *lseg) 546 { 547 if (lseg) { 548 refcount_inc(&lseg->pls_refcount); 549 smp_mb__after_atomic(); 550 } 551 return lseg; 552 } 553 554 static inline bool 555 pnfs_is_valid_lseg(struct pnfs_layout_segment *lseg) 556 { 557 return test_bit(NFS_LSEG_VALID, &lseg->pls_flags) != 0; 558 } 559 560 /* Return true if a layout driver is being used for this mountpoint */ 561 static inline int pnfs_enabled_sb(struct nfs_server *nfss) 562 { 563 return nfss->pnfs_curr_ld != NULL; 564 } 565 566 static inline int 567 pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how, 568 struct nfs_commit_info *cinfo) 569 { 570 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; 571 572 if (fl_cinfo == NULL || fl_cinfo->ncommitting == 0) 573 return PNFS_NOT_ATTEMPTED; 574 return fl_cinfo->ops->commit_pagelist(inode, mds_pages, how, cinfo); 575 } 576 577 static inline struct pnfs_ds_commit_info * 578 pnfs_get_ds_info(struct inode *inode) 579 { 580 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; 581 582 if (ld == NULL || ld->get_ds_info == NULL) 583 return NULL; 584 return ld->get_ds_info(inode); 585 } 586 587 static inline void 588 pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode) 589 { 590 struct pnfs_ds_commit_info *inode_cinfo = pnfs_get_ds_info(inode); 591 if (inode_cinfo != NULL) 592 fl_cinfo->ops = inode_cinfo->ops; 593 } 594 595 static inline void 596 pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo) 597 { 598 INIT_LIST_HEAD(&fl_cinfo->commits); 599 fl_cinfo->ops = NULL; 600 } 601 602 static inline void 603 pnfs_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode) 604 { 605 if (fl_cinfo->ops != NULL && fl_cinfo->ops->release_ds_info != NULL) 606 fl_cinfo->ops->release_ds_info(fl_cinfo, inode); 607 } 608 609 static inline void 610 pnfs_generic_mark_devid_invalid(struct nfs4_deviceid_node *node) 611 { 612 set_bit(NFS_DEVICEID_INVALID, &node->flags); 613 } 614 615 static inline bool 616 pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, 617 struct nfs_commit_info *cinfo, u32 ds_commit_idx) 618 { 619 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; 620 621 if (!lseg || !fl_cinfo->ops || !fl_cinfo->ops->mark_request_commit) 622 return false; 623 fl_cinfo->ops->mark_request_commit(req, lseg, cinfo, ds_commit_idx); 624 return true; 625 } 626 627 static inline bool 628 pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo) 629 { 630 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; 631 632 if (!fl_cinfo || !fl_cinfo->ops || !fl_cinfo->ops->clear_request_commit) 633 return false; 634 fl_cinfo->ops->clear_request_commit(req, cinfo); 635 return true; 636 } 637 638 static inline int 639 pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, 640 int max) 641 { 642 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; 643 644 if (!fl_cinfo || fl_cinfo->nwritten == 0) 645 return 0; 646 return fl_cinfo->ops->scan_commit_lists(cinfo, max); 647 } 648 649 static inline void 650 pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo) 651 { 652 struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; 653 654 if (fl_cinfo && fl_cinfo->nwritten != 0) 655 fl_cinfo->ops->recover_commit_reqs(head, cinfo); 656 } 657 658 /* Should the pNFS client commit and return the layout upon a setattr */ 659 static inline bool 660 pnfs_ld_layoutret_on_setattr(struct inode *inode) 661 { 662 if (!pnfs_enabled_sb(NFS_SERVER(inode))) 663 return false; 664 return NFS_SERVER(inode)->pnfs_curr_ld->flags & 665 PNFS_LAYOUTRET_ON_SETATTR; 666 } 667 668 static inline bool 669 pnfs_ld_read_whole_page(struct inode *inode) 670 { 671 if (!pnfs_enabled_sb(NFS_SERVER(inode))) 672 return false; 673 return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE; 674 } 675 676 static inline int 677 pnfs_sync_inode(struct inode *inode, bool datasync) 678 { 679 if (!pnfs_enabled_sb(NFS_SERVER(inode))) 680 return 0; 681 return NFS_SERVER(inode)->pnfs_curr_ld->sync(inode, datasync); 682 } 683 684 static inline bool 685 pnfs_layoutcommit_outstanding(struct inode *inode) 686 { 687 struct nfs_inode *nfsi = NFS_I(inode); 688 689 return test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags) != 0 || 690 test_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags) != 0; 691 } 692 693 static inline int pnfs_return_layout(struct inode *ino) 694 { 695 struct nfs_inode *nfsi = NFS_I(ino); 696 struct nfs_server *nfss = NFS_SERVER(ino); 697 698 if (pnfs_enabled_sb(nfss) && nfsi->layout) { 699 set_bit(NFS_LAYOUT_RETURN_REQUESTED, &nfsi->layout->plh_flags); 700 return _pnfs_return_layout(ino); 701 } 702 703 return 0; 704 } 705 706 static inline bool 707 pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src, 708 struct nfs_server *nfss) 709 { 710 return (dst && src && src->bm != 0 && nfss->pnfs_curr_ld && 711 nfss->pnfs_curr_ld->id == src->l_type); 712 } 713 714 static inline u64 715 pnfs_calc_offset_end(u64 offset, u64 len) 716 { 717 if (len == NFS4_MAX_UINT64 || len >= NFS4_MAX_UINT64 - offset) 718 return NFS4_MAX_UINT64; 719 return offset + len - 1; 720 } 721 722 static inline u64 723 pnfs_calc_offset_length(u64 offset, u64 end) 724 { 725 if (end == NFS4_MAX_UINT64 || end <= offset) 726 return NFS4_MAX_UINT64; 727 return 1 + end - offset; 728 } 729 730 static inline void 731 pnfs_copy_range(struct pnfs_layout_range *dst, 732 const struct pnfs_layout_range *src) 733 { 734 memcpy(dst, src, sizeof(*dst)); 735 } 736 737 static inline u64 738 pnfs_end_offset(u64 start, u64 len) 739 { 740 if (NFS4_MAX_UINT64 - start <= len) 741 return NFS4_MAX_UINT64; 742 return start + len; 743 } 744 745 /* 746 * Are 2 ranges intersecting? 747 * start1 end1 748 * [----------------------------------) 749 * start2 end2 750 * [----------------) 751 */ 752 static inline bool 753 pnfs_is_range_intersecting(u64 start1, u64 end1, u64 start2, u64 end2) 754 { 755 return (end1 == NFS4_MAX_UINT64 || start2 < end1) && 756 (end2 == NFS4_MAX_UINT64 || start1 < end2); 757 } 758 759 static inline bool 760 pnfs_lseg_range_intersecting(const struct pnfs_layout_range *l1, 761 const struct pnfs_layout_range *l2) 762 { 763 u64 end1 = pnfs_end_offset(l1->offset, l1->length); 764 u64 end2 = pnfs_end_offset(l2->offset, l2->length); 765 766 return pnfs_is_range_intersecting(l1->offset, end1, l2->offset, end2); 767 } 768 769 static inline bool 770 pnfs_lseg_request_intersecting(struct pnfs_layout_segment *lseg, struct nfs_page *req) 771 { 772 u64 seg_last = pnfs_end_offset(lseg->pls_range.offset, lseg->pls_range.length); 773 u64 req_last = req_offset(req) + req->wb_bytes; 774 775 return pnfs_is_range_intersecting(lseg->pls_range.offset, seg_last, 776 req_offset(req), req_last); 777 } 778 779 static inline void pnfs_lseg_cancel_io(struct nfs_server *server, 780 struct pnfs_layout_segment *lseg, 781 const struct nfs4_deviceid *devid) 782 { 783 if (server->pnfs_curr_ld->cancel_io) 784 server->pnfs_curr_ld->cancel_io(lseg, devid); 785 } 786 787 extern unsigned int layoutstats_timer; 788 789 #ifdef NFS_DEBUG 790 void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id); 791 #else 792 static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id) 793 { 794 } 795 796 #endif /* NFS_DEBUG */ 797 #else /* CONFIG_NFS_V4 */ 798 799 static inline bool nfs_have_layout(struct inode *inode) 800 { 801 return false; 802 } 803 804 static inline void pnfs_destroy_all_layouts(struct nfs_client *clp) 805 { 806 } 807 808 static inline void pnfs_destroy_layout(struct nfs_inode *nfsi) 809 { 810 } 811 812 static inline void pnfs_destroy_layout_final(struct nfs_inode *nfsi) 813 { 814 } 815 816 static inline int pnfs_layout_handle_reboot(struct nfs_client *clp) 817 { 818 return 0; 819 } 820 821 static inline struct pnfs_layout_segment * 822 pnfs_get_lseg(struct pnfs_layout_segment *lseg) 823 { 824 return NULL; 825 } 826 827 static inline void pnfs_put_lseg(struct pnfs_layout_segment *lseg) 828 { 829 } 830 831 static inline int pnfs_return_layout(struct inode *ino) 832 { 833 return 0; 834 } 835 836 static inline int pnfs_commit_and_return_layout(struct inode *inode) 837 { 838 return 0; 839 } 840 841 static inline bool 842 pnfs_ld_layoutret_on_setattr(struct inode *inode) 843 { 844 return false; 845 } 846 847 static inline bool 848 pnfs_ld_read_whole_page(struct inode *inode) 849 { 850 return false; 851 } 852 853 static inline int 854 pnfs_sync_inode(struct inode *inode, bool datasync) 855 { 856 return 0; 857 } 858 859 static inline bool 860 pnfs_layoutcommit_outstanding(struct inode *inode) 861 { 862 return false; 863 } 864 865 static inline bool pnfs_roc(struct inode *ino, 866 struct nfs4_layoutreturn_args *args, 867 struct nfs4_layoutreturn_res *res, 868 const struct cred *cred, bool sync) 869 { 870 return false; 871 } 872 873 static inline int 874 pnfs_roc_done(struct rpc_task *task, 875 struct nfs4_layoutreturn_args **argpp, 876 struct nfs4_layoutreturn_res **respp, 877 int *ret) 878 { 879 return 0; 880 } 881 882 static inline void 883 pnfs_roc_release(struct nfs4_layoutreturn_args *args, 884 struct nfs4_layoutreturn_res *res, 885 int ret) 886 { 887 } 888 889 static inline bool 890 pnfs_wait_on_layoutreturn(struct inode *ino, struct rpc_task *task) 891 { 892 return false; 893 } 894 895 static inline void set_pnfs_layoutdriver(struct nfs_server *s, 896 const struct nfs_fh *mntfh, 897 struct nfs_fsinfo *fsinfo) 898 { 899 } 900 901 static inline void unset_pnfs_layoutdriver(struct nfs_server *s) 902 { 903 } 904 905 static inline int 906 pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how, 907 struct nfs_commit_info *cinfo) 908 { 909 return PNFS_NOT_ATTEMPTED; 910 } 911 912 static inline struct pnfs_ds_commit_info * 913 pnfs_get_ds_info(struct inode *inode) 914 { 915 return NULL; 916 } 917 918 static inline void 919 pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode) 920 { 921 } 922 923 static inline void 924 pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo) 925 { 926 } 927 928 static inline void 929 pnfs_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode) 930 { 931 } 932 933 static inline bool 934 pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, 935 struct nfs_commit_info *cinfo, u32 ds_commit_idx) 936 { 937 return false; 938 } 939 940 static inline bool 941 pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo) 942 { 943 return false; 944 } 945 946 static inline int 947 pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, 948 int max) 949 { 950 return 0; 951 } 952 953 static inline void 954 pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo) 955 { 956 } 957 958 static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync) 959 { 960 return 0; 961 } 962 963 static inline bool 964 pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src, 965 struct nfs_server *nfss) 966 { 967 return false; 968 } 969 970 static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) 971 { 972 return NULL; 973 } 974 975 static inline void nfs4_pnfs_v3_ds_connect_unload(void) 976 { 977 } 978 979 static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, 980 struct pnfs_layout_range *dst_range, 981 struct inode *inode) 982 { 983 return false; 984 } 985 986 static inline void pnfs_lgopen_prepare(struct nfs4_opendata *data, 987 struct nfs_open_context *ctx) 988 { 989 } 990 991 static inline void pnfs_parse_lgopen(struct inode *ino, 992 struct nfs4_layoutget *lgp, 993 struct nfs_open_context *ctx) 994 { 995 } 996 997 static inline void nfs4_lgopen_release(struct nfs4_layoutget *lgp) 998 { 999 } 1000 1001 static inline bool pnfs_layout_is_valid(const struct pnfs_layout_hdr *lo) 1002 { 1003 return false; 1004 } 1005 1006 #endif /* CONFIG_NFS_V4 */ 1007 1008 #if IS_ENABLED(CONFIG_NFS_V4_2) 1009 int pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags); 1010 #else 1011 static inline int 1012 pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags) 1013 { 1014 return 0; 1015 } 1016 #endif 1017 1018 #endif /* FS_NFS_PNFS_H */ 1019