Skip to content

Commit f453a54

Browse files
Fred IsamanTrond Myklebust
authored andcommitted
NFS: create nfs_commit_completion_ops
Factors out the code that needs to change when directio starts using these code paths. Signed-off-by: Fred Isaman <iisaman@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent ea2cf22 commit f453a54

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

fs/nfs/internal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,12 @@ extern int nfs_initiate_commit(struct rpc_clnt *clnt,
344344
int how);
345345
extern void nfs_init_commit(struct nfs_commit_data *data,
346346
struct list_head *head,
347-
struct pnfs_layout_segment *lseg);
347+
struct pnfs_layout_segment *lseg,
348+
struct nfs_commit_info *cinfo);
348349
void nfs_retry_commit(struct list_head *page_list,
349350
struct pnfs_layout_segment *lseg,
350351
struct nfs_commit_info *cinfo);
351-
void nfs_commit_clear_lock(struct nfs_inode *nfsi);
352352
void nfs_commitdata_release(struct nfs_commit_data *data);
353-
void nfs_commit_release_pages(struct nfs_commit_data *data);
354353
void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
355354
struct nfs_commit_info *cinfo);
356355
void nfs_request_remove_commit_list(struct nfs_page *req,

fs/nfs/nfs4filelayout.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,8 @@ static void filelayout_commit_count_stats(struct rpc_task *task, void *data)
347347
static void filelayout_commit_release(void *calldata)
348348
{
349349
struct nfs_commit_data *data = calldata;
350-
struct nfs_commit_info cinfo;
351350

352-
nfs_commit_release_pages(data);
353-
nfs_init_cinfo(&cinfo, data->inode, data->dreq);
354-
if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
355-
nfs_commit_clear_lock(NFS_I(data->inode));
351+
data->completion_ops->completion(data);
356352
put_lseg(data->lseg);
357353
nfs_commitdata_release(data);
358354
}
@@ -1108,7 +1104,7 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
11081104
nreq += alloc_ds_commits(cinfo, &list);
11091105

11101106
if (nreq == 0) {
1111-
nfs_commit_clear_lock(NFS_I(inode));
1107+
cinfo->completion_ops->error_cleanup(NFS_I(inode));
11121108
goto out;
11131109
}
11141110

@@ -1117,14 +1113,14 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
11171113
list_for_each_entry_safe(data, tmp, &list, pages) {
11181114
list_del_init(&data->pages);
11191115
if (!data->lseg) {
1120-
nfs_init_commit(data, mds_pages, NULL);
1116+
nfs_init_commit(data, mds_pages, NULL, cinfo);
11211117
nfs_initiate_commit(NFS_CLIENT(inode), data,
11221118
data->mds_ops, how);
11231119
} else {
11241120
struct pnfs_commit_bucket *buckets;
11251121

11261122
buckets = cinfo->ds->buckets;
1127-
nfs_init_commit(data, &buckets[data->ds_commit_index].committing, data->lseg);
1123+
nfs_init_commit(data, &buckets[data->ds_commit_index].committing, data->lseg, cinfo);
11281124
filelayout_initiate_commit(data, how);
11291125
}
11301126
}

fs/nfs/write.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void nfs_redirty_request(struct nfs_page *req);
4646
static const struct rpc_call_ops nfs_write_common_ops;
4747
static const struct rpc_call_ops nfs_commit_ops;
4848
static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops;
49+
static const struct nfs_commit_completion_ops nfs_commit_completion_ops;
4950

5051
static struct kmem_cache *nfs_wdata_cachep;
5152
static mempool_t *nfs_wdata_mempool;
@@ -505,6 +506,7 @@ static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
505506
cinfo->lock = &inode->i_lock;
506507
cinfo->mds = &NFS_I(inode)->commit_info;
507508
cinfo->ds = pnfs_get_ds_info(inode);
509+
cinfo->completion_ops = &nfs_commit_completion_ops;
508510
}
509511

510512
void nfs_init_cinfo(struct nfs_commit_info *cinfo,
@@ -1358,13 +1360,12 @@ static int nfs_commit_set_lock(struct nfs_inode *nfsi, int may_wait)
13581360
return (ret < 0) ? ret : 1;
13591361
}
13601362

1361-
void nfs_commit_clear_lock(struct nfs_inode *nfsi)
1363+
static void nfs_commit_clear_lock(struct nfs_inode *nfsi)
13621364
{
13631365
clear_bit(NFS_INO_COMMIT, &nfsi->flags);
13641366
smp_mb__after_clear_bit();
13651367
wake_up_bit(&nfsi->flags, NFS_INO_COMMIT);
13661368
}
1367-
EXPORT_SYMBOL_GPL(nfs_commit_clear_lock);
13681369

13691370
void nfs_commitdata_release(struct nfs_commit_data *data)
13701371
{
@@ -1413,8 +1414,9 @@ EXPORT_SYMBOL_GPL(nfs_initiate_commit);
14131414
* Set up the argument/result storage required for the RPC call.
14141415
*/
14151416
void nfs_init_commit(struct nfs_commit_data *data,
1416-
struct list_head *head,
1417-
struct pnfs_layout_segment *lseg)
1417+
struct list_head *head,
1418+
struct pnfs_layout_segment *lseg,
1419+
struct nfs_commit_info *cinfo)
14181420
{
14191421
struct nfs_page *first = nfs_list_entry(head->next);
14201422
struct inode *inode = first->wb_context->dentry->d_inode;
@@ -1428,6 +1430,7 @@ void nfs_init_commit(struct nfs_commit_data *data,
14281430
data->cred = first->wb_context->cred;
14291431
data->lseg = lseg; /* reference transferred */
14301432
data->mds_ops = &nfs_commit_ops;
1433+
data->completion_ops = cinfo->completion_ops;
14311434

14321435
data->args.fh = NFS_FH(data->inode);
14331436
/* Note: we always request a commit of the entire inode */
@@ -1473,11 +1476,12 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
14731476
goto out_bad;
14741477

14751478
/* Set up the argument struct */
1476-
nfs_init_commit(data, head, NULL);
1479+
nfs_init_commit(data, head, NULL, cinfo);
1480+
atomic_inc(&cinfo->mds->rpcs_out);
14771481
return nfs_initiate_commit(NFS_CLIENT(inode), data, data->mds_ops, how);
14781482
out_bad:
14791483
nfs_retry_commit(head, NULL, cinfo);
1480-
nfs_commit_clear_lock(NFS_I(inode));
1484+
cinfo->completion_ops->error_cleanup(NFS_I(inode));
14811485
return -ENOMEM;
14821486
}
14831487

@@ -1495,10 +1499,11 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
14951499
NFS_PROTO(data->inode)->commit_done(task, data);
14961500
}
14971501

1498-
void nfs_commit_release_pages(struct nfs_commit_data *data)
1502+
static void nfs_commit_release_pages(struct nfs_commit_data *data)
14991503
{
15001504
struct nfs_page *req;
15011505
int status = data->task.tk_status;
1506+
struct nfs_commit_info cinfo;
15021507

15031508
while (!list_empty(&data->pages)) {
15041509
req = nfs_list_entry(data->pages.next);
@@ -1531,15 +1536,16 @@ void nfs_commit_release_pages(struct nfs_commit_data *data)
15311536
next:
15321537
nfs_unlock_request(req);
15331538
}
1539+
nfs_init_cinfo(&cinfo, data->inode, data->dreq);
1540+
if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
1541+
nfs_commit_clear_lock(NFS_I(data->inode));
15341542
}
1535-
EXPORT_SYMBOL_GPL(nfs_commit_release_pages);
15361543

15371544
static void nfs_commit_release(void *calldata)
15381545
{
15391546
struct nfs_commit_data *data = calldata;
15401547

1541-
nfs_commit_release_pages(data);
1542-
nfs_commit_clear_lock(NFS_I(data->inode));
1548+
data->completion_ops->completion(data);
15431549
nfs_commitdata_release(calldata);
15441550
}
15451551

@@ -1549,6 +1555,11 @@ static const struct rpc_call_ops nfs_commit_ops = {
15491555
.rpc_release = nfs_commit_release,
15501556
};
15511557

1558+
static const struct nfs_commit_completion_ops nfs_commit_completion_ops = {
1559+
.completion = nfs_commit_release_pages,
1560+
.error_cleanup = nfs_commit_clear_lock,
1561+
};
1562+
15521563
static int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
15531564
int how, struct nfs_commit_info *cinfo)
15541565
{

include/linux/nfs_xdr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,18 @@ struct nfs_mds_commit_info {
12631263
struct list_head list;
12641264
};
12651265

1266+
struct nfs_commit_data;
1267+
struct nfs_inode;
1268+
struct nfs_commit_completion_ops {
1269+
void (*error_cleanup) (struct nfs_inode *nfsi);
1270+
void (*completion) (struct nfs_commit_data *data);
1271+
};
1272+
12661273
struct nfs_commit_info {
12671274
spinlock_t *lock;
12681275
struct nfs_mds_commit_info *mds;
12691276
struct pnfs_ds_commit_info *ds;
1277+
const struct nfs_commit_completion_ops *completion_ops;
12701278
};
12711279

12721280
struct nfs_commit_data {
@@ -1285,6 +1293,7 @@ struct nfs_commit_data {
12851293
struct nfs_client *ds_clp; /* pNFS data server */
12861294
int ds_commit_index;
12871295
const struct rpc_call_ops *mds_ops;
1296+
const struct nfs_commit_completion_ops *completion_ops;
12881297
int (*commit_done_cb) (struct rpc_task *task, struct nfs_commit_data *data);
12891298
};
12901299

0 commit comments

Comments
 (0)