virsh: optimize creation of default connection

Ramon de Carvalho Valle reported a problem with:
virsh connect qemu:///system
as a non-root user.  The real root problem appears to be a regression
in libvirtd being auto-started on the default qemu:///session URI;
however, the symptom points to an independent flaw in virsh - we
shouldn't be wasting efforts on making a connection if we aren't going
to be using that connection.  Fixing virsh avoids Ramon's issue, while
I work in the meantime to fix the real libvirtd regression.

This patch looks big, but that's because 'gcc -Wmissing-field-initializers'
gets triggered by './autobuild.sh --enable-compile-warnings=error', so I
had to add 0 initialization to everyone (rather than my preference of
just adding the non-zero flags to virshCmds and to cmdConnect).

Meanwhile, if you use 'virsh -c URI', the connection must succeed; this
patch _only_ optimizes the default connection to be deferred to a later
point where we know if a particular command to be run needs a connection.

* tools/virsh.c (VSH_CMD_FLAG_NOCONNECT): New flag.
(vshCmdDef): Add new flags field.
(vshCommandRun): Honor new flag.
(domManagementCmds, domMonitoringCmds, storagePoolCmds)
(storageVolCmds, networkCmds, nodedevCmds, ifaceCmds)
(nwfilterCmds, secretCmds, virshCmds, snapshotCmds)
(hostAndHypervisorCmds): Populate new field.
(vshReconnect): Don't warn on initial connection.
This commit is contained in:
Eric Blake 2011-03-14 14:30:24 -06:00
parent 4d2a189646
commit d218344e6c
1 changed files with 250 additions and 179 deletions

View File

@ -185,6 +185,13 @@ typedef struct vshCmdOpt {
struct vshCmdOpt *next; struct vshCmdOpt *next;
} vshCmdOpt; } vshCmdOpt;
/*
* Command Usage Flags
*/
enum {
VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */
};
/* /*
* vshCmdDef - command definition * vshCmdDef - command definition
*/ */
@ -193,6 +200,7 @@ typedef struct {
bool (*handler) (vshControl *, const vshCmd *); /* command handler */ bool (*handler) (vshControl *, const vshCmd *); /* command handler */
const vshCmdOptDef *opts; /* definition of command options */ const vshCmdOptDef *opts; /* definition of command options */
const vshCmdInfo *info; /* details about command */ const vshCmdInfo *info; /* details about command */
int flags; /* bitwise OR of VSH_CMD_FLAG */
} vshCmdDef; } vshCmdDef;
/* /*
@ -563,16 +571,21 @@ vshSetupSignals(void) {
* *
*/ */
static void static void
vshReconnect(vshControl *ctl) { vshReconnect(vshControl *ctl)
if (ctl->conn != NULL) {
bool connected = false;
if (ctl->conn != NULL) {
connected = true;
virConnectClose(ctl->conn); virConnectClose(ctl->conn);
}
ctl->conn = virConnectOpenAuth(ctl->name, ctl->conn = virConnectOpenAuth(ctl->name,
virConnectAuthPtrDefault, virConnectAuthPtrDefault,
ctl->readonly ? VIR_CONNECT_RO : 0); ctl->readonly ? VIR_CONNECT_RO : 0);
if (!ctl->conn) if (!ctl->conn)
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor")); vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
else else if (connected)
vshError(ctl, "%s", _("Reconnected to the hypervisor")); vshError(ctl, "%s", _("Reconnected to the hypervisor"));
disconnected = 0; disconnected = 0;
ctl->useGetInfo = false; ctl->useGetInfo = false;
@ -9966,7 +9979,7 @@ static const vshCmdOptDef opts_cd[] = {
}; };
static bool static bool
cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdCd(vshControl *ctl, const vshCmd *cmd)
{ {
const char *dir = NULL; const char *dir = NULL;
char *dir_malloced = NULL; char *dir_malloced = NULL;
@ -10737,205 +10750,259 @@ cleanup:
} }
static const vshCmdDef domManagementCmds[] = { static const vshCmdDef domManagementCmds[] = {
{"attach-device", cmdAttachDevice, opts_attach_device, info_attach_device}, {"attach-device", cmdAttachDevice, opts_attach_device,
{"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk}, info_attach_device, 0},
{"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface}, {"attach-disk", cmdAttachDisk, opts_attach_disk,
{"autostart", cmdAutostart, opts_autostart, info_autostart}, info_attach_disk, 0},
{"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune}, {"attach-interface", cmdAttachInterface, opts_attach_interface,
info_attach_interface, 0},
{"autostart", cmdAutostart, opts_autostart, info_autostart, 0},
{"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune, 0},
#ifndef WIN32 #ifndef WIN32
{"console", cmdConsole, opts_console, info_console}, {"console", cmdConsole, opts_console, info_console, 0},
#endif #endif
{"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline}, {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline, 0},
{"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare}, {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare, 0},
{"create", cmdCreate, opts_create, info_create}, {"create", cmdCreate, opts_create, info_create, 0},
{"define", cmdDefine, opts_define, info_define}, {"define", cmdDefine, opts_define, info_define, 0},
{"destroy", cmdDestroy, opts_destroy, info_destroy}, {"destroy", cmdDestroy, opts_destroy, info_destroy, 0},
{"detach-device", cmdDetachDevice, opts_detach_device, info_detach_device}, {"detach-device", cmdDetachDevice, opts_detach_device,
{"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk}, info_detach_device, 0},
{"detach-interface", cmdDetachInterface, opts_detach_interface, info_detach_interface}, {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk, 0},
{"domid", cmdDomid, opts_domid, info_domid}, {"detach-interface", cmdDetachInterface, opts_detach_interface,
{"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort}, info_detach_interface, 0},
{"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo}, {"domid", cmdDomid, opts_domid, info_domid, 0},
{"domname", cmdDomname, opts_domname, info_domname}, {"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort, 0},
{"domuuid", cmdDomuuid, opts_domuuid, info_domuuid}, {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0},
{"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative, info_domxmlfromnative}, {"domname", cmdDomname, opts_domname, info_domname, 0},
{"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative, info_domxmltonative}, {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0},
{"dump", cmdDump, opts_dump, info_dump}, {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative,
{"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml}, info_domxmlfromnative, 0},
{"edit", cmdEdit, opts_edit, info_edit}, {"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative,
{"managedsave", cmdManagedSave, opts_managedsave, info_managedsave}, info_domxmltonative, 0},
{"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove, info_managedsaveremove}, {"dump", cmdDump, opts_dump, info_dump, 0},
{"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus}, {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml, 0},
{"memtune", cmdMemtune, opts_memtune, info_memtune}, {"edit", cmdEdit, opts_edit, info_edit, 0},
{"migrate", cmdMigrate, opts_migrate, info_migrate}, {"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi, 0},
{"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime, opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime}, {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave, 0},
{"reboot", cmdReboot, opts_reboot, info_reboot}, {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove,
{"restore", cmdRestore, opts_restore, info_restore}, info_managedsaveremove, 0},
{"resume", cmdResume, opts_resume, info_resume}, {"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus, 0},
{"save", cmdSave, opts_save, info_save}, {"memtune", cmdMemtune, opts_memtune, info_memtune, 0},
{"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo}, {"migrate", cmdMigrate, opts_migrate, info_migrate, 0},
{"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem}, {"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime,
{"setmem", cmdSetmem, opts_setmem, info_setmem}, opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime, 0},
{"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus}, {"reboot", cmdReboot, opts_reboot, info_reboot, 0},
{"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi}, {"restore", cmdRestore, opts_restore, info_restore, 0},
{"shutdown", cmdShutdown, opts_shutdown, info_shutdown}, {"resume", cmdResume, opts_resume, info_resume, 0},
{"start", cmdStart, opts_start, info_start}, {"save", cmdSave, opts_save, info_save, 0},
{"suspend", cmdSuspend, opts_suspend, info_suspend}, {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo, 0},
{"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole}, {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem, 0},
{"undefine", cmdUndefine, opts_undefine, info_undefine}, {"setmem", cmdSetmem, opts_setmem, info_setmem, 0},
{"update-device", cmdUpdateDevice, opts_update_device, info_update_device}, {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus, 0},
{"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount}, {"shutdown", cmdShutdown, opts_shutdown, info_shutdown, 0},
{"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo}, {"start", cmdStart, opts_start, info_start, 0},
{"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin}, {"suspend", cmdSuspend, opts_suspend, info_suspend, 0},
{"version", cmdVersion, NULL, info_version}, {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole, 0},
{"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay}, {"undefine", cmdUndefine, opts_undefine, info_undefine, 0},
{NULL, NULL, NULL, NULL} {"update-device", cmdUpdateDevice, opts_update_device,
info_update_device, 0},
{"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount, 0},
{"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo, 0},
{"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin, 0},
{"version", cmdVersion, NULL, info_version, 0},
{"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef domMonitoringCmds[] = { static const vshCmdDef domMonitoringCmds[] = {
{"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo}, {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
{"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat}, {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
{"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat}, {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
{"dominfo", cmdDominfo, opts_dominfo, info_dominfo}, {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
{"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat}, {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0},
{"domstate", cmdDomstate, opts_domstate, info_domstate}, {"domstate", cmdDomstate, opts_domstate, info_domstate, 0},
{"list", cmdList, opts_list, info_list}, {"list", cmdList, opts_list, info_list, 0},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef storagePoolCmds[] = { static const vshCmdDef storagePoolCmds[] = {
{"find-storage-pool-sources-as", cmdPoolDiscoverSourcesAs, {"find-storage-pool-sources-as", cmdPoolDiscoverSourcesAs,
opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as}, opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as, 0},
{"find-storage-pool-sources", cmdPoolDiscoverSources, {"find-storage-pool-sources", cmdPoolDiscoverSources,
opts_find_storage_pool_sources, info_find_storage_pool_sources}, opts_find_storage_pool_sources, info_find_storage_pool_sources, 0},
{"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart}, {"pool-autostart", cmdPoolAutostart, opts_pool_autostart,
{"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build}, info_pool_autostart, 0},
{"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as}, {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build, 0},
{"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create}, {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as, 0},
{"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as}, {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create, 0},
{"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define}, {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as, 0},
{"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete}, {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define, 0},
{"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy}, {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete, 0},
{"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml}, {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy, 0},
{"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit}, {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml, 0},
{"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info}, {"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit, 0},
{"pool-list", cmdPoolList, opts_pool_list, info_pool_list}, {"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info, 0},
{"pool-name", cmdPoolName, opts_pool_name, info_pool_name}, {"pool-list", cmdPoolList, opts_pool_list, info_pool_list, 0},
{"pool-refresh", cmdPoolRefresh, opts_pool_refresh, info_pool_refresh}, {"pool-name", cmdPoolName, opts_pool_name, info_pool_name, 0},
{"pool-start", cmdPoolStart, opts_pool_start, info_pool_start}, {"pool-refresh", cmdPoolRefresh, opts_pool_refresh, info_pool_refresh, 0},
{"pool-undefine", cmdPoolUndefine, opts_pool_undefine, info_pool_undefine}, {"pool-start", cmdPoolStart, opts_pool_start, info_pool_start, 0},
{"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid}, {"pool-undefine", cmdPoolUndefine, opts_pool_undefine,
{NULL, NULL, NULL, NULL} info_pool_undefine, 0},
{"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef storageVolCmds[] = { static const vshCmdDef storageVolCmds[] = {
{"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone}, {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone, 0},
{"vol-create-as", cmdVolCreateAs, opts_vol_create_as, info_vol_create_as}, {"vol-create-as", cmdVolCreateAs, opts_vol_create_as,
{"vol-create", cmdVolCreate, opts_vol_create, info_vol_create}, info_vol_create_as, 0},
{"vol-create-from", cmdVolCreateFrom, opts_vol_create_from, info_vol_create_from}, {"vol-create", cmdVolCreate, opts_vol_create, info_vol_create, 0},
{"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete}, {"vol-create-from", cmdVolCreateFrom, opts_vol_create_from,
{"vol-download", cmdVolDownload, opts_vol_download, info_vol_download }, info_vol_create_from, 0},
{"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml}, {"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete, 0},
{"vol-info", cmdVolInfo, opts_vol_info, info_vol_info}, {"vol-download", cmdVolDownload, opts_vol_download, info_vol_download, 0},
{"vol-key", cmdVolKey, opts_vol_key, info_vol_key}, {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml, 0},
{"vol-list", cmdVolList, opts_vol_list, info_vol_list}, {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info, 0},
{"vol-name", cmdVolName, opts_vol_name, info_vol_name}, {"vol-key", cmdVolKey, opts_vol_key, info_vol_key, 0},
{"vol-path", cmdVolPath, opts_vol_path, info_vol_path}, {"vol-list", cmdVolList, opts_vol_list, info_vol_list, 0},
{"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool}, {"vol-name", cmdVolName, opts_vol_name, info_vol_name, 0},
{"vol-upload", cmdVolUpload, opts_vol_upload, info_vol_upload }, {"vol-path", cmdVolPath, opts_vol_path, info_vol_path, 0},
{"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe}, {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool, 0},
{NULL, NULL, NULL, NULL} {"vol-upload", cmdVolUpload, opts_vol_upload, info_vol_upload, 0},
{"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef networkCmds[] = { static const vshCmdDef networkCmds[] = {
{"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart}, {"net-autostart", cmdNetworkAutostart, opts_network_autostart,
{"net-create", cmdNetworkCreate, opts_network_create, info_network_create}, info_network_autostart, 0},
{"net-define", cmdNetworkDefine, opts_network_define, info_network_define}, {"net-create", cmdNetworkCreate, opts_network_create,
{"net-destroy", cmdNetworkDestroy, opts_network_destroy, info_network_destroy}, info_network_create, 0},
{"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml, info_network_dumpxml}, {"net-define", cmdNetworkDefine, opts_network_define,
{"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit}, info_network_define, 0},
{"net-info", cmdNetworkInfo, opts_network_info, info_network_info}, {"net-destroy", cmdNetworkDestroy, opts_network_destroy,
{"net-list", cmdNetworkList, opts_network_list, info_network_list}, info_network_destroy, 0},
{"net-name", cmdNetworkName, opts_network_name, info_network_name}, {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml,
{"net-start", cmdNetworkStart, opts_network_start, info_network_start}, info_network_dumpxml, 0},
{"net-undefine", cmdNetworkUndefine, opts_network_undefine, info_network_undefine}, {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit, 0},
{"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid}, {"net-info", cmdNetworkInfo, opts_network_info, info_network_info, 0},
{NULL, NULL, NULL, NULL} {"net-list", cmdNetworkList, opts_network_list, info_network_list, 0},
{"net-name", cmdNetworkName, opts_network_name, info_network_name, 0},
{"net-start", cmdNetworkStart, opts_network_start, info_network_start, 0},
{"net-undefine", cmdNetworkUndefine, opts_network_undefine,
info_network_undefine, 0},
{"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef nodedevCmds[] = { static const vshCmdDef nodedevCmds[] = {
{"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create}, {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create,
{"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, info_node_device_destroy}, info_node_device_create, 0},
{"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach, info_node_device_dettach}, {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy,
{"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml, info_node_device_dumpxml}, info_node_device_destroy, 0},
{"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices}, {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach,
{"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach, info_node_device_reattach}, info_node_device_dettach, 0},
{"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset, info_node_device_reset}, {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml,
{NULL, NULL, NULL, NULL} info_node_device_dumpxml, 0},
{"nodedev-list", cmdNodeListDevices, opts_node_list_devices,
info_node_list_devices, 0},
{"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach,
info_node_device_reattach, 0},
{"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset,
info_node_device_reset, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef ifaceCmds[] = { static const vshCmdDef ifaceCmds[] = {
{"iface-define", cmdInterfaceDefine, opts_interface_define, info_interface_define}, {"iface-define", cmdInterfaceDefine, opts_interface_define,
{"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy, info_interface_destroy}, info_interface_define, 0},
{"iface-dumpxml", cmdInterfaceDumpXML, opts_interface_dumpxml, info_interface_dumpxml}, {"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy,
{"iface-edit", cmdInterfaceEdit, opts_interface_edit, info_interface_edit}, info_interface_destroy, 0},
{"iface-list", cmdInterfaceList, opts_interface_list, info_interface_list}, {"iface-dumpxml", cmdInterfaceDumpXML, opts_interface_dumpxml,
{"iface-mac", cmdInterfaceMAC, opts_interface_mac, info_interface_mac}, info_interface_dumpxml, 0},
{"iface-name", cmdInterfaceName, opts_interface_name, info_interface_name}, {"iface-edit", cmdInterfaceEdit, opts_interface_edit,
{"iface-start", cmdInterfaceStart, opts_interface_start, info_interface_start}, info_interface_edit, 0},
{"iface-undefine", cmdInterfaceUndefine, opts_interface_undefine, info_interface_undefine}, {"iface-list", cmdInterfaceList, opts_interface_list,
{NULL, NULL, NULL, NULL} info_interface_list, 0},
{"iface-mac", cmdInterfaceMAC, opts_interface_mac,
info_interface_mac, 0},
{"iface-name", cmdInterfaceName, opts_interface_name,
info_interface_name, 0},
{"iface-start", cmdInterfaceStart, opts_interface_start,
info_interface_start, 0},
{"iface-undefine", cmdInterfaceUndefine, opts_interface_undefine,
info_interface_undefine, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef nwfilterCmds[] = { static const vshCmdDef nwfilterCmds[] = {
{"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define, info_nwfilter_define}, {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define,
{"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml, info_nwfilter_dumpxml}, info_nwfilter_define, 0},
{"nwfilter-edit", cmdNWFilterEdit, opts_nwfilter_edit, info_nwfilter_edit}, {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml,
{"nwfilter-list", cmdNWFilterList, opts_nwfilter_list, info_nwfilter_list}, info_nwfilter_dumpxml, 0},
{"nwfilter-undefine", cmdNWFilterUndefine, opts_nwfilter_undefine, info_nwfilter_undefine}, {"nwfilter-edit", cmdNWFilterEdit, opts_nwfilter_edit,
{NULL, NULL, NULL, NULL} info_nwfilter_edit, 0},
{"nwfilter-list", cmdNWFilterList, opts_nwfilter_list,
info_nwfilter_list, 0},
{"nwfilter-undefine", cmdNWFilterUndefine, opts_nwfilter_undefine,
info_nwfilter_undefine, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef secretCmds[] = { static const vshCmdDef secretCmds[] = {
{"secret-define", cmdSecretDefine, opts_secret_define, info_secret_define}, {"secret-define", cmdSecretDefine, opts_secret_define,
{"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml, info_secret_dumpxml}, info_secret_define, 0},
{"secret-get-value", cmdSecretGetValue, opts_secret_get_value, info_secret_get_value}, {"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml,
{"secret-list", cmdSecretList, NULL, info_secret_list}, info_secret_dumpxml, 0},
{"secret-set-value", cmdSecretSetValue, opts_secret_set_value, info_secret_set_value}, {"secret-get-value", cmdSecretGetValue, opts_secret_get_value,
{"secret-undefine", cmdSecretUndefine, opts_secret_undefine, info_secret_undefine}, info_secret_get_value, 0},
{NULL, NULL, NULL, NULL} {"secret-list", cmdSecretList, NULL, info_secret_list, 0},
{"secret-set-value", cmdSecretSetValue, opts_secret_set_value,
info_secret_set_value, 0},
{"secret-undefine", cmdSecretUndefine, opts_secret_undefine,
info_secret_undefine, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef virshCmds[] = { static const vshCmdDef virshCmds[] = {
{"cd", cmdCd, opts_cd, info_cd}, {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT},
{"echo", cmdEcho, opts_echo, info_echo}, {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT},
{"exit", cmdQuit, NULL, info_quit}, {"exit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
{"help", cmdHelp, opts_help, info_help}, {"help", cmdHelp, opts_help, info_help, VSH_CMD_FLAG_NOCONNECT},
{"pwd", cmdPwd, NULL, info_pwd}, {"pwd", cmdPwd, NULL, info_pwd, VSH_CMD_FLAG_NOCONNECT},
{"quit", cmdQuit, NULL, info_quit}, {"quit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef snapshotCmds[] = { static const vshCmdDef snapshotCmds[] = {
{"snapshot-create", cmdSnapshotCreate, opts_snapshot_create, info_snapshot_create}, {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create,
{"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current, info_snapshot_current}, info_snapshot_create, 0},
{"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete, info_snapshot_delete}, {"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current,
{"snapshot-dumpxml", cmdSnapshotDumpXML, opts_snapshot_dumpxml, info_snapshot_dumpxml}, info_snapshot_current, 0},
{"snapshot-list", cmdSnapshotList, opts_snapshot_list, info_snapshot_list}, {"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete,
{"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert, info_snapshot_revert}, info_snapshot_delete, 0},
{NULL, NULL, NULL, NULL} {"snapshot-dumpxml", cmdSnapshotDumpXML, opts_snapshot_dumpxml,
info_snapshot_dumpxml, 0},
{"snapshot-list", cmdSnapshotList, opts_snapshot_list,
info_snapshot_list, 0},
{"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert,
info_snapshot_revert, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdDef hostAndHypervisorCmds[] = { static const vshCmdDef hostAndHypervisorCmds[] = {
{"capabilities", cmdCapabilities, NULL, info_capabilities}, {"capabilities", cmdCapabilities, NULL, info_capabilities, 0},
{"connect", cmdConnect, opts_connect, info_connect}, {"connect", cmdConnect, opts_connect, info_connect,
{"freecell", cmdFreecell, opts_freecell, info_freecell}, VSH_CMD_FLAG_NOCONNECT},
{"hostname", cmdHostname, NULL, info_hostname}, {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
{"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo}, {"hostname", cmdHostname, NULL, info_hostname, 0},
{"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command}, {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
{"sysinfo", cmdSysinfo, NULL, info_sysinfo}, {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command,
{"uri", cmdURI, NULL, info_uri}, info_qemu_monitor_command, 0},
{NULL, NULL, NULL, NULL} {"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0},
{"uri", cmdURI, NULL, info_uri, 0},
{NULL, NULL, NULL, NULL, 0}
}; };
static const vshCmdGrp cmdGroups[] = { static const vshCmdGrp cmdGroups[] = {
@ -11744,7 +11811,8 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
struct timeval before, after; struct timeval before, after;
bool enable_timing = ctl->timing; bool enable_timing = ctl->timing;
if ((ctl->conn == NULL) || (disconnected != 0)) if ((ctl->conn == NULL || disconnected) &&
!(cmd->def->flags & VSH_CMD_FLAG_NOCONNECT))
vshReconnect(ctl); vshReconnect(ctl);
if (enable_timing) if (enable_timing)
@ -12352,19 +12420,22 @@ vshInit(vshControl *ctl)
if (virEventRegisterDefaultImpl() < 0) if (virEventRegisterDefaultImpl() < 0)
return false; return false;
ctl->conn = virConnectOpenAuth(ctl->name, if (ctl->name) {
virConnectAuthPtrDefault, ctl->conn = virConnectOpenAuth(ctl->name,
ctl->readonly ? VIR_CONNECT_RO : 0); virConnectAuthPtrDefault,
ctl->readonly ? VIR_CONNECT_RO : 0);
/* Connecting to a named connection must succeed, but we delay
/* This is not necessarily fatal. All the individual commands check * connecting to the default connection until we need it
* vshConnectionUsability, except ones which don't need a connection * (since the first command might be 'connect' which allows a
* such as "help". * non-default connection, or might be 'help' which needs no
*/ * connection).
if (!ctl->conn) { */
virshReportError(ctl); if (!ctl->conn) {
vshError(ctl, "%s", _("failed to connect to the hypervisor")); virshReportError(ctl);
return false; vshError(ctl, "%s", _("failed to connect to the hypervisor"));
return false;
}
} }
return true; return true;