[PATCH V2] fuse: Do not mask return value from fuse_direct_io for partially valid data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH V2] fuse: Do not mask return value from fuse_direct_io for partially valid data

Ashish Samant
If a user calls writev/readv in direct io mode with partially valid data
in the iovec array such that any vector other than the first one in the
array contains invalid data, we currently return the error for the invalid
iovec.

Instead, we should return the number of bytes already written/read and not
the error as we do in the non direct_io case.

Reported-by: Alexey Kodanev <[hidden email]>
Signed-off-by: Ashish Samant <[hidden email]>

V1->V2:
 - Fix compile error.
 - fuse_get_user_pages should be fixed as well.
---
 fs/fuse/file.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index b03d253..4eec987 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1240,6 +1240,7 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii,
        size_t *nbytesp, int write)
 {
  size_t nbytes = 0;  /* # bytes already packed in req */
+ ssize_t ret = 0;
 
  /* Special case for kernel I/O: can copy directly into the buffer */
  if (ii->type & ITER_KVEC) {
@@ -1259,13 +1260,12 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii,
  while (nbytes < *nbytesp && req->num_pages < req->max_pages) {
  unsigned npages;
  size_t start;
- ssize_t ret = iov_iter_get_pages(ii,
- &req->pages[req->num_pages],
+ ret = iov_iter_get_pages(ii, &req->pages[req->num_pages],
  *nbytesp - nbytes,
  req->max_pages - req->num_pages,
  &start);
  if (ret < 0)
- return ret;
+ break;
 
  iov_iter_advance(ii, ret);
  nbytes += ret;
@@ -1288,7 +1288,7 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii,
 
  *nbytesp = nbytes;
 
- return 0;
+ return ret;
 }
 
 static inline int fuse_iter_npages(const struct iov_iter *ii_p)
@@ -1312,6 +1312,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  pgoff_t idx_to = (pos + count - 1) >> PAGE_CACHE_SHIFT;
  ssize_t res = 0;
  struct fuse_req *req;
+ int err = 0;
 
  if (io->async)
  req = fuse_get_req_for_background(fc, fuse_iter_npages(iter));
@@ -1332,11 +1333,9 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  size_t nres;
  fl_owner_t owner = current->files;
  size_t nbytes = min(count, nmax);
- int err = fuse_get_user_pages(req, iter, &nbytes, write);
- if (err) {
- res = err;
+ err = fuse_get_user_pages(req, iter, &nbytes, write);
+ if (err && !nbytes)
  break;
- }
 
  if (write)
  nres = fuse_send_write(req, io, pos, nbytes, owner);
@@ -1347,10 +1346,11 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  fuse_release_user_pages(req, !write);
  if (req->out.h.error) {
  if (!res)
- res = req->out.h.error;
+ err = req->out.h.error;
  break;
  } else if (nres > nbytes) {
- res = -EIO;
+ res = 0;
+ err = -EIO;
  break;
  }
  count -= nres;
@@ -1374,7 +1374,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  if (res > 0)
  *ppos = pos;
 
- return res;
+ return res > 0 ? res : err;
 }
 EXPORT_SYMBOL_GPL(fuse_direct_io);
 
--
1.7.1


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH V2] fuse: Do not mask return value from fuse_direct_io for partially valid data

Miklos Szeredi
On Tue, Mar 15, 2016 at 5:57 AM, Ashish Samant <[hidden email]> wrote:

> If a user calls writev/readv in direct io mode with partially valid data
> in the iovec array such that any vector other than the first one in the
> array contains invalid data, we currently return the error for the invalid
> iovec.
>
> Instead, we should return the number of bytes already written/read and not
> the error as we do in the non direct_io case.
>
> Reported-by: Alexey Kodanev <[hidden email]>
> Signed-off-by: Ashish Samant <[hidden email]>
>
> V1->V2:
>  - Fix compile error.
>  - fuse_get_user_pages should be fixed as well.

Thanks, applied.

Miklos

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel