Skip to contentSkip to conversation

xl block-attach refactoring to reuse xl parsing code

PATCH In review Kamala Narasimhan 2 participants 2 messages Feb 7, 2011 – Feb 8, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 xl block-attach refactoring to reuse xl parsing code

Attached changes reuse disk parsing code for block-attach.

Kamala

xl_cmdimpl.c +10 -36
diff -r -u libxl-parsing-changes/xl_cmdimpl.c libxl/xl_cmdimpl.c
@@ -4408,8 +4408,7 @@
 
 int main_blockattach(int argc, char **argv)
 {
-    int opt;
-    const char *tok;
+    int opt, ret_val;
     uint32_t fe_domid, be_domid = 0;
     libxl_device_disk disk = { 0 };
 
@@ -4428,40 +4427,15 @@
         return 0;
     }
 
-    tok = strtok(argv[optind+1], ":");
-    if (!strcmp(tok, "phy")) {
-        disk.backend = DISK_BACKEND_BLKBACK;
-    } else if (!strcmp(tok, "file")) {
-        disk.backend = DISK_BACKEND_TAPDISK2;
-    } else if (!strcmp(tok, "tap")) {
-        tok = strtok(NULL, ":");
-        if (!strcmp(tok, "aio")) {
-            disk.backend = DISK_BACKEND_TAPDISK2;
-        } else if (!strcmp(tok, "vhd")) {
-            disk.format = DISK_FORMAT_VHD;
-            disk.backend = DISK_BACKEND_TAPDISK2;
-        } else if (!strcmp(tok, "qcow")) {
-            disk.format = DISK_FORMAT_QCOW;
-            disk.backend = DISK_BACKEND_QEMU;
-        } else if (!strcmp(tok, "qcow2")) {
-            disk.format = DISK_FORMAT_QCOW2;
-            disk.backend = DISK_BACKEND_QEMU;
-        } else {
-            fprintf(stderr, "Error: `%s' is not a valid disk image.\n", tok);
-            return 1;
-        }
-    } else {
-        fprintf(stderr, "Error: `%s' is not a valid block device.\n", tok);
-        return 1;
-    }
-    disk.pdev_path = strtok(NULL, "\0");
-    if (!disk.pdev_path) {
-        fprintf(stderr, "Error: missing path to disk image.\n");
-        return 1;
-    }
-    disk.vdev = argv[optind+2];
-    disk.unpluggable = 1;
-    disk.readwrite = ((argc-optind <= 3) || (argv[optind+3][0] == 'w'));
+    ret_val = parse_disk_pdev_info(&disk, argv[optind+1]);
+    if ( ret_val )
+        return ret_val; 
+    ret_val = parse_disk_vdev_info(&disk, argv[optind+2]); 
+    if ( ret_val )
+        return ret_val; 
+    ret_val = parse_disk_attrib(&disk, argv[optind+3]);
+    if ( ret_val ) 
+        return ret_val;
 
     if (domain_qualifier_to_domid(argv[optind], &fe_domid, 0) < 0) {
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 6 lines · Kamala Narasimhan

Attached changes reuse disk parsing code for block-attach.

Kamala

patch 3 and 4 are generated against tools/libxl instead of the root of xen-unstable.
Even though they are not difficult to apply anyway, it would be better to send diff against the root directory.