[libvirt] [PATCH v2] virsh: A bit smarter attach-disk

Osier Yang jyang at redhat.com
Thu Mar 15 10:17:47 UTC 2012


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 |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index d45a4c9..19f9bbe 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -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")) {
-- 
1.7.1




More information about the libvir-list mailing list