[Devel] [PATCH RHEL7 COMMIT] ploop: Use preallocation for ext4

Vasily Averin vvs at virtuozzo.com
Mon May 17 14:22:01 MSK 2021


The commit is pushed to "branch-rh7-3.10.0-1160.25.1.vz7.180.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.25.1.vz7.180.2
------>
commit c15a5ba1b836583b935886d7c6dc09202b9708d0
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 17 14:22:01 2021 +0300

    ploop: Use preallocation for ext4
    
    In case of kaio we should call preallocation directly,
    since it is not called from generic code.
    
    https://jira.sw.ru/browse/PSBM-129303
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/io_kaio.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 112fd92acb40..44df242d8128 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -35,6 +35,7 @@ int ploop_kaio_upgrade(struct address_space * mapping);
 
 static int __kaio_truncate(struct ploop_io * io, struct file * file, u64 pos);
 static int kaio_truncate(struct ploop_io * io, struct file * file, __u32 a_h);
+static int kaio_file_expand(struct ploop_io *io, struct file *file, u64 pos);
 
 static void __kaio_queue_fsync_req(struct ploop_request * preq, int prio)
 {
@@ -545,8 +546,8 @@ static int kaio_fsync_thread(void * data)
 				preq->prealloc_size = isize;
 				goto ready;
 			}
-			err = __kaio_truncate(io, io->files.file,
-					      preq->prealloc_size);
+			err = kaio_file_expand(io, io->files.file,
+					       preq->prealloc_size);
 			if (err)
 				PLOOP_REQ_SET_ERROR(preq, -EIO);
 		} else {
@@ -928,7 +929,7 @@ static int kaio_alloc_sync(struct ploop_io * io, loff_t pos, loff_t len)
 		size = io->prealloced_size;
 
 	if (size > i_size_read(io->files.inode))
-		err = __kaio_truncate(io, io->files.file, size);
+		err = kaio_file_expand(io, io->files.file, size);
 
 	if (!err) {
 		WARN_ON(io->alloc_head > a_h);
@@ -1171,6 +1172,32 @@ static int kaio_truncate(struct ploop_io * io, struct file * file,
 			       (u64)alloc_head << (io->plo->cluster_log + 9));
 }
 
+static int kaio_file_allocate(struct ploop_io *io, struct file *file, u64 pos)
+{
+	u64 isize;
+	int ret;
+
+	if (file->f_mapping != io->files.mapping)
+		return -EINVAL;
+
+	isize = i_size_read(io->files.inode);
+	WARN_ON_ONCE(pos < isize);
+
+	ret = file->f_op->fallocate(file, 0, isize, pos - isize);
+	if (ret)
+		return ret;
+
+	return vfs_fsync(file, 0);
+}
+
+static int kaio_file_expand(struct ploop_io *io, struct file *file, u64 pos)
+{
+	if (file_inode(file)->i_sb->s_magic == FUSE_SUPER_MAGIC)
+		return __kaio_truncate(io, file, pos);
+
+	return kaio_file_allocate(io, file, pos);
+}
+
 static void kaio_unplug(struct ploop_io * io)
 {
 	/* Need more thinking how to implement unplug */


More information about the Devel mailing list