From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v5 qemu] fix #1534: vma: Add extract filter for disk images
Date: Wed, 30 Aug 2023 10:33:47 +0200 [thread overview]
Message-ID: <20230830083347.38259-1-f.schauer@proxmox.com> (raw)
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 v4:
* Use g_strsplit at the beginning to split the drive list instead of
splitting it manually on every iteration
* Update diff index
...VE-Backup-add-vma-backup-format-code.patch | 40 ++++++++++++++-----
1 file changed, 31 insertions(+), 9 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..4525eae 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
@@ -1735,10 +1735,10 @@ index 0000000000..ac7da237d0
+}
diff --git a/vma.c b/vma.c
new file mode 100644
-index 0000000000..304f02bc84
+index 0000000000..1604d955d8
--- /dev/null
+++ b/vma.c
-@@ -0,0 +1,878 @@
+@@ -0,0 +1,900 @@
+/*
+ * 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 gchar **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 = g_strsplit(optarg, ",", 254);
++ 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,21 @@ index 0000000000..304f02bc84
+
+ BlockBackend *blk = NULL;
+
-+ if (readmap) {
++ if (drive_list) {
++ skip = true;
++ int j;
++ for (j = 0; drive_list[j]; j++) {
++ if (strcmp(drive_list[j], di->devname) == 0) {
++ skip = false;
++ drive_rename_bitmap[i] = true;
++ break;
++ }
++ }
++ } 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 +2120,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);
@@ -2183,6 +2201,10 @@ index 0000000000..304f02bc84
+ }
+ }
+
++ if (drive_list) {
++ g_strfreev(drive_list);
++ }
++
+ if (vma_reader_restore(vmar, vmstate_fd, verbose, &errp) < 0) {
+ g_error("restore failed - %s", error_get_pretty(errp));
+ }
@@ -2190,7 +2212,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
next reply other threads:[~2023-08-30 8:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 8:33 Filip Schauer [this message]
2023-08-30 9:06 ` [pve-devel] applied: " Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230830083347.38259-1-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.