Re: [PATCH v7 06/15] iomap: Return error code from iomap_write_iter()

Matthew Wilcox
2022-06-02T12:38:39Z

On Wed, Jun 01, 2022 at 02:01:32PM -0700, Stefan Roesch wrote:
> Change the signature of iomap_write_iter() to return an error code. In
> case we cannot allocate a page in iomap_write_begin(), we will not retry
> the memory alloction in iomap_write_begin().

loff_t can already represent an error code. And it's already used like
that.

> @@ -829,7 +830,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
> length -= status;
> } while (iov_iter_count(i) && length);
>
> - return written ? written : status;
> + *processed = written ? written : error;
> + return error;

I think the change you really want is:

if (status == -EAGAIN)
return -EAGAIN;
if (written)
return written;
return status;

> @@ -843,12 +845,15 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
> .flags = IOMAP_WRITE,
> };
> int ret;
> + int error = 0;
>
> if (iocb->ki_flags & IOCB_NOWAIT)
> iter.flags |= IOMAP_NOWAIT;
>
> - while ((ret = iomap_iter(&iter, ops)) > 0)
> - iter.processed = iomap_write_iter(&iter, i);
> + while ((ret = iomap_iter(&iter, ops)) > 0) {
> + if (error != -EAGAIN)
> + error = iomap_write_iter(&iter, i, &iter.processed);
> + }

You don't need to change any of this. Look at how iomap_iter_advance()
works.