* [patch 2/5] fuse: fix reading past EOF
2007-10-24 11:13 [patch 0/5] fuse fixes for 2.6.24 Miklos Szeredi
2007-10-24 11:13 ` [patch 1/5] fuse: fuse_file_alloc(): fix NULL dereferences Miklos Szeredi
@ 2007-10-24 11:13 ` Miklos Szeredi
2007-10-24 11:13 ` [patch 3/5] fuse: cleanup: add fuse_get_attr_version() Miklos Szeredi
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Miklos Szeredi @ 2007-10-24 11:13 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
[-- Attachment #1: fuse_read_eof_fix.patch --]
[-- Type: text/plain, Size: 4241 bytes --]
From: Miklos Szeredi <mszeredi@suse.cz>
Currently reading a fuse file will stop at cached i_size and return
EOF, even though the file might have grown since the attributes were
last updated.
So detect if trying to read past EOF, and refresh the attributes
before continuing with the read.
Thanks to mpb for the report.
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
Index: linux/fs/fuse/dir.c
===================================================================
--- linux.orig/fs/fuse/dir.c 2007-10-19 16:45:09.000000000 +0200
+++ linux/fs/fuse/dir.c 2007-10-19 16:46:33.000000000 +0200
@@ -775,6 +775,31 @@ static int fuse_do_getattr(struct inode
return err;
}
+int fuse_update_attributes(struct inode *inode, struct kstat *stat,
+ struct file *file, bool *refreshed)
+{
+ struct fuse_inode *fi = get_fuse_inode(inode);
+ int err;
+ bool r;
+
+ if (fi->i_time < get_jiffies_64()) {
+ r = true;
+ err = fuse_do_getattr(inode, stat, file);
+ } else {
+ r = false;
+ err = 0;
+ if (stat) {
+ generic_fillattr(inode, stat);
+ stat->mode = fi->orig_i_mode;
+ }
+ }
+
+ if (refreshed != NULL)
+ *refreshed = r;
+
+ return err;
+}
+
/*
* Calling into a user-controlled filesystem gives the filesystem
* daemon ptrace-like capabilities over the requester process. This
@@ -862,14 +887,9 @@ static int fuse_permission(struct inode
*/
if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) ||
((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
- struct fuse_inode *fi = get_fuse_inode(inode);
- if (fi->i_time < get_jiffies_64()) {
- err = fuse_do_getattr(inode, NULL, NULL);
- if (err)
- return err;
-
- refreshed = true;
- }
+ err = fuse_update_attributes(inode, NULL, NULL, &refreshed);
+ if (err)
+ return err;
}
if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
@@ -1173,22 +1193,12 @@ static int fuse_getattr(struct vfsmount
struct kstat *stat)
{
struct inode *inode = entry->d_inode;
- struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_conn *fc = get_fuse_conn(inode);
- int err;
if (!fuse_allow_task(fc, current))
return -EACCES;
- if (fi->i_time < get_jiffies_64())
- err = fuse_do_getattr(inode, stat, NULL);
- else {
- err = 0;
- generic_fillattr(inode, stat);
- stat->mode = fi->orig_i_mode;
- }
-
- return err;
+ return fuse_update_attributes(inode, stat, NULL, NULL);
}
static int fuse_setxattr(struct dentry *entry, const char *name,
Index: linux/fs/fuse/file.c
===================================================================
--- linux.orig/fs/fuse/file.c 2007-10-19 16:45:22.000000000 +0200
+++ linux/fs/fuse/file.c 2007-10-19 16:46:33.000000000 +0200
@@ -453,6 +453,25 @@ out:
return err;
}
+static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
+ unsigned long nr_segs, loff_t pos)
+{
+ struct inode *inode = iocb->ki_filp->f_mapping->host;
+
+ if (pos + iov_length(iov, nr_segs) > i_size_read(inode)) {
+ int err;
+ /*
+ * If trying to read past EOF, make sure the i_size
+ * attribute is up-to-date.
+ */
+ err = fuse_update_attributes(inode, NULL, iocb->ki_filp, NULL);
+ if (err)
+ return err;
+ }
+
+ return generic_file_aio_read(iocb, iov, nr_segs, pos);
+}
+
static void fuse_write_fill(struct fuse_req *req, struct fuse_file *ff,
struct inode *inode, loff_t pos, size_t count,
int writepage)
@@ -887,7 +906,7 @@ static sector_t fuse_bmap(struct address
static const struct file_operations fuse_file_operations = {
.llseek = generic_file_llseek,
.read = do_sync_read,
- .aio_read = generic_file_aio_read,
+ .aio_read = fuse_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = fuse_file_mmap,
Index: linux/fs/fuse/fuse_i.h
===================================================================
--- linux.orig/fs/fuse/fuse_i.h 2007-10-19 16:45:09.000000000 +0200
+++ linux/fs/fuse/fuse_i.h 2007-10-19 16:46:33.000000000 +0200
@@ -593,3 +593,6 @@ int fuse_valid_type(int m);
int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task);
u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
+
+int fuse_update_attributes(struct inode *inode, struct kstat *stat,
+ struct file *file, bool *refreshed);
--
^ permalink raw reply [flat|nested] 6+ messages in thread* [patch 4/5] fuse: pass open flags to read and write
2007-10-24 11:13 [patch 0/5] fuse fixes for 2.6.24 Miklos Szeredi
` (2 preceding siblings ...)
2007-10-24 11:13 ` [patch 3/5] fuse: cleanup: add fuse_get_attr_version() Miklos Szeredi
@ 2007-10-24 11:13 ` Miklos Szeredi
2007-10-24 11:13 ` [patch 5/5] fuse: fix FUSE_FILE_OPS sending Miklos Szeredi
4 siblings, 0 replies; 6+ messages in thread
From: Miklos Szeredi @ 2007-10-24 11:13 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
[-- Attachment #1: fuse_file_flags.patch --]
[-- Type: text/plain, Size: 6921 bytes --]
From: Miklos Szeredi <mszeredi@suse.cz>
Some open flags (O_APPEND, O_DIRECT) can be changed with
fcntl(F_SETFL, ...) after open, but fuse currently only sends the
flags to userspace in open.
To make it possible to correcly handle changing flags, send the
current value to userspace in each read and write.
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
Index: linux/fs/fuse/file.c
===================================================================
--- linux.orig/fs/fuse/file.c 2007-10-19 19:58:08.000000000 +0200
+++ linux/fs/fuse/file.c 2007-10-19 20:20:59.000000000 +0200
@@ -289,14 +289,16 @@ static int fuse_fsync(struct file *file,
return fuse_fsync_common(file, de, datasync, 0);
}
-void fuse_read_fill(struct fuse_req *req, struct fuse_file *ff,
+void fuse_read_fill(struct fuse_req *req, struct file *file,
struct inode *inode, loff_t pos, size_t count, int opcode)
{
struct fuse_read_in *inarg = &req->misc.read_in;
+ struct fuse_file *ff = file->private_data;
inarg->fh = ff->fh;
inarg->offset = pos;
inarg->size = count;
+ inarg->flags = file->f_flags;
req->in.h.opcode = opcode;
req->in.h.nodeid = get_node_id(inode);
req->in.numargs = 1;
@@ -313,9 +315,8 @@ static size_t fuse_send_read(struct fuse
fl_owner_t owner)
{
struct fuse_conn *fc = get_fuse_conn(inode);
- struct fuse_file *ff = file->private_data;
- fuse_read_fill(req, ff, inode, pos, count, FUSE_READ);
+ fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
if (owner != NULL) {
struct fuse_read_in *inarg = &req->misc.read_in;
@@ -376,15 +377,16 @@ static void fuse_readpages_end(struct fu
fuse_put_request(fc, req);
}
-static void fuse_send_readpages(struct fuse_req *req, struct fuse_file *ff,
+static void fuse_send_readpages(struct fuse_req *req, struct file *file,
struct inode *inode)
{
struct fuse_conn *fc = get_fuse_conn(inode);
loff_t pos = page_offset(req->pages[0]);
size_t count = req->num_pages << PAGE_CACHE_SHIFT;
req->out.page_zeroing = 1;
- fuse_read_fill(req, ff, inode, pos, count, FUSE_READ);
+ fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
if (fc->async_read) {
+ struct fuse_file *ff = file->private_data;
req->ff = fuse_file_get(ff);
req->end = fuse_readpages_end;
request_send_background(fc, req);
@@ -396,7 +398,7 @@ static void fuse_send_readpages(struct f
struct fuse_fill_data {
struct fuse_req *req;
- struct fuse_file *ff;
+ struct file *file;
struct inode *inode;
};
@@ -411,7 +413,7 @@ static int fuse_readpages_fill(void *_da
(req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
(req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
req->pages[req->num_pages - 1]->index + 1 != page->index)) {
- fuse_send_readpages(req, data->ff, inode);
+ fuse_send_readpages(req, data->file, inode);
data->req = req = fuse_get_req(fc);
if (IS_ERR(req)) {
unlock_page(page);
@@ -435,7 +437,7 @@ static int fuse_readpages(struct file *f
if (is_bad_inode(inode))
goto out;
- data.ff = file->private_data;
+ data.file = file;
data.inode = inode;
data.req = fuse_get_req(fc);
err = PTR_ERR(data.req);
@@ -445,7 +447,7 @@ static int fuse_readpages(struct file *f
err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data);
if (!err) {
if (data.req->num_pages)
- fuse_send_readpages(data.req, data.ff, inode);
+ fuse_send_readpages(data.req, file, inode);
else
fuse_put_request(fc, data.req);
}
@@ -472,11 +474,12 @@ static ssize_t fuse_file_aio_read(struct
return generic_file_aio_read(iocb, iov, nr_segs, pos);
}
-static void fuse_write_fill(struct fuse_req *req, struct fuse_file *ff,
+static void fuse_write_fill(struct fuse_req *req, struct file *file,
struct inode *inode, loff_t pos, size_t count,
int writepage)
{
struct fuse_conn *fc = get_fuse_conn(inode);
+ struct fuse_file *ff = file->private_data;
struct fuse_write_in *inarg = &req->misc.write.in;
struct fuse_write_out *outarg = &req->misc.write.out;
@@ -485,6 +488,7 @@ static void fuse_write_fill(struct fuse_
inarg->offset = pos;
inarg->size = count;
inarg->write_flags = writepage ? FUSE_WRITE_CACHE : 0;
+ inarg->flags = file->f_flags;
req->in.h.opcode = FUSE_WRITE;
req->in.h.nodeid = get_node_id(inode);
req->in.argpages = 1;
@@ -505,7 +509,7 @@ static size_t fuse_send_write(struct fus
fl_owner_t owner)
{
struct fuse_conn *fc = get_fuse_conn(inode);
- fuse_write_fill(req, file->private_data, inode, pos, count, 0);
+ fuse_write_fill(req, file, inode, pos, count, 0);
if (owner != NULL) {
struct fuse_write_in *inarg = &req->misc.write.in;
inarg->write_flags |= FUSE_WRITE_LOCKOWNER;
Index: linux/include/linux/fuse.h
===================================================================
--- linux.orig/include/linux/fuse.h 2007-10-15 13:48:52.000000000 +0200
+++ linux/include/linux/fuse.h 2007-10-19 20:22:41.000000000 +0200
@@ -16,6 +16,7 @@
* - add lk_flags in fuse_lk_in
* - add lock_owner field to fuse_setattr_in, fuse_read_in and fuse_write_in
* - add blksize field to fuse_attr
+ * - add file flags field to fuse_read_in and fuse_write_in
*/
#include <asm/types.h>
@@ -280,6 +281,8 @@ struct fuse_read_in {
__u32 size;
__u32 read_flags;
__u64 lock_owner;
+ __u32 flags;
+ __u32 padding;
};
#define FUSE_COMPAT_WRITE_IN_SIZE 24
@@ -290,6 +293,8 @@ struct fuse_write_in {
__u32 size;
__u32 write_flags;
__u64 lock_owner;
+ __u32 flags;
+ __u32 padding;
};
struct fuse_write_out {
Index: linux/fs/fuse/dir.c
===================================================================
--- linux.orig/fs/fuse/dir.c 2007-10-19 20:02:53.000000000 +0200
+++ linux/fs/fuse/dir.c 2007-10-19 20:27:51.000000000 +0200
@@ -964,7 +964,6 @@ static int fuse_readdir(struct file *fil
struct page *page;
struct inode *inode = file->f_path.dentry->d_inode;
struct fuse_conn *fc = get_fuse_conn(inode);
- struct fuse_file *ff = file->private_data;
struct fuse_req *req;
if (is_bad_inode(inode))
@@ -981,7 +980,7 @@ static int fuse_readdir(struct file *fil
}
req->num_pages = 1;
req->pages[0] = page;
- fuse_read_fill(req, ff, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR);
+ fuse_read_fill(req, file, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR);
request_send(fc, req);
nbytes = req->out.args[0].size;
err = req->out.h.error;
Index: linux/fs/fuse/fuse_i.h
===================================================================
--- linux.orig/fs/fuse/fuse_i.h 2007-10-19 20:02:53.000000000 +0200
+++ linux/fs/fuse/fuse_i.h 2007-10-19 20:27:04.000000000 +0200
@@ -447,7 +447,7 @@ void fuse_send_forget(struct fuse_conn *
/**
* Initialize READ or READDIR request
*/
-void fuse_read_fill(struct fuse_req *req, struct fuse_file *ff,
+void fuse_read_fill(struct fuse_req *req, struct file *file,
struct inode *inode, loff_t pos, size_t count, int opcode);
/**
--
^ permalink raw reply [flat|nested] 6+ messages in thread