The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear 
at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.54
------>
commit ca412abe814ff7b1ef17f855a534980a1b9bb205
Author: Kirill Tkhai <[email protected]>
Date:   Thu Jul 15 11:13:49 2021 +0300

    ploop: Add interface to configure new clusters preallocation
    
    Add new optional parameter "falloc_new_clu" to configure new clusters 
preallocation.
    It goes after clu_size and before fds:
    
    $dmsetup create dm_ploop --table "0 $sectors ploop <clu_size> 
falloc_new_clu <fd1 ... <fdN>"
    
    In case of falloc is not needed (truncate will be used instead),
    we just don't use it:
    
    $dmsetup create dm_ploop --table "0 $sectors ploop <clu_size> <fd1 ... 
<fdN>"
    
    In case of falloc is enabled, 'f' is added to status line:
    
    $dmsetup table ploopXXX
    ploopXXX: 0 4194304 ploop 2 v2 2048 f
    (it may be combined with other status symbols like 'ftn').
    
    It may be enabled dynamically:
    
    $dmsetup message dm_ploop 0 set_falloc_new_clu <enabled>
    where enabled is 1 or 0.
    
    Note, that now we use rwsem in ploop_status() to get status
    letters, since they are modified under this rwsem.
    
    https://jira.sw.ru/browse/PSBM-106554
    
    Signed-off-by: Kirill Tkhai <[email protected]>
---
 drivers/md/dm-ploop-cmd.c    | 12 ++++++++++++
 drivers/md/dm-ploop-target.c | 29 +++++++++++++++++++++++++----
 drivers/md/dm-ploop.h        |  1 +
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 137067cccd47..ed775e9bbeb4 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -940,6 +940,14 @@ static int process_flip_upper_deltas(struct ploop *ploop)
        return 0;
 }
 
+static int ploop_set_falloc_new_clu(struct ploop *ploop, u64 val)
+{
+       if (val > 1)
+               return -EINVAL;
+       ploop->falloc_new_clu = !!val;
+       return 0;
+}
+
 static int process_tracking_start(struct ploop *ploop, void *tracking_bitmap,
                                  u32 tb_nr)
 {
@@ -1269,6 +1277,10 @@ int ploop_message(struct dm_target *ti, unsigned int 
argc, char **argv,
                if (argc != 3 || kstrtou64(argv[1], 10, &val) < 0)
                        goto unlock;
                ret = ploop_update_delta_index(ploop, val, argv[2]);
+       } else if (!strncmp(argv[0], "set_falloc_new_clu", 20)) {
+               if (argc != 2 || kstrtou64(argv[1], 10, &val) < 0)
+                       goto unlock;
+               ret = ploop_set_falloc_new_clu(ploop, val);
        } else if (!strncmp(argv[0], "tracking_", 9)) {
                if (argc != 1)
                        goto unlock;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index c69e18bfa13d..472f5aed73e5 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -253,8 +253,8 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char 
**argv, int argc)
        ploop->deltas = deltas;
        ploop->nr_deltas = argc;
 
-       ret = -EINVAL;
        for (i = argc - 1; i >= 0; i--) {
+               ret = -EINVAL;
                arg = argv[i];
                is_raw = false;
                if (strncmp(arg, "raw@", 4) == 0) {
@@ -290,6 +290,13 @@ static int ploop_add_deltas_stack(struct ploop *ploop, 
char **argv, int argc)
        fput(file);
        goto out;
 }
+
+#define EAT_ARG(argc, argv)                                    \
+       do {                                                    \
+               BUILD_BUG_ON(sizeof(argc) != sizeof(int));      \
+               argc--;                                         \
+               argv++;                                         \
+       } while (0);
 /*
  * <data dev>
  */
@@ -366,13 +373,24 @@ static int ploop_ctr(struct dm_target *ti, unsigned int 
argc, char **argv)
                ti->error = "could not parse cluster_log";
                goto err;
        }
+       EAT_ARG(argc, argv);
        ret = dm_set_target_max_io_len(ti, CLU_TO_SEC(ploop, 1));
        if (ret) {
                ti->error = "could not set max_io_len";
                goto err;
        }
 
-       ret = ploop_add_deltas_stack(ploop, &argv[1], argc - 1);
+       /* Optional parameter */
+       if (strcmp(argv[0], "falloc_new_clu") == 0) {
+               if (argc < 2) {
+                       ret = -EINVAL;
+                       goto err;
+               }
+               ploop->falloc_new_clu = true;
+               EAT_ARG(argc, argv);
+       }
+
+       ret = ploop_add_deltas_stack(ploop, &argv[0], argc);
        if (ret)
                goto err;
 
@@ -412,16 +430,19 @@ static void ploop_status(struct dm_target *ti, 
status_type_t type,
        char stat[16] = { 0 }, *p = stat;
        ssize_t sz = 0;
 
-       read_lock_irq(&ploop->bat_rwlock);
+       down_read(&ploop->ctl_rwsem);
+       if (ploop->falloc_new_clu)
+               p += sprintf(p, "f");
        if (ploop->tracking_bitmap)
                p += sprintf(p, "t");
        if (READ_ONCE(ploop->noresume))
                p += sprintf(p, "n");
        if (p == stat)
                p += sprintf(p, "o");
+       up_read(&ploop->ctl_rwsem);
+
        BUG_ON(p - stat >= sizeof(stat));
        DMEMIT("%u v2 %u %s", ploop->nr_deltas, (u32)CLU_TO_SEC(ploop, 1), 
stat);
-       read_unlock_irq(&ploop->bat_rwlock);
 }
 
 static void ploop_set_wants_suspend(struct dm_target *ti, bool wants)
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 9fcad49015b1..b10820887350 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -140,6 +140,7 @@ struct ploop {
        struct rb_root bat_entries;
        struct ploop_delta *deltas;
        u8 nr_deltas;
+       bool falloc_new_clu; /* fallocate() instead of truncate() */
        u32 nr_bat_entries;
        unsigned int cluster_log; /* In sectors */
 
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to