2012-07-18 19:06:58 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_sheepdog.c: storage backend for Sheepdog handling
|
|
|
|
*
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
* Copyright (C) 2013-2014 Red Hat, Inc.
|
2012-07-18 19:06:58 +00:00
|
|
|
* Copyright (C) 2012 Wido den Hollander
|
|
|
|
* Copyright (C) 2012 Frank Spijkerman
|
|
|
|
* Copyright (C) 2012 Sebastian Wiedenroth
|
|
|
|
*
|
|
|
|
* 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-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2012-07-18 19:06:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-07-18 19:06:58 +00:00
|
|
|
#include "storage_backend_sheepdog.h"
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_STORAGE_BACKEND_SHEEPDOG_PRIV_H_ALLOW
|
2017-01-16 12:41:18 +00:00
|
|
|
#include "storage_backend_sheepdog_priv.h"
|
2012-07-18 19:06:58 +00:00
|
|
|
#include "storage_conf.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2013-05-02 17:24:02 +00:00
|
|
|
#include "virstring.h"
|
2017-01-11 17:04:15 +00:00
|
|
|
#include "storage_util.h"
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
static int virStorageBackendSheepdogRefreshVol(virStoragePoolObjPtr pool,
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageVolDefPtr vol);
|
|
|
|
|
|
|
|
void virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
|
|
|
|
virStoragePoolObjPtr pool);
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
|
|
|
|
char *output)
|
|
|
|
{
|
|
|
|
/* fields:
|
|
|
|
* node id/total, size, used, use%, [total vdi size]
|
|
|
|
*
|
|
|
|
* example output:
|
|
|
|
* 0 15245667872 117571104 0%
|
|
|
|
* Total 15245667872 117571104 0% 20972341
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *p, *next;
|
|
|
|
|
|
|
|
pool->allocation = pool->capacity = pool->available = 0;
|
|
|
|
|
|
|
|
p = output;
|
|
|
|
do {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
if ((next = strchr(p, '\n')))
|
|
|
|
++next;
|
|
|
|
else
|
2013-03-05 12:28:04 +00:00
|
|
|
break;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
if (!STRPREFIX(p, "Total "))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = p + 6;
|
|
|
|
|
|
|
|
if (virStrToLong_ull(p, &end, 10, &pool->capacity) < 0)
|
2013-03-05 12:28:04 +00:00
|
|
|
break;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
if ((p = end + 1) > next)
|
2013-03-05 12:28:04 +00:00
|
|
|
break;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
if (virStrToLong_ull(p, &end, 10, &pool->allocation) < 0)
|
2013-03-05 12:28:04 +00:00
|
|
|
break;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
pool->available = pool->capacity - pool->allocation;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} while ((p = next));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
|
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2017-07-26 18:17:22 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2012-07-18 19:06:58 +00:00
|
|
|
const char *address = "localhost";
|
|
|
|
int port = 7000;
|
2017-07-26 18:17:22 +00:00
|
|
|
if (def->source.nhost > 0) {
|
|
|
|
if (def->source.hosts[0].name != NULL)
|
|
|
|
address = def->source.hosts[0].name;
|
|
|
|
if (def->source.hosts[0].port)
|
|
|
|
port = def->source.hosts[0].port;
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
virCommandAddArg(cmd, "-a");
|
|
|
|
virCommandAddArgFormat(cmd, "%s", address);
|
|
|
|
virCommandAddArg(cmd, "-p");
|
|
|
|
virCommandAddArgFormat(cmd, "%d", port);
|
|
|
|
}
|
|
|
|
|
2014-02-11 11:25:33 +00:00
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr pool, const char *diskInfo)
|
2014-02-11 11:25:33 +00:00
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virStorageVolDef) vol = NULL;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
|
|
|
if (diskInfo == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing disk info when adding volume"));
|
2019-01-31 14:44:54 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 18:41:28 +00:00
|
|
|
vol = g_new0(virStorageVolDef, 1);
|
2014-02-11 11:25:33 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
vol->name = g_strdup(diskInfo);
|
|
|
|
|
2014-02-11 11:25:33 +00:00
|
|
|
vol->type = VIR_STORAGE_VOL_NETWORK;
|
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
if (virStorageBackendSheepdogRefreshVol(pool, vol) < 0)
|
2019-01-31 14:44:54 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
2017-05-09 12:05:16 +00:00
|
|
|
if (virStoragePoolObjAddVol(pool, vol) < 0)
|
2019-01-31 14:44:54 +00:00
|
|
|
return -1;
|
|
|
|
vol = NULL;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
|
2014-02-11 11:25:33 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *output = NULL;
|
2019-02-22 14:01:02 +00:00
|
|
|
VIR_AUTOSTRINGLIST lines = NULL;
|
|
|
|
VIR_AUTOSTRINGLIST cells = NULL;
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
2019-01-31 18:16:44 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL);
|
2014-02-11 11:25:33 +00:00
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2019-01-31 17:09:38 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
|
|
|
lines = virStringSplit(output, "\n", 0);
|
|
|
|
if (lines == NULL)
|
2019-01-31 17:09:38 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
|
|
|
for (i = 0; lines[i]; i++) {
|
|
|
|
const char *line = lines[i];
|
|
|
|
if (line == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
cells = virStringSplit(line, " ", 0);
|
|
|
|
|
2016-02-09 17:18:49 +00:00
|
|
|
if (cells != NULL &&
|
|
|
|
virStringListLength((const char * const *)cells) > 2) {
|
2018-01-26 13:31:58 +00:00
|
|
|
if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0)
|
2019-01-31 17:09:38 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-02 17:36:03 +00:00
|
|
|
g_strfreev(cells);
|
2014-02-11 11:25:33 +00:00
|
|
|
cells = NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-31 17:09:38 +00:00
|
|
|
return 0;
|
2014-02-11 11:25:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool)
|
2012-07-18 19:06:58 +00:00
|
|
|
{
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *output = NULL;
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
2015-06-18 13:20:42 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
2014-02-11 11:25:33 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2019-01-31 17:09:38 +00:00
|
|
|
return -1;
|
2014-02-11 11:25:33 +00:00
|
|
|
|
2017-07-26 18:17:22 +00:00
|
|
|
if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(pool),
|
|
|
|
output) < 0)
|
2019-01-31 17:09:38 +00:00
|
|
|
return -1;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
2019-01-31 17:09:38 +00:00
|
|
|
return virStorageBackendSheepdogRefreshAllVol(pool);
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogDeleteVol(virStoragePoolObjPtr pool,
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2019-01-31 18:16:44 +00:00
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2019-01-31 18:16:44 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "delete", vol->name, NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
2019-01-31 18:16:44 +00:00
|
|
|
return virCommandRun(cmd, NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogCreateVol(virStoragePoolObjPtr pool,
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
2017-07-26 18:17:22 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
if (vol->target.encryption != NULL) {
|
2016-03-15 06:17:32 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
"%s", _("storage pool does not support encrypted "
|
|
|
|
"volumes"));
|
2012-07-18 19:06:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-11 16:04:24 +00:00
|
|
|
vol->type = VIR_STORAGE_VOL_NETWORK;
|
|
|
|
|
|
|
|
VIR_FREE(vol->key);
|
2019-10-22 13:26:14 +00:00
|
|
|
vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
|
2013-12-11 16:04:24 +00:00
|
|
|
|
|
|
|
VIR_FREE(vol->target.path);
|
2019-10-20 11:49:46 +00:00
|
|
|
vol->target.path = g_strdup(vol->name);
|
2013-12-11 16:04:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogBuildVol(virStoragePoolObjPtr pool,
|
2013-12-11 16:04:24 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2013-12-11 16:04:24 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2015-02-17 15:57:02 +00:00
|
|
|
if (!vol->target.capacity) {
|
|
|
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
|
|
|
_("volume capacity required for this pool"));
|
2019-01-31 18:16:44 +00:00
|
|
|
return -1;
|
2015-02-17 15:57:02 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 13:20:42 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "create", vol->name, NULL);
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
2019-01-31 18:16:44 +00:00
|
|
|
return virCommandRun(cmd, NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
|
|
|
|
char *output)
|
|
|
|
{
|
|
|
|
/* fields:
|
|
|
|
* current/clone/snapshot, name, id, size, used, shared, creation time, vdi id, [tag]
|
|
|
|
*
|
|
|
|
* example output:
|
|
|
|
* s test 1 10 0 0 1336556634 7c2b25
|
|
|
|
* s test 2 10 0 0 1336557203 7c2b26
|
|
|
|
* = test 3 10 0 0 1336557216 7c2b27
|
|
|
|
*/
|
|
|
|
|
|
|
|
int id;
|
|
|
|
const char *p, *next;
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
vol->target.allocation = vol->target.capacity = 0;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
p = output;
|
|
|
|
do {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
if ((next = strchr(p, '\n')))
|
|
|
|
++next;
|
|
|
|
|
|
|
|
/* ignore snapshots */
|
|
|
|
if (*p != '=')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* skip space */
|
2013-04-22 12:33:46 +00:00
|
|
|
if (p + 2 < next)
|
2012-07-18 19:06:58 +00:00
|
|
|
p += 2;
|
2013-04-22 12:33:46 +00:00
|
|
|
else
|
2012-07-18 19:06:58 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* skip name */
|
|
|
|
while (*p != '\0' && *p != ' ') {
|
|
|
|
if (*p == '\\')
|
|
|
|
++p;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_i(p, &end, 10, &id) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
p = end + 1;
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (virStrToLong_ull(p, &end, 10, &vol->target.capacity) < 0)
|
2012-07-18 19:06:58 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
p = end + 1;
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (virStrToLong_ull(p, &end, 10, &vol->target.allocation) < 0)
|
2012-07-18 19:06:58 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} while ((p = next));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogRefreshVol(virStoragePoolObjPtr pool,
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
char *output = NULL;
|
2017-07-26 18:17:22 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2017-07-26 18:17:22 +00:00
|
|
|
|
2019-01-31 18:16:44 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", vol->name, "-r", NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
|
|
|
virCommandSetOutputBuffer(cmd, &output);
|
2019-01-31 18:16:44 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
return -1;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
2019-01-31 18:16:44 +00:00
|
|
|
if (virStorageBackendSheepdogParseVdiList(vol, output) < 0)
|
|
|
|
return -1;
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
vol->type = VIR_STORAGE_VOL_NETWORK;
|
|
|
|
|
|
|
|
VIR_FREE(vol->key);
|
2019-10-22 13:26:14 +00:00
|
|
|
vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
VIR_FREE(vol->target.path);
|
2019-10-18 11:27:03 +00:00
|
|
|
vol->target.path = g_strdup(vol->name);
|
2019-01-31 18:16:44 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendSheepdogResizeVol(virStoragePoolObjPtr pool,
|
2012-07-18 19:06:58 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned long long capacity,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2019-01-31 18:16:44 +00:00
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2019-01-31 18:16:44 +00:00
|
|
|
cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "resize", vol->name, NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
virCommandAddArgFormat(cmd, "%llu", capacity);
|
|
|
|
virStorageBackendSheepdogAddHostArg(cmd, pool);
|
2019-01-31 18:16:44 +00:00
|
|
|
return virCommandRun(cmd, NULL);
|
2012-07-18 19:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virStorageBackend virStorageBackendSheepdog = {
|
|
|
|
.type = VIR_STORAGE_POOL_SHEEPDOG,
|
|
|
|
|
|
|
|
.refreshPool = virStorageBackendSheepdogRefreshPool,
|
|
|
|
.createVol = virStorageBackendSheepdogCreateVol,
|
2013-12-11 16:04:24 +00:00
|
|
|
.buildVol = virStorageBackendSheepdogBuildVol,
|
2012-07-18 19:06:58 +00:00
|
|
|
.refreshVol = virStorageBackendSheepdogRefreshVol,
|
|
|
|
.deleteVol = virStorageBackendSheepdogDeleteVol,
|
|
|
|
.resizeVol = virStorageBackendSheepdogResizeVol,
|
|
|
|
};
|
2017-01-13 15:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendSheepdogRegister(void)
|
|
|
|
{
|
|
|
|
return virStorageBackendRegister(&virStorageBackendSheepdog);
|
|
|
|
}
|