2012-07-24 08:49:27 +00:00
|
|
|
/*
|
|
|
|
* virsh-pool.c: Commands to manage storage pool
|
|
|
|
*
|
2016-01-09 13:36:22 +00:00
|
|
|
* Copyright (C) 2005, 2007-2016 Red Hat, Inc.
|
2012-07-24 08:49:27 +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-24 08:49:27 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-08-20 22:56:53 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include "virsh-pool.h"
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-08-20 22:56:53 +00:00
|
|
|
#include "internal.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2013-05-09 18:59:04 +00:00
|
|
|
#include "virfile.h"
|
2012-09-05 06:36:33 +00:00
|
|
|
#include "conf/storage_conf.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2016-06-16 17:27:10 +00:00
|
|
|
#include "virtime.h"
|
2018-09-21 14:17:22 +00:00
|
|
|
#include "vsh-table.h"
|
2019-04-01 10:14:26 +00:00
|
|
|
#include "virenum.h"
|
2012-08-20 22:56:53 +00:00
|
|
|
|
2018-01-12 13:01:33 +00:00
|
|
|
#define VIRSH_COMMON_OPT_POOL_FULL(cflags) \
|
|
|
|
VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags)
|
2017-11-03 12:09:47 +00:00
|
|
|
|
|
|
|
#define VIRSH_COMMON_OPT_POOL_BUILD \
|
|
|
|
{.name = "build", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.flags = 0, \
|
|
|
|
.help = N_("build the pool as normal") \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2017-11-03 12:09:47 +00:00
|
|
|
|
|
|
|
#define VIRSH_COMMON_OPT_POOL_NO_OVERWRITE \
|
|
|
|
{.name = "no-overwrite", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.flags = 0, \
|
|
|
|
.help = N_("do not overwrite any existing data") \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2017-11-03 12:09:47 +00:00
|
|
|
|
|
|
|
#define VIRSH_COMMON_OPT_POOL_OVERWRITE \
|
|
|
|
{.name = "overwrite", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.flags = 0, \
|
|
|
|
.help = N_("overwrite any existing data") \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2017-11-03 12:09:47 +00:00
|
|
|
|
|
|
|
#define VIRSH_COMMON_OPT_POOL_X_AS \
|
|
|
|
{.name = "name", \
|
|
|
|
.type = VSH_OT_DATA, \
|
|
|
|
.flags = VSH_OFLAG_REQ, \
|
|
|
|
.help = N_("name of the pool") \
|
|
|
|
}, \
|
|
|
|
{.name = "type", \
|
|
|
|
.type = VSH_OT_DATA, \
|
|
|
|
.flags = VSH_OFLAG_REQ, \
|
|
|
|
.help = N_("type of the pool") \
|
|
|
|
}, \
|
|
|
|
{.name = "print-xml", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = N_("print XML document, but don't define/create") \
|
|
|
|
}, \
|
|
|
|
{.name = "source-host", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("source-host for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "source-path", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("source path for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "source-dev", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("source device for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "source-name", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("source name for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "target", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("target for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "source-format", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("format for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "auth-type", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("auth type to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "auth-username", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("auth username to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "secret-usage", \
|
|
|
|
.type = VSH_OT_STRING, \
|
2015-11-25 13:57:30 +00:00
|
|
|
.help = N_("auth secret usage to be used for underlying storage") \
|
2017-11-03 12:09:47 +00:00
|
|
|
}, \
|
|
|
|
{.name = "secret-uuid", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("auth secret UUID to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-name", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter name to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-wwnn", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter wwnn to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-wwpn", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter wwpn to be used for underlying storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-parent", \
|
|
|
|
.type = VSH_OT_STRING, \
|
2018-03-08 23:19:58 +00:00
|
|
|
.help = N_("adapter parent scsi_hostN to be used for underlying vHBA storage") \
|
2018-03-08 23:17:10 +00:00
|
|
|
}, \
|
|
|
|
{.name = "adapter-parent-wwnn", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter parent scsi_hostN wwnn to be used for underlying vHBA storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-parent-wwpn", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter parent scsi_hostN wwpn to be used for underlying vHBA storage") \
|
|
|
|
}, \
|
|
|
|
{.name = "adapter-parent-fabric-wwn", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("adapter parent scsi_hostN fabric_wwn to be used for underlying vHBA storage") \
|
2019-01-11 19:48:31 +00:00
|
|
|
}, \
|
|
|
|
{.name = "source-protocol-ver", \
|
|
|
|
.type = VSH_OT_STRING, \
|
|
|
|
.help = N_("nfsvers value for NFS pool mount option") \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2015-11-25 13:57:30 +00:00
|
|
|
|
2012-08-20 22:56:53 +00:00
|
|
|
virStoragePoolPtr
|
2015-06-15 16:53:58 +00:00
|
|
|
virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
|
|
|
|
const char **name, unsigned int flags)
|
2012-07-24 08:49:27 +00:00
|
|
|
{
|
|
|
|
virStoragePoolPtr pool = NULL;
|
|
|
|
const char *n = NULL;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
|
|
|
|
|
|
|
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
2018-02-28 01:17:54 +00:00
|
|
|
if (cmd->skipChecks && !n)
|
|
|
|
return NULL;
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n",
|
|
|
|
cmd->def->name, optname, n);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
*name = n;
|
|
|
|
|
|
|
|
/* try it by UUID */
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
|
2012-07-24 08:49:27 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool UUID\n",
|
|
|
|
cmd->def->name, optname);
|
2015-06-15 16:53:58 +00:00
|
|
|
pool = virStoragePoolLookupByUUIDString(priv->conn, n);
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
/* try it by NAME */
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!pool && (flags & VIRSH_BYNAME)) {
|
2012-07-24 08:49:27 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool NAME\n",
|
|
|
|
cmd->def->name, optname);
|
2015-06-15 16:53:58 +00:00
|
|
|
pool = virStoragePoolLookupByName(priv->conn, n);
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pool)
|
|
|
|
vshError(ctl, _("failed to get pool '%s'"), n);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-autostart" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_autostart[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("autostart a pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Configure a pool to be automatically started at boot.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_autostart[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = "disable",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("disable autostarting")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
const char *name;
|
|
|
|
int autostart;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
autostart = !vshCommandOptBool(cmd, "disable");
|
|
|
|
|
|
|
|
if (virStoragePoolSetAutostart(pool, autostart) < 0) {
|
|
|
|
if (autostart)
|
|
|
|
vshError(ctl, _("failed to mark pool %s as autostarted"), name);
|
|
|
|
else
|
|
|
|
vshError(ctl, _("failed to unmark pool %s as autostarted"), name);
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autostart)
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s marked as autostarted\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
else
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s unmarked as autostarted\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-create" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_create[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("create a pool from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Create a pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_create[] = {
|
2016-01-09 13:36:29 +00:00
|
|
|
VIRSH_COMMON_OPT_FILE(N_("file containing an XML pool description")),
|
2016-01-09 13:36:22 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_BUILD,
|
|
|
|
VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
|
|
|
|
VIRSH_COMMON_OPT_POOL_OVERWRITE,
|
2015-11-25 14:08:54 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = true;
|
|
|
|
char *buffer;
|
2015-11-25 14:51:51 +00:00
|
|
|
bool build;
|
|
|
|
bool overwrite;
|
|
|
|
bool no_overwrite;
|
|
|
|
unsigned int flags = 0;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-11-25 14:51:51 +00:00
|
|
|
build = vshCommandOptBool(cmd, "build");
|
|
|
|
overwrite = vshCommandOptBool(cmd, "overwrite");
|
|
|
|
no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_EXPR("overwrite", overwrite,
|
|
|
|
"no-overwrite", no_overwrite);
|
|
|
|
|
|
|
|
if (build)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
|
|
|
|
if (overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
|
|
|
|
if (no_overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
|
|
|
|
|
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-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-11-25 14:51:51 +00:00
|
|
|
pool = virStoragePoolCreateXML(priv->conn, buffer, flags);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s created from %s\n"),
|
|
|
|
virStoragePoolGetName(pool), from);
|
2012-07-24 08:49:27 +00:00
|
|
|
virStoragePoolFree(pool);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to create pool from %s"), from);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-25 13:57:30 +00:00
|
|
|
static const vshCmdOptDef opts_pool_define_as[] = {
|
2016-01-09 13:36:22 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_X_AS,
|
2015-11-25 13:57:30 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
2013-01-21 14:11:12 +00:00
|
|
|
static int
|
2015-06-15 16:53:58 +00:00
|
|
|
virshBuildPoolXML(vshControl *ctl,
|
|
|
|
const vshCmd *cmd,
|
|
|
|
const char **retname,
|
|
|
|
char **xml)
|
2013-01-21 14:11:12 +00:00
|
|
|
{
|
2012-07-24 08:49:27 +00:00
|
|
|
const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
|
2013-01-21 14:11:12 +00:00
|
|
|
*srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
|
2014-12-03 23:45:50 +00:00
|
|
|
*target = NULL, *authType = NULL, *authUsername = NULL,
|
2014-12-04 14:22:30 +00:00
|
|
|
*secretUsage = NULL, *adapterName = NULL, *adapterParent = NULL,
|
2018-03-08 23:17:10 +00:00
|
|
|
*adapterWwnn = NULL, *adapterWwpn = NULL, *secretUUID = NULL,
|
|
|
|
*adapterParentWwnn = NULL, *adapterParentWwpn = NULL,
|
2019-01-11 19:48:31 +00:00
|
|
|
*adapterParentFabricWwn = NULL, *protoVer = NULL;
|
2020-07-02 23:40:16 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2017-09-05 17:44:15 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid");
|
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
2020-07-03 03:20:27 +00:00
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
2020-07-03 03:20:27 +00:00
|
|
|
return false;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "source-host", &srcHost) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "source-path", &srcPath) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "source-dev", &srcDev) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "source-name", &srcName) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "source-format", &srcFormat) < 0 ||
|
2014-12-03 23:45:50 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "auth-type", &authType) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "auth-username", &authUsername) < 0 ||
|
2014-12-04 14:22:30 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "secret-usage", &secretUsage) < 0 ||
|
2017-09-05 17:44:15 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "secret-uuid", &secretUUID) < 0 ||
|
2014-12-04 14:22:30 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-name", &adapterName) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-wwnn", &adapterWwnn) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-wwpn", &adapterWwpn) < 0 ||
|
2018-03-08 23:17:10 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-parent", &adapterParent) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwnn", &adapterParentWwnn) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwpn", &adapterParentWwpn) < 0 ||
|
2019-01-11 19:48:31 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", &adapterParentFabricWwn) < 0 ||
|
2020-07-03 03:20:27 +00:00
|
|
|
vshCommandOptStringReq(ctl, cmd, "source-protocol-ver", &protoVer) < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferAsprintf(&buf, "<name>%s</name>\n", name);
|
2015-05-28 18:29:19 +00:00
|
|
|
if (srcHost || srcPath || srcDev || srcFormat || srcName ||
|
|
|
|
(adapterWwnn && adapterWwpn) || adapterName) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAddLit(&buf, "<source>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
if (srcHost)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<host name='%s'/>\n", srcHost);
|
2012-07-24 08:49:27 +00:00
|
|
|
if (srcPath)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<dir path='%s'/>\n", srcPath);
|
2012-07-24 08:49:27 +00:00
|
|
|
if (srcDev)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<device path='%s'/>\n", srcDev);
|
2014-12-04 14:22:30 +00:00
|
|
|
if (adapterWwnn && adapterWwpn) {
|
|
|
|
virBufferAddLit(&buf, "<adapter type='fc_host'");
|
|
|
|
if (adapterParent)
|
|
|
|
virBufferAsprintf(&buf, " parent='%s'", adapterParent);
|
2018-03-08 23:17:10 +00:00
|
|
|
else if (adapterParentWwnn && adapterParentWwpn)
|
2018-07-19 18:00:07 +00:00
|
|
|
virBufferAsprintf(&buf, " parent_wwnn='%s' parent_wwpn='%s'",
|
2018-03-08 23:17:10 +00:00
|
|
|
adapterParentWwnn, adapterParentWwpn);
|
|
|
|
else if (adapterParentFabricWwn)
|
|
|
|
virBufferAsprintf(&buf, " parent_fabric_wwn='%s'",
|
|
|
|
adapterParentFabricWwn);
|
2014-12-04 14:22:30 +00:00
|
|
|
virBufferAsprintf(&buf, " wwnn='%s' wwpn='%s'/>\n",
|
|
|
|
adapterWwnn, adapterWwpn);
|
|
|
|
} else if (adapterName) {
|
|
|
|
virBufferAsprintf(&buf, "<adapter type='scsi_host' name='%s'/>\n",
|
|
|
|
adapterName);
|
|
|
|
}
|
2017-09-05 17:44:15 +00:00
|
|
|
if (authType && authUsername && (secretUsage || secretUUID)) {
|
2014-12-03 23:45:50 +00:00
|
|
|
virBufferAsprintf(&buf, "<auth type='%s' username='%s'>\n",
|
|
|
|
authType, authUsername);
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2017-09-05 17:44:15 +00:00
|
|
|
if (secretUsage)
|
|
|
|
virBufferAsprintf(&buf, "<secret usage='%s'/>\n", secretUsage);
|
|
|
|
else
|
|
|
|
virBufferAsprintf(&buf, "<secret uuid='%s'/>\n", secretUUID);
|
2014-12-03 23:45:50 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</auth>\n");
|
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
if (srcFormat)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<format type='%s'/>\n", srcFormat);
|
2012-07-24 08:49:27 +00:00
|
|
|
if (srcName)
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAsprintf(&buf, "<name>%s</name>\n", srcName);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2019-01-11 19:48:31 +00:00
|
|
|
if (protoVer)
|
|
|
|
virBufferAsprintf(&buf, "<protocol ver='%s'/>\n", protoVer);
|
|
|
|
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</source>\n");
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
if (target) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAddLit(&buf, "<target>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferAsprintf(&buf, "<path>%s</path>\n", target);
|
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</target>\n");
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
2012-07-24 08:49:27 +00:00
|
|
|
virBufferAddLit(&buf, "</pool>\n");
|
|
|
|
|
|
|
|
*xml = virBufferContentAndReset(&buf);
|
|
|
|
*retname = name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-create-as" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_create_as[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("create a pool from a set of args")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Create a pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
2015-11-25 13:57:30 +00:00
|
|
|
static const vshCmdOptDef opts_pool_create_as[] = {
|
2016-01-09 13:36:22 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_X_AS,
|
|
|
|
VIRSH_COMMON_OPT_POOL_BUILD,
|
|
|
|
VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
|
|
|
|
VIRSH_COMMON_OPT_POOL_OVERWRITE,
|
2015-11-25 13:57:30 +00:00
|
|
|
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
static bool
|
|
|
|
cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
const char *name;
|
|
|
|
char *xml;
|
|
|
|
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
2015-11-25 14:51:51 +00:00
|
|
|
bool build;
|
|
|
|
bool overwrite;
|
|
|
|
bool no_overwrite;
|
|
|
|
unsigned int flags = 0;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2015-11-25 14:51:51 +00:00
|
|
|
build = vshCommandOptBool(cmd, "build");
|
|
|
|
overwrite = vshCommandOptBool(cmd, "overwrite");
|
|
|
|
no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_EXPR("overwrite", overwrite,
|
|
|
|
"no-overwrite", no_overwrite);
|
|
|
|
|
|
|
|
if (build)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
|
|
|
|
if (overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
|
|
|
|
if (no_overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (printXML) {
|
|
|
|
vshPrint(ctl, "%s", xml);
|
|
|
|
VIR_FREE(xml);
|
|
|
|
} else {
|
2015-11-25 14:51:51 +00:00
|
|
|
pool = virStoragePoolCreateXML(priv->conn, xml, flags);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s created\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
virStoragePoolFree(pool);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to create pool %s"), name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-define" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_define[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
2015-02-25 14:51:41 +00:00
|
|
|
.data = N_("define an inactive persistent storage pool or modify "
|
|
|
|
"an existing persistent one from an XML file")
|
2013-02-07 15:25:10 +00:00
|
|
|
},
|
|
|
|
{.name = "desc",
|
2015-02-25 14:51:41 +00:00
|
|
|
.data = N_("Define or modify a persistent storage pool.")
|
2013-02-07 15:25:10 +00:00
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_define[] = {
|
2016-01-09 13:36:29 +00:00
|
|
|
VIRSH_COMMON_OPT_FILE(N_("file containing an XML pool description")),
|
2015-11-25 14:08:54 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = true;
|
|
|
|
char *buffer;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-24 08:49:27 +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-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
pool = virStoragePoolDefineXML(priv->conn, buffer, 0);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s defined from %s\n"),
|
|
|
|
virStoragePoolGetName(pool), from);
|
2012-07-24 08:49:27 +00:00
|
|
|
virStoragePoolFree(pool);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to define pool from %s"), from);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-define-as" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_define_as[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("define a pool from a set of args")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Define a pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
const char *name;
|
|
|
|
char *xml;
|
|
|
|
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (printXML) {
|
|
|
|
vshPrint(ctl, "%s", xml);
|
|
|
|
VIR_FREE(xml);
|
|
|
|
} else {
|
2015-06-15 16:53:58 +00:00
|
|
|
pool = virStoragePoolDefineXML(priv->conn, xml, 0);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s defined\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
virStoragePoolFree(pool);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to define pool %s"), name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-build" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_build[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("build a pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Build a given pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_build[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2016-01-09 13:36:22 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
|
|
|
|
VIRSH_COMMON_OPT_POOL_OVERWRITE,
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2014-11-13 14:20:51 +00:00
|
|
|
if (vshCommandOptBool(cmd, "no-overwrite"))
|
2012-07-24 08:49:27 +00:00
|
|
|
flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
|
|
|
|
|
2014-11-13 14:20:51 +00:00
|
|
|
if (vshCommandOptBool(cmd, "overwrite"))
|
2012-07-24 08:49:27 +00:00
|
|
|
flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
|
|
|
|
|
|
|
|
if (virStoragePoolBuild(pool, flags) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s built\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to build pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-destroy" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_destroy[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("destroy (stop) a pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Forcefully stop a given pool. Raw data in the pool is untouched")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_destroy[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virStoragePoolDestroy(pool) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s destroyed\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to destroy pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-delete" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_delete[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("delete a pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Delete a given pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_delete[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virStoragePoolDelete(pool, 0) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s deleted\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to delete pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-refresh" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_refresh[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("refresh a pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Refresh a given pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_refresh[] = {
|
2019-03-01 09:56:42 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virStoragePoolRefresh(pool, 0) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s refreshed\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to refresh pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-dumpxml" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_dumpxml[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("pool information in XML")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Output the pool information as an XML dump to stdout.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_dumpxml[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = "inactive",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("show inactive defined XML")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
bool inactive = vshCommandOptBool(cmd, "inactive");
|
|
|
|
unsigned int flags = 0;
|
|
|
|
char *dump;
|
|
|
|
|
|
|
|
if (inactive)
|
|
|
|
flags |= VIR_STORAGE_XML_INACTIVE;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
dump = virStoragePoolGetXMLDesc(pool, flags);
|
|
|
|
if (dump != NULL) {
|
|
|
|
vshPrint(ctl, "%s", dump);
|
|
|
|
VIR_FREE(dump);
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
static int
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolSorter(const void *a, const void *b)
|
2012-09-05 06:36:33 +00:00
|
|
|
{
|
|
|
|
virStoragePoolPtr *pa = (virStoragePoolPtr *) a;
|
|
|
|
virStoragePoolPtr *pb = (virStoragePoolPtr *) b;
|
|
|
|
|
|
|
|
if (*pa && !*pb)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!*pa)
|
|
|
|
return *pb != NULL;
|
|
|
|
|
|
|
|
return vshStrcasecmp(virStoragePoolGetName(*pa),
|
|
|
|
virStoragePoolGetName(*pb));
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
struct virshStoragePoolList {
|
2012-09-05 06:36:33 +00:00
|
|
|
virStoragePoolPtr *pools;
|
|
|
|
size_t npools;
|
|
|
|
};
|
2015-06-15 16:53:58 +00:00
|
|
|
typedef struct virshStoragePoolList *virshStoragePoolListPtr;
|
2012-09-05 06:36:33 +00:00
|
|
|
|
|
|
|
static void
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolListFree(virshStoragePoolListPtr list)
|
2012-09-05 06:36:33 +00:00
|
|
|
{
|
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-09-05 06:36:33 +00:00
|
|
|
|
|
|
|
if (list && list->pools) {
|
|
|
|
for (i = 0; i < list->npools; i++) {
|
|
|
|
if (list->pools[i])
|
|
|
|
virStoragePoolFree(list->pools[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(list->pools);
|
|
|
|
}
|
|
|
|
VIR_FREE(list);
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
static virshStoragePoolListPtr
|
|
|
|
virshStoragePoolListCollect(vshControl *ctl,
|
|
|
|
unsigned int flags)
|
2012-09-05 06:36:33 +00:00
|
|
|
{
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
|
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-09-05 06:36:33 +00:00
|
|
|
int ret;
|
|
|
|
char **names = NULL;
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool success = false;
|
|
|
|
size_t deleted = 0;
|
|
|
|
int persistent;
|
|
|
|
int autostart;
|
|
|
|
int nActivePools = 0;
|
|
|
|
int nInactivePools = 0;
|
|
|
|
int nAllPools = 0;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-09-05 06:36:33 +00:00
|
|
|
|
2012-09-13 08:56:07 +00:00
|
|
|
/* try the list with flags support (0.10.2 and later) */
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((ret = virConnectListAllStoragePools(priv->conn,
|
2012-09-05 06:36:33 +00:00
|
|
|
&list->pools,
|
|
|
|
flags)) >= 0) {
|
|
|
|
list->npools = ret;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the command is actually supported */
|
2012-09-13 08:56:07 +00:00
|
|
|
if (last_error && last_error->code == VIR_ERR_NO_SUPPORT)
|
2012-09-05 06:36:33 +00:00
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
if (last_error && last_error->code == VIR_ERR_INVALID_ARG) {
|
|
|
|
/* try the new API again but mask non-guaranteed flags */
|
|
|
|
unsigned int newflags = flags & (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
|
|
|
|
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE);
|
|
|
|
vshResetLibvirtError();
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((ret = virConnectListAllStoragePools(priv->conn, &list->pools,
|
2012-09-05 06:36:33 +00:00
|
|
|
newflags)) >= 0) {
|
|
|
|
list->npools = ret;
|
|
|
|
goto filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there was an error during the first or second call */
|
|
|
|
vshError(ctl, "%s", _("Failed to list pools"));
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
fallback:
|
2012-09-13 08:56:07 +00:00
|
|
|
/* fall back to old method (0.10.1 and older) */
|
2012-09-05 06:36:33 +00:00
|
|
|
vshResetLibvirtError();
|
|
|
|
|
|
|
|
/* There is no way to get the pool type */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)) {
|
2012-09-05 06:36:33 +00:00
|
|
|
vshError(ctl, "%s", _("Filtering using --type is not supported "
|
|
|
|
"by this libvirt"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the number of active pools */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
|
|
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((nActivePools = virConnectNumOfStoragePools(priv->conn)) < 0) {
|
2012-09-05 06:36:33 +00:00
|
|
|
vshError(ctl, "%s", _("Failed to get the number of active pools "));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the number of inactive pools */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
|
|
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((nInactivePools = virConnectNumOfDefinedStoragePools(priv->conn)) < 0) {
|
2012-09-05 06:36:33 +00:00
|
|
|
vshError(ctl, "%s", _("Failed to get the number of inactive pools"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nAllPools = nActivePools + nInactivePools;
|
|
|
|
|
|
|
|
if (nAllPools == 0)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
names = vshMalloc(ctl, sizeof(char *) * nAllPools);
|
|
|
|
|
|
|
|
/* Retrieve a list of active storage pool names */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
|
|
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if (virConnectListStoragePools(priv->conn,
|
2012-09-05 06:36:33 +00:00
|
|
|
names, nActivePools) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to list active pools"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the inactive storage pools to the end of the name list */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
|
|
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if (virConnectListDefinedStoragePools(priv->conn,
|
2012-09-05 06:36:33 +00:00
|
|
|
&names[nActivePools],
|
|
|
|
nInactivePools) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to list inactive pools"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list->pools = vshMalloc(ctl, sizeof(virStoragePoolPtr) * (nAllPools));
|
|
|
|
list->npools = 0;
|
|
|
|
|
|
|
|
/* get active pools */
|
|
|
|
for (i = 0; i < nActivePools; i++) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virStoragePoolLookupByName(priv->conn, names[i])))
|
2012-09-05 06:36:33 +00:00
|
|
|
continue;
|
|
|
|
list->pools[list->npools++] = pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get inactive pools */
|
|
|
|
for (i = 0; i < nInactivePools; i++) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virStoragePoolLookupByName(priv->conn, names[i])))
|
2012-09-05 06:36:33 +00:00
|
|
|
continue;
|
|
|
|
list->pools[list->npools++] = pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truncate pools that weren't found */
|
|
|
|
deleted = nAllPools - list->npools;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
filter:
|
2012-09-05 06:36:33 +00:00
|
|
|
/* filter list the list if the list was acquired by fallback means */
|
|
|
|
for (i = 0; i < list->npools; i++) {
|
|
|
|
pool = list->pools[i];
|
|
|
|
|
|
|
|
/* persistence filter */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT)) {
|
2012-09-05 06:36:33 +00:00
|
|
|
if ((persistent = virStoragePoolIsPersistent(pool)) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to get pool persistence info"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!((VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT) && persistent) ||
|
|
|
|
(VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT) && !persistent)))
|
2012-09-05 06:36:33 +00:00
|
|
|
goto remove_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* autostart filter */
|
2012-09-06 15:35:00 +00:00
|
|
|
if (VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART)) {
|
2012-09-05 06:36:33 +00:00
|
|
|
if (virStoragePoolGetAutostart(pool, &autostart) < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to get pool autostart state"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-09-06 15:35:00 +00:00
|
|
|
if (!((VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART) && autostart) ||
|
|
|
|
(VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART) && !autostart)))
|
2012-09-05 06:36:33 +00:00
|
|
|
goto remove_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the pool matched all filters, it may stay */
|
|
|
|
continue;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
remove_entry:
|
2012-09-05 06:36:33 +00:00
|
|
|
/* the pool has to be removed as it failed one of the filters */
|
|
|
|
virStoragePoolFree(list->pools[i]);
|
|
|
|
list->pools[i] = NULL;
|
|
|
|
deleted++;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
finished:
|
2012-09-05 06:36:33 +00:00
|
|
|
/* sort the list */
|
|
|
|
if (list->pools && list->npools)
|
|
|
|
qsort(list->pools, list->npools,
|
2015-06-15 16:53:58 +00:00
|
|
|
sizeof(*list->pools), virshStoragePoolSorter);
|
2012-09-05 06:36:33 +00:00
|
|
|
|
|
|
|
/* truncate the list if filter simulation deleted entries */
|
|
|
|
if (deleted)
|
|
|
|
VIR_SHRINK_N(list->pools, list->npools, deleted);
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-09-05 06:36:33 +00:00
|
|
|
for (i = 0; i < nAllPools; i++)
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
|
|
|
|
if (!success) {
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolListFree(list);
|
2012-09-05 06:36:33 +00:00
|
|
|
list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(names);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virshStoragePoolState);
|
2015-06-15 16:53:58 +00:00
|
|
|
VIR_ENUM_IMPL(virshStoragePoolState,
|
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_STORAGE_POOL_STATE_LAST,
|
|
|
|
N_("inactive"),
|
|
|
|
N_("building"),
|
|
|
|
N_("running"),
|
|
|
|
N_("degraded"),
|
2019-01-20 16:30:15 +00:00
|
|
|
N_("inaccessible"));
|
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 *
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolStateToString(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
|
|
|
{
|
2015-06-15 16:53:58 +00:00
|
|
|
const char *str = virshStoragePoolStateTypeToString(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
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
/*
|
|
|
|
* "pool-list" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_list[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("list pools")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns list of pools.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_list[] = {
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = "inactive",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list inactive pools")
|
|
|
|
},
|
|
|
|
{.name = "all",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list inactive & active pools")
|
|
|
|
},
|
|
|
|
{.name = "transient",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list transient pools")
|
|
|
|
},
|
|
|
|
{.name = "persistent",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list persistent pools")
|
|
|
|
},
|
|
|
|
{.name = "autostart",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list pools with autostart enabled")
|
|
|
|
},
|
|
|
|
{.name = "no-autostart",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list pools with autostart disabled")
|
|
|
|
},
|
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_STRING,
|
2019-07-19 08:25:19 +00:00
|
|
|
.completer = virshPoolTypeCompleter,
|
2013-01-14 14:36:53 +00:00
|
|
|
.help = N_("only list pool of specified type(s) (if supported)")
|
|
|
|
},
|
|
|
|
{.name = "details",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("display extended details for pools")
|
|
|
|
},
|
2017-01-06 14:42:51 +00:00
|
|
|
{.name = "uuid",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list UUID of active pools only")
|
|
|
|
},
|
2017-01-06 14:42:52 +00:00
|
|
|
{.name = "name",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("list name of active pools only")
|
|
|
|
},
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2019-10-14 12:44:29 +00:00
|
|
|
cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
2012-07-24 08:49:27 +00:00
|
|
|
{
|
|
|
|
virStoragePoolInfo info;
|
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;
|
2014-02-21 21:33:30 +00:00
|
|
|
bool ret = false;
|
2012-07-24 08:49:27 +00:00
|
|
|
struct poolInfoText {
|
|
|
|
char *state;
|
|
|
|
char *autostart;
|
|
|
|
char *persistent;
|
|
|
|
char *capacity;
|
|
|
|
char *allocation;
|
|
|
|
char *available;
|
|
|
|
};
|
|
|
|
struct poolInfoText *poolInfoTexts = NULL;
|
2012-09-05 06:36:33 +00:00
|
|
|
unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolListPtr list = NULL;
|
2012-09-05 06:36:33 +00:00
|
|
|
const char *type = NULL;
|
2012-07-24 08:49:27 +00:00
|
|
|
bool details = vshCommandOptBool(cmd, "details");
|
2012-09-05 06:36:33 +00:00
|
|
|
bool inactive, all;
|
2017-01-06 14:42:51 +00:00
|
|
|
bool uuid = false;
|
2017-01-06 14:42:52 +00:00
|
|
|
bool name = false;
|
2018-09-21 14:17:22 +00:00
|
|
|
vshTablePtr table = NULL;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
inactive = vshCommandOptBool(cmd, "inactive");
|
|
|
|
all = vshCommandOptBool(cmd, "all");
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
if (inactive)
|
|
|
|
flags = VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
if (all)
|
|
|
|
flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
|
|
|
|
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
if (vshCommandOptBool(cmd, "autostart"))
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
if (vshCommandOptBool(cmd, "no-autostart"))
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "persistent"))
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "transient"))
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT;
|
|
|
|
|
2017-01-06 14:42:51 +00:00
|
|
|
if (vshCommandOptBool(cmd, "uuid"))
|
|
|
|
uuid = true;
|
|
|
|
|
2017-01-06 14:42:52 +00:00
|
|
|
if (vshCommandOptBool(cmd, "name"))
|
|
|
|
name = true;
|
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
2012-09-05 06:36:33 +00:00
|
|
|
return false;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2017-01-06 14:42:51 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS("details", "uuid");
|
2017-01-06 14:42:52 +00:00
|
|
|
VSH_EXCLUSIVE_OPTIONS("details", "name");
|
2017-01-06 14:42:51 +00:00
|
|
|
|
2012-09-05 06:36:33 +00:00
|
|
|
if (type) {
|
|
|
|
int poolType = -1;
|
|
|
|
char **poolTypes = NULL;
|
|
|
|
int npoolTypes = 0;
|
|
|
|
|
2013-08-15 16:20:05 +00:00
|
|
|
if ((npoolTypes = vshStringToArray(type, &poolTypes)) < 0)
|
|
|
|
return false;
|
2012-09-05 06:36:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < npoolTypes; i++) {
|
|
|
|
if ((poolType = virStoragePoolTypeFromString(poolTypes[i])) < 0) {
|
2013-08-15 16:27:37 +00:00
|
|
|
vshError(ctl, _("Invalid pool type '%s'"), poolTypes[i]);
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(poolTypes);
|
2012-09-05 06:36:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-11 15:08:50 +00:00
|
|
|
switch ((virStoragePoolType) poolType) {
|
2012-09-05 06:36:33 +00:00
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_DIR;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_FS;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_NETFS;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_DISK;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI;
|
|
|
|
break;
|
2018-07-31 08:44:21 +00:00
|
|
|
case VIR_STORAGE_POOL_ISCSI_DIRECT:
|
2019-07-11 07:23:05 +00:00
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI_DIRECT;
|
2018-07-31 08:44:21 +00:00
|
|
|
break;
|
2012-09-05 06:36:33 +00:00
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_SCSI;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_MPATH:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_MPATH;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_RBD:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_RBD;
|
|
|
|
break;
|
2013-12-13 09:31:50 +00:00
|
|
|
case VIR_STORAGE_POOL_SHEEPDOG:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG;
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_POOL_GLUSTER:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER;
|
|
|
|
break;
|
2014-07-21 14:38:42 +00:00
|
|
|
case VIR_STORAGE_POOL_ZFS:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_ZFS;
|
|
|
|
break;
|
2017-01-17 14:10:55 +00:00
|
|
|
case VIR_STORAGE_POOL_VSTORAGE:
|
|
|
|
flags |= VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE;
|
|
|
|
break;
|
2013-12-13 09:31:50 +00:00
|
|
|
case VIR_STORAGE_POOL_LAST:
|
2012-09-05 06:36:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(poolTypes);
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(list = virshStoragePoolListCollect(ctl, flags)))
|
2012-09-05 06:36:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
poolInfoTexts = vshCalloc(ctl, list->npools, sizeof(*poolInfoTexts));
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
/* Collect the storage pool information for display */
|
2012-09-05 06:36:33 +00:00
|
|
|
for (i = 0; i < list->npools; i++) {
|
2012-07-24 08:49:27 +00:00
|
|
|
int autostart = 0, persistent = 0;
|
|
|
|
|
|
|
|
/* Retrieve the autostart status of the pool */
|
2012-09-05 06:36:33 +00:00
|
|
|
if (virStoragePoolGetAutostart(list->pools[i], &autostart) < 0)
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].autostart = g_strdup(_("no autostart"));
|
2012-07-24 08:49:27 +00:00
|
|
|
else
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].autostart = g_strdup(autostart ? _("yes") : _("no"));
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
/* Retrieve the persistence status of the pool */
|
|
|
|
if (details) {
|
2012-09-05 06:36:33 +00:00
|
|
|
persistent = virStoragePoolIsPersistent(list->pools[i]);
|
2012-07-24 08:49:27 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "Persistent flag value: %d\n",
|
|
|
|
persistent);
|
|
|
|
if (persistent < 0)
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].persistent = g_strdup(_("unknown"));
|
2012-07-24 08:49:27 +00:00
|
|
|
else
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].persistent = g_strdup(persistent ? _("yes") : _("no"));
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Collect further extended information about the pool */
|
2012-09-05 06:36:33 +00:00
|
|
|
if (virStoragePoolGetInfo(list->pools[i], &info) != 0) {
|
2012-07-24 08:49:27 +00:00
|
|
|
/* Something went wrong retrieving pool info, cope with it */
|
|
|
|
vshError(ctl, "%s", _("Could not retrieve pool information"));
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].state = g_strdup(_("unknown"));
|
2012-07-24 08:49:27 +00:00
|
|
|
if (details) {
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].capacity = g_strdup(_("unknown"));
|
|
|
|
poolInfoTexts[i].allocation = g_strdup(_("unknown"));
|
|
|
|
poolInfoTexts[i].available = g_strdup(_("unknown"));
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Decide which state string to display */
|
|
|
|
if (details) {
|
2015-06-15 16:53:58 +00:00
|
|
|
const char *state = virshStoragePoolStateToString(info.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
|
|
|
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].state = g_strdup(state);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
/* Create the pool size related strings */
|
|
|
|
if (info.state == VIR_STORAGE_POOL_RUNNING ||
|
|
|
|
info.state == VIR_STORAGE_POOL_DEGRADED) {
|
|
|
|
double val;
|
|
|
|
const char *unit;
|
|
|
|
|
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
|
|
|
val = vshPrettyCapacity(info.capacity, &unit);
|
2019-10-22 13:26:14 +00:00
|
|
|
poolInfoTexts[i].capacity = g_strdup_printf("%.2lf %s", val,
|
|
|
|
unit);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
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
|
|
|
val = vshPrettyCapacity(info.allocation, &unit);
|
2019-10-22 13:26:14 +00:00
|
|
|
poolInfoTexts[i].allocation = g_strdup_printf("%.2lf %s", val,
|
|
|
|
unit);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
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
|
|
|
val = vshPrettyCapacity(info.available, &unit);
|
2019-10-22 13:26:14 +00:00
|
|
|
poolInfoTexts[i].available = g_strdup_printf("%.2lf %s", val,
|
|
|
|
unit);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
/* Capacity related information isn't available */
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].capacity = g_strdup(_("-"));
|
|
|
|
poolInfoTexts[i].allocation = g_strdup(_("-"));
|
|
|
|
poolInfoTexts[i].available = g_strdup(_("-"));
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* --details option was not specified, only active/inactive
|
2012-09-05 06:36:33 +00:00
|
|
|
* state strings are used */
|
|
|
|
if (virStoragePoolIsActive(list->pools[i]))
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].state = g_strdup(_("active"));
|
2012-09-05 06:36:33 +00:00
|
|
|
else
|
2019-10-18 15:24:02 +00:00
|
|
|
poolInfoTexts[i].state = g_strdup(_("inactive"));
|
2012-09-05 06:36:33 +00:00
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the --details option wasn't selected, we output the pool
|
|
|
|
* info using the fixed string format from previous versions to
|
|
|
|
* maintain backward compatibility.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Output basic info then return if --details option not selected */
|
|
|
|
if (!details) {
|
2017-01-06 14:42:53 +00:00
|
|
|
if (uuid || name) {
|
2017-01-06 14:42:51 +00:00
|
|
|
for (i = 0; i < list->npools; i++) {
|
2017-01-06 14:42:53 +00:00
|
|
|
if (uuid) {
|
|
|
|
char uuid_str[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virStoragePoolGetUUIDString(list->pools[i], uuid_str);
|
|
|
|
vshPrint(ctl, "%-36s%c", uuid_str, name ? ' ': '\n');
|
|
|
|
}
|
|
|
|
if (name) {
|
|
|
|
const char *name_str =
|
|
|
|
virStoragePoolGetName(list->pools[i]);
|
|
|
|
vshPrint(ctl, "%-20s\n", name_str);
|
|
|
|
}
|
2017-01-06 14:42:52 +00:00
|
|
|
}
|
|
|
|
ret = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
/* Output old style header */
|
2018-09-21 14:17:22 +00:00
|
|
|
table = vshTableNew(_("Name"), _("State"), _("Autostart"), NULL);
|
|
|
|
if (!table)
|
|
|
|
goto cleanup;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
/* Output old style pool info */
|
2012-09-05 06:36:33 +00:00
|
|
|
for (i = 0; i < list->npools; i++) {
|
2017-01-06 14:42:52 +00:00
|
|
|
const char *name_str = virStoragePoolGetName(list->pools[i]);
|
2018-09-21 14:17:22 +00:00
|
|
|
if (vshTableRowAppend(table,
|
|
|
|
name_str,
|
|
|
|
poolInfoTexts[i].state,
|
|
|
|
poolInfoTexts[i].autostart,
|
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:17:22 +00:00
|
|
|
vshTablePrintToStdout(table, ctl);
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
/* Cleanup and return */
|
2014-02-21 21:33:30 +00:00
|
|
|
ret = true;
|
2012-07-24 08:49:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We only get here if the --details option was selected. */
|
|
|
|
|
2018-09-21 14:17:22 +00:00
|
|
|
/* Insert the header into table */
|
|
|
|
table = vshTableNew(_("Name"), _("State"), _("Autostart"), _("Persistent"),
|
|
|
|
_("Capacity"), _("Allocation"), _("Available"), NULL);
|
|
|
|
if (!table)
|
2014-02-21 21:33:30 +00:00
|
|
|
goto cleanup;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2020-01-24 20:30:04 +00:00
|
|
|
/* Insert the pool info rows into table */
|
2012-09-05 06:36:33 +00:00
|
|
|
for (i = 0; i < list->npools; i++) {
|
2018-09-21 14:17:22 +00:00
|
|
|
if (vshTableRowAppend(table,
|
|
|
|
virStoragePoolGetName(list->pools[i]),
|
|
|
|
poolInfoTexts[i].state,
|
|
|
|
poolInfoTexts[i].autostart,
|
|
|
|
poolInfoTexts[i].persistent,
|
|
|
|
poolInfoTexts[i].capacity,
|
|
|
|
poolInfoTexts[i].allocation,
|
|
|
|
poolInfoTexts[i].available,
|
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:17:22 +00:00
|
|
|
vshTablePrintToStdout(table, ctl);
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
/* Cleanup and return */
|
2014-02-21 21:33:30 +00:00
|
|
|
ret = true;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2018-09-21 14:17:22 +00:00
|
|
|
vshTableFree(table);
|
2012-09-05 06:36:33 +00:00
|
|
|
if (list && list->npools) {
|
|
|
|
for (i = 0; i < list->npools; i++) {
|
|
|
|
VIR_FREE(poolInfoTexts[i].state);
|
|
|
|
VIR_FREE(poolInfoTexts[i].autostart);
|
|
|
|
VIR_FREE(poolInfoTexts[i].persistent);
|
|
|
|
VIR_FREE(poolInfoTexts[i].capacity);
|
|
|
|
VIR_FREE(poolInfoTexts[i].allocation);
|
|
|
|
VIR_FREE(poolInfoTexts[i].available);
|
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(poolInfoTexts);
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolListFree(list);
|
2014-02-21 21:33:30 +00:00
|
|
|
return ret;
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "find-storage-pool-sources-as" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_find_storage_pool_sources_as[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("find potential storage pool sources")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns XML <sources> document.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_find_storage_pool_sources_as[] = {
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("type of storage pool sources to find")
|
|
|
|
},
|
|
|
|
{.name = "host",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 14:36:53 +00:00
|
|
|
.help = N_("optional host to query")
|
|
|
|
},
|
|
|
|
{.name = "port",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 14:36:53 +00:00
|
|
|
.help = N_("optional port to query")
|
|
|
|
},
|
|
|
|
{.name = "initiator",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 14:36:53 +00:00
|
|
|
.help = N_("optional initiator IQN to use for query")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2019-10-14 12:44:29 +00:00
|
|
|
cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
|
2012-07-24 08:49:27 +00:00
|
|
|
{
|
|
|
|
const char *type = NULL, *host = NULL;
|
|
|
|
char *srcSpec = NULL;
|
|
|
|
char *srcList;
|
|
|
|
const char *initiator = NULL;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "host", &host) < 0 ||
|
|
|
|
vshCommandOptStringReq(ctl, cmd, "initiator", &initiator) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (host) {
|
|
|
|
const char *port = NULL;
|
2020-07-02 23:40:16 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "port", &port) < 0) {
|
2012-07-24 08:49:27 +00:00
|
|
|
vshError(ctl, "%s", _("missing argument"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virBufferAddLit(&buf, "<source>\n");
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferAsprintf(&buf, "<host name='%s'", host);
|
2012-07-24 08:49:27 +00:00
|
|
|
if (port)
|
|
|
|
virBufferAsprintf(&buf, " port='%s'", port);
|
|
|
|
virBufferAddLit(&buf, "/>\n");
|
|
|
|
if (initiator) {
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAddLit(&buf, "<initiator>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
|
|
|
virBufferAsprintf(&buf, "<iqn name='%s'/>\n", initiator);
|
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</initiator>\n");
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
2014-03-12 23:52:07 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
2012-07-24 08:49:27 +00:00
|
|
|
virBufferAddLit(&buf, "</source>\n");
|
|
|
|
srcSpec = virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(srcSpec);
|
|
|
|
if (srcList == NULL) {
|
|
|
|
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
vshPrint(ctl, "%s", srcList);
|
|
|
|
VIR_FREE(srcList);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "find-storage-pool-sources" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_find_storage_pool_sources[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("discover potential storage pool sources")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns XML <sources> document.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_find_storage_pool_sources[] = {
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = "type",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("type of storage pool sources to discover")
|
|
|
|
},
|
|
|
|
{.name = "srcSpec",
|
2014-12-11 02:46:15 +00:00
|
|
|
.type = VSH_OT_STRING,
|
2013-01-14 14:36:53 +00:00
|
|
|
.help = N_("optional file of source xml to query for pools")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
2019-10-14 12:44:29 +00:00
|
|
|
cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
|
2012-07-24 08:49:27 +00:00
|
|
|
{
|
|
|
|
const char *type = NULL, *srcSpecFile = NULL;
|
|
|
|
char *srcSpec = NULL, *srcList;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2013-01-21 14:15:01 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "srcSpec", &srcSpecFile) < 0)
|
2012-07-24 08:49:27 +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 (srcSpecFile && virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE,
|
|
|
|
&srcSpec) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0);
|
2012-07-24 08:49:27 +00:00
|
|
|
VIR_FREE(srcSpec);
|
|
|
|
if (srcList == NULL) {
|
|
|
|
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
vshPrint(ctl, "%s", srcList);
|
|
|
|
VIR_FREE(srcList);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-info" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_info[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("storage pool information")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns basic information about the storage pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_info[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2017-01-04 01:01:21 +00:00
|
|
|
{.name = "bytes",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("Reture pool info in bytes"),
|
|
|
|
},
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolInfo info;
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
int autostart = 0;
|
|
|
|
int persistent = 0;
|
|
|
|
bool ret = true;
|
2017-01-04 01:01:21 +00:00
|
|
|
bool bytes = false;
|
2012-07-24 08:49:27 +00:00
|
|
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2017-01-04 01:01:21 +00:00
|
|
|
bytes = vshCommandOptBool(cmd, "bytes");
|
|
|
|
|
2012-07-24 08:49:27 +00:00
|
|
|
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStoragePoolGetName(pool));
|
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
if (virStoragePoolGetUUIDString(pool, &uuid[0]) == 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
vshPrint(ctl, "%-15s %s\n", _("UUID:"), uuid);
|
|
|
|
|
|
|
|
if (virStoragePoolGetInfo(pool, &info) == 0) {
|
|
|
|
double val;
|
|
|
|
const char *unit;
|
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, "%-15s %s\n", _("State:"),
|
2015-06-15 16:53:58 +00:00
|
|
|
virshStoragePoolStateToString(info.state));
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
/* Check and display whether the pool is persistent or not */
|
|
|
|
persistent = virStoragePoolIsPersistent(pool);
|
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "Pool persistent flag value: %d\n",
|
|
|
|
persistent);
|
|
|
|
if (persistent < 0)
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("Persistent:"), _("unknown"));
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("Persistent:"), persistent ? _("yes") : _("no"));
|
|
|
|
|
|
|
|
/* Check and display whether the pool is autostarted or not */
|
2012-11-30 12:09:21 +00:00
|
|
|
if (virStoragePoolGetAutostart(pool, &autostart) < 0)
|
2012-07-24 08:49:27 +00:00
|
|
|
vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
|
|
|
|
else
|
|
|
|
vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
|
|
|
|
|
|
|
|
if (info.state == VIR_STORAGE_POOL_RUNNING ||
|
|
|
|
info.state == VIR_STORAGE_POOL_DEGRADED) {
|
2017-01-04 01:01:21 +00:00
|
|
|
if (bytes) {
|
|
|
|
vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity);
|
|
|
|
vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation);
|
|
|
|
vshPrint(ctl, "%-15s %llu\n", _("Available:"), info.available);
|
|
|
|
} else {
|
|
|
|
val = vshPrettyCapacity(info.capacity, &unit);
|
|
|
|
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2017-01-04 01:01:21 +00:00
|
|
|
val = vshPrettyCapacity(info.allocation, &unit);
|
|
|
|
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2017-01-04 01:01:21 +00:00
|
|
|
val = vshPrettyCapacity(info.available, &unit);
|
|
|
|
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
|
|
|
|
}
|
2012-07-24 08:49:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-name" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_name[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("convert a pool UUID to pool name")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_name[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolName(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYUUID)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-start" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_start[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("start a (previously defined) inactive pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Start a pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_start[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE),
|
2016-01-09 13:36:22 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_BUILD,
|
|
|
|
VIRSH_COMMON_OPT_POOL_NO_OVERWRITE,
|
|
|
|
VIRSH_COMMON_OPT_POOL_OVERWRITE,
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name = NULL;
|
2015-11-25 14:51:51 +00:00
|
|
|
bool build;
|
|
|
|
bool overwrite;
|
|
|
|
bool no_overwrite;
|
|
|
|
unsigned int flags = 0;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
2015-11-25 14:51:51 +00:00
|
|
|
build = vshCommandOptBool(cmd, "build");
|
|
|
|
overwrite = vshCommandOptBool(cmd, "overwrite");
|
|
|
|
no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
|
|
|
|
|
|
|
|
VSH_EXCLUSIVE_OPTIONS_EXPR("overwrite", overwrite,
|
|
|
|
"no-overwrite", no_overwrite);
|
|
|
|
|
|
|
|
if (build)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
|
|
|
|
if (overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
|
|
|
|
if (no_overwrite)
|
|
|
|
flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
|
|
|
|
|
|
|
|
if (virStoragePoolCreate(pool, flags) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s started\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to start pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-undefine" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_undefine[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("undefine an inactive pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Undefine the configuration for an inactive pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_undefine[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virStoragePoolUndefine(pool) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s has been undefined\n"), name);
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to undefine pool %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-uuid" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_uuid[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("convert a pool name to pool UUID")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = ""
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_uuid[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool;
|
|
|
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYNAME)))
|
2012-07-24 08:49:27 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virStoragePoolGetUUIDString(pool, uuid) != -1)
|
|
|
|
vshPrint(ctl, "%s\n", uuid);
|
|
|
|
else
|
|
|
|
vshError(ctl, "%s", _("failed to get pool UUID"));
|
|
|
|
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "pool-edit" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_edit[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("edit XML configuration for a storage pool")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Edit the XML configuration for a storage pool.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_edit[] = {
|
2018-01-12 13:01:33 +00:00
|
|
|
VIRSH_COMMON_OPT_POOL_FULL(0),
|
2015-11-25 14:06:33 +00:00
|
|
|
|
2013-01-14 14:36:53 +00:00
|
|
|
{.name = NULL}
|
2012-07-24 08:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
virStoragePoolPtr pool = NULL;
|
|
|
|
virStoragePoolPtr pool_edited = NULL;
|
|
|
|
unsigned int flags = VIR_STORAGE_XML_INACTIVE;
|
|
|
|
char *tmp_desc = NULL;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-24 08:49:27 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
pool = virshCommandOptPool(ctl, cmd, "pool", NULL);
|
2012-07-24 08:49:27 +00:00
|
|
|
if (pool == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Some old daemons don't support _INACTIVE flag */
|
|
|
|
if (!(tmp_desc = virStoragePoolGetXMLDesc(pool, flags))) {
|
|
|
|
if (last_error->code == VIR_ERR_INVALID_ARG) {
|
|
|
|
flags &= ~VIR_STORAGE_XML_INACTIVE;
|
2012-07-25 11:41:49 +00:00
|
|
|
vshResetLibvirtError();
|
2012-07-24 08:49:27 +00:00
|
|
|
} else {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_FREE(tmp_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags)
|
2017-11-03 12:09:47 +00:00
|
|
|
#define EDIT_NOT_CHANGED \
|
|
|
|
do { \
|
|
|
|
vshPrintExtra(ctl, _("Pool %s XML configuration not changed.\n"), \
|
|
|
|
virStoragePoolGetName(pool)); \
|
|
|
|
ret = true; \
|
|
|
|
goto edit_cleanup; \
|
2014-11-14 14:57:17 +00:00
|
|
|
} while (0)
|
2012-07-24 08:49:27 +00:00
|
|
|
#define EDIT_DEFINE \
|
2015-06-15 16:53:58 +00:00
|
|
|
(pool_edited = virStoragePoolDefineXML(priv->conn, doc_edited, 0))
|
2012-07-24 08:49:27 +00:00
|
|
|
#include "virsh-edit.c"
|
|
|
|
|
2016-11-04 14:22:26 +00:00
|
|
|
vshPrintExtra(ctl, _("Pool %s XML configuration edited.\n"),
|
|
|
|
virStoragePoolGetName(pool_edited));
|
2012-07-24 08:49:27 +00:00
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (pool)
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
if (pool_edited)
|
|
|
|
virStoragePoolFree(pool_edited);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-23 07:19:04 +00:00
|
|
|
|
2016-06-16 17:27:10 +00:00
|
|
|
/*
|
|
|
|
* "pool-event" command
|
|
|
|
*/
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virshPoolEvent);
|
2016-06-16 17:27:10 +00:00
|
|
|
VIR_ENUM_IMPL(virshPoolEvent,
|
|
|
|
VIR_STORAGE_POOL_EVENT_LAST,
|
|
|
|
N_("Defined"),
|
|
|
|
N_("Undefined"),
|
|
|
|
N_("Started"),
|
2017-09-09 15:09:49 +00:00
|
|
|
N_("Stopped"),
|
|
|
|
N_("Created"),
|
2019-01-20 16:30:15 +00:00
|
|
|
N_("Deleted"));
|
2016-06-16 17:27:10 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
virshPoolEventToString(int event)
|
|
|
|
{
|
|
|
|
const char *str = virshPoolEventTypeToString(event);
|
|
|
|
return str ? _(str) : _("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct virshPoolEventData {
|
|
|
|
vshControl *ctl;
|
|
|
|
bool loop;
|
|
|
|
bool timestamp;
|
|
|
|
int count;
|
2018-05-24 13:19:29 +00:00
|
|
|
virshPoolEventCallback *cb;
|
2016-06-16 17:27:10 +00:00
|
|
|
};
|
|
|
|
typedef struct virshPoolEventData virshPoolEventData;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2019-10-14 12:44:29 +00:00
|
|
|
vshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED,
|
2016-06-16 17:27:10 +00:00
|
|
|
virStoragePoolPtr pool,
|
|
|
|
int event,
|
2019-10-14 12:44:29 +00:00
|
|
|
int detail G_GNUC_UNUSED,
|
2016-06-16 17:27:10 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virshPoolEventData *data = opaque;
|
|
|
|
|
|
|
|
if (!data->loop && data->count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->timestamp) {
|
|
|
|
char timestamp[VIR_TIME_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (virTimeStringNowRaw(timestamp) < 0)
|
|
|
|
timestamp[0] = '\0';
|
|
|
|
|
|
|
|
vshPrint(data->ctl, _("%s: event 'lifecycle' for storage pool %s: %s\n"),
|
|
|
|
timestamp,
|
|
|
|
virStoragePoolGetName(pool),
|
|
|
|
virshPoolEventToString(event));
|
|
|
|
} else {
|
|
|
|
vshPrint(data->ctl, _("event 'lifecycle' for storage pool %s: %s\n"),
|
|
|
|
virStoragePoolGetName(pool),
|
|
|
|
virshPoolEventToString(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
2016-06-24 16:35:51 +00:00
|
|
|
static void
|
2019-10-14 12:44:29 +00:00
|
|
|
vshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED,
|
2016-06-24 16:35:51 +00:00
|
|
|
virStoragePoolPtr pool,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virshPoolEventData *data = opaque;
|
|
|
|
|
|
|
|
if (!data->loop && data->count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->timestamp) {
|
|
|
|
char timestamp[VIR_TIME_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (virTimeStringNowRaw(timestamp) < 0)
|
|
|
|
timestamp[0] = '\0';
|
|
|
|
|
2016-08-02 07:04:39 +00:00
|
|
|
vshPrint(data->ctl, _("%s: event '%s' for storage pool %s\n"),
|
2016-06-24 16:35:51 +00:00
|
|
|
timestamp,
|
|
|
|
data->cb->name,
|
|
|
|
virStoragePoolGetName(pool));
|
|
|
|
} else {
|
|
|
|
vshPrint(data->ctl, _("event '%s' for storage pool %s\n"),
|
|
|
|
data->cb->name,
|
|
|
|
virStoragePoolGetName(pool));
|
|
|
|
}
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
if (!data->loop)
|
|
|
|
vshEventDone(data->ctl);
|
|
|
|
}
|
|
|
|
|
2018-05-24 13:19:29 +00:00
|
|
|
virshPoolEventCallback virshPoolEventCallbacks[] = {
|
2016-06-24 16:35:51 +00:00
|
|
|
{ "lifecycle",
|
|
|
|
VIR_STORAGE_POOL_EVENT_CALLBACK(vshEventLifecyclePrint), },
|
|
|
|
{ "refresh", vshEventGenericPrint, }
|
|
|
|
};
|
2020-01-09 10:39:55 +00:00
|
|
|
G_STATIC_ASSERT(VIR_STORAGE_POOL_EVENT_ID_LAST == G_N_ELEMENTS(virshPoolEventCallbacks));
|
2016-06-24 16:35:51 +00:00
|
|
|
|
|
|
|
|
2016-06-16 17:27:10 +00:00
|
|
|
static const vshCmdInfo info_pool_event[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("Storage Pool Events")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("List event types, or wait for storage pool events to occur")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_event[] = {
|
|
|
|
{.name = "pool",
|
|
|
|
.type = VSH_OT_STRING,
|
|
|
|
.help = N_("filter by storage pool name or uuid")
|
|
|
|
},
|
|
|
|
{.name = "event",
|
|
|
|
.type = VSH_OT_STRING,
|
2018-05-24 13:16:26 +00:00
|
|
|
.completer = virshPoolEventNameCompleter,
|
2016-06-16 17:27:10 +00:00
|
|
|
.help = N_("which event type to wait for")
|
|
|
|
},
|
|
|
|
{.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 = "timestamp",
|
|
|
|
.type = VSH_OT_BOOL,
|
|
|
|
.help = N_("show timestamp for each printed event")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virStoragePoolPtr pool = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
int eventId = -1;
|
|
|
|
int timeout = 0;
|
|
|
|
virshPoolEventData data;
|
|
|
|
const char *eventName = NULL;
|
|
|
|
int event;
|
|
|
|
virshControlPtr priv = ctl->privData;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "list")) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++)
|
2018-05-24 13:19:29 +00:00
|
|
|
vshPrint(ctl, "%s\n", virshPoolEventCallbacks[i].name);
|
2016-06-16 17:27:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0)
|
|
|
|
return false;
|
|
|
|
if (!eventName) {
|
2016-09-06 11:14:34 +00:00
|
|
|
vshError(ctl, "%s", _("either --list or --event <type> is required"));
|
2016-06-16 17:27:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 16:35:51 +00:00
|
|
|
|
|
|
|
for (event = 0; event < VIR_STORAGE_POOL_EVENT_ID_LAST; event++)
|
2018-05-24 13:19:29 +00:00
|
|
|
if (STREQ(eventName, virshPoolEventCallbacks[event].name))
|
2016-06-24 16:35:51 +00:00
|
|
|
break;
|
|
|
|
if (event == VIR_STORAGE_POOL_EVENT_ID_LAST) {
|
2016-06-16 17:27:10 +00:00
|
|
|
vshError(ctl, _("unknown event type %s"), eventName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.ctl = ctl;
|
|
|
|
data.loop = vshCommandOptBool(cmd, "loop");
|
|
|
|
data.timestamp = vshCommandOptBool(cmd, "timestamp");
|
|
|
|
data.count = 0;
|
2018-05-24 13:19:29 +00:00
|
|
|
data.cb = &virshPoolEventCallbacks[event];
|
2016-06-16 17:27:10 +00:00
|
|
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (vshCommandOptBool(cmd, "pool"))
|
|
|
|
pool = virshCommandOptPool(ctl, cmd, "pool", NULL);
|
|
|
|
if (vshEventStart(ctl, timeout) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((eventId = virConnectStoragePoolEventRegisterAny(priv->conn, pool, event,
|
2016-06-24 16:35:51 +00:00
|
|
|
data.cb->cb,
|
2016-06-16 17:27:10 +00:00
|
|
|
&data, NULL)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
vshPrint(ctl, _("events received: %d\n"), data.count);
|
|
|
|
if (data.count)
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
vshEventCleanup(ctl);
|
|
|
|
if (eventId >= 0 &&
|
|
|
|
virConnectStoragePoolEventDeregisterAny(priv->conn, eventId) < 0)
|
|
|
|
ret = false;
|
|
|
|
if (pool)
|
|
|
|
virStoragePoolFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-07 17:02:53 +00:00
|
|
|
/*
|
|
|
|
* "pool-capabilities" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_pool_capabilities[] = {
|
|
|
|
{.name = "help",
|
|
|
|
.data = N_("storage pool capabilities")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns capabilities of storage pool support.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_pool_capabilities[] = {
|
|
|
|
{.name = NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdPoolCapabilities(vshControl *ctl,
|
2019-10-14 12:44:29 +00:00
|
|
|
const vshCmd *cmd G_GNUC_UNUSED)
|
2019-02-07 17:02:53 +00:00
|
|
|
{
|
|
|
|
const unsigned int flags = 0; /* No flags so far */
|
|
|
|
virshControlPtr priv = ctl->privData;
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *caps = NULL;
|
2019-02-07 17:02:53 +00:00
|
|
|
|
|
|
|
caps = virConnectGetStoragePoolCapabilities(priv->conn, flags);
|
|
|
|
if (!caps) {
|
|
|
|
vshError(ctl, "%s", _("failed to get storage pool capabilities"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vshPrint(ctl, "%s\n", caps);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-20 22:56:53 +00:00
|
|
|
const vshCmdDef storagePoolCmds[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "find-storage-pool-sources-as",
|
|
|
|
.handler = cmdPoolDiscoverSourcesAs,
|
|
|
|
.opts = opts_find_storage_pool_sources_as,
|
|
|
|
.info = info_find_storage_pool_sources_as,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "find-storage-pool-sources",
|
|
|
|
.handler = cmdPoolDiscoverSources,
|
|
|
|
.opts = opts_find_storage_pool_sources,
|
|
|
|
.info = info_find_storage_pool_sources,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-autostart",
|
|
|
|
.handler = cmdPoolAutostart,
|
|
|
|
.opts = opts_pool_autostart,
|
|
|
|
.info = info_pool_autostart,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-build",
|
|
|
|
.handler = cmdPoolBuild,
|
|
|
|
.opts = opts_pool_build,
|
|
|
|
.info = info_pool_build,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-create-as",
|
|
|
|
.handler = cmdPoolCreateAs,
|
2015-11-25 13:57:30 +00:00
|
|
|
.opts = opts_pool_create_as,
|
2013-02-07 15:25:10 +00:00
|
|
|
.info = info_pool_create_as,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-create",
|
|
|
|
.handler = cmdPoolCreate,
|
|
|
|
.opts = opts_pool_create,
|
|
|
|
.info = info_pool_create,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-define-as",
|
|
|
|
.handler = cmdPoolDefineAs,
|
2015-11-25 13:57:30 +00:00
|
|
|
.opts = opts_pool_define_as,
|
2013-02-07 15:25:10 +00:00
|
|
|
.info = info_pool_define_as,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-define",
|
|
|
|
.handler = cmdPoolDefine,
|
|
|
|
.opts = opts_pool_define,
|
|
|
|
.info = info_pool_define,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-delete",
|
|
|
|
.handler = cmdPoolDelete,
|
|
|
|
.opts = opts_pool_delete,
|
|
|
|
.info = info_pool_delete,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-destroy",
|
|
|
|
.handler = cmdPoolDestroy,
|
|
|
|
.opts = opts_pool_destroy,
|
|
|
|
.info = info_pool_destroy,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-dumpxml",
|
|
|
|
.handler = cmdPoolDumpXML,
|
|
|
|
.opts = opts_pool_dumpxml,
|
|
|
|
.info = info_pool_dumpxml,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-edit",
|
|
|
|
.handler = cmdPoolEdit,
|
|
|
|
.opts = opts_pool_edit,
|
|
|
|
.info = info_pool_edit,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-info",
|
|
|
|
.handler = cmdPoolInfo,
|
|
|
|
.opts = opts_pool_info,
|
|
|
|
.info = info_pool_info,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-list",
|
|
|
|
.handler = cmdPoolList,
|
|
|
|
.opts = opts_pool_list,
|
|
|
|
.info = info_pool_list,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-name",
|
|
|
|
.handler = cmdPoolName,
|
|
|
|
.opts = opts_pool_name,
|
|
|
|
.info = info_pool_name,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-refresh",
|
|
|
|
.handler = cmdPoolRefresh,
|
|
|
|
.opts = opts_pool_refresh,
|
|
|
|
.info = info_pool_refresh,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-start",
|
|
|
|
.handler = cmdPoolStart,
|
|
|
|
.opts = opts_pool_start,
|
|
|
|
.info = info_pool_start,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-undefine",
|
|
|
|
.handler = cmdPoolUndefine,
|
|
|
|
.opts = opts_pool_undefine,
|
|
|
|
.info = info_pool_undefine,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "pool-uuid",
|
|
|
|
.handler = cmdPoolUuid,
|
|
|
|
.opts = opts_pool_uuid,
|
|
|
|
.info = info_pool_uuid,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2016-06-16 17:27:10 +00:00
|
|
|
{.name = "pool-event",
|
|
|
|
.handler = cmdPoolEvent,
|
|
|
|
.opts = opts_pool_event,
|
|
|
|
.info = info_pool_event,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2019-02-07 17:02:53 +00:00
|
|
|
{.name = "pool-capabilities",
|
|
|
|
.handler = cmdPoolCapabilities,
|
|
|
|
.opts = opts_pool_capabilities,
|
|
|
|
.info = info_pool_capabilities,
|
|
|
|
.flags = 0
|
|
|
|
},
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = NULL}
|
2012-07-23 07:19:04 +00:00
|
|
|
};
|