all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 qemu] fix #1534: vma: Add extract filter for disk images
@ 2023-08-08 12:00 Filip Schauer
  2023-08-09 11:06 ` Fiona Ebner
  0 siblings, 1 reply; 2+ messages in thread
From: Filip Schauer @ 2023-08-08 12:00 UTC (permalink / raw)
  To: pve-devel

Add a filter to the "vma extract" command. A comma seperated list of
disk images that should be extracted can be passed with the "-f" option.

Example to extract an IDE drive and an SCSI drive from vzdump.vma:

vma extract vzdump.vma -f "drive-ide0,drive-scsi0" extractdir

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 ...VE-Backup-add-vma-backup-format-code.patch | 42 +++++++++++++++----
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch b/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch
index 8471a6f..dc9c882 100644
--- a/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch
+++ b/debian/patches/pve/0027-PVE-Backup-add-vma-backup-format-code.patch
@@ -1738,7 +1738,7 @@ new file mode 100644
 index 0000000000..304f02bc84
 --- /dev/null
 +++ b/vma.c
-@@ -0,0 +1,878 @@
+@@ -0,0 +1,904 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -1772,7 +1772,7 @@ index 0000000000..304f02bc84
 +        "vma list <filename>\n"
 +        "vma config <filename> [-c config]\n"
 +        "vma create <filename> [-c config] pathname ...\n"
-+        "vma extract <filename> [-r <fifo>] <targetdir>\n"
++        "vma extract <filename> [-f <filter>] [-r <fifo>] <targetdir>\n"
 +        "vma verify <filename> [-v]\n"
 +        ;
 +
@@ -1917,9 +1917,10 @@ index 0000000000..304f02bc84
 +    const char *filename;
 +    const char *dirname;
 +    const char *readmap = NULL;
++    const char *filter = NULL;
 +
 +    for (;;) {
-+        c = getopt(argc, argv, "hvr:");
++        c = getopt(argc, argv, "hvf:r:");
 +        if (c == -1) {
 +            break;
 +        }
@@ -1928,6 +1929,9 @@ index 0000000000..304f02bc84
 +        case 'h':
 +            help();
 +            break;
++        case 'f':
++            filter = optarg;
++            break;
 +        case 'r':
 +            readmap = optarg;
 +            break;
@@ -2064,12 +2068,12 @@ index 0000000000..304f02bc84
 +
 +    int i;
 +    int vmstate_fd = -1;
-+    guint8 vmstate_stream = 0;
++    bool filter_bitmap[256];
++    memset(filter_bitmap, 0, sizeof(filter_bitmap));
 +
 +    for (i = 1; i < 255; i++) {
 +        VmaDeviceInfo *di = vma_reader_get_device_info(vmar, i);
 +        if (di && (strcmp(di->devname, "vmstate") == 0)) {
-+            vmstate_stream = i;
 +            char *statefn = g_strdup_printf("%s/vmstate.bin", dirname);
 +            vmstate_fd = open(statefn, O_WRONLY|O_CREAT|O_EXCL, 0644);
 +            if (vmstate_fd < 0) {
@@ -2089,7 +2093,29 @@ index 0000000000..304f02bc84
 +
 +            BlockBackend *blk = NULL;
 +
-+            if (readmap) {
++            if (filter) {
++                const char *token = filter;
++                while (*token) {
++                    const char *comma = strchr(token, ',');
++                    if (comma == NULL) {
++                        comma = token + strlen(token);
++                    }
++
++                    if (strncmp(token, di->devname, comma - token) == 0) {
++                        skip = true;
++                        filter_bitmap[i] = true;
++                        break;
++                    }
++
++                    if (*comma == '\0') {
++                        break;
++                    }
++
++                    token = comma + 1;
++                }
++            }
++
++            if (!skip && readmap) {
 +                RestoreMap *map;
 +                map = (RestoreMap *)g_hash_table_lookup(devmap, di->devname);
 +                if (map == NULL) {
@@ -2102,7 +2128,7 @@ index 0000000000..304f02bc84
 +                cache = map->cache;
 +                write_zero = map->write_zero;
 +                skip = map->skip;
-+            } else {
++            } else if (!skip) {
 +                devfn = g_strdup_printf("%s/tmp-disk-%s.raw",
 +                                        dirname, di->devname);
 +                printf("DEVINFO %s %zd\n", devfn, di->size);
@@ -2190,7 +2216,7 @@ index 0000000000..304f02bc84
 +    if (!readmap) {
 +        for (i = 1; i < 255; i++) {
 +            VmaDeviceInfo *di = vma_reader_get_device_info(vmar, i);
-+            if (di && (i != vmstate_stream)) {
++            if (di && filter_bitmap[i]) {
 +                char *tmpfn = g_strdup_printf("%s/tmp-disk-%s.raw",
 +                                              dirname, di->devname);
 +                char *fn = g_strdup_printf("%s/disk-%s.raw",
-- 
2.39.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH v2 qemu] fix #1534: vma: Add extract filter for disk images
  2023-08-08 12:00 [pve-devel] [PATCH v2 qemu] fix #1534: vma: Add extract filter for disk images Filip Schauer
@ 2023-08-09 11:06 ` Fiona Ebner
  0 siblings, 0 replies; 2+ messages in thread
From: Fiona Ebner @ 2023-08-09 11:06 UTC (permalink / raw)
  To: Proxmox VE development discussion, Filip Schauer

Am 08.08.23 um 14:00 schrieb Filip Schauer:
> @@ -1772,7 +1772,7 @@ index 0000000000..304f02bc84
>  +        "vma list <filename>\n"
>  +        "vma config <filename> [-c config]\n"
>  +        "vma create <filename> [-c config] pathname ...\n"
> -+        "vma extract <filename> [-r <fifo>] <targetdir>\n"
> ++        "vma extract <filename> [-f <filter>] [-r <fifo>] <targetdir>\n"

Not sure about calling it "filter" now, I feel like "drive-list" or
similar would be more obvious to a user, except...

>  +        "vma verify <filename> [-v]\n"
>  +        ;
>  +

(...)

> ++
> ++                    if (strncmp(token, di->devname, comma - token) == 0) {

...you actually make it a list of prefixes that should match, not a list
of drive names by using "comma - token" ;) E.g. -f "drive" will match
all those that start with "drive" and the empty one will match all.

> ++                        skip = true;

This is the wrong way around: skip should be true iff none of the given
file names match.

> ++                        filter_bitmap[i] = true;

This is fine, it should indicate what is included.

You only set the filter bitmap if a filter option is given...

(...)

> @@ -2190,7 +2216,7 @@ index 0000000000..304f02bc84
>  +    if (!readmap) {
>  +        for (i = 1; i < 255; i++) {
>  +            VmaDeviceInfo *di = vma_reader_get_device_info(vmar, i);
> -+            if (di && (i != vmstate_stream)) {
> ++            if (di && filter_bitmap[i]) {

...so the renaming will not happen anymore when extracting everything,
without a filter.

Maybe it's better called rename_bitmap or rename_required, because that
is the only use.

>  +                char *tmpfn = g_strdup_printf("%s/tmp-disk-%s.raw",
>  +                                              dirname, di->devname);
>  +                char *fn = g_strdup_printf("%s/disk-%s.raw",




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-09 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-08 12:00 [pve-devel] [PATCH v2 qemu] fix #1534: vma: Add extract filter for disk images Filip Schauer
2023-08-09 11:06 ` Fiona Ebner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal