Messages in this thread Patch in this message |  | | From | Bart Van Assche <> | Subject | [PATCH 2/4] configfs: Fix writing at a non-zero offset | Date | Fri, 23 Jul 2021 14:23:51 -0700 |
| |
Store data at the right offset when writing with a non-zero offset. I think this patch fixes behavior introduced in the initial configfs commit. From a source code comment in the initial configfs commit: "There is no easy way for us to know if userspace is only doing a partial write, so we don't support them."
Cc: Bodo Stroesser <bostroesser@gmail.com> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: Yanko Kaneti <yaneti@declera.com> Cc: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- fs/configfs/file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 8121bb1b2121..3b2ddc2e5d42 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -226,14 +226,16 @@ static ssize_t configfs_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct configfs_buffer *buffer = file->private_data; - ssize_t len; + int len, written = 0; mutex_lock(&buffer->mutex); len = fill_write_buffer(buffer, iocb->ki_pos, from); if (len > 0) - len = flush_write_buffer(file, buffer, len); - if (len > 0) - iocb->ki_pos += len; + written = flush_write_buffer(file, buffer, iocb->ki_pos + len); + if (written > 0) { + len = max_t(int, 0, written - iocb->ki_pos); + iocb->ki_pos = written; + } mutex_unlock(&buffer->mutex); return len; }
|  |