]> xenbits.xensource.com Git - xen.git/commitdiff
xl: Implement block-attach command
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 13 May 2010 07:50:54 +0000 (08:50 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 13 May 2010 07:50:54 +0000 (08:50 +0100)
Signed-off-by: Eric Chanudet <eric.chanudet@citrix.com>
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.h
tools/libxl/xl_cmdtable.c

index 334eff65d5b9d85b1657df9c7bdd7fcb8da1c1eb..5ef8d5e17259ab0c70be31f1aba146ccc079ab93 100644 (file)
@@ -3344,3 +3344,75 @@ int main_networkdetach(int argc, char **argv)
     }
     exit(0);
 }
+
+int main_blockattach(int argc, char **argv)
+{
+    int opt;
+    char *tok;
+    uint32_t fe_domid, be_domid = 0;
+    libxl_device_disk disk = { 0 };
+
+    if ((argc < 3) || (argc > 6)) {
+        help("block-attach");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("block-attach");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    tok = strtok(argv[2], ":");
+    if (!strcmp(tok, "phy")) {
+        disk.phystype = PHYSTYPE_PHY;
+    } else if (!strcmp(tok, "file")) {
+        disk.phystype = PHYSTYPE_FILE;
+    } else if (!strcmp(tok, "tap")) {
+        tok = strtok(NULL, ":");
+        if (!strcmp(tok, "aio")) {
+            disk.phystype = PHYSTYPE_AIO;
+        } else if (!strcmp(tok, "vhd")) {
+            disk.phystype = PHYSTYPE_VHD;
+        } else if (!strcmp(tok, "qcow")) {
+            disk.phystype = PHYSTYPE_QCOW;
+        } else if (!strcmp(tok, "qcow2")) {
+            disk.phystype = PHYSTYPE_QCOW2;
+        } else {
+            fprintf(stderr, "Error: `%s' is not a valid disk image.\n", tok);
+            exit(1);
+        }
+    } else {
+        fprintf(stderr, "Error: `%s' is not a valid block device.\n", tok);
+        exit(1);
+    }
+    disk.physpath = strtok(NULL, "\0");
+    if (!disk.physpath) {
+        fprintf(stderr, "Error: missing path to disk image.\n");
+        exit(1);
+    }
+    disk.virtpath = argv[3];
+    disk.unpluggable = 1;
+    disk.readwrite = (argv[4][0] == 'w') ? 1 : 0;
+
+    if (domain_qualifier_to_domid(argv[1], &fe_domid, 0) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]);
+        exit(1);
+    }
+    if (argc == 6) {
+        if (domain_qualifier_to_domid(argv[5], &be_domid, 0) < 0) {
+            fprintf(stderr, "%s is an invalid domain identifier\n", argv[5]);
+            exit(1);
+        }
+    }
+    disk.domid = fe_domid;
+    disk.backend_domid = be_domid;
+    if (libxl_device_disk_add(&ctx, fe_domid, &disk)) {
+        fprintf(stderr, "libxl_device_disk_add failed.\n");
+    }
+    exit(0);
+}
index 5cc2d7ab4488e1cd0bc709c56d9cc4dc37afacca..2f49e611120c4a4126b5b684c0ef4cfd354111a4 100644 (file)
@@ -45,5 +45,6 @@ int main_top(int argc, char **argv);
 int main_networkattach(int argc, char **argv);
 int main_networklist(int argc, char **argv);
 int main_networkdetach(int argc, char **argv);
+int main_blockattach(int argc, char **argv);
 
 void help(char *command);
index 9eaaeb46516f12f31b50abe8df21c0b3d7514ca8..99ceaf2b5b42cef34388f701f93ec3ac55035441 100644 (file)
@@ -204,6 +204,11 @@ struct cmd_spec cmd_table[] = {
       "Destroy a domain's virtual network device",
       "<Domain> <DevId|mac>",
     },
+    { "block-attach",
+      &main_blockattach,
+      "Create a new virtual block device",
+      "<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);