((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
-typedef enum {
- VSH_MESG, /* standard output */
- VSH_HEADER, /* header for standard output */
- VSH_FOOTER, /* timing, last command state, or whatever */
- VSH_DEBUG1, /* debugN where 'N' = level */
- VSH_DEBUG2,
- VSH_DEBUG3,
- VSH_DEBUG4,
- VSH_DEBUG5
-} vshOutType;
-
/*
* The error handler for virtsh
*/
static virDomainPtr vshCommandOptDomain(vshControl * ctl, vshCmd * cmd,
const char *optname, char **name);
-
-static void vshPrint(vshControl * ctl, vshOutType out, const char *format,
- ...);
+static void vshPrintExtra(vshControl * ctl, const char *format, ...);
+static void vshDebug(vshControl * ctl, int level, const char *format, ...);
+#define vshPrint(_ctl, ...) fprintf(stdout, __VA_ARGS__)
static const char *vshDomainStateToString(int state);
static int vshConnectionUsability(vshControl * ctl, virConnectPtr conn,
if (!cmdname) {
vshCmdDef *def;
- vshPrint(ctl, VSH_HEADER, "Commands:\n\n");
+ vshPrint(ctl, "Commands:\n\n");
for (def = commands; def->name; def++)
- vshPrint(ctl, VSH_MESG, " %-15s %s\n", def->name,
+ vshPrint(ctl, " %-15s %s\n", def->name,
vshCmddefGetInfo(def, "help"));
return TRUE;
}
virConnectListDomains(ctl->conn, &ids[0], maxid);
- vshPrint(ctl, VSH_HEADER, "%3s %-20s %s\n", "Id", "Name", "State");
- vshPrint(ctl, VSH_HEADER, "----------------------------------\n");
+ vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
+ vshPrintExtra(ctl, "----------------------------------\n");
for (i = 0; i < maxid; i++) {
int ret;
continue;
ret = virDomainGetInfo(dom, &info);
- vshPrint(ctl, VSH_MESG, "%3d %-20s %s\n",
+ vshPrint(ctl, "%3d %-20s %s\n",
virDomainGetID(dom),
virDomainGetName(dom),
ret <
return FALSE;
if (virDomainGetInfo(dom, &info) == 0)
- vshPrint(ctl, VSH_MESG, "%s\n",
+ vshPrint(ctl, "%s\n",
vshDomainStateToString(info.state));
else
ret = FALSE;
return FALSE;
if (virDomainSuspend(dom) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s suspended\n", name);
+ vshPrint(ctl, "Domain %s suspended\n", name);
} else {
vshError(ctl, FALSE, "Failed to suspend domain\n");
ret = FALSE;
buffer[l] = 0;
dom = virDomainCreateLinux(ctl->conn, &buffer[0], 0);
if (dom != NULL) {
- vshPrint(ctl, VSH_MESG, "Domain %s created from %s\n",
+ vshPrint(ctl, "Domain %s created from %s\n",
virDomainGetName(dom), from);
} else {
vshError(ctl, FALSE, "Failed to create domain\n");
return FALSE;
if (virDomainSave(dom, to) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s saved\n", name);
+ vshPrint(ctl, "Domain %s saved\n", name);
} else {
vshError(ctl, FALSE, "Failed to save domain\n");
ret = FALSE;
return FALSE;
if (virDomainRestore(ctl->conn, from) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain restored from %s\n", from);
+ vshPrint(ctl, "Domain restored from %s\n", from);
} else {
vshError(ctl, FALSE, "Failed to restore domain\n");
ret = FALSE;
return FALSE;
if (virDomainResume(dom) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s resumed\n", name);
+ vshPrint(ctl, "Domain %s resumed\n", name);
} else {
vshError(ctl, FALSE, "Failed to resume domain\n");
ret = FALSE;
return FALSE;
if (virDomainShutdown(dom) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s is being shutdown\n", name);
+ vshPrint(ctl, "Domain %s is being shutdown\n", name);
} else {
vshError(ctl, FALSE, "Failed to shutdown domain\n");
ret = FALSE;
return FALSE;
if (virDomainReboot(dom, 0) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s is being rebooted\n", name);
+ vshPrint(ctl, "Domain %s is being rebooted\n", name);
} else {
vshError(ctl, FALSE, "Failed to reboot domain\n");
ret = FALSE;
return FALSE;
if (virDomainDestroy(dom) == 0) {
- vshPrint(ctl, VSH_MESG, "Domain %s destroyed\n", name);
+ vshPrint(ctl, "Domain %s destroyed\n", name);
} else {
vshError(ctl, FALSE, "Failed to destroy domain\n");
ret = FALSE;
virDomainInfo info;
virDomainPtr dom;
int ret = TRUE;
- char *str;
+ char *str, uuid[37];
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
return FALSE;
- vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:", virDomainGetID(dom));
- vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:", virDomainGetName(dom));
+ vshPrint(ctl, "%-15s %d\n", "Id:", virDomainGetID(dom));
+ vshPrint(ctl, "%-15s %s\n", "Name:", virDomainGetName(dom));
+ if (virDomainGetUUIDString(dom, &uuid[0])==0)
+ vshPrint(ctl, "%-15s %s\n", "UUID:", uuid);
if ((str = virDomainGetOSType(dom))) {
- vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
+ vshPrint(ctl, "%-15s %s\n", "OS Type:", str);
free(str);
}
if (virDomainGetInfo(dom, &info) == 0) {
- vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",
+ vshPrint(ctl, "%-15s %s\n", "State:",
vshDomainStateToString(info.state));
- vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
+ vshPrint(ctl, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
if (info.cpuTime != 0) {
float cpuUsed = info.cpuTime;
cpuUsed /= 1000000000;
- vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed);
+ vshPrint(ctl, "%-15s %.1fs\n", "CPU time:", cpuUsed);
}
- vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Max memory:",
+ vshPrint(ctl, "%-15s %lu kB\n", "Max memory:",
info.maxMem);
- vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Used memory:",
+ vshPrint(ctl, "%-15s %lu kB\n", "Used memory:",
info.memory);
} else {
vshError(ctl, FALSE, "failed to get node information");
return FALSE;
}
- vshPrint(ctl, VSH_MESG, "%-20s %s\n", "CPU model:", info.model);
- vshPrint(ctl, VSH_MESG, "%-20s %d\n", "CPU(s):", info.cpus);
- vshPrint(ctl, VSH_MESG, "%-20s %d MHz\n", "CPU frequency:", info.mhz);
- vshPrint(ctl, VSH_MESG, "%-20s %d\n", "CPU socket(s):", info.sockets);
- vshPrint(ctl, VSH_MESG, "%-20s %d\n", "Core(s) per socket:", info.cores);
- vshPrint(ctl, VSH_MESG, "%-20s %d\n", "Thread(s) per core:", info.threads);
- vshPrint(ctl, VSH_MESG, "%-20s %d\n", "NUMA cell(s):", info.nodes);
- vshPrint(ctl, VSH_MESG, "%-20s %lu kB\n", "Memory size:", info.memory);
+ vshPrint(ctl, "%-20s %s\n", "CPU model:", info.model);
+ vshPrint(ctl, "%-20s %d\n", "CPU(s):", info.cpus);
+ vshPrint(ctl, "%-20s %d MHz\n", "CPU frequency:", info.mhz);
+ vshPrint(ctl, "%-20s %d\n", "CPU socket(s):", info.sockets);
+ vshPrint(ctl, "%-20s %d\n", "Core(s) per socket:", info.cores);
+ vshPrint(ctl, "%-20s %d\n", "Thread(s) per core:", info.threads);
+ vshPrint(ctl, "%-20s %d\n", "NUMA cell(s):", info.nodes);
+ vshPrint(ctl, "%-20s %lu kB\n", "Memory size:", info.memory);
return TRUE;
}
dom = virDomainLookupByID(ctl->conn, id);
if (dom) {
- vshPrint(ctl, VSH_MESG, "%s\n", virDomainGetName(dom));
+ vshPrint(ctl, "%s\n", virDomainGetName(dom));
virDomainFree(dom);
} else {
vshError(ctl, FALSE, "failed to get domain '%d'", id);
dom = virDomainLookupByName(ctl->conn, name);
if (dom) {
- vshPrint(ctl, VSH_MESG, "%d\n", virDomainGetID(dom));
+ vshPrint(ctl, "%d\n", virDomainGetID(dom));
virDomainFree(dom);
} else {
vshError(ctl, FALSE, "failed to get domain '%s'", name);
includeVersion %= 1000000;
minor = includeVersion / 1000;
rel = includeVersion % 1000;
- vshPrint(ctl, VSH_MESG, "Compiled against library: libvir %d.%d.%d\n",
+ vshPrint(ctl, "Compiled against library: libvir %d.%d.%d\n",
major, minor, rel);
ret = virGetVersion(&libVersion, hvType, &apiVersion);
libVersion %= 1000000;
minor = libVersion / 1000;
rel = libVersion % 1000;
- vshPrint(ctl, VSH_MESG, "Using library: libvir %d.%d.%d\n",
+ vshPrint(ctl, "Using library: libvir %d.%d.%d\n",
major, minor, rel);
major = apiVersion / 1000000;
apiVersion %= 1000000;
minor = apiVersion / 1000;
rel = apiVersion % 1000;
- vshPrint(ctl, VSH_MESG, "Using API: %s %d.%d.%d\n", hvType,
+ vshPrint(ctl, "Using API: %s %d.%d.%d\n", hvType,
major, minor, rel);
ret = virConnectGetVersion(ctl->conn, &hvVersion);
return FALSE;
}
if (hvVersion == 0) {
- vshPrint(ctl, VSH_MESG,
+ vshPrint(ctl,
"cannot extract running %s hypervisor version\n", hvType);
} else {
major = hvVersion / 1000000;
minor = hvVersion / 1000;
rel = hvVersion % 1000;
- vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n",
+ vshPrint(ctl, "Running hypervisor: %s %d.%d.%d\n",
hvType, major, minor, rel);
}
return TRUE;
return NULL;
}
- vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n",
+ vshDebug(ctl, 5, "%s: found option <%s>: %s\n",
cmd->def->name, optname, n);
if (name)
/* try it by ID */
id = (int) strtol(n, &end, 10);
if (id >= 0 && end && *end == '\0') {
- vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n",
+ vshDebug(ctl, 5, "%s: <%s> seems like domain ID\n",
cmd->def->name, optname);
dom = virDomainLookupByID(ctl->conn, id);
}
+ /* try it by UUID */
+ if (dom==NULL && strlen(n)==36) {
+ vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n",
+ cmd->def->name, optname);
+ dom = virDomainLookupByUUIDString(ctl->conn, (const unsigned char *) n);
+ }
+
/* try it by NAME */
if (!dom) {
- vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n",
+ vshDebug(ctl, 5, "%s: <%s> tring as domain NAME\n",
cmd->def->name, optname);
dom = virDomainLookupByName(ctl->conn, n);
}
+
if (!dom)
vshError(ctl, FALSE, "failed to get domain '%s'", n);
return ret;
if (ctl->timing)
- vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n",
+ vshPrint(ctl, "\n(Time: %.3f ms)\n\n",
DIFF_MSEC(&after, &before));
else
- vshPrint(ctl, VSH_FOOTER, "\n");
+ vshPrintExtra(ctl, "\n");
cmd = cmd->next;
}
return ret;
last->next = arg;
last = arg;
- vshPrint(ctl, VSH_DEBUG4, "%s: %s(%s): %s\n",
+ vshDebug(ctl, 4, "%s: %s(%s): %s\n",
cmd->name,
opt->name,
tk == VSH_TK_OPTION ? "OPTION" : "DATA",
return "in shutdown";
case VIR_DOMAIN_SHUTOFF:
return "shut off";
+ case VIR_DOMAIN_CRASHED:
+ return "crashed";
default:
return "no state"; /* = dom0 state */
}
return TRUE;
}
-static int
-vshWantedDebug(vshOutType type, int mode)
+static void
+vshDebug(vshControl * ctl, int level, const char *format, ...)
{
- switch (type) {
- case VSH_DEBUG5:
- if (mode < 5)
- return FALSE;
- return TRUE;
- case VSH_DEBUG4:
- if (mode < 4)
- return FALSE;
- return TRUE;
- case VSH_DEBUG3:
- if (mode < 3)
- return FALSE;
- return TRUE;
- case VSH_DEBUG2:
- if (mode < 2)
- return FALSE;
- return TRUE;
- case VSH_DEBUG1:
- if (mode < 1)
- return FALSE;
- return TRUE;
- default:
- /* it's right, all others types have to pass */
- return TRUE;
- }
- return FALSE;
+ va_list ap;
+
+ if (level > ctl->debug)
+ return;
+
+ va_start(ap, format);
+ vfprintf(stdout, format, ap);
+ va_end(ap);
}
static void
-vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
+vshPrintExtra(vshControl * ctl, const char *format, ...)
{
va_list ap;
- if (ctl->quiet == TRUE && (type == VSH_HEADER || type == VSH_FOOTER))
- return;
-
- if (!vshWantedDebug(type, ctl->debug))
+ if (ctl->quiet == TRUE)
return;
va_start(ap, format);
va_end(ap);
}
+
static void
vshError(vshControl * ctl, int doexit, const char *format, ...)
{
sz -= strlen(argv[i]);
strncat(cmdstr, " ", sz--);
}
- vshPrint(ctl, VSH_DEBUG2, "command: \"%s\"\n", cmdstr);
+ vshDebug(ctl, 2, "command: \"%s\"\n", cmdstr);
ret = vshCommandParse(ctl, cmdstr);
free(cmdstr);
} else {
/* interactive mode */
if (!ctl->quiet) {
- vshPrint(ctl, VSH_MESG,
+ vshPrint(ctl,
"Welcome to %s, the virtualization interactive terminal.\n\n",
progname);
- vshPrint(ctl, VSH_MESG,
+ vshPrint(ctl,
"Type: 'help' for help with commands\n"
" 'quit' to quit\n\n");
}
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \fBvirsh\fR program is the main interface for managing virsh guest
-domains. The program can be used to create, pause, and shutdown
+domains. The program can be used to create, suspend, resume, save, and shutdown
domains. It can also be used to list current domains. Libvirt is a C toolkit to interract with the virtualization capabilities of recent versions of Linux (and other OSes). It is free software available under the \s-1GNU\s0 Lesser General Public License. Virtualization of the Linux Operating System means the ability to run multiple instances of Operating Systems concurently on a single hardware system where the basic resources are driven by a Linux instance. The library aim at providing long term stable C \s-1API\s0 initially for the Xen paravirtualization but should be able to integrate other virtualization mechanisms if needed.
.PP
The basic structure of every virsh command is almost always:
.PP
.Vb 1
-\& virsh <subcommand> <domain-id> [OPTIONS]
+\& virsh <subcommand> <domain-id|name|uuid> [OPTIONS]
.Ve
.PP
Where \fIsubcommand\fR is one of the sub commands listed below, \fIdomain-id\fR
.IP "\fBcreate\fR \fI\s-1FILE\s0\fR" 4
.IX Item "create FILE"
Create a domain from an \s-1XML\s0 <file> an easy way to create one if you have a pre-existing xen guest created via \fBxm\fR create <\s-1XMLFILE\s0>.
-.Sp
-\&\fBExample\fR
-.Sp
-virsh dumpxml <domain\-name or id> to a file.
-.IP "\fBdinfo\fR \fIdomain-name or id\fR" 4
-.IX Item "dinfo domain-name or id"
-Returns basic information about the domain.
-.IP "\fBdumpxml\fR \fIdomain-name or id\fR" 4
-.IX Item "dumpxml domain-name or id"
+.IP "\fBdumpxml\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "dumpxml domain-name, id or uuid"
Ouput the domain informations as an \s-1XML\s0 dump to stdout, this format can be used by the create sub command.
-.IP "\fBdestroy\fR \fIdomain-name or id\fR" 4
-.IX Item "destroy domain-name or id"
+.IP "\fBdestroy\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "destroy domain-name, id or uuid"
Immediately terminate the domain domain\-id. This doesn't give the domain
\&\s-1OS\s0 any chance to react, and it the equivalent of ripping the power
cord out on a physical machine. In most cases you will want to use
.IP "\fBdomid\fR \fIdomain-name\fR" 4
.IX Item "domid domain-name"
Converts a domain name to a domain id using xend's internal mapping.
-.IP "\fBdominfo\fR \fIdomain-name or id\fR" 4
-.IX Item "dominfo domain-name or id"
+.IP "\fBdominfo\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "dominfo domain-name, id or uuid"
Returns basic information about the domain.
.IP "\fBdomname\fR \fIdomain-id\fR" 4
.IX Item "domname domain-id"
convert a domain Id to domain name
-.IP "\fBdomstate\fR \fIdomain-name or id\fR" 4
-.IX Item "domstate domain-name or id"
+.IP "\fBdomstate\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "domstate domain-name, id or uuid"
Returns state about a running domain.
.IP "\fBhelp\fR optional \fIsubcommand\fR" 4
.IX Item "help optional subcommand"
current Domain is in.
=back
.RE
-.IP "\fBr \- running\fR" 4
-.IX Item "r - running"
+.IP "\fBrunning\fR" 4
+.IX Item "running"
The domain is currently running on a \s-1CPU\s0
-.IP "\fBb \- blocked\fR" 4
-.IX Item "b - blocked"
+.IP "\fBblocked\fR" 4
+.IX Item "blocked"
The domain is blocked, and not running or runable. This can be caused
because the domain is waiting on \s-1IO\s0 (a traditional wait state) or has
gone to sleep because there was nothing else for it to do.
-.IP "\fBp \- paused\fR" 4
-.IX Item "p - paused"
+.IP "\fBpaused\fR" 4
+.IX Item "paused"
The domain has been paused, usually occurring through the administrator
-running \fBxm pause\fR. When in a paused state the domain will still
+running \fBvirsh suspend\fR. When in a suspend state the domain will still
consume allocated resources like memory, but will not be eligible for
scheduling by the Xen hypervisor.
-.IP "\fBs \- shutdown\fR" 4
-.IX Item "s - shutdown"
-\&\s-1FIXME:\s0 Why would you ever see this state?
-.IP "\fBc \- crashed\fR" 4
-.IX Item "c - crashed"
+.IP "\fBin shutdown\fR" 4
+.IX Item "in shutdown"
+The domain is in process of dying, but hasn't completely shutdown or
+crashed.
+.IP "\fBshut off\fR" 4
+.IX Item "shut off"
+The domain is down.
+.IP "\fBcrashed\fR" 4
+.IX Item "crashed"
The domain has crashed, which is always a violent ending. Usually
this state can only occur if the domain has been configured not to
restart on crash. See xmdomain.cfg for more info.
-.IP "\fBd \- dying\fR" 4
-.IX Item "d - dying"
-The domain is in process of dying, but hasn't completely shutdown or
-crashed.
-.Sp
-\&\s-1FIXME:\s0 Is this right?
.RE
.RS 4
.RE
-.IP "\fBnodeinfo\fR \fIdomain-name or id\fR" 4
-.IX Item "nodeinfo domain-name or id"
+.IP "\fBnodeinfo\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "nodeinfo domain-name, id or uuid"
Returns basic information about the node.
.IP "\fBquit\fR" 4
.IX Item "quit"
quit this interactive terminal
-.IP "\fBreboot\fR \fIdomain-id\fR" 4
-.IX Item "reboot domain-id"
+.IP "\fBreboot\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "reboot domain-name, id or uuid"
Reboot a domain. This acts just as if the domain had the \fBreboot\fR
command run from the console. The command returns as soon as it has
executed the reboot action, which may be significantly before the
.IP "\fBrestore\fR \fIstate-file\fR" 4
.IX Item "restore state-file"
Restores a domain from an \fBvirsh save\fR state file. See \fIsave\fR for more info.
-.IP "\fBsave\fR \fIdomain-id\fR \fIstate-file\fR" 4
-.IX Item "save domain-id state-file"
+.IP "\fBsave\fR \fIdomain-name, id or uuid\fR \fIstate-file\fR" 4
+.IX Item "save domain-name, id or uuid state-file"
Saves a running domain to a state file so that it can be restored
later. Once saved, the domain will no longer be running on the
system, thus the memory allocated for the domain will be free for
This is roughly equivalent to doing a hibernate on a running computer,
with all the same limitations. Open network connections may be
severed upon restore, as \s-1TCP\s0 timeouts may have expired.
-.IP "\fBshutdown\fR \fIdomain-id\fR" 4
-.IX Item "shutdown domain-id"
+.IP "\fBshutdown\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "shutdown domain-name, id or uuid"
Gracefully shuts down a domain. This coordinates with the domain \s-1OS\s0
to perform graceful shutdown, so there is no guaruntee that it will
succeed, and may take a variable length of time depending on what
For a xen guest vm the behavior of what happens to a domain when it reboots is set by the
\&\fIon_shutdown\fR parameter of the xmdomain.cfg file when the domain was
created.
-.IP "\fBresume\fR \fIdomain-id\fR" 4
-.IX Item "resume domain-id"
+.IP "\fBsuspend\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "suspend domain-name, id or uuid"
+Suspend a domain. When in a suspened state the domain will still consume allocated resources
+such as memory, but will not be eligible for scheduling by the Xen hypervisor.
+.IP "\fBresume\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "resume domain-name, id or uuid"
Moves a domain out of the paused state. This will allow a previously
paused domain to now be eligible for scheduling by the the under lying hypervisor.
.IP "\fBversion\fR" 4
.Vb 2
\& Andrew Puch <apuch @ redhat.com>
\& Daniel Veillard <veillard @ redhat.com>
+\& Karel Zak <kzak @ redhat.com>
.Ve
.Sp
.Vb 3