]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: A bit smarter attach-disk
authorOsier Yang <jyang@redhat.com>
Thu, 15 Mar 2012 10:16:52 +0000 (18:16 +0800)
committerOsier Yang <jyang@redhat.com>
Thu, 15 Mar 2012 10:16:52 +0000 (18:16 +0800)
Detects the file type of source path if no "--sourcetype" and
"driver" is specified, instead of always set the disk type as
"block".

tools/virsh.c

index d45a4c917e27f10956bd0b914d0d555c5a10e10b..19f9bbe3939ba9bf9b464d4a49b288c256e99135 100644 (file)
@@ -14428,6 +14428,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     const char *stype = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *xml;
+    struct stat st;
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;
@@ -14458,8 +14459,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (!stype) {
-        if (driver && (STREQ(driver, "file") || STREQ(driver, "tap")))
+        if (driver && (STREQ(driver, "file") || STREQ(driver, "tap"))) {
             isFile = true;
+        } else {
+            if (source && !stat(source, &st))
+                isFile = S_ISREG(st.st_mode) ? true : false;
+        }
     } else if (STREQ(stype, "file")) {
         isFile = true;
     } else if (STRNEQ(stype, "block")) {