Skip to content

Commit 9c455a8

Browse files
author
Trond Myklebust
committed
NFS/pNFS: Clean up pNFS commit operations
Move the pNFS commit related operations into a separate structure that can be carried by the pnfs_ds_commit_info. Signed-off-by: Trond Myklebust <[email protected]>
1 parent 0aa647b commit 9c455a8

File tree

6 files changed

+98
-71
lines changed

6 files changed

+98
-71
lines changed

fs/nfs/direct.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,7 @@ nfs_direct_write_scan_commit_list(struct inode *inode,
511511
struct nfs_commit_info *cinfo)
512512
{
513513
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
514-
#ifdef CONFIG_NFS_V4_1
515-
if (cinfo->ds != NULL && cinfo->ds->nwritten != 0)
516-
NFS_SERVER(inode)->pnfs_curr_ld->recover_commit_reqs(list, cinfo);
517-
#endif
514+
pnfs_recover_commit_reqs(list, cinfo);
518515
nfs_scan_commit_list(&cinfo->mds->list, list, cinfo, 0);
519516
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
520517
}
@@ -917,6 +914,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
917914
dreq->l_ctx = l_ctx;
918915
if (!is_sync_kiocb(iocb))
919916
dreq->iocb = iocb;
917+
pnfs_init_ds_commit_info_ops(&dreq->ds_cinfo, inode);
920918

921919
nfs_start_io_direct(inode);
922920

fs/nfs/filelayout/filelayout.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ MODULE_AUTHOR("Dean Hildebrand <[email protected]>");
4949
MODULE_DESCRIPTION("The NFSv4 file layout driver");
5050

5151
#define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
52+
static const struct pnfs_commit_ops filelayout_commit_ops;
5253

5354
static loff_t
5455
filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
@@ -1045,6 +1046,7 @@ filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
10451046
if (flo == NULL)
10461047
return NULL;
10471048
pnfs_init_ds_commit_info(&flo->commit_info);
1049+
flo->commit_info.ops = &filelayout_commit_ops;
10481050
return &flo->generic_hdr;
10491051
}
10501052

@@ -1094,6 +1096,16 @@ filelayout_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
10941096
spin_unlock(&inode->i_lock);
10951097
}
10961098

1099+
static const struct pnfs_commit_ops filelayout_commit_ops = {
1100+
.setup_ds_info = filelayout_setup_ds_info,
1101+
.release_ds_info = filelayout_release_ds_info,
1102+
.mark_request_commit = filelayout_mark_request_commit,
1103+
.clear_request_commit = pnfs_generic_clear_request_commit,
1104+
.scan_commit_lists = pnfs_generic_scan_commit_lists,
1105+
.recover_commit_reqs = pnfs_generic_recover_commit_reqs,
1106+
.search_commit_reqs = pnfs_generic_search_commit_reqs,
1107+
.commit_pagelist = filelayout_commit_pagelist,
1108+
};
10971109

10981110
static struct pnfs_layoutdriver_type filelayout_type = {
10991111
.id = LAYOUT_NFSV4_1_FILES,
@@ -1108,14 +1120,6 @@ static struct pnfs_layoutdriver_type filelayout_type = {
11081120
.pg_read_ops = &filelayout_pg_read_ops,
11091121
.pg_write_ops = &filelayout_pg_write_ops,
11101122
.get_ds_info = &filelayout_get_ds_info,
1111-
.setup_ds_info = filelayout_setup_ds_info,
1112-
.release_ds_info = filelayout_release_ds_info,
1113-
.mark_request_commit = filelayout_mark_request_commit,
1114-
.clear_request_commit = pnfs_generic_clear_request_commit,
1115-
.scan_commit_lists = pnfs_generic_scan_commit_lists,
1116-
.recover_commit_reqs = pnfs_generic_recover_commit_reqs,
1117-
.search_commit_reqs = pnfs_generic_search_commit_reqs,
1118-
.commit_pagelist = filelayout_commit_pagelist,
11191123
.read_pagelist = filelayout_read_pagelist,
11201124
.write_pagelist = filelayout_write_pagelist,
11211125
.alloc_deviceid_node = filelayout_alloc_deviceid_node,

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
static unsigned short io_maxretrans;
3434

35+
static const struct pnfs_commit_ops ff_layout_commit_ops;
3536
static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
3637
struct nfs_pgio_header *hdr);
3738
static int ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,
@@ -52,6 +53,7 @@ ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
5253
INIT_LIST_HEAD(&ffl->error_list);
5354
INIT_LIST_HEAD(&ffl->mirrors);
5455
ffl->last_report_time = ktime_get();
56+
ffl->commit_info.ops = &ff_layout_commit_ops;
5557
return &ffl->generic_hdr;
5658
} else
5759
return NULL;
@@ -2440,6 +2442,16 @@ ff_layout_set_layoutdriver(struct nfs_server *server,
24402442
return 0;
24412443
}
24422444

2445+
static const struct pnfs_commit_ops ff_layout_commit_ops = {
2446+
.setup_ds_info = ff_layout_setup_ds_info,
2447+
.release_ds_info = ff_layout_release_ds_info,
2448+
.mark_request_commit = pnfs_layout_mark_request_commit,
2449+
.clear_request_commit = pnfs_generic_clear_request_commit,
2450+
.scan_commit_lists = pnfs_generic_scan_commit_lists,
2451+
.recover_commit_reqs = pnfs_generic_recover_commit_reqs,
2452+
.commit_pagelist = ff_layout_commit_pagelist,
2453+
};
2454+
24432455
static struct pnfs_layoutdriver_type flexfilelayout_type = {
24442456
.id = LAYOUT_FLEX_FILES,
24452457
.name = "LAYOUT_FLEX_FILES",
@@ -2455,14 +2467,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
24552467
.pg_read_ops = &ff_layout_pg_read_ops,
24562468
.pg_write_ops = &ff_layout_pg_write_ops,
24572469
.get_ds_info = ff_layout_get_ds_info,
2458-
.setup_ds_info = ff_layout_setup_ds_info,
2459-
.release_ds_info = ff_layout_release_ds_info,
24602470
.free_deviceid_node = ff_layout_free_deviceid_node,
2461-
.mark_request_commit = pnfs_layout_mark_request_commit,
2462-
.clear_request_commit = pnfs_generic_clear_request_commit,
2463-
.scan_commit_lists = pnfs_generic_scan_commit_lists,
2464-
.recover_commit_reqs = pnfs_generic_recover_commit_reqs,
2465-
.commit_pagelist = ff_layout_commit_pagelist,
24662471
.read_pagelist = ff_layout_read_pagelist,
24672472
.write_pagelist = ff_layout_write_pagelist,
24682473
.alloc_deviceid_node = ff_layout_alloc_deviceid_node,

fs/nfs/pnfs.h

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,6 @@ struct pnfs_layoutdriver_type {
150150
const struct nfs_pageio_ops *pg_write_ops;
151151

152152
struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode);
153-
void (*setup_ds_info)(struct pnfs_ds_commit_info *,
154-
struct pnfs_layout_segment *);
155-
void (*release_ds_info)(struct pnfs_ds_commit_info *,
156-
struct inode *inode);
157-
void (*mark_request_commit) (struct nfs_page *req,
158-
struct pnfs_layout_segment *lseg,
159-
struct nfs_commit_info *cinfo,
160-
u32 ds_commit_idx);
161-
void (*clear_request_commit) (struct nfs_page *req,
162-
struct nfs_commit_info *cinfo);
163-
int (*scan_commit_lists) (struct nfs_commit_info *cinfo,
164-
int max);
165-
void (*recover_commit_reqs) (struct list_head *list,
166-
struct nfs_commit_info *cinfo);
167-
struct nfs_page * (*search_commit_reqs)(struct nfs_commit_info *cinfo,
168-
struct page *page);
169-
int (*commit_pagelist)(struct inode *inode,
170-
struct list_head *mds_pages,
171-
int how,
172-
struct nfs_commit_info *cinfo);
173153

174154
int (*sync)(struct inode *inode, bool datasync);
175155

@@ -192,6 +172,29 @@ struct pnfs_layoutdriver_type {
192172
int (*prepare_layoutstats) (struct nfs42_layoutstat_args *args);
193173
};
194174

175+
struct pnfs_commit_ops {
176+
void (*setup_ds_info)(struct pnfs_ds_commit_info *,
177+
struct pnfs_layout_segment *);
178+
void (*release_ds_info)(struct pnfs_ds_commit_info *,
179+
struct inode *inode);
180+
int (*commit_pagelist)(struct inode *inode,
181+
struct list_head *mds_pages,
182+
int how,
183+
struct nfs_commit_info *cinfo);
184+
void (*mark_request_commit) (struct nfs_page *req,
185+
struct pnfs_layout_segment *lseg,
186+
struct nfs_commit_info *cinfo,
187+
u32 ds_commit_idx);
188+
void (*clear_request_commit) (struct nfs_page *req,
189+
struct nfs_commit_info *cinfo);
190+
int (*scan_commit_lists) (struct nfs_commit_info *cinfo,
191+
int max);
192+
void (*recover_commit_reqs) (struct list_head *list,
193+
struct nfs_commit_info *cinfo);
194+
struct nfs_page * (*search_commit_reqs)(struct nfs_commit_info *cinfo,
195+
struct page *page);
196+
};
197+
195198
struct pnfs_layout_hdr {
196199
refcount_t plh_refcount;
197200
atomic_t plh_outstanding; /* number of RPCs out */
@@ -461,9 +464,11 @@ static inline int
461464
pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how,
462465
struct nfs_commit_info *cinfo)
463466
{
464-
if (cinfo->ds == NULL || cinfo->ds->ncommitting == 0)
467+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
468+
469+
if (fl_cinfo == NULL || fl_cinfo->ncommitting == 0)
465470
return PNFS_NOT_ATTEMPTED;
466-
return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how, cinfo);
471+
return fl_cinfo->ops->commit_pagelist(inode, mds_pages, how, cinfo);
467472
}
468473

469474
static inline struct pnfs_ds_commit_info *
@@ -476,19 +481,26 @@ pnfs_get_ds_info(struct inode *inode)
476481
return ld->get_ds_info(inode);
477482
}
478483

484+
static inline void
485+
pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
486+
{
487+
struct pnfs_ds_commit_info *inode_cinfo = pnfs_get_ds_info(inode);
488+
if (inode_cinfo != NULL)
489+
fl_cinfo->ops = inode_cinfo->ops;
490+
}
491+
479492
static inline void
480493
pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo)
481494
{
482495
INIT_LIST_HEAD(&fl_cinfo->commits);
496+
fl_cinfo->ops = NULL;
483497
}
484498

485499
static inline void
486500
pnfs_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
487501
{
488-
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
489-
490-
if (ld != NULL && ld->release_ds_info != NULL)
491-
ld->release_ds_info(fl_cinfo, inode);
502+
if (fl_cinfo->ops != NULL && fl_cinfo->ops->release_ds_info != NULL)
503+
fl_cinfo->ops->release_ds_info(fl_cinfo, inode);
492504
}
493505

494506
static inline void
@@ -501,46 +513,54 @@ static inline bool
501513
pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
502514
struct nfs_commit_info *cinfo, u32 ds_commit_idx)
503515
{
504-
struct inode *inode = d_inode(nfs_req_openctx(req)->dentry);
505-
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
516+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
506517

507-
if (lseg == NULL || ld->mark_request_commit == NULL)
518+
if (!lseg || !fl_cinfo->ops->mark_request_commit)
508519
return false;
509-
ld->mark_request_commit(req, lseg, cinfo, ds_commit_idx);
520+
fl_cinfo->ops->mark_request_commit(req, lseg, cinfo, ds_commit_idx);
510521
return true;
511522
}
512523

513524
static inline bool
514525
pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
515526
{
516-
struct inode *inode = d_inode(nfs_req_openctx(req)->dentry);
517-
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
527+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
518528

519-
if (ld == NULL || ld->clear_request_commit == NULL)
529+
if (!fl_cinfo || !fl_cinfo->ops || !fl_cinfo->ops->clear_request_commit)
520530
return false;
521-
ld->clear_request_commit(req, cinfo);
531+
fl_cinfo->ops->clear_request_commit(req, cinfo);
522532
return true;
523533
}
524534

525535
static inline int
526536
pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
527537
int max)
528538
{
529-
if (cinfo->ds == NULL || cinfo->ds->nwritten == 0)
539+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
540+
541+
if (!fl_cinfo || fl_cinfo->nwritten == 0)
530542
return 0;
531-
else
532-
return NFS_SERVER(inode)->pnfs_curr_ld->scan_commit_lists(cinfo, max);
543+
return fl_cinfo->ops->scan_commit_lists(cinfo, max);
544+
}
545+
546+
static inline void
547+
pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo)
548+
{
549+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
550+
551+
if (fl_cinfo && fl_cinfo->nwritten != 0)
552+
fl_cinfo->ops->recover_commit_reqs(head, cinfo);
533553
}
534554

535555
static inline struct nfs_page *
536556
pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
537557
struct page *page)
538558
{
539-
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
559+
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
540560

541-
if (ld == NULL || ld->search_commit_reqs == NULL)
561+
if (!fl_cinfo->ops || !fl_cinfo->ops->search_commit_reqs)
542562
return NULL;
543-
return ld->search_commit_reqs(cinfo, page);
563+
return fl_cinfo->ops->search_commit_reqs(cinfo, page);
544564
}
545565

546566
/* Should the pNFS client commit and return the layout upon a setattr */
@@ -788,6 +808,11 @@ pnfs_get_ds_info(struct inode *inode)
788808
return NULL;
789809
}
790810

811+
static inline void
812+
pnfs_init_ds_commit_info_ops(struct pnfs_ds_commit_info *fl_cinfo, struct inode *inode)
813+
{
814+
}
815+
791816
static inline void
792817
pnfs_init_ds_commit_info(struct pnfs_ds_commit_info *fl_cinfo)
793818
{
@@ -818,6 +843,11 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo,
818843
return 0;
819844
}
820845

846+
static inline void
847+
pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo)
848+
{
849+
}
850+
821851
static inline struct nfs_page *
822852
pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo,
823853
struct page *page)

fs/nfs/pnfs_nfs.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,6 @@ pnfs_add_commit_array(struct pnfs_ds_commit_info *fl_cinfo,
149149
}
150150
EXPORT_SYMBOL_GPL(pnfs_add_commit_array);
151151

152-
static void
153-
pnfs_setup_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
154-
struct pnfs_layout_segment *lseg)
155-
{
156-
struct inode *inode = lseg->pls_layout->plh_inode;
157-
struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
158-
159-
if (ld->setup_ds_info != NULL)
160-
ld->setup_ds_info(fl_cinfo, lseg);
161-
}
162-
163152
static struct pnfs_commit_array *
164153
pnfs_lookup_commit_array(struct pnfs_ds_commit_info *fl_cinfo,
165154
struct pnfs_layout_segment *lseg)
@@ -170,7 +159,7 @@ pnfs_lookup_commit_array(struct pnfs_ds_commit_info *fl_cinfo,
170159
array = pnfs_find_commit_array_by_lseg(fl_cinfo, lseg);
171160
if (!array) {
172161
rcu_read_unlock();
173-
pnfs_setup_ds_info(fl_cinfo, lseg);
162+
fl_cinfo->ops->setup_ds_info(fl_cinfo, lseg);
174163
rcu_read_lock();
175164
array = pnfs_find_commit_array_by_lseg(fl_cinfo, lseg);
176165
}

include/linux/nfs_xdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ struct pnfs_ds_commit_info {
12841284
struct list_head commits;
12851285
unsigned int nwritten;
12861286
unsigned int ncommitting;
1287+
const struct pnfs_commit_ops *ops;
12871288
};
12881289

12891290
struct nfs41_state_protection {

0 commit comments

Comments
 (0)