public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v4 qemu] fix #1534: vma: Add extract filter for disk images
@ 2023-08-09 14:08 Filip Schauer
  2023-08-29 12:10 ` Fiona Ebner
  0 siblings, 1 reply; 3+ messages in thread
From: Filip Schauer @ 2023-08-09 14:08 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 "-d" option.

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

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

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
Changes since v3:
* Fix option "-d" not being recognized correctly (case 'f' --> case 'd')

 ...VE-Backup-add-vma-backup-format-code.patch | 47 +++++++++++++++----
 1 file changed, 39 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..312727d 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,909 @@
 +/*
 + * 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> [-d <drive-list>] [-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 *drive_list = NULL;
 +
 +    for (;;) {
-+        c = getopt(argc, argv, "hvr:");
++        c = getopt(argc, argv, "hvd:r:");
 +        if (c == -1) {
 +            break;
 +        }
@@ -1928,6 +1929,9 @@ index 0000000000..304f02bc84
 +        case 'h':
 +            help();
 +            break;
++        case 'd':
++            drive_list = 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 drive_rename_bitmap[255];
++    memset(drive_rename_bitmap, 0, sizeof(drive_rename_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,34 @@ index 0000000000..304f02bc84
 +
 +            BlockBackend *blk = NULL;
 +
-+            if (readmap) {
++            if (drive_list) {
++                skip = true;
++                size_t devname_len = strlen(di->devname);
++                const char *token = drive_list;
++                while (*token) {
++                    const char *comma = strchr(token, ',');
++                    if (comma == NULL) {
++                        comma = token + strlen(token);
++                    }
++
++                    size_t token_len = comma - token;
++                    if (token_len == devname_len && strncmp(token, di->devname, token_len) == 0) {
++                        skip = false;
++                        drive_rename_bitmap[i] = true;
++                        break;
++                    }
++
++                    if (*comma == '\0') {
++                        break;
++                    }
++
++                    token = comma + 1;
++                }
++            } else {
++                drive_rename_bitmap[i] = true;
++            }
++
++            if (!skip && readmap) {
 +                RestoreMap *map;
 +                map = (RestoreMap *)g_hash_table_lookup(devmap, di->devname);
 +                if (map == NULL) {
@@ -2102,7 +2133,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 +2221,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 && drive_rename_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] 3+ messages in thread

* Re: [pve-devel] [PATCH v4 qemu] fix #1534: vma: Add extract filter for disk images
  2023-08-09 14:08 [pve-devel] [PATCH v4 qemu] fix #1534: vma: Add extract filter for disk images Filip Schauer
@ 2023-08-29 12:10 ` Fiona Ebner
  2023-08-30  7:16   ` Fiona Ebner
  0 siblings, 1 reply; 3+ messages in thread
From: Fiona Ebner @ 2023-08-29 12:10 UTC (permalink / raw)
  To: Proxmox VE development discussion, Filip Schauer

Am 09.08.23 um 16:08 schrieb Filip Schauer:
> 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..312727d 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

Needs a rebase, because the index changed. I would've fixed it up while
applying, but I got two more suggestions:

> @@ -1928,6 +1929,9 @@ index 0000000000..304f02bc84
>  +        case 'h':
>  +            help();
>  +            break;
> ++        case 'd':
> ++            drive_list = optarg;

I think we can use g_strsplit() here already to split the string and
then just iterate over the result below, rather than splitting manually
for each iteration. Note that you need to free the result at the very
end as mentioned in the docs:

https://docs.gtk.org/glib/func.strsplit.html

> ++            break;
>  +        case 'r':
>  +            readmap = optarg;
>  +            break;

(...)

> @@ -2089,7 +2093,34 @@ index 0000000000..304f02bc84
>  +
>  +            BlockBackend *blk = NULL;
>  +
> -+            if (readmap) {
> ++            if (drive_list) {
> ++                skip = true;
> ++                size_t devname_len = strlen(di->devname);
> ++                const char *token = drive_list;
> ++                while (*token) {
> ++                    const char *comma = strchr(token, ',');
> ++                    if (comma == NULL) {
> ++                        comma = token + strlen(token);
> ++                    }
> ++
> ++                    size_t token_len = comma - token;
> ++                    if (token_len == devname_len && strncmp(token, di->devname, token_len) == 0) {

Passing devname_len to strncmp would avoid the token_len variable.




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

* Re: [pve-devel] [PATCH v4 qemu] fix #1534: vma: Add extract filter for disk images
  2023-08-29 12:10 ` Fiona Ebner
@ 2023-08-30  7:16   ` Fiona Ebner
  0 siblings, 0 replies; 3+ messages in thread
From: Fiona Ebner @ 2023-08-30  7:16 UTC (permalink / raw)
  To: Proxmox VE development discussion, Filip Schauer

Am 29.08.23 um 14:10 schrieb Fiona Ebner:
> Am 09.08.23 um 16:08 schrieb Filip Schauer:
>> ++                    size_t token_len = comma - token;
>> ++                    if (token_len == devname_len && strncmp(token, di->devname, token_len) == 0) {
> 
> Passing devname_len to strncmp would avoid the token_len variable.
> 

Would need to be devname_len + 1, but since we want to compare the whole
string, especially once we got the null-terminated split tokens, we can
also just use strcmp().




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

end of thread, other threads:[~2023-08-30  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-09 14:08 [pve-devel] [PATCH v4 qemu] fix #1534: vma: Add extract filter for disk images Filip Schauer
2023-08-29 12:10 ` Fiona Ebner
2023-08-30  7:16   ` Fiona Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal