2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* virsh-domain.c: Commands to manage domain
|
|
|
|
*
|
2015-02-10 09:35:56 +00:00
|
|
|
* Copyright (C) 2005, 2007-2015 Red Hat, Inc.
|
2012-07-25 15:37:18 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-25 15:37:18 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
* Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-18 04:00:42 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include "virsh-domain.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/xpath.h>
|
|
|
|
#include <libxml/xmlsave.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2012-12-04 11:56:32 +00:00
|
|
|
#include "virbitmap.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-08-18 04:00:42 +00:00
|
|
|
#include "c-ctype.h"
|
|
|
|
#include "conf/domain_conf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-21 16:51:33 +00:00
|
|
|
#include "vircommand.h"
|
2012-08-18 04:00:42 +00:00
|
|
|
#include "virfile.h"
|
2012-12-21 14:26:27 +00:00
|
|
|
#include "virjson.h"
|
2012-08-18 04:00:42 +00:00
|
|
|
#include "virkeycode.h"
|
|
|
|
#include "virmacaddr.h"
|
2015-04-01 15:09:04 +00:00
|
|
|
#include "virnetdevbandwidth.h"
|
2012-12-21 16:51:33 +00:00
|
|
|
#include "virprocess.h"
|
2012-11-30 15:30:05 +00:00
|
|
|
#include "virstring.h"
|
2013-08-26 09:53:43 +00:00
|
|
|
#include "virsh-console.h"
|
2012-08-20 13:46:38 +00:00
|
|
|
#include "virsh-domain-monitor.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-08-18 04:00:42 +00:00
|
|
|
#include "virtypedparam.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-08-18 04:00:42 +00:00
|
|
|
|
2012-08-20 14:59:31 +00:00
|
|
|
/* Gnulib doesn't guarantee SA_SIGINFO support. */
|
|
|
|
#ifndef SA_SIGINFO
|
|
|
|
# define SA_SIGINFO 0
|
|
|
|
#endif
|
|
|
|
|
2014-08-26 12:16:01 +00:00
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
vshLookupDomainInternal(vshControl *ctl,
|
|
|
|
const char *cmdname,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
2012-08-20 20:29:27 +00:00
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int id;
|
|
|
|
virCheckFlags(VSH_BYID | VSH_BYUUID | VSH_BYNAME, NULL);
|
|
|
|
|
|
|
|
/* try it by ID */
|
|
|
|
if (flags & VSH_BYID) {
|
2014-08-26 12:16:01 +00:00
|
|
|
if (virStrToLong_i(name, NULL, 10, &id) == 0 && id >= 0) {
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> looks like ID\n",
|
|
|
|
cmdname);
|
2012-08-20 20:29:27 +00:00
|
|
|
dom = virDomainLookupByID(ctl->conn, id);
|
|
|
|
}
|
|
|
|
}
|
2014-08-26 12:16:01 +00:00
|
|
|
|
2012-08-20 20:29:27 +00:00
|
|
|
/* try it by UUID */
|
|
|
|
if (!dom && (flags & VSH_BYUUID) &&
|
2014-08-26 12:16:01 +00:00
|
|
|
strlen(name) == VIR_UUID_STRING_BUFLEN-1) {
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain UUID\n",
|
|
|
|
cmdname);
|
|
|
|
dom = virDomainLookupByUUIDString(ctl->conn, name);
|
2012-08-20 20:29:27 +00:00
|
|
|
}
|
2014-08-26 12:16:01 +00:00
|
|
|
|
2012-08-20 20:29:27 +00:00
|
|
|
/* try it by NAME */
|
|
|
|
if (!dom && (flags & VSH_BYNAME)) {
|
2014-08-26 12:16:01 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain NAME\n",
|
|
|
|
cmdname);
|
|
|
|
dom = virDomainLookupByName(ctl->conn, name);
|
2012-08-20 20:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dom)
|
2014-08-26 12:16:01 +00:00
|
|
|
vshError(ctl, _("failed to get domain '%s'"), name);
|
2012-08-20 20:29:27 +00:00
|
|
|
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2014-08-26 12:16:01 +00:00
|
|
|
|
|
|
|
virDomainPtr
|
|
|
|
vshLookupDomainBy(vshControl *ctl,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return vshLookupDomainInternal(ctl, "unknown", name, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virDomainPtr
|
|
|
|
vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
|
|
|
|
const char **name, unsigned int flags)
|
|
|
|
{
|
|
|
|
const char *n = NULL;
|
|
|
|
const char *optname = "domain";
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n",
|
|
|
|
cmd->def->name, optname, n);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
*name = n;
|
|
|
|
|
|
|
|
return vshLookupDomainInternal(ctl, cmd->def->name, n, flags);
|
|
|
|
}
|
|
|
|
|
2015-01-08 15:26:50 +00:00
|
|
|
static virDomainPtr
|
|
|
|
vshDomainDefine(virConnectPtr conn, const char *xml, unsigned int flags)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
if (flags) {
|
|
|
|
dom = virDomainDefineXMLFlags(conn, xml, flags);
|
|
|
|
/* If validate is the only flag, just drop it and
|
|
|
|
* try again.
|
|
|
|
*/
|
|
|
|
if (!dom) {
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (err &&
|
|
|
|
(err->code == VIR_ERR_NO_SUPPORT) &&
|
|
|
|
(flags == VIR_DOMAIN_DEFINE_VALIDATE))
|
|
|
|
dom = virDomainDefineXML(conn, xml);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dom = virDomainDefineXML(conn, xml);
|
|
|
|
}
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainVcpuState)
|
|
|
|
VIR_ENUM_IMPL(vshDomainVcpuState,
|
|
|
|
VIR_VCPU_LAST,
|
|
|
|
N_("offline"),
|
|
|
|
N_("running"),
|
|
|
|
N_("blocked"))
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static const char *
|
|
|
|
vshDomainVcpuStateToString(int state)
|
|
|
|
{
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
const char *str = vshDomainVcpuStateTypeToString(state);
|
|
|
|
return str ? _(str) : _("no state");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 12:54:39 +00:00
|
|
|
/*
|
|
|
|
* Determine number of CPU nodes present by trying
|
|
|
|
* virNodeGetCPUMap and falling back to virNodeGetInfo
|
|
|
|
* if needed.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vshNodeGetCPUCount(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
virNodeInfo nodeinfo;
|
|
|
|
|
|
|
|
if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) {
|
|
|
|
/* fall back to nodeinfo */
|
|
|
|
vshResetLibvirtError();
|
2014-11-13 14:20:51 +00:00
|
|
|
if (virNodeGetInfo(conn, &nodeinfo) == 0)
|
2012-11-13 12:54:39 +00:00
|
|
|
ret = VIR_NODEINFO_MAXCPUS(nodeinfo);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "attach-device" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_attach_device[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("attach device from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Attach device from an XML <file>.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_attach_device[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("XML file")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
2013-05-28 09:07:33 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
2013-05-28 09:07:33 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *from = NULL;
|
|
|
|
char *buffer;
|
2013-01-21 14:39:18 +00:00
|
|
|
int rv;
|
|
|
|
bool ret = false;
|
2013-05-28 09:07:33 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-05-28 09:07:33 +00:00
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
|
|
|
vshReportError(ctl);
|
2013-01-21 14:39:18 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags || current)
|
2013-01-21 14:39:18 +00:00
|
|
|
rv = virDomainAttachDeviceFlags(dom, buffer, flags);
|
2013-05-28 09:07:33 +00:00
|
|
|
else
|
2013-01-21 14:39:18 +00:00
|
|
|
rv = virDomainAttachDevice(dom, buffer);
|
2013-05-28 09:07:33 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (rv < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to attach device from %s"), from);
|
2013-01-21 14:39:18 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
vshPrint(ctl, "%s", _("Device attached successfully\n"));
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
2013-01-21 14:39:18 +00:00
|
|
|
return ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "attach-disk" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_attach_disk[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("attach disk device")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Attach new disk device.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_attach_disk[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "source",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK,
|
|
|
|
.help = N_("source of disk device")
|
|
|
|
},
|
|
|
|
{.name = "target",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("target of disk device")
|
|
|
|
},
|
2014-07-01 10:02:03 +00:00
|
|
|
{.name = "targetbus",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("target bus of disk device")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "driver",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("driver of disk device")
|
|
|
|
},
|
|
|
|
{.name = "subdriver",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("subdriver of disk device")
|
|
|
|
},
|
2014-09-02 15:20:41 +00:00
|
|
|
{.name = "iothread",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("IOThread to be used by supported device")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "cache",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("cache mode of disk device")
|
|
|
|
},
|
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("target device type")
|
|
|
|
},
|
2013-10-24 07:15:56 +00:00
|
|
|
{.name = "shareable",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "mode=shareable"
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "mode",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("mode of device reading and writing")
|
|
|
|
},
|
|
|
|
{.name = "sourcetype",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("type of source (block|file)")
|
|
|
|
},
|
|
|
|
{.name = "serial",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("serial of disk device")
|
|
|
|
},
|
2013-06-04 03:27:04 +00:00
|
|
|
{.name = "wwn",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("wwn of disk device")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "rawio",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("needs rawio capability")
|
|
|
|
},
|
|
|
|
{.name = "address",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("address of disk device")
|
|
|
|
},
|
|
|
|
{.name = "multifunction",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("use multifunction pci under specified address")
|
|
|
|
},
|
2013-01-25 12:21:23 +00:00
|
|
|
{.name = "print-xml",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("print XML document rather than attach the disk")
|
|
|
|
},
|
2013-05-28 09:07:33 +00:00
|
|
|
{.name = "persistent",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DISK_ADDR_TYPE_INVALID,
|
|
|
|
DISK_ADDR_TYPE_PCI,
|
|
|
|
DISK_ADDR_TYPE_SCSI,
|
|
|
|
DISK_ADDR_TYPE_IDE,
|
2015-02-04 14:00:08 +00:00
|
|
|
DISK_ADDR_TYPE_CCW,
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PCIAddress {
|
|
|
|
unsigned int domain;
|
|
|
|
unsigned int bus;
|
|
|
|
unsigned int slot;
|
|
|
|
unsigned int function;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SCSIAddress {
|
|
|
|
unsigned int controller;
|
|
|
|
unsigned int bus;
|
2015-06-17 03:29:53 +00:00
|
|
|
unsigned long long unit;
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IDEAddress {
|
|
|
|
unsigned int controller;
|
|
|
|
unsigned int bus;
|
|
|
|
unsigned int unit;
|
|
|
|
};
|
|
|
|
|
2015-02-04 14:00:08 +00:00
|
|
|
struct CCWAddress {
|
|
|
|
unsigned int cssid;
|
|
|
|
unsigned int ssid;
|
|
|
|
unsigned int devno;
|
|
|
|
};
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
struct DiskAddress {
|
|
|
|
int type;
|
|
|
|
union {
|
|
|
|
struct PCIAddress pci;
|
|
|
|
struct SCSIAddress scsi;
|
|
|
|
struct IDEAddress ide;
|
2015-02-04 14:00:08 +00:00
|
|
|
struct CCWAddress ccw;
|
2012-07-25 15:37:18 +00:00
|
|
|
} addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr)
|
|
|
|
{
|
|
|
|
char *domain, *bus, *slot, *function;
|
|
|
|
|
|
|
|
if (!pciAddr)
|
|
|
|
return -1;
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
domain = (char *)str;
|
|
|
|
|
|
|
|
if (virStrToLong_ui(domain, &bus, 0, &pciAddr->domain) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bus++;
|
|
|
|
if (virStrToLong_ui(bus, &slot, 0, &pciAddr->bus) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
slot++;
|
|
|
|
if (virStrToLong_ui(slot, &function, 0, &pciAddr->slot) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
function++;
|
|
|
|
if (virStrToLong_ui(function, NULL, 0, &pciAddr->function) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int str2SCSIAddress(const char *str, struct SCSIAddress *scsiAddr)
|
|
|
|
{
|
|
|
|
char *controller, *bus, *unit;
|
|
|
|
|
|
|
|
if (!scsiAddr)
|
|
|
|
return -1;
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
controller = (char *)str;
|
|
|
|
|
2015-06-17 03:29:51 +00:00
|
|
|
if (virStrToLong_uip(controller, &bus, 0, &scsiAddr->controller) != 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
bus++;
|
2015-06-17 03:29:51 +00:00
|
|
|
if (virStrToLong_uip(bus, &unit, 0, &scsiAddr->bus) != 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
unit++;
|
2015-06-17 03:29:53 +00:00
|
|
|
if (virStrToLong_ullp(unit, NULL, 0, &scsiAddr->unit) != 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr)
|
|
|
|
{
|
|
|
|
char *controller, *bus, *unit;
|
|
|
|
|
|
|
|
if (!ideAddr)
|
|
|
|
return -1;
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
controller = (char *)str;
|
|
|
|
|
|
|
|
if (virStrToLong_ui(controller, &bus, 0, &ideAddr->controller) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bus++;
|
|
|
|
if (virStrToLong_ui(bus, &unit, 0, &ideAddr->bus) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
unit++;
|
|
|
|
if (virStrToLong_ui(unit, NULL, 0, &ideAddr->unit) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-04 14:00:08 +00:00
|
|
|
static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr)
|
|
|
|
{
|
|
|
|
char *cssid, *ssid, *devno;
|
|
|
|
|
|
|
|
if (!ccwAddr)
|
|
|
|
return -1;
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
cssid = (char *)str;
|
|
|
|
|
|
|
|
if (virStrToLong_ui(cssid, &ssid, 0, &ccwAddr->cssid) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ssid++;
|
|
|
|
if (virStrToLong_ui(ssid, &devno, 0, &ccwAddr->ssid) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
devno++;
|
|
|
|
if (virStrToLong_ui(devno, NULL, 0, &ccwAddr->devno) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function)
|
|
|
|
* ide disk address: ide:00.00.0 (controller:bus:unit)
|
|
|
|
* scsi disk address: scsi:00.00.0 (controller:bus:unit)
|
2015-02-04 14:00:08 +00:00
|
|
|
* ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno)
|
2012-07-25 15:37:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr)
|
|
|
|
{
|
|
|
|
char *type, *addr;
|
|
|
|
|
|
|
|
if (!diskAddr)
|
|
|
|
return -1;
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
type = (char *)str;
|
|
|
|
addr = strchr(type, ':');
|
|
|
|
if (!addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (STREQLEN(type, "pci", addr - type)) {
|
|
|
|
diskAddr->type = DISK_ADDR_TYPE_PCI;
|
|
|
|
return str2PCIAddress(addr + 1, &diskAddr->addr.pci);
|
|
|
|
} else if (STREQLEN(type, "scsi", addr - type)) {
|
|
|
|
diskAddr->type = DISK_ADDR_TYPE_SCSI;
|
|
|
|
return str2SCSIAddress(addr + 1, &diskAddr->addr.scsi);
|
|
|
|
} else if (STREQLEN(type, "ide", addr - type)) {
|
|
|
|
diskAddr->type = DISK_ADDR_TYPE_IDE;
|
|
|
|
return str2IDEAddress(addr + 1, &diskAddr->addr.ide);
|
2015-02-04 14:00:08 +00:00
|
|
|
} else if (STREQLEN(type, "ccw", addr - type)) {
|
|
|
|
diskAddr->type = DISK_ADDR_TYPE_CCW;
|
|
|
|
return str2CCWAddress(addr + 1, &diskAddr->addr.ccw);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *source = NULL, *target = NULL, *driver = NULL,
|
|
|
|
*subdriver = NULL, *type = NULL, *mode = NULL,
|
2014-09-02 15:20:41 +00:00
|
|
|
*iothread = NULL, *cache = NULL, *serial = NULL,
|
|
|
|
*straddr = NULL, *wwn = NULL, *targetbus = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
struct DiskAddress diskAddr;
|
|
|
|
bool isFile = false, functionReturn = false;
|
|
|
|
int ret;
|
2013-05-28 09:07:33 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *stype = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2013-01-25 12:21:23 +00:00
|
|
|
char *xml = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
struct stat st;
|
2013-05-28 09:07:33 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "subdriver", &subdriver) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0 ||
|
2014-09-02 15:20:41 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "iothread", &iothread) < 0 ||
|
2013-01-21 14:39:18 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "cache", &cache) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "serial", &serial) < 0 ||
|
2013-06-04 03:27:04 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "wwn", &wwn) < 0 ||
|
2013-01-21 14:39:18 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 ||
|
2014-07-01 10:02:03 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 ||
|
2013-01-21 14:39:18 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!stype) {
|
|
|
|
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")) {
|
|
|
|
vshError(ctl, _("Unknown source type: '%s'"), stype);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode) {
|
|
|
|
if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) {
|
|
|
|
vshError(ctl, _("No support for %s in command 'attach-disk'"),
|
|
|
|
mode);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 03:27:04 +00:00
|
|
|
if (wwn && !virValidateWWN(wwn))
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Make XML of disk */
|
|
|
|
virBufferAsprintf(&buf, "<disk type='%s'",
|
2014-03-12 23:52:07 +00:00
|
|
|
isFile ? "file" : "block");
|
2012-07-25 15:37:18 +00:00
|
|
|
if (type)
|
|
|
|
virBufferAsprintf(&buf, " device='%s'", type);
|
|
|
|
if (vshCommandOptBool(cmd, "rawio"))
|
|
|
|
virBufferAddLit(&buf, " rawio='yes'");
|
|
|
|
virBufferAddLit(&buf, ">\n");
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-09-02 15:20:41 +00:00
|
|
|
if (driver || subdriver || iothread || cache) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAddLit(&buf, "<driver");
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (driver)
|
|
|
|
virBufferAsprintf(&buf, " name='%s'", driver);
|
|
|
|
if (subdriver)
|
|
|
|
virBufferAsprintf(&buf, " type='%s'", subdriver);
|
2014-09-02 15:20:41 +00:00
|
|
|
if (iothread)
|
|
|
|
virBufferAsprintf(&buf, " iothread='%s'", iothread);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (cache)
|
|
|
|
virBufferAsprintf(&buf, " cache='%s'", cache);
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<source %s='%s'/>\n",
|
|
|
|
isFile ? "file" : "dev", source);
|
2014-07-01 10:02:03 +00:00
|
|
|
virBufferAsprintf(&buf, "<target dev='%s'", target);
|
|
|
|
if (targetbus)
|
|
|
|
virBufferAsprintf(&buf, " bus='%s'", targetbus);
|
|
|
|
virBufferAddLit(&buf, "/>\n");
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (mode)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<%s/>\n", mode);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (serial)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<serial>%s</serial>\n", serial);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-06-04 03:27:04 +00:00
|
|
|
if (wwn)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<wwn>%s</wwn>\n", wwn);
|
2013-06-04 03:27:04 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (straddr) {
|
|
|
|
if (str2DiskAddress(straddr, &diskAddr) != 0) {
|
|
|
|
vshError(ctl, _("Invalid address."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRPREFIX((const char *)target, "vd")) {
|
|
|
|
if (diskAddr.type == DISK_ADDR_TYPE_PCI) {
|
|
|
|
virBufferAsprintf(&buf,
|
2014-03-12 23:52:07 +00:00
|
|
|
"<address type='pci' domain='0x%04x'"
|
2012-07-25 15:37:18 +00:00
|
|
|
" bus ='0x%02x' slot='0x%02x' function='0x%0x'",
|
|
|
|
diskAddr.addr.pci.domain, diskAddr.addr.pci.bus,
|
|
|
|
diskAddr.addr.pci.slot, diskAddr.addr.pci.function);
|
|
|
|
if (vshCommandOptBool(cmd, "multifunction"))
|
|
|
|
virBufferAddLit(&buf, " multifunction='on'");
|
|
|
|
virBufferAddLit(&buf, "/>\n");
|
2015-02-04 14:00:08 +00:00
|
|
|
} else if (diskAddr.type == DISK_ADDR_TYPE_CCW) {
|
|
|
|
virBufferAsprintf(&buf,
|
|
|
|
"<address type='ccw' cssid='0x%02x'"
|
|
|
|
" ssid='0x%01x' devno='0x%04x' />\n",
|
|
|
|
diskAddr.addr.ccw.cssid, diskAddr.addr.ccw.ssid,
|
|
|
|
diskAddr.addr.ccw.devno);
|
2012-07-25 15:37:18 +00:00
|
|
|
} else {
|
2015-02-04 14:00:08 +00:00
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("expecting a pci:0000.00.00.00 or ccw:00.0.0000 address."));
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STRPREFIX((const char *)target, "sd")) {
|
|
|
|
if (diskAddr.type == DISK_ADDR_TYPE_SCSI) {
|
|
|
|
virBufferAsprintf(&buf,
|
2015-06-17 03:29:52 +00:00
|
|
|
"<address type='drive' controller='%u'"
|
2015-06-17 03:29:53 +00:00
|
|
|
" bus='%u' unit='%llu' />\n",
|
2012-07-25 15:37:18 +00:00
|
|
|
diskAddr.addr.scsi.controller, diskAddr.addr.scsi.bus,
|
|
|
|
diskAddr.addr.scsi.unit);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, "%s", _("expecting a scsi:00.00.00 address."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STRPREFIX((const char *)target, "hd")) {
|
|
|
|
if (diskAddr.type == DISK_ADDR_TYPE_IDE) {
|
|
|
|
virBufferAsprintf(&buf,
|
2014-03-12 23:52:07 +00:00
|
|
|
"<address type='drive' controller='%d'"
|
2012-07-25 15:37:18 +00:00
|
|
|
" bus='%d' unit='%d' />\n",
|
|
|
|
diskAddr.addr.ide.controller, diskAddr.addr.ide.bus,
|
|
|
|
diskAddr.addr.ide.unit);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, "%s", _("expecting an ide:00.00.00 address."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
2012-07-25 15:37:18 +00:00
|
|
|
virBufferAddLit(&buf, "</disk>\n");
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
|
2013-08-31 03:39:35 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xml = virBufferContentAndReset(&buf);
|
|
|
|
|
2013-01-25 12:21:23 +00:00
|
|
|
if (vshCommandOptBool(cmd, "print-xml")) {
|
|
|
|
vshPrint(ctl, "%s", xml);
|
|
|
|
functionReturn = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 04:05:21 +00:00
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags || current)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainAttachDeviceFlags(dom, xml, flags);
|
2013-05-28 09:07:33 +00:00
|
|
|
else
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainAttachDevice(dom, xml);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to attach disk"));
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%s", _("Disk attached successfully\n"));
|
|
|
|
functionReturn = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2013-01-25 12:21:23 +00:00
|
|
|
VIR_FREE(xml);
|
2013-10-17 04:05:21 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "attach-interface" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_attach_interface[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("attach network interface")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Attach new network interface.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_attach_interface[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("network interface type")
|
|
|
|
},
|
|
|
|
{.name = "source",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("source of network interface")
|
|
|
|
},
|
|
|
|
{.name = "target",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("target network name")
|
|
|
|
},
|
|
|
|
{.name = "mac",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("MAC address")
|
|
|
|
},
|
|
|
|
{.name = "script",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("script used to bridge network interface")
|
|
|
|
},
|
|
|
|
{.name = "model",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("model type")
|
|
|
|
},
|
|
|
|
{.name = "inbound",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("control domain's incoming traffics")
|
|
|
|
},
|
|
|
|
{.name = "outbound",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("control domain's outgoing traffics")
|
|
|
|
},
|
2013-05-28 09:07:33 +00:00
|
|
|
{.name = "persistent",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* parse inbound and outbound which are in the format of
|
|
|
|
* 'average,peak,burst', in which peak and burst are optional,
|
|
|
|
* thus 'average,,burst' and 'average,peak' are also legal. */
|
|
|
|
static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate)
|
|
|
|
{
|
|
|
|
const char *average = NULL;
|
|
|
|
char *peak = NULL, *burst = NULL;
|
|
|
|
|
|
|
|
average = rateStr;
|
|
|
|
if (!average)
|
|
|
|
return -1;
|
|
|
|
if (virStrToLong_ull(average, &peak, 10, &rate->average) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* peak will be updated to point to the end of rateStr in case
|
|
|
|
* of 'average' */
|
|
|
|
if (peak && *peak != '\0') {
|
|
|
|
burst = strchr(peak + 1, ',');
|
|
|
|
if (!(burst && (burst - peak == 1))) {
|
|
|
|
if (virStrToLong_ull(peak + 1, &burst, 10, &rate->peak) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* burst will be updated to point to the end of rateStr in case
|
|
|
|
* of 'average,peak' */
|
|
|
|
if (burst && *burst != '\0') {
|
|
|
|
if (virStrToLong_ull(burst + 1, NULL, 10, &rate->burst) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *mac = NULL, *target = NULL, *script = NULL,
|
|
|
|
*type = NULL, *source = NULL, *model = NULL,
|
|
|
|
*inboundStr = NULL, *outboundStr = NULL;
|
|
|
|
virNetDevBandwidthRate inbound, outbound;
|
2015-02-09 14:53:54 +00:00
|
|
|
virDomainNetType typ;
|
2012-07-25 15:37:18 +00:00
|
|
|
int ret;
|
|
|
|
bool functionReturn = false;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *xml;
|
2013-05-28 09:07:33 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2013-05-28 09:07:33 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "script", &script) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* check interface type */
|
2015-02-09 15:04:58 +00:00
|
|
|
if ((int)(typ = virDomainNetTypeFromString(type)) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("No support for %s in command 'attach-interface'"),
|
|
|
|
type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inboundStr) {
|
|
|
|
memset(&inbound, 0, sizeof(inbound));
|
|
|
|
if (parseRateStr(inboundStr, &inbound) < 0) {
|
|
|
|
vshError(ctl, _("inbound format is incorrect"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (inbound.average == 0) {
|
|
|
|
vshError(ctl, _("inbound average is mandatory"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outboundStr) {
|
|
|
|
memset(&outbound, 0, sizeof(outbound));
|
|
|
|
if (parseRateStr(outboundStr, &outbound) < 0) {
|
|
|
|
vshError(ctl, _("outbound format is incorrect"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (outbound.average == 0) {
|
|
|
|
vshError(ctl, _("outbound average is mandatory"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make XML of interface */
|
|
|
|
virBufferAsprintf(&buf, "<interface type='%s'>\n", type);
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-02-09 15:04:58 +00:00
|
|
|
switch (typ) {
|
|
|
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
|
|
|
virBufferAsprintf(&buf, "<source %s='%s'/>\n",
|
|
|
|
virDomainNetTypeToString(typ), source);
|
|
|
|
break;
|
2015-02-09 15:17:51 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
|
|
|
virBufferAsprintf(&buf, "<source dev='%s'/>\n", source);
|
|
|
|
break;
|
2015-02-09 15:04:58 +00:00
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_USER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
|
|
|
vshError(ctl, _("No support for %s in command 'attach-interface'"),
|
|
|
|
type);
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (target != NULL)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<target dev='%s'/>\n", target);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (mac != NULL)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<mac address='%s'/>\n", mac);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (script != NULL)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<script path='%s'/>\n", script);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (model != NULL)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<model type='%s'/>\n", model);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (inboundStr || outboundStr) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAddLit(&buf, "<bandwidth>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (inboundStr && inbound.average > 0) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<inbound average='%llu'", inbound.average);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (inbound.peak > 0)
|
|
|
|
virBufferAsprintf(&buf, " peak='%llu'", inbound.peak);
|
|
|
|
if (inbound.burst > 0)
|
|
|
|
virBufferAsprintf(&buf, " burst='%llu'", inbound.burst);
|
2013-05-07 10:28:50 +00:00
|
|
|
virBufferAddLit(&buf, "/>\n");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
if (outboundStr && outbound.average > 0) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<outbound average='%llu'", outbound.average);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (outbound.peak > 0)
|
|
|
|
virBufferAsprintf(&buf, " peak='%llu'", outbound.peak);
|
|
|
|
if (outbound.burst > 0)
|
|
|
|
virBufferAsprintf(&buf, " burst='%llu'", outbound.burst);
|
2013-05-07 10:28:50 +00:00
|
|
|
virBufferAddLit(&buf, "/>\n");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</bandwidth>\n");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "</interface>\n");
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
xml = virBufferContentAndReset(&buf);
|
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags || current)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainAttachDeviceFlags(dom, xml, flags);
|
2013-05-28 09:07:33 +00:00
|
|
|
else
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainAttachDevice(dom, xml);
|
|
|
|
|
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to attach interface"));
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%s", _("Interface attached successfully\n"));
|
|
|
|
functionReturn = true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-05-28 09:07:33 +00:00
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "autostart" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_autostart[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("autostart a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Configure a domain to be automatically started at boot.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_autostart[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "disable",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("disable autostarting")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdAutostart(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
int autostart;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
autostart = !vshCommandOptBool(cmd, "disable");
|
|
|
|
|
|
|
|
if (virDomainSetAutostart(dom, autostart) < 0) {
|
|
|
|
if (autostart)
|
|
|
|
vshError(ctl, _("Failed to mark domain %s as autostarted"), name);
|
|
|
|
else
|
|
|
|
vshError(ctl, _("Failed to unmark domain %s as autostarted"), name);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autostart)
|
|
|
|
vshPrint(ctl, _("Domain %s marked as autostarted\n"), name);
|
|
|
|
else
|
|
|
|
vshPrint(ctl, _("Domain %s unmarked as autostarted\n"), name);
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "blkdeviotune" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_blkdeviotune[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Set or query a block device I/O tuning parameters.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Set or query disk I/O parameters such as block throttling.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_blkdeviotune[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "device",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("block device")
|
|
|
|
},
|
|
|
|
{.name = "total_bytes_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "total-bytes-sec"
|
|
|
|
},
|
|
|
|
{.name = "total-bytes-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("total throughput limit in bytes per second")
|
|
|
|
},
|
|
|
|
{.name = "read_bytes_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "read-bytes-sec"
|
|
|
|
},
|
|
|
|
{.name = "read-bytes-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("read throughput limit in bytes per second")
|
|
|
|
},
|
|
|
|
{.name = "write_bytes_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "write-bytes-sec"
|
|
|
|
},
|
|
|
|
{.name = "write-bytes-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("write throughput limit in bytes per second")
|
|
|
|
},
|
|
|
|
{.name = "total_iops_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "total-iops-sec"
|
|
|
|
},
|
|
|
|
{.name = "total-iops-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("total I/O operations limit per second")
|
|
|
|
},
|
|
|
|
{.name = "read_iops_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "read-iops-sec"
|
|
|
|
},
|
|
|
|
{.name = "read-iops-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("read I/O operations limit per second")
|
|
|
|
},
|
|
|
|
{.name = "write_iops_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "write-iops-sec"
|
|
|
|
},
|
|
|
|
{.name = "write-iops-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("write I/O operations limit per second")
|
|
|
|
},
|
2014-10-29 12:16:05 +00:00
|
|
|
{.name = "total_bytes_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "total-bytes-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "total-bytes-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("total max in bytes")
|
|
|
|
},
|
|
|
|
{.name = "read_bytes_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "read-bytes-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "read-bytes-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("read max in bytes")
|
|
|
|
},
|
|
|
|
{.name = "write_bytes_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "write-bytes-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "write-bytes-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("write max in bytes")
|
|
|
|
},
|
|
|
|
{.name = "total_iops_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "total-iops-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "total-iops-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("total I/O operations max")
|
|
|
|
},
|
|
|
|
{.name = "read_iops_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "read-iops-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "read-iops-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("read I/O operations max")
|
|
|
|
},
|
|
|
|
{.name = "write_iops_sec_max",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "write-iops-sec-max"
|
|
|
|
},
|
|
|
|
{.name = "write-iops-sec-max",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("write I/O operations max")
|
|
|
|
},
|
|
|
|
{.name = "size_iops_sec",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "size-iops-sec"
|
|
|
|
},
|
|
|
|
{.name = "size-iops-sec",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("I/O size in bytes")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *name, *disk;
|
2013-01-15 23:01:54 +00:00
|
|
|
unsigned long long value;
|
2012-07-25 15:37:18 +00:00
|
|
|
int nparams = 0;
|
2013-01-15 23:01:54 +00:00
|
|
|
int maxparams = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
int rv = 0;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool ret = false;
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "device", &disk) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec", &value)) < 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
goto interror;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rv > 0) {
|
2013-01-15 23:01:54 +00:00
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
|
|
|
|
value) < 0)
|
2014-10-29 12:16:05 +00:00
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec-max", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX,
|
|
|
|
value) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptULongLong(ctl, cmd, "size-iops-sec", &value)) < 0) {
|
2014-10-29 12:16:05 +00:00
|
|
|
goto interror;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC,
|
|
|
|
value) < 0)
|
2013-01-15 23:01:54 +00:00
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
if (virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get number of block I/O throttle parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
|
|
|
|
|
|
if (virDomainGetBlockIoTune(dom, disk, params, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get block I/O throttle parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-15 23:01:54 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2013-05-23 10:24:08 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-01-15 23:01:54 +00:00
|
|
|
vshSaveLibvirtError();
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to change block I/O throttle"));
|
|
|
|
goto cleanup;
|
2013-01-15 23:01:54 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
interror:
|
2013-01-15 23:01:54 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to parse integer parameter"));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "blkiotune" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_blkiotune[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Get or set blkio parameters")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get or set the current blkio parameters for a guest"
|
2012-07-25 15:37:18 +00:00
|
|
|
" domain.\n"
|
|
|
|
" To get the blkio parameters use following command: \n\n"
|
2013-02-07 15:25:10 +00:00
|
|
|
" virsh # blkiotune <domain>")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_blkiotune[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "weight",
|
|
|
|
.type = VSH_OT_INT,
|
2014-07-24 11:43:47 +00:00
|
|
|
.help = N_("IO Weight")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "device-weights",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("per-device IO Weights, in the form of /path/to/device,weight,...")
|
|
|
|
},
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
{.name = "device-read-iops-sec",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("per-device read I/O limit per second, in the form of /path/to/device,read_iops_sec,...")
|
|
|
|
},
|
|
|
|
{.name = "device-write-iops-sec",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("per-device write I/O limit per second, in the form of /path/to/device,write_iops_sec,...")
|
|
|
|
},
|
|
|
|
{.name = "device-read-bytes-sec",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("per-device bytes read per second, in the form of /path/to/device,read_bytes_sec,...")
|
|
|
|
},
|
|
|
|
{.name = "device-write-bytes-sec",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("per-device bytes wrote per second, in the form of /path/to/device,write_bytes_sec,...")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *device_weight = NULL;
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
const char *device_riops = NULL;
|
|
|
|
const char *device_wiops = NULL;
|
|
|
|
const char *device_rbps = NULL;
|
|
|
|
const char *device_wbps = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
int weight = 0;
|
|
|
|
int nparams = 0;
|
2013-01-15 23:03:07 +00:00
|
|
|
int maxparams = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
int rv = 0;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-01-15 23:03:07 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool ret = false;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptInt(ctl, cmd, "weight", &weight)) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
2013-01-15 23:03:07 +00:00
|
|
|
} else if (rv > 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (weight <= 0) {
|
|
|
|
vshError(ctl, _("Invalid value of %d for I/O weight"), weight);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-01-15 23:03:07 +00:00
|
|
|
if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_WEIGHT, weight) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rv = vshCommandOptString(ctl, cmd, "device-weights", &device_weight);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (rv < 0) {
|
2013-01-15 23:03:07 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to parse string parameter"));
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
2013-01-15 23:03:07 +00:00
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_DEVICE_WEIGHT,
|
|
|
|
device_weight) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rv = vshCommandOptString(ctl, cmd, "device-read-iops-sec", &device_riops);
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
if (rv < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to parse string parameter"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS,
|
|
|
|
device_riops) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rv = vshCommandOptString(ctl, cmd, "device-write-iops-sec", &device_wiops);
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
if (rv < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to parse string parameter"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS,
|
|
|
|
device_wiops) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rv = vshCommandOptString(ctl, cmd, "device-read-bytes-sec", &device_rbps);
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
if (rv < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to parse string parameter"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_DEVICE_READ_BPS,
|
|
|
|
device_rbps) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rv = vshCommandOptString(ctl, cmd, "device-write-bytes-sec", &device_wbps);
|
virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-11 08:29:51 +00:00
|
|
|
if (rv < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to parse string parameter"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS,
|
|
|
|
device_wbps) < 0)
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (nparams == 0) {
|
|
|
|
/* get the number of blkio parameters */
|
|
|
|
if (virDomainGetBlkioParameters(dom, NULL, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get number of blkio parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* nothing to output */
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now go get all the blkio parameters */
|
|
|
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
|
|
if (virDomainGetBlkioParameters(dom, params, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to get blkio parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* set the blkio parameters */
|
2013-01-15 23:03:07 +00:00
|
|
|
if (virDomainSetBlkioParameters(dom, params, nparams, flags) < 0)
|
|
|
|
goto error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-15 23:03:07 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
2013-01-15 23:03:07 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-01-15 23:03:07 +00:00
|
|
|
vshSaveLibvirtError();
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2013-01-15 23:03:07 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to change blkio parameters"));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
2014-08-28 19:18:22 +00:00
|
|
|
VSH_CMD_BLOCK_JOB_ABORT,
|
|
|
|
VSH_CMD_BLOCK_JOB_SPEED,
|
|
|
|
VSH_CMD_BLOCK_JOB_PULL,
|
|
|
|
VSH_CMD_BLOCK_JOB_COMMIT,
|
2012-07-25 15:37:18 +00:00
|
|
|
} vshCmdBlockJobMode;
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
static bool
|
2012-07-25 15:37:18 +00:00
|
|
|
blockJobImpl(vshControl *ctl, const vshCmd *cmd,
|
2014-08-28 19:18:22 +00:00
|
|
|
vshCmdBlockJobMode mode, virDomainPtr *pdom)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
2014-08-27 04:17:07 +00:00
|
|
|
const char *path;
|
2012-07-25 15:37:18 +00:00
|
|
|
unsigned long bandwidth = 0;
|
2014-08-28 19:18:22 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *base = NULL;
|
2012-09-17 20:56:01 +00:00
|
|
|
const char *top = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2014-08-27 04:17:07 +00:00
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
switch (mode) {
|
2012-09-17 20:56:01 +00:00
|
|
|
case VSH_CMD_BLOCK_JOB_ABORT:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (vshCommandOptBool(cmd, "async"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
|
|
|
|
if (vshCommandOptBool(cmd, "pivot"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT;
|
2014-08-28 19:18:22 +00:00
|
|
|
if (virDomainBlockJobAbort(dom, path, flags) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
break;
|
|
|
|
case VSH_CMD_BLOCK_JOB_SPEED:
|
2014-08-28 19:18:22 +00:00
|
|
|
if (virDomainBlockJobSetSpeed(dom, path, bandwidth, 0) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
break;
|
|
|
|
case VSH_CMD_BLOCK_JOB_PULL:
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
2014-05-16 13:40:06 +00:00
|
|
|
if (vshCommandOptBool(cmd, "keep-relative"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE;
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
if (base || flags) {
|
|
|
|
if (virDomainBlockRebase(dom, path, base, bandwidth, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virDomainBlockPull(dom, path, bandwidth, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-05-16 13:40:06 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
break;
|
2012-09-17 20:56:01 +00:00
|
|
|
case VSH_CMD_BLOCK_JOB_COMMIT:
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "top", &top) < 0)
|
2012-09-17 20:56:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (vshCommandOptBool(cmd, "shallow"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_COMMIT_SHALLOW;
|
|
|
|
if (vshCommandOptBool(cmd, "delete"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_COMMIT_DELETE;
|
2014-05-21 04:11:29 +00:00
|
|
|
if (vshCommandOptBool(cmd, "active") ||
|
|
|
|
vshCommandOptBool(cmd, "pivot") ||
|
|
|
|
vshCommandOptBool(cmd, "keep-overlay"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE;
|
2014-05-13 15:59:32 +00:00
|
|
|
if (vshCommandOptBool(cmd, "keep-relative"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE;
|
2014-08-28 19:18:22 +00:00
|
|
|
if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0)
|
|
|
|
goto cleanup;
|
2012-09-17 20:56:01 +00:00
|
|
|
break;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2014-08-28 19:18:22 +00:00
|
|
|
if (pdom && ret)
|
2012-07-25 15:37:18 +00:00
|
|
|
*pdom = dom;
|
|
|
|
else if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(const char *label, unsigned long long remaining,
|
|
|
|
unsigned long long total)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
|
|
|
int progress;
|
|
|
|
|
|
|
|
if (total == 0)
|
|
|
|
/* migration has not been started */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (remaining == 0) {
|
|
|
|
/* migration has completed */
|
|
|
|
progress = 100;
|
|
|
|
} else {
|
|
|
|
/* use float to avoid overflow */
|
|
|
|
progress = (int)(100.0 - remaining * 100.0 / total);
|
|
|
|
if (progress >= 100) {
|
|
|
|
/* migration has not completed, do not print [100 %] */
|
|
|
|
progress = 99;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see comments in vshError about why we must flush */
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stderr, "\r%s: [%3d %%]", label, progress);
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:38:04 +00:00
|
|
|
static volatile sig_atomic_t intCaught;
|
2012-08-18 04:00:42 +00:00
|
|
|
|
|
|
|
static void vshCatchInt(int sig ATTRIBUTE_UNUSED,
|
|
|
|
siginfo_t *siginfo ATTRIBUTE_UNUSED,
|
|
|
|
void *context ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
intCaught = 1;
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
static void
|
|
|
|
vshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom ATTRIBUTE_UNUSED,
|
|
|
|
const char *disk ATTRIBUTE_UNUSED,
|
|
|
|
int type ATTRIBUTE_UNUSED,
|
|
|
|
int status,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
*(int *) opaque = status;
|
|
|
|
}
|
|
|
|
|
2012-09-17 20:56:01 +00:00
|
|
|
/*
|
|
|
|
* "blockcommit" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_block_commit[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Start a block commit operation.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Commit changes from a snapshot down to its backing image.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-09-17 20:56:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_block_commit[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("fully-qualified path of disk")
|
|
|
|
},
|
|
|
|
{.name = "bandwidth",
|
2014-11-06 08:01:00 +00:00
|
|
|
.type = VSH_OT_INT,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("bandwidth limit in MiB/s")
|
|
|
|
},
|
|
|
|
{.name = "base",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("path of base file to commit into (default bottom of chain)")
|
|
|
|
},
|
|
|
|
{.name = "shallow",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("use backing file of top as base")
|
|
|
|
},
|
|
|
|
{.name = "top",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("path of top file to commit from (default top of chain)")
|
|
|
|
},
|
2014-05-21 04:11:29 +00:00
|
|
|
{.name = "active",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("trigger two-stage active commit of top file")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "delete",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("delete files that were successfully committed")
|
|
|
|
},
|
|
|
|
{.name = "wait",
|
|
|
|
.type = VSH_OT_BOOL,
|
2014-05-21 04:11:29 +00:00
|
|
|
.help = N_("wait for job to complete "
|
|
|
|
"(with --active, wait for job to sync)")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, display the progress")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
2014-05-21 04:11:29 +00:00
|
|
|
.help = N_("implies --wait, abort if copy exceeds timeout (in seconds)")
|
|
|
|
},
|
|
|
|
{.name = "pivot",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("implies --active --wait, pivot when commit is synced")
|
|
|
|
},
|
|
|
|
{.name = "keep-overlay",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("implies --active --wait, quit when commit is synced")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
2013-09-19 13:08:29 +00:00
|
|
|
{.name = "async",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, don't wait for cancel to finish")
|
|
|
|
},
|
2014-05-13 15:59:32 +00:00
|
|
|
{.name = "keep-relative",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("keep the backing chain relatively referenced")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-09-17 20:56:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
bool verbose = vshCommandOptBool(cmd, "verbose");
|
2014-05-21 04:11:29 +00:00
|
|
|
bool pivot = vshCommandOptBool(cmd, "pivot");
|
|
|
|
bool finish = vshCommandOptBool(cmd, "keep-overlay");
|
|
|
|
bool active = vshCommandOptBool(cmd, "active") || pivot || finish;
|
|
|
|
bool blocking = vshCommandOptBool(cmd, "wait");
|
2012-09-17 20:56:01 +00:00
|
|
|
int timeout = 0;
|
|
|
|
struct sigaction sig_action;
|
|
|
|
struct sigaction old_sig_action;
|
2012-10-11 15:12:13 +00:00
|
|
|
sigset_t sigmask, oldsigmask;
|
2012-09-17 20:56:01 +00:00
|
|
|
struct timeval start;
|
|
|
|
struct timeval curr;
|
|
|
|
const char *path = NULL;
|
|
|
|
bool quit = false;
|
|
|
|
int abort_flags = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
int status = -1;
|
|
|
|
int cb_id = -1;
|
2012-09-17 20:56:01 +00:00
|
|
|
|
2014-05-21 04:11:29 +00:00
|
|
|
blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
|
2012-09-17 20:56:01 +00:00
|
|
|
if (blocking) {
|
2014-05-21 04:11:29 +00:00
|
|
|
if (pivot && finish) {
|
|
|
|
vshError(ctl, "%s", _("cannot mix --pivot and --keep-overlay"));
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-14 00:08:42 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
2013-03-26 15:41:06 +00:00
|
|
|
return false;
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
2012-09-17 20:56:01 +00:00
|
|
|
return false;
|
|
|
|
if (vshCommandOptBool(cmd, "async"))
|
|
|
|
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
|
|
|
|
intCaught = 0;
|
|
|
|
sig_action.sa_sigaction = vshCatchInt;
|
|
|
|
sig_action.sa_flags = SA_SIGINFO;
|
|
|
|
sigemptyset(&sig_action.sa_mask);
|
|
|
|
sigaction(SIGINT, &sig_action, &old_sig_action);
|
|
|
|
|
|
|
|
GETTIMEOFDAY(&start);
|
2014-05-21 04:11:29 +00:00
|
|
|
} else if (verbose || vshCommandOptBool(cmd, "async")) {
|
2012-09-17 20:56:01 +00:00
|
|
|
vshError(ctl, "%s", _("missing --wait option"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
virConnectDomainEventGenericCallback cb =
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
|
|
|
|
|
|
|
|
if ((cb_id = virConnectDomainEventRegisterAny(ctl->conn,
|
|
|
|
dom,
|
|
|
|
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
|
|
|
|
cb,
|
|
|
|
&status,
|
|
|
|
NULL)) < 0)
|
|
|
|
vshResetLibvirtError();
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_COMMIT, &dom))
|
2012-09-17 20:56:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!blocking) {
|
2014-10-23 10:13:15 +00:00
|
|
|
vshPrint(ctl, "%s", active ?
|
|
|
|
_("Active Block Commit started") :
|
|
|
|
_("Block Commit started"));
|
2012-09-17 20:56:01 +00:00
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (blocking) {
|
|
|
|
virDomainBlockJobInfo info;
|
2012-10-11 15:12:13 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
|
|
|
result = virDomainGetBlockJobInfo(dom, path, &info, 0);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2012-09-17 20:56:01 +00:00
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
vshError(ctl, _("failed to query job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (result == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (verbose)
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(_("Block Commit"),
|
|
|
|
info.end - info.cur, info.end);
|
2014-05-21 04:11:29 +00:00
|
|
|
if (active && info.cur == info.end)
|
|
|
|
break;
|
2012-09-17 20:56:01 +00:00
|
|
|
|
|
|
|
GETTIMEOFDAY(&curr);
|
|
|
|
if (intCaught || (timeout &&
|
|
|
|
(((int)(curr.tv_sec - start.tv_sec) * 1000 +
|
|
|
|
(int)(curr.tv_usec - start.tv_usec) / 1000) >
|
|
|
|
timeout))) {
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
|
|
|
intCaught ? "interrupted" : "timeout");
|
|
|
|
intCaught = 0;
|
|
|
|
timeout = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
|
2012-09-17 20:56:01 +00:00
|
|
|
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to abort job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (abort_flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
usleep(500 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
|
|
|
|
quit = true;
|
|
|
|
|
2012-09-17 20:56:01 +00:00
|
|
|
if (verbose && !quit) {
|
|
|
|
/* printf [100 %] */
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(_("Block Commit"), 0, 1);
|
2012-09-17 20:56:01 +00:00
|
|
|
}
|
2014-05-21 04:11:29 +00:00
|
|
|
if (!quit && pivot) {
|
|
|
|
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT;
|
|
|
|
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to pivot job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (finish && !quit &&
|
|
|
|
virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to finish job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (quit)
|
|
|
|
vshPrint(ctl, "\n%s", _("Commit aborted"));
|
|
|
|
else if (pivot)
|
|
|
|
vshPrint(ctl, "\n%s", _("Successfully pivoted"));
|
2015-03-13 15:56:48 +00:00
|
|
|
else if (!finish && active)
|
2014-05-21 04:11:29 +00:00
|
|
|
vshPrint(ctl, "\n%s", _("Now in synchronized phase"));
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "\n%s", _("Commit complete"));
|
2012-09-17 20:56:01 +00:00
|
|
|
|
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-09-17 20:56:01 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
if (blocking)
|
|
|
|
sigaction(SIGINT, &old_sig_action, NULL);
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (cb_id >= 0)
|
|
|
|
virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
|
2012-09-17 20:56:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "blockcopy" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_block_copy[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Start a block copy operation.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
2013-03-26 16:46:28 +00:00
|
|
|
.data = N_("Copy a disk backing image chain to dest.")
|
2013-02-07 15:25:10 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_block_copy[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
.help = N_("fully-qualified path of source disk")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "dest",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("path of the copy to create")
|
|
|
|
},
|
|
|
|
{.name = "bandwidth",
|
2014-11-06 08:01:00 +00:00
|
|
|
.type = VSH_OT_INT,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("bandwidth limit in MiB/s")
|
|
|
|
},
|
|
|
|
{.name = "shallow",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make the copy share a backing chain")
|
|
|
|
},
|
|
|
|
{.name = "reuse-external",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("reuse existing destination")
|
|
|
|
},
|
|
|
|
{.name = "raw",
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "format=raw"
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
2014-08-28 04:03:04 +00:00
|
|
|
{.name = "blockdev",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("copy destination is block device instead of regular file")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "wait",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("wait for job to reach mirroring phase")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, display the progress")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
2014-06-11 15:36:49 +00:00
|
|
|
.help = N_("implies --wait, abort if copy exceeds timeout (in seconds)")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "pivot",
|
|
|
|
.type = VSH_OT_BOOL,
|
2014-06-11 15:36:49 +00:00
|
|
|
.help = N_("implies --wait, pivot when mirroring starts")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "finish",
|
|
|
|
.type = VSH_OT_BOOL,
|
2014-06-11 15:36:49 +00:00
|
|
|
.help = N_("implies --wait, quit when mirroring starts")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "async",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, don't wait for cancel to finish")
|
|
|
|
},
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
{.name = "xml",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
.help = N_("filename containing XML description of the copy destination")
|
|
|
|
},
|
|
|
|
{.name = "format",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
.help = N_("format of the destination file")
|
|
|
|
},
|
|
|
|
{.name = "granularity",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("power-of-two granularity to use during the copy")
|
|
|
|
},
|
|
|
|
{.name = "buf-size",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("maximum amount of in-flight data during the copy")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
const char *dest = NULL;
|
|
|
|
const char *format = NULL;
|
2014-08-29 21:20:30 +00:00
|
|
|
unsigned long bandwidth = 0;
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
unsigned int granularity = 0;
|
|
|
|
unsigned long long buf_size = 0;
|
|
|
|
unsigned int flags = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool ret = false;
|
|
|
|
bool blocking = vshCommandOptBool(cmd, "wait");
|
|
|
|
bool verbose = vshCommandOptBool(cmd, "verbose");
|
|
|
|
bool pivot = vshCommandOptBool(cmd, "pivot");
|
|
|
|
bool finish = vshCommandOptBool(cmd, "finish");
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
bool blockdev = vshCommandOptBool(cmd, "blockdev");
|
2012-07-25 15:37:18 +00:00
|
|
|
int timeout = 0;
|
|
|
|
struct sigaction sig_action;
|
|
|
|
struct sigaction old_sig_action;
|
2012-10-11 15:12:13 +00:00
|
|
|
sigset_t sigmask, oldsigmask;
|
2012-07-25 15:37:18 +00:00
|
|
|
struct timeval start;
|
|
|
|
struct timeval curr;
|
|
|
|
const char *path = NULL;
|
|
|
|
bool quit = false;
|
|
|
|
int abort_flags = 0;
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
const char *xml = NULL;
|
|
|
|
char *xmlstr = NULL;
|
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
int nparams = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
int status = -1;
|
|
|
|
int cb_id = -1;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-08-29 21:20:30 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
|
|
|
return false;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "dest", &dest) < 0)
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
return false;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "xml", &xml) < 0)
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
return false;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "format", &format) < 0)
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(dest, xml);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(format, xml);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(blockdev, xml);
|
2014-08-29 21:20:30 +00:00
|
|
|
|
2014-06-11 15:36:49 +00:00
|
|
|
blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (blocking) {
|
|
|
|
if (pivot && finish) {
|
|
|
|
vshError(ctl, "%s", _("cannot mix --pivot and --finish"));
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-14 00:08:42 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
2013-03-26 15:41:06 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (vshCommandOptBool(cmd, "async"))
|
|
|
|
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
|
|
|
|
intCaught = 0;
|
|
|
|
sig_action.sa_sigaction = vshCatchInt;
|
|
|
|
sig_action.sa_flags = SA_SIGINFO;
|
|
|
|
sigemptyset(&sig_action.sa_mask);
|
|
|
|
sigaction(SIGINT, &sig_action, &old_sig_action);
|
|
|
|
|
|
|
|
GETTIMEOFDAY(&start);
|
2014-06-11 15:36:49 +00:00
|
|
|
} else if (verbose || vshCommandOptBool(cmd, "async")) {
|
2012-09-17 20:56:01 +00:00
|
|
|
vshError(ctl, "%s", _("missing --wait option"));
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
virConnectDomainEventGenericCallback cb =
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
|
|
|
|
|
|
|
|
if ((cb_id = virConnectDomainEventRegisterAny(ctl->conn,
|
|
|
|
dom,
|
|
|
|
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
|
|
|
|
cb,
|
|
|
|
&status,
|
|
|
|
NULL)) < 0)
|
|
|
|
vshResetLibvirtError();
|
|
|
|
|
2014-08-29 21:20:30 +00:00
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
/* XXX: Parse bandwidth as scaled input, rather than forcing
|
|
|
|
* MiB/s, and either reject negative input or treat it as 0 rather
|
|
|
|
* than trying to guess which value will work well across both
|
|
|
|
* APIs with their different sizes and scales. */
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0)
|
2014-08-29 21:20:30 +00:00
|
|
|
goto cleanup;
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0)
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
goto cleanup;
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0)
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (xml) {
|
2014-10-14 08:04:31 +00:00
|
|
|
if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlstr) < 0) {
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
vshReportError(ctl);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (!dest) {
|
|
|
|
vshError(ctl, "%s", _("need either --dest or --xml"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-08-29 21:20:30 +00:00
|
|
|
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
/* Exploit that some VIR_DOMAIN_BLOCK_REBASE_* and
|
|
|
|
* VIR_DOMAIN_BLOCK_COPY_* flags have the same values. */
|
2014-08-29 21:20:30 +00:00
|
|
|
if (vshCommandOptBool(cmd, "shallow"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW;
|
|
|
|
if (vshCommandOptBool(cmd, "reuse-external"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT;
|
|
|
|
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml) {
|
|
|
|
/* New API */
|
|
|
|
if (bandwidth || granularity || buf_size) {
|
|
|
|
params = vshCalloc(ctl, 3, sizeof(*params));
|
|
|
|
if (bandwidth) {
|
|
|
|
/* bandwidth is ulong MiB/s, but the typed parameter is
|
|
|
|
* ullong bytes/s; make sure we don't overflow */
|
2014-11-20 15:29:23 +00:00
|
|
|
unsigned long long limit = MIN(ULONG_MAX, ULLONG_MAX >> 20);
|
|
|
|
if (bandwidth > limit) {
|
2015-03-27 09:56:29 +00:00
|
|
|
vshError(ctl, _("bandwidth must be less than %llu"), limit);
|
|
|
|
goto cleanup;
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
}
|
|
|
|
if (virTypedParameterAssign(¶ms[nparams++],
|
|
|
|
VIR_DOMAIN_BLOCK_COPY_BANDWIDTH,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
bandwidth << 20ULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (granularity &&
|
|
|
|
virTypedParameterAssign(¶ms[nparams++],
|
|
|
|
VIR_DOMAIN_BLOCK_COPY_GRANULARITY,
|
|
|
|
VIR_TYPED_PARAM_UINT,
|
|
|
|
granularity) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (buf_size &&
|
|
|
|
virTypedParameterAssign(¶ms[nparams++],
|
|
|
|
VIR_DOMAIN_BLOCK_COPY_BUF_SIZE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
buf_size) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xmlstr) {
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
virBufferAsprintf(&buf, "<disk type='%s'>\n",
|
|
|
|
blockdev ? "block" : "file");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferAsprintf(&buf, "<source %s", blockdev ? "dev" : "file");
|
|
|
|
virBufferEscapeString(&buf, "='%s'/>\n", dest);
|
|
|
|
virBufferEscapeString(&buf, "<driver type='%s'/>\n", format);
|
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</disk>\n");
|
|
|
|
if (virBufferCheckError(&buf) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
xmlstr = virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainBlockCopy(dom, path, xmlstr, params, nparams, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
/* Old API */
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_COPY;
|
|
|
|
if (vshCommandOptBool(cmd, "blockdev"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_DEV;
|
|
|
|
if (STREQ_NULLABLE(format, "raw"))
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW;
|
|
|
|
|
|
|
|
if (virDomainBlockRebase(dom, path, dest, bandwidth, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!blocking) {
|
|
|
|
vshPrint(ctl, "%s", _("Block Copy started"));
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (blocking) {
|
|
|
|
virDomainBlockJobInfo info;
|
2012-10-11 15:12:13 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
|
|
|
result = virDomainGetBlockJobInfo(dom, path, &info, 0);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-08-09 20:52:11 +00:00
|
|
|
if (result < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("failed to query job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-06-19 13:43:02 +00:00
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
vshError(ctl, _("Block Copy unexpectedly failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-08-09 20:52:11 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (verbose)
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(_("Block Copy"), info.end - info.cur, info.end);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (info.cur == info.end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
GETTIMEOFDAY(&curr);
|
|
|
|
if (intCaught || (timeout &&
|
|
|
|
(((int)(curr.tv_sec - start.tv_sec) * 1000 +
|
|
|
|
(int)(curr.tv_usec - start.tv_usec) / 1000) >
|
2012-09-17 20:56:01 +00:00
|
|
|
timeout))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
|
|
|
intCaught ? "interrupted" : "timeout");
|
|
|
|
intCaught = 0;
|
|
|
|
timeout = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to abort job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (abort_flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
usleep(500 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
|
|
|
|
quit = true;
|
|
|
|
|
2013-08-09 20:52:11 +00:00
|
|
|
if (!quit && pivot) {
|
2012-07-25 15:37:18 +00:00
|
|
|
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT;
|
|
|
|
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to pivot job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-08-09 20:52:11 +00:00
|
|
|
} else if (finish && !quit &&
|
|
|
|
virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("failed to finish job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-06-11 15:36:49 +00:00
|
|
|
if (quit)
|
|
|
|
vshPrint(ctl, "\n%s", _("Copy aborted"));
|
|
|
|
else if (pivot)
|
|
|
|
vshPrint(ctl, "\n%s", _("Successfully pivoted"));
|
|
|
|
else if (finish)
|
|
|
|
vshPrint(ctl, "\n%s", _("Successfully copied"));
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "\n%s", _("Now in mirroring phase"));
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
blockcopy: expose new API in virsh
Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch). Continue to use the older API where
possible, for maximum compatibility.
The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:
<disk type='network'>
<driver type='raw'/>
<source protocol='gluster' name='vol1/img'>
<host name='red'/>
</source>
</disk>
[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]
Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.
The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.
I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.
* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-29 21:47:28 +00:00
|
|
|
VIR_FREE(xmlstr);
|
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
if (blocking)
|
|
|
|
sigaction(SIGINT, &old_sig_action, NULL);
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (cb_id >= 0)
|
|
|
|
virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "blockjob" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_block_job[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Manage active block operations")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Query, adjust speed, or cancel active block operations.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_block_job[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("fully-qualified path of disk")
|
|
|
|
},
|
|
|
|
{.name = "abort",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("abort the active job on the specified disk")
|
|
|
|
},
|
|
|
|
{.name = "async",
|
|
|
|
.type = VSH_OT_BOOL,
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
.help = N_("implies --abort; request but don't wait for job end")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "pivot",
|
|
|
|
.type = VSH_OT_BOOL,
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
.help = N_("implies --abort; conclude and pivot a copy or commit job")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "info",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get active job information for the specified disk")
|
|
|
|
},
|
2014-08-28 23:39:25 +00:00
|
|
|
{.name = "bytes",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --info, get bandwidth in bytes rather than MiB/s")
|
|
|
|
},
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
{.name = "raw",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("implies --info; output details rather than human summary")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "bandwidth",
|
2014-11-06 08:01:00 +00:00
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("set the bandwidth limit in MiB/s")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainBlockJob)
|
|
|
|
VIR_ENUM_IMPL(vshDomainBlockJob,
|
|
|
|
VIR_DOMAIN_BLOCK_JOB_TYPE_LAST,
|
|
|
|
N_("Unknown job"),
|
|
|
|
N_("Block Pull"),
|
|
|
|
N_("Block Copy"),
|
blockcommit: document semantics of committing active layer
Now that qemu 2.0 allows commit of the active layer, people are
attempting to use virsh blockcommit and getting into a stuck
state, because libvirt is unprepared to handle the two-phase
commit required by qemu.
Stepping back a bit, there are two valid semantics for a
commit operation:
1. Maintain a 'golden' base, and a transient overlay. Make
changes in the overlay, and if everything appears to work,
commit those changes into the base, but still keep the overlay
for the next round of changes; repeat the cycle as desired.
2. Create an external snapshot, then back up the stable state
in the backing file. Once the backup is complete, commit the
overlay back into the base, and delete the temporary snapshot.
Since qemu doesn't know up front which of the two styles is
preferred, a block commit of the active layer merely gets
the job into a synchronized state, and sends an event; then
the user must either cancel (case 1) or complete (case 2),
where qemu then sends a second event that actually ends the
job. However, until commit e6bcbcd, libvirt was blindly
assuming the semantics that apply to a commit of an
intermediate image, where there is only one sane conclusion
(the job automatically ends with fewer elements in the chain);
and getting stuck because it wasn't prepared for qemu to enter
a second phase of the job.
This patch adds a flag to the libvirt API that a user MUST
supply in order to acknowledge that they will be using two-phase
semantics. It might be possible to have a mode where if the
flag is omitted, we automatically do the case 2 semantics on
the user's behalf; but before that happens, I must do additional
patches to track the fact that we are doing an active commit
in the domain XML. Later patches will add support of the flag,
and once 2-phase semantics are working, we can then decide
whether to relax things to allow an omitted flag to cause an
automatic pivot.
* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)
(VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT): New enums.
* src/libvirt.c (virDomainBlockCommit): Document two-phase job
when committing active layer, through new flag.
(virDomainBlockJobAbort): Document that pivot also occurs after
active commit.
* tools/virsh-domain.c (vshDomainBlockJob): Cover new job.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Explicitly
reject active copy; later patches will add it in.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-16 19:48:43 +00:00
|
|
|
N_("Block Commit"),
|
|
|
|
N_("Active Block Commit"))
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainBlockJobToString(int type)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainBlockJobTypeToString(type);
|
|
|
|
return str ? _(str) : _("Unknown job");
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainBlockJobInfo info;
|
2014-08-28 19:18:22 +00:00
|
|
|
bool ret = false;
|
2014-08-28 23:39:25 +00:00
|
|
|
int rc = -1;
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
bool raw = vshCommandOptBool(cmd, "raw");
|
2014-08-28 23:39:25 +00:00
|
|
|
bool bytes = vshCommandOptBool(cmd, "bytes");
|
2012-07-25 15:37:18 +00:00
|
|
|
bool abortMode = (vshCommandOptBool(cmd, "abort") ||
|
|
|
|
vshCommandOptBool(cmd, "async") ||
|
|
|
|
vshCommandOptBool(cmd, "pivot"));
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
bool infoMode = vshCommandOptBool(cmd, "info") || raw;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool bandwidth = vshCommandOptBool(cmd, "bandwidth");
|
2014-08-28 19:18:22 +00:00
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *path;
|
|
|
|
unsigned int flags = 0;
|
2014-08-28 23:39:25 +00:00
|
|
|
unsigned long long speed;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (abortMode + infoMode + bandwidth > 1) {
|
|
|
|
vshError(ctl, "%s",
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
_("conflict between abort, info, and bandwidth modes"));
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-28 23:39:25 +00:00
|
|
|
/* XXX also support --bytes with bandwidth mode */
|
|
|
|
if (bytes && (abortMode || bandwidth)) {
|
|
|
|
vshError(ctl, "%s", _("--bytes requires info mode"));
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (abortMode)
|
2014-08-28 19:18:22 +00:00
|
|
|
return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_ABORT, NULL);
|
|
|
|
if (bandwidth)
|
|
|
|
return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_SPEED, NULL);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
/* Everything below here is for --info mode */
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
/* XXX Allow path to be optional to list info on all devices at once */
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-28 23:39:25 +00:00
|
|
|
/* If bytes were requested, or if raw mode is not forcing a MiB/s
|
|
|
|
* query and cache can't prove failure, then query bytes/sec. */
|
|
|
|
if (bytes || !(raw || ctl->blockJobNoBytes)) {
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES;
|
|
|
|
rc = virDomainGetBlockJobInfo(dom, path, &info, flags);
|
|
|
|
if (rc < 0) {
|
|
|
|
/* Check for particular errors, let all the rest be fatal. */
|
|
|
|
switch (last_error->code) {
|
|
|
|
case VIR_ERR_INVALID_ARG:
|
|
|
|
ctl->blockJobNoBytes = true;
|
|
|
|
/* fallthrough */
|
|
|
|
case VIR_ERR_OVERFLOW:
|
|
|
|
if (!bytes && !raw) {
|
|
|
|
/* try again with MiB/s, unless forcing bytes */
|
|
|
|
vshResetLibvirtError();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
|
|
|
default:
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
speed = info.bandwidth;
|
|
|
|
}
|
|
|
|
/* If we don't already have a query result, query for MiB/s */
|
|
|
|
if (rc < 0) {
|
|
|
|
flags &= ~VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES;
|
|
|
|
if ((rc = virDomainGetBlockJobInfo(dom, path, &info, flags)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
speed = info.bandwidth;
|
|
|
|
/* Scale to bytes/s unless in raw mode */
|
|
|
|
if (!raw) {
|
|
|
|
speed <<= 20;
|
|
|
|
if (speed >> 20 != info.bandwidth) {
|
|
|
|
vshError(ctl, _("overflow in converting %ld MiB/s to bytes\n"),
|
|
|
|
info.bandwidth);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
if (rc == 0) {
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
if (!raw)
|
|
|
|
vshPrint(ctl, _("No current block job for %s"), path);
|
2014-08-28 19:18:22 +00:00
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
if (raw) {
|
|
|
|
vshPrint(ctl, _(" type=%s\n bandwidth=%lu\n cur=%llu\n end=%llu\n"),
|
|
|
|
vshDomainBlockJobTypeToString(info.type),
|
|
|
|
info.bandwidth, info.cur, info.end);
|
|
|
|
} else {
|
|
|
|
vshPrintJobProgress(vshDomainBlockJobToString(info.type),
|
|
|
|
info.end - info.cur, info.end);
|
2014-08-28 23:39:25 +00:00
|
|
|
if (speed) {
|
|
|
|
const char *unit;
|
|
|
|
double val = vshPrettyCapacity(speed, &unit);
|
|
|
|
vshPrint(ctl, _(" Bandwidth limit: %llu bytes/s (%-.3lf %s/s)"),
|
|
|
|
speed, val, unit);
|
|
|
|
}
|
blockjob: add new --raw flag to virsh blockjob
The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing. Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.
$ virsh blockjob testvm1 vda --raw
type=Block Copy
bandwidth=1
cur=197120
end=197120
The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.
Now that we have a raw mode, we can guarantee that it won't change
format over time. Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.
My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).
Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:
$ virsh blockjob test1 hda --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes
even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line. Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:
error: conflict between abort, info, and bandwidth modes
* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-28 23:23:49 +00:00
|
|
|
vshPrint(ctl, "\n");
|
|
|
|
}
|
2014-08-28 19:18:22 +00:00
|
|
|
ret = true;
|
|
|
|
cleanup:
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "blockpull" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_block_pull[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Populate a disk from its backing image.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Populate a disk from its backing image.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_block_pull[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("fully-qualified path of disk")
|
|
|
|
},
|
|
|
|
{.name = "bandwidth",
|
2014-11-06 08:01:00 +00:00
|
|
|
.type = VSH_OT_INT,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("bandwidth limit in MiB/s")
|
|
|
|
},
|
|
|
|
{.name = "base",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("path of backing file in chain for a partial pull")
|
|
|
|
},
|
|
|
|
{.name = "wait",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("wait for job to finish")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, display the progress")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("with --wait, abort if pull exceeds timeout (in seconds)")
|
|
|
|
},
|
|
|
|
{.name = "async",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("with --wait, don't wait for cancel to finish")
|
|
|
|
},
|
2014-05-16 13:40:06 +00:00
|
|
|
{.name = "keep-relative",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("keep the backing chain relatively referenced")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
bool blocking = vshCommandOptBool(cmd, "wait");
|
|
|
|
bool verbose = vshCommandOptBool(cmd, "verbose");
|
|
|
|
int timeout = 0;
|
|
|
|
struct sigaction sig_action;
|
|
|
|
struct sigaction old_sig_action;
|
2012-10-11 15:12:13 +00:00
|
|
|
sigset_t sigmask, oldsigmask;
|
2012-07-25 15:37:18 +00:00
|
|
|
struct timeval start;
|
|
|
|
struct timeval curr;
|
|
|
|
const char *path = NULL;
|
|
|
|
bool quit = false;
|
|
|
|
int abort_flags = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
int status = -1;
|
|
|
|
int cb_id = -1;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (blocking) {
|
2014-02-14 00:08:42 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
2013-03-26 15:41:06 +00:00
|
|
|
return false;
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
if (vshCommandOptBool(cmd, "async"))
|
|
|
|
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
|
|
|
|
intCaught = 0;
|
|
|
|
sig_action.sa_sigaction = vshCatchInt;
|
|
|
|
sig_action.sa_flags = SA_SIGINFO;
|
|
|
|
sigemptyset(&sig_action.sa_mask);
|
|
|
|
sigaction(SIGINT, &sig_action, &old_sig_action);
|
|
|
|
|
|
|
|
GETTIMEOFDAY(&start);
|
|
|
|
} else if (verbose || vshCommandOptBool(cmd, "timeout") ||
|
|
|
|
vshCommandOptBool(cmd, "async")) {
|
2012-09-17 20:56:01 +00:00
|
|
|
vshError(ctl, "%s", _("missing --wait option"));
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
virConnectDomainEventGenericCallback cb =
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
|
|
|
|
|
|
|
|
if ((cb_id = virConnectDomainEventRegisterAny(ctl->conn,
|
|
|
|
dom,
|
|
|
|
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
|
|
|
|
cb,
|
|
|
|
&status,
|
|
|
|
NULL)) < 0)
|
|
|
|
vshResetLibvirtError();
|
|
|
|
|
2014-08-28 19:18:22 +00:00
|
|
|
if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_PULL, &dom))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!blocking) {
|
|
|
|
vshPrint(ctl, "%s", _("Block Pull started"));
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (blocking) {
|
|
|
|
virDomainBlockJobInfo info;
|
2012-10-11 15:12:13 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
|
|
|
result = virDomainGetBlockJobInfo(dom, path, &info, 0);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
vshError(ctl, _("failed to query job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (result == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (verbose)
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(_("Block Pull"), info.end - info.cur, info.end);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
GETTIMEOFDAY(&curr);
|
|
|
|
if (intCaught || (timeout &&
|
|
|
|
(((int)(curr.tv_sec - start.tv_sec) * 1000 +
|
|
|
|
(int)(curr.tv_usec - start.tv_usec) / 1000) >
|
2012-09-17 20:56:01 +00:00
|
|
|
timeout))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
|
|
|
intCaught ? "interrupted" : "timeout");
|
|
|
|
intCaught = 0;
|
|
|
|
timeout = 0;
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
|
|
|
|
vshError(ctl, _("failed to abort job for disk %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (abort_flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
usleep(500 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
|
|
|
|
quit = true;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (verbose && !quit) {
|
|
|
|
/* printf [100 %] */
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(_("Block Pull"), 0, 1);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
vshPrint(ctl, "\n%s", quit ? _("Pull aborted") : _("Pull complete"));
|
|
|
|
|
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
if (blocking)
|
|
|
|
sigaction(SIGINT, &old_sig_action, NULL);
|
virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 11:52:57 +00:00
|
|
|
if (cb_id >= 0)
|
|
|
|
virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "blockresize" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_block_resize[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Resize block device of domain.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Resize block device of domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_block_resize[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("Fully-qualified path of block device")
|
|
|
|
},
|
|
|
|
{.name = "size",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("New size of the block device, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdBlockResize(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *path = NULL;
|
|
|
|
unsigned long long size = 0;
|
|
|
|
unsigned int flags = 0;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Prefer the older interface of KiB. */
|
|
|
|
if (size % 1024 == 0)
|
|
|
|
size /= 1024;
|
|
|
|
else
|
|
|
|
flags |= VIR_DOMAIN_BLOCK_RESIZE_BYTES;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainBlockResize(dom, path, size, flags) < 0) {
|
|
|
|
vshError(ctl, _("Failed to resize block device '%s'"), path);
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, _("Block device '%s' is resized"), path);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
/*
|
|
|
|
* "console" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_console[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("connect to the guest console")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Connect the virtual serial console for the guest")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_console[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2014-10-01 14:07:46 +00:00
|
|
|
{.name = "devname", /* sc_prohibit_devname */
|
2013-01-14 11:26:54 +00:00
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("character device name")
|
|
|
|
},
|
|
|
|
{.name = "force",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force console connection (disconnect already connected sessions)")
|
|
|
|
},
|
|
|
|
{.name = "safe",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("only connect if safe console handling is supported")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdRunConsole(vshControl *ctl, virDomainPtr dom,
|
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
if ((state = vshDomainState(ctl, dom, NULL)) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to get domain status"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == VIR_DOMAIN_SHUTOFF) {
|
|
|
|
vshError(ctl, "%s", _("The domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isatty(STDIN_FILENO)) {
|
|
|
|
vshError(ctl, "%s", _("Cannot run interactive console without a controlling TTY"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrintExtra(ctl, _("Connected to domain %s\n"), virDomainGetName(dom));
|
|
|
|
vshPrintExtra(ctl, _("Escape character is %s\n"), ctl->escapeChar);
|
|
|
|
fflush(stdout);
|
2013-08-29 16:15:07 +00:00
|
|
|
if (vshRunConsole(ctl, dom, name, flags) == 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdConsole(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
bool force = vshCommandOptBool(cmd, "force");
|
|
|
|
bool safe = vshCommandOptBool(cmd, "safe");
|
|
|
|
unsigned int flags = 0;
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2014-10-01 14:07:46 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "devname", &name) < 0) /* sc_prohibit_devname */
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
flags |= VIR_DOMAIN_CONSOLE_FORCE;
|
|
|
|
if (safe)
|
|
|
|
flags |= VIR_DOMAIN_CONSOLE_SAFE;
|
|
|
|
|
|
|
|
ret = cmdRunConsole(ctl, dom, name, flags);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-15 20:43:01 +00:00
|
|
|
#endif /* WIN32 */
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* "domif-setlink" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domif_setlink[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("set link state of a virtual interface")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Set link state of a domain's virtual interface. This command "
|
|
|
|
"wraps usage of update-device command.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domif_setlink[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "interface",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("interface device (MAC Address)")
|
|
|
|
},
|
|
|
|
{.name = "state",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("new state of the device")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "config"
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *iface;
|
|
|
|
const char *state;
|
2013-09-03 11:36:22 +00:00
|
|
|
char *value;
|
|
|
|
char *desc;
|
2012-07-25 15:37:18 +00:00
|
|
|
virMacAddr macaddr;
|
|
|
|
const char *element;
|
|
|
|
const char *attr;
|
|
|
|
bool config;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlXPathObjectPtr obj = NULL;
|
|
|
|
xmlNodePtr cur = NULL;
|
2013-09-04 15:27:27 +00:00
|
|
|
char *xml_buf = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "state", &state) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
config = vshCommandOptBool(cmd, "config");
|
|
|
|
|
|
|
|
if (STRNEQ(state, "up") && STRNEQ(state, "down")) {
|
|
|
|
vshError(ctl, _("invalid link state '%s'"), state);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get persistent or live description of network device */
|
|
|
|
desc = virDomainGetXMLDesc(dom, config ? VIR_DOMAIN_XML_INACTIVE : 0);
|
|
|
|
if (desc == NULL) {
|
|
|
|
vshError(ctl, _("Failed to get domain description xml"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
else
|
|
|
|
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (virDomainIsActive(dom) == 0)
|
|
|
|
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
|
|
|
|
/* extract current network device description */
|
|
|
|
xml = virXMLParseStringCtxt(desc, _("(domain_definition)"), &ctxt);
|
|
|
|
VIR_FREE(desc);
|
|
|
|
if (!xml) {
|
|
|
|
vshError(ctl, _("Failed to parse domain description xml"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
|
|
|
|
if (obj == NULL || obj->type != XPATH_NODESET ||
|
|
|
|
obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
|
|
|
|
vshError(ctl, _("Failed to extract interface information or no interfaces found"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virMacAddrParse(iface, &macaddr) == 0) {
|
|
|
|
element = "mac";
|
|
|
|
attr = "address";
|
|
|
|
} else {
|
|
|
|
element = "target";
|
|
|
|
attr = "dev";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find interface with matching mac addr */
|
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
|
|
|
cur = obj->nodesetval->nodeTab[i]->children;
|
|
|
|
|
|
|
|
while (cur) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE &&
|
|
|
|
xmlStrEqual(cur->name, BAD_CAST element)) {
|
|
|
|
value = virXMLPropString(cur, attr);
|
|
|
|
|
|
|
|
if (STRCASEEQ(value, iface)) {
|
|
|
|
VIR_FREE(value);
|
|
|
|
goto hit;
|
|
|
|
}
|
|
|
|
VIR_FREE(value);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vshError(ctl, _("interface (%s: %s) not found"), element, iface);
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
hit:
|
2012-07-25 15:37:18 +00:00
|
|
|
/* find and modify/add link state node */
|
|
|
|
/* try to find <link> element */
|
|
|
|
cur = obj->nodesetval->nodeTab[i]->children;
|
|
|
|
|
|
|
|
while (cur) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE &&
|
|
|
|
xmlStrEqual(cur->name, BAD_CAST "link")) {
|
|
|
|
/* found, just modify the property */
|
|
|
|
xmlSetProp(cur, BAD_CAST "state", BAD_CAST state);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cur) {
|
|
|
|
/* element <link> not found, add one */
|
|
|
|
cur = xmlNewChild(obj->nodesetval->nodeTab[i],
|
|
|
|
NULL,
|
|
|
|
BAD_CAST "link",
|
|
|
|
NULL);
|
|
|
|
if (!cur)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-04 15:27:27 +00:00
|
|
|
if (!(xml_buf = virXMLNodeToString(xml, obj->nodesetval->nodeTab[i]))) {
|
|
|
|
vshSaveLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to create XML"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-04 15:27:27 +00:00
|
|
|
if (virDomainUpdateDeviceFlags(dom, xml_buf, flags) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to update interface link state"));
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%s", _("Device updated successfully\n"));
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
2013-09-04 15:27:27 +00:00
|
|
|
VIR_FREE(xml_buf);
|
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "domiftune" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domiftune[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("get/set parameters of a virtual interface")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get/set parameters of a domain's virtual interface.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domiftune[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "interface",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("interface device (MAC Address)")
|
|
|
|
},
|
|
|
|
{.name = "inbound",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("control domain's incoming traffics")
|
|
|
|
},
|
|
|
|
{.name = "outbound",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("control domain's outgoing traffics")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name = NULL, *device = NULL,
|
|
|
|
*inboundStr = NULL, *outboundStr = NULL;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
int nparams = 0;
|
2013-01-15 23:04:33 +00:00
|
|
|
int maxparams = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
virNetDevBandwidthRate inbound, outbound;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0)
|
2013-01-15 23:04:33 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 ||
|
2013-11-19 22:50:56 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
memset(&inbound, 0, sizeof(inbound));
|
|
|
|
memset(&outbound, 0, sizeof(outbound));
|
|
|
|
|
|
|
|
if (inboundStr) {
|
|
|
|
if (parseRateStr(inboundStr, &inbound) < 0) {
|
|
|
|
vshError(ctl, _("inbound format is incorrect"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-06-26 08:06:57 +00:00
|
|
|
/* we parse the rate as unsigned long long, but the API
|
|
|
|
* only accepts UINT */
|
|
|
|
if (inbound.average > UINT_MAX || inbound.peak > UINT_MAX ||
|
|
|
|
inbound.burst > UINT_MAX) {
|
|
|
|
vshError(ctl, _("inbound rate larger than maximum %u"),
|
|
|
|
UINT_MAX);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-18 09:50:02 +00:00
|
|
|
if (inbound.average == 0 && (inbound.burst || inbound.peak)) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("inbound average is mandatory"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-01-15 23:04:33 +00:00
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_IN_AVERAGE,
|
|
|
|
inbound.average) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
|
|
|
if (inbound.peak &&
|
|
|
|
virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_IN_PEAK,
|
|
|
|
inbound.peak) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
|
|
|
if (inbound.burst &&
|
|
|
|
virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_IN_BURST,
|
|
|
|
inbound.burst) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2013-01-15 23:04:33 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (outboundStr) {
|
|
|
|
if (parseRateStr(outboundStr, &outbound) < 0) {
|
|
|
|
vshError(ctl, _("outbound format is incorrect"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-06-26 08:06:57 +00:00
|
|
|
if (outbound.average > UINT_MAX || outbound.peak > UINT_MAX ||
|
|
|
|
outbound.burst > UINT_MAX) {
|
|
|
|
vshError(ctl, _("outbound rate larger than maximum %u"),
|
|
|
|
UINT_MAX);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-18 09:50:02 +00:00
|
|
|
if (outbound.average == 0 && (outbound.burst || outbound.peak)) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("outbound average is mandatory"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-01-15 23:04:33 +00:00
|
|
|
|
|
|
|
if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE,
|
|
|
|
outbound.average) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
|
|
|
if (outbound.peak &&
|
|
|
|
virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_OUT_PEAK,
|
|
|
|
outbound.peak) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
|
|
|
if (outbound.burst &&
|
|
|
|
virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_BANDWIDTH_OUT_BURST,
|
|
|
|
outbound.burst) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* get the number of interface parameters */
|
|
|
|
if (virDomainGetInterfaceParameters(dom, device, NULL, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get number of interface parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* nothing to output */
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get all interface parameters */
|
|
|
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
|
|
if (virDomainGetInterfaceParameters(dom, device, params, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to get interface parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-15 23:04:33 +00:00
|
|
|
if (virDomainSetInterfaceParameters(dom, device, params,
|
|
|
|
nparams, flags) != 0)
|
|
|
|
goto error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-15 23:04:33 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
2013-01-15 23:04:33 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-01-15 23:04:33 +00:00
|
|
|
vshSaveLibvirtError();
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2013-01-15 23:04:33 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to set interface parameters"));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "suspend" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_suspend[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("suspend a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Suspend a running domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_suspend[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSuspend(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainSuspend(dom) == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s suspended\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to suspend domain %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "dompmsuspend" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_dom_pm_suspend[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("suspend a domain gracefully using power management "
|
|
|
|
"functions")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Suspends a running domain using guest OS's power management. "
|
2012-07-25 15:37:18 +00:00
|
|
|
"(Note: This requires a guest agent configured and running in "
|
2013-02-07 15:25:10 +00:00
|
|
|
"the guest OS).")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_dom_pm_suspend[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "target",
|
2014-11-11 02:12:20 +00:00
|
|
|
.type = VSH_OT_DATA,
|
2013-01-14 11:26:54 +00:00
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("mem(Suspend-to-RAM), "
|
|
|
|
"disk(Suspend-to-Disk), "
|
|
|
|
"hybrid(Hybrid-Suspend)")
|
|
|
|
},
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "duration",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
|
|
|
.help = N_("duration in seconds")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
bool ret = false;
|
|
|
|
const char *target = NULL;
|
|
|
|
unsigned int suspendTarget;
|
|
|
|
unsigned long long duration = 0;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-09-03 19:39:21 +00:00
|
|
|
if (STREQ(target, "mem")) {
|
2012-07-25 15:37:18 +00:00
|
|
|
suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (STREQ(target, "disk")) {
|
2012-07-25 15:37:18 +00:00
|
|
|
suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (STREQ(target, "hybrid")) {
|
2012-07-25 15:37:18 +00:00
|
|
|
suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("Invalid target"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0) {
|
|
|
|
vshError(ctl, _("Domain %s could not be suspended"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Domain %s successfully suspended"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "dompmwakeup" command
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const vshCmdInfo info_dom_pm_wakeup[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("wakeup a domain from pmsuspended state")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Wakeup a domain that was previously suspended "
|
|
|
|
"by power management.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_dom_pm_wakeup[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainPMWakeup(dom, flags) < 0) {
|
|
|
|
vshError(ctl, _("Domain %s could not be woken up"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Domain %s successfully woken up"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "undefine" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_undefine[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("undefine a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Undefine an inactive domain, or convert persistent to transient.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_undefine[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name or uuid")
|
|
|
|
},
|
|
|
|
{.name = "managed-save",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("remove domain managed state file")
|
|
|
|
},
|
|
|
|
{.name = "storage",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("remove associated storage volumes (comma separated list of "
|
|
|
|
"targets or source paths) (see domblklist)")
|
|
|
|
},
|
|
|
|
{.name = "remove-all-storage",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("remove all associated storage volumes (use with caution)")
|
|
|
|
},
|
|
|
|
{.name = "wipe-storage",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("wipe data on the removed volumes")
|
|
|
|
},
|
|
|
|
{.name = "snapshots-metadata",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("remove all domain snapshot metadata, if inactive")
|
|
|
|
},
|
2014-09-11 11:17:11 +00:00
|
|
|
{.name = "nvram",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("remove nvram file, if inactive")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2012-06-22 12:16:24 +00:00
|
|
|
typedef struct {
|
|
|
|
virStorageVolPtr vol;
|
|
|
|
char *source;
|
|
|
|
char *target;
|
|
|
|
} vshUndefineVolume;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdUndefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
const char *name = NULL;
|
|
|
|
/* Flags to attempt. */
|
|
|
|
unsigned int flags = 0;
|
|
|
|
/* User-requested actions. */
|
|
|
|
bool managed_save = vshCommandOptBool(cmd, "managed-save");
|
|
|
|
bool snapshots_metadata = vshCommandOptBool(cmd, "snapshots-metadata");
|
|
|
|
bool wipe_storage = vshCommandOptBool(cmd, "wipe-storage");
|
|
|
|
bool remove_all_storage = vshCommandOptBool(cmd, "remove-all-storage");
|
2014-09-11 11:17:11 +00:00
|
|
|
bool nvram = vshCommandOptBool(cmd, "nvram");
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Positive if these items exist. */
|
|
|
|
int has_managed_save = 0;
|
|
|
|
int has_snapshots_metadata = 0;
|
|
|
|
int has_snapshots = 0;
|
|
|
|
/* True if undefine will not strand data, even on older servers. */
|
|
|
|
bool managed_save_safe = false;
|
|
|
|
bool snapshots_safe = false;
|
|
|
|
int rc = -1;
|
|
|
|
int running;
|
|
|
|
/* list of volumes to remove along with this domain */
|
2013-08-15 14:48:20 +00:00
|
|
|
const char *vol_string = NULL; /* string containing volumes to delete */
|
|
|
|
char **vol_list = NULL; /* tokenized vol_string */
|
|
|
|
int nvol_list = 0;
|
|
|
|
vshUndefineVolume *vols = NULL; /* info about the volumes to delete*/
|
|
|
|
size_t nvols = 0;
|
|
|
|
char *def = NULL; /* domain def */
|
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */
|
|
|
|
int nvol_nodes;
|
2012-07-25 15:37:18 +00:00
|
|
|
char *source = NULL;
|
|
|
|
char *target = NULL;
|
2013-12-18 13:54:07 +00:00
|
|
|
char *pool = NULL;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
size_t j;
|
2012-06-22 12:16:24 +00:00
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
ignore_value(vshCommandOptString(ctl, cmd, "storage", &vol_string));
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-05-14 06:15:37 +00:00
|
|
|
if (!(vol_string || remove_all_storage) && wipe_storage) {
|
|
|
|
vshError(ctl,
|
|
|
|
_("'--wipe-storage' requires '--storage <string>' or "
|
|
|
|
"'--remove-all-storage'"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (managed_save) {
|
|
|
|
flags |= VIR_DOMAIN_UNDEFINE_MANAGED_SAVE;
|
|
|
|
managed_save_safe = true;
|
|
|
|
}
|
|
|
|
if (snapshots_metadata) {
|
|
|
|
flags |= VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA;
|
|
|
|
snapshots_safe = true;
|
|
|
|
}
|
2014-11-13 14:20:51 +00:00
|
|
|
if (nvram)
|
2014-09-11 11:17:11 +00:00
|
|
|
flags |= VIR_DOMAIN_UNDEFINE_NVRAM;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Do some flag manipulation. The goal here is to disable bits
|
|
|
|
* from flags to reduce the likelihood of a server rejecting
|
|
|
|
* unknown flag bits, as well as to track conditions which are
|
|
|
|
* safe by default for the given hypervisor and server version. */
|
2012-06-22 12:16:24 +00:00
|
|
|
if ((running = virDomainIsActive(dom)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (!running) {
|
|
|
|
/* Undefine with snapshots only fails for inactive domains,
|
|
|
|
* and managed save only exists on inactive domains; if
|
|
|
|
* running, then we don't want to remove anything. */
|
|
|
|
has_managed_save = virDomainHasManagedSaveImage(dom, 0);
|
|
|
|
if (has_managed_save < 0) {
|
2012-06-22 12:16:24 +00:00
|
|
|
if (last_error->code != VIR_ERR_NO_SUPPORT)
|
|
|
|
goto error;
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
has_managed_save = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
has_snapshots = virDomainSnapshotNum(dom, 0);
|
|
|
|
if (has_snapshots < 0) {
|
2012-06-22 12:16:24 +00:00
|
|
|
if (last_error->code != VIR_ERR_NO_SUPPORT)
|
|
|
|
goto error;
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
has_snapshots = 0;
|
|
|
|
}
|
|
|
|
if (has_snapshots) {
|
|
|
|
has_snapshots_metadata
|
|
|
|
= virDomainSnapshotNum(dom, VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
|
|
|
|
if (has_snapshots_metadata < 0) {
|
|
|
|
/* The server did not know the new flag, assume that all
|
|
|
|
snapshots have metadata. */
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
has_snapshots_metadata = has_snapshots;
|
|
|
|
} else {
|
|
|
|
/* The server knew the new flag, all aspects of
|
|
|
|
* undefineFlags are safe. */
|
|
|
|
managed_save_safe = snapshots_safe = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_managed_save) {
|
|
|
|
flags &= ~VIR_DOMAIN_UNDEFINE_MANAGED_SAVE;
|
|
|
|
managed_save_safe = true;
|
|
|
|
}
|
2014-11-13 14:20:51 +00:00
|
|
|
if (has_snapshots == 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
snapshots_safe = true;
|
|
|
|
if (has_snapshots_metadata == 0) {
|
|
|
|
flags &= ~VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA;
|
|
|
|
snapshots_safe = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stash domain description for later use */
|
2013-08-15 14:48:20 +00:00
|
|
|
if (vol_string || remove_all_storage) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (running) {
|
2013-08-15 14:48:20 +00:00
|
|
|
vshError(ctl,
|
|
|
|
_("Storage volume deletion is supported only on "
|
|
|
|
"stopped domains"));
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:48:20 +00:00
|
|
|
if (vol_string && remove_all_storage) {
|
|
|
|
vshError(ctl,
|
|
|
|
_("Specified both --storage and --remove-all-storage"));
|
2012-06-22 12:16:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (!(def = virDomainGetXMLDesc(dom, 0))) {
|
|
|
|
vshError(ctl, _("Could not retrieve domain XML description"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-06-22 12:16:24 +00:00
|
|
|
|
|
|
|
if (!(doc = virXMLParseStringCtxt(def, _("(domain_definition)"),
|
|
|
|
&ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
2013-10-17 01:42:25 +00:00
|
|
|
/* tokenize the string from user and save its parts into an array */
|
2013-08-15 14:48:20 +00:00
|
|
|
if (vol_string &&
|
|
|
|
(nvol_list = vshStringToArray(vol_string, &vol_list)) < 0)
|
2012-06-22 12:16:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-08-15 14:48:20 +00:00
|
|
|
if ((nvol_nodes = virXPathNodeSet("./devices/disk", ctxt,
|
|
|
|
&vol_nodes)) < 0)
|
|
|
|
goto error;
|
2012-06-22 12:16:24 +00:00
|
|
|
|
2013-08-15 14:48:20 +00:00
|
|
|
for (i = 0; i < nvol_nodes; i++) {
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
ctxt->node = vol_nodes[i];
|
2013-08-15 14:48:20 +00:00
|
|
|
vshUndefineVolume vol;
|
2013-08-12 14:09:53 +00:00
|
|
|
VIR_FREE(source);
|
|
|
|
VIR_FREE(target);
|
2013-12-18 13:54:07 +00:00
|
|
|
VIR_FREE(pool);
|
2012-06-22 12:16:24 +00:00
|
|
|
|
|
|
|
/* get volume source and target paths */
|
|
|
|
if (!(target = virXPathString("string(./target/@dev)", ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(source = virXPathString("string("
|
|
|
|
"./source/@file|"
|
|
|
|
"./source/@dir|"
|
|
|
|
"./source/@name|"
|
2013-12-18 13:54:07 +00:00
|
|
|
"./source/@dev|"
|
|
|
|
"./source/@volume)", ctxt)))
|
2013-08-15 14:48:20 +00:00
|
|
|
continue;
|
2012-06-22 12:16:24 +00:00
|
|
|
|
2013-12-18 13:54:07 +00:00
|
|
|
pool = virXPathString("string(./source/@pool)", ctxt);
|
|
|
|
|
2012-06-22 12:16:24 +00:00
|
|
|
/* lookup if volume was selected by user */
|
2013-08-15 14:48:20 +00:00
|
|
|
if (vol_list) {
|
|
|
|
bool found = false;
|
|
|
|
for (j = 0; j < nvol_list; j++) {
|
|
|
|
if (STREQ_NULLABLE(vol_list[j], target) ||
|
|
|
|
STREQ_NULLABLE(vol_list[j], source)) {
|
|
|
|
VIR_FREE(vol_list[j]);
|
|
|
|
found = true;
|
2012-06-22 12:16:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-15 14:48:20 +00:00
|
|
|
if (!found)
|
2012-06-22 12:16:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-12-18 13:54:07 +00:00
|
|
|
if (pool) {
|
|
|
|
virStoragePoolPtr storagepool = NULL;
|
|
|
|
|
|
|
|
if (!source) {
|
|
|
|
vshPrint(ctl,
|
|
|
|
_("Missing storage volume name for disk '%s'"),
|
|
|
|
target);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(storagepool = virStoragePoolLookupByName(ctl->conn,
|
|
|
|
pool))) {
|
|
|
|
vshPrint(ctl,
|
|
|
|
_("Storage pool '%s' for volume '%s' not found."),
|
|
|
|
pool, target);
|
|
|
|
vshResetLibvirtError();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
vol.vol = virStorageVolLookupByName(storagepool, source);
|
|
|
|
virStoragePoolFree(storagepool);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
vol.vol = virStorageVolLookupByPath(ctl->conn, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vol.vol) {
|
2012-06-22 12:16:24 +00:00
|
|
|
vshPrint(ctl,
|
|
|
|
_("Storage volume '%s'(%s) is not managed by libvirt. "
|
|
|
|
"Remove it manually.\n"), target, source);
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-06-22 12:16:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-08-15 14:48:20 +00:00
|
|
|
|
|
|
|
vol.source = source;
|
|
|
|
vol.target = target;
|
2013-08-12 14:09:53 +00:00
|
|
|
source = NULL;
|
|
|
|
target = NULL;
|
2013-08-15 14:48:20 +00:00
|
|
|
if (VIR_APPEND_ELEMENT(vols, nvols, vol) < 0)
|
|
|
|
goto cleanup;
|
2012-06-22 12:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print volumes specified by user that were not found in domain definition */
|
2013-08-15 14:48:20 +00:00
|
|
|
if (vol_list) {
|
|
|
|
bool found = false;
|
|
|
|
for (i = 0; i < nvol_list; i++) {
|
|
|
|
if (vol_list[i]) {
|
|
|
|
vshError(ctl,
|
|
|
|
_("Volume '%s' was not found in domain's "
|
|
|
|
"definition.\n"), vol_list[i]);
|
|
|
|
found = true;
|
2012-06-22 12:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:48:20 +00:00
|
|
|
if (found)
|
2012-06-22 12:16:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generally we want to try the new API first. However, while
|
|
|
|
* virDomainUndefineFlags was introduced at the same time as
|
|
|
|
* VIR_DOMAIN_UNDEFINE_MANAGED_SAVE in 0.9.4, the
|
|
|
|
* VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA flag was not present
|
|
|
|
* until 0.9.5; skip to piecewise emulation if we couldn't prove
|
2014-09-11 11:17:11 +00:00
|
|
|
* above that the new API is safe.
|
|
|
|
* Moreover, only the newer UndefineFlags() API understands
|
|
|
|
* the VIR_DOMAIN_UNDEFINE_NVRAM flag. So if user has
|
|
|
|
* specified --nvram we must use the Flags() API. */
|
|
|
|
if ((managed_save_safe && snapshots_safe) || nvram) {
|
2012-07-25 15:37:18 +00:00
|
|
|
rc = virDomainUndefineFlags(dom, flags);
|
2014-09-11 11:17:11 +00:00
|
|
|
if (rc == 0 || nvram ||
|
|
|
|
(last_error->code != VIR_ERR_NO_SUPPORT &&
|
|
|
|
last_error->code != VIR_ERR_INVALID_ARG))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The new API is unsupported or unsafe; fall back to doing things
|
|
|
|
* piecewise. */
|
|
|
|
if (has_managed_save) {
|
|
|
|
if (!managed_save) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Refusing to undefine while domain managed save "
|
|
|
|
"image exists"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virDomainManagedSaveRemove(dom, 0) < 0) {
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
vshReportError(ctl);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No way to emulate deletion of just snapshot metadata
|
|
|
|
* without support for the newer flags. Oh well. */
|
|
|
|
if (has_snapshots_metadata) {
|
|
|
|
vshError(ctl,
|
|
|
|
snapshots_metadata ?
|
|
|
|
_("Unable to remove metadata of %d snapshots") :
|
|
|
|
_("Refusing to undefine while %d snapshots exist"),
|
|
|
|
has_snapshots_metadata);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virDomainUndefine(dom);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
out:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s has been undefined\n"), name);
|
|
|
|
ret = true;
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to undefine domain %s"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to undefine storage volumes associated with this domain, if it's requested */
|
2012-06-22 12:16:24 +00:00
|
|
|
if (nvols) {
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; i < nvols; i++) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (wipe_storage) {
|
2012-06-22 12:16:24 +00:00
|
|
|
vshPrint(ctl, _("Wiping volume '%s'(%s) ... "),
|
2013-08-15 14:48:20 +00:00
|
|
|
vols[i].target, vols[i].source);
|
2012-07-25 15:37:18 +00:00
|
|
|
fflush(stdout);
|
2013-08-15 14:48:20 +00:00
|
|
|
if (virStorageVolWipe(vols[i].vol, 0) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed! Volume not removed."));
|
2012-06-22 12:16:24 +00:00
|
|
|
ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, _("Done.\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete the volume */
|
2013-08-15 14:48:20 +00:00
|
|
|
if (virStorageVolDelete(vols[i].vol, 0) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to remove storage volume '%s'(%s)"),
|
2013-08-15 14:48:20 +00:00
|
|
|
vols[i].target, vols[i].source);
|
2012-06-22 12:16:24 +00:00
|
|
|
ret = false;
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, _("Volume '%s'(%s) removed.\n"),
|
2013-08-15 14:48:20 +00:00
|
|
|
vols[i].target, vols[i].source);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-08-12 14:09:53 +00:00
|
|
|
VIR_FREE(source);
|
|
|
|
VIR_FREE(target);
|
2013-12-18 13:54:07 +00:00
|
|
|
VIR_FREE(pool);
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; i < nvols; i++) {
|
2013-08-15 14:48:20 +00:00
|
|
|
VIR_FREE(vols[i].source);
|
|
|
|
VIR_FREE(vols[i].target);
|
|
|
|
if (vols[i].vol)
|
|
|
|
virStorageVolFree(vols[i].vol);
|
2012-06-22 12:16:24 +00:00
|
|
|
}
|
2013-08-15 14:48:20 +00:00
|
|
|
VIR_FREE(vols);
|
|
|
|
|
|
|
|
for (i = 0; i < nvol_list; i++)
|
|
|
|
VIR_FREE(vol_list[i]);
|
|
|
|
VIR_FREE(vol_list);
|
2012-06-22 12:16:24 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(def);
|
|
|
|
VIR_FREE(vol_nodes);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
2012-06-22 12:16:24 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
vshReportError(ctl);
|
2012-06-22 12:16:24 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "start" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_start[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("start a (previously defined) inactive domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Start a domain, either from the last managedsave\n"
|
2012-07-25 15:37:18 +00:00
|
|
|
" state, or via a fresh boot if no managedsave state\n"
|
2013-02-07 15:25:10 +00:00
|
|
|
" is present.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_start[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("name of the inactive domain")
|
|
|
|
},
|
2012-07-25 15:37:18 +00:00
|
|
|
#ifndef WIN32
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "console",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("attach to console after creation")
|
|
|
|
},
|
2012-07-25 15:37:18 +00:00
|
|
|
#endif
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("leave the guest paused after creation")
|
|
|
|
},
|
|
|
|
{.name = "autodestroy",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("automatically destroy the guest when virsh disconnects")
|
|
|
|
},
|
|
|
|
{.name = "bypass-cache",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("avoid file system cache when loading")
|
|
|
|
},
|
|
|
|
{.name = "force-boot",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force fresh boot by discarding any managed save")
|
|
|
|
},
|
2013-07-11 15:32:14 +00:00
|
|
|
{.name = "pass-fds",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("pass file descriptors N,M,... to the guest")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2013-07-11 15:32:14 +00:00
|
|
|
static int
|
|
|
|
cmdStartGetFDs(vshControl *ctl,
|
|
|
|
const vshCmd *cmd,
|
|
|
|
size_t *nfdsret,
|
|
|
|
int **fdsret)
|
|
|
|
{
|
|
|
|
const char *fdopt;
|
|
|
|
char **fdlist = NULL;
|
|
|
|
int *fds = NULL;
|
|
|
|
size_t nfds = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*nfdsret = 0;
|
|
|
|
*fdsret = NULL;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "pass-fds", &fdopt) <= 0)
|
2013-07-11 15:32:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!(fdlist = virStringSplit(fdopt, ",", -1))) {
|
|
|
|
vshError(ctl, _("Unable to split FD list '%s'"), fdopt);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; fdlist[i] != NULL; i++) {
|
|
|
|
int fd;
|
|
|
|
if (virStrToLong_i(fdlist[i], NULL, 10, &fd) < 0) {
|
|
|
|
vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (VIR_EXPAND_N(fds, nfds, 1) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to allocate FD list"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
fds[nfds - 1] = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStringFreeList(fdlist);
|
|
|
|
|
|
|
|
*fdsret = fds;
|
|
|
|
*nfdsret = nfds;
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2013-07-11 15:32:14 +00:00
|
|
|
virStringFreeList(fdlist);
|
|
|
|
VIR_FREE(fds);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdStart(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
#ifndef WIN32
|
|
|
|
bool console = vshCommandOptBool(cmd, "console");
|
|
|
|
#endif
|
|
|
|
unsigned int flags = VIR_DOMAIN_NONE;
|
|
|
|
int rc;
|
2013-07-11 15:32:14 +00:00
|
|
|
size_t nfds = 0;
|
|
|
|
int *fds = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
|
|
|
|
VSH_BYNAME | VSH_BYUUID)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainGetID(dom) != (unsigned int)-1) {
|
|
|
|
vshError(ctl, "%s", _("Domain is already active"));
|
2014-02-20 09:29:15 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 15:32:14 +00:00
|
|
|
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
|
2014-02-20 09:29:15 +00:00
|
|
|
goto cleanup;
|
2013-07-11 15:32:14 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_START_PAUSED;
|
|
|
|
if (vshCommandOptBool(cmd, "autodestroy"))
|
|
|
|
flags |= VIR_DOMAIN_START_AUTODESTROY;
|
|
|
|
if (vshCommandOptBool(cmd, "bypass-cache"))
|
|
|
|
flags |= VIR_DOMAIN_START_BYPASS_CACHE;
|
|
|
|
if (vshCommandOptBool(cmd, "force-boot"))
|
|
|
|
flags |= VIR_DOMAIN_START_FORCE_BOOT;
|
|
|
|
|
|
|
|
/* We can emulate force boot, even for older servers that reject it. */
|
|
|
|
if (flags & VIR_DOMAIN_START_FORCE_BOOT) {
|
2013-07-11 15:32:14 +00:00
|
|
|
if ((nfds ?
|
|
|
|
virDomainCreateWithFiles(dom, nfds, fds, flags) :
|
|
|
|
virDomainCreateWithFlags(dom, flags)) == 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto started;
|
|
|
|
if (last_error->code != VIR_ERR_NO_SUPPORT &&
|
|
|
|
last_error->code != VIR_ERR_INVALID_ARG) {
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
vshReportError(ctl);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
rc = virDomainHasManagedSaveImage(dom, 0);
|
|
|
|
if (rc < 0) {
|
|
|
|
/* No managed save image to remove */
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (rc > 0) {
|
|
|
|
if (virDomainManagedSaveRemove(dom, 0) < 0) {
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
vshReportError(ctl);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flags &= ~VIR_DOMAIN_START_FORCE_BOOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prefer older API unless we have to pass a flag. */
|
2013-07-11 15:32:14 +00:00
|
|
|
if ((nfds ? virDomainCreateWithFiles(dom, nfds, fds, flags) :
|
|
|
|
(flags ? virDomainCreateWithFlags(dom, flags)
|
|
|
|
: virDomainCreate(dom))) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to start domain %s"), virDomainGetName(dom));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
started:
|
2012-07-25 15:37:18 +00:00
|
|
|
vshPrint(ctl, _("Domain %s started\n"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
#ifndef WIN32
|
|
|
|
if (console && !cmdRunConsole(ctl, dom, NULL, 0))
|
|
|
|
goto cleanup;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
2013-07-11 15:32:14 +00:00
|
|
|
VIR_FREE(fds);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "save" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_save[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("save a domain state to a file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Save the RAM state of a running domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_save[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("where to save the data")
|
|
|
|
},
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "bypass-cache",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("avoid file system cache when saving")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "xml",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("filename containing updated XML for the target")
|
|
|
|
},
|
|
|
|
{.name = "running",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be running on restore")
|
|
|
|
},
|
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be paused on restore")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("display the progress of save")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
doSave(void *opaque)
|
|
|
|
{
|
|
|
|
vshCtrlData *data = opaque;
|
|
|
|
vshControl *ctl = data->ctl;
|
|
|
|
const vshCmd *cmd = data->cmd;
|
|
|
|
char ret = '1';
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *name = NULL;
|
|
|
|
const char *to = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
const char *xmlfile = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
sigset_t sigmask, oldsigmask;
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
|
|
|
goto out_sig;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "bypass-cache"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
|
|
|
|
if (vshCommandOptBool(cmd, "running"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_RUNNING;
|
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_PAUSED;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (xmlfile &&
|
2014-10-14 08:04:31 +00:00
|
|
|
virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) {
|
2012-11-15 13:25:09 +00:00
|
|
|
vshReportError(ctl);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
2012-11-15 13:25:09 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (((flags || xml)
|
|
|
|
? virDomainSaveFlags(dom, to, xml, flags)
|
|
|
|
: virDomainSave(dom, to)) < 0) {
|
|
|
|
vshError(ctl, _("Failed to save domain %s to %s"), name, to);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = '0';
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
out:
|
2012-07-25 15:37:18 +00:00
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2014-03-25 06:53:59 +00:00
|
|
|
out_sig:
|
2014-09-09 15:13:29 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
|
|
|
}
|
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
typedef void (*jobWatchTimeoutFunc)(vshControl *ctl, virDomainPtr dom,
|
|
|
|
void *opaque);
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
|
2012-08-18 03:23:07 +00:00
|
|
|
static bool
|
|
|
|
vshWatchJob(vshControl *ctl,
|
|
|
|
virDomainPtr dom,
|
|
|
|
bool verbose,
|
|
|
|
int pipe_fd,
|
2014-02-14 00:08:42 +00:00
|
|
|
int timeout_ms,
|
2012-08-18 03:23:07 +00:00
|
|
|
jobWatchTimeoutFunc timeout_func,
|
|
|
|
void *opaque,
|
|
|
|
const char *label)
|
|
|
|
{
|
|
|
|
struct sigaction sig_action;
|
|
|
|
struct sigaction old_sig_action;
|
2013-08-29 13:18:20 +00:00
|
|
|
struct pollfd pollfd[2] = {{.fd = pipe_fd, .events = POLLIN, .revents = 0},
|
|
|
|
{.fd = STDIN_FILENO, .events = POLLIN, .revents = 0}};
|
2012-08-18 03:23:07 +00:00
|
|
|
struct timeval start, curr;
|
|
|
|
virDomainJobInfo jobinfo;
|
|
|
|
int ret = -1;
|
|
|
|
char retchar;
|
|
|
|
bool functionReturn = false;
|
|
|
|
sigset_t sigmask, oldsigmask;
|
2013-08-29 13:18:20 +00:00
|
|
|
bool jobStarted = false;
|
2013-10-22 14:01:26 +00:00
|
|
|
nfds_t npollfd = 2;
|
2012-08-18 03:23:07 +00:00
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
|
|
|
|
intCaught = 0;
|
|
|
|
sig_action.sa_sigaction = vshCatchInt;
|
|
|
|
sig_action.sa_flags = SA_SIGINFO;
|
|
|
|
sigemptyset(&sig_action.sa_mask);
|
|
|
|
sigaction(SIGINT, &sig_action, &old_sig_action);
|
|
|
|
|
2013-10-22 14:01:26 +00:00
|
|
|
/* don't poll on STDIN if we are not using a terminal */
|
|
|
|
if (!vshTTYAvailable(ctl))
|
|
|
|
npollfd = 1;
|
|
|
|
|
2012-08-18 03:23:07 +00:00
|
|
|
GETTIMEOFDAY(&start);
|
|
|
|
while (1) {
|
2013-10-22 14:01:26 +00:00
|
|
|
ret = poll((struct pollfd *)&pollfd, npollfd, 500);
|
2012-08-18 03:23:07 +00:00
|
|
|
if (ret > 0) {
|
2013-08-29 13:18:20 +00:00
|
|
|
if (pollfd[1].revents & POLLIN &&
|
|
|
|
saferead(STDIN_FILENO, &retchar, sizeof(retchar)) > 0) {
|
2015-06-01 13:06:16 +00:00
|
|
|
if (vshTTYIsInterruptCharacter(ctl, retchar))
|
2013-08-29 13:18:20 +00:00
|
|
|
virDomainAbortJob(dom);
|
2015-06-01 13:06:16 +00:00
|
|
|
continue;
|
2013-08-29 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pollfd[0].revents & POLLIN &&
|
2012-08-18 03:23:07 +00:00
|
|
|
saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 &&
|
|
|
|
retchar == '0') {
|
|
|
|
if (verbose) {
|
|
|
|
/* print [100 %] */
|
2013-08-26 10:31:51 +00:00
|
|
|
vshPrintJobProgress(label, 0, 1);
|
2012-08-18 03:23:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
if (intCaught) {
|
|
|
|
virDomainAbortJob(dom);
|
|
|
|
intCaught = 0;
|
|
|
|
}
|
2015-06-01 13:06:16 +00:00
|
|
|
continue;
|
2012-08-18 03:23:07 +00:00
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
GETTIMEOFDAY(&curr);
|
2014-02-14 00:08:42 +00:00
|
|
|
if (timeout_ms && (((int)(curr.tv_sec - start.tv_sec) * 1000 +
|
|
|
|
(int)(curr.tv_usec - start.tv_usec) / 1000) >
|
|
|
|
timeout_ms)) {
|
2012-08-18 03:23:07 +00:00
|
|
|
/* suspend the domain when migration timeouts. */
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label);
|
|
|
|
if (timeout_func)
|
|
|
|
(timeout_func)(ctl, dom, opaque);
|
2014-02-14 00:08:42 +00:00
|
|
|
timeout_ms = 0;
|
2012-08-18 03:23:07 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 13:18:20 +00:00
|
|
|
if (verbose || !jobStarted) {
|
2012-08-18 03:23:07 +00:00
|
|
|
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
|
|
|
ret = virDomainGetJobInfo(dom, &jobinfo);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2013-08-29 13:18:20 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
if (verbose)
|
|
|
|
vshPrintJobProgress(label, jobinfo.dataRemaining,
|
|
|
|
jobinfo.dataTotal);
|
|
|
|
|
|
|
|
if (!jobStarted &&
|
|
|
|
(jobinfo.type == VIR_DOMAIN_JOB_BOUNDED ||
|
|
|
|
jobinfo.type == VIR_DOMAIN_JOB_UNBOUNDED)) {
|
|
|
|
vshTTYDisableInterrupt(ctl);
|
|
|
|
jobStarted = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vshResetLibvirtError();
|
|
|
|
}
|
2012-08-18 03:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
functionReturn = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-08-18 03:23:07 +00:00
|
|
|
sigaction(SIGINT, &old_sig_action, NULL);
|
2013-08-29 13:18:20 +00:00
|
|
|
vshTTYRestore(ctl);
|
2012-08-18 03:23:07 +00:00
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdSave(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int p[2] = {-1. -1};
|
|
|
|
virThread workerThread;
|
|
|
|
bool verbose = false;
|
|
|
|
vshCtrlData data;
|
|
|
|
const char *to = NULL;
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "verbose"))
|
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
if (pipe(p) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data.ctl = ctl;
|
|
|
|
data.cmd = cmd;
|
|
|
|
data.writefd = p[1];
|
|
|
|
|
|
|
|
if (virThreadCreate(&workerThread,
|
|
|
|
true,
|
|
|
|
doSave,
|
|
|
|
&data) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Save"));
|
|
|
|
|
|
|
|
virThreadJoin(&workerThread);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
vshPrint(ctl, _("\nDomain %s saved to %s\n"), name, to);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2014-09-09 15:13:29 +00:00
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "save-image-dumpxml" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_save_image_dumpxml[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("saved state domain information in XML")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Dump XML of domain information for a saved state file to stdout.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_save_image_dumpxml[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("saved state file to read")
|
|
|
|
},
|
|
|
|
{.name = "security-info",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("include security sensitive information in XML dump")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *file = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "security-info"))
|
|
|
|
flags |= VIR_DOMAIN_XML_SECURE;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
xml = virDomainSaveImageGetXMLDesc(ctl->conn, file, flags);
|
|
|
|
if (!xml)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s", xml);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "save-image-define" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_save_image_define[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("redefine the XML for a domain's saved state file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Replace the domain XML associated with a saved state file")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_save_image_define[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("saved state file to modify")
|
|
|
|
},
|
|
|
|
{.name = "xml",
|
2014-11-11 02:12:20 +00:00
|
|
|
.type = VSH_OT_DATA,
|
2013-01-14 11:26:54 +00:00
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("filename containing updated XML for the target")
|
|
|
|
},
|
|
|
|
{.name = "running",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be running on restore")
|
|
|
|
},
|
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be paused on restore")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *file = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
const char *xmlfile = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "running"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_RUNNING;
|
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_PAUSED;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2014-10-14 08:04:31 +00:00
|
|
|
if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainSaveImageDefineXML(ctl->conn, file, xml, flags) < 0) {
|
|
|
|
vshError(ctl, _("Failed to update %s"), file);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("State file %s updated.\n"), file);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "save-image-edit" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_save_image_edit[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("edit XML for a domain's saved state file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Edit the domain XML associated with a saved state file")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_save_image_edit[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("saved state file to edit")
|
|
|
|
},
|
|
|
|
{.name = "running",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be running on restore")
|
|
|
|
},
|
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be paused on restore")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *file = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE;
|
|
|
|
unsigned int define_flags = 0;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "running"))
|
|
|
|
define_flags |= VIR_DOMAIN_SAVE_RUNNING;
|
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
define_flags |= VIR_DOMAIN_SAVE_PAUSED;
|
|
|
|
|
|
|
|
/* Normally, we let the API reject mutually exclusive flags.
|
|
|
|
* However, in the edit cycle, we let the user retry if the define
|
|
|
|
* step fails, but the define step will always fail on invalid
|
|
|
|
* flags, so we reject it up front to avoid looping. */
|
|
|
|
if (define_flags == (VIR_DOMAIN_SAVE_RUNNING | VIR_DOMAIN_SAVE_PAUSED)) {
|
2013-03-07 09:51:01 +00:00
|
|
|
vshError(ctl, "%s", _("--running and --paused are mutually exclusive"));
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#define EDIT_GET_XML \
|
|
|
|
virDomainSaveImageGetXMLDesc(ctl->conn, file, getxml_flags)
|
2014-11-14 14:57:17 +00:00
|
|
|
#define EDIT_NOT_CHANGED \
|
|
|
|
do { \
|
|
|
|
vshPrint(ctl, _("Saved image %s XML configuration " \
|
|
|
|
"not changed.\n"), file); \
|
|
|
|
ret = true; \
|
|
|
|
goto edit_cleanup; \
|
|
|
|
} while (0)
|
2012-07-25 15:37:18 +00:00
|
|
|
#define EDIT_DEFINE \
|
2012-08-10 13:20:43 +00:00
|
|
|
(virDomainSaveImageDefineXML(ctl->conn, file, doc_edited, define_flags) == 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
#include "virsh-edit.c"
|
|
|
|
|
|
|
|
vshPrint(ctl, _("State file %s edited.\n"), file);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "managedsave" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_managedsave[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("managed save of a domain state")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Save and destroy a running domain, so it can be restarted from\n"
|
2012-07-25 15:37:18 +00:00
|
|
|
" the same state at a later time. When the virsh 'start'\n"
|
|
|
|
" command is next run for the domain, it will automatically\n"
|
2013-02-07 15:25:10 +00:00
|
|
|
" be started from this saved state.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_managedsave[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "bypass-cache",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("avoid file system cache when saving")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "running",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be running on next start")
|
|
|
|
},
|
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set domain to be paused on next start")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("display the progress of save")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
doManagedsave(void *opaque)
|
|
|
|
{
|
|
|
|
char ret = '1';
|
|
|
|
vshCtrlData *data = opaque;
|
|
|
|
vshControl *ctl = data->ctl;
|
|
|
|
const vshCmd *cmd = data->cmd;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
sigset_t sigmask, oldsigmask;
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
|
|
|
goto out_sig;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "bypass-cache"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
|
|
|
|
if (vshCommandOptBool(cmd, "running"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_RUNNING;
|
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_PAUSED;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (virDomainManagedSave(dom, flags) < 0) {
|
|
|
|
vshError(ctl, _("Failed to save domain %s state"), name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = '0';
|
2014-03-25 06:53:59 +00:00
|
|
|
out:
|
2012-07-25 15:37:18 +00:00
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2014-03-25 06:53:59 +00:00
|
|
|
out_sig:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int p[2] = { -1, -1};
|
|
|
|
bool ret = false;
|
|
|
|
bool verbose = false;
|
|
|
|
const char *name = NULL;
|
|
|
|
vshCtrlData data;
|
|
|
|
virThread workerThread;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "verbose"))
|
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
if (pipe(p) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data.ctl = ctl;
|
|
|
|
data.cmd = cmd;
|
|
|
|
data.writefd = p[1];
|
|
|
|
|
|
|
|
if (virThreadCreate(&workerThread,
|
|
|
|
true,
|
|
|
|
doManagedsave,
|
|
|
|
&data) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = vshWatchJob(ctl, dom, verbose, p[0], 0,
|
|
|
|
NULL, NULL, _("Managedsave"));
|
|
|
|
|
|
|
|
virThreadJoin(&workerThread);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
vshPrint(ctl, _("\nDomain %s state saved by libvirt\n"), name);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
VIR_FORCE_CLOSE(p[0]);
|
|
|
|
VIR_FORCE_CLOSE(p[1]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "managedsave-remove" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_managedsaveremove[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Remove managed save of a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Remove an existing managed save state file from a domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_managedsaveremove[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
bool ret = false;
|
|
|
|
int hassave;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hassave = virDomainHasManagedSaveImage(dom, 0);
|
|
|
|
if (hassave < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to check for domain managed save image"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hassave) {
|
|
|
|
if (virDomainManagedSaveRemove(dom, 0) < 0) {
|
|
|
|
vshError(ctl, _("Failed to remove managed save image for domain %s"),
|
|
|
|
name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vshPrint(ctl, _("Removed managedsave image for domain %s"), name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vshPrint(ctl, _("Domain %s has no manage save image; removal skipped"),
|
|
|
|
name);
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "schedinfo" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_schedinfo[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("show/set scheduler parameters")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Show/Set scheduler parameters.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_schedinfo[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "weight",
|
|
|
|
.type = VSH_OT_INT,
|
2013-03-15 13:42:42 +00:00
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("weight for XEN_CREDIT")
|
|
|
|
},
|
|
|
|
{.name = "cap",
|
|
|
|
.type = VSH_OT_INT,
|
2013-03-15 13:42:42 +00:00
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("cap for XEN_CREDIT")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get/set current scheduler info")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get/set value to be used on next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get/set value from running domain")
|
|
|
|
},
|
2013-03-15 13:42:42 +00:00
|
|
|
{.name = "set",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.flags = VSH_OFLAG_NONE,
|
|
|
|
.help = N_("parameter=value")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2013-03-15 13:42:42 +00:00
|
|
|
static int
|
|
|
|
cmdSchedInfoUpdateOne(vshControl *ctl,
|
|
|
|
virTypedParameterPtr src_params, int nsrc_params,
|
|
|
|
virTypedParameterPtr *params,
|
|
|
|
int *nparams, int *maxparams,
|
|
|
|
const char *field, const char *value)
|
|
|
|
{
|
|
|
|
virTypedParameterPtr param;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-03-15 13:42:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nsrc_params; i++) {
|
|
|
|
param = &(src_params[i]);
|
|
|
|
|
|
|
|
if (STRNEQ(field, param->field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (virTypedParamsAddFromString(params, nparams, maxparams,
|
|
|
|
field, param->type,
|
|
|
|
value) < 0) {
|
|
|
|
vshSaveLibvirtError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
vshError(ctl, _("invalid scheduler option: %s"), field);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static int
|
|
|
|
cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
|
2012-09-05 12:41:25 +00:00
|
|
|
virTypedParameterPtr src_params, int nsrc_params,
|
|
|
|
virTypedParameterPtr *update_params)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
2012-09-05 12:41:25 +00:00
|
|
|
char *set_field = NULL;
|
|
|
|
char *set_val = NULL;
|
2013-03-15 13:42:42 +00:00
|
|
|
const char *val = NULL;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
2012-09-05 12:41:25 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
int nparams = 0;
|
2013-01-15 23:06:20 +00:00
|
|
|
int maxparams = 0;
|
2012-09-05 12:41:25 +00:00
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2013-03-15 13:42:42 +00:00
|
|
|
set_field = vshStrdup(ctl, opt->data);
|
2012-09-05 12:41:25 +00:00
|
|
|
if (!(set_val = strchr(set_field, '='))) {
|
2013-03-15 13:42:42 +00:00
|
|
|
vshError(ctl, "%s", _("Invalid syntax for --set, "
|
|
|
|
"expecting name=value"));
|
2012-09-05 12:41:25 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2012-09-05 12:41:25 +00:00
|
|
|
|
|
|
|
*set_val = '\0';
|
|
|
|
set_val++;
|
|
|
|
|
2013-03-15 13:42:42 +00:00
|
|
|
if (cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
|
|
|
¶ms, &nparams, &maxparams,
|
|
|
|
set_field, set_val) < 0)
|
|
|
|
goto cleanup;
|
2012-09-05 12:41:25 +00:00
|
|
|
|
2013-03-15 13:42:42 +00:00
|
|
|
VIR_FREE(set_field);
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-15 13:42:42 +00:00
|
|
|
rv = vshCommandOptStringReq(ctl, cmd, "cap", &val);
|
|
|
|
if (rv < 0 ||
|
|
|
|
(val &&
|
|
|
|
cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
|
|
|
¶ms, &nparams, &maxparams,
|
|
|
|
"cap", val) < 0))
|
|
|
|
goto cleanup;
|
2012-09-05 12:41:25 +00:00
|
|
|
|
2013-03-15 13:42:42 +00:00
|
|
|
rv = vshCommandOptStringReq(ctl, cmd, "weight", &val);
|
|
|
|
if (rv < 0 ||
|
|
|
|
(val &&
|
|
|
|
cmdSchedInfoUpdateOne(ctl, src_params, nsrc_params,
|
|
|
|
¶ms, &nparams, &maxparams,
|
|
|
|
"weight", val) < 0))
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2012-09-05 12:41:25 +00:00
|
|
|
ret = nparams;
|
2013-03-15 13:42:42 +00:00
|
|
|
*update_params = params;
|
2012-09-05 12:41:25 +00:00
|
|
|
params = NULL;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-09-05 12:41:25 +00:00
|
|
|
VIR_FREE(set_field);
|
2013-01-15 23:06:20 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-09-05 12:41:25 +00:00
|
|
|
return ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
char *schedulertype;
|
|
|
|
virDomainPtr dom;
|
|
|
|
virTypedParameterPtr params = NULL;
|
2012-09-05 12:41:25 +00:00
|
|
|
virTypedParameterPtr updates = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
int nparams = 0;
|
2012-09-05 12:41:25 +00:00
|
|
|
int nupdates = 0;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool ret_val = false;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Print SchedulerType */
|
|
|
|
schedulertype = virDomainGetSchedulerType(dom, &nparams);
|
|
|
|
if (schedulertype != NULL) {
|
2012-12-03 13:17:29 +00:00
|
|
|
vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), schedulertype);
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(schedulertype);
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), _("Unknown"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams) {
|
|
|
|
params = vshMalloc(ctl, sizeof(*params) * nparams);
|
|
|
|
|
|
|
|
memset(params, 0, sizeof(*params) * nparams);
|
|
|
|
if (flags || current) {
|
|
|
|
/* We cannot query both live and config at once, so settle
|
|
|
|
on current in that case. If we are setting, then the
|
|
|
|
two values should match when we re-query; otherwise, we
|
|
|
|
report the error later. */
|
|
|
|
ret = virDomainGetSchedulerParametersFlags(dom, params, &nparams,
|
|
|
|
((live && config) ? 0
|
|
|
|
: flags));
|
|
|
|
} else {
|
|
|
|
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
|
|
|
|
}
|
|
|
|
if (ret == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* See if any params are being set */
|
2012-09-05 12:41:25 +00:00
|
|
|
if ((nupdates = cmdSchedInfoUpdate(ctl, cmd, params, nparams,
|
|
|
|
&updates)) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* Update parameters & refresh data */
|
2012-09-05 12:41:25 +00:00
|
|
|
if (nupdates > 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (flags || current)
|
2012-09-05 12:41:25 +00:00
|
|
|
ret = virDomainSetSchedulerParametersFlags(dom, updates,
|
|
|
|
nupdates, flags);
|
2012-07-25 15:37:18 +00:00
|
|
|
else
|
2012-09-05 12:41:25 +00:00
|
|
|
ret = virDomainSetSchedulerParameters(dom, updates, nupdates);
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (ret == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags || current)
|
|
|
|
ret = virDomainGetSchedulerParametersFlags(dom, params,
|
|
|
|
&nparams,
|
|
|
|
((live && config) ? 0
|
|
|
|
: flags));
|
|
|
|
else
|
|
|
|
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
|
|
|
|
if (ret == -1)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
/* When not doing --set, --live and --config do not mix. */
|
|
|
|
if (live && config) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("cannot query both live and config at once"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret_val = true;
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2013-01-15 23:06:20 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
|
|
|
virTypedParamsFree(updates, nupdates);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "restore" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_restore[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("restore a domain from a saved state in a file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Restore a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_restore[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the state to restore")
|
|
|
|
},
|
|
|
|
{.name = "bypass-cache",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("avoid file system cache when restoring")
|
|
|
|
},
|
|
|
|
{.name = "xml",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("filename containing updated XML for the target")
|
|
|
|
},
|
|
|
|
{.name = "running",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("restore domain into running state")
|
|
|
|
},
|
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("restore domain into paused state")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdRestore(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
const char *xmlfile = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "bypass-cache"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
|
|
|
|
if (vshCommandOptBool(cmd, "running"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_RUNNING;
|
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_SAVE_PAUSED;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (xmlfile &&
|
2014-10-14 08:04:31 +00:00
|
|
|
virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (((flags || xml)
|
|
|
|
? virDomainRestoreFlags(ctl->conn, from, xml, flags)
|
|
|
|
: virDomainRestore(ctl->conn, from)) < 0) {
|
|
|
|
vshError(ctl, _("Failed to restore domain from %s"), from);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Domain restored from %s\n"), from);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "dump" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_dump[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("dump the core of a domain to a file for analysis")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Core dump a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_dump[] = {
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("where to dump the core")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("perform a live core dump if supported")
|
|
|
|
},
|
|
|
|
{.name = "crash",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("crash the domain after core dump")
|
|
|
|
},
|
|
|
|
{.name = "bypass-cache",
|
|
|
|
.type = VSH_OT_BOOL,
|
2013-03-15 07:40:18 +00:00
|
|
|
.help = N_("avoid file system cache when dumping")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "reset",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("reset the domain after core dump")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("display the progress of dump")
|
|
|
|
},
|
|
|
|
{.name = "memory-only",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("dump domain's memory only")
|
|
|
|
},
|
2014-03-23 03:51:15 +00:00
|
|
|
{.name = "format",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-03-23 03:51:15 +00:00
|
|
|
.help = N_("specify the format of memory-only dump")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
doDump(void *opaque)
|
|
|
|
{
|
|
|
|
char ret = '1';
|
|
|
|
vshCtrlData *data = opaque;
|
|
|
|
vshControl *ctl = data->ctl;
|
|
|
|
const vshCmd *cmd = data->cmd;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
sigset_t sigmask, oldsigmask;
|
|
|
|
const char *name = NULL;
|
|
|
|
const char *to = NULL;
|
|
|
|
unsigned int flags = 0;
|
2014-03-23 03:51:15 +00:00
|
|
|
const char *format = NULL;
|
|
|
|
unsigned int dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_RAW;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
|
|
|
goto out_sig;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "live"))
|
|
|
|
flags |= VIR_DUMP_LIVE;
|
|
|
|
if (vshCommandOptBool(cmd, "crash"))
|
|
|
|
flags |= VIR_DUMP_CRASH;
|
|
|
|
if (vshCommandOptBool(cmd, "bypass-cache"))
|
|
|
|
flags |= VIR_DUMP_BYPASS_CACHE;
|
|
|
|
if (vshCommandOptBool(cmd, "reset"))
|
|
|
|
flags |= VIR_DUMP_RESET;
|
|
|
|
if (vshCommandOptBool(cmd, "memory-only"))
|
|
|
|
flags |= VIR_DUMP_MEMORY_ONLY;
|
|
|
|
|
2014-03-23 03:51:15 +00:00
|
|
|
if (vshCommandOptBool(cmd, "format")) {
|
|
|
|
if (!(flags & VIR_DUMP_MEMORY_ONLY)) {
|
|
|
|
vshError(ctl, "%s", _("--format only works with --memory-only"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "format", &format)) {
|
2014-03-23 03:51:15 +00:00
|
|
|
if (STREQ(format, "kdump-zlib")) {
|
|
|
|
dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB;
|
|
|
|
} else if (STREQ(format, "kdump-lzo")) {
|
|
|
|
dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO;
|
|
|
|
} else if (STREQ(format, "kdump-snappy")) {
|
|
|
|
dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY;
|
|
|
|
} else if (STREQ(format, "elf")) {
|
|
|
|
dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_RAW;
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("format '%s' is not supported, expecting "
|
|
|
|
"'kdump-zlib', 'kdump-lzo', 'kdump-snappy' "
|
|
|
|
"or 'elf'"), format);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) {
|
|
|
|
if (virDomainCoreDumpWithFormat(dom, to, dumpformat, flags) < 0) {
|
|
|
|
vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virDomainCoreDump(dom, to, flags) < 0) {
|
|
|
|
vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = '0';
|
2014-03-25 06:53:59 +00:00
|
|
|
out:
|
2012-07-25 15:37:18 +00:00
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2014-03-25 06:53:59 +00:00
|
|
|
out_sig:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDump(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int p[2] = { -1, -1};
|
|
|
|
bool ret = false;
|
|
|
|
bool verbose = false;
|
|
|
|
const char *name = NULL;
|
|
|
|
const char *to = NULL;
|
|
|
|
vshCtrlData data;
|
|
|
|
virThread workerThread;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
|
2013-09-27 22:02:31 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "verbose"))
|
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
if (pipe(p) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data.ctl = ctl;
|
|
|
|
data.cmd = cmd;
|
|
|
|
data.writefd = p[1];
|
|
|
|
|
|
|
|
if (virThreadCreate(&workerThread,
|
|
|
|
true,
|
|
|
|
doDump,
|
|
|
|
&data) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Dump"));
|
|
|
|
|
|
|
|
virThreadJoin(&workerThread);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
vshPrint(ctl, _("\nDomain %s dumped to %s\n"), name, to);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
VIR_FORCE_CLOSE(p[0]);
|
|
|
|
VIR_FORCE_CLOSE(p[1]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const vshCmdInfo info_screenshot[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("take a screenshot of a current domain console and store it "
|
|
|
|
"into a file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("screenshot of a current domain console")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_screenshot[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("where to store the screenshot")
|
|
|
|
},
|
|
|
|
{.name = "screen",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("ID of a screen to take screenshot of")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate string: '<domain name>-<timestamp>[<extension>]'
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
vshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
|
|
|
|
{
|
|
|
|
char timestr[100];
|
Pass a correct pointer type to localtime_r(3).
On 09/04/2012 08:20 AM, Eric Blake wrote:
> tv_sec is required by POSIX to be
> of type time_t; so this is a bug in the OpenBSD header
> [for declaring it as long]
Most likely this problem arose because of the patch I pushed
in gnulib commit e07d7c40f3ca5ec410cf5aa6fa03cfe51e712039.
Previously, gnulib required timeval's tv_sec to be
the same size as time_t. But now, it requires only that
tv_sec be big enough to hold a time_t.
This patch was needed for Emacs. Without the patch, gnulib
replaced struct timeval on OpenBSD, and this messed up
utimens.c, and Emacs wouldn't build.
Alternatively, gnulib could substitute its own struct timeval
for the system's, wrapping every struct timeval-using function
(gettimeofday, futimesat, futimes, lutimes, etc. That'd be
more work, though. And it would introduce some performance
issues with gettimeofday, which is supposed to be fast.
I've been trying to get away from using struct timeval,
and to use the higher-resolution struct timespec instead,
so messing with these obsolescent interfaces has been
lower priority for me. But if someone wants to take the
more-ambitious approach that'd be fine, I expect.
For this particular case, though, how about if we avoid
the problem entirely? libvirt doesn't need to use struct
timeval here at all. It makes libvirt smaller and probably
faster, and it ports to OpenBSD without messing with gnulib.
2012-09-04 17:03:41 +00:00
|
|
|
time_t cur_time;
|
2012-07-25 15:37:18 +00:00
|
|
|
struct tm time_info;
|
|
|
|
const char *ext = NULL;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!dom) {
|
|
|
|
vshError(ctl, "%s", _("Invalid domain supplied"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(mime, "image/x-portable-pixmap"))
|
|
|
|
ext = ".ppm";
|
|
|
|
else if (STREQ(mime, "image/png"))
|
|
|
|
ext = ".png";
|
|
|
|
/* add mime type here */
|
|
|
|
|
2012-09-04 23:35:27 +00:00
|
|
|
time(&cur_time);
|
Pass a correct pointer type to localtime_r(3).
On 09/04/2012 08:20 AM, Eric Blake wrote:
> tv_sec is required by POSIX to be
> of type time_t; so this is a bug in the OpenBSD header
> [for declaring it as long]
Most likely this problem arose because of the patch I pushed
in gnulib commit e07d7c40f3ca5ec410cf5aa6fa03cfe51e712039.
Previously, gnulib required timeval's tv_sec to be
the same size as time_t. But now, it requires only that
tv_sec be big enough to hold a time_t.
This patch was needed for Emacs. Without the patch, gnulib
replaced struct timeval on OpenBSD, and this messed up
utimens.c, and Emacs wouldn't build.
Alternatively, gnulib could substitute its own struct timeval
for the system's, wrapping every struct timeval-using function
(gettimeofday, futimesat, futimes, lutimes, etc. That'd be
more work, though. And it would introduce some performance
issues with gettimeofday, which is supposed to be fast.
I've been trying to get away from using struct timeval,
and to use the higher-resolution struct timespec instead,
so messing with these obsolescent interfaces has been
lower priority for me. But if someone wants to take the
more-ambitious approach that'd be fine, I expect.
For this particular case, though, how about if we avoid
the problem entirely? libvirt doesn't need to use struct
timeval here at all. It makes libvirt smaller and probably
faster, and it ports to OpenBSD without messing with gnulib.
2012-09-04 17:03:41 +00:00
|
|
|
localtime_r(&cur_time, &time_info);
|
2012-07-25 15:37:18 +00:00
|
|
|
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
|
|
|
|
|
|
|
|
if (virAsprintf(&ret, "%s-%s%s", virDomainGetName(dom),
|
|
|
|
timestr, ext ? ext : "") < 0) {
|
|
|
|
vshError(ctl, "%s", _("Out of memory"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name = NULL;
|
|
|
|
char *file = NULL;
|
|
|
|
int fd = -1;
|
|
|
|
virStreamPtr st = NULL;
|
|
|
|
unsigned int screen = 0;
|
|
|
|
unsigned int flags = 0; /* currently unused */
|
2014-11-17 23:39:48 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool created = false;
|
|
|
|
bool generated = false;
|
|
|
|
char *mime = NULL;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
2013-09-25 14:54:24 +00:00
|
|
|
if (!(st = virStreamNew(ctl->conn, 0)))
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
mime = virDomainScreenshot(dom, st, screen, flags);
|
|
|
|
if (!mime) {
|
|
|
|
vshError(ctl, _("could not take a screenshot of %s"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file) {
|
2013-09-25 14:54:24 +00:00
|
|
|
if (!(file = vshGenFileName(ctl, dom, mime)))
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
generated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
|
|
|
|
if (errno != EEXIST ||
|
|
|
|
(fd = open(file, O_WRONLY|O_TRUNC, 0666)) < 0) {
|
|
|
|
vshError(ctl, _("cannot create file %s"), file);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
created = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStreamRecvAll(st, vshStreamSink, &fd) < 0) {
|
|
|
|
vshError(ctl, _("could not receive data from domain %s"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_CLOSE(fd) < 0) {
|
|
|
|
vshError(ctl, _("cannot close file %s"), file);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStreamFinish(st) < 0) {
|
|
|
|
vshError(ctl, _("cannot close stream on domain %s"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Screenshot saved to %s, with type of %s"), file, mime);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
if (!ret && created)
|
|
|
|
unlink(file);
|
|
|
|
if (generated)
|
|
|
|
VIR_FREE(file);
|
|
|
|
virDomainFree(dom);
|
|
|
|
if (st)
|
|
|
|
virStreamFree(st);
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
VIR_FREE(mime);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-18 10:37:38 +00:00
|
|
|
/*
|
|
|
|
* "set-user-password" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_set_user_password[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("set the user password inside the domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("changes the password of the specified user inside the domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_set_user_password[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "user",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the username")
|
|
|
|
},
|
|
|
|
{.name = "password",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the new password")
|
|
|
|
},
|
|
|
|
{.name = "encrypted",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("the password is already encrypted")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *name;
|
|
|
|
const char *password = NULL;
|
|
|
|
const char *user = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "encrypted"))
|
|
|
|
flags = VIR_DOMAIN_PASSWORD_ENCRYPTED;
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "password", &password) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainSetUserPassword(dom, user, password, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Password set successfully for %s in %s"), user, name);
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "resume" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_resume[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("resume a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Resume a previously suspended domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_resume[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdResume(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainResume(dom) == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s resumed\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to resume domain %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "shutdown" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_shutdown[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("gracefully shutdown a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Run shutdown in the target domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_shutdown[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "mode",
|
|
|
|
.type = VSH_OT_STRING,
|
2014-05-01 17:42:54 +00:00
|
|
|
.help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdShutdown(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
2012-11-30 15:30:05 +00:00
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *name;
|
|
|
|
const char *mode = NULL;
|
|
|
|
int flags = 0;
|
|
|
|
int rv;
|
2012-11-30 21:48:24 +00:00
|
|
|
char **modes = NULL, **tmp;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2012-11-30 21:48:24 +00:00
|
|
|
if (mode && !(modes = virStringSplit(mode, ",", 0))) {
|
2012-11-30 15:30:05 +00:00
|
|
|
vshError(ctl, "%s", _("Cannot parse mode string"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = modes;
|
2012-11-30 21:48:24 +00:00
|
|
|
while (tmp && *tmp) {
|
2012-11-30 15:30:05 +00:00
|
|
|
mode = *tmp;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (STREQ(mode, "acpi")) {
|
|
|
|
flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
|
|
|
|
} else if (STREQ(mode, "agent")) {
|
|
|
|
flags |= VIR_DOMAIN_SHUTDOWN_GUEST_AGENT;
|
2012-11-28 13:24:23 +00:00
|
|
|
} else if (STREQ(mode, "initctl")) {
|
|
|
|
flags |= VIR_DOMAIN_SHUTDOWN_INITCTL;
|
|
|
|
} else if (STREQ(mode, "signal")) {
|
|
|
|
flags |= VIR_DOMAIN_SHUTDOWN_SIGNAL;
|
2014-05-01 17:42:54 +00:00
|
|
|
} else if (STREQ(mode, "paravirt")) {
|
|
|
|
flags |= VIR_DOMAIN_SHUTDOWN_PARAVIRT;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else {
|
2012-11-28 13:24:23 +00:00
|
|
|
vshError(ctl, _("Unknown mode %s value, expecting "
|
2014-05-01 17:42:54 +00:00
|
|
|
"'acpi', 'agent', 'initctl', 'signal', "
|
|
|
|
"or 'paravirt'"), mode);
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2012-11-30 15:30:05 +00:00
|
|
|
tmp++;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (flags)
|
|
|
|
rv = virDomainShutdownFlags(dom, flags);
|
|
|
|
else
|
|
|
|
rv = virDomainShutdown(dom);
|
|
|
|
if (rv == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s is being shutdown\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to shutdown domain %s"), name);
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 15:30:05 +00:00
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-11-30 15:30:05 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
virStringFreeList(modes);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "reboot" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_reboot[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("reboot a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Run a reboot command in the target domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_reboot[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "mode",
|
|
|
|
.type = VSH_OT_STRING,
|
2014-05-01 17:42:54 +00:00
|
|
|
.help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdReboot(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
2012-11-30 15:30:05 +00:00
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *name;
|
|
|
|
const char *mode = NULL;
|
|
|
|
int flags = 0;
|
2012-11-30 21:48:24 +00:00
|
|
|
char **modes = NULL, **tmp;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2012-11-30 21:48:24 +00:00
|
|
|
if (mode && !(modes = virStringSplit(mode, ",", 0))) {
|
2012-11-30 15:30:05 +00:00
|
|
|
vshError(ctl, "%s", _("Cannot parse mode string"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = modes;
|
2012-11-30 21:48:24 +00:00
|
|
|
while (tmp && *tmp) {
|
2012-11-30 15:30:05 +00:00
|
|
|
mode = *tmp;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (STREQ(mode, "acpi")) {
|
2012-11-28 16:31:14 +00:00
|
|
|
flags |= VIR_DOMAIN_REBOOT_ACPI_POWER_BTN;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else if (STREQ(mode, "agent")) {
|
2012-11-28 16:31:14 +00:00
|
|
|
flags |= VIR_DOMAIN_REBOOT_GUEST_AGENT;
|
2012-11-28 13:24:23 +00:00
|
|
|
} else if (STREQ(mode, "initctl")) {
|
|
|
|
flags |= VIR_DOMAIN_REBOOT_INITCTL;
|
|
|
|
} else if (STREQ(mode, "signal")) {
|
|
|
|
flags |= VIR_DOMAIN_REBOOT_SIGNAL;
|
2014-05-01 17:42:54 +00:00
|
|
|
} else if (STREQ(mode, "paravirt")) {
|
|
|
|
flags |= VIR_DOMAIN_REBOOT_PARAVIRT;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else {
|
2012-11-28 13:24:23 +00:00
|
|
|
vshError(ctl, _("Unknown mode %s value, expecting "
|
2014-05-01 17:42:54 +00:00
|
|
|
"'acpi', 'agent', 'initctl', 'signal' "
|
|
|
|
"or 'paravirt'"), mode);
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2012-11-30 15:30:05 +00:00
|
|
|
tmp++;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (virDomainReboot(dom, flags) == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s is being rebooted\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to reboot domain %s"), name);
|
2012-11-30 15:30:05 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 15:30:05 +00:00
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-11-30 15:30:05 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
virStringFreeList(modes);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "reset" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_reset[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("reset a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Reset the target domain as if by power button")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_reset[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdReset(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainReset(dom, 0) == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s was reset\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to reset domain %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domjobinfo" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domjobinfo[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("domain job information")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns information about jobs running on a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domjobinfo[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2014-09-12 08:05:32 +00:00
|
|
|
{.name = "completed",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("return statistics of a recently completed job")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainJob)
|
|
|
|
VIR_ENUM_IMPL(vshDomainJob,
|
|
|
|
VIR_DOMAIN_JOB_LAST,
|
|
|
|
N_("None"),
|
|
|
|
N_("Bounded"),
|
|
|
|
N_("Unbounded"),
|
|
|
|
N_("Completed"),
|
|
|
|
N_("Failed"),
|
|
|
|
N_("Cancelled"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainJobToString(int type)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainJobTypeToString(type);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainJobInfo info;
|
|
|
|
virDomainPtr dom;
|
2013-02-08 08:55:17 +00:00
|
|
|
bool ret = false;
|
|
|
|
const char *unit;
|
|
|
|
double val;
|
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
int nparams = 0;
|
|
|
|
unsigned long long value;
|
2014-08-22 12:29:41 +00:00
|
|
|
unsigned int flags = 0;
|
2013-02-08 08:55:17 +00:00
|
|
|
int rc;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2014-08-22 12:29:41 +00:00
|
|
|
if (vshCommandOptBool(cmd, "completed"))
|
|
|
|
flags |= VIR_DOMAIN_JOB_STATS_COMPLETED;
|
|
|
|
|
2013-02-08 08:55:17 +00:00
|
|
|
memset(&info, 0, sizeof(info));
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-08-22 12:29:41 +00:00
|
|
|
rc = virDomainGetJobStats(dom, &info.type, ¶ms, &nparams, flags);
|
2013-02-08 08:55:17 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
if (virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_TIME_ELAPSED,
|
|
|
|
&info.timeElapsed) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_TIME_REMAINING,
|
|
|
|
&info.timeRemaining) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DATA_TOTAL,
|
|
|
|
&info.dataTotal) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DATA_PROCESSED,
|
|
|
|
&info.dataProcessed) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DATA_REMAINING,
|
|
|
|
&info.dataRemaining) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_TOTAL,
|
|
|
|
&info.memTotal) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_PROCESSED,
|
|
|
|
&info.memProcessed) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_REMAINING,
|
|
|
|
&info.memRemaining) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DISK_TOTAL,
|
|
|
|
&info.fileTotal) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DISK_PROCESSED,
|
|
|
|
&info.fileProcessed) < 0 ||
|
|
|
|
virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DISK_REMAINING,
|
|
|
|
&info.fileRemaining) < 0)
|
|
|
|
goto save_error;
|
|
|
|
} else if (last_error->code == VIR_ERR_NO_SUPPORT) {
|
2014-08-22 12:29:41 +00:00
|
|
|
if (flags) {
|
|
|
|
vshError(ctl, "%s", _("Optional flags are not supported by the "
|
|
|
|
"daemon"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-02-08 08:55:17 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "detailed statistics not supported\n");
|
|
|
|
vshResetLibvirtError();
|
|
|
|
rc = virDomainGetJobInfo(dom, &info);
|
|
|
|
}
|
|
|
|
if (rc < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
vshPrint(ctl, "%-17s %-12s\n", _("Job type:"),
|
|
|
|
vshDomainJobToString(info.type));
|
|
|
|
if (info.type != VIR_DOMAIN_JOB_BOUNDED &&
|
2014-08-22 12:29:41 +00:00
|
|
|
info.type != VIR_DOMAIN_JOB_UNBOUNDED &&
|
|
|
|
(!(flags & VIR_DOMAIN_JOB_STATS_COMPLETED) ||
|
|
|
|
info.type != VIR_DOMAIN_JOB_COMPLETED)) {
|
2013-09-11 13:49:48 +00:00
|
|
|
ret = true;
|
2013-02-08 08:55:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time elapsed:"), info.timeElapsed);
|
2015-04-23 07:19:12 +00:00
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_TIME_ELAPSED_NET,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time elapsed w/o network:"),
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2013-02-08 08:55:17 +00:00
|
|
|
if (info.type == VIR_DOMAIN_JOB_BOUNDED)
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"),
|
|
|
|
info.timeRemaining);
|
2013-02-08 08:55:17 +00:00
|
|
|
|
|
|
|
if (info.dataTotal || info.dataRemaining || info.dataProcessed) {
|
|
|
|
val = vshPrettyCapacity(info.dataProcessed, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.dataRemaining, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.dataTotal, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.memTotal || info.memRemaining || info.memProcessed) {
|
|
|
|
val = vshPrettyCapacity(info.memProcessed, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.memRemaining, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.memTotal, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit);
|
2014-01-13 06:28:10 +00:00
|
|
|
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_BPS,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc && value) {
|
|
|
|
val = vshPrettyCapacity(value, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s/s\n",
|
|
|
|
_("Memory bandwidth:"), val, unit);
|
|
|
|
}
|
2013-02-08 08:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info.fileTotal || info.fileRemaining || info.fileProcessed) {
|
|
|
|
val = vshPrettyCapacity(info.fileProcessed, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.fileRemaining, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit);
|
|
|
|
val = vshPrettyCapacity(info.fileTotal, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit);
|
2014-01-13 06:28:10 +00:00
|
|
|
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DISK_BPS,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc && value) {
|
|
|
|
val = vshPrettyCapacity(value, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s/s\n",
|
|
|
|
_("File bandwidth:"), val, unit);
|
|
|
|
}
|
2013-02-08 08:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_CONSTANT,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-12llu\n", _("Constant pages:"), value);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_NORMAL,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-12llu\n", _("Normal pages:"), value);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_MEMORY_NORMAL_BYTES,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
val = vshPrettyCapacity(value, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Normal data:"), val, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DOWNTIME,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
2014-08-22 12:29:41 +00:00
|
|
|
if (info.type == VIR_DOMAIN_JOB_COMPLETED) {
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n",
|
|
|
|
_("Total downtime:"), value);
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n",
|
|
|
|
_("Expected downtime:"), value);
|
|
|
|
}
|
2013-02-08 08:55:17 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 07:19:12 +00:00
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_DOWNTIME_NET,
|
|
|
|
&value)) < 0)
|
|
|
|
goto save_error;
|
|
|
|
else if (rc)
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n", _("Downtime w/o network:"), value);
|
|
|
|
|
2014-01-13 06:28:10 +00:00
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_SETUP_TIME,
|
|
|
|
&value)) < 0)
|
|
|
|
goto save_error;
|
|
|
|
else if (rc)
|
|
|
|
vshPrint(ctl, "%-17s %-12llu ms\n", _("Setup time:"), value);
|
|
|
|
|
2013-02-08 08:55:17 +00:00
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_COMPRESSION_CACHE,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
val = vshPrettyCapacity(value, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compression cache:"), val, unit);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_COMPRESSION_BYTES,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
val = vshPrettyCapacity(value, &unit);
|
|
|
|
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compressed data:"), val, unit);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_COMPRESSION_PAGES,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-13llu\n", _("Compressed pages:"), value);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_COMPRESSION_CACHE_MISSES,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-13llu\n", _("Compression cache misses:"), value);
|
|
|
|
}
|
|
|
|
if ((rc = virTypedParamsGetULLong(params, nparams,
|
|
|
|
VIR_DOMAIN_JOB_COMPRESSION_OVERFLOW,
|
|
|
|
&value)) < 0) {
|
|
|
|
goto save_error;
|
|
|
|
} else if (rc) {
|
|
|
|
vshPrint(ctl, "%-17s %-13llu\n", _("Compression overflows:"), value);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2013-02-08 08:55:17 +00:00
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
2013-02-08 08:55:17 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
2013-02-08 08:55:17 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-02-08 08:55:17 +00:00
|
|
|
vshSaveLibvirtError();
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domjobabort" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domjobabort[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("abort active domain job")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Aborts the currently running domain job")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domjobabort[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomjobabort(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainAbortJob(dom) < 0)
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "vcpucount" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_vcpucount[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("domain vcpu counts")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns the number of virtual CPUs used by the domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_vcpucount[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "maximum",
|
|
|
|
.type = VSH_OT_BOOL,
|
2013-04-15 09:07:23 +00:00
|
|
|
.help = N_("get maximum count of vcpus")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "active",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get number of currently active vcpus")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get value from running domain")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get value to be used on next boot")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("get value according to current domain state")
|
|
|
|
},
|
2013-06-07 15:12:47 +00:00
|
|
|
{.name = "guest",
|
2013-04-12 12:30:41 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
2013-06-07 15:12:47 +00:00
|
|
|
.help = N_("retrieve vcpu count from the guest instead of the hypervisor")
|
2013-04-12 12:30:41 +00:00
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
/**
|
|
|
|
* Collect the number of vCPUs for a guest possibly with fallback means.
|
|
|
|
*
|
|
|
|
* Returns the count of vCPUs for a domain and certain flags. Returns -2 in case
|
|
|
|
* of error. If @checkState is true, in case live stats can't be collected when
|
|
|
|
* the domain is inactive or persistent stats can't be collected if domain is
|
|
|
|
* transient -1 is returned and no error is reported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
vshCPUCountCollect(vshControl *ctl,
|
|
|
|
virDomainPtr dom,
|
|
|
|
unsigned int flags,
|
|
|
|
bool checkState)
|
|
|
|
{
|
|
|
|
int ret = -2;
|
|
|
|
virDomainInfo info;
|
|
|
|
int count;
|
|
|
|
char *def = NULL;
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
|
|
|
|
if (checkState &&
|
|
|
|
((flags & VIR_DOMAIN_AFFECT_LIVE && virDomainIsActive(dom) < 1) ||
|
|
|
|
(flags & VIR_DOMAIN_AFFECT_CONFIG && virDomainIsPersistent(dom) < 1)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* In all cases, try the new API first; if it fails because we are talking
|
|
|
|
* to an older daemon, generally we try a fallback API before giving up.
|
|
|
|
* --current requires the new API, since we don't know whether the domain is
|
|
|
|
* running or inactive. */
|
|
|
|
if ((count = virDomainGetVcpusFlags(dom, flags)) >= 0)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
/* fallback code */
|
|
|
|
if (!(last_error->code == VIR_ERR_NO_SUPPORT ||
|
|
|
|
last_error->code == VIR_ERR_INVALID_ARG))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-07 15:12:47 +00:00
|
|
|
if (flags & VIR_DOMAIN_VCPU_GUEST) {
|
|
|
|
vshError(ctl, "%s", _("Failed to retrieve vCPU count from the guest"));
|
2013-04-12 12:30:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
if (!(flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
vshResetLibvirtError();
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
|
|
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
|
|
|
count = virDomainGetMaxVcpus(dom);
|
|
|
|
} else {
|
|
|
|
if (virDomainGetInfo(dom, &info) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
count = info.nrVirtCpu;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(def = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(xml = virXMLParseStringCtxt(def, _("(domain_definition)"), &ctxt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
|
|
|
if (virXPathInt("string(/domain/vcpus)", ctxt, &count) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virXPathInt("string(/domain/vcpus/@current)",
|
|
|
|
ctxt, &count) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to retrieve current vcpu count"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = count;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-04-15 09:07:23 +00:00
|
|
|
VIR_FREE(def);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2013-04-15 09:07:23 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool maximum = vshCommandOptBool(cmd, "maximum");
|
|
|
|
bool active = vshCommandOptBool(cmd, "active");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
2013-06-07 15:12:47 +00:00
|
|
|
bool guest = vshCommandOptBool(cmd, "guest");
|
|
|
|
bool all = maximum + active + current + config + live + guest == 0;
|
2013-04-15 09:07:23 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* Backwards compatibility: prior to 0.9.4,
|
|
|
|
* VIR_DOMAIN_AFFECT_CURRENT was unsupported, and --current meant
|
|
|
|
* the opposite of --maximum. Translate the old '--current
|
|
|
|
* --live' into the new '--active --live', while treating the new
|
|
|
|
* '--maximum --current' correctly rather than rejecting it as
|
|
|
|
* '--maximum --active'. */
|
2013-04-15 09:07:23 +00:00
|
|
|
if (!maximum && !active && current)
|
2012-07-25 15:37:18 +00:00
|
|
|
current = false;
|
|
|
|
|
2013-10-30 12:58:09 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(live, config)
|
2013-04-15 09:07:23 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(active, maximum);
|
2013-06-07 15:12:47 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(guest, config);
|
2013-04-15 09:07:23 +00:00
|
|
|
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (maximum)
|
|
|
|
flags |= VIR_DOMAIN_VCPU_MAXIMUM;
|
2013-06-07 15:12:47 +00:00
|
|
|
if (guest)
|
|
|
|
flags |= VIR_DOMAIN_VCPU_GUEST;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
if (all) {
|
|
|
|
int conf_max = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_CONFIG |
|
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM, true);
|
|
|
|
int conf_cur = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_CONFIG, true);
|
|
|
|
int live_max = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_LIVE |
|
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM, true);
|
|
|
|
int live_cur = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_LIVE, true);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
if (conf_max == -2 || conf_cur == -2 || live_max == -2 || live_cur == -2)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
#define PRINT_COUNT(VAR, WHICH, STATE) if (VAR > 0) \
|
|
|
|
vshPrint(ctl, "%-12s %-12s %3d\n", WHICH, STATE, VAR)
|
|
|
|
PRINT_COUNT(conf_max, _("maximum"), _("config"));
|
|
|
|
PRINT_COUNT(live_max, _("maximum"), _("live"));
|
|
|
|
PRINT_COUNT(conf_cur, _("current"), _("config"));
|
|
|
|
PRINT_COUNT(live_cur, _("current"), _("live"));
|
|
|
|
#undef PRINT_COUNT
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
} else {
|
|
|
|
int count = vshCPUCountCollect(ctl, dom, flags, false);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
if (count < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
vshPrint(ctl, "%d\n", count);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 09:07:23 +00:00
|
|
|
ret = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "vcpuinfo" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_vcpuinfo[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("detailed domain vcpu information")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns basic information about the domain virtual CPUs.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_vcpuinfo[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2014-06-05 11:16:00 +00:00
|
|
|
{.name = "pretty",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("return human readable output")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainInfo info;
|
|
|
|
virDomainPtr dom;
|
2014-06-05 08:42:19 +00:00
|
|
|
virVcpuInfoPtr cpuinfo = NULL;
|
|
|
|
unsigned char *cpumaps = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
int ncpus, maxcpu;
|
|
|
|
size_t cpumaplen;
|
2014-06-05 08:42:19 +00:00
|
|
|
bool ret = false;
|
2014-06-05 11:16:00 +00:00
|
|
|
bool pretty = vshCommandOptBool(cmd, "pretty");
|
2012-07-25 15:37:18 +00:00
|
|
|
int n, m;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2014-06-05 08:42:19 +00:00
|
|
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-06-05 08:42:19 +00:00
|
|
|
if (virDomainGetInfo(dom, &info) != 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
|
|
|
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
|
|
|
cpumaps = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
|
|
|
|
|
|
|
|
if ((ncpus = virDomainGetVcpus(dom,
|
|
|
|
cpuinfo, info.nrVirtCpu,
|
2014-06-05 08:42:23 +00:00
|
|
|
cpumaps, cpumaplen)) < 0) {
|
|
|
|
if (info.state != VIR_DOMAIN_SHUTOFF)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* fall back to virDomainGetVcpuPinInfo and free cpuinfo to mark this */
|
|
|
|
VIR_FREE(cpuinfo);
|
|
|
|
if ((ncpus = virDomainGetVcpuPinInfo(dom, info.nrVirtCpu,
|
|
|
|
cpumaps, cpumaplen,
|
|
|
|
VIR_DOMAIN_AFFECT_CONFIG)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < ncpus; n++) {
|
|
|
|
vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n);
|
|
|
|
if (cpuinfo) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu);
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
vshDomainVcpuStateToString(cpuinfo[n].state));
|
2012-07-25 15:37:18 +00:00
|
|
|
if (cpuinfo[n].cpuTime != 0) {
|
|
|
|
double cpuUsed = cpuinfo[n].cpuTime;
|
|
|
|
|
|
|
|
cpuUsed /= 1000000000.0;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%-15s %.1lfs\n", _("CPU time:"), cpuUsed);
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-05 08:42:23 +00:00
|
|
|
vshPrint(ctl, "%-15s %s\n", _("CPU:"), _("N/A"));
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("State:"), _("N/A"));
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("CPU time"), _("N/A"));
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2014-06-05 08:42:23 +00:00
|
|
|
vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
|
2014-06-05 11:16:00 +00:00
|
|
|
if (pretty) {
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = virBitmapDataToString(VIR_GET_CPUMAP(cpumaps, cpumaplen, n),
|
|
|
|
cpumaplen);
|
|
|
|
if (!str)
|
|
|
|
goto cleanup;
|
|
|
|
vshPrint(ctl, _("%s (out of %d)"), str, maxcpu);
|
|
|
|
VIR_FREE(str);
|
|
|
|
} else {
|
|
|
|
for (m = 0; m < maxcpu; m++) {
|
|
|
|
vshPrint(ctl, "%c",
|
|
|
|
VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
|
|
|
|
}
|
2014-06-05 08:42:23 +00:00
|
|
|
}
|
|
|
|
vshPrint(ctl, "\n");
|
|
|
|
if (n < (ncpus - 1))
|
|
|
|
vshPrint(ctl, "\n");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 08:42:19 +00:00
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(cpumaps);
|
|
|
|
VIR_FREE(cpuinfo);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "vcpupin" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_vcpupin[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("control or query domain vcpu affinity")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Pin domain VCPUs to host physical CPUs.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_vcpupin[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "vcpu",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("vcpu number")
|
|
|
|
},
|
|
|
|
{.name = "cpulist",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.flags = VSH_OFLAG_EMPTY_OK,
|
|
|
|
.help = N_("host cpu number(s) to set, or omit option to query")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2012-08-21 09:18:39 +00:00
|
|
|
/*
|
|
|
|
* Helper function to print vcpupin info.
|
|
|
|
*/
|
|
|
|
static bool
|
2015-03-26 14:24:09 +00:00
|
|
|
vshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen)
|
2012-08-21 09:18:39 +00:00
|
|
|
{
|
2015-03-26 14:24:09 +00:00
|
|
|
char *str = NULL;
|
2012-08-21 09:18:39 +00:00
|
|
|
|
2015-03-26 14:24:09 +00:00
|
|
|
if (!(str = virBitmapDataToString(cpumap, cpumaplen)))
|
2012-08-21 09:18:39 +00:00
|
|
|
return false;
|
|
|
|
|
2015-03-26 14:24:09 +00:00
|
|
|
vshPrint(ctl, "%s", str);
|
|
|
|
VIR_FREE(str);
|
2012-08-21 09:18:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-28 11:36:30 +00:00
|
|
|
static unsigned char *
|
2015-05-11 08:25:19 +00:00
|
|
|
vshParseCPUList(vshControl *ctl, int *cpumaplen, const char *cpulist, int maxcpu)
|
2013-03-28 11:36:30 +00:00
|
|
|
{
|
|
|
|
unsigned char *cpumap = NULL;
|
2015-04-01 16:46:56 +00:00
|
|
|
virBitmapPtr map = NULL;
|
2013-03-28 11:36:30 +00:00
|
|
|
|
2015-04-01 16:46:56 +00:00
|
|
|
if (cpulist[0] == 'r') {
|
|
|
|
if (!(map = virBitmapNew(maxcpu)))
|
|
|
|
return NULL;
|
|
|
|
virBitmapSetAll(map);
|
|
|
|
} else {
|
2015-05-11 08:25:19 +00:00
|
|
|
if ((virBitmapParse(cpulist, '\0', &map, 1024) < 0) ||
|
|
|
|
virBitmapIsAllClear(map)) {
|
|
|
|
vshError(ctl, _("Invalid cpulist '%s'"), cpulist);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
int lastcpu = virBitmapLastSetBit(map);
|
|
|
|
if (lastcpu >= maxcpu) {
|
|
|
|
vshError(ctl, _("CPU %d in cpulist '%s' exceed the maxcpu %d"),
|
|
|
|
lastcpu, cpulist, maxcpu);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-03-28 11:36:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 16:46:56 +00:00
|
|
|
if (virBitmapToData(map, &cpumap, cpumaplen) < 0)
|
|
|
|
goto cleanup;
|
2013-03-28 11:36:30 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2015-04-01 16:46:56 +00:00
|
|
|
virBitmapFree(map);
|
|
|
|
return cpumap;
|
2013-03-28 11:36:30 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
static bool
|
|
|
|
cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2014-05-29 03:34:40 +00:00
|
|
|
unsigned int vcpu = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *cpulist = NULL;
|
2013-03-28 11:36:30 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
unsigned char *cpumap = NULL;
|
2015-04-01 16:46:56 +00:00
|
|
|
int cpumaplen;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int maxcpu, ncpus;
|
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
2014-05-29 03:34:40 +00:00
|
|
|
int got_vcpu;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
/* none of the options were specified */
|
|
|
|
if (!current && !live && !config)
|
|
|
|
flags = -1;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-20 07:21:05 +00:00
|
|
|
if (!cpulist)
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(live, config);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0)
|
2015-02-20 07:21:05 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-05-29 03:34:40 +00:00
|
|
|
/* In pin mode, "vcpu" is necessary */
|
2015-02-20 07:21:05 +00:00
|
|
|
if (cpulist && got_vcpu == 0) {
|
2014-05-29 03:34:40 +00:00
|
|
|
vshError(ctl, "%s", _("vcpupin: Missing vCPU number in pin mode."));
|
2015-02-20 07:21:05 +00:00
|
|
|
return false;
|
2014-05-29 03:34:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 14:20:51 +00:00
|
|
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
2015-02-20 07:21:05 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-02-20 07:21:05 +00:00
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Query mode: show CPU affinity information then exit.*/
|
2015-02-20 07:21:05 +00:00
|
|
|
if (!cpulist) {
|
2012-07-25 15:37:18 +00:00
|
|
|
/* When query mode and neither "live", "config" nor "current"
|
|
|
|
* is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */
|
|
|
|
if (flags == -1)
|
|
|
|
flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
2015-02-20 07:21:05 +00:00
|
|
|
if ((ncpus = vshCPUCountCollect(ctl, dom, flags, true)) < 0) {
|
|
|
|
if (ncpus == -1) {
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
|
|
|
vshError(ctl, "%s", _("cannot get vcpupin for offline domain"));
|
|
|
|
else
|
|
|
|
vshError(ctl, "%s", _("cannot get vcpupin for transient domain"));
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-06-29 02:10:15 +00:00
|
|
|
if (got_vcpu && vcpu >= ncpus) {
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_LIVE ||
|
2015-07-14 14:23:26 +00:00
|
|
|
(!(flags & VIR_DOMAIN_AFFECT_CONFIG) &&
|
2015-06-29 02:10:15 +00:00
|
|
|
virDomainIsActive(dom) == 1))
|
|
|
|
vshError(ctl,
|
|
|
|
_("vcpu %d is out of range of live cpu count %d"),
|
|
|
|
vcpu, ncpus);
|
|
|
|
else
|
|
|
|
vshError(ctl,
|
|
|
|
_("vcpu %d is out of range of persistent cpu count %d"),
|
|
|
|
vcpu, ncpus);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-04-01 16:46:56 +00:00
|
|
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
2015-02-20 07:21:05 +00:00
|
|
|
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
|
|
|
|
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
|
|
|
|
cpumaplen, flags)) >= 0) {
|
2014-02-26 10:54:25 +00:00
|
|
|
vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
|
|
|
|
vshPrintExtra(ctl, "----------------------------------\n");
|
2012-07-25 15:37:18 +00:00
|
|
|
for (i = 0; i < ncpus; i++) {
|
2015-03-26 14:10:50 +00:00
|
|
|
if (got_vcpu && i != vcpu)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%4zu: ", i);
|
2015-03-26 14:24:09 +00:00
|
|
|
ret = vshPrintPinInfo(VIR_GET_CPUMAP(cpumap, cpumaplen, i),
|
|
|
|
cpumaplen);
|
2015-03-26 14:10:50 +00:00
|
|
|
vshPrint(ctl, "\n");
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-20 07:21:05 +00:00
|
|
|
/* Pin mode: pinning specified vcpu to specified physical cpus*/
|
2015-05-11 08:25:19 +00:00
|
|
|
if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
|
2013-03-28 11:36:30 +00:00
|
|
|
goto cleanup;
|
2015-02-20 07:21:05 +00:00
|
|
|
|
|
|
|
if (flags == -1) {
|
|
|
|
if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(cpumap);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-21 09:18:40 +00:00
|
|
|
/*
|
|
|
|
* "emulatorpin" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_emulatorpin[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("control or query domain emulator affinity")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Pin domain emulator threads to host physical CPUs.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-08-21 09:18:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_emulatorpin[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "cpulist",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.flags = VSH_OFLAG_EMPTY_OK,
|
|
|
|
.help = N_("host cpu number(s) to set, or omit option to query")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-08-21 09:18:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *cpulist = NULL;
|
2013-03-28 11:36:30 +00:00
|
|
|
bool ret = false;
|
2012-08-21 09:18:40 +00:00
|
|
|
unsigned char *cpumap = NULL;
|
2015-04-01 16:46:56 +00:00
|
|
|
int cpumaplen;
|
2013-03-28 11:36:30 +00:00
|
|
|
int maxcpu;
|
2012-08-21 09:18:40 +00:00
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool query = false; /* Query mode if no cpulist */
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-08-21 09:18:40 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
/* none of the options were specified */
|
|
|
|
if (!current && !live && !config)
|
|
|
|
flags = -1;
|
2012-08-21 09:18:40 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) {
|
2012-08-21 09:18:40 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
query = !cpulist;
|
|
|
|
|
2012-11-13 12:54:39 +00:00
|
|
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
|
2012-08-21 09:18:40 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query mode: show CPU affinity information then exit.*/
|
|
|
|
if (query) {
|
|
|
|
/* When query mode and neither "live", "config" nor "current"
|
|
|
|
* is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */
|
|
|
|
if (flags == -1)
|
|
|
|
flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
2015-04-01 16:46:56 +00:00
|
|
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
2015-03-26 14:24:09 +00:00
|
|
|
cpumap = vshMalloc(ctl, cpumaplen);
|
|
|
|
if (virDomainGetEmulatorPinInfo(dom, cpumap,
|
2012-08-21 09:18:40 +00:00
|
|
|
cpumaplen, flags) >= 0) {
|
2014-02-26 10:54:25 +00:00
|
|
|
vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity"));
|
|
|
|
vshPrintExtra(ctl, "----------------------------------\n");
|
|
|
|
vshPrintExtra(ctl, " *: ");
|
2015-03-26 14:24:09 +00:00
|
|
|
ret = vshPrintPinInfo(cpumap, cpumaplen);
|
2012-08-21 09:18:40 +00:00
|
|
|
vshPrint(ctl, "\n");
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pin mode: pinning emulator threads to specified physical cpus*/
|
2015-05-11 08:25:19 +00:00
|
|
|
if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
|
2013-03-28 11:36:30 +00:00
|
|
|
goto cleanup;
|
2012-08-21 09:18:40 +00:00
|
|
|
|
|
|
|
if (flags == -1)
|
|
|
|
flags = VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) != 0)
|
2013-03-28 11:36:30 +00:00
|
|
|
goto cleanup;
|
2012-08-21 09:18:40 +00:00
|
|
|
|
2013-03-28 11:36:30 +00:00
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-08-21 09:18:40 +00:00
|
|
|
VIR_FREE(cpumap);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "setvcpus" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_setvcpus[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("change number of virtual CPUs")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Change the number of virtual CPUs in the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_setvcpus[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "count",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("number of virtual CPUs")
|
|
|
|
},
|
|
|
|
{.name = "maximum",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("set maximum limit on next boot")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-06-07 15:12:47 +00:00
|
|
|
{.name = "guest",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify cpu state in the guest")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int count = 0;
|
2013-08-13 09:14:56 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool maximum = vshCommandOptBool(cmd, "maximum");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
2013-06-07 15:12:47 +00:00
|
|
|
bool guest = vshCommandOptBool(cmd, "guest");
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
2013-06-07 15:12:47 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(guest, config);
|
2013-03-07 12:38:19 +00:00
|
|
|
|
2015-03-20 14:39:03 +00:00
|
|
|
VSH_REQUIRE_OPTION_VAR(maximum, config);
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2013-06-07 15:12:47 +00:00
|
|
|
if (guest)
|
|
|
|
flags |= VIR_DOMAIN_VCPU_GUEST;
|
2015-03-20 14:39:03 +00:00
|
|
|
if (maximum)
|
|
|
|
flags |= VIR_DOMAIN_VCPU_MAXIMUM;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-20 14:39:03 +00:00
|
|
|
/* none of the options were specified */
|
|
|
|
if (!current && flags == 0) {
|
2013-08-13 09:14:56 +00:00
|
|
|
if (virDomainSetVcpus(dom, count) != 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
} else {
|
2013-08-13 09:14:56 +00:00
|
|
|
if (virDomainSetVcpusFlags(dom, count, flags) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 09:14:56 +00:00
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-11 20:29:22 +00:00
|
|
|
/*
|
2015-03-25 16:15:04 +00:00
|
|
|
* "iothreadinfo" command
|
2015-02-11 20:29:22 +00:00
|
|
|
*/
|
2015-03-25 16:15:04 +00:00
|
|
|
static const vshCmdInfo info_iothreadinfo[] = {
|
2015-02-11 20:29:22 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("view domain IOThreads")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns basic information about the domain IOThreads.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
2015-03-25 16:15:04 +00:00
|
|
|
static const vshCmdOptDef opts_iothreadinfo[] = {
|
2015-02-11 20:29:22 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2015-03-25 16:15:04 +00:00
|
|
|
cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
|
2015-02-11 20:29:22 +00:00
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
int niothreads = 0;
|
|
|
|
virDomainIOThreadInfoPtr *info;
|
|
|
|
size_t i;
|
|
|
|
int maxcpu;
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-25 16:02:26 +00:00
|
|
|
if ((niothreads = virDomainGetIOThreadInfo(dom, &info, flags)) < 0) {
|
2015-02-11 20:29:22 +00:00
|
|
|
vshError(ctl, _("Unable to get domain IOThreads information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (niothreads == 0) {
|
|
|
|
vshPrintExtra(ctl, _("No IOThreads found for the domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrintExtra(ctl, " %-15s %-15s\n",
|
|
|
|
_("IOThread ID"), _("CPU Affinity"));
|
|
|
|
vshPrintExtra(ctl, "---------------------------------------------------\n");
|
|
|
|
for (i = 0; i < niothreads; i++) {
|
|
|
|
|
|
|
|
vshPrint(ctl, " %-15u ", info[i]->iothread_id);
|
2015-03-26 14:24:09 +00:00
|
|
|
ignore_value(vshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen));
|
2015-02-11 20:29:22 +00:00
|
|
|
vshPrint(ctl, "\n");
|
2015-03-25 15:47:49 +00:00
|
|
|
virDomainIOThreadInfoFree(info[i]);
|
2015-02-11 20:29:22 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(info);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainFree(dom);
|
|
|
|
return niothreads >= 0;
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:08:04 +00:00
|
|
|
/*
|
|
|
|
* "iothreadpin" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_iothreadpin[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("control domain IOThread affinity")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Pin domain IOThreads to host physical CPUs.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_iothreadpin[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "iothread",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("IOThread ID number")
|
|
|
|
},
|
|
|
|
{.name = "cpulist",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("host cpu number(s) to set")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *cpulist = NULL;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
unsigned int iothread_id = 0;
|
|
|
|
int maxcpu;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned char *cpumap = NULL;
|
2015-04-01 16:46:56 +00:00
|
|
|
int cpumaplen;
|
2015-03-06 00:08:04 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0)
|
2015-03-06 00:08:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "cpulist", &cpulist) < 0) {
|
2015-03-06 00:08:04 +00:00
|
|
|
vshError(ctl, "%s", _("iothreadpin: invalid cpulist."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-05-11 08:25:19 +00:00
|
|
|
if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
|
2015-03-06 00:08:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainPinIOThread(dom, iothread_id,
|
|
|
|
cpumap, cpumaplen, flags) != 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(cpumap);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:01:50 +00:00
|
|
|
/*
|
|
|
|
* "iothreadadd" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_iothreadadd[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("add an IOThread to the guest domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Add an IOThread to the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_iothreadadd[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "id",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("iothread for the new IOThread")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int iothread_id = 0;
|
|
|
|
bool ret = false;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0)
|
2015-03-18 13:01:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (iothread_id <= 0) {
|
|
|
|
vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainAddIOThread(dom, iothread_id, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "iothreaddel" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_iothreaddel[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("delete an IOThread from the guest domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Delete an IOThread from the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_iothreaddel[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "id",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("iothread_id for the IOThread to delete")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int iothread_id = 0;
|
|
|
|
bool ret = false;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0)
|
2015-03-18 13:01:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (iothread_id <= 0) {
|
|
|
|
vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainDelIOThread(dom, iothread_id, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "cpu-compare" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_cpu_compare[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("compare host CPU with a CPU described by an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("compare CPU with host CPU")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_cpu_compare[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("file containing an XML CPU description")
|
|
|
|
},
|
2014-05-28 13:12:59 +00:00
|
|
|
{.name = "error",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("report error if CPUs are incompatible")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
char *buffer;
|
|
|
|
int result;
|
2013-09-04 15:27:27 +00:00
|
|
|
char *snippet = NULL;
|
2014-05-28 13:12:59 +00:00
|
|
|
unsigned int flags = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlNodePtr node;
|
|
|
|
|
2014-05-28 13:12:59 +00:00
|
|
|
if (vshCommandOptBool(cmd, "error"))
|
|
|
|
flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* try to extract the CPU element from as it would appear in a domain XML*/
|
|
|
|
if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((node = virXPathNode("/cpu|"
|
|
|
|
"/domain/cpu|"
|
|
|
|
"/capabilities/host/cpu", ctxt))) {
|
2013-09-04 15:27:27 +00:00
|
|
|
if (!(snippet = virXMLNodeToString(xml, node))) {
|
|
|
|
vshSaveLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("File '%s' does not contain a <cpu> element or is not "
|
|
|
|
"a valid domain or capabilities XML"), from);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:12:59 +00:00
|
|
|
result = virConnectCompareCPU(ctl->conn, snippet, flags);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case VIR_CPU_COMPARE_INCOMPATIBLE:
|
|
|
|
vshPrint(ctl, _("CPU described in %s is incompatible with host CPU\n"),
|
|
|
|
from);
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_CPU_COMPARE_IDENTICAL:
|
|
|
|
vshPrint(ctl, _("CPU described in %s is identical to host CPU\n"),
|
|
|
|
from);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_CPU_COMPARE_SUPERSET:
|
|
|
|
vshPrint(ctl, _("Host CPU is a superset of CPU described in %s\n"),
|
|
|
|
from);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_CPU_COMPARE_ERROR:
|
|
|
|
default:
|
|
|
|
vshError(ctl, _("Failed to compare host CPU with %s"), from);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(buffer);
|
2013-09-04 15:27:27 +00:00
|
|
|
VIR_FREE(snippet);
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "cpu-baseline" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_cpu_baseline[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("compute baseline CPU")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Compute baseline CPU for a set of given CPUs.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_cpu_baseline[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("file containing XML CPU descriptions")
|
|
|
|
},
|
2013-08-02 19:08:19 +00:00
|
|
|
{.name = "features",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Show features that are part of the CPU model type")
|
|
|
|
},
|
2015-02-05 14:30:50 +00:00
|
|
|
{.name = "migratable",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Do not include features that block migration")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
char *buffer;
|
|
|
|
char *result = NULL;
|
2013-09-03 11:36:22 +00:00
|
|
|
char **list = NULL;
|
2013-08-02 19:08:19 +00:00
|
|
|
unsigned int flags = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlNodePtr *node_list = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-08-02 19:08:19 +00:00
|
|
|
if (vshCommandOptBool(cmd, "features"))
|
|
|
|
flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES;
|
2015-02-05 14:30:50 +00:00
|
|
|
if (vshCommandOptBool(cmd, "migratable"))
|
|
|
|
flags |= VIR_CONNECT_BASELINE_CPU_MIGRATABLE;
|
2013-08-02 19:08:19 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* add a separate container around the xml */
|
|
|
|
virBufferStrcat(&buf, "<container>", buffer, "</container>", NULL);
|
|
|
|
if (virBufferError(&buf))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
VIR_FREE(buffer);
|
|
|
|
buffer = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
|
|
|
|
if (!(xml = virXMLParseStringCtxt(buffer, from, &ctxt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((count = virXPathNodeSet("//cpu[not(ancestor::cpus)]",
|
|
|
|
ctxt, &node_list)) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
vshError(ctl, _("No host CPU specified in '%s'"), from);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = vshCalloc(ctl, count, sizeof(const char *));
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2013-09-04 15:27:27 +00:00
|
|
|
if (!(list[i] = virXMLNodeToString(xml, node_list[i]))) {
|
|
|
|
vshSaveLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-03 11:36:22 +00:00
|
|
|
result = virConnectBaselineCPU(ctl->conn,
|
|
|
|
(const char **)list, count, flags);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
vshPrint(ctl, "%s", result);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
VIR_FREE(result);
|
|
|
|
if (list != NULL && count > 0) {
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
VIR_FREE(list[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(list);
|
|
|
|
VIR_FREE(buffer);
|
2013-08-16 08:33:30 +00:00
|
|
|
VIR_FREE(node_list);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
no_memory:
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("Out of memory"));
|
|
|
|
ret = false;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "cpu-stats" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_cpu_stats[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("show domain cpu statistics")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Display per-CPU and total statistics about the domain's CPUs")
|
|
|
|
},
|
2013-04-08 14:15:42 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_cpu_stats[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "total",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Show total statistics only")
|
|
|
|
},
|
|
|
|
{.name = "start",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Show statistics from this CPU")
|
|
|
|
},
|
|
|
|
{.name = "count",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Number of shown CPUs at most")
|
|
|
|
},
|
2013-04-08 14:15:42 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
virTypedParameterPtr params = NULL;
|
2014-09-04 21:08:48 +00:00
|
|
|
int pos, max_id, cpu = 0, show_count = -1, nparams = 0, stats_per_cpu;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i, j;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool show_total = false, show_per_cpu = false;
|
|
|
|
unsigned int flags = 0;
|
2013-01-22 11:17:18 +00:00
|
|
|
bool ret = false;
|
2013-04-08 14:49:34 +00:00
|
|
|
int rv = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
show_total = vshCommandOptBool(cmd, "total");
|
2013-04-08 14:49:34 +00:00
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptInt(ctl, cmd, "start", &cpu)) < 0) {
|
2013-04-08 14:49:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (cpu < 0) {
|
|
|
|
vshError(ctl, "%s", _("Invalid value for start CPU"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
show_per_cpu = true;
|
2013-04-08 14:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rv = vshCommandOptInt(ctl, cmd, "count", &show_count)) < 0) {
|
2013-04-08 14:49:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else if (rv > 0) {
|
|
|
|
if (show_count < 0) {
|
|
|
|
vshError(ctl, "%s", _("Invalid value for number of CPUs to show"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
show_per_cpu = true;
|
2013-04-08 14:49:34 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* default show per_cpu and total */
|
|
|
|
if (!show_total && !show_per_cpu) {
|
|
|
|
show_total = true;
|
|
|
|
show_per_cpu = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!show_per_cpu) /* show total stats only */
|
|
|
|
goto do_show_total;
|
|
|
|
|
|
|
|
/* get number of cpus on the node */
|
|
|
|
if ((max_id = virDomainGetCPUStats(dom, NULL, 0, 0, 0, flags)) < 0)
|
|
|
|
goto failed_stats;
|
2013-04-08 14:49:34 +00:00
|
|
|
if (show_count < 0 || show_count > max_id) {
|
|
|
|
if (show_count > max_id)
|
|
|
|
vshPrint(ctl, _("Only %d CPUs available to show\n"), max_id);
|
2012-07-25 15:37:18 +00:00
|
|
|
show_count = max_id;
|
2013-04-08 14:49:34 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* get percpu information */
|
|
|
|
if ((nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, flags)) < 0)
|
|
|
|
goto failed_stats;
|
|
|
|
|
|
|
|
if (!nparams) {
|
|
|
|
vshPrint(ctl, "%s", _("No per-CPU stats available"));
|
2013-08-23 10:17:25 +00:00
|
|
|
if (show_total)
|
|
|
|
goto do_show_total;
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
|
2013-07-04 10:20:45 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
while (show_count) {
|
|
|
|
int ncpus = MIN(show_count, 128);
|
|
|
|
|
|
|
|
if (virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, flags) < 0)
|
|
|
|
goto failed_stats;
|
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
if (params[i * nparams].type == 0) /* this cpu is not in the map */
|
|
|
|
continue;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
vshPrint(ctl, "CPU%zu:\n", cpu + i);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
for (j = 0; j < nparams; j++) {
|
|
|
|
pos = i * nparams + j;
|
|
|
|
vshPrint(ctl, "\t%-12s ", params[pos].field);
|
|
|
|
if ((STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
|
|
|
|
STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_VCPUTIME)) &&
|
|
|
|
params[j].type == VIR_TYPED_PARAM_ULLONG) {
|
|
|
|
vshPrint(ctl, "%9lld.%09lld seconds\n",
|
|
|
|
params[pos].value.ul / 1000000000,
|
|
|
|
params[pos].value.ul % 1000000000);
|
|
|
|
} else {
|
2013-09-03 11:36:22 +00:00
|
|
|
char *s = vshGetTypedParamValue(ctl, ¶ms[pos]);
|
2012-07-25 15:37:18 +00:00
|
|
|
vshPrint(ctl, _("%s\n"), s);
|
|
|
|
VIR_FREE(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cpu += ncpus;
|
|
|
|
show_count -= ncpus;
|
2013-01-15 23:42:35 +00:00
|
|
|
virTypedParamsClear(params, nparams * ncpus);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(params);
|
|
|
|
|
2013-08-23 10:17:25 +00:00
|
|
|
if (!show_total) {
|
|
|
|
ret = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
2013-08-23 10:17:25 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
do_show_total:
|
2012-07-25 15:37:18 +00:00
|
|
|
/* get supported num of parameter for total statistics */
|
|
|
|
if ((nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, flags)) < 0)
|
|
|
|
goto failed_stats;
|
|
|
|
|
|
|
|
if (!nparams) {
|
|
|
|
vshPrint(ctl, "%s", _("No total stats available"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-01-22 11:17:18 +00:00
|
|
|
if (VIR_ALLOC_N(params, nparams) < 0)
|
2013-07-04 10:20:45 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* passing start_cpu == -1 gives us domain's total status */
|
2014-09-04 21:08:48 +00:00
|
|
|
if ((stats_per_cpu = virDomainGetCPUStats(dom, params, nparams,
|
|
|
|
-1, 1, flags)) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto failed_stats;
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Total:\n"));
|
2014-09-04 21:08:48 +00:00
|
|
|
for (i = 0; i < stats_per_cpu; i++) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshPrint(ctl, "\t%-12s ", params[i].field);
|
|
|
|
if ((STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
|
|
|
|
STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_USERTIME) ||
|
|
|
|
STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_SYSTEMTIME)) &&
|
|
|
|
params[i].type == VIR_TYPED_PARAM_ULLONG) {
|
|
|
|
vshPrint(ctl, "%9lld.%09lld seconds\n",
|
|
|
|
params[i].value.ul / 1000000000,
|
|
|
|
params[i].value.ul % 1000000000);
|
|
|
|
} else {
|
|
|
|
char *s = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%s\n", s);
|
|
|
|
VIR_FREE(s);
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 11:17:18 +00:00
|
|
|
|
|
|
|
ret = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-22 11:17:18 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
2013-01-22 11:17:18 +00:00
|
|
|
return ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
failed_stats:
|
2013-01-22 11:17:18 +00:00
|
|
|
vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "create" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_create[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("create a domain from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Create a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_create[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("file containing an XML domain description")
|
|
|
|
},
|
2012-07-25 15:37:18 +00:00
|
|
|
#ifndef WIN32
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "console",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("attach to console after creation")
|
|
|
|
},
|
2012-07-25 15:37:18 +00:00
|
|
|
#endif
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "paused",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("leave the guest paused after creation")
|
|
|
|
},
|
|
|
|
{.name = "autodestroy",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("automatically destroy the guest when virsh disconnects")
|
|
|
|
},
|
2013-07-11 15:32:14 +00:00
|
|
|
{.name = "pass-fds",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("pass file descriptors N,M,... to the guest")
|
|
|
|
},
|
2015-01-08 15:26:50 +00:00
|
|
|
{.name = "validate",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("validate the XML against the schema")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdCreate(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *from = NULL;
|
2014-02-24 13:26:53 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
char *buffer;
|
|
|
|
#ifndef WIN32
|
|
|
|
bool console = vshCommandOptBool(cmd, "console");
|
|
|
|
#endif
|
2015-01-08 15:26:50 +00:00
|
|
|
unsigned int flags = 0;
|
2013-07-11 15:32:14 +00:00
|
|
|
size_t nfds = 0;
|
|
|
|
int *fds = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2013-07-11 15:32:14 +00:00
|
|
|
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
|
2014-02-24 13:26:53 +00:00
|
|
|
goto cleanup;
|
2013-07-11 15:32:14 +00:00
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (vshCommandOptBool(cmd, "paused"))
|
|
|
|
flags |= VIR_DOMAIN_START_PAUSED;
|
|
|
|
if (vshCommandOptBool(cmd, "autodestroy"))
|
|
|
|
flags |= VIR_DOMAIN_START_AUTODESTROY;
|
2015-01-08 15:26:50 +00:00
|
|
|
if (vshCommandOptBool(cmd, "validate"))
|
|
|
|
flags |= VIR_DOMAIN_START_VALIDATE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-07-11 15:32:14 +00:00
|
|
|
if (nfds)
|
|
|
|
dom = virDomainCreateXMLWithFiles(ctl->conn, buffer, nfds, fds, flags);
|
|
|
|
else
|
|
|
|
dom = virDomainCreateXML(ctl->conn, buffer, flags);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-02-24 13:26:53 +00:00
|
|
|
if (!dom) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to create domain from %s"), from);
|
2014-02-24 13:26:53 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2014-02-24 13:26:53 +00:00
|
|
|
|
|
|
|
vshPrint(ctl, _("Domain %s created from %s\n"),
|
|
|
|
virDomainGetName(dom), from);
|
|
|
|
#ifndef WIN32
|
|
|
|
if (console)
|
|
|
|
cmdRunConsole(ctl, dom, NULL, 0);
|
|
|
|
#endif
|
|
|
|
virDomainFree(dom);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2014-02-24 13:26:53 +00:00
|
|
|
VIR_FREE(buffer);
|
2013-07-11 15:32:14 +00:00
|
|
|
VIR_FREE(fds);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "define" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_define[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("define (but don't start) a domain from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Define a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_define[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("file containing an XML domain description")
|
|
|
|
},
|
2015-01-08 15:26:50 +00:00
|
|
|
{.name = "validate",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("validate the XML against the schema")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = true;
|
|
|
|
char *buffer;
|
2015-01-08 15:26:50 +00:00
|
|
|
unsigned int flags = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-01-08 15:26:50 +00:00
|
|
|
if (vshCommandOptBool(cmd, "validate"))
|
|
|
|
flags |= VIR_DOMAIN_DEFINE_VALIDATE;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2015-01-08 15:26:50 +00:00
|
|
|
if (flags)
|
|
|
|
dom = virDomainDefineXMLFlags(ctl->conn, buffer, flags);
|
|
|
|
else
|
|
|
|
dom = virDomainDefineXML(ctl->conn, buffer);
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
|
|
|
if (dom != NULL) {
|
|
|
|
vshPrint(ctl, _("Domain %s defined from %s\n"),
|
|
|
|
virDomainGetName(dom), from);
|
|
|
|
virDomainFree(dom);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to define domain from %s"), from);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "destroy" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_destroy[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("destroy (stop) a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Forcefully stop a given domain, but leave its resources intact.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_destroy[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "graceful",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("terminate gracefully")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDestroy(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "graceful"))
|
|
|
|
flags |= VIR_DOMAIN_DESTROY_GRACEFUL;
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
result = virDomainDestroyFlags(dom, VIR_DOMAIN_DESTROY_GRACEFUL);
|
|
|
|
else
|
|
|
|
result = virDomainDestroy(dom);
|
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
vshPrint(ctl, _("Domain %s destroyed\n"), name);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to destroy domain %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "desc" command for managing domain description and title
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_desc[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("show or set domain's description or title")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Allows to show or modify description or title of a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_desc[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get running state")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get persistent configuration")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get current state configuration")
|
|
|
|
},
|
|
|
|
{.name = "title",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get the title instead of description")
|
|
|
|
},
|
|
|
|
{.name = "edit",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("open an editor to modify the description")
|
|
|
|
},
|
|
|
|
{.name = "new-desc",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.help = N_("message")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2013-09-09 08:52:08 +00:00
|
|
|
cmdDesc(vshControl *ctl, const vshCmd *cmd)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
|
|
|
|
bool title = vshCommandOptBool(cmd, "title");
|
|
|
|
bool edit = vshCommandOptBool(cmd, "edit");
|
|
|
|
|
|
|
|
int state;
|
|
|
|
int type;
|
|
|
|
char *desc = NULL;
|
|
|
|
char *desc_edited = NULL;
|
|
|
|
char *tmp = NULL;
|
|
|
|
char *tmpstr;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
bool pad = false;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((state = vshDomainState(ctl, dom, NULL)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (pad)
|
|
|
|
virBufferAddChar(&buf, ' ');
|
|
|
|
pad = true;
|
|
|
|
virBufferAdd(&buf, opt->data, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title)
|
|
|
|
type = VIR_DOMAIN_METADATA_TITLE;
|
|
|
|
else
|
|
|
|
type = VIR_DOMAIN_METADATA_DESCRIPTION;
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to collect new description/title"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
desc = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
if (edit || desc) {
|
|
|
|
if (!desc) {
|
|
|
|
desc = vshGetDomainDescription(ctl, dom, title,
|
|
|
|
config?VIR_DOMAIN_XML_INACTIVE:0);
|
|
|
|
if (!desc)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit) {
|
|
|
|
/* Create and open the temporary file. */
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (!(tmp = vshEditWriteToTempFile(ctl, desc)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Start the editor. */
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (vshEditFile(ctl, tmp) == -1)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Read back the edited file. */
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (!(desc_edited = vshEditReadBackFile(ctl, tmp)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* strip a possible newline at the end of file; some
|
|
|
|
* editors enforce a newline, this makes editing the title
|
|
|
|
* more convenient */
|
|
|
|
if (title &&
|
|
|
|
(tmpstr = strrchr(desc_edited, '\n')) &&
|
|
|
|
*(tmpstr+1) == '\0')
|
|
|
|
*tmpstr = '\0';
|
|
|
|
|
|
|
|
/* Compare original XML with edited. Has it changed at all? */
|
|
|
|
if (STREQ(desc, desc_edited)) {
|
2014-09-10 08:46:41 +00:00
|
|
|
vshPrint(ctl, "%s",
|
|
|
|
title ? _("Domain title not changed\n") :
|
|
|
|
_("Domain description not changed\n"));
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(desc);
|
|
|
|
desc = desc_edited;
|
|
|
|
desc_edited = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) {
|
|
|
|
vshError(ctl, "%s",
|
2014-09-10 08:46:41 +00:00
|
|
|
title ? _("Failed to set new domain title") :
|
|
|
|
_("Failed to set new domain description"));
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-09-10 08:46:41 +00:00
|
|
|
vshPrint(ctl, "%s",
|
|
|
|
title ? _("Domain title updated successfully") :
|
|
|
|
_("Domain description updated successfully"));
|
2012-07-25 15:37:18 +00:00
|
|
|
} else {
|
|
|
|
desc = vshGetDomainDescription(ctl, dom, title,
|
|
|
|
config?VIR_DOMAIN_XML_INACTIVE:0);
|
|
|
|
if (!desc)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (strlen(desc) > 0)
|
|
|
|
vshPrint(ctl, "%s", desc);
|
|
|
|
else
|
2014-09-10 08:46:41 +00:00
|
|
|
vshPrint(ctl,
|
|
|
|
title ? _("No title for domain: %s") :
|
|
|
|
_("No description for domain: %s"),
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainGetName(dom));
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(desc_edited);
|
|
|
|
VIR_FREE(desc);
|
|
|
|
if (tmp) {
|
|
|
|
unlink(tmp);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
}
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-09 08:54:04 +00:00
|
|
|
|
|
|
|
static const vshCmdInfo info_metadata[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("show or set domain's custom XML metadata")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Shows or modifies the XML metadata of a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_metadata[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "uri",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("URI of the namespace")
|
|
|
|
},
|
2013-09-09 08:54:04 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get running state")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get persistent configuration")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("modify/get current state configuration")
|
|
|
|
},
|
|
|
|
{.name = "edit",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("use an editor to change the metadata")
|
|
|
|
},
|
|
|
|
{.name = "key",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-09-09 08:54:04 +00:00
|
|
|
.help = N_("key to be used as a namespace identifier"),
|
|
|
|
},
|
|
|
|
{.name = "set",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-09-09 08:54:04 +00:00
|
|
|
.help = N_("new metadata to set"),
|
|
|
|
},
|
|
|
|
{.name = "remove",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("remove the metadata corresponding to an uri")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* helper to add new metadata using the --edit option */
|
|
|
|
static char *
|
|
|
|
vshDomainGetEditMetadata(vshControl *ctl,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *uri,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (!(ret = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
|
|
|
|
uri, flags))) {
|
|
|
|
vshResetLibvirtError();
|
|
|
|
ret = vshStrdup(ctl, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMetadata(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool edit = vshCommandOptBool(cmd, "edit");
|
2013-09-17 11:40:08 +00:00
|
|
|
bool rem = vshCommandOptBool(cmd, "remove");
|
2013-09-09 08:54:04 +00:00
|
|
|
const char *set = NULL;
|
|
|
|
const char *uri = NULL;
|
|
|
|
const char *key = NULL;
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS("edit", "set");
|
|
|
|
VSH_EXCLUSIVE_OPTIONS("remove", "set");
|
|
|
|
VSH_EXCLUSIVE_OPTIONS("remove", "edit");
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "uri", &uri) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "key", &key) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "set", &set) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((set || edit) && !key) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("namespace key is required when modifying metadata"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-17 11:40:08 +00:00
|
|
|
if (set || rem) {
|
2013-09-09 08:54:04 +00:00
|
|
|
if (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
|
|
|
|
set, key, uri, flags))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-09-17 11:40:08 +00:00
|
|
|
if (rem)
|
2013-09-09 08:54:04 +00:00
|
|
|
vshPrint("%s\n", _("Metadata removed"));
|
|
|
|
else
|
|
|
|
vshPrint("%s\n", _("Metadata modified"));
|
|
|
|
} else if (edit) {
|
|
|
|
#define EDIT_GET_XML \
|
|
|
|
vshDomainGetEditMetadata(ctl, dom, uri, flags)
|
2014-11-14 14:57:17 +00:00
|
|
|
#define EDIT_NOT_CHANGED \
|
|
|
|
do { \
|
|
|
|
vshPrint(ctl, "%s", _("Metadata not changed")); \
|
|
|
|
ret = true; \
|
|
|
|
goto edit_cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
2013-09-09 08:54:04 +00:00
|
|
|
#define EDIT_DEFINE \
|
|
|
|
(virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited, \
|
|
|
|
key, uri, flags) == 0)
|
|
|
|
#include "virsh-edit.c"
|
|
|
|
|
|
|
|
vshPrint("%s\n", _("Metadata modified"));
|
|
|
|
} else {
|
|
|
|
char *data;
|
|
|
|
/* get */
|
|
|
|
if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
|
|
|
|
uri, flags)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s\n", data);
|
|
|
|
VIR_FREE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-09-09 08:54:04 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "inject-nmi" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_inject_nmi[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Inject NMI to the guest")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Inject NMI to the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_inject_nmi[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdInjectNMI(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool ret = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainInjectNMI(dom, 0) < 0)
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "send-key" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_send_key[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Send keycodes to the guest")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Send keycodes (integers or symbolic names) to the guest")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_send_key[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "codeset",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
|
|
|
.help = N_("the codeset of keycodes, default:linux")
|
|
|
|
},
|
|
|
|
{.name = "holdtime",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
|
|
|
.help = N_("the time (in milliseconds) how long the keys will be held")
|
|
|
|
},
|
|
|
|
{.name = "keycode",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the key code")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2013-04-18 08:40:49 +00:00
|
|
|
vshKeyCodeGetInt(const char *key_name)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
2013-12-19 15:40:16 +00:00
|
|
|
if (virStrToLong_ui(key_name, NULL, 0, &val) < 0 || val > 0xffff)
|
2012-07-25 15:37:18 +00:00
|
|
|
return -1;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSendKey(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool ret = false;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *codeset_option;
|
|
|
|
int codeset;
|
2013-04-18 08:42:47 +00:00
|
|
|
unsigned int holdtime = 0;
|
2012-07-25 15:37:18 +00:00
|
|
|
int count = 0;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
int keycode;
|
|
|
|
unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "codeset", &codeset_option) <= 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
codeset_option = "linux";
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0)
|
2013-04-18 08:42:47 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
codeset = virKeycodeSetTypeFromString(codeset_option);
|
2013-04-18 08:40:49 +00:00
|
|
|
if (codeset < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("unknown codeset: '%s'"), codeset_option);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
|
|
|
|
vshError(ctl, _("too many keycodes"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-12-19 15:40:16 +00:00
|
|
|
if ((keycode = vshKeyCodeGetInt(opt->data)) < 0) {
|
|
|
|
if ((keycode = virKeycodeValueFromString(codeset, opt->data)) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("invalid keycode: '%s'"), opt->data);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keycodes[count] = keycode;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0))
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-15 16:01:11 +00:00
|
|
|
/*
|
|
|
|
* "send-process-signal" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_send_process_signal[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Send signals to processes")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Send signals to processes in the guest")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2011-11-15 16:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_send_process_signal[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "pid",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the process ID")
|
|
|
|
},
|
|
|
|
{.name = "signame",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("the signal number or name")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2011-11-15 16:01:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virDomainProcessSignal)
|
|
|
|
VIR_ENUM_IMPL(virDomainProcessSignal,
|
|
|
|
VIR_DOMAIN_PROCESS_SIGNAL_LAST,
|
2013-09-09 09:47:20 +00:00
|
|
|
"nop", "hup", "int", "quit", "ill", /* 0-4 */
|
|
|
|
"trap", "abrt", "bus", "fpe", "kill", /* 5-9 */
|
|
|
|
"usr1", "segv", "usr2", "pipe", "alrm", /* 10-14 */
|
|
|
|
"term", "stkflt", "chld", "cont", "stop", /* 15-19 */
|
|
|
|
"tstp", "ttin", "ttou", "urg", "xcpu", /* 20-24 */
|
2011-11-15 16:01:11 +00:00
|
|
|
"xfsz", "vtalrm", "prof", "winch", "poll", /* 25-29 */
|
2013-09-09 09:47:20 +00:00
|
|
|
"pwr", "sys", "rt0", "rt1", "rt2", /* 30-34 */
|
|
|
|
"rt3", "rt4", "rt5", "rt6", "rt7", /* 35-39 */
|
|
|
|
"rt8", "rt9", "rt10", "rt11", "rt12", /* 40-44 */
|
|
|
|
"rt13", "rt14", "rt15", "rt16", "rt17", /* 45-49 */
|
|
|
|
"rt18", "rt19", "rt20", "rt21", "rt22", /* 50-54 */
|
|
|
|
"rt23", "rt24", "rt25", "rt26", "rt27", /* 55-59 */
|
|
|
|
"rt28", "rt29", "rt30", "rt31", "rt32") /* 60-64 */
|
2011-11-15 16:01:11 +00:00
|
|
|
|
|
|
|
static int getSignalNumber(vshControl *ctl, const char *signame)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int signum;
|
|
|
|
char *lower = vshStrdup(ctl, signame);
|
|
|
|
char *tmp = lower;
|
|
|
|
|
2013-05-21 07:44:53 +00:00
|
|
|
for (i = 0; signame[i]; i++)
|
2011-11-15 16:01:11 +00:00
|
|
|
lower[i] = c_tolower(signame[i]);
|
|
|
|
|
|
|
|
if (virStrToLong_i(lower, NULL, 10, &signum) >= 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STRPREFIX(lower, "sig_"))
|
|
|
|
lower += 4;
|
|
|
|
else if (STRPREFIX(lower, "sig"))
|
|
|
|
lower += 3;
|
|
|
|
|
|
|
|
if ((signum = virDomainProcessSignalTypeFromString(lower)) >= 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
signum = -1;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2011-11-15 16:01:11 +00:00
|
|
|
VIR_FREE(tmp);
|
|
|
|
return signum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool ret = false;
|
2011-11-15 16:01:11 +00:00
|
|
|
const char *signame;
|
|
|
|
long long pid_value;
|
|
|
|
int signum;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0)
|
2013-01-21 14:39:18 +00:00
|
|
|
goto cleanup;
|
2011-11-15 16:01:11 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "signame", &signame) < 0)
|
|
|
|
goto cleanup;
|
2011-11-15 16:01:11 +00:00
|
|
|
|
|
|
|
if ((signum = getSignalNumber(ctl, signame)) < 0) {
|
|
|
|
vshError(ctl, _("malformed signal name: %s"), signame);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainSendProcessSignal(dom, pid_value, signum, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2011-11-15 16:01:11 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "setmem" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_setmem[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("change memory allocation")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Change the current memory allocation in the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_setmem[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "kilobytes",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "size"
|
|
|
|
},
|
|
|
|
{.name = "size",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("new memory size, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSetmem(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
unsigned long long bytes = 0;
|
|
|
|
unsigned long long max;
|
|
|
|
unsigned long kibibytes = 0;
|
|
|
|
bool ret = true;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
/* none of the options were specified */
|
|
|
|
if (!current && !live && !config)
|
|
|
|
flags = -1;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* The API expects 'unsigned long' KiB, so depending on whether we
|
|
|
|
* are 32-bit or 64-bit determines the maximum we can use. */
|
|
|
|
if (sizeof(kibibytes) < sizeof(max))
|
|
|
|
max = 1024ull * ULONG_MAX;
|
|
|
|
else
|
|
|
|
max = ULONG_MAX;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
kibibytes = VIR_DIV_UP(bytes, 1024);
|
|
|
|
|
|
|
|
if (flags == -1) {
|
2014-11-13 14:20:51 +00:00
|
|
|
if (virDomainSetMemory(dom, kibibytes) != 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = false;
|
|
|
|
} else {
|
2014-11-13 14:20:51 +00:00
|
|
|
if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "setmaxmem" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_setmaxmem[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("change maximum memory limit")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Change the maximum memory allocation limit in the guest domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_setmaxmem[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "kilobytes",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "size"
|
|
|
|
},
|
|
|
|
{.name = "size",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("new maximum memory size, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
unsigned long long bytes = 0;
|
|
|
|
unsigned long long max;
|
|
|
|
unsigned long kibibytes = 0;
|
|
|
|
bool ret = true;
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT | VIR_DOMAIN_MEM_MAXIMUM;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
/* none of the options were specified */
|
|
|
|
if (!current && !live && !config)
|
|
|
|
flags = -1;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* The API expects 'unsigned long' KiB, so depending on whether we
|
|
|
|
* are 32-bit or 64-bit determines the maximum we can use. */
|
|
|
|
if (sizeof(kibibytes) < sizeof(max))
|
|
|
|
max = 1024ull * ULONG_MAX;
|
|
|
|
else
|
|
|
|
max = ULONG_MAX;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
kibibytes = VIR_DIV_UP(bytes, 1024);
|
|
|
|
|
|
|
|
if (flags == -1) {
|
|
|
|
if (virDomainSetMaxMemory(dom, kibibytes) != 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "memtune" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_memtune[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Get or set memory parameters")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get or set the current memory parameters for a guest"
|
2012-07-25 15:37:18 +00:00
|
|
|
" domain.\n"
|
|
|
|
" To get the memory parameters use following command: \n\n"
|
2013-02-07 15:25:10 +00:00
|
|
|
" virsh # memtune <domain>")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_memtune[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "hard-limit",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Max memory, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "soft-limit",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Memory during contention, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "swap-hard-limit",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Max memory plus swap, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "min-guarantee",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Min guaranteed memory, as scaled integer (default KiB)")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
2015-03-02 15:26:52 +00:00
|
|
|
/**
|
|
|
|
* vshMemtuneGetSize
|
|
|
|
*
|
|
|
|
* @cmd: pointer to vshCmd
|
|
|
|
* @name: name of a parameter for which we would like to get a value
|
|
|
|
* @value: pointer to variable where the value will be stored
|
|
|
|
*
|
|
|
|
* This function will parse virsh command line in order to load a value of
|
|
|
|
* specified parameter. If the value is -1 we will handle it as unlimited and
|
|
|
|
* use VIR_DOMAIN_MEMORY_PARAM_UNLIMITED instead.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* >0 if option found and valid
|
|
|
|
* 0 if option not found and not required
|
|
|
|
* <0 in all other cases
|
|
|
|
*/
|
2012-07-25 15:37:18 +00:00
|
|
|
static int
|
2015-06-02 09:17:28 +00:00
|
|
|
vshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd, const char *name, long long *value)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long long tmp;
|
|
|
|
const char *str;
|
|
|
|
char *end;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
ret = vshCommandOptString(ctl, cmd, name, &str);
|
2012-07-25 15:37:18 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
return ret;
|
|
|
|
if (virStrToLong_ll(str, &end, 10, value) < 0)
|
|
|
|
return -1;
|
|
|
|
if (*value < 0) {
|
|
|
|
*value = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
tmp = *value;
|
|
|
|
if (virScaleInteger(&tmp, end, 1024, LLONG_MAX) < 0)
|
|
|
|
return -1;
|
|
|
|
*value = VIR_DIV_UP(tmp, 1024);
|
2015-03-02 15:26:52 +00:00
|
|
|
return 1;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMemtune(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
2015-03-02 15:26:52 +00:00
|
|
|
long long tmpVal;
|
2012-07-25 15:37:18 +00:00
|
|
|
int nparams = 0;
|
2013-01-15 23:09:05 +00:00
|
|
|
int maxparams = 0;
|
2015-03-02 15:26:52 +00:00
|
|
|
int rc;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-01-15 23:09:05 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool ret = false;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-03-02 15:26:52 +00:00
|
|
|
#define PARSE_MEMTUNE_PARAM(NAME, FIELD) \
|
2015-06-02 09:17:28 +00:00
|
|
|
if ((rc = vshMemtuneGetSize(ctl, cmd, NAME, &tmpVal)) < 0) { \
|
2015-04-14 10:24:40 +00:00
|
|
|
vshError(ctl, _("Unable to parse integer parameter %s"), NAME); \
|
2015-03-02 15:26:52 +00:00
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
if (rc == 1) { \
|
|
|
|
if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, \
|
|
|
|
FIELD, tmpVal) < 0) \
|
|
|
|
goto save_error; \
|
|
|
|
} \
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
|
2015-03-02 15:26:52 +00:00
|
|
|
PARSE_MEMTUNE_PARAM("hard-limit", VIR_DOMAIN_MEMORY_HARD_LIMIT);
|
|
|
|
PARSE_MEMTUNE_PARAM("soft-limit", VIR_DOMAIN_MEMORY_SOFT_LIMIT);
|
|
|
|
PARSE_MEMTUNE_PARAM("swap-hard-limit", VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT);
|
|
|
|
PARSE_MEMTUNE_PARAM("min-guarantee", VIR_DOMAIN_MEMORY_MIN_GUARANTEE);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-02 15:26:52 +00:00
|
|
|
#undef PARSE_MEMTUNE_PARAM
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* get the number of memory parameters */
|
|
|
|
if (virDomainGetMemoryParameters(dom, NULL, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get number of memory parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* nothing to output */
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now go get all the memory parameters */
|
|
|
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
|
|
if (virDomainGetMemoryParameters(dom, params, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to get memory parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
if (params[i].type == VIR_TYPED_PARAM_ULLONG &&
|
|
|
|
params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) {
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, _("unlimited"));
|
|
|
|
} else {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virDomainSetMemoryParameters(dom, params, nparams, flags) != 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:09:05 +00:00
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-15 23:09:05 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-01-15 23:09:05 +00:00
|
|
|
vshSaveLibvirtError();
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to change memory parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "numatune" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_numatune[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Get or set numa parameters")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get or set the current numa parameters for a guest"
|
2012-07-25 15:37:18 +00:00
|
|
|
" domain.\n"
|
|
|
|
" To get the numa parameters use following command: \n\n"
|
2013-02-07 15:25:10 +00:00
|
|
|
" virsh # numatune <domain>")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_numatune[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "mode",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-07-09 07:53:14 +00:00
|
|
|
.help = N_("NUMA mode, one of strict, preferred and interleave \n"
|
|
|
|
"or a number from the virDomainNumatuneMemMode enum")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "nodeset",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("NUMA node selections to set")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNumatune(vshControl * ctl, const vshCmd * cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
int nparams = 0;
|
2013-01-15 23:09:55 +00:00
|
|
|
int maxparams = 0;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-01-15 23:09:55 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *nodeset = NULL;
|
|
|
|
bool ret = false;
|
2013-03-07 12:38:19 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
const char *mode = NULL;
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "nodeset", &nodeset) < 0)
|
2013-01-15 23:09:55 +00:00
|
|
|
goto cleanup;
|
2013-01-21 14:39:18 +00:00
|
|
|
|
2013-01-15 23:09:55 +00:00
|
|
|
if (nodeset &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_NUMA_NODESET, nodeset) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
|
2013-01-15 23:09:55 +00:00
|
|
|
goto cleanup;
|
2013-01-21 14:39:18 +00:00
|
|
|
|
2013-01-15 23:09:55 +00:00
|
|
|
if (mode) {
|
|
|
|
int m;
|
|
|
|
/* Accept string or integer, in case server understands newer
|
|
|
|
* integer than what strings we were compiled with
|
|
|
|
*/
|
|
|
|
if ((m = virDomainNumatuneMemModeTypeFromString(mode)) < 0 &&
|
|
|
|
virStrToLong_i(mode, NULL, 0, &m) < 0) {
|
|
|
|
vshError(ctl, _("Invalid mode: %s"), mode);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virTypedParamsAddInt(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_DOMAIN_NUMA_MODE, m) < 0)
|
|
|
|
goto save_error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* get the number of numa parameters */
|
|
|
|
if (virDomainGetNumaParameters(dom, NULL, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("Unable to get number of memory parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nparams == 0) {
|
|
|
|
/* nothing to output */
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now go get all the numa parameters */
|
|
|
|
params = vshCalloc(ctl, nparams, sizeof(*params));
|
|
|
|
if (virDomainGetNumaParameters(dom, params, &nparams, flags) != 0) {
|
|
|
|
vshError(ctl, "%s", _("Unable to get numa parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
if (params[i].type == VIR_TYPED_PARAM_INT &&
|
|
|
|
STREQ(params[i].field, VIR_DOMAIN_NUMA_MODE)) {
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field,
|
|
|
|
virDomainNumatuneMemModeTypeToString(params[i].value.i));
|
|
|
|
} else {
|
|
|
|
char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
|
|
|
|
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virDomainSetNumaParameters(dom, params, nparams, flags) != 0)
|
2013-01-15 23:09:55 +00:00
|
|
|
goto error;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:09:55 +00:00
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-15 23:09:55 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
2013-01-15 23:09:55 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-01-15 23:09:55 +00:00
|
|
|
vshSaveLibvirtError();
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2013-01-15 23:09:55 +00:00
|
|
|
vshError(ctl, "%s", _("Unable to change numa parameters"));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-12-21 14:26:27 +00:00
|
|
|
/*
|
|
|
|
* "qemu-monitor-command" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_qemu_monitor_command[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("QEMU Monitor Command")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("QEMU Monitor Command")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_qemu_monitor_command[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "hmp",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("command is in human monitor protocol")
|
|
|
|
},
|
|
|
|
{.name = "pretty",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("pretty-print any qemu monitor protocol output")
|
|
|
|
},
|
|
|
|
{.name = "cmd",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("command")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
char *monitor_cmd = NULL;
|
|
|
|
char *result = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
bool pad = false;
|
|
|
|
virJSONValuePtr pretty = NULL;
|
|
|
|
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (dom == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2012-12-21 14:26:27 +00:00
|
|
|
if (pad)
|
|
|
|
virBufferAddChar(&buf, ' ');
|
|
|
|
pad = true;
|
|
|
|
virBufferAdd(&buf, opt->data, -1);
|
|
|
|
}
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to collect command"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
monitor_cmd = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "hmp")) {
|
|
|
|
if (vshCommandOptBool(cmd, "pretty")) {
|
|
|
|
vshError(ctl, _("--hmp and --pretty are not compatible"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "pretty")) {
|
|
|
|
char *tmp;
|
|
|
|
pretty = virJSONValueFromString(result);
|
|
|
|
if (pretty && (tmp = virJSONValueToString(pretty, true))) {
|
|
|
|
VIR_FREE(result);
|
|
|
|
result = tmp;
|
|
|
|
} else {
|
|
|
|
vshResetLibvirtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vshPrint(ctl, "%s\n", result);
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-12-21 14:26:27 +00:00
|
|
|
VIR_FREE(result);
|
|
|
|
VIR_FREE(monitor_cmd);
|
|
|
|
virJSONValueFree(pretty);
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-31 23:52:17 +00:00
|
|
|
/*
|
|
|
|
* "qemu-monitor-event" command
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vshQemuEventData {
|
|
|
|
vshControl *ctl;
|
|
|
|
bool loop;
|
|
|
|
bool pretty;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
typedef struct vshQemuEventData vshQemuEventData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventPrint(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom,
|
|
|
|
const char *event, long long seconds, unsigned int micros,
|
|
|
|
const char *details, void *opaque)
|
|
|
|
{
|
|
|
|
vshQemuEventData *data = opaque;
|
|
|
|
virJSONValuePtr pretty = NULL;
|
|
|
|
char *str = NULL;
|
|
|
|
|
|
|
|
if (!data->loop && data->count)
|
|
|
|
return;
|
|
|
|
if (data->pretty && details) {
|
|
|
|
pretty = virJSONValueFromString(details);
|
|
|
|
if (pretty && (str = virJSONValueToString(pretty, true)))
|
|
|
|
details = str;
|
|
|
|
}
|
|
|
|
vshPrint(data->ctl, "event %s at %lld.%06u for domain %s: %s\n",
|
|
|
|
event, seconds, micros, virDomainGetName(dom), NULLSTR(details));
|
|
|
|
data->count++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
|
|
|
|
VIR_FREE(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const vshCmdInfo info_qemu_monitor_event[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("QEMU Monitor Events")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Listen for QEMU Monitor Events")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_qemu_monitor_event[] = {
|
|
|
|
{.name = "domain",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-01-31 23:52:17 +00:00
|
|
|
.help = N_("filter by domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "event",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-01-31 23:52:17 +00:00
|
|
|
.help = N_("filter by event name")
|
|
|
|
},
|
|
|
|
{.name = "pretty",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("pretty-print any JSON output")
|
|
|
|
},
|
|
|
|
{.name = "loop",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("loop until timeout or interrupt, rather than one-shot")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("timeout seconds")
|
|
|
|
},
|
2014-02-06 21:46:52 +00:00
|
|
|
{.name = "regex",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("treat event as a regex rather than literal filter")
|
|
|
|
},
|
|
|
|
{.name = "no-case",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("treat event case-insensitively")
|
|
|
|
},
|
2014-01-31 23:52:17 +00:00
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
int eventId = -1;
|
|
|
|
int timeout = 0;
|
|
|
|
const char *event = NULL;
|
|
|
|
vshQemuEventData data;
|
|
|
|
|
2014-02-06 21:46:52 +00:00
|
|
|
if (vshCommandOptBool(cmd, "regex"))
|
|
|
|
flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX;
|
|
|
|
if (vshCommandOptBool(cmd, "no-case"))
|
|
|
|
flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE;
|
|
|
|
|
2014-01-31 23:52:17 +00:00
|
|
|
data.ctl = ctl;
|
|
|
|
data.loop = vshCommandOptBool(cmd, "loop");
|
|
|
|
data.pretty = vshCommandOptBool(cmd, "pretty");
|
|
|
|
data.count = 0;
|
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
|
|
|
return false;
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "event", &event) < 0)
|
2014-01-31 23:52:17 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "domain"))
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (vshEventStart(ctl, timeout) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((eventId = virConnectDomainQemuMonitorEventRegister(ctl->conn, dom,
|
|
|
|
event,
|
|
|
|
vshEventPrint,
|
|
|
|
&data, NULL,
|
|
|
|
flags)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
switch (vshEventWait(ctl)) {
|
|
|
|
case VSH_EVENT_INTERRUPT:
|
|
|
|
vshPrint(ctl, _("event loop interrupted\n"));
|
|
|
|
break;
|
|
|
|
case VSH_EVENT_TIMEOUT:
|
|
|
|
vshPrint(ctl, _("event loop timed out\n"));
|
|
|
|
break;
|
|
|
|
case VSH_EVENT_DONE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
vshPrint(ctl, _("events received: %d\n"), data.count);
|
|
|
|
if (data.count)
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2014-01-31 23:52:17 +00:00
|
|
|
vshEventCleanup(ctl);
|
|
|
|
if (eventId >= 0 &&
|
|
|
|
virConnectDomainQemuMonitorEventDeregister(ctl->conn, eventId) < 0)
|
|
|
|
ret = false;
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-21 14:26:27 +00:00
|
|
|
/*
|
|
|
|
* "qemu-attach" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_qemu_attach[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("QEMU Attach")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("QEMU Attach")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_qemu_attach[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "pid",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("pid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdQemuAttach(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
unsigned int pid_value; /* API uses unsigned int, not pid_t */
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0)
|
2012-12-21 14:26:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-09-04 19:42:08 +00:00
|
|
|
if (!(dom = virDomainQemuAttach(ctl->conn, pid_value, flags))) {
|
2012-12-21 14:26:27 +00:00
|
|
|
vshError(ctl, _("Failed to attach to pid %u"), pid_value);
|
2014-09-04 19:42:08 +00:00
|
|
|
goto cleanup;
|
2012-12-21 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 19:42:08 +00:00
|
|
|
vshPrint(ctl, _("Domain %s attached to pid %u\n"),
|
|
|
|
virDomainGetName(dom), pid_value);
|
|
|
|
virDomainFree(dom);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-12-21 14:26:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "qemu-agent-command" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_qemu_agent_command[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("QEMU Guest Agent Command")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Run an arbitrary qemu guest agent command; use at your own risk")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_qemu_agent_command[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
|
|
|
.help = N_("timeout seconds. must be positive.")
|
|
|
|
},
|
|
|
|
{.name = "async",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("execute command without waiting for timeout")
|
|
|
|
},
|
|
|
|
{.name = "block",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("execute command without timeout")
|
|
|
|
},
|
2013-05-14 15:32:33 +00:00
|
|
|
{.name = "pretty",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("pretty-print the output")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "cmd",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("command")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 14:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
char *guest_agent_cmd = NULL;
|
|
|
|
char *result = NULL;
|
|
|
|
int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT;
|
|
|
|
int judge = 0;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
bool pad = false;
|
2013-05-14 15:32:33 +00:00
|
|
|
virJSONValuePtr pretty = NULL;
|
2012-12-21 14:26:27 +00:00
|
|
|
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (dom == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2012-12-21 14:26:27 +00:00
|
|
|
if (pad)
|
|
|
|
virBufferAddChar(&buf, ' ');
|
|
|
|
pad = true;
|
|
|
|
virBufferAdd(&buf, opt->data, -1);
|
|
|
|
}
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to collect command"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
guest_agent_cmd = virBufferContentAndReset(&buf);
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout);
|
2015-06-02 09:17:29 +00:00
|
|
|
if (judge < 0)
|
2012-12-21 14:26:27 +00:00
|
|
|
goto cleanup;
|
2015-06-02 09:17:29 +00:00
|
|
|
else if (judge > 0)
|
2012-12-21 14:26:27 +00:00
|
|
|
judge = 1;
|
|
|
|
if (judge && timeout < 1) {
|
|
|
|
vshError(ctl, "%s", _("timeout must be positive"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "async")) {
|
|
|
|
timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT;
|
|
|
|
judge++;
|
|
|
|
}
|
|
|
|
if (vshCommandOptBool(cmd, "block")) {
|
|
|
|
timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK;
|
|
|
|
judge++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (judge > 1) {
|
|
|
|
vshError(ctl, "%s", _("timeout, async and block options are exclusive"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-03 13:42:26 +00:00
|
|
|
|
2012-12-21 14:26:27 +00:00
|
|
|
result = virDomainQemuAgentCommand(dom, guest_agent_cmd, timeout, flags);
|
2013-06-03 13:42:26 +00:00
|
|
|
if (!result)
|
|
|
|
goto cleanup;
|
2012-12-21 14:26:27 +00:00
|
|
|
|
2013-05-14 15:32:33 +00:00
|
|
|
if (vshCommandOptBool(cmd, "pretty")) {
|
|
|
|
char *tmp;
|
|
|
|
pretty = virJSONValueFromString(result);
|
|
|
|
if (pretty && (tmp = virJSONValueToString(pretty, true))) {
|
|
|
|
VIR_FREE(result);
|
|
|
|
result = tmp;
|
|
|
|
} else {
|
|
|
|
vshResetLibvirtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-14 15:27:01 +00:00
|
|
|
vshPrint(ctl, "%s\n", result);
|
2012-12-21 14:26:27 +00:00
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-12-21 14:26:27 +00:00
|
|
|
VIR_FREE(result);
|
|
|
|
VIR_FREE(guest_agent_cmd);
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-21 16:51:33 +00:00
|
|
|
/*
|
|
|
|
* "lxc-enter-namespace" namespace
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_lxc_enter_namespace[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("LXC Guest Enter Namespace")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Run an arbitrary lxc guest enter namespace; use at your own risk")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 16:51:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_lxc_enter_namespace[] = {
|
2013-08-26 12:36:52 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "noseclabel",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Do not change process security label")
|
|
|
|
},
|
|
|
|
{.name = "cmd",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("namespace")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-12-21 16:51:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
char **cmdargv = NULL;
|
|
|
|
size_t ncmdargv = 0;
|
|
|
|
pid_t pid;
|
|
|
|
int nfdlist;
|
|
|
|
int *fdlist;
|
|
|
|
size_t i;
|
2013-03-12 17:24:01 +00:00
|
|
|
bool setlabel = true;
|
|
|
|
virSecurityModelPtr secmodel = NULL;
|
|
|
|
virSecurityLabelPtr seclabel = NULL;
|
2012-12-21 16:51:33 +00:00
|
|
|
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (dom == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-12 17:24:01 +00:00
|
|
|
if (vshCommandOptBool(cmd, "noseclabel"))
|
|
|
|
setlabel = false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2012-12-21 16:51:33 +00:00
|
|
|
if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) {
|
|
|
|
vshError(ctl, _("%s: %d: failed to allocate argv"),
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
}
|
|
|
|
cmdargv[ncmdargv-1] = opt->data;
|
|
|
|
}
|
|
|
|
if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) {
|
|
|
|
vshError(ctl, _("%s: %d: failed to allocate argv"),
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
}
|
|
|
|
cmdargv[ncmdargv - 1] = NULL;
|
|
|
|
|
|
|
|
if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-12 17:24:01 +00:00
|
|
|
if (setlabel) {
|
|
|
|
if (VIR_ALLOC(secmodel) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to allocate security model"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_ALLOC(seclabel) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to allocate security label"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virNodeGetSecurityModel(ctl->conn, secmodel) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virDomainGetSecurityLabel(dom, seclabel) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-12-21 16:51:33 +00:00
|
|
|
/* Fork once because we don't want to affect
|
virFork: simplify semantics
The old semantics of virFork() violates the priciple of good
usability: it requires the caller to check the pid argument
after use, *even when virFork returned -1*, in order to properly
abort a child process that failed setup done immediately after
fork() - that is, the caller must call _exit() in the child.
While uses in virfile.c did this correctly, uses in 'virsh
lxc-enter-namespace' and 'virt-login-shell' would happily return
from the calling function in both the child and the parent,
leading to very confusing results. [Thankfully, I found the
problem by inspection, and can't actually trigger the double
return on error without an LD_PRELOAD library.]
It is much better if the semantics of virFork are impossible
to abuse. Looking at virFork(), the parent could only ever
return -1 with a non-negative pid if it misused pthread_sigmask,
but this never happens. Up until this patch series, the child
could return -1 with non-negative pid if it fails to set up
signals correctly, but we recently fixed that to make the child
call _exit() at that point instead of forcing the caller to do
it. Thus, the return value and contents of the pid argument are
now redundant (a -1 return now happens only for failure to fork,
a child 0 return only happens for a successful 0 pid, and a
parent 0 return only happens for a successful non-zero pid),
so we might as well return the pid directly rather than an
integer of whether it succeeded or failed; this is also good
from the interface design perspective as users are already
familiar with fork() semantics.
One last change in this patch: before returning the pid directly,
I found cases where using virProcessWait unconditionally on a
cleanup path of a virFork's -1 pid return would be nicer if there
were a way to avoid it overwriting an earlier message. While
such paths are a bit harder to come by with my change to a direct
pid return, I decided to keep the virProcessWait change in this
patch.
* src/util/vircommand.h (virFork): Change signature.
* src/util/vircommand.c (virFork): Guarantee that child will only
return on success, to simplify callers. Return pid rather than
status, now that the situations are always the same.
(virExec): Adjust caller, also avoid open-coding process death.
* src/util/virprocess.c (virProcessWait): Tweak semantics when pid
is -1.
(virProcessRunInMountNamespace): Adjust caller.
* src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
(virDirCreate): Likewise.
* tools/virt-login-shell.c (main): Likewise.
* tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise.
* tests/commandtest.c (test23): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-22 00:54:33 +00:00
|
|
|
* virsh's namespace itself, and because user namespace
|
|
|
|
* can only be changed in single-threaded process
|
2012-12-21 16:51:33 +00:00
|
|
|
*/
|
virFork: simplify semantics
The old semantics of virFork() violates the priciple of good
usability: it requires the caller to check the pid argument
after use, *even when virFork returned -1*, in order to properly
abort a child process that failed setup done immediately after
fork() - that is, the caller must call _exit() in the child.
While uses in virfile.c did this correctly, uses in 'virsh
lxc-enter-namespace' and 'virt-login-shell' would happily return
from the calling function in both the child and the parent,
leading to very confusing results. [Thankfully, I found the
problem by inspection, and can't actually trigger the double
return on error without an LD_PRELOAD library.]
It is much better if the semantics of virFork are impossible
to abuse. Looking at virFork(), the parent could only ever
return -1 with a non-negative pid if it misused pthread_sigmask,
but this never happens. Up until this patch series, the child
could return -1 with non-negative pid if it fails to set up
signals correctly, but we recently fixed that to make the child
call _exit() at that point instead of forcing the caller to do
it. Thus, the return value and contents of the pid argument are
now redundant (a -1 return now happens only for failure to fork,
a child 0 return only happens for a successful 0 pid, and a
parent 0 return only happens for a successful non-zero pid),
so we might as well return the pid directly rather than an
integer of whether it succeeded or failed; this is also good
from the interface design perspective as users are already
familiar with fork() semantics.
One last change in this patch: before returning the pid directly,
I found cases where using virProcessWait unconditionally on a
cleanup path of a virFork's -1 pid return would be nicer if there
were a way to avoid it overwriting an earlier message. While
such paths are a bit harder to come by with my change to a direct
pid return, I decided to keep the virProcessWait change in this
patch.
* src/util/vircommand.h (virFork): Change signature.
* src/util/vircommand.c (virFork): Guarantee that child will only
return on success, to simplify callers. Return pid rather than
status, now that the situations are always the same.
(virExec): Adjust caller, also avoid open-coding process death.
* src/util/virprocess.c (virProcessWait): Tweak semantics when pid
is -1.
(virProcessRunInMountNamespace): Adjust caller.
* src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
(virDirCreate): Likewise.
* tools/virt-login-shell.c (main): Likewise.
* tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise.
* tests/commandtest.c (test23): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-22 00:54:33 +00:00
|
|
|
if ((pid = virFork()) < 0)
|
2012-12-21 16:51:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (pid == 0) {
|
2013-12-23 16:32:45 +00:00
|
|
|
int status;
|
|
|
|
|
2013-03-12 17:24:01 +00:00
|
|
|
if (setlabel &&
|
|
|
|
virDomainLxcEnterSecurityLabel(secmodel,
|
|
|
|
seclabel,
|
|
|
|
NULL,
|
|
|
|
0) < 0)
|
2013-12-23 16:32:45 +00:00
|
|
|
_exit(EXIT_CANCELED);
|
2013-03-12 17:24:01 +00:00
|
|
|
|
2012-12-21 16:51:33 +00:00
|
|
|
if (virDomainLxcEnterNamespace(dom,
|
|
|
|
nfdlist,
|
|
|
|
fdlist,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0) < 0)
|
2013-12-23 16:32:45 +00:00
|
|
|
_exit(EXIT_CANCELED);
|
2012-12-21 16:51:33 +00:00
|
|
|
|
|
|
|
/* Fork a second time because entering the
|
|
|
|
* pid namespace only takes effect after fork
|
|
|
|
*/
|
virFork: simplify semantics
The old semantics of virFork() violates the priciple of good
usability: it requires the caller to check the pid argument
after use, *even when virFork returned -1*, in order to properly
abort a child process that failed setup done immediately after
fork() - that is, the caller must call _exit() in the child.
While uses in virfile.c did this correctly, uses in 'virsh
lxc-enter-namespace' and 'virt-login-shell' would happily return
from the calling function in both the child and the parent,
leading to very confusing results. [Thankfully, I found the
problem by inspection, and can't actually trigger the double
return on error without an LD_PRELOAD library.]
It is much better if the semantics of virFork are impossible
to abuse. Looking at virFork(), the parent could only ever
return -1 with a non-negative pid if it misused pthread_sigmask,
but this never happens. Up until this patch series, the child
could return -1 with non-negative pid if it fails to set up
signals correctly, but we recently fixed that to make the child
call _exit() at that point instead of forcing the caller to do
it. Thus, the return value and contents of the pid argument are
now redundant (a -1 return now happens only for failure to fork,
a child 0 return only happens for a successful 0 pid, and a
parent 0 return only happens for a successful non-zero pid),
so we might as well return the pid directly rather than an
integer of whether it succeeded or failed; this is also good
from the interface design perspective as users are already
familiar with fork() semantics.
One last change in this patch: before returning the pid directly,
I found cases where using virProcessWait unconditionally on a
cleanup path of a virFork's -1 pid return would be nicer if there
were a way to avoid it overwriting an earlier message. While
such paths are a bit harder to come by with my change to a direct
pid return, I decided to keep the virProcessWait change in this
patch.
* src/util/vircommand.h (virFork): Change signature.
* src/util/vircommand.c (virFork): Guarantee that child will only
return on success, to simplify callers. Return pid rather than
status, now that the situations are always the same.
(virExec): Adjust caller, also avoid open-coding process death.
* src/util/virprocess.c (virProcessWait): Tweak semantics when pid
is -1.
(virProcessRunInMountNamespace): Adjust caller.
* src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
(virDirCreate): Likewise.
* tools/virt-login-shell.c (main): Likewise.
* tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise.
* tests/commandtest.c (test23): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-22 00:54:33 +00:00
|
|
|
if ((pid = virFork()) < 0)
|
2013-12-23 16:32:45 +00:00
|
|
|
_exit(EXIT_CANCELED);
|
2012-12-21 16:51:33 +00:00
|
|
|
if (pid == 0) {
|
|
|
|
execv(cmdargv[0], cmdargv);
|
2013-12-23 16:32:45 +00:00
|
|
|
_exit(errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE);
|
2012-12-21 16:51:33 +00:00
|
|
|
}
|
2013-12-23 16:32:45 +00:00
|
|
|
if (virProcessWait(pid, &status, true) < 0)
|
|
|
|
_exit(EXIT_CANNOT_INVOKE);
|
|
|
|
virProcessExitWithStatus(status);
|
2012-12-21 16:51:33 +00:00
|
|
|
} else {
|
2013-05-21 07:44:53 +00:00
|
|
|
for (i = 0; i < nfdlist; i++)
|
2012-12-21 16:51:33 +00:00
|
|
|
VIR_FORCE_CLOSE(fdlist[i]);
|
|
|
|
VIR_FREE(fdlist);
|
2013-12-23 16:32:45 +00:00
|
|
|
if (virProcessWait(pid, NULL, false) < 0) {
|
|
|
|
vshReportError(ctl);
|
2012-12-21 16:51:33 +00:00
|
|
|
goto cleanup;
|
2013-12-23 16:32:45 +00:00
|
|
|
}
|
2012-12-21 16:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-03-12 17:24:01 +00:00
|
|
|
VIR_FREE(seclabel);
|
|
|
|
VIR_FREE(secmodel);
|
2012-12-21 16:51:33 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
VIR_FREE(cmdargv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "dumpxml" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_dumpxml[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("domain information in XML")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Output the domain information as an XML dump to stdout.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_dumpxml[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "inactive",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("show inactive defined XML")
|
|
|
|
},
|
|
|
|
{.name = "security-info",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("include security sensitive information in XML dump")
|
|
|
|
},
|
|
|
|
{.name = "update-cpu",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("update guest CPU according to host CPU")
|
|
|
|
},
|
|
|
|
{.name = "migratable",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("provide XML suitable for migrations")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = true;
|
|
|
|
char *dump;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
bool inactive = vshCommandOptBool(cmd, "inactive");
|
|
|
|
bool secure = vshCommandOptBool(cmd, "security-info");
|
|
|
|
bool update = vshCommandOptBool(cmd, "update-cpu");
|
2012-10-08 09:58:05 +00:00
|
|
|
bool migratable = vshCommandOptBool(cmd, "migratable");
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (inactive)
|
|
|
|
flags |= VIR_DOMAIN_XML_INACTIVE;
|
|
|
|
if (secure)
|
|
|
|
flags |= VIR_DOMAIN_XML_SECURE;
|
|
|
|
if (update)
|
|
|
|
flags |= VIR_DOMAIN_XML_UPDATE_CPU;
|
2012-10-08 09:58:05 +00:00
|
|
|
if (migratable)
|
|
|
|
flags |= VIR_DOMAIN_XML_MIGRATABLE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dump = virDomainGetXMLDesc(dom, flags);
|
|
|
|
if (dump != NULL) {
|
|
|
|
vshPrint(ctl, "%s", dump);
|
|
|
|
VIR_FREE(dump);
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domxml-from-native" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domxmlfromnative[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Convert native config to domain XML")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Convert native guest configuration format to domain XML format.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domxmlfromnative[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "format",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("source config data format")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("config data file to import from")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
const char *format = NULL;
|
|
|
|
const char *configFile = NULL;
|
|
|
|
char *configData;
|
|
|
|
char *xmlData;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "config", &configFile) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2014-10-14 08:04:31 +00:00
|
|
|
if (virFileReadAll(configFile, VSH_MAX_XML_FILE, &configData) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
|
|
|
|
if (xmlData != NULL) {
|
|
|
|
vshPrint(ctl, "%s", xmlData);
|
|
|
|
VIR_FREE(xmlData);
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(configData);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domxml-to-native" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domxmltonative[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Convert domain XML to native config")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Convert domain XML config to a native guest configuration format.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domxmltonative[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "format",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("target config data type format")
|
|
|
|
},
|
|
|
|
{.name = "xml",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("xml data file to export from")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
const char *format = NULL;
|
|
|
|
const char *xmlFile = NULL;
|
|
|
|
char *configData;
|
|
|
|
char *xmlData;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
2014-10-14 08:04:31 +00:00
|
|
|
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
|
|
|
|
if (configData != NULL) {
|
|
|
|
vshPrint(ctl, "%s", configData);
|
|
|
|
VIR_FREE(configData);
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(xmlData);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domname" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domname[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("convert a domain id or UUID to domain name")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domname[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomname(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
|
|
|
|
VSH_BYID|VSH_BYUUID)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s\n", virDomainGetName(dom));
|
|
|
|
virDomainFree(dom);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domid" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domid[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("convert a domain name or UUID to domain id")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domid[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomid(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
|
|
|
|
VSH_BYNAME|VSH_BYUUID)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
id = virDomainGetID(dom);
|
|
|
|
if (id == ((unsigned int)-1))
|
|
|
|
vshPrint(ctl, "%s\n", "-");
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "%d\n", id);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domuuid" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domuuid[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("convert a domain name or id to domain UUID")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domuuid[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain id or name")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomuuid(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
|
|
|
|
VSH_BYNAME|VSH_BYID)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainGetUUIDString(dom, uuid) != -1)
|
|
|
|
vshPrint(ctl, "%s\n", uuid);
|
|
|
|
else
|
|
|
|
vshError(ctl, "%s", _("failed to get domain UUID"));
|
|
|
|
|
|
|
|
virDomainFree(dom);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "migrate" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_migrate[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("migrate domain to another host")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Migrate domain to another host. Add --live for live migration.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_migrate[] = {
|
2014-11-11 09:45:24 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "desturi",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("connection URI of the destination host as seen from the client(normal migration) or source(p2p migration)")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("live migration")
|
|
|
|
},
|
|
|
|
{.name = "offline",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("offline migration")
|
|
|
|
},
|
|
|
|
{.name = "p2p",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("peer-2-peer migration")
|
|
|
|
},
|
|
|
|
{.name = "direct",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("direct migration")
|
|
|
|
},
|
|
|
|
{.name = "tunneled",
|
|
|
|
.type = VSH_OT_ALIAS,
|
|
|
|
.help = "tunnelled"
|
|
|
|
},
|
|
|
|
{.name = "tunnelled",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("tunnelled migration")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("persist VM on destination")
|
|
|
|
},
|
|
|
|
{.name = "undefinesource",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("undefine VM on source")
|
|
|
|
},
|
|
|
|
{.name = "suspend",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("do not restart the domain on the destination host")
|
|
|
|
},
|
|
|
|
{.name = "copy-storage-all",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("migration with non-shared storage with full disk copy")
|
|
|
|
},
|
|
|
|
{.name = "copy-storage-inc",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("migration with non-shared storage with incremental copy (same base image shared between source and destination)")
|
|
|
|
},
|
|
|
|
{.name = "change-protection",
|
|
|
|
.type = VSH_OT_BOOL,
|
2013-03-26 03:02:17 +00:00
|
|
|
.help = N_("prevent any configuration changes to domain until migration ends")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "unsafe",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force migration even if it may be unsafe")
|
|
|
|
},
|
|
|
|
{.name = "verbose",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("display the progress of migration")
|
|
|
|
},
|
2013-01-10 12:39:34 +00:00
|
|
|
{.name = "compressed",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("compress repeated pages during live migration")
|
|
|
|
},
|
2014-02-06 23:44:36 +00:00
|
|
|
{.name = "auto-converge",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force convergence during live migration")
|
|
|
|
},
|
2014-01-13 06:28:12 +00:00
|
|
|
{.name = "rdma-pin-all",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("support memory pinning during RDMA live migration")
|
|
|
|
},
|
2013-06-12 14:11:21 +00:00
|
|
|
{.name = "abort-on-error",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("abort on soft errors during migration")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "migrateuri",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("migration URI, usually can be omitted")
|
|
|
|
},
|
2013-06-18 07:46:49 +00:00
|
|
|
{.name = "graphicsuri",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-06-18 07:46:49 +00:00
|
|
|
.help = N_("graphics URI to be used for seamless graphics migration")
|
|
|
|
},
|
2013-10-08 11:49:25 +00:00
|
|
|
{.name = "listen-address",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-10-08 11:49:25 +00:00
|
|
|
.help = N_("listen address that destination should bind to for incoming migration")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "dname",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("rename to new name during migration (if supported)")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("force guest to suspend if live migration exceeds timeout (in seconds)")
|
|
|
|
},
|
|
|
|
{.name = "xml",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("filename containing updated XML for the target")
|
|
|
|
},
|
2015-06-15 22:42:11 +00:00
|
|
|
{.name = "migrate-disks",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("comma separated list of disks to be migrated")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
doMigrate(void *opaque)
|
|
|
|
{
|
|
|
|
char ret = '1';
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *desturi = NULL;
|
2013-06-17 08:49:27 +00:00
|
|
|
const char *opt = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
unsigned int flags = 0;
|
|
|
|
vshCtrlData *data = opaque;
|
|
|
|
vshControl *ctl = data->ctl;
|
|
|
|
const vshCmd *cmd = data->cmd;
|
|
|
|
sigset_t sigmask, oldsigmask;
|
2013-06-17 08:49:27 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
int nparams = 0;
|
|
|
|
int maxparams = 0;
|
cmdMigrate: move vshConnect before vshWatchJob
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227
While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing "ENTER" key, it will exit.
The code hangs at tools/virsh-domain.c: cmdMigrate
->vshWatchJob->poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing "ENTER" key, poll() can get the
event and select pipe_fd, then command line can exit.
In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-08-08 08:44:36 +00:00
|
|
|
virConnectPtr dconn = data->dconn;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
|
|
|
goto out_sig;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
goto out;
|
|
|
|
|
2013-06-17 08:49:27 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "desturi", &desturi) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-06-17 08:49:27 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "migrateuri", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_URI, opt) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
2013-06-18 07:46:49 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "graphicsuri", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_GRAPHICS_URI, opt) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
2013-10-08 11:49:25 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "listen-address", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_LISTEN_ADDRESS, opt) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
2013-06-17 08:49:27 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "dname", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt &&
|
|
|
|
virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_NAME, opt) < 0)
|
|
|
|
goto save_error;
|
|
|
|
|
2015-06-15 22:42:11 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "migrate-disks", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt) {
|
|
|
|
char **val = NULL;
|
|
|
|
|
|
|
|
val = virStringSplit(opt, ",", 0);
|
|
|
|
|
|
|
|
if (virTypedParamsAddStringList(¶ms,
|
|
|
|
&nparams,
|
|
|
|
&maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_MIGRATE_DISKS,
|
|
|
|
(const char **)val) < 0) {
|
|
|
|
VIR_FREE(val);
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(val);
|
|
|
|
}
|
|
|
|
|
2013-06-17 08:49:27 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "xml", &opt) < 0)
|
|
|
|
goto out;
|
|
|
|
if (opt) {
|
|
|
|
char *xml;
|
|
|
|
|
2014-10-14 08:04:31 +00:00
|
|
|
if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) {
|
2013-06-17 08:49:27 +00:00
|
|
|
vshError(ctl, _("cannot read file '%s'"), opt);
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
|
|
|
VIR_MIGRATE_PARAM_DEST_XML, xml) < 0) {
|
|
|
|
VIR_FREE(xml);
|
|
|
|
goto save_error;
|
|
|
|
}
|
|
|
|
VIR_FREE(xml);
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (vshCommandOptBool(cmd, "live"))
|
|
|
|
flags |= VIR_MIGRATE_LIVE;
|
|
|
|
if (vshCommandOptBool(cmd, "p2p"))
|
|
|
|
flags |= VIR_MIGRATE_PEER2PEER;
|
|
|
|
if (vshCommandOptBool(cmd, "tunnelled"))
|
|
|
|
flags |= VIR_MIGRATE_TUNNELLED;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "persistent"))
|
|
|
|
flags |= VIR_MIGRATE_PERSIST_DEST;
|
|
|
|
if (vshCommandOptBool(cmd, "undefinesource"))
|
|
|
|
flags |= VIR_MIGRATE_UNDEFINE_SOURCE;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "suspend"))
|
|
|
|
flags |= VIR_MIGRATE_PAUSED;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "copy-storage-all"))
|
|
|
|
flags |= VIR_MIGRATE_NON_SHARED_DISK;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "copy-storage-inc"))
|
|
|
|
flags |= VIR_MIGRATE_NON_SHARED_INC;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "change-protection"))
|
|
|
|
flags |= VIR_MIGRATE_CHANGE_PROTECTION;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "unsafe"))
|
|
|
|
flags |= VIR_MIGRATE_UNSAFE;
|
|
|
|
|
2013-01-10 12:39:34 +00:00
|
|
|
if (vshCommandOptBool(cmd, "compressed"))
|
|
|
|
flags |= VIR_MIGRATE_COMPRESSED;
|
|
|
|
|
2014-02-06 23:44:36 +00:00
|
|
|
if (vshCommandOptBool(cmd, "auto-converge"))
|
|
|
|
flags |= VIR_MIGRATE_AUTO_CONVERGE;
|
|
|
|
|
2014-01-13 06:28:12 +00:00
|
|
|
if (vshCommandOptBool(cmd, "rdma-pin-all"))
|
|
|
|
flags |= VIR_MIGRATE_RDMA_PIN_ALL;
|
|
|
|
|
2014-11-13 14:20:51 +00:00
|
|
|
if (vshCommandOptBool(cmd, "offline"))
|
2012-11-21 08:28:49 +00:00
|
|
|
flags |= VIR_MIGRATE_OFFLINE;
|
|
|
|
|
2013-06-12 14:11:21 +00:00
|
|
|
if (vshCommandOptBool(cmd, "abort-on-error"))
|
|
|
|
flags |= VIR_MIGRATE_ABORT_ON_ERROR;
|
|
|
|
|
2015-04-30 12:47:46 +00:00
|
|
|
if (flags & VIR_MIGRATE_PEER2PEER || vshCommandOptBool(cmd, "direct")) {
|
2013-06-17 08:49:27 +00:00
|
|
|
if (virDomainMigrateToURI3(dom, desturi, params, nparams, flags) == 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = '0';
|
|
|
|
} else {
|
|
|
|
/* For traditional live migration, connect to the destination host directly. */
|
|
|
|
virDomainPtr ddom = NULL;
|
|
|
|
|
2013-06-17 08:49:27 +00:00
|
|
|
if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(ddom);
|
|
|
|
ret = '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
out:
|
2012-07-25 15:37:18 +00:00
|
|
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
2014-03-25 06:53:59 +00:00
|
|
|
out_sig:
|
2013-06-17 08:49:27 +00:00
|
|
|
virTypedParamsFree(params, nparams);
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
2013-06-17 08:49:27 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
save_error:
|
2013-06-17 08:49:27 +00:00
|
|
|
vshSaveLibvirtError();
|
|
|
|
goto out;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshMigrationTimeout(vshControl *ctl,
|
|
|
|
virDomainPtr dom,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "suspending the domain, "
|
|
|
|
"since migration timed out\n");
|
|
|
|
virDomainSuspend(dom);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMigrate(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int p[2] = {-1, -1};
|
|
|
|
virThread workerThread;
|
|
|
|
bool verbose = false;
|
|
|
|
bool functionReturn = false;
|
|
|
|
int timeout = 0;
|
|
|
|
bool live_flag = false;
|
2014-08-26 11:18:43 +00:00
|
|
|
vshCtrlData data = { .dconn = NULL };
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "verbose"))
|
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "live"))
|
|
|
|
live_flag = true;
|
2014-02-14 00:08:42 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
} else if (timeout > 0 && !live_flag) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("migrate: Unexpected timeout for offline migration"));
|
2013-03-26 15:41:06 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pipe(p) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data.ctl = ctl;
|
|
|
|
data.cmd = cmd;
|
|
|
|
data.writefd = p[1];
|
|
|
|
|
cmdMigrate: move vshConnect before vshWatchJob
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227
While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing "ENTER" key, it will exit.
The code hangs at tools/virsh-domain.c: cmdMigrate
->vshWatchJob->poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing "ENTER" key, poll() can get the
event and select pipe_fd, then command line can exit.
In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-08-08 08:44:36 +00:00
|
|
|
if (vshCommandOptBool(cmd, "p2p") || vshCommandOptBool(cmd, "direct")) {
|
|
|
|
data.dconn = NULL;
|
|
|
|
} else {
|
|
|
|
/* For traditional live migration, connect to the destination host. */
|
|
|
|
virConnectPtr dconn = NULL;
|
|
|
|
const char *desturi = NULL;
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "desturi", &desturi) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
dconn = vshConnect(ctl, desturi, false);
|
|
|
|
if (!dconn)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data.dconn = dconn;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (virThreadCreate(&workerThread,
|
|
|
|
true,
|
|
|
|
doMigrate,
|
|
|
|
&data) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
functionReturn = vshWatchJob(ctl, dom, verbose, p[0], timeout,
|
|
|
|
vshMigrationTimeout, NULL, _("Migration"));
|
|
|
|
|
|
|
|
virThreadJoin(&workerThread);
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
cmdMigrate: move vshConnect before vshWatchJob
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227
While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing "ENTER" key, it will exit.
The code hangs at tools/virsh-domain.c: cmdMigrate
->vshWatchJob->poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing "ENTER" key, poll() can get the
event and select pipe_fd, then command line can exit.
In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-08-08 08:44:36 +00:00
|
|
|
if (data.dconn)
|
|
|
|
virConnectClose(data.dconn);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
VIR_FORCE_CLOSE(p[0]);
|
|
|
|
VIR_FORCE_CLOSE(p[1]);
|
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "migrate-setmaxdowntime" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_migrate_setmaxdowntime[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("set maximum tolerable downtime")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Set maximum tolerable downtime of a domain which is being live-migrated to another host.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_migrate_setmaxdowntime[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "downtime",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("maximum tolerable downtime (in milliseconds) for migration")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
long long downtime = 0;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0)
|
2015-05-15 16:14:39 +00:00
|
|
|
goto done;
|
|
|
|
if (downtime < 1) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("migrate: Invalid downtime"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainMigrateSetMaxDowntime(dom, downtime, 0))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
done:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-18 20:14:49 +00:00
|
|
|
/*
|
|
|
|
* "migrate-compcache" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_migrate_compcache[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("get/set compression cache size")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get/set size of the cache (in bytes) used for compressing "
|
|
|
|
"repeatedly transferred memory pages during live migration.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_migrate_compcache[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "size",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ_OPT,
|
|
|
|
.help = N_("requested size of the cache (in bytes) used for compression")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
unsigned long long size = 0;
|
|
|
|
bool ret = false;
|
|
|
|
const char *unit;
|
|
|
|
double value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
rc = vshCommandOptULongLong(ctl, cmd, "size", &size);
|
2013-02-18 20:14:49 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
} else if (rc != 0) {
|
|
|
|
if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
value = vshPrettyCapacity(size, &unit);
|
|
|
|
vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit);
|
|
|
|
|
|
|
|
ret = true;
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-02-18 20:14:49 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "migrate-setspeed" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_migrate_setspeed[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Set the maximum migration bandwidth")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Set the maximum migration bandwidth (in MiB/s) for a domain "
|
|
|
|
"which is being migrated to another host.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_migrate_setspeed[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "bandwidth",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("migration bandwidth limit in MiB/s")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
unsigned long bandwidth = 0;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (virDomainMigrateSetMaxSpeed(dom, bandwidth, 0) < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
done:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "migrate-getspeed" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_migrate_getspeed[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Get the maximum migration bandwidth")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get the maximum migration bandwidth (in MiB/s) for a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_migrate_getspeed[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
unsigned long bandwidth;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virDomainMigrateGetMaxSpeed(dom, &bandwidth, 0) < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%lu\n", bandwidth);
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
done:
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domdisplay" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domdisplay[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("domain display connection URI")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
2014-07-24 12:23:12 +00:00
|
|
|
.data = N_("Output the IP address and port number "
|
|
|
|
"for the graphical display.")
|
2013-02-07 15:25:10 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domdisplay[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "include-password",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("includes the password into the connection URI if available")
|
|
|
|
},
|
2014-07-24 12:23:12 +00:00
|
|
|
{.name = "type",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-11-21 10:10:21 +00:00
|
|
|
.help = N_("select particular graphical display "
|
2014-07-24 12:23:12 +00:00
|
|
|
"(e.g. \"vnc\", \"spice\", \"rdp\")")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virDomainPtr dom;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
bool ret = false;
|
2012-11-21 15:31:51 +00:00
|
|
|
char *doc = NULL;
|
|
|
|
char *xpath = NULL;
|
|
|
|
char *listen_addr = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
int port, tls_port = 0;
|
|
|
|
char *passwd = NULL;
|
|
|
|
char *output = NULL;
|
|
|
|
const char *scheme[] = { "vnc", "spice", "rdp", NULL };
|
2014-07-24 12:23:12 +00:00
|
|
|
const char *type = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
int iter = 0;
|
|
|
|
int tmp;
|
|
|
|
int flags = 0;
|
2012-11-21 15:31:51 +00:00
|
|
|
bool params = false;
|
2015-02-10 09:35:56 +00:00
|
|
|
const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/%s)";
|
2013-10-01 09:16:30 +00:00
|
|
|
virSocketAddr addr;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!virDomainIsActive(dom)) {
|
|
|
|
vshError(ctl, _("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "include-password"))
|
|
|
|
flags |= VIR_DOMAIN_XML_SECURE;
|
|
|
|
|
2014-07-24 12:23:12 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-21 15:31:51 +00:00
|
|
|
if (!(doc = virDomainGetXMLDesc(dom, flags)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-21 15:31:51 +00:00
|
|
|
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Attempt to grab our display info */
|
|
|
|
for (iter = 0; scheme[iter] != NULL; iter++) {
|
2014-07-24 12:23:12 +00:00
|
|
|
/* Particular scheme requested */
|
|
|
|
if (type && STRNEQ(type, scheme[iter]))
|
|
|
|
continue;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Create our XPATH lookup for the current display's port */
|
2015-02-10 09:35:56 +00:00
|
|
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@port") < 0)
|
2013-07-04 10:20:45 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* Attempt to get the port number for the current graphics scheme */
|
|
|
|
tmp = virXPathInt(xpath, ctxt, &port);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
|
|
|
|
/* If there is no port number for this type, then jump to the next
|
2012-11-21 15:31:51 +00:00
|
|
|
* scheme */
|
2012-07-25 15:37:18 +00:00
|
|
|
if (tmp)
|
2013-09-25 15:48:01 +00:00
|
|
|
port = 0;
|
|
|
|
|
|
|
|
/* Create our XPATH lookup for TLS Port (automatically skipped
|
|
|
|
* for unsupported schemes */
|
2015-02-10 09:35:56 +00:00
|
|
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@tlsPort") < 0)
|
2013-09-25 15:48:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Attempt to get the TLS port number */
|
|
|
|
tmp = virXPathInt(xpath, ctxt, &tls_port);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
if (tmp)
|
|
|
|
tls_port = 0;
|
|
|
|
|
|
|
|
if (!port && !tls_port)
|
2012-07-25 15:37:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Create our XPATH lookup for the current display's address */
|
2015-02-10 09:35:56 +00:00
|
|
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0)
|
2013-07-04 10:20:45 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* Attempt to get the listening addr if set for the current
|
2012-11-21 15:31:51 +00:00
|
|
|
* graphics scheme */
|
2012-07-25 15:37:18 +00:00
|
|
|
listen_addr = virXPathString(xpath, ctxt);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
|
2015-02-10 09:35:56 +00:00
|
|
|
if (!listen_addr) {
|
|
|
|
/* The subelement address - <listen address='xyz'/> -
|
|
|
|
* *should* have been automatically backfilled into its
|
|
|
|
* parent <graphics listen='xyz'> (which we just tried to
|
|
|
|
* retrieve into listen_addr above) but in some cases it
|
|
|
|
* isn't, so we also do an explicit check for the
|
|
|
|
* subelement (which, by the way, doesn't exist on libvirt
|
|
|
|
* < 0.9.4, so we really do need to check both places)
|
|
|
|
*/
|
|
|
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@address") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
listen_addr = virXPathString(xpath, ctxt);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
}
|
|
|
|
|
2012-11-21 15:31:51 +00:00
|
|
|
/* We can query this info for all the graphics types since we'll
|
|
|
|
* get nothing for the unsupported ones (just rdp for now).
|
|
|
|
* Also the parameter '--include-password' was already taken
|
|
|
|
* care of when getting the XML */
|
|
|
|
|
|
|
|
/* Create our XPATH lookup for the password */
|
2015-02-10 09:35:56 +00:00
|
|
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@passwd") < 0)
|
2013-07-04 10:20:45 +00:00
|
|
|
goto cleanup;
|
2012-11-21 15:31:51 +00:00
|
|
|
|
|
|
|
/* Attempt to get the password */
|
|
|
|
passwd = virXPathString(xpath, ctxt);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Build up the full URI, starting with the scheme */
|
|
|
|
virBufferAsprintf(&buf, "%s://", scheme[iter]);
|
|
|
|
|
2012-11-21 15:31:51 +00:00
|
|
|
/* There is no user, so just append password if there's any */
|
|
|
|
if (STREQ(scheme[iter], "vnc") && passwd)
|
|
|
|
virBufferAsprintf(&buf, ":%s@", passwd);
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/* Then host name or IP */
|
2013-10-01 09:16:30 +00:00
|
|
|
if (!listen_addr ||
|
|
|
|
(virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
|
|
|
|
virSocketAddrIsWildcard(&addr)))
|
2012-07-25 15:37:18 +00:00
|
|
|
virBufferAddLit(&buf, "localhost");
|
2013-10-01 09:16:30 +00:00
|
|
|
else if (strchr(listen_addr, ':'))
|
|
|
|
virBufferAsprintf(&buf, "[%s]", listen_addr);
|
2012-07-25 15:37:18 +00:00
|
|
|
else
|
|
|
|
virBufferAsprintf(&buf, "%s", listen_addr);
|
|
|
|
|
|
|
|
/* Add the port */
|
2014-05-13 09:26:28 +00:00
|
|
|
if (port) {
|
|
|
|
if (STREQ(scheme[iter], "vnc")) {
|
|
|
|
/* VNC protocol handlers take their port number as
|
|
|
|
* 'port' - 5900 */
|
|
|
|
port -= 5900;
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:48:01 +00:00
|
|
|
virBufferAsprintf(&buf, ":%d", port);
|
2014-05-13 09:26:28 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* TLS Port */
|
2012-11-21 15:31:51 +00:00
|
|
|
if (tls_port) {
|
|
|
|
virBufferAsprintf(&buf,
|
2014-09-12 12:04:28 +00:00
|
|
|
"?tls-port=%d",
|
2012-11-21 15:31:51 +00:00
|
|
|
tls_port);
|
|
|
|
params = true;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2012-11-21 15:31:51 +00:00
|
|
|
if (STREQ(scheme[iter], "spice") && passwd) {
|
|
|
|
virBufferAsprintf(&buf,
|
|
|
|
"%spassword=%s",
|
|
|
|
params ? "&" : "?",
|
|
|
|
passwd);
|
|
|
|
params = true;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure we can print our URI */
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
vshPrint(ctl, "%s", _("Failed to create display URI"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out our full URI */
|
|
|
|
output = virBufferContentAndReset(&buf);
|
|
|
|
vshPrint(ctl, "%s", output);
|
|
|
|
|
|
|
|
/* We got what we came for so return successfully */
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-24 12:23:12 +00:00
|
|
|
if (!ret) {
|
|
|
|
if (type)
|
|
|
|
vshError(ctl, _("No graphical display with type '%s' found"), type);
|
|
|
|
else
|
|
|
|
vshError(ctl, _("No graphical display found"));
|
|
|
|
}
|
2014-07-24 12:18:23 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-11-21 15:31:51 +00:00
|
|
|
VIR_FREE(doc);
|
|
|
|
VIR_FREE(xpath);
|
|
|
|
VIR_FREE(passwd);
|
|
|
|
VIR_FREE(listen_addr);
|
|
|
|
VIR_FREE(output);
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "vncdisplay" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_vncdisplay[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("vnc display")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Output the IP address and port number for the VNC display.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_vncdisplay[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
int port = 0;
|
|
|
|
char *doc = NULL;
|
|
|
|
char *listen_addr = NULL;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Check if the domain is active and don't rely on -1 for this */
|
|
|
|
if (!virDomainIsActive(dom)) {
|
|
|
|
vshError(ctl, _("Domain is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(doc = virDomainGetXMLDesc(dom, 0)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Get the VNC port */
|
|
|
|
if (virXPathInt("string(/domain/devices/graphics[@type='vnc']/@port)",
|
|
|
|
ctxt, &port)) {
|
|
|
|
vshError(ctl, _("Failed to get VNC port. Is this domain using VNC?"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
listen_addr = virXPathString("string(/domain/devices/graphics"
|
|
|
|
"[@type='vnc']/@listen)", ctxt);
|
2015-02-15 08:49:09 +00:00
|
|
|
if (!listen_addr) {
|
|
|
|
/* The subelement address - <listen address='xyz'/> -
|
|
|
|
* *should* have been automatically backfilled into its
|
|
|
|
* parent <graphics listen='xyz'> (which we just tried to
|
|
|
|
* retrieve into listen_addr above) but in some cases it
|
|
|
|
* isn't, so we also do an explicit check for the
|
|
|
|
* subelement (which, by the way, doesn't exist on libvirt
|
|
|
|
* < 0.9.4, so we really do need to check both places)
|
|
|
|
*/
|
|
|
|
listen_addr = virXPathString("string(/domain/devices/graphics"
|
|
|
|
"[@type='vnc']/listen/@address)", ctxt);
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
if (listen_addr == NULL || STREQ(listen_addr, "0.0.0.0"))
|
|
|
|
vshPrint(ctl, ":%d\n", port-5900);
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "%s:%d\n", listen_addr, port-5900);
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(doc);
|
|
|
|
VIR_FREE(listen_addr);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "ttyconsole" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_ttyconsole[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("tty console")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Output the device for the TTY console.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_ttyconsole[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlXPathObjectPtr obj = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
char *doc;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
doc = virDomainGetXMLDesc(dom, 0);
|
|
|
|
if (!doc)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt);
|
|
|
|
VIR_FREE(doc);
|
|
|
|
if (!xml)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
|
|
|
|
if (obj == NULL || obj->type != XPATH_STRING ||
|
|
|
|
obj->stringval == NULL || obj->stringval[0] == 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
vshPrint(ctl, "%s\n", (const char *)obj->stringval);
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "domhostname" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_domhostname[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("print the domain's hostname")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domhostname[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
char *hostname;
|
|
|
|
virDomainPtr dom;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hostname = virDomainGetHostname(dom, 0);
|
|
|
|
if (hostname == NULL) {
|
|
|
|
vshError(ctl, "%s", _("failed to get hostname"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s\n", hostname);
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
error:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(hostname);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if n1 is superset of n2, meaning n1 contains all elements and
|
|
|
|
* attributes as n2 at least. Including children.
|
|
|
|
* @n1 first node
|
|
|
|
* @n2 second node
|
|
|
|
* returns true in case n1 covers n2, false otherwise.
|
|
|
|
*/
|
|
|
|
ATTRIBUTE_UNUSED
|
|
|
|
static bool
|
|
|
|
vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
|
|
|
|
{
|
|
|
|
xmlNodePtr child1, child2;
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
char *prop1, *prop2;
|
|
|
|
bool found;
|
|
|
|
bool visited;
|
|
|
|
bool ret = false;
|
|
|
|
long n1_child_size, n2_child_size, n1_iter;
|
|
|
|
virBitmapPtr bitmap;
|
|
|
|
|
|
|
|
if (!n1 && !n2)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!n1 || !n2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!xmlStrEqual(n1->name, n2->name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Iterate over n2 attributes and check if n1 contains them*/
|
|
|
|
attr = n2->properties;
|
|
|
|
while (attr) {
|
|
|
|
if (attr->type == XML_ATTRIBUTE_NODE) {
|
|
|
|
prop1 = virXMLPropString(n1, (const char *) attr->name);
|
|
|
|
prop2 = virXMLPropString(n2, (const char *) attr->name);
|
|
|
|
if (STRNEQ_NULLABLE(prop1, prop2)) {
|
|
|
|
xmlFree(prop1);
|
|
|
|
xmlFree(prop2);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
xmlFree(prop1);
|
|
|
|
xmlFree(prop2);
|
|
|
|
}
|
|
|
|
attr = attr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
n1_child_size = virXMLChildElementCount(n1);
|
|
|
|
n2_child_size = virXMLChildElementCount(n2);
|
|
|
|
if (n1_child_size < 0 || n2_child_size < 0 ||
|
|
|
|
n1_child_size < n2_child_size)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (n1_child_size == 0 && n2_child_size == 0)
|
|
|
|
return true;
|
|
|
|
|
2013-07-04 10:20:45 +00:00
|
|
|
if (!(bitmap = virBitmapNew(n1_child_size)))
|
2012-07-25 15:37:18 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
child2 = n2->children;
|
|
|
|
while (child2) {
|
|
|
|
if (child2->type != XML_ELEMENT_NODE) {
|
|
|
|
child2 = child2->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
child1 = n1->children;
|
|
|
|
n1_iter = 0;
|
|
|
|
found = false;
|
|
|
|
while (child1) {
|
|
|
|
if (child1->type != XML_ELEMENT_NODE) {
|
|
|
|
child1 = child1->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virBitmapGetBit(bitmap, n1_iter, &visited) < 0) {
|
|
|
|
vshError(NULL, "%s", _("Bad child elements counting."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visited) {
|
|
|
|
child1 = child1->next;
|
|
|
|
n1_iter++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmlStrEqual(child1->name, child2->name)) {
|
|
|
|
found = true;
|
|
|
|
if (virBitmapSetBit(bitmap, n1_iter) < 0) {
|
|
|
|
vshError(NULL, "%s", _("Bad child elements counting."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vshNodeIsSuperset(child1, child2))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
child1 = child1->next;
|
|
|
|
n1_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
child2 = child2->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
virBitmapFree(bitmap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "detach-device" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_detach_device[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("detach device from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Detach device from an XML <file>")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_detach_device[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("XML file")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
2013-03-21 15:26:23 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
2013-03-21 15:26:23 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *from = NULL;
|
|
|
|
char *buffer = NULL;
|
|
|
|
int ret;
|
|
|
|
bool funcRet = false;
|
2013-03-21 15:26:23 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-03-21 15:26:23 +00:00
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
|
|
|
vshReportError(ctl);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags != 0 || current)
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainDetachDeviceFlags(dom, buffer, flags);
|
2013-03-21 15:26:23 +00:00
|
|
|
else
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainDetachDevice(dom, buffer);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
vshError(ctl, _("Failed to detach device from %s"), from);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s", _("Device detached successfully\n"));
|
|
|
|
funcRet = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return funcRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "update-device" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_update_device[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("update device from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Update device from an XML <file>.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_update_device[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "file",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("XML file")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
2013-03-15 16:11:28 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
2013-03-15 16:11:28 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "force",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force device update")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom;
|
|
|
|
const char *from = NULL;
|
2013-01-21 14:39:18 +00:00
|
|
|
char *buffer = NULL;
|
|
|
|
bool ret = false;
|
2013-03-15 16:11:28 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-15 16:11:28 +00:00
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
|
|
|
vshReportError(ctl);
|
2013-01-21 14:39:18 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "force"))
|
|
|
|
flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, _("Failed to update device from %s"), from);
|
2013-01-21 14:39:18 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
vshPrint(ctl, "%s", _("Device updated successfully\n"));
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-01-21 14:39:18 +00:00
|
|
|
VIR_FREE(buffer);
|
2012-07-25 15:37:18 +00:00
|
|
|
virDomainFree(dom);
|
2013-01-21 14:39:18 +00:00
|
|
|
return ret;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "detach-interface" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_detach_interface[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("detach network interface")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Detach network interface.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_detach_interface[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("network interface type")
|
|
|
|
},
|
|
|
|
{.name = "mac",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("MAC address")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
2013-03-21 14:03:42 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
2013-03-21 14:03:42 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
xmlDocPtr xml = NULL;
|
2014-01-20 11:27:29 +00:00
|
|
|
xmlXPathObjectPtr obj = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
xmlNodePtr cur = NULL, matchNode = NULL;
|
2013-09-04 15:27:27 +00:00
|
|
|
char *detach_xml = NULL;
|
2014-01-20 11:27:29 +00:00
|
|
|
const char *mac = NULL, *type = NULL;
|
2013-03-21 14:03:42 +00:00
|
|
|
char *doc = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
char buf[64];
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int diff_mac;
|
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
int ret;
|
2014-11-17 23:39:48 +00:00
|
|
|
bool functionReturn = false;
|
2013-03-21 14:03:42 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2013-01-21 14:39:18 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-21 14:03:42 +00:00
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
2014-07-04 13:03:07 +00:00
|
|
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
|
|
|
doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
else
|
|
|
|
doc = virDomainGetXMLDesc(dom, 0);
|
|
|
|
|
|
|
|
if (!doc)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-21 14:03:42 +00:00
|
|
|
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt))) {
|
2012-07-25 15:37:18 +00:00
|
|
|
vshError(ctl, "%s", _("Failed to get interface information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type);
|
|
|
|
obj = xmlXPathEval(BAD_CAST buf, ctxt);
|
|
|
|
if (obj == NULL || obj->type != XPATH_NODESET ||
|
|
|
|
obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
|
2013-12-02 21:40:15 +00:00
|
|
|
vshError(ctl, _("No interface found whose type is %s"), type);
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mac && obj->nodesetval->nodeNr > 1) {
|
|
|
|
vshError(ctl, _("Domain has %d interfaces. Please specify which one "
|
|
|
|
"to detach using --mac"), obj->nodesetval->nodeNr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
if (!mac) {
|
|
|
|
matchNode = obj->nodesetval->nodeTab[0];
|
2012-07-25 15:37:18 +00:00
|
|
|
goto hit;
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
/* multiple possibilities, so search for matching mac */
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
2012-07-25 15:37:18 +00:00
|
|
|
cur = obj->nodesetval->nodeTab[i]->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE &&
|
|
|
|
xmlStrEqual(cur->name, BAD_CAST "mac")) {
|
|
|
|
char *tmp_mac = virXMLPropString(cur, "address");
|
|
|
|
diff_mac = virMacAddrCompare(tmp_mac, mac);
|
|
|
|
VIR_FREE(tmp_mac);
|
|
|
|
if (!diff_mac) {
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
if (matchNode) {
|
|
|
|
/* this is the 2nd match, so it's ambiguous */
|
|
|
|
vshError(ctl, _("Domain has multiple interfaces matching "
|
|
|
|
"MAC address %s. You must use detach-device and "
|
|
|
|
"specify the device pci address to remove it."),
|
|
|
|
mac);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
matchNode = obj->nodesetval->nodeTab[i];
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=862515
which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.
(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)
A synopsis of the problems:
1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.
2) you *can* do a live attach-interface of such a device.
3) you *can* directly edit a domain and put in two devices with
matching mac addresses.
4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.
5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.
Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:
1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.
2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.
This patch does three things:
1) removes the check for duplicate mac address during a persistent
netdev attach.
2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.
Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)
3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.
Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device
* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
* added new virDomainNetFindIdx function
* removed now unused virDomainNetIndexByMac and
virDomainNetRemoveByMac
* src/qemu/qemu_driver.c
* remove check for duplicate max from qemuDomainAttachDeviceConfig
* use virDomainNetFindIdx/virDomainNetRemove instead
of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
* use virDomainNetFindIdx instead of virDomainIndexByMac
in qemuDomainUpdateDeviceConfig
* src/qemu/qemu_hotplug.c
* use virDomainNetFindIdx instead of a homespun loop in
qemuDomainDetachNetDevice.
* tools/virsh-domain.c: modified detach-interface command as described
above
2012-10-25 20:03:35 +00:00
|
|
|
if (!matchNode) {
|
|
|
|
vshError(ctl, _("No interface with MAC address %s was found"), mac);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
hit:
|
2013-09-04 15:27:27 +00:00
|
|
|
if (!(detach_xml = virXMLNodeToString(xml, matchNode))) {
|
|
|
|
vshSaveLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags != 0 || current)
|
2013-09-04 15:27:27 +00:00
|
|
|
ret = virDomainDetachDeviceFlags(dom, detach_xml, flags);
|
|
|
|
else
|
|
|
|
ret = virDomainDetachDevice(dom, detach_xml);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to detach interface"));
|
|
|
|
} else {
|
|
|
|
vshPrint(ctl, "%s", _("Interface detached successfully\n"));
|
|
|
|
functionReturn = true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-03-21 14:03:42 +00:00
|
|
|
VIR_FREE(doc);
|
2013-09-04 15:27:27 +00:00
|
|
|
VIR_FREE(detach_xml);
|
2013-01-21 14:39:18 +00:00
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VSH_FIND_DISK_NORMAL,
|
|
|
|
VSH_FIND_DISK_CHANGEABLE,
|
|
|
|
} vshFindDiskType;
|
|
|
|
|
|
|
|
/* Helper function to find disk device in XML doc. Returns the disk
|
|
|
|
* node on success, or NULL on failure. Caller must free the result
|
|
|
|
* @path: Fully-qualified path or target of disk device.
|
|
|
|
* @type: Either VSH_FIND_DISK_NORMAL or VSH_FIND_DISK_CHANGEABLE.
|
|
|
|
*/
|
|
|
|
static xmlNodePtr
|
|
|
|
vshFindDisk(const char *doc,
|
|
|
|
const char *path,
|
|
|
|
int type)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
2014-01-20 11:27:29 +00:00
|
|
|
xmlXPathObjectPtr obj = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlNodePtr cur = NULL;
|
|
|
|
xmlNodePtr ret = NULL;
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt);
|
|
|
|
if (!xml) {
|
|
|
|
vshError(NULL, "%s", _("Failed to get disk information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
|
|
|
|
if (obj == NULL ||
|
|
|
|
obj->type != XPATH_NODESET ||
|
|
|
|
obj->nodesetval == NULL ||
|
|
|
|
obj->nodesetval->nodeNr == 0) {
|
|
|
|
vshError(NULL, "%s", _("Failed to get disk information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search disk using @path */
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
2012-07-25 15:37:18 +00:00
|
|
|
bool is_supported = true;
|
|
|
|
|
|
|
|
if (type == VSH_FIND_DISK_CHANGEABLE) {
|
|
|
|
xmlNodePtr n = obj->nodesetval->nodeTab[i];
|
|
|
|
is_supported = false;
|
|
|
|
|
|
|
|
/* Check if the disk is CDROM or floppy disk */
|
|
|
|
if (xmlStrEqual(n->name, BAD_CAST "disk")) {
|
|
|
|
char *device_value = virXMLPropString(n, "device");
|
|
|
|
|
|
|
|
if (STREQ(device_value, "cdrom") ||
|
|
|
|
STREQ(device_value, "floppy"))
|
|
|
|
is_supported = true;
|
|
|
|
|
|
|
|
VIR_FREE(device_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_supported)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = obj->nodesetval->nodeTab[i]->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
|
|
|
char *tmp = NULL;
|
|
|
|
|
|
|
|
if (xmlStrEqual(cur->name, BAD_CAST "source")) {
|
|
|
|
if ((tmp = virXMLPropString(cur, "file")) ||
|
|
|
|
(tmp = virXMLPropString(cur, "dev")) ||
|
|
|
|
(tmp = virXMLPropString(cur, "dir")) ||
|
|
|
|
(tmp = virXMLPropString(cur, "name"))) {
|
|
|
|
}
|
|
|
|
} else if (xmlStrEqual(cur->name, BAD_CAST "target")) {
|
|
|
|
tmp = virXMLPropString(cur, "dev");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ_NULLABLE(tmp, path)) {
|
|
|
|
ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 21:40:15 +00:00
|
|
|
vshError(NULL, _("No disk found whose source path or target is %s"), path);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
2015-03-12 15:41:21 +00:00
|
|
|
VSH_UPDATE_DISK_XML_EJECT,
|
|
|
|
VSH_UPDATE_DISK_XML_INSERT,
|
|
|
|
VSH_UPDATE_DISK_XML_UPDATE,
|
|
|
|
} vshUpdateDiskXMLType;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
/* Helper function to prepare disk XML. Could be used for disk
|
|
|
|
* detaching, media changing(ejecting, inserting, updating)
|
|
|
|
* for changeable disk. Returns the processed XML as string on
|
|
|
|
* success, or NULL on failure. Caller must free the result.
|
|
|
|
*/
|
|
|
|
static char *
|
2015-03-12 15:41:21 +00:00
|
|
|
vshUpdateDiskXML(xmlNodePtr disk_node,
|
|
|
|
const char *new_source,
|
|
|
|
bool source_block,
|
|
|
|
const char *target,
|
|
|
|
vshUpdateDiskXMLType type)
|
2012-07-25 15:37:18 +00:00
|
|
|
{
|
2015-03-12 15:41:21 +00:00
|
|
|
xmlNodePtr source = NULL;
|
2014-07-15 11:36:00 +00:00
|
|
|
char *device_type = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!disk_node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
device_type = virXMLPropString(disk_node, "device");
|
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
if (!(STREQ_NULLABLE(device_type, "cdrom") ||
|
|
|
|
STREQ_NULLABLE(device_type, "floppy"))) {
|
|
|
|
vshError(NULL, _("The disk device '%s' is not removable"), target);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
/* find the current source subelement */
|
|
|
|
for (source = disk_node->children; source; source = source->next) {
|
|
|
|
if (source->type == XML_ELEMENT_NODE &&
|
|
|
|
xmlStrEqual(source->name, BAD_CAST "source"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == VSH_UPDATE_DISK_XML_EJECT) {
|
|
|
|
if (!source) {
|
|
|
|
vshError(NULL, _("The disk device '%s' doesn't have media"), target);
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
/* forcibly switch to empty file cdrom */
|
|
|
|
source_block = false;
|
|
|
|
new_source = NULL;
|
|
|
|
} else if (!new_source) {
|
|
|
|
vshError(NULL, _("New disk media source was not specified"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
if (type == VSH_UPDATE_DISK_XML_INSERT && source) {
|
|
|
|
vshError(NULL, _("The disk device '%s' already has media"), target);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
/* remove current source */
|
|
|
|
if (source) {
|
|
|
|
xmlUnlinkNode(source);
|
|
|
|
xmlFreeNode(source);
|
|
|
|
source = NULL;
|
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
/* set the correct disk type */
|
|
|
|
if (source_block)
|
|
|
|
xmlSetProp(disk_node, BAD_CAST "type", BAD_CAST "block");
|
|
|
|
else
|
|
|
|
xmlSetProp(disk_node, BAD_CAST "type", BAD_CAST "file");
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
if (new_source) {
|
|
|
|
/* create new source subelement */
|
|
|
|
if (!(source = xmlNewNode(NULL, BAD_CAST "source"))) {
|
|
|
|
vshError(NULL, _("Failed to allocate new source node"));
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
2015-03-12 15:41:21 +00:00
|
|
|
|
|
|
|
if (source_block)
|
|
|
|
xmlNewProp(source, BAD_CAST "dev", BAD_CAST new_source);
|
|
|
|
else
|
|
|
|
xmlNewProp(source, BAD_CAST "file", BAD_CAST new_source);
|
|
|
|
|
|
|
|
xmlAddChild(disk_node, source);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 15:27:27 +00:00
|
|
|
if (!(ret = virXMLNodeToString(NULL, disk_node))) {
|
|
|
|
vshSaveLibvirtError();
|
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(device_type);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "detach-disk" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_detach_disk[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("detach disk device")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Detach disk device.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_detach_disk[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "target",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("target of disk device")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
2013-03-21 15:29:10 +00:00
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("make live change persistent")
|
2013-01-14 11:26:54 +00:00
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect next boot")
|
|
|
|
},
|
2013-03-21 15:29:10 +00:00
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect running domain")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("affect current domain")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
char *disk_xml = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *target = NULL;
|
|
|
|
char *doc = NULL;
|
|
|
|
int ret;
|
|
|
|
bool functionReturn = false;
|
|
|
|
xmlNodePtr disk_node = NULL;
|
2013-03-21 15:29:10 +00:00
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
|
|
|
|
|
|
|
if (config || persistent)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2013-01-21 14:39:18 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-01-07 16:58:47 +00:00
|
|
|
if (flags == VIR_DOMAIN_AFFECT_CONFIG)
|
|
|
|
doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
else
|
|
|
|
doc = virDomainGetXMLDesc(dom, 0);
|
|
|
|
|
|
|
|
if (!doc)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-21 15:29:10 +00:00
|
|
|
if (persistent &&
|
|
|
|
virDomainIsActive(dom) == 1)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (!(disk_node = vshFindDisk(doc, target, VSH_FIND_DISK_NORMAL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-12 10:51:51 +00:00
|
|
|
if (!(disk_xml = virXMLNodeToString(NULL, disk_node))) {
|
|
|
|
vshSaveLibvirtError();
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
2015-03-12 10:51:51 +00:00
|
|
|
}
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2014-01-07 15:44:02 +00:00
|
|
|
if (flags != 0 || current)
|
2013-03-21 15:29:10 +00:00
|
|
|
ret = virDomainDetachDeviceFlags(dom, disk_xml, flags);
|
|
|
|
else
|
2012-07-25 15:37:18 +00:00
|
|
|
ret = virDomainDetachDevice(dom, disk_xml);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to detach disk"));
|
2013-03-21 15:29:10 +00:00
|
|
|
goto cleanup;
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 15:29:10 +00:00
|
|
|
vshPrint(ctl, "%s", _("Disk detached successfully\n"));
|
|
|
|
functionReturn = true;
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
cleanup:
|
|
|
|
xmlFreeNode(disk_node);
|
|
|
|
VIR_FREE(disk_xml);
|
|
|
|
VIR_FREE(doc);
|
2013-01-21 14:39:18 +00:00
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
return functionReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "edit" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_edit[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("edit XML configuration for a domain")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Edit the XML configuration for a domain.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_edit[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
2015-01-08 15:26:50 +00:00
|
|
|
{.name = "skip-validate",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("skip validation of the XML against the schema")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdEdit(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
virDomainPtr dom_edited = NULL;
|
2015-01-08 15:26:50 +00:00
|
|
|
unsigned int query_flags = VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE;
|
|
|
|
unsigned int define_flags = VIR_DOMAIN_DEFINE_VALIDATE;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (dom == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-01-08 15:26:50 +00:00
|
|
|
if (vshCommandOptBool(cmd, "skip-validate"))
|
|
|
|
define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE;
|
|
|
|
|
|
|
|
#define EDIT_GET_XML virDomainGetXMLDesc(dom, query_flags)
|
2014-11-14 14:57:17 +00:00
|
|
|
#define EDIT_NOT_CHANGED \
|
|
|
|
do { \
|
|
|
|
vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \
|
|
|
|
virDomainGetName(dom)); \
|
|
|
|
ret = true; \
|
|
|
|
goto edit_cleanup; \
|
|
|
|
} while (0)
|
2012-07-25 15:37:18 +00:00
|
|
|
#define EDIT_DEFINE \
|
2015-01-08 15:26:50 +00:00
|
|
|
(dom_edited = vshDomainDefine(ctl->conn, doc_edited, define_flags))
|
2015-02-19 13:16:39 +00:00
|
|
|
#define EDIT_RELAX \
|
|
|
|
do { \
|
|
|
|
define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; \
|
|
|
|
} while (0);
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
#include "virsh-edit.c"
|
2015-02-19 13:16:39 +00:00
|
|
|
#undef EDIT_RELAX
|
2012-07-25 15:37:18 +00:00
|
|
|
|
|
|
|
vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
|
|
|
|
virDomainGetName(dom_edited));
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
if (dom_edited)
|
|
|
|
virDomainFree(dom_edited);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-14 23:59:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "event" command
|
|
|
|
*/
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainEvent)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEvent,
|
|
|
|
VIR_DOMAIN_EVENT_LAST,
|
|
|
|
N_("Defined"),
|
|
|
|
N_("Undefined"),
|
|
|
|
N_("Started"),
|
|
|
|
N_("Suspended"),
|
|
|
|
N_("Resumed"),
|
|
|
|
N_("Stopped"),
|
|
|
|
N_("Shutdown"),
|
|
|
|
N_("PMSuspended"),
|
|
|
|
N_("Crashed"))
|
|
|
|
|
2014-02-14 23:59:35 +00:00
|
|
|
static const char *
|
|
|
|
vshDomainEventToString(int event)
|
|
|
|
{
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
const char *str = vshDomainEventTypeToString(event);
|
|
|
|
return str ? _(str) : _("unknown");
|
2014-02-14 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainEventDefined)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventDefined,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_LAST,
|
|
|
|
N_("Added"),
|
|
|
|
N_("Updated"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventUndefined)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventUndefined,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_LAST,
|
|
|
|
N_("Removed"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventStarted)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventStarted,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_LAST,
|
|
|
|
N_("Booted"),
|
|
|
|
N_("Migrated"),
|
|
|
|
N_("Restored"),
|
|
|
|
N_("Snapshot"),
|
|
|
|
N_("Event wakeup"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventSuspended)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventSuspended,
|
|
|
|
VIR_DOMAIN_EVENT_SUSPENDED_LAST,
|
|
|
|
N_("Paused"),
|
|
|
|
N_("Migrated"),
|
|
|
|
N_("I/O Error"),
|
|
|
|
N_("Watchdog"),
|
|
|
|
N_("Restored"),
|
|
|
|
N_("Snapshot"),
|
|
|
|
N_("API error"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventResumed)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventResumed,
|
|
|
|
VIR_DOMAIN_EVENT_RESUMED_LAST,
|
|
|
|
N_("Unpaused"),
|
|
|
|
N_("Migrated"),
|
|
|
|
N_("Snapshot"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventStopped)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventStopped,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_LAST,
|
|
|
|
N_("Shutdown"),
|
|
|
|
N_("Destroyed"),
|
|
|
|
N_("Crashed"),
|
|
|
|
N_("Migrated"),
|
|
|
|
N_("Saved"),
|
|
|
|
N_("Failed"),
|
|
|
|
N_("Snapshot"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventShutdown)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventShutdown,
|
|
|
|
VIR_DOMAIN_EVENT_SHUTDOWN_LAST,
|
|
|
|
N_("Finished"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventPMSuspended)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventPMSuspended,
|
|
|
|
VIR_DOMAIN_EVENT_PMSUSPENDED_LAST,
|
|
|
|
N_("Memory"),
|
|
|
|
N_("Disk"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventCrashed)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventCrashed,
|
|
|
|
VIR_DOMAIN_EVENT_CRASHED_LAST,
|
|
|
|
N_("Panicked"))
|
|
|
|
|
2014-02-14 23:59:35 +00:00
|
|
|
static const char *
|
|
|
|
vshDomainEventDetailToString(int event, int detail)
|
|
|
|
{
|
2014-02-25 06:28:25 +00:00
|
|
|
const char *str = NULL;
|
2014-02-14 23:59:35 +00:00
|
|
|
switch ((virDomainEventType) event) {
|
|
|
|
case VIR_DOMAIN_EVENT_DEFINED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventDefinedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_UNDEFINED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventUndefinedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_STARTED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventStartedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_SUSPENDED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventSuspendedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_RESUMED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventResumedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_STOPPED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventStoppedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_SHUTDOWN:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventShutdownTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_PMSUSPENDED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventPMSuspendedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_CRASHED:
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
str = vshDomainEventCrashedTypeToString(detail);
|
2014-02-14 23:59:35 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_EVENT_LAST:
|
|
|
|
break;
|
|
|
|
}
|
virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future. Make this change throughout virsh.
Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.
* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-21 19:55:06 +00:00
|
|
|
return str ? _(str) : _("unknown");
|
2014-02-14 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
VIR_ENUM_DECL(vshDomainEventWatchdog)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventWatchdog,
|
|
|
|
VIR_DOMAIN_EVENT_WATCHDOG_LAST,
|
|
|
|
N_("none"),
|
|
|
|
N_("pause"),
|
|
|
|
N_("reset"),
|
|
|
|
N_("poweroff"),
|
|
|
|
N_("shutdown"),
|
2015-06-24 09:28:41 +00:00
|
|
|
N_("debug"),
|
|
|
|
N_("inject-nmi"))
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainEventWatchdogToString(int action)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainEventWatchdogTypeToString(action);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventIOError)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventIOError,
|
|
|
|
VIR_DOMAIN_EVENT_IO_ERROR_LAST,
|
|
|
|
N_("none"),
|
|
|
|
N_("pause"),
|
|
|
|
N_("report"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainEventIOErrorToString(int action)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainEventIOErrorTypeToString(action);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshGraphicsPhase)
|
|
|
|
VIR_ENUM_IMPL(vshGraphicsPhase,
|
|
|
|
VIR_DOMAIN_EVENT_GRAPHICS_LAST,
|
|
|
|
N_("connect"),
|
|
|
|
N_("initialize"),
|
|
|
|
N_("disconnect"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshGraphicsPhaseToString(int phase)
|
|
|
|
{
|
|
|
|
const char *str = vshGraphicsPhaseTypeToString(phase);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshGraphicsAddress)
|
|
|
|
VIR_ENUM_IMPL(vshGraphicsAddress,
|
|
|
|
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST,
|
|
|
|
N_("IPv4"),
|
|
|
|
N_("IPv6"),
|
|
|
|
N_("unix"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshGraphicsAddressToString(int family)
|
|
|
|
{
|
|
|
|
const char *str = vshGraphicsAddressTypeToString(family);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainBlockJobStatus)
|
|
|
|
VIR_ENUM_IMPL(vshDomainBlockJobStatus,
|
|
|
|
VIR_DOMAIN_BLOCK_JOB_LAST,
|
|
|
|
N_("completed"),
|
|
|
|
N_("failed"),
|
|
|
|
N_("canceled"),
|
|
|
|
N_("ready"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainBlockJobStatusToString(int status)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainBlockJobStatusTypeToString(status);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventDiskChange)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventDiskChange,
|
|
|
|
VIR_DOMAIN_EVENT_DISK_CHANGE_LAST,
|
|
|
|
N_("changed"),
|
|
|
|
N_("dropped"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainEventDiskChangeToString(int reason)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainEventDiskChangeTypeToString(reason);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshDomainEventTrayChange)
|
|
|
|
VIR_ENUM_IMPL(vshDomainEventTrayChange,
|
|
|
|
VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST,
|
|
|
|
N_("opened"),
|
|
|
|
N_("closed"))
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
vshDomainEventTrayChangeToString(int reason)
|
|
|
|
{
|
|
|
|
const char *str = vshDomainEventTrayChangeTypeToString(reason);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vshEventCallback {
|
|
|
|
const char *name;
|
|
|
|
virConnectDomainEventGenericCallback cb;
|
|
|
|
};
|
|
|
|
typedef struct vshEventCallback vshEventCallback;
|
|
|
|
|
2014-02-14 23:59:35 +00:00
|
|
|
struct vshDomEventData {
|
|
|
|
vshControl *ctl;
|
|
|
|
bool loop;
|
2014-02-24 23:57:06 +00:00
|
|
|
int *count;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
vshEventCallback *cb;
|
2014-02-24 23:57:06 +00:00
|
|
|
int id;
|
2014-02-14 23:59:35 +00:00
|
|
|
};
|
|
|
|
typedef struct vshDomEventData vshDomEventData;
|
|
|
|
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
static void
|
|
|
|
vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event '%s' for domain %s\n"),
|
|
|
|
data->cb->name, virDomainGetName(dom));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
2014-02-14 23:59:35 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int event,
|
|
|
|
int detail,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
2014-02-14 23:59:35 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'lifecycle' for domain %s: %s %s\n"),
|
|
|
|
virDomainGetName(dom), vshDomainEventToString(event),
|
|
|
|
vshDomainEventDetailToString(event, detail));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
2014-02-14 23:59:35 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
static void
|
|
|
|
vshEventRTCChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
long long utcoffset,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'rtc-change' for domain %s: %lld\n"),
|
|
|
|
virDomainGetName(dom), utcoffset);
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventWatchdogPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int action,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'watchdog' for domain %s: %s\n"),
|
|
|
|
virDomainGetName(dom), vshDomainEventWatchdogToString(action));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventIOErrorPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *srcPath,
|
|
|
|
const char *devAlias,
|
|
|
|
int action,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'io-error' for domain %s: %s (%s) %s\n"),
|
|
|
|
virDomainGetName(dom), srcPath, devAlias,
|
|
|
|
vshDomainEventIOErrorToString(action));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventGraphicsPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int phase,
|
|
|
|
const virDomainEventGraphicsAddress *local,
|
|
|
|
const virDomainEventGraphicsAddress *remote,
|
|
|
|
const char *authScheme,
|
|
|
|
const virDomainEventGraphicsSubject *subject,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
size_t i;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'graphics' for domain %s: "
|
|
|
|
"%s local[%s %s %s] remote[%s %s %s] %s"),
|
|
|
|
virDomainGetName(dom), vshGraphicsPhaseToString(phase),
|
|
|
|
vshGraphicsAddressToString(local->family),
|
|
|
|
local->node, local->service,
|
|
|
|
vshGraphicsAddressToString(remote->family),
|
|
|
|
remote->node, remote->service,
|
|
|
|
authScheme);
|
|
|
|
for (i = 0; i < subject->nidentity; i++)
|
|
|
|
vshPrint(data->ctl, " %s=%s", subject->identities[i].type,
|
|
|
|
subject->identities[i].name);
|
|
|
|
vshPrint(data->ctl, "\n");
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventIOErrorReasonPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *srcPath,
|
|
|
|
const char *devAlias,
|
|
|
|
int action,
|
|
|
|
const char *reason,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl, _("event 'io-error-reason' for domain %s: "
|
|
|
|
"%s (%s) %s due to %s\n"),
|
|
|
|
virDomainGetName(dom), srcPath, devAlias,
|
|
|
|
vshDomainEventIOErrorToString(action), reason);
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventBlockJobPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *disk,
|
|
|
|
int type,
|
|
|
|
int status,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
blockjob: use stable disk string in job event
When the block job event was first added, it was for block pull,
where the active layer of the disk remains the same name. It was
also in a day where we only cared about local files, and so we
always had a canonical absolute file name. But two things have
changed since then: we now have network disks, where determining
a single absolute string does not really make sense; and we have
two-phase jobs (copy and active commit) where the name of the
active layer changes between the first event (ready, on the old
name) and second (complete, on the pivoted name).
Adam Litke reported that having an unstable string between events
makes life harder for clients. Furthermore, all of our API that
operate on a particular disk of a domain accept multiple strings:
not only the absolute name of the active layer, but also the
destination device name (such as 'vda'). As this latter name is
stable, even for network sources, it serves as a better string
to supply in block job events.
But backwards-compatibility demands that we should not change the
name handed to users unless they explicitly request it. Therefore,
this patch adds a new event, BLOCK_JOB_2 (alas, I couldn't think of
any nicer name - but at least Migrate2 and Migrate3 are precedent
for a number suffix). We must double up on emitting both old-style
and new-style events according to what clients have registered for
(see also how IOError and IOErrorReason emits double events, but
there the difference was a larger struct rather than changed
meaning of one of the struct members).
Unfortunately, adding a new event isn't something that can easily
be broken into pieces, so the commit is rather large.
* include/libvirt/libvirt.h.in (virDomainEventID): Add a new id
for VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2.
(virConnectDomainEventBlockJobCallback): Document new semantics.
* src/conf/domain_event.c (_virDomainEventBlockJob): Rename field,
to ensure we catch all clients.
(virDomainEventBlockJobNew): Add parameter.
(virDomainEventBlockJobDispose)
(virDomainEventBlockJobNewFromObj)
(virDomainEventBlockJobNewFromDom)
(virDomainEventDispatchDefaultFunc): Adjust clients.
(virDomainEventBlockJob2NewFromObj)
(virDomainEventBlockJob2NewFromDom): New functions.
* src/conf/domain_event.h: Add new prototypes.
* src/libvirt_private.syms (domain_event.h): Export new functions.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Generate two
different events.
* src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Likewise.
* src/remote/remote_protocol.x
(remote_domain_event_block_job_2_msg): New struct.
(REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB_2): New RPC.
* src/remote/remote_driver.c
(remoteDomainBuildEventBlockJob2): New handler.
(remoteEvents): Register new event.
* daemon/remote.c (remoteRelayDomainEventBlockJob2): New handler.
(domainEventCallbacks): Register new event.
* tools/virsh-domain.c (vshEventCallbacks): Likewise.
(vshEventBlockJobPrint): Adjust client.
* src/remote_protocol-structs: Regenerate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-14 13:18:04 +00:00
|
|
|
vshPrint(data->ctl, _("event '%s' for domain %s: %s for %s %s\n"),
|
|
|
|
data->cb->name, virDomainGetName(dom),
|
|
|
|
vshDomainBlockJobToString(type),
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
disk, vshDomainBlockJobStatusToString(status));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventDiskChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *oldSrc,
|
|
|
|
const char *newSrc,
|
|
|
|
const char *alias,
|
|
|
|
int reason,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'disk-change' for domain %s disk %s: %s -> %s: %s\n"),
|
|
|
|
virDomainGetName(dom), alias, NULLSTR(oldSrc), NULLSTR(newSrc),
|
|
|
|
vshDomainEventDiskChangeToString(reason));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventTrayChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *alias,
|
|
|
|
int reason,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
2015-05-28 12:04:07 +00:00
|
|
|
_("event 'tray-change' for domain %s disk %s: %s\n"),
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
virDomainGetName(dom), alias,
|
|
|
|
vshDomainEventTrayChangeToString(reason));
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventPMChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int reason ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
/* As long as libvirt.h doesn't define any reasons, we might as
|
|
|
|
* well treat all PM state changes as generic events. */
|
|
|
|
vshEventGenericPrint(conn, dom, opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventBalloonChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
unsigned long long actual,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'balloon-change' for domain %s: %lluKiB\n"),
|
|
|
|
virDomainGetName(dom), actual);
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vshEventDeviceRemovedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *alias,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (!data->loop && *data->count)
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'device-removed' for domain %s: %s\n"),
|
|
|
|
virDomainGetName(dom), alias);
|
2014-02-24 23:57:06 +00:00
|
|
|
(*data->count)++;
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:46:21 +00:00
|
|
|
static void
|
|
|
|
vshEventDeviceAddedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
const char *alias,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
|
|
|
if (!data->loop && *data->count)
|
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'device-added' for domain %s: %s\n"),
|
|
|
|
virDomainGetName(dom), alias);
|
|
|
|
(*data->count)++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
2014-09-10 11:28:24 +00:00
|
|
|
static void
|
|
|
|
vshEventTunablePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
virTypedParameterPtr params,
|
|
|
|
int nparams,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
size_t i;
|
|
|
|
char *value = NULL;
|
|
|
|
|
|
|
|
if (!data->loop && *data->count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'tunable' for domain %s:\n"),
|
|
|
|
virDomainGetName(dom));
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
value = virTypedParameterToString(¶ms[i]);
|
|
|
|
if (value) {
|
|
|
|
vshPrint(data->ctl, _("\t%s: %s\n"), params[i].field, value);
|
|
|
|
VIR_FREE(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*data->count)++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
2014-11-19 09:32:20 +00:00
|
|
|
VIR_ENUM_DECL(vshEventAgentLifecycleState)
|
|
|
|
VIR_ENUM_IMPL(vshEventAgentLifecycleState,
|
|
|
|
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_LAST,
|
|
|
|
N_("unknown"),
|
|
|
|
N_("connected"),
|
|
|
|
N_("disconnected"))
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(vshEventAgentLifecycleReason)
|
|
|
|
VIR_ENUM_IMPL(vshEventAgentLifecycleReason,
|
|
|
|
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_LAST,
|
|
|
|
N_("unknown"),
|
|
|
|
N_("domain started"),
|
|
|
|
N_("channel event"))
|
|
|
|
|
|
|
|
#define UNKNOWNSTR(str) (str ? str : N_("unsupported value"))
|
|
|
|
static void
|
|
|
|
vshEventAgentLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virDomainPtr dom,
|
|
|
|
int state,
|
|
|
|
int reason,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
vshDomEventData *data = opaque;
|
|
|
|
|
|
|
|
if (!data->loop && *data->count)
|
|
|
|
return;
|
|
|
|
vshPrint(data->ctl,
|
|
|
|
_("event 'agent-lifecycle' for domain %s: state: '%s' reason: '%s'\n"),
|
|
|
|
virDomainGetName(dom),
|
|
|
|
UNKNOWNSTR(vshEventAgentLifecycleStateTypeToString(state)),
|
|
|
|
UNKNOWNSTR(vshEventAgentLifecycleReasonTypeToString(reason)));
|
|
|
|
|
|
|
|
(*data->count)++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
static vshEventCallback vshEventCallbacks[] = {
|
|
|
|
{ "lifecycle",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventLifecyclePrint), },
|
|
|
|
{ "reboot", vshEventGenericPrint, },
|
|
|
|
{ "rtc-change",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventRTCChangePrint), },
|
|
|
|
{ "watchdog",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventWatchdogPrint), },
|
|
|
|
{ "io-error",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventIOErrorPrint), },
|
|
|
|
{ "graphics",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventGraphicsPrint), },
|
|
|
|
{ "io-error-reason",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventIOErrorReasonPrint), },
|
|
|
|
{ "control-error", vshEventGenericPrint, },
|
|
|
|
{ "block-job",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventBlockJobPrint), },
|
|
|
|
{ "disk-change",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventDiskChangePrint), },
|
|
|
|
{ "tray-change",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventTrayChangePrint), },
|
|
|
|
{ "pm-wakeup",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
|
|
|
|
{ "pm-suspend",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
|
|
|
|
{ "balloon-change",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventBalloonChangePrint), },
|
|
|
|
{ "pm-suspend-disk",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
|
|
|
|
{ "device-removed",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventDeviceRemovedPrint), },
|
blockjob: use stable disk string in job event
When the block job event was first added, it was for block pull,
where the active layer of the disk remains the same name. It was
also in a day where we only cared about local files, and so we
always had a canonical absolute file name. But two things have
changed since then: we now have network disks, where determining
a single absolute string does not really make sense; and we have
two-phase jobs (copy and active commit) where the name of the
active layer changes between the first event (ready, on the old
name) and second (complete, on the pivoted name).
Adam Litke reported that having an unstable string between events
makes life harder for clients. Furthermore, all of our API that
operate on a particular disk of a domain accept multiple strings:
not only the absolute name of the active layer, but also the
destination device name (such as 'vda'). As this latter name is
stable, even for network sources, it serves as a better string
to supply in block job events.
But backwards-compatibility demands that we should not change the
name handed to users unless they explicitly request it. Therefore,
this patch adds a new event, BLOCK_JOB_2 (alas, I couldn't think of
any nicer name - but at least Migrate2 and Migrate3 are precedent
for a number suffix). We must double up on emitting both old-style
and new-style events according to what clients have registered for
(see also how IOError and IOErrorReason emits double events, but
there the difference was a larger struct rather than changed
meaning of one of the struct members).
Unfortunately, adding a new event isn't something that can easily
be broken into pieces, so the commit is rather large.
* include/libvirt/libvirt.h.in (virDomainEventID): Add a new id
for VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2.
(virConnectDomainEventBlockJobCallback): Document new semantics.
* src/conf/domain_event.c (_virDomainEventBlockJob): Rename field,
to ensure we catch all clients.
(virDomainEventBlockJobNew): Add parameter.
(virDomainEventBlockJobDispose)
(virDomainEventBlockJobNewFromObj)
(virDomainEventBlockJobNewFromDom)
(virDomainEventDispatchDefaultFunc): Adjust clients.
(virDomainEventBlockJob2NewFromObj)
(virDomainEventBlockJob2NewFromDom): New functions.
* src/conf/domain_event.h: Add new prototypes.
* src/libvirt_private.syms (domain_event.h): Export new functions.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Generate two
different events.
* src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Likewise.
* src/remote/remote_protocol.x
(remote_domain_event_block_job_2_msg): New struct.
(REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB_2): New RPC.
* src/remote/remote_driver.c
(remoteDomainBuildEventBlockJob2): New handler.
(remoteEvents): Register new event.
* daemon/remote.c (remoteRelayDomainEventBlockJob2): New handler.
(domainEventCallbacks): Register new event.
* tools/virsh-domain.c (vshEventCallbacks): Likewise.
(vshEventBlockJobPrint): Adjust client.
* src/remote_protocol-structs: Regenerate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-14 13:18:04 +00:00
|
|
|
{ "block-job-2",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventBlockJobPrint), },
|
2014-09-10 11:28:24 +00:00
|
|
|
{ "tunable",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventTunablePrint), },
|
2014-11-19 09:32:20 +00:00
|
|
|
{ "agent-lifecycle",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventAgentLifecyclePrint), },
|
2015-03-30 16:46:21 +00:00
|
|
|
{ "device-added",
|
|
|
|
VIR_DOMAIN_EVENT_CALLBACK(vshEventDeviceAddedPrint), },
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
};
|
|
|
|
verify(VIR_DOMAIN_EVENT_ID_LAST == ARRAY_CARDINALITY(vshEventCallbacks));
|
|
|
|
|
2014-02-14 23:59:35 +00:00
|
|
|
static const vshCmdInfo info_event[] = {
|
2014-03-31 13:05:33 +00:00
|
|
|
{.name = "help",
|
2014-02-14 23:59:35 +00:00
|
|
|
.data = N_("Domain Events")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("List event types, or wait for domain events to occur")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_event[] = {
|
|
|
|
{.name = "domain",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-02-14 23:59:35 +00:00
|
|
|
.help = N_("filter by domain name, id, or uuid")
|
|
|
|
},
|
|
|
|
{.name = "event",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2014-02-14 23:59:35 +00:00
|
|
|
.help = N_("which event type to wait for")
|
|
|
|
},
|
2014-02-24 23:57:06 +00:00
|
|
|
{.name = "all",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("wait for all events instead of just one type")
|
|
|
|
},
|
2014-02-14 23:59:35 +00:00
|
|
|
{.name = "loop",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("loop until timeout or interrupt, rather than one-shot")
|
|
|
|
},
|
|
|
|
{.name = "timeout",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("timeout seconds")
|
|
|
|
},
|
|
|
|
{.name = "list",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list valid event types")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdEvent(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
int timeout = 0;
|
2014-02-24 23:57:06 +00:00
|
|
|
vshDomEventData *data = NULL;
|
|
|
|
size_t i;
|
2014-02-14 23:59:35 +00:00
|
|
|
const char *eventName = NULL;
|
2014-02-24 23:57:06 +00:00
|
|
|
int event = -1;
|
|
|
|
bool all = vshCommandOptBool(cmd, "all");
|
|
|
|
bool loop = vshCommandOptBool(cmd, "loop");
|
|
|
|
int count = 0;
|
2014-02-14 23:59:35 +00:00
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "list")) {
|
virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time. A future patch may add an --all parameter to
make it possible to register for all events through a single
call.
* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 21:46:29 +00:00
|
|
|
for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++)
|
|
|
|
vshPrint(ctl, "%s\n", vshEventCallbacks[event].name);
|
2014-02-14 23:59:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
if (vshCommandOptString(ctl, cmd, "event", &eventName) < 0)
|
2014-02-14 23:59:35 +00:00
|
|
|
return false;
|
2014-02-24 23:57:06 +00:00
|
|
|
if (eventName) {
|
|
|
|
for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++)
|
|
|
|
if (STREQ(eventName, vshEventCallbacks[event].name))
|
|
|
|
break;
|
|
|
|
if (event == VIR_DOMAIN_EVENT_ID_LAST) {
|
|
|
|
vshError(ctl, _("unknown event type %s"), eventName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!all) {
|
|
|
|
vshError(ctl, "%s",
|
|
|
|
_("one of --list, --all, or event type is required"));
|
2014-02-14 23:59:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
if (all) {
|
|
|
|
if (VIR_ALLOC_N(data, VIR_DOMAIN_EVENT_ID_LAST) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
|
|
|
|
data[i].ctl = ctl;
|
|
|
|
data[i].loop = loop;
|
|
|
|
data[i].count = &count;
|
|
|
|
data[i].cb = &vshEventCallbacks[i];
|
|
|
|
data[i].id = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (VIR_ALLOC_N(data, 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
data[0].ctl = ctl;
|
|
|
|
data[0].loop = vshCommandOptBool(cmd, "loop");
|
|
|
|
data[0].count = &count;
|
|
|
|
data[0].cb = &vshEventCallbacks[event];
|
|
|
|
data[0].id = -1;
|
|
|
|
}
|
2014-02-14 23:59:35 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
2014-02-24 23:57:06 +00:00
|
|
|
goto cleanup;
|
2014-02-14 23:59:35 +00:00
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "domain"))
|
|
|
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
|
|
|
if (vshEventStart(ctl, timeout) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-24 23:57:06 +00:00
|
|
|
for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) {
|
|
|
|
if ((data[i].id = virConnectDomainEventRegisterAny(ctl->conn, dom,
|
|
|
|
all ? i : event,
|
|
|
|
data[i].cb->cb,
|
|
|
|
&data[i],
|
|
|
|
NULL)) < 0) {
|
|
|
|
/* When registering for all events: if the first
|
|
|
|
* registration succeeds, silently ignore failures on all
|
|
|
|
* later registrations on the assumption that the server
|
|
|
|
* is older and didn't know quite as many events. */
|
|
|
|
if (i)
|
|
|
|
vshResetLibvirtError();
|
|
|
|
else
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 23:59:35 +00:00
|
|
|
switch (vshEventWait(ctl)) {
|
|
|
|
case VSH_EVENT_INTERRUPT:
|
|
|
|
vshPrint(ctl, "%s", _("event loop interrupted\n"));
|
|
|
|
break;
|
|
|
|
case VSH_EVENT_TIMEOUT:
|
|
|
|
vshPrint(ctl, "%s", _("event loop timed out\n"));
|
|
|
|
break;
|
|
|
|
case VSH_EVENT_DONE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-02-24 23:57:06 +00:00
|
|
|
vshPrint(ctl, _("events received: %d\n"), count);
|
|
|
|
if (count)
|
2014-02-14 23:59:35 +00:00
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2014-02-14 23:59:35 +00:00
|
|
|
vshEventCleanup(ctl);
|
2014-02-24 23:57:06 +00:00
|
|
|
if (data) {
|
|
|
|
for (i = 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) {
|
|
|
|
if (data[i].id >= 0 &&
|
|
|
|
virConnectDomainEventDeregisterAny(ctl->conn, data[i].id) < 0)
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
VIR_FREE(data);
|
|
|
|
}
|
2014-02-14 23:59:35 +00:00
|
|
|
if (dom)
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
/*
|
|
|
|
* "change-media" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_change_media[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Change media of CD or floppy drive")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Change media of CD or floppy drive.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_change_media[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "path",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("Fully-qualified path or target of disk device")
|
|
|
|
},
|
|
|
|
{.name = "source",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("source of the media")
|
|
|
|
},
|
|
|
|
{.name = "eject",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Eject the media")
|
|
|
|
},
|
|
|
|
{.name = "insert",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Insert the media")
|
|
|
|
},
|
|
|
|
{.name = "update",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Update the media")
|
|
|
|
},
|
|
|
|
{.name = "current",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("can be either or both of --live and --config, "
|
|
|
|
"depends on implementation of hypervisor driver")
|
|
|
|
},
|
|
|
|
{.name = "live",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("alter live configuration of running domain")
|
|
|
|
},
|
|
|
|
{.name = "config",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("alter persistent configuration, effect observed on next boot")
|
|
|
|
},
|
|
|
|
{.name = "force",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("force media changing")
|
|
|
|
},
|
2015-03-12 15:04:00 +00:00
|
|
|
{.name = "print-xml",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("print XML document rather than change media")
|
|
|
|
},
|
2015-03-12 15:41:21 +00:00
|
|
|
{.name = "block",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("source media is a block device")
|
|
|
|
},
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = NULL}
|
2012-07-25 15:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
const char *source = NULL;
|
|
|
|
const char *path = NULL;
|
2013-09-03 11:36:22 +00:00
|
|
|
char *doc = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
xmlNodePtr disk_node = NULL;
|
2013-09-03 11:36:22 +00:00
|
|
|
char *disk_xml = NULL;
|
2012-07-25 15:37:18 +00:00
|
|
|
bool ret = false;
|
2015-03-12 15:41:21 +00:00
|
|
|
vshUpdateDiskXMLType update_type;
|
2012-07-25 15:37:18 +00:00
|
|
|
const char *action = NULL;
|
2015-04-06 17:59:46 +00:00
|
|
|
const char *success_msg = NULL;
|
2013-03-21 14:35:13 +00:00
|
|
|
bool config = vshCommandOptBool(cmd, "config");
|
|
|
|
bool live = vshCommandOptBool(cmd, "live");
|
|
|
|
bool current = vshCommandOptBool(cmd, "current");
|
|
|
|
bool force = vshCommandOptBool(cmd, "force");
|
|
|
|
bool eject = vshCommandOptBool(cmd, "eject");
|
|
|
|
bool insert = vshCommandOptBool(cmd, "insert");
|
|
|
|
bool update = vshCommandOptBool(cmd, "update");
|
2015-03-12 15:41:21 +00:00
|
|
|
bool block = vshCommandOptBool(cmd, "block");
|
2013-03-21 14:35:13 +00:00
|
|
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-21 14:35:13 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(eject, insert);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(eject, update);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(insert, update);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(eject, block);
|
|
|
|
|
2015-06-09 11:27:42 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Docs state that update without source is eject */
|
|
|
|
if (update && !source) {
|
|
|
|
update = false;
|
|
|
|
eject = true;
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:18 +00:00
|
|
|
if (eject) {
|
2015-03-12 15:41:21 +00:00
|
|
|
update_type = VSH_UPDATE_DISK_XML_EJECT;
|
2012-07-25 15:37:18 +00:00
|
|
|
action = "eject";
|
2015-04-06 17:59:46 +00:00
|
|
|
success_msg = _("Successfully ejected media.");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (insert) {
|
2015-03-12 15:41:21 +00:00
|
|
|
update_type = VSH_UPDATE_DISK_XML_INSERT;
|
2012-07-25 15:37:18 +00:00
|
|
|
action = "insert";
|
2015-04-06 17:59:46 +00:00
|
|
|
success_msg = _("Successfully inserted media.");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update || (!eject && !insert)) {
|
2015-03-12 15:41:21 +00:00
|
|
|
update_type = VSH_UPDATE_DISK_XML_UPDATE;
|
2012-07-25 15:37:18 +00:00
|
|
|
action = "update";
|
2015-04-06 17:59:46 +00:00
|
|
|
success_msg = _("Successfully updated media.");
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-03-07 12:38:19 +00:00
|
|
|
if (config)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_CONFIG;
|
|
|
|
if (live)
|
|
|
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
2012-07-25 15:37:18 +00:00
|
|
|
if (force)
|
|
|
|
flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2015-03-12 15:41:21 +00:00
|
|
|
return false;
|
2012-07-25 15:37:18 +00:00
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
|
|
|
doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
else
|
|
|
|
doc = virDomainGetXMLDesc(dom, 0);
|
|
|
|
if (!doc)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(disk_node = vshFindDisk(doc, path, VSH_FIND_DISK_CHANGEABLE)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-12 15:41:21 +00:00
|
|
|
if (!(disk_xml = vshUpdateDiskXML(disk_node, source, block, path,
|
|
|
|
update_type)))
|
2012-07-25 15:37:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-12 15:04:00 +00:00
|
|
|
if (vshCommandOptBool(cmd, "print-xml")) {
|
|
|
|
vshPrint(ctl, "%s", disk_xml);
|
|
|
|
} else {
|
|
|
|
if (virDomainUpdateDeviceFlags(dom, disk_xml, flags) != 0) {
|
|
|
|
vshError(ctl, _("Failed to complete action %s on media"), action);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-04-06 17:59:46 +00:00
|
|
|
vshPrint(ctl, "%s", success_msg);
|
2012-07-25 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-25 15:37:18 +00:00
|
|
|
VIR_FREE(doc);
|
|
|
|
xmlFreeNode(disk_node);
|
|
|
|
VIR_FREE(disk_xml);
|
2015-03-12 15:41:21 +00:00
|
|
|
virDomainFree(dom);
|
2012-07-25 15:37:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-07-23 07:19:04 +00:00
|
|
|
|
2012-11-20 17:23:20 +00:00
|
|
|
static const vshCmdInfo info_domfstrim[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Invoke fstrim on domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Invoke fstrim on domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-11-20 17:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domfstrim[] = {
|
2013-01-14 11:26:54 +00:00
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "minimum",
|
|
|
|
.type = VSH_OT_INT,
|
|
|
|
.help = N_("Just a hint to ignore contiguous "
|
|
|
|
"free ranges smaller than this (Bytes)")
|
|
|
|
},
|
|
|
|
{.name = "mountpoint",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 11:26:54 +00:00
|
|
|
.help = N_("which mount point to trim")
|
|
|
|
},
|
2013-08-26 12:36:52 +00:00
|
|
|
{.name = NULL}
|
2012-11-20 17:23:20 +00:00
|
|
|
};
|
|
|
|
static bool
|
|
|
|
cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
unsigned long long minimum = 0;
|
|
|
|
const char *mountPoint = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
2013-04-02 15:18:30 +00:00
|
|
|
return ret;
|
2012-11-20 17:23:20 +00:00
|
|
|
|
2015-06-02 09:17:29 +00:00
|
|
|
if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0)
|
2012-11-20 17:23:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-21 14:39:18 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0)
|
2012-11-20 17:23:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) {
|
|
|
|
vshError(ctl, _("Unable to invoke fstrim"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2013-04-02 15:18:30 +00:00
|
|
|
virDomainFree(dom);
|
2012-11-20 17:23:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-02 00:06:13 +00:00
|
|
|
static const vshCmdInfo info_domfsfreeze[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Freeze domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Freeze domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domfsfreeze[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "mountpoint",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.help = N_("mountpoint path to be frozen")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
static bool
|
|
|
|
cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
const char **mountpoints = NULL;
|
|
|
|
size_t nmountpoints = 0;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2014-05-02 00:06:13 +00:00
|
|
|
if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) {
|
|
|
|
vshError(ctl, _("%s: %d: failed to allocate mountpoints"),
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
mountpoints[nmountpoints-1] = opt->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virDomainFSFreeze(dom, mountpoints, nmountpoints, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
vshError(ctl, _("Unable to freeze filesystems"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Froze %d filesystem(s)\n"), ret);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(mountpoints);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const vshCmdInfo info_domfsthaw[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Thaw domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Thaw domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domfsthaw[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = "mountpoint",
|
|
|
|
.type = VSH_OT_ARGV,
|
|
|
|
.help = N_("mountpoint path to be thawed")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
static bool
|
|
|
|
cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const vshCmdOpt *opt = NULL;
|
|
|
|
const char **mountpoints = NULL;
|
|
|
|
size_t nmountpoints = 0;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
2015-06-02 09:17:28 +00:00
|
|
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
2014-05-02 00:06:13 +00:00
|
|
|
if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) {
|
|
|
|
vshError(ctl, _("%s: %d: failed to allocate mountpoints"),
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
mountpoints[nmountpoints-1] = opt->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virDomainFSThaw(dom, mountpoints, nmountpoints, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
vshError(ctl, _("Unable to thaw filesystems"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, _("Thawed %d filesystem(s)\n"), ret);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(mountpoints);
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret >= 0;
|
|
|
|
}
|
|
|
|
|
2014-11-22 01:27:52 +00:00
|
|
|
static const vshCmdInfo info_domfsinfo[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Get information of domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Get information of domain's mounted filesystems.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_domfsinfo[] = {
|
|
|
|
{.name = "domain",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("domain name, id or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i, j;
|
|
|
|
virDomainFSInfoPtr *info;
|
|
|
|
|
|
|
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ret = virDomainGetFSInfo(dom, &info, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
vshError(ctl, _("Unable to get filesystem information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (ret == 0) {
|
|
|
|
vshError(ctl, _("No filesystems are mounted in the domain"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
vshPrintExtra(ctl, "%-36s %-8s %-8s %s\n",
|
|
|
|
_("Mountpoint"), _("Name"), _("Type"), _("Target"));
|
|
|
|
vshPrintExtra(ctl, "-------------------------------------------------------------------\n");
|
|
|
|
for (i = 0; i < ret; i++) {
|
|
|
|
vshPrintExtra(ctl, "%-36s %-8s %-8s ",
|
|
|
|
info[i]->mountpoint, info[i]->name, info[i]->fstype);
|
|
|
|
for (j = 0; j < info[i]->ndevAlias; j++) {
|
|
|
|
vshPrintExtra(ctl, "%s", info[i]->devAlias[j]);
|
|
|
|
if (j != info[i]->ndevAlias - 1)
|
|
|
|
vshPrint(ctl, ",");
|
|
|
|
}
|
|
|
|
vshPrint(ctl, "\n");
|
|
|
|
|
|
|
|
virDomainFSInfoFree(info[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainFree(dom);
|
|
|
|
return ret >= 0;
|
|
|
|
}
|
|
|
|
|
2012-08-18 04:00:42 +00:00
|
|
|
const vshCmdDef domManagementCmds[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "attach-device",
|
|
|
|
.handler = cmdAttachDevice,
|
|
|
|
.opts = opts_attach_device,
|
|
|
|
.info = info_attach_device,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "attach-disk",
|
|
|
|
.handler = cmdAttachDisk,
|
|
|
|
.opts = opts_attach_disk,
|
|
|
|
.info = info_attach_disk,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "attach-interface",
|
|
|
|
.handler = cmdAttachInterface,
|
|
|
|
.opts = opts_attach_interface,
|
|
|
|
.info = info_attach_interface,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "autostart",
|
|
|
|
.handler = cmdAutostart,
|
|
|
|
.opts = opts_autostart,
|
|
|
|
.info = info_autostart,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blkdeviotune",
|
|
|
|
.handler = cmdBlkdeviotune,
|
|
|
|
.opts = opts_blkdeviotune,
|
|
|
|
.info = info_blkdeviotune,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blkiotune",
|
|
|
|
.handler = cmdBlkiotune,
|
|
|
|
.opts = opts_blkiotune,
|
|
|
|
.info = info_blkiotune,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blockcommit",
|
|
|
|
.handler = cmdBlockCommit,
|
|
|
|
.opts = opts_block_commit,
|
|
|
|
.info = info_block_commit,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blockcopy",
|
|
|
|
.handler = cmdBlockCopy,
|
|
|
|
.opts = opts_block_copy,
|
|
|
|
.info = info_block_copy,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blockjob",
|
|
|
|
.handler = cmdBlockJob,
|
|
|
|
.opts = opts_block_job,
|
|
|
|
.info = info_block_job,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blockpull",
|
|
|
|
.handler = cmdBlockPull,
|
|
|
|
.opts = opts_block_pull,
|
|
|
|
.info = info_block_pull,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "blockresize",
|
|
|
|
.handler = cmdBlockResize,
|
|
|
|
.opts = opts_block_resize,
|
|
|
|
.info = info_block_resize,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "change-media",
|
|
|
|
.handler = cmdChangeMedia,
|
|
|
|
.opts = opts_change_media,
|
|
|
|
.info = info_change_media,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2012-07-23 07:19:04 +00:00
|
|
|
#ifndef WIN32
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "console",
|
|
|
|
.handler = cmdConsole,
|
|
|
|
.opts = opts_console,
|
|
|
|
.info = info_console,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2012-07-23 07:19:04 +00:00
|
|
|
#endif
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "cpu-baseline",
|
|
|
|
.handler = cmdCPUBaseline,
|
|
|
|
.opts = opts_cpu_baseline,
|
|
|
|
.info = info_cpu_baseline,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "cpu-compare",
|
|
|
|
.handler = cmdCPUCompare,
|
|
|
|
.opts = opts_cpu_compare,
|
|
|
|
.info = info_cpu_compare,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "cpu-stats",
|
|
|
|
.handler = cmdCPUStats,
|
|
|
|
.opts = opts_cpu_stats,
|
|
|
|
.info = info_cpu_stats,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "create",
|
|
|
|
.handler = cmdCreate,
|
|
|
|
.opts = opts_create,
|
|
|
|
.info = info_create,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "define",
|
|
|
|
.handler = cmdDefine,
|
|
|
|
.opts = opts_define,
|
|
|
|
.info = info_define,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.handler = cmdDesc,
|
|
|
|
.opts = opts_desc,
|
|
|
|
.info = info_desc,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "destroy",
|
|
|
|
.handler = cmdDestroy,
|
|
|
|
.opts = opts_destroy,
|
|
|
|
.info = info_destroy,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "detach-device",
|
|
|
|
.handler = cmdDetachDevice,
|
|
|
|
.opts = opts_detach_device,
|
|
|
|
.info = info_detach_device,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "detach-disk",
|
|
|
|
.handler = cmdDetachDisk,
|
|
|
|
.opts = opts_detach_disk,
|
|
|
|
.info = info_detach_disk,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "detach-interface",
|
|
|
|
.handler = cmdDetachInterface,
|
|
|
|
.opts = opts_detach_interface,
|
|
|
|
.info = info_detach_interface,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domdisplay",
|
|
|
|
.handler = cmdDomDisplay,
|
|
|
|
.opts = opts_domdisplay,
|
|
|
|
.info = info_domdisplay,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2014-05-02 00:06:13 +00:00
|
|
|
{.name = "domfsfreeze",
|
|
|
|
.handler = cmdDomFSFreeze,
|
|
|
|
.opts = opts_domfsfreeze,
|
|
|
|
.info = info_domfsfreeze,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domfsthaw",
|
|
|
|
.handler = cmdDomFSThaw,
|
|
|
|
.opts = opts_domfsthaw,
|
|
|
|
.info = info_domfsthaw,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2014-11-22 01:27:52 +00:00
|
|
|
{.name = "domfsinfo",
|
|
|
|
.handler = cmdDomFSInfo,
|
|
|
|
.opts = opts_domfsinfo,
|
|
|
|
.info = info_domfsinfo,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "domfstrim",
|
|
|
|
.handler = cmdDomFSTrim,
|
|
|
|
.opts = opts_domfstrim,
|
|
|
|
.info = info_domfstrim,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domhostname",
|
|
|
|
.handler = cmdDomHostname,
|
|
|
|
.opts = opts_domhostname,
|
|
|
|
.info = info_domhostname,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domid",
|
|
|
|
.handler = cmdDomid,
|
|
|
|
.opts = opts_domid,
|
|
|
|
.info = info_domid,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domif-setlink",
|
|
|
|
.handler = cmdDomIfSetLink,
|
|
|
|
.opts = opts_domif_setlink,
|
|
|
|
.info = info_domif_setlink,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domiftune",
|
|
|
|
.handler = cmdDomIftune,
|
|
|
|
.opts = opts_domiftune,
|
|
|
|
.info = info_domiftune,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domjobabort",
|
|
|
|
.handler = cmdDomjobabort,
|
|
|
|
.opts = opts_domjobabort,
|
|
|
|
.info = info_domjobabort,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domjobinfo",
|
|
|
|
.handler = cmdDomjobinfo,
|
|
|
|
.opts = opts_domjobinfo,
|
|
|
|
.info = info_domjobinfo,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domname",
|
|
|
|
.handler = cmdDomname,
|
|
|
|
.opts = opts_domname,
|
|
|
|
.info = info_domname,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "dompmsuspend",
|
|
|
|
.handler = cmdDomPMSuspend,
|
|
|
|
.opts = opts_dom_pm_suspend,
|
|
|
|
.info = info_dom_pm_suspend,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "dompmwakeup",
|
|
|
|
.handler = cmdDomPMWakeup,
|
|
|
|
.opts = opts_dom_pm_wakeup,
|
|
|
|
.info = info_dom_pm_wakeup,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domuuid",
|
|
|
|
.handler = cmdDomuuid,
|
|
|
|
.opts = opts_domuuid,
|
|
|
|
.info = info_domuuid,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domxml-from-native",
|
|
|
|
.handler = cmdDomXMLFromNative,
|
|
|
|
.opts = opts_domxmlfromnative,
|
|
|
|
.info = info_domxmlfromnative,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "domxml-to-native",
|
|
|
|
.handler = cmdDomXMLToNative,
|
|
|
|
.opts = opts_domxmltonative,
|
|
|
|
.info = info_domxmltonative,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "dump",
|
|
|
|
.handler = cmdDump,
|
|
|
|
.opts = opts_dump,
|
|
|
|
.info = info_dump,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "dumpxml",
|
|
|
|
.handler = cmdDumpXML,
|
|
|
|
.opts = opts_dumpxml,
|
|
|
|
.info = info_dumpxml,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "edit",
|
|
|
|
.handler = cmdEdit,
|
|
|
|
.opts = opts_edit,
|
|
|
|
.info = info_edit,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2014-02-14 23:59:35 +00:00
|
|
|
{.name = "event",
|
|
|
|
.handler = cmdEvent,
|
|
|
|
.opts = opts_event,
|
|
|
|
.info = info_event,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "inject-nmi",
|
|
|
|
.handler = cmdInjectNMI,
|
|
|
|
.opts = opts_inject_nmi,
|
|
|
|
.info = info_inject_nmi,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2015-03-25 16:15:04 +00:00
|
|
|
{.name = "iothreadinfo",
|
|
|
|
.handler = cmdIOThreadInfo,
|
|
|
|
.opts = opts_iothreadinfo,
|
|
|
|
.info = info_iothreadinfo,
|
2015-02-11 20:29:22 +00:00
|
|
|
.flags = 0
|
|
|
|
},
|
2015-03-06 00:08:04 +00:00
|
|
|
{.name = "iothreadpin",
|
|
|
|
.handler = cmdIOThreadPin,
|
|
|
|
.opts = opts_iothreadpin,
|
|
|
|
.info = info_iothreadpin,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2015-03-18 13:01:50 +00:00
|
|
|
{.name = "iothreadadd",
|
|
|
|
.handler = cmdIOThreadAdd,
|
|
|
|
.opts = opts_iothreadadd,
|
|
|
|
.info = info_iothreadadd,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "iothreaddel",
|
|
|
|
.handler = cmdIOThreadDel,
|
|
|
|
.opts = opts_iothreaddel,
|
|
|
|
.info = info_iothreaddel,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "send-key",
|
|
|
|
.handler = cmdSendKey,
|
|
|
|
.opts = opts_send_key,
|
|
|
|
.info = info_send_key,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "send-process-signal",
|
|
|
|
.handler = cmdSendProcessSignal,
|
|
|
|
.opts = opts_send_process_signal,
|
|
|
|
.info = info_send_process_signal,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "lxc-enter-namespace",
|
|
|
|
.handler = cmdLxcEnterNamespace,
|
|
|
|
.opts = opts_lxc_enter_namespace,
|
|
|
|
.info = info_lxc_enter_namespace,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "managedsave",
|
|
|
|
.handler = cmdManagedSave,
|
|
|
|
.opts = opts_managedsave,
|
|
|
|
.info = info_managedsave,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "managedsave-remove",
|
|
|
|
.handler = cmdManagedSaveRemove,
|
|
|
|
.opts = opts_managedsaveremove,
|
|
|
|
.info = info_managedsaveremove,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "memtune",
|
|
|
|
.handler = cmdMemtune,
|
|
|
|
.opts = opts_memtune,
|
|
|
|
.info = info_memtune,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-09-09 08:54:04 +00:00
|
|
|
{.name = "metadata",
|
|
|
|
.handler = cmdMetadata,
|
|
|
|
.opts = opts_metadata,
|
|
|
|
.info = info_metadata,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "migrate",
|
|
|
|
.handler = cmdMigrate,
|
|
|
|
.opts = opts_migrate,
|
|
|
|
.info = info_migrate,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "migrate-setmaxdowntime",
|
|
|
|
.handler = cmdMigrateSetMaxDowntime,
|
|
|
|
.opts = opts_migrate_setmaxdowntime,
|
|
|
|
.info = info_migrate_setmaxdowntime,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-18 20:14:49 +00:00
|
|
|
{.name = "migrate-compcache",
|
|
|
|
.handler = cmdMigrateCompCache,
|
|
|
|
.opts = opts_migrate_compcache,
|
|
|
|
.info = info_migrate_compcache,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "migrate-setspeed",
|
|
|
|
.handler = cmdMigrateSetMaxSpeed,
|
|
|
|
.opts = opts_migrate_setspeed,
|
|
|
|
.info = info_migrate_setspeed,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "migrate-getspeed",
|
|
|
|
.handler = cmdMigrateGetMaxSpeed,
|
|
|
|
.opts = opts_migrate_getspeed,
|
|
|
|
.info = info_migrate_getspeed,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "numatune",
|
|
|
|
.handler = cmdNumatune,
|
|
|
|
.opts = opts_numatune,
|
|
|
|
.info = info_numatune,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "qemu-attach",
|
|
|
|
.handler = cmdQemuAttach,
|
|
|
|
.opts = opts_qemu_attach,
|
|
|
|
.info = info_qemu_attach,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "qemu-monitor-command",
|
|
|
|
.handler = cmdQemuMonitorCommand,
|
|
|
|
.opts = opts_qemu_monitor_command,
|
|
|
|
.info = info_qemu_monitor_command,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2014-01-31 23:52:17 +00:00
|
|
|
{.name = "qemu-monitor-event",
|
|
|
|
.handler = cmdQemuMonitorEvent,
|
|
|
|
.opts = opts_qemu_monitor_event,
|
|
|
|
.info = info_qemu_monitor_event,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "qemu-agent-command",
|
|
|
|
.handler = cmdQemuAgentCommand,
|
|
|
|
.opts = opts_qemu_agent_command,
|
|
|
|
.info = info_qemu_agent_command,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "reboot",
|
|
|
|
.handler = cmdReboot,
|
|
|
|
.opts = opts_reboot,
|
|
|
|
.info = info_reboot,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "reset",
|
|
|
|
.handler = cmdReset,
|
|
|
|
.opts = opts_reset,
|
|
|
|
.info = info_reset,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "restore",
|
|
|
|
.handler = cmdRestore,
|
|
|
|
.opts = opts_restore,
|
|
|
|
.info = info_restore,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "resume",
|
|
|
|
.handler = cmdResume,
|
|
|
|
.opts = opts_resume,
|
|
|
|
.info = info_resume,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "save",
|
|
|
|
.handler = cmdSave,
|
|
|
|
.opts = opts_save,
|
|
|
|
.info = info_save,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "save-image-define",
|
|
|
|
.handler = cmdSaveImageDefine,
|
|
|
|
.opts = opts_save_image_define,
|
|
|
|
.info = info_save_image_define,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "save-image-dumpxml",
|
|
|
|
.handler = cmdSaveImageDumpxml,
|
|
|
|
.opts = opts_save_image_dumpxml,
|
|
|
|
.info = info_save_image_dumpxml,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "save-image-edit",
|
|
|
|
.handler = cmdSaveImageEdit,
|
|
|
|
.opts = opts_save_image_edit,
|
|
|
|
.info = info_save_image_edit,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "schedinfo",
|
|
|
|
.handler = cmdSchedinfo,
|
|
|
|
.opts = opts_schedinfo,
|
|
|
|
.info = info_schedinfo,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "screenshot",
|
|
|
|
.handler = cmdScreenshot,
|
|
|
|
.opts = opts_screenshot,
|
|
|
|
.info = info_screenshot,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2015-05-18 10:37:38 +00:00
|
|
|
{.name = "set-user-password",
|
|
|
|
.handler = cmdSetUserPassword,
|
|
|
|
.opts = opts_set_user_password,
|
|
|
|
.info = info_set_user_password,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "setmaxmem",
|
|
|
|
.handler = cmdSetmaxmem,
|
|
|
|
.opts = opts_setmaxmem,
|
|
|
|
.info = info_setmaxmem,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "setmem",
|
|
|
|
.handler = cmdSetmem,
|
|
|
|
.opts = opts_setmem,
|
|
|
|
.info = info_setmem,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "setvcpus",
|
|
|
|
.handler = cmdSetvcpus,
|
|
|
|
.opts = opts_setvcpus,
|
|
|
|
.info = info_setvcpus,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "shutdown",
|
|
|
|
.handler = cmdShutdown,
|
|
|
|
.opts = opts_shutdown,
|
|
|
|
.info = info_shutdown,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "start",
|
|
|
|
.handler = cmdStart,
|
|
|
|
.opts = opts_start,
|
|
|
|
.info = info_start,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "suspend",
|
|
|
|
.handler = cmdSuspend,
|
|
|
|
.opts = opts_suspend,
|
|
|
|
.info = info_suspend,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "ttyconsole",
|
|
|
|
.handler = cmdTTYConsole,
|
|
|
|
.opts = opts_ttyconsole,
|
|
|
|
.info = info_ttyconsole,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "undefine",
|
|
|
|
.handler = cmdUndefine,
|
|
|
|
.opts = opts_undefine,
|
|
|
|
.info = info_undefine,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "update-device",
|
|
|
|
.handler = cmdUpdateDevice,
|
|
|
|
.opts = opts_update_device,
|
|
|
|
.info = info_update_device,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "vcpucount",
|
|
|
|
.handler = cmdVcpucount,
|
|
|
|
.opts = opts_vcpucount,
|
|
|
|
.info = info_vcpucount,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "vcpuinfo",
|
|
|
|
.handler = cmdVcpuinfo,
|
|
|
|
.opts = opts_vcpuinfo,
|
|
|
|
.info = info_vcpuinfo,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "vcpupin",
|
|
|
|
.handler = cmdVcpuPin,
|
|
|
|
.opts = opts_vcpupin,
|
|
|
|
.info = info_vcpupin,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "emulatorpin",
|
|
|
|
.handler = cmdEmulatorPin,
|
|
|
|
.opts = opts_emulatorpin,
|
|
|
|
.info = info_emulatorpin,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "vncdisplay",
|
|
|
|
.handler = cmdVNCDisplay,
|
|
|
|
.opts = opts_vncdisplay,
|
|
|
|
.info = info_vncdisplay,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 07:19:04 +00:00
|
|
|
};
|