mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Allow a zfs pool or dataset as source for zfs storage backend
Enables hosting a pool on an existing zfs pool without affecting other datasets there. Specify dataset instead of pool as source to use. Parent of dataset must exist for pool-build to succeed. Beware that pool-delete destroys the source dataset and all children. Solves: https://www.redhat.com/archives/libvirt-users/2017-April/msg00041.html Signed-off-by: Gregor Kopka <gregor@kopka.net> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
43b01ef2d6
commit
98f931de7c
@ -110,10 +110,10 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
|
|||||||
if (count != 3)
|
if (count != 3)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(name_tokens = virStringSplit(tokens[0], "/", 2)))
|
if (!(name_tokens = virStringSplitCount(tokens[0], "/", 0, &count)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vol_name = name_tokens[1];
|
vol_name = name_tokens[count-1];
|
||||||
|
|
||||||
if (vol == NULL)
|
if (vol == NULL)
|
||||||
volume = virStorageVolDefFindByName(pool, vol_name);
|
volume = virStorageVolDefFindByName(pool, vol_name);
|
||||||
@ -219,6 +219,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool G_GNUC_UNUSED)
|
|||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
VIR_AUTOSTRINGLIST lines = NULL;
|
VIR_AUTOSTRINGLIST lines = NULL;
|
||||||
VIR_AUTOSTRINGLIST tokens = NULL;
|
VIR_AUTOSTRINGLIST tokens = NULL;
|
||||||
|
VIR_AUTOSTRINGLIST name_tokens = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $ zpool get -Hp health,size,free,allocated test
|
* $ zpool get -Hp health,size,free,allocated test
|
||||||
@ -230,10 +231,13 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool G_GNUC_UNUSED)
|
|||||||
*
|
*
|
||||||
* Here we just provide a list of properties we want to see
|
* Here we just provide a list of properties we want to see
|
||||||
*/
|
*/
|
||||||
|
if (!(name_tokens = virStringSplit(def->source.name, "/", 0)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
cmd = virCommandNewArgList(ZPOOL,
|
cmd = virCommandNewArgList(ZPOOL,
|
||||||
"get", "-Hp",
|
"get", "-Hp",
|
||||||
"health,size,free,allocated",
|
"health,size,free,allocated",
|
||||||
def->source.name,
|
name_tokens[0],
|
||||||
NULL);
|
NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &zpool_props);
|
virCommandSetOutputBuffer(cmd, &zpool_props);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
@ -372,21 +376,28 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr pool,
|
|||||||
size_t i;
|
size_t i;
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (def->source.ndevice == 0) {
|
tmp = strstr(def->source.name, "/");
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
if (tmp) {
|
||||||
"%s", _("missing source devices"));
|
cmd = virCommandNewArgList(ZFS, "create", "-o", "mountpoint=none",
|
||||||
return -1;
|
def->source.name, NULL);
|
||||||
|
} else {
|
||||||
|
if (def->source.ndevice == 0) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
"%s", _("missing source devices"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = virCommandNewArgList(ZPOOL, "create",
|
||||||
|
def->source.name, NULL);
|
||||||
|
|
||||||
|
for (i = 0; i < def->source.ndevice; i++)
|
||||||
|
virCommandAddArg(cmd, def->source.devices[i].path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNewArgList(ZPOOL, "create",
|
|
||||||
def->source.name, NULL);
|
|
||||||
|
|
||||||
for (i = 0; i < def->source.ndevice; i++)
|
|
||||||
virCommandAddArg(cmd, def->source.devices[i].path);
|
|
||||||
|
|
||||||
virObjectUnlock(pool);
|
virObjectUnlock(pool);
|
||||||
ret = virCommandRun(cmd, NULL);
|
ret = virCommandRun(cmd, NULL);
|
||||||
virObjectLock(pool);
|
virObjectLock(pool);
|
||||||
@ -400,11 +411,18 @@ virStorageBackendZFSDeletePool(virStoragePoolObjPtr pool,
|
|||||||
{
|
{
|
||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
cmd = virCommandNewArgList(ZPOOL, "destroy",
|
tmp = strstr(def->source.name, "/");
|
||||||
def->source.name, NULL);
|
if (tmp) {
|
||||||
|
cmd = virCommandNewArgList(ZFS, "destroy", "-r",
|
||||||
|
def->source.name, NULL);
|
||||||
|
} else {
|
||||||
|
cmd = virCommandNewArgList(ZPOOL, "destroy",
|
||||||
|
def->source.name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return virCommandRun(cmd, NULL);
|
return virCommandRun(cmd, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user