]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm vdo: add dmsetup message for returning configuration info
authorBruce Johnston <bjohnsto@redhat.com>
Thu, 18 Jul 2024 18:02:38 +0000 (14:02 -0400)
committerMikulas Patocka <mpatocka@redhat.com>
Wed, 21 Aug 2024 11:05:56 +0000 (13:05 +0200)
Add a new dmsetup message called config, which will return
useful configuration information for the vdo volume and
the uds index associated with it. The output is a YAML
string, and contains a version number to allow future
additions to the content.

Signed-off-by: Bruce Johnston <bjohnsto@redhat.com>
Signed-off-by: Matthew Sakai <msakai@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Documentation/admin-guide/device-mapper/vdo.rst
drivers/md/dm-vdo/dm-vdo-target.c
drivers/md/dm-vdo/message-stats.c
drivers/md/dm-vdo/message-stats.h

index c69ac186863a317b80c3c3adc1aa1d28a9816a64..a14e6d3e787c9191c9e0036ac16ea13a14190e5e 100644 (file)
@@ -251,7 +251,12 @@ The messages are:
                by the vdostats userspace program to interpret the output
                buffer.
 
-        dump:
+       config:
+               Outputs useful vdo configuration information. Mostly used
+               by users who want to recreate a similar VDO volume and
+               want to know the creation configuration used.
+
+       dump:
                Dumps many internal structures to the system log. This is
                not always safe to run, so it should only be used to debug
                a hung vdo. Optional parameters to specify structures to
index dd05691e4097dcab1dc4240253fc4a7c0bc8ed64..4b94f5718ed7af1d6d88d43fffda80e9f10278e7 100644 (file)
@@ -1105,6 +1105,9 @@ static int vdo_message(struct dm_target *ti, unsigned int argc, char **argv,
        if ((argc == 1) && (strcasecmp(argv[0], "stats") == 0)) {
                vdo_write_stats(vdo, result_buffer, maxlen);
                result = 1;
+       } else if ((argc == 1) && (strcasecmp(argv[0], "config") == 0)) {
+               vdo_write_config(vdo, &result_buffer, &maxlen);
+               result = 1;
        } else {
                result = vdo_status_to_errno(process_vdo_message(vdo, argc, argv));
        }
@@ -2832,7 +2835,7 @@ static void vdo_resume(struct dm_target *ti)
 static struct target_type vdo_target_bio = {
        .features = DM_TARGET_SINGLETON,
        .name = "vdo",
-       .version = { 9, 0, 0 },
+       .version = { 9, 1, 0 },
        .module = THIS_MODULE,
        .ctr = vdo_ctr,
        .dtr = vdo_dtr,
index 2802cf92922bd0dd5e6e8c01bb93c4904da887a7..75dfcd7c5f631414c033c12fb1294a21bf0a00b2 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "dedupe.h"
+#include "indexer.h"
 #include "logger.h"
 #include "memory-alloc.h"
 #include "message-stats.h"
@@ -430,3 +431,50 @@ int vdo_write_stats(struct vdo *vdo, char *buf, unsigned int maxlen)
        vdo_free(stats);
        return VDO_SUCCESS;
 }
+
+static void write_index_memory(u32 mem, char **buf, unsigned int *maxlen)
+{
+       char *prefix = "memorySize : ";
+
+       /* Convert index memory to fractional value */
+       if (mem == (u32)UDS_MEMORY_CONFIG_256MB)
+               write_string(prefix, "0.25, ", NULL, buf, maxlen);
+       else if (mem == (u32)UDS_MEMORY_CONFIG_512MB)
+               write_string(prefix, "0.50, ", NULL, buf, maxlen);
+       else if (mem == (u32)UDS_MEMORY_CONFIG_768MB)
+               write_string(prefix, "0.75, ", NULL, buf, maxlen);
+       else
+               write_u32(prefix, mem, ", ", buf, maxlen);
+}
+
+static void write_index_config(struct index_config *config, char **buf,
+                              unsigned int *maxlen)
+{
+       write_string("index :  ", "{ ", NULL, buf, maxlen);
+       /* index mem size */
+       write_index_memory(config->mem, buf, maxlen);
+       /* whether the index is sparse or not */
+       write_bool("isSparse : ", config->sparse, ", ", buf, maxlen);
+       write_string(NULL, "}", ", ", buf, maxlen);
+}
+
+int vdo_write_config(struct vdo *vdo, char **buf, unsigned int *maxlen)
+{
+       struct vdo_config *config = &vdo->states.vdo.config;
+
+       write_string(NULL, "{ ", NULL, buf, maxlen);
+       /* version */
+       write_u32("version : ", 1, ", ", buf, maxlen);
+       /* physical size */
+       write_block_count_t("physicalSize : ", config->physical_blocks * VDO_BLOCK_SIZE, ", ",
+                           buf, maxlen);
+       /* logical size */
+       write_block_count_t("logicalSize : ", config->logical_blocks * VDO_BLOCK_SIZE, ", ",
+                           buf, maxlen);
+       /* slab size */
+       write_block_count_t("slabSize : ", config->slab_size, ", ", buf, maxlen);
+       /* index config */
+       write_index_config(&vdo->geometry.index_config, buf, maxlen);
+       write_string(NULL, "}", NULL, buf, maxlen);
+       return VDO_SUCCESS;
+}
index f7fceca9acab47a93a5b345350e0c2e1ffc855b6..f9c95eff569dcd61a8b18f732c1c5b4652107a46 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "types.h"
 
+int vdo_write_config(struct vdo *vdo, char **buf, unsigned int *maxlen);
 int vdo_write_stats(struct vdo *vdo, char *buf, unsigned int maxlen);
 
 #endif /* VDO_MESSAGE_STATS_H */