Skip to content

Commit 5bb89b4

Browse files
committed
NFSv4.1/pnfs: Separate out metadata and data consistency for pNFS
The LAYOUTCOMMIT operation means different things to different layout types. For blocks and objects, it is both a data and metadata consistency operation. For files and flexfiles, it is only a metadata consistency operation. This patch separates out the 2 cases, allowing the files/flexfiles layout drivers to optimise away the data consistency calls to layoutcommit. Signed-off-by: Trond Myklebust <[email protected]>
1 parent 7140171 commit 5bb89b4

File tree

9 files changed

+47
-8
lines changed

9 files changed

+47
-8
lines changed

fs/nfs/blocklayout/blocklayout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = {
890890
.free_deviceid_node = bl_free_deviceid_node,
891891
.pg_read_ops = &bl_pg_read_ops,
892892
.pg_write_ops = &bl_pg_write_ops,
893+
.sync = pnfs_generic_sync,
893894
};
894895

895896
static int __init nfs4blocklayout_init(void)

fs/nfs/filelayout/filelayout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ static struct pnfs_layoutdriver_type filelayout_type = {
11391139
.write_pagelist = filelayout_write_pagelist,
11401140
.alloc_deviceid_node = filelayout_alloc_deviceid_node,
11411141
.free_deviceid_node = filelayout_free_deviceid_node,
1142+
.sync = pnfs_nfs_generic_sync,
11421143
};
11431144

11441145
static int __init nfs4filelayout_init(void)

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
15091509
.write_pagelist = ff_layout_write_pagelist,
15101510
.alloc_deviceid_node = ff_layout_alloc_deviceid_node,
15111511
.encode_layoutreturn = ff_layout_encode_layoutreturn,
1512+
.sync = pnfs_nfs_generic_sync,
15121513
};
15131514

15141515
static int __init nfs4flexfilelayout_init(void)

fs/nfs/nfs4file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
112112
mutex_lock(&inode->i_mutex);
113113
ret = nfs_file_fsync_commit(file, start, end, datasync);
114114
if (!ret)
115-
ret = pnfs_layoutcommit_inode(inode, true);
115+
ret = pnfs_sync_inode(inode, !!datasync);
116116
mutex_unlock(&inode->i_mutex);
117117
/*
118118
* If nfs_file_fsync_commit detected a server reboot, then

fs/nfs/objlayout/objio_osd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ static struct pnfs_layoutdriver_type objlayout_type = {
637637
.pg_read_ops = &objio_pg_read_ops,
638638
.pg_write_ops = &objio_pg_write_ops,
639639

640+
.sync = pnfs_generic_sync,
641+
640642
.free_deviceid_node = objio_free_deviceid_node,
641643

642644
.encode_layoutcommit = objlayout_encode_layoutcommit,

fs/nfs/pnfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,13 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
22312231
}
22322232
EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode);
22332233

2234+
int
2235+
pnfs_generic_sync(struct inode *inode, bool datasync)
2236+
{
2237+
return pnfs_layoutcommit_inode(inode, true);
2238+
}
2239+
EXPORT_SYMBOL_GPL(pnfs_generic_sync);
2240+
22342241
struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
22352242
{
22362243
struct nfs4_threshold *thp;

fs/nfs/pnfs.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ struct pnfs_layoutdriver_type {
155155
int how,
156156
struct nfs_commit_info *cinfo);
157157

158+
int (*sync)(struct inode *inode, bool datasync);
159+
158160
/*
159161
* Return PNFS_ATTEMPTED to indicate the layout code has attempted
160162
* I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS
@@ -267,6 +269,8 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task);
267269
void pnfs_set_layoutcommit(struct inode *, struct pnfs_layout_segment *, loff_t);
268270
void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data);
269271
int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
272+
int pnfs_generic_sync(struct inode *inode, bool datasync);
273+
int pnfs_nfs_generic_sync(struct inode *inode, bool datasync);
270274
int _pnfs_return_layout(struct inode *);
271275
int pnfs_commit_and_return_layout(struct inode *);
272276
void pnfs_ld_write_done(struct nfs_pgio_header *);
@@ -488,6 +492,14 @@ pnfs_ld_read_whole_page(struct inode *inode)
488492
return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE;
489493
}
490494

495+
static inline int
496+
pnfs_sync_inode(struct inode *inode, bool datasync)
497+
{
498+
if (!pnfs_enabled_sb(NFS_SERVER(inode)))
499+
return 0;
500+
return NFS_SERVER(inode)->pnfs_curr_ld->sync(inode, datasync);
501+
}
502+
491503
static inline bool
492504
pnfs_layoutcommit_outstanding(struct inode *inode)
493505
{
@@ -570,6 +582,12 @@ pnfs_ld_read_whole_page(struct inode *inode)
570582
return false;
571583
}
572584

585+
static inline int
586+
pnfs_sync_inode(struct inode *inode, bool datasync)
587+
{
588+
return 0;
589+
}
590+
573591
static inline bool
574592
pnfs_roc(struct inode *ino)
575593
{

fs/nfs/pnfs_nfs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,13 @@ pnfs_layout_mark_request_commit(struct nfs_page *req,
868868
nfs_request_add_commit_list(req, list, cinfo);
869869
}
870870
EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit);
871+
872+
int
873+
pnfs_nfs_generic_sync(struct inode *inode, bool datasync)
874+
{
875+
if (datasync)
876+
return 0;
877+
return pnfs_layoutcommit_inode(inode, true);
878+
}
879+
EXPORT_SYMBOL_GPL(pnfs_nfs_generic_sync);
880+

fs/nfs/write.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,17 +1840,16 @@ EXPORT_SYMBOL_GPL(nfs_write_inode);
18401840
*/
18411841
int nfs_wb_all(struct inode *inode)
18421842
{
1843-
struct writeback_control wbc = {
1844-
.sync_mode = WB_SYNC_ALL,
1845-
.nr_to_write = LONG_MAX,
1846-
.range_start = 0,
1847-
.range_end = LLONG_MAX,
1848-
};
18491843
int ret;
18501844

18511845
trace_nfs_writeback_inode_enter(inode);
18521846

1853-
ret = sync_inode(inode, &wbc);
1847+
ret = filemap_write_and_wait(inode->i_mapping);
1848+
if (!ret) {
1849+
ret = nfs_commit_inode(inode, FLUSH_SYNC);
1850+
if (!ret)
1851+
pnfs_sync_inode(inode, true);
1852+
}
18541853

18551854
trace_nfs_writeback_inode_exit(inode, ret);
18561855
return ret;

0 commit comments

Comments
 (0)