Skip to content

Commit 637d020

Browse files
Abhishek KulkarniEric Van Hensbergen
authored andcommitted
9p: Fix the incorrect update of inode size in v9fs_file_write()
When using the cache=loose flags, the inode's size was not being updated correctly on a remote write. Thus subsequent reads of the whole file resulted in a truncated read. Fix it. Signed-off-by: Abhishek Kulkarni <adkulkar@umail.iu.edu> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent 7549ae3 commit 637d020

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎fs/9p/vfs_file.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/string.h>
3333
#include <linux/inet.h>
3434
#include <linux/list.h>
35+
#include <linux/pagemap.h>
3536
#include <asm/uaccess.h>
3637
#include <linux/idr.h>
3738
#include <net/9p/9p.h>
@@ -210,6 +211,7 @@ v9fs_file_write(struct file *filp, const char __user * data,
210211
struct p9_client *clnt;
211212
struct inode *inode = filp->f_path.dentry->d_inode;
212213
int origin = *offset;
214+
unsigned long pg_start, pg_end;
213215

214216
P9_DPRINTK(P9_DEBUG_VFS, "data %p count %d offset %x\n", data,
215217
(int)count, (int)*offset);
@@ -225,7 +227,7 @@ v9fs_file_write(struct file *filp, const char __user * data,
225227
if (count < rsize)
226228
rsize = count;
227229

228-
n = p9_client_write(fid, NULL, data+total, *offset+total,
230+
n = p9_client_write(fid, NULL, data+total, origin+total,
229231
rsize);
230232
if (n <= 0)
231233
break;
@@ -234,13 +236,12 @@ v9fs_file_write(struct file *filp, const char __user * data,
234236
} while (count > 0);
235237

236238
if (total > 0) {
237-
invalidate_inode_pages2_range(inode->i_mapping, origin,
238-
origin+total);
239+
pg_start = origin >> PAGE_CACHE_SHIFT;
240+
pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
241+
invalidate_inode_pages2_range(inode->i_mapping, pg_start,
242+
pg_end);
239243
*offset += total;
240-
}
241-
242-
if (*offset > i_size_read(inode)) {
243-
i_size_write(inode, *offset);
244+
i_size_write(inode, i_size_read(inode) + total);
244245
inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
245246
}
246247

0 commit comments

Comments
 (0)