History

NFS: Don't zap caches on fallocate()

This patch adds a GETATTR to the end of ALLOCATE and DEALLOCATE operations so we can set the updated inode size and change attribute directly. DEALLOCATE will still need to release pagecache pages, so nfs42_proc_deallocate() now calls truncate_pagecache_range() before contacting the server.

Anna Schumaker committed 11 years ago

Commit 9a519401 parent 8c18d765 files · +39 −10Browse files

Unified · Split

5 files
  1. fs/nfs/inode.c +0 −1
  2. fs/nfs/nfs42proc.c +19 −4
  3. fs/nfs/nfs42xdr.c +16 −4
  4. fs/nfs/nfs4file.c +0 −1
  5. include/linux/nfs_xdr.h +4 −0
fs/nfs/inode.c+0−1
@@ -199,7 +199,6 @@ void nfs_zap_caches(struct inode *inode) · 198 unmodified lines
199199 nfs_zap_caches_locked(inode);
200200 spin_unlock(&inode->i_lock);
201201 }
202−EXPORT_SYMBOL_GPL(nfs_zap_caches);
203202
204203 void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
205204 {
fs/nfs/nfs42proc.c+19−4
@@ -36,13 +36,16 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, · 35 unmodified lines
3636 loff_t offset, loff_t len)
3737 {
3838 struct inode *inode = file_inode(filep);
39+ struct nfs_server *server = NFS_SERVER(inode);
3940 struct nfs42_falloc_args args = {
4041 .falloc_fh = NFS_FH(inode),
4142 .falloc_offset = offset,
4243 .falloc_length = len,
44+ .falloc_bitmask = server->cache_consistency_bitmask,
45+ };
46+ struct nfs42_falloc_res res = {
47+ .falloc_server = server,
4348 };
44− struct nfs42_falloc_res res;
45− struct nfs_server *server = NFS_SERVER(inode);
4649 int status;
4750
4851 msg->rpc_argp = &args;
@@ -52,8 +55,17 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, · 3 unmodified lines
5255 if (status)
5356 return status;
5457
55− return nfs4_call_sync(server->client, server, msg,
56− &args.seq_args, &res.seq_res, 0);
58+ res.falloc_fattr = nfs_alloc_fattr();
59+ if (!res.falloc_fattr)
60+ return -ENOMEM;
61+
62+ status = nfs4_call_sync(server->client, server, msg,
63+ &args.seq_args, &res.seq_res, 0);
64+ if (status == 0)
65+ status = nfs_post_op_update_inode(inode, res.falloc_fattr);
66+
67+ kfree(res.falloc_fattr);
68+ return status;
5769 }
5870
5971 static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
@@ -101,7 +113,10 @@ int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len) · 41 unmodified lines
101113 if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
102114 return -EOPNOTSUPP;
103115
116+ nfs_wb_all(inode);
104117 err = nfs42_proc_fallocate(&msg, filep, offset, len);
118+ if (err == 0)
119+ truncate_pagecache_range(inode, offset, (offset + len) -1);
105120 if (err == -EOPNOTSUPP)
106121 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
107122 return err;
fs/nfs/nfs42xdr.c+16−4
@@ -25,16 +25,20 @@ · 24 unmodified lines
2525
2626 #define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
2727 encode_putfh_maxsz + \
28− encode_allocate_maxsz)
28+ encode_allocate_maxsz + \
29+ encode_getattr_maxsz)
2930 #define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
3031 decode_putfh_maxsz + \
31− decode_allocate_maxsz)
32+ decode_allocate_maxsz + \
33+ decode_getattr_maxsz)
3234 #define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
3335 encode_putfh_maxsz + \
34− encode_deallocate_maxsz)
36+ encode_deallocate_maxsz + \
37+ encode_getattr_maxsz)
3538 #define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
3639 decode_putfh_maxsz + \
37− decode_deallocate_maxsz)
40+ decode_deallocate_maxsz + \
41+ decode_getattr_maxsz)
3842 #define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
3943 encode_putfh_maxsz + \
4044 encode_seek_maxsz)
@@ -92,6 +96,7 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req, · 51 unmodified lines
9296 encode_sequence(xdr, &args->seq_args, &hdr);
9397 encode_putfh(xdr, args->falloc_fh, &hdr);
9498 encode_allocate(xdr, args, &hdr);
99+ encode_getfattr(xdr, args->falloc_bitmask, &hdr);
95100 encode_nops(&hdr);
96101 }
97102
@@ -110,6 +115,7 @@ static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req, · 12 unmodified lines
110115 encode_sequence(xdr, &args->seq_args, &hdr);
111116 encode_putfh(xdr, args->falloc_fh, &hdr);
112117 encode_deallocate(xdr, args, &hdr);
118+ encode_getfattr(xdr, args->falloc_bitmask, &hdr);
113119 encode_nops(&hdr);
114120 }
115121
@@ -183,6 +189,9 @@ static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp, · 67 unmodified lines
183189 if (status)
184190 goto out;
185191 status = decode_allocate(xdr, res);
192+ if (status)
193+ goto out;
194+ decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
186195 out:
187196 return status;
188197 }
@@ -207,6 +216,9 @@ static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp, · 18 unmodified lines
207216 if (status)
208217 goto out;
209218 status = decode_deallocate(xdr, res);
219+ if (status)
220+ goto out;
221+ decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
210222 out:
211223 return status;
212224 }
fs/nfs/nfs4file.c+0−1
@@ -165,7 +165,6 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t · 164 unmodified lines
165165 ret = nfs42_proc_allocate(filep, offset, len);
166166 mutex_unlock(&inode->i_mutex);
167167
168− nfs_zap_caches(inode);
169168 return ret;
170169 }
171170 #endif /* CONFIG_NFS_V4_2 */
include/linux/nfs_xdr.h+4−0
@@ -1273,11 +1273,15 @@ struct nfs42_falloc_args { · 1272 unmodified lines
12731273 nfs4_stateid falloc_stateid;
12741274 u64 falloc_offset;
12751275 u64 falloc_length;
1276+ const u32 *falloc_bitmask;
12761277 };
12771278
12781279 struct nfs42_falloc_res {
12791280 struct nfs4_sequence_res seq_res;
12801281 unsigned int status;
1282+
1283+ struct nfs_fattr *falloc_fattr;
1284+ const struct nfs_server *falloc_server;
12811285 };
12821286
12831287 struct nfs42_seek_args {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t