The commit is pushed to "branch-rh9-5.14.0-70.22.1.vz9.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-70.22.1.vz9.17.8
------>
commit 00b0bcce93303294ecdf0d3a005050d7cf374993
Author: Alexander Atanasov <alexander.atana...@virtuozzo.com>
Date:   Tue Sep 20 11:23:28 2022 +0300

    dm-qcow2: check if files are opened with O_DIRECT
    
    Check that passed file descriptors are using O_DIRECT.
    Required to avoid data integrity problems caused by
    the page cache.
    
    + add error messages
    
    https://jira.sw.ru/browse/PSBM-142050
    Signed-off-by: Alexander Atanasov <alexander.atana...@virtuozzo.com>
---
 drivers/md/dm-qcow2-target.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 9a6f970343ec..f646992a6040 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -672,16 +672,28 @@ static int qcow2_attach_file(struct dm_target *ti, struct 
qcow2_target *tgt,
        fmode_t mode;
 
        file = qcow2->file = fget(fd);
-       if (!file) /* In case of further errors, cleanup is made by caller */
+       /* In case of further errors, cleanup is made by caller */
+       if (!file) {
+               ti->error = "No image file set";
                return -ENOENT;
+       }
+
+       if (!S_ISREG(file_inode(file)->i_mode)) {
+               ti->error = "Image file is not a regular file";
+               return -EINVAL;
+       }
 
-       if (!S_ISREG(file_inode(file)->i_mode))
+       if (!(file->f_flags & O_DIRECT)) {
+               ti->error = "Image file is opened in cached mode";
                return -EINVAL;
+       }
 
        mode = tgt->top != qcow2 ? FMODE_READ : dm_table_get_mode(ti->table);
        mode &= (FMODE_READ|FMODE_WRITE);
-       if (mode & ~(file->f_mode & (FMODE_READ|FMODE_WRITE)))
+       if (mode & ~(file->f_mode & (FMODE_READ|FMODE_WRITE))) {
+               ti->error = "Image file is opened in a wrong mode";
                return -EACCES;
+       }
 
        return 0;
 }
@@ -808,7 +820,8 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int 
argc, char **argv)
 
                ret = qcow2_attach_file(ti, tgt, qcow2, fd);
                if (ret) {
-                       ti->error = "Error attaching file";
+                       if (!ti->error)
+                               ti->error = "Error attaching file";
                        goto err;
                }
 
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to