[PATCH] Fix pathological behaviour of "virsh help" (was: Re: RFC: replace "no support for hypervisor" error)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Veillard wrote:
    - if our default behaviour was a bit less pathological

   virsh: error: failed to connect to the hypervisor
   paphio:~/libvirt -> virsh help
   libvir: error : operation failed: xenProxyOpen
   virsh: error: failed to connect to the hypervisor

This patch fixes the pathological failure of 'virsh help command'.

(1) We allow ctl->conn to be NULL, meaning "no connection".

(2) All cmd* functions check vshConnectionUsability where required (I checked this) except the ones which don't need to such as cmdHelp.

(3) vshInit has changed so that not being able to connect to a hypervisor is a non-fatal condition. Thus after vshInit, ctl->conn may be NULL.

(4) I reordered the list of commands alphabetically, except that "help" is listed first.

$ virsh help save
libvir: error : operation failed: xenProxyOpen
error: failed to connect to the hypervisor
  NAME
    save - save a domain state to a file

  SYNOPSIS
    save <domain> <file>

  DESCRIPTION
    Save a running domain.

  OPTIONS
    <domain>         domain name, id or uuid
    <file>           where to save the data


Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.87
diff -u -r1.87 virsh.c
--- src/virsh.c	19 Jun 2007 09:32:04 -0000	1.87
+++ src/virsh.c	20 Jun 2007 11:21:47 -0000
@@ -195,7 +195,7 @@
  */
 typedef struct __vshControl {
     char *name;                 /* connection name */
-    virConnectPtr conn;         /* connection to hypervisor */
+    virConnectPtr conn;         /* connection to hypervisor (MAY BE NULL) */
     vshCmd *cmd;                /* the current command */
     char *cmdstr;               /* string with command */
     uid_t uid;                  /* process owner */
@@ -3309,6 +3309,10 @@
  * Commands
  */
 static vshCmdDef commands[] = {
+    {"help", cmdHelp, opts_help, info_help},
+    {"attach-device", cmdAttachDevice, opts_attach_device, info_attach_device},
+    {"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk},
+    {"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
     {"autostart", cmdAutostart, opts_autostart, info_autostart},
     {"capabilities", cmdCapabilities, NULL, info_capabilities},
     {"connect", cmdConnect, opts_connect, info_connect},
@@ -3316,6 +3320,9 @@
     {"create", cmdCreate, opts_create, info_create},
     {"start", cmdStart, opts_start, info_start},
     {"destroy", cmdDestroy, opts_destroy, info_destroy},
+    {"detach-device", cmdDetachDevice, opts_detach_device, info_detach_device},
+    {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk},
+    {"detach-interface", cmdDetachInterface, opts_detach_interface, info_detach_interface},
     {"define", cmdDefine, opts_define, info_define},
     {"domid", cmdDomid, opts_domid, info_domid},
     {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid},
@@ -3323,7 +3330,6 @@
     {"domname", cmdDomname, opts_domname, info_domname},
     {"domstate", cmdDomstate, opts_domstate, info_domstate},
     {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml},
-    {"help", cmdHelp, opts_help, info_help},
     {"list", cmdList, opts_list, info_list},
     {"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart},
     {"net-create", cmdNetworkCreate, opts_network_create, info_network_create},
@@ -3353,12 +3359,6 @@
     {"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin},
     {"version", cmdVersion, NULL, info_version},
     {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay},
-    {"attach-device", cmdAttachDevice, opts_attach_device, info_attach_device},
-    {"detach-device", cmdDetachDevice, opts_detach_device, info_detach_device},
-    {"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
-    {"detach-interface", cmdDetachInterface, opts_detach_interface, info_detach_interface},
-    {"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk},
-    {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk},
     {NULL, NULL, NULL, NULL}
 };
 
@@ -4099,7 +4099,7 @@
 }
 
 /*
- * Initialize vistsh
+ * Initialize connection.
  */
 static int
 vshInit(vshControl * ctl)
@@ -4124,8 +4124,12 @@
     else
         ctl->conn = virConnectOpenReadOnly(ctl->name);
 
+    /* This is not necessarily fatal.  All the individual commands check
+     * vshConnectionUsability, except ones which don't need a connection
+     * such as "help".
+     */
     if (!ctl->conn)
-        vshError(ctl, TRUE, _("failed to connect to the hypervisor"));
+        vshError(ctl, FALSE, _("failed to connect to the hypervisor"));
 
     return TRUE;
 }

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]