--- libvirt.orig/src/virsh.c	2007-07-26 17:41:16.000000000 +0900
+++ libvirt.detach/src/virsh.c	2007-07-31 15:04:46.000000000 +0900
@@ -2846,7 +2846,13 @@ cmdAttachDevice(vshControl * ctl, vshCmd
     free (buffer);
 
     if (ret < 0) {
-        vshError(ctl, FALSE, _("Failed to attach device from %s"), from);
+        if (ret == -2)
+        {
+            vshError(ctl, FALSE, 
+                   _("Not supported config file format. Use XML."));
+        } else {
+            vshError(ctl, FALSE, _("Failed to attach device from %s"), from);
+        }
         virDomainFree(dom);
         return FALSE;
     }
@@ -2900,7 +2906,13 @@ cmdDetachDevice(vshControl * ctl, vshCmd
     free (buffer);
 
     if (ret < 0) {
-        vshError(ctl, FALSE, _("Failed to detach device from %s"), from);
+        if (ret == -2)
+        {
+            vshError(ctl, FALSE, 
+                   _("Not supported config file format. Use XML."));
+        } else {
+            vshError(ctl, FALSE, _("Failed to detach device from %s"), from);
+        }
         virDomainFree(dom);
         return FALSE;
     }
--- libvirt.orig/src/xen_unified.c	2007-07-12 17:34:51.000000000 +0900
+++ libvirt.detach/src/xen_unified.c	2007-07-31 15:12:30.000000000 +0900
@@ -872,28 +872,28 @@ static int
 xenUnifiedDomainAttachDevice (virDomainPtr dom, char *xml)
 {
     GET_PRIVATE(dom->conn);
-    int i;
+    int i, ret;
 
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] && drivers[i]->domainAttachDevice &&
-            drivers[i]->domainAttachDevice (dom, xml) == 0)
+            (ret = drivers[i]->domainAttachDevice (dom, xml)) == 0)
             return 0;
 
-    return -1;
+    return ret;
 }
 
 static int
 xenUnifiedDomainDetachDevice (virDomainPtr dom, char *xml)
 {
     GET_PRIVATE(dom->conn);
-    int i;
+    int i, ret;
 
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] && drivers[i]->domainDetachDevice &&
-            drivers[i]->domainDetachDevice (dom, xml) == 0)
+            (ret = drivers[i]->domainDetachDevice (dom, xml)) == 0)
             return 0;
 
-    return -1;
+    return ret;
 }
 
 static char *
--- libvirt.orig/src/xend_internal.c	2007-07-31 14:33:15.000000000 +0900
+++ libvirt.detach/src/xend_internal.c	2007-07-31 14:33:58.000000000 +0900
@@ -3114,7 +3114,7 @@ xenDaemonAttachDevice(virDomainPtr domai
         free(str);
     sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
     if (sexpr == NULL)
-        return (-1);
+        return (-2);
     if (!memcmp(sexpr, "(device ", 8)) {
         conf = sexpr + 8;
         *(conf + strlen(conf) -1) = 0; /* suppress final ) */
@@ -3146,7 +3146,7 @@ xenDaemonDetachDevice(virDomainPtr domai
         return (-1);
     }
     if (virDomainXMLDevID(domain, xml, class, ref))
-        return (-1);
+        return (-2);
     return(xend_op(domain->conn, domain->name, "op", "device_destroy",
         "type", class, "dev", ref, NULL));
 }
