backing-file: always end a queued write
Subsystems (2)
PATCH 1/1 backing-file: always end a queued write
From: Chris Mason <[email protected]>
commit 627cdcbc2a2eceb0452078a0c14370f9f1f17a91 upstream.
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
---
[ backport: context: no do_backing_file_write_iter(), the write is marked
in backing_file_write_iter() ]
fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/backing-file.c +4 -1
@@ -83,6 +83,7 @@ struct backing_aio {refcount_t ref;struct kiocb *orig_iocb;/* used for aio completion */ +bool is_write;void (*end_write)(struct file *,loff_t ,ssize_t );struct work_struct work;long res;
@@ -123,7 +124,8 @@ static void backing_aio_rw_complete(struct kiocb *iocb, long res) struct backing_aio *aio = container_of(iocb, struct backing_aio, iocb);struct kiocb *orig_iocb = aio->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) +/* Pairs with kiocb_start_write() in vfs_iocb_iter_write() */ +if (aio->is_write)kiocb_end_write (iocb);backing_aio_cleanup (aio, res);
@@ -255,6 +257,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,if (!aio) goto out; aio->orig_iocb = iocb; + aio->is_write = true; aio->end_write = ctx->end_write;kiocb_clone (&aio->iocb, iocb,get_file (file));
aio->iocb.ki_flags = flags;
Signature · 1 line
backport
PATCH 1/1 backing-file: always end a queued write
From: Chris Mason <[email protected]>
commit 627cdcbc2a2eceb0452078a0c14370f9f1f17a91 upstream.
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
---
[ backport: context: no do_backing_file_write_iter(), the write is marked
in backing_file_write_iter() ]
fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/backing-file.c +4 -1
@@ -83,6 +83,7 @@ struct backing_aio {refcount_t ref;struct kiocb *orig_iocb;/* used for aio completion */ +bool is_write;void (*end_write)(struct kiocb *iocb,ssize_t );struct work_struct work;long res;
@@ -123,7 +124,8 @@ static void backing_aio_rw_complete(struct kiocb *iocb, long res) struct backing_aio *aio = container_of(iocb, struct backing_aio, iocb);struct kiocb *orig_iocb = aio->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) +/* Pairs with kiocb_start_write() in vfs_iocb_iter_write() */ +if (aio->is_write)kiocb_end_write (iocb);backing_aio_cleanup (aio, res);
@@ -255,6 +257,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,if (!aio) goto out; aio->orig_iocb = iocb; + aio->is_write = true; aio->end_write = ctx->end_write;kiocb_clone (&aio->iocb, iocb,get_file (file));
aio->iocb.ki_flags = flags;
Signature · 1 line
backport
PATCH 1/1 backing-file: always end a queued write
In reply to Amir GoldsteinFrom: Chris Mason <[email protected]>
commit 627cdcbc2a2eceb0452078a0c14370f9f1f17a91 upstream.
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
[backport: no fs/backing-file.c, mark the write in struct ovl_aio_req and
test it in ovl_aio_cleanup_handler()]
--- fs/overlayfs/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +3 -1
@@ -19,6 +19,7 @@ struct ovl_aio_req {struct kiocb iocb;refcount_t ref;struct kiocb *orig_iocb; +bool is_write; };static struct kmem_cache *ovl_aio_request_cachep;
@@ -269,7 +270,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)struct kiocb *iocb = &aio_req->iocb;struct kiocb *orig_iocb = aio_req->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) { +if (aio_req->is_write) {struct inode *inode =file_inode (orig_iocb->ki_filp);/* Actually acquired in ovl_write_iter() */
@@ -396,6 +397,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) SB_FREEZE_WRITE); real.flags =0 ; aio_req->orig_iocb = iocb; + aio_req->is_write = true;kiocb_clone (&aio_req->iocb, iocb,get_file (real.file)); aio_req->iocb.ki_flags = ifl; aio_req->iocb.ki_complete = ovl_aio_rw_complete;
Signature · 1 line
backport
PATCH 1/1 backing-file: always end a queued write
In reply to Amir GoldsteinFrom: Chris Mason <[email protected]>
commit 627cdcbc2a2eceb0452078a0c14370f9f1f17a91 upstream.
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
[backport: no fs/backing-file.c, mark the write in struct ovl_aio_req and
test it in ovl_aio_cleanup_handler()]
--- fs/overlayfs/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +4 -1
@@ -19,6 +19,7 @@ struct ovl_aio_req {struct kiocb iocb;refcount_t ref;struct kiocb *orig_iocb; +bool is_write; };static struct kmem_cache *ovl_aio_request_cachep;
@@ -289,7 +290,8 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)struct kiocb *iocb = &aio_req->iocb;struct kiocb *orig_iocb = aio_req->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) { +/* Pairs with kiocb_start_write() in ovl_write_iter() */ +if (aio_req->is_write) {struct inode *inode =file_inode (orig_iocb->ki_filp);kiocb_end_write (iocb);
@@ -413,6 +415,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) goto out; aio_req->orig_iocb = iocb; + aio_req->is_write = true;kiocb_clone (&aio_req->iocb, iocb,get_file (real.file)); aio_req->iocb.ki_flags = ifl; aio_req->iocb.ki_complete = ovl_aio_rw_complete;
Signature · 1 line
backport