NFS: Add ALLOCATE and DEALLOCATE support
Subsystems (2)
cover NFS: Add ALLOCATE and DEALLOCATE support
These patches add client support for the ALLOCATE and DEALLOCATE operations part of NFS v4.2.
These operations are triggered by a vfs_fallocate() call, and we determine which to use based on if the FALLOC_FL_PUNCH_HOLE flag is set.
Anna Schumaker (2):
nfs: Add ALLOCATE support
nfs: Add DEALLOCATE support
fs/nfs/nfs42proc.c | 74 +++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 3 + fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 47 ++++++++++++++++ fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 + include/linux/nfs4.h | 2 + include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 28 ++++++++++ 10 files changed, 296 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 nfs: Add ALLOCATE support
This patch adds support for using the NFS v4.2 operation ALLOCATE to preallocate data in a file.
--- fs/nfs/nfs42proc.c | 37 ++++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 34 ++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 1 + include/linux/nfs4.h | 1 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 14 ++++++++++ 10 files changed, 160 insertions(+), 2 deletions(-)
fs/nfs/nfs42proc.c +37 -0
@@ -12,6 +12,43 @@#include "nfs42.h" +int _nfs42_proc_allocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs42_allocate_args args = { + .alloc_fh =NFS_FH (inode), + .alloc_stateid = stateid, + .alloc_offset = offset, + .alloc_length = len, + }; +struct nfs42_allocate_res res; +struct rpc_message msg = { + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE ], + .rpc_argp = &args, + .rpc_resp = &res, + }; +struct nfs_server *server =NFS_SERVER (inode); + +return nfs4_call_sync (server->client, server, &msg, + &args.seq_args, &res.seq_res,0 ); +} + +int nfs42_proc_allocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs4_exception exception = { }; +int err; + +do { + err =_nfs42_proc_allocate (inode, stateid, offset, len); +if (err == -ENOTSUPP ) +return -EOPNOTSUPP ; + err =nfs4_handle_exception (NFS_SERVER (inode), err, &exception); + }while (exception.retry); + +return err; +} +loff_t nfs42_proc_llseek (struct inode *inode,nfs4_stateid *stateid,loff_t offset,int whence) {
fs/nfs/nfs42xdr.h +68 -0
104 lines not on this page · raw message
fs/nfs/nfs4_fs.h +2 -0
@@ -227,6 +227,7 @@ int nfs4_replace_transport(struct nfs_server *server, const struct nfs4_fs_locations *locations);/* nfs4proc.c */ +extern int nfs4_handle_exception (struct nfs_server *,int ,struct nfs4_exception *);extern int nfs4_call_sync (struct rpc_clnt *,struct nfs_server *,struct rpc_message *,struct nfs4_sequence_args *,struct nfs4_sequence_res *,int );
@@ -368,6 +369,7 @@ nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,#endif /* CONFIG_NFS_V4_1 */ #ifdef CONFIG_NFS_V4_2 +int nfs42_proc_allocate (struct inode *,nfs4_stateid *,loff_t ,loff_t );loff_t nfs42_proc_llseek (struct inode *,nfs4_stateid *,loff_t ,int );#endif /* CONFIG_NFS_V4_2 */
fs/nfs/nfs4client.c +1 -1
@@ -932,7 +932,7 @@ static int nfs4_server_common_setup(struct nfs_server *server, server->caps |=NFS_CAP_UIDGID_NOMAP ;if (server->nfs_client->cl_minorversion >=2 ) - server->caps |=NFS_CAP_SEEK ; + server->caps |=NFS_CAP_ALLOCATE |NFS_CAP_SEEK ;/* Probe the root fh to retrieve its FSID and filehandle */ error =nfs4_get_rootfh (server, mntfh, auth_probe);
fs/nfs/nfs4file.c +34 -0
@@ -3,6 +3,8 @@* * Copyright (C) 1992 Rick Sladkey */ +#include <linux/fs.h> +#include <linux/falloc.h> #include <linux/nfs_fs.h> #include "internal.h" #include "fscache.h"
@@ -177,6 +179,35 @@ static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence) return nfs_file_llseek(filep, offset, whence); } } + +static long nfs42_allocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs_server *server =NFS_SERVER (inode); +long ret = -EOPNOTSUPP ; + +if (server->caps &NFS_CAP_ALLOCATE ) { + ret =nfs42_proc_allocate (inode, stateid, offset, len); +if (ret == -EOPNOTSUPP ) + server->caps &= ~NFS_CAP_ALLOCATE ; + } +return ret; +} + +static long nfs42_fallocate (struct file *file,int mode,loff_t offset,loff_t len) +{ +nfs4_stateid stateid; +int err; + +if (mode &FALLOC_FL_PUNCH_HOLE ) +return -EOPNOTSUPP ; + + err =nfs42_select_stateid (file, &stateid,FMODE_WRITE ); +if (err <0 ) +return err; + +return nfs42_allocate (file_inode (file), &stateid, offset, len); +}#endif /* CONFIG_NFS_V4_2 */ const struct file_operations nfs4_file_operations = {
@@ -198,6 +229,9 @@ const struct file_operations nfs4_file_operations = { .flock = nfs_flock, .splice_read = nfs_file_splice_read, .splice_write = iter_file_splice_write, +#ifdef CONFIG_NFS_V4_2 + .fallocate = nfs42_fallocate, +#endif /* CONFIG_NFS_V4_2 */ .check_flags = nfs_check_flags, .setlease = nfs_setlease, };
fs/nfs/nfs4proc.c +1 -1
@@ -334,7 +334,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)/* This is the error handling routine for processes that are allowed * to sleep. */ -static int nfs4_handle_exception (struct nfs_server *server,int errorcode,struct nfs4_exception *exception) +int nfs4_handle_exception (struct nfs_server *server,int errorcode,struct nfs4_exception *exception) {struct nfs_client *clp = server->nfs_client;struct nfs4_state *state = exception->state;
fs/nfs/nfs4xdr.c +1 -0
@@ -7501,6 +7501,7 @@ struct rpc_procinfo nfs4_procedures[] = {#endif /* CONFIG_NFS_V4_1 */ #if defined(CONFIG_NFS_V4_2 ) PROC(SEEK, enc_seek, dec_seek), + PROC(ALLOCATE, enc_allocate, dec_allocate),#endif /* CONFIG_NFS_V4_2 */ };
include/linux/nfs4.h +1 -0
@@ -490,6 +490,7 @@ enum {/* nfs42 */ NFSPROC4_CLNT_SEEK , + NFSPROC4_CLNT_ALLOCATE, };/* nfs41 types */
include/linux/nfs_fs_sb.h +1 -0
@@ -231,5 +231,6 @@ struct nfs_server {#define NFS_CAP_ATOMIC_OPEN_V1 (1U << 17)#define NFS_CAP_SECURITY_LABEL (1U << 18)#define NFS_CAP_SEEK (1U << 19) +#define NFS_CAP_ALLOCATE (1U << 20)#endif
include/linux/nfs_xdr.h +14 -0
@@ -1240,6 +1240,20 @@ struct pnfs_ds_commit_info {#endif /* CONFIG_NFS_V4_1 */ #ifdef CONFIG_NFS_V4_2 +struct nfs42_allocate_args { + struct nfs4_sequence_args seq_args; + + struct nfs_fh *alloc_fh; + nfs4_stateid *alloc_stateid; + u64 alloc_offset; + u64 alloc_length; +}; + +struct nfs42_allocate_res { + struct nfs4_sequence_res seq_res; + unsigned int status; +}; + struct nfs42_seek_args { struct nfs4_sequence_args seq_args;
Signature · 1 line
2.1.0
Re: [PATCH 1/2] nfs: Add ALLOCATE support
fs/nfs/nfs4file.c static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence) · line 193
Quoted 8 lines · Anna Schumaker
fs/nfs/nfs4file.c +8
-0+struct nfs_server *server =NFS_SERVER (inode); +long ret = -EOPNOTSUPP ; + +if (server->caps &NFS_CAP_ALLOCATE ) { + ret =nfs42_proc_allocate (inode, stateid, offset, len); +if (ret == -EOPNOTSUPP ) + server->caps &= ~NFS_CAP_ALLOCATE ; + }
So if we want clients to allow this sort of optimization we can't return NFSERR_PNOTSUPP if it's called on the "wrong" kind of file. Back to the drawing board on that one.
PATCH 2/2 nfs: Add DEALLOCATE support
In reply to Anna SchumakerThis patch adds support for using the NFS v4.2 operation DEALLOCATE to punch holes in a file.
--- fs/nfs/nfs42proc.c | 37 ++++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 19 ++++++++++--- fs/nfs/nfs4xdr.c | 1 + include/linux/nfs4.h | 1 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 14 ++++++++++ 9 files changed, 140 insertions(+), 4 deletions(-)
fs/nfs/nfs42proc.c +37 -0
@@ -49,6 +49,43 @@ int nfs42_proc_allocate(struct inode *inode, nfs4_stateid *stateid,return err; } +int _nfs42_proc_deallocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs42_deallocate_args args = { + .dealloc_fh =NFS_FH (inode), + .dealloc_stateid = stateid, + .dealloc_offset = offset, + .dealloc_length = len, + }; +struct nfs42_deallocate_res res; +struct rpc_message msg = { + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE ], + .rpc_argp = &args, + .rpc_resp = &res, + }; +struct nfs_server *server =NFS_SERVER (inode); + +return nfs4_call_sync (server->client, server, &msg, + &args.seq_args, &res.seq_res,0 ); +} + +int nfs42_proc_deallocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs4_exception exception = { }; +int err; + +do { + err =_nfs42_proc_deallocate (inode, stateid, offset, len); +if (err == -ENOTSUPP ) +return -EOPNOTSUPP ; + err =nfs4_handle_exception (NFS_SERVER (inode), err, &exception); + }while (exception.retry); + +return err; +} +loff_t nfs42_proc_llseek (struct inode *inode,nfs4_stateid *stateid,loff_t offset,int whence) {
fs/nfs/nfs42xdr.h +68 -0
104 lines not on this page · raw message
fs/nfs/nfs4_fs.h +1 -0
@@ -370,6 +370,7 @@ nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,#ifdef CONFIG_NFS_V4_2 int nfs42_proc_allocate (struct inode *,nfs4_stateid *,loff_t ,loff_t ); +int nfs42_proc_deallocate (struct inode *,nfs4_stateid *,loff_t ,loff_t );loff_t nfs42_proc_llseek (struct inode *,nfs4_stateid *,loff_t ,int );#endif /* CONFIG_NFS_V4_2 */
fs/nfs/nfs4client.c +1 -1
@@ -932,7 +932,7 @@ static int nfs4_server_common_setup(struct nfs_server *server, server->caps |=NFS_CAP_UIDGID_NOMAP ;if (server->nfs_client->cl_minorversion >=2 ) - server->caps |=NFS_CAP_ALLOCATE |NFS_CAP_SEEK ; + server->caps |=NFS_CAP_ALLOCATE |NFS_CAP_DEALLOCATE |NFS_CAP_SEEK ;/* Probe the root fh to retrieve its FSID and filehandle */ error =nfs4_get_rootfh (server, mntfh, auth_probe);
fs/nfs/nfs4file.c +16 -3
@@ -194,18 +194,31 @@ static long nfs42_allocate(struct inode *inode, nfs4_stateid *stateid,return ret; } +static long nfs42_deallocate (struct inode *inode,nfs4_stateid *stateid, +loff_t offset,loff_t len) +{ +struct nfs_server *server =NFS_SERVER (inode); +long ret = -EOPNOTSUPP ; + +if (server->caps &NFS_CAP_DEALLOCATE ) { + ret =nfs42_proc_deallocate (inode, stateid, offset, len); +if (ret == -EOPNOTSUPP ) + server->caps &= ~NFS_CAP_DEALLOCATE ; + } +return ret; +} +static long nfs42_fallocate (struct file *file,int mode,loff_t offset,loff_t len) {nfs4_stateid stateid;int err; -if (mode &FALLOC_FL_PUNCH_HOLE ) -return -EOPNOTSUPP ; - err =nfs42_select_stateid (file, &stateid,FMODE_WRITE );if (err <0 )return err; +if (mode &FALLOC_FL_PUNCH_HOLE ) +return nfs42_deallocate (file_inode (file), &stateid, offset, len);return nfs42_allocate (file_inode (file), &stateid, offset, len); }#endif /* CONFIG_NFS_V4_2 */
fs/nfs/nfs4xdr.c +1 -0
@@ -7502,6 +7502,7 @@ struct rpc_procinfo nfs4_procedures[] = {#if defined(CONFIG_NFS_V4_2 )PROC (SEEK , enc_seek, dec_seek),PROC (ALLOCATE , enc_allocate, dec_allocate), + PROC(DEALLOCATE, enc_deallocate, dec_deallocate), #endif /* CONFIG_NFS_V4_2 */ };
include/linux/nfs4.h +1 -0
@@ -491,6 +491,7 @@ enum {/* nfs42 */ NFSPROC4_CLNT_SEEK ,NFSPROC4_CLNT_ALLOCATE , + NFSPROC4_CLNT_DEALLOCATE, };/* nfs41 types */
include/linux/nfs_fs_sb.h +1 -0
@@ -232,5 +232,6 @@ struct nfs_server {#define NFS_CAP_SECURITY_LABEL (1U << 18)#define NFS_CAP_SEEK (1U << 19)#define NFS_CAP_ALLOCATE (1U << 20) +#define NFS_CAP_DEALLOCATE (1U << 21)#endif
include/linux/nfs_xdr.h +14 -0
@@ -1254,6 +1254,20 @@ struct nfs42_allocate_res {unsigned int status; }; +struct nfs42_deallocate_args { +struct nfs4_sequence_args seq_args; + +struct nfs_fh *dealloc_fh; +nfs4_stateid *dealloc_stateid; +u64 dealloc_offset; +u64 dealloc_length; +}; + +struct nfs42_deallocate_res { +struct nfs4_sequence_res seq_res; +unsigned int status; +}; +struct nfs42_seek_args {struct nfs4_sequence_args seq_args;
Signature · 1 line
2.1.0
Hi Anna,
Did you get a chance to set up a git tree with all your changes, at least for the client side, maybe Trond will include it in his tree?
Thanks, Marc.
From: Anna Schumaker <[email protected]> To: <[email protected]>, <[email protected]>, Date: 09/09/2014 07:50 AM Subject: [PATCH 0/2] NFS: Add ALLOCATE and DEALLOCATE support Sent by: [email protected]
These patches add client support for the ALLOCATE and DEALLOCATE operations
part of NFS v4.2.
These operations are triggered by a vfs_fallocate() call, and we determine which to use based on if the FALLOC_FL_PUNCH_HOLE flag is set.
Anna Schumaker (2):
nfs: Add ALLOCATE support
nfs: Add DEALLOCATE support
fs/nfs/nfs42proc.c | 74 +++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 3 + fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 47 ++++++++++++++++ fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 + include/linux/nfs4.h | 2 + include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 28 ++++++++++ 10 files changed, 296 insertions(+), 2 deletions(-)
Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Marc Eshel
Hi Anna,
Did you get a chance to set up a git tree with all your changes, at least for the client side, maybe Trond will include it in his tree?
I did for SEEK. I haven't updated it to include these patches yet, but I will after making the changes that Trond and Christoph are asking for.
git://git.linux-nfs.org/projects/anna/linux-nfs.git (see the "seek" branch)
Anna
Quoted 36 lines
Thanks, Marc.
From: Anna Schumaker <[email protected]> To: <[email protected]>, <[email protected]>, Date: 09/09/2014 07:50 AM Subject: [PATCH 0/2] NFS: Add ALLOCATE and DEALLOCATE support Sent by: [email protected]These patches add client support for the ALLOCATE and DEALLOCATE operations
part of NFS v4.2.These operations are triggered by a
vfs_fallocate()call, and we determine which to use based on if theFALLOC_FL_PUNCH_HOLEflag is set.Anna Schumaker (2):
nfs: Add ALLOCATE support
nfs: Add DEALLOCATE supportfs/nfs/nfs42proc.c | 74 +++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 3 + fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 47 ++++++++++++++++ fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 + include/linux/nfs4.h | 2 + include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 28 ++++++++++ 10 files changed, 296 insertions(+), 2 deletions(-)
Quoted 4 lines · Marc Eshel
Hi Anna,
Did you get a chance to set up a git tree with all your changes, at least for the client side, maybe Trond will include it in his tree?
I did for SEEK. I haven't updated it to include these patches yet, but I will after making the changes that Trond and Christoph are asking for.
git://git.linux-nfs.org/projects/anna/linux-nfs.git (see the "seek" branch)
Anna
Quoted 36 lines
Thanks, Marc.
From: Anna Schumaker <[email protected]> To: <[email protected]>, <[email protected]>, Date: 09/09/2014 07:50 AM Subject: [PATCH 0/2] NFS: Add ALLOCATE and DEALLOCATE support Sent by: [email protected]These patches add client support for the ALLOCATE and DEALLOCATE operations
part of NFS v4.2.These operations are triggered by a
vfs_fallocate()call, and we determine which to use based on if theFALLOC_FL_PUNCH_HOLEflag is set.Anna Schumaker (2):
nfs: Add ALLOCATE support
nfs: Add DEALLOCATE supportfs/nfs/nfs42proc.c | 74 +++++++++++++++++++++++++ fs/nfs/nfs42xdr.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4_fs.h | 3 + fs/nfs/nfs4client.c | 2 +- fs/nfs/nfs4file.c | 47 ++++++++++++++++ fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 + include/linux/nfs4.h | 2 + include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 28 ++++++++++ 10 files changed, 296 insertions(+), 2 deletions(-)
Oh, another thing I missed first time around: We really need to take i_mutex to protect against concurrent writes on the client.