aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorAnna Schumaker <Anna.Schumaker@netapp.com>2014-11-25 13:18:16 -0500
committerTrond Myklebust <trond.myklebust@primarydata.com>2014-11-25 16:38:32 -0500
commit624bd5b7b683c978c6d5f4e9f6142cfb3470983d (patch)
treedcbe9728ea9a6ef12b57c63aec6b34b872a42542 /fs/nfs
parentf4ac1674f5da420ef17896f0f222c5215ebcde80 (diff)
nfs: Add DEALLOCATE support
This patch adds support for using the NFS v4.2 operation DEALLOCATE to punch holes in a file. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/nfs42.h1
-rw-r--r--fs/nfs/nfs42proc.c17
-rw-r--r--fs/nfs/nfs42xdr.c64
-rw-r--r--fs/nfs/nfs4file.c7
-rw-r--r--fs/nfs/nfs4proc.c1
-rw-r--r--fs/nfs/nfs4xdr.c1
6 files changed, 89 insertions, 2 deletions
diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h
index 42656a9cf485..7afb8947dfdf 100644
--- a/fs/nfs/nfs42.h
+++ b/fs/nfs/nfs42.h
@@ -7,6 +7,7 @@
7 7
8/* nfs4.2proc.c */ 8/* nfs4.2proc.c */
9int nfs42_proc_allocate(struct file *, loff_t, loff_t); 9int nfs42_proc_allocate(struct file *, loff_t, loff_t);
10int nfs42_proc_deallocate(struct file *, loff_t, loff_t);
10loff_t nfs42_proc_llseek(struct file *, loff_t, int); 11loff_t nfs42_proc_llseek(struct file *, loff_t, int);
11 12
12/* nfs4.2xdr.h */ 13/* nfs4.2xdr.h */
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index 581f34e9d8a0..cb170722769c 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -90,6 +90,23 @@ int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
90 return err; 90 return err;
91} 91}
92 92
93int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
94{
95 struct rpc_message msg = {
96 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE],
97 };
98 struct inode *inode = file_inode(filep);
99 int err;
100
101 if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
102 return -EOPNOTSUPP;
103
104 err = nfs42_proc_fallocate(&msg, filep, offset, len);
105 if (err == -EOPNOTSUPP)
106 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
107 return err;
108}
109
93loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence) 110loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
94{ 111{
95 struct inode *inode = file_inode(filep); 112 struct inode *inode = file_inode(filep);
diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
index 4248d034479c..038a7e1521fa 100644
--- a/fs/nfs/nfs42xdr.c
+++ b/fs/nfs/nfs42xdr.c
@@ -10,6 +10,9 @@
10#define encode_allocate_maxsz (op_encode_hdr_maxsz + \ 10#define encode_allocate_maxsz (op_encode_hdr_maxsz + \
11 encode_fallocate_maxsz) 11 encode_fallocate_maxsz)
12#define decode_allocate_maxsz (op_decode_hdr_maxsz) 12#define decode_allocate_maxsz (op_decode_hdr_maxsz)
13#define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
14 encode_fallocate_maxsz)
15#define decode_deallocate_maxsz (op_decode_hdr_maxsz)
13#define encode_seek_maxsz (op_encode_hdr_maxsz + \ 16#define encode_seek_maxsz (op_encode_hdr_maxsz + \
14 encode_stateid_maxsz + \ 17 encode_stateid_maxsz + \
15 2 /* offset */ + \ 18 2 /* offset */ + \
@@ -26,6 +29,12 @@
26#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \ 29#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
27 decode_putfh_maxsz + \ 30 decode_putfh_maxsz + \
28 decode_allocate_maxsz) 31 decode_allocate_maxsz)
32#define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
33 encode_putfh_maxsz + \
34 encode_deallocate_maxsz)
35#define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
36 decode_putfh_maxsz + \
37 decode_deallocate_maxsz)
29#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \ 38#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
30 encode_putfh_maxsz + \ 39 encode_putfh_maxsz + \
31 encode_seek_maxsz) 40 encode_seek_maxsz)
@@ -50,6 +59,14 @@ static void encode_allocate(struct xdr_stream *xdr,
50 encode_fallocate(xdr, args); 59 encode_fallocate(xdr, args);
51} 60}
52 61
62static void encode_deallocate(struct xdr_stream *xdr,
63 struct nfs42_falloc_args *args,
64 struct compound_hdr *hdr)
65{
66 encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
67 encode_fallocate(xdr, args);
68}
69
53static void encode_seek(struct xdr_stream *xdr, 70static void encode_seek(struct xdr_stream *xdr,
54 struct nfs42_seek_args *args, 71 struct nfs42_seek_args *args,
55 struct compound_hdr *hdr) 72 struct compound_hdr *hdr)
@@ -79,6 +96,24 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
79} 96}
80 97
81/* 98/*
99 * Encode DEALLOCATE request
100 */
101static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
102 struct xdr_stream *xdr,
103 struct nfs42_falloc_args *args)
104{
105 struct compound_hdr hdr = {
106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
107 };
108
109 encode_compound_hdr(xdr, req, &hdr);
110 encode_sequence(xdr, &args->seq_args, &hdr);
111 encode_putfh(xdr, args->falloc_fh, &hdr);
112 encode_deallocate(xdr, args, &hdr);
113 encode_nops(&hdr);
114}
115
116/*
82 * Encode SEEK request 117 * Encode SEEK request
83 */ 118 */
84static void nfs4_xdr_enc_seek(struct rpc_rqst *req, 119static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
@@ -101,6 +136,11 @@ static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
101 return decode_op_hdr(xdr, OP_ALLOCATE); 136 return decode_op_hdr(xdr, OP_ALLOCATE);
102} 137}
103 138
139static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
140{
141 return decode_op_hdr(xdr, OP_DEALLOCATE);
142}
143
104static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) 144static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
105{ 145{
106 int status; 146 int status;
@@ -148,6 +188,30 @@ out:
148} 188}
149 189
150/* 190/*
191 * Decode DEALLOCATE request
192 */
193static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
194 struct xdr_stream *xdr,
195 struct nfs42_falloc_res *res)
196{
197 struct compound_hdr hdr;
198 int status;
199
200 status = decode_compound_hdr(xdr, &hdr);
201 if (status)
202 goto out;
203 status = decode_sequence(xdr, &res->seq_res, rqstp);
204 if (status)
205 goto out;
206 status = decode_putfh(xdr);
207 if (status)
208 goto out;
209 status = decode_deallocate(xdr, res);
210out:
211 return status;
212}
213
214/*
151 * Decode SEEK request 215 * Decode SEEK request
152 */ 216 */
153static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, 217static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index f78e9fd0735a..8b46389c4c5b 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -145,7 +145,7 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
145 if (!S_ISREG(inode->i_mode)) 145 if (!S_ISREG(inode->i_mode))
146 return -EOPNOTSUPP; 146 return -EOPNOTSUPP;
147 147
148 if (mode != 0) 148 if ((mode != 0) && (mode != (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE)))
149 return -EOPNOTSUPP; 149 return -EOPNOTSUPP;
150 150
151 ret = inode_newsize_ok(inode, offset + len); 151 ret = inode_newsize_ok(inode, offset + len);
@@ -153,7 +153,10 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
153 return ret; 153 return ret;
154 154
155 mutex_lock(&inode->i_mutex); 155 mutex_lock(&inode->i_mutex);
156 ret = nfs42_proc_allocate(filep, offset, len); 156 if (mode & FALLOC_FL_PUNCH_HOLE)
157 ret = nfs42_proc_deallocate(filep, offset, len);
158 else
159 ret = nfs42_proc_allocate(filep, offset, len);
157 mutex_unlock(&inode->i_mutex); 160 mutex_unlock(&inode->i_mutex);
158 161
159 nfs_zap_caches(inode); 162 nfs_zap_caches(inode);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index b1b403b0ca0d..e7f8d5ff2581 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -8425,6 +8425,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
8425 | NFS_CAP_STATEID_NFSV41 8425 | NFS_CAP_STATEID_NFSV41
8426 | NFS_CAP_ATOMIC_OPEN_V1 8426 | NFS_CAP_ATOMIC_OPEN_V1
8427 | NFS_CAP_ALLOCATE 8427 | NFS_CAP_ALLOCATE
8428 | NFS_CAP_DEALLOCATE
8428 | NFS_CAP_SEEK, 8429 | NFS_CAP_SEEK,
8429 .init_client = nfs41_init_client, 8430 .init_client = nfs41_init_client,
8430 .shutdown_client = nfs41_shutdown_client, 8431 .shutdown_client = nfs41_shutdown_client,
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 0a1484561e4b..03d0fa62a06e 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -7395,6 +7395,7 @@ struct rpc_procinfo nfs4_procedures[] = {
7395#ifdef CONFIG_NFS_V4_2 7395#ifdef CONFIG_NFS_V4_2
7396 PROC(SEEK, enc_seek, dec_seek), 7396 PROC(SEEK, enc_seek, dec_seek),
7397 PROC(ALLOCATE, enc_allocate, dec_allocate), 7397 PROC(ALLOCATE, enc_allocate, dec_allocate),
7398 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
7398#endif /* CONFIG_NFS_V4_2 */ 7399#endif /* CONFIG_NFS_V4_2 */
7399}; 7400};
7400 7401