Skip to content

Commit 338d00c

Browse files
Tom Haynestrondmypd
authored andcommitted
pnfs: Refactor the *_layout_mark_request_commit to use pnfs_layout_mark_request_commit
The File Layout's filelayout_mark_request_commit() is almost the Flex File Layout's ff_layout_mark_request_commit(). And that can be reduced by calling into nfs_request_add_commit_list(). Signed-off-by: Tom Haynes <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 487b9b8 commit 338d00c

File tree

4 files changed

+45
-75
lines changed

4 files changed

+45
-75
lines changed

fs/nfs/filelayout/filelayout.c

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -960,48 +960,20 @@ filelayout_mark_request_commit(struct nfs_page *req,
960960
{
961961
struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
962962
u32 i, j;
963-
struct list_head *list;
964-
struct pnfs_commit_bucket *buckets;
965963

966964
if (fl->commit_through_mds) {
967-
list = &cinfo->mds->list;
968-
spin_lock(cinfo->lock);
969-
goto mds_commit;
970-
}
971-
972-
/* Note that we are calling nfs4_fl_calc_j_index on each page
973-
* that ends up being committed to a data server. An attractive
974-
* alternative is to add a field to nfs_write_data and nfs_page
975-
* to store the value calculated in filelayout_write_pagelist
976-
* and just use that here.
977-
*/
978-
j = nfs4_fl_calc_j_index(lseg, req_offset(req));
979-
i = select_bucket_index(fl, j);
980-
spin_lock(cinfo->lock);
981-
buckets = cinfo->ds->buckets;
982-
list = &buckets[i].written;
983-
if (list_empty(list)) {
984-
/* Non-empty buckets hold a reference on the lseg. That ref
985-
* is normally transferred to the COMMIT call and released
986-
* there. It could also be released if the last req is pulled
987-
* off due to a rewrite, in which case it will be done in
988-
* pnfs_generic_clear_request_commit
965+
nfs_request_add_commit_list(req, &cinfo->mds->list, cinfo);
966+
} else {
967+
/* Note that we are calling nfs4_fl_calc_j_index on each page
968+
* that ends up being committed to a data server. An attractive
969+
* alternative is to add a field to nfs_write_data and nfs_page
970+
* to store the value calculated in filelayout_write_pagelist
971+
* and just use that here.
989972
*/
990-
buckets[i].wlseg = pnfs_get_lseg(lseg);
973+
j = nfs4_fl_calc_j_index(lseg, req_offset(req));
974+
i = select_bucket_index(fl, j);
975+
pnfs_layout_mark_request_commit(req, lseg, cinfo, i);
991976
}
992-
set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
993-
cinfo->ds->nwritten++;
994-
995-
mds_commit:
996-
/* nfs_request_add_commit_list(). We need to add req to list without
997-
* dropping cinfo lock.
998-
*/
999-
set_bit(PG_CLEAN, &(req)->wb_flags);
1000-
nfs_list_add_request(req, list);
1001-
cinfo->mds->ncommit++;
1002-
spin_unlock(cinfo->lock);
1003-
if (!cinfo->dreq)
1004-
nfs_mark_page_unstable(req->wb_page);
1005977
}
1006978

1007979
static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,42 +1332,6 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
13321332
return PNFS_ATTEMPTED;
13331333
}
13341334

1335-
static void
1336-
ff_layout_mark_request_commit(struct nfs_page *req,
1337-
struct pnfs_layout_segment *lseg,
1338-
struct nfs_commit_info *cinfo,
1339-
u32 ds_commit_idx)
1340-
{
1341-
struct list_head *list;
1342-
struct pnfs_commit_bucket *buckets;
1343-
1344-
spin_lock(cinfo->lock);
1345-
buckets = cinfo->ds->buckets;
1346-
list = &buckets[ds_commit_idx].written;
1347-
if (list_empty(list)) {
1348-
/* Non-empty buckets hold a reference on the lseg. That ref
1349-
* is normally transferred to the COMMIT call and released
1350-
* there. It could also be released if the last req is pulled
1351-
* off due to a rewrite, in which case it will be done in
1352-
* pnfs_common_clear_request_commit
1353-
*/
1354-
WARN_ON_ONCE(buckets[ds_commit_idx].wlseg != NULL);
1355-
buckets[ds_commit_idx].wlseg = pnfs_get_lseg(lseg);
1356-
}
1357-
set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
1358-
cinfo->ds->nwritten++;
1359-
1360-
/* nfs_request_add_commit_list(). We need to add req to list without
1361-
* dropping cinfo lock.
1362-
*/
1363-
set_bit(PG_CLEAN, &(req)->wb_flags);
1364-
nfs_list_add_request(req, list);
1365-
cinfo->mds->ncommit++;
1366-
spin_unlock(cinfo->lock);
1367-
if (!cinfo->dreq)
1368-
nfs_mark_page_unstable(req->wb_page);
1369-
}
1370-
13711335
static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
13721336
{
13731337
return i;
@@ -1535,7 +1499,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
15351499
.pg_write_ops = &ff_layout_pg_write_ops,
15361500
.get_ds_info = ff_layout_get_ds_info,
15371501
.free_deviceid_node = ff_layout_free_deveiceid_node,
1538-
.mark_request_commit = ff_layout_mark_request_commit,
1502+
.mark_request_commit = pnfs_layout_mark_request_commit,
15391503
.clear_request_commit = pnfs_generic_clear_request_commit,
15401504
.scan_commit_lists = pnfs_generic_scan_commit_lists,
15411505
.recover_commit_reqs = pnfs_generic_recover_commit_reqs,

fs/nfs/pnfs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ void nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
344344
struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net,
345345
struct xdr_stream *xdr,
346346
gfp_t gfp_flags);
347+
void pnfs_layout_mark_request_commit(struct nfs_page *req,
348+
struct pnfs_layout_segment *lseg,
349+
struct nfs_commit_info *cinfo,
350+
u32 ds_commit_idx);
347351

348352
static inline bool nfs_have_layout(struct inode *inode)
349353
{

fs/nfs/pnfs_nfs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,33 @@ nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags)
838838
return NULL;
839839
}
840840
EXPORT_SYMBOL_GPL(nfs4_decode_mp_ds_addr);
841+
842+
void
843+
pnfs_layout_mark_request_commit(struct nfs_page *req,
844+
struct pnfs_layout_segment *lseg,
845+
struct nfs_commit_info *cinfo,
846+
u32 ds_commit_idx)
847+
{
848+
struct list_head *list;
849+
struct pnfs_commit_bucket *buckets;
850+
851+
spin_lock(cinfo->lock);
852+
buckets = cinfo->ds->buckets;
853+
list = &buckets[ds_commit_idx].written;
854+
if (list_empty(list)) {
855+
/* Non-empty buckets hold a reference on the lseg. That ref
856+
* is normally transferred to the COMMIT call and released
857+
* there. It could also be released if the last req is pulled
858+
* off due to a rewrite, in which case it will be done in
859+
* pnfs_common_clear_request_commit
860+
*/
861+
WARN_ON_ONCE(buckets[ds_commit_idx].wlseg != NULL);
862+
buckets[ds_commit_idx].wlseg = pnfs_get_lseg(lseg);
863+
}
864+
set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
865+
cinfo->ds->nwritten++;
866+
spin_unlock(cinfo->lock);
867+
868+
nfs_request_add_commit_list(req, list, cinfo);
869+
}
870+
EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit);

0 commit comments

Comments
 (0)