提交 98f931de 编写于 作者: G Gregor Kopka 提交者: Michal Privoznik

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.htmlSigned-off-by: NGregor Kopka <gregor@kopka.net>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 43b01ef2
......@@ -110,10 +110,10 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
if (count != 3)
goto cleanup;
if (!(name_tokens = virStringSplit(tokens[0], "/", 2)))
if (!(name_tokens = virStringSplitCount(tokens[0], "/", 0, &count)))
goto cleanup;
vol_name = name_tokens[1];
vol_name = name_tokens[count-1];
if (vol == NULL)
volume = virStorageVolDefFindByName(pool, vol_name);
......@@ -219,6 +219,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool G_GNUC_UNUSED)
g_autoptr(virCommand) cmd = NULL;
VIR_AUTOSTRINGLIST lines = NULL;
VIR_AUTOSTRINGLIST tokens = NULL;
VIR_AUTOSTRINGLIST name_tokens = NULL;
/**
* $ 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
*/
if (!(name_tokens = virStringSplit(def->source.name, "/", 0)))
goto cleanup;
cmd = virCommandNewArgList(ZPOOL,
"get", "-Hp",
"health,size,free,allocated",
def->source.name,
name_tokens[0],
NULL);
virCommandSetOutputBuffer(cmd, &zpool_props);
if (virCommandRun(cmd, NULL) < 0)
......@@ -372,20 +376,27 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr pool,
size_t i;
g_autoptr(virCommand) cmd = NULL;
int ret = -1;
char *tmp;
virCheckFlags(0, -1);
if (def->source.ndevice == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("missing source devices"));
return -1;
}
tmp = strstr(def->source.name, "/");
if (tmp) {
cmd = virCommandNewArgList(ZFS, "create", "-o", "mountpoint=none",
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);
cmd = virCommandNewArgList(ZPOOL, "create",
def->source.name, NULL);
for (i = 0; i < def->source.ndevice; i++)
virCommandAddArg(cmd, def->source.devices[i].path);
for (i = 0; i < def->source.ndevice; i++)
virCommandAddArg(cmd, def->source.devices[i].path);
}
virObjectUnlock(pool);
ret = virCommandRun(cmd, NULL);
......@@ -400,11 +411,18 @@ virStorageBackendZFSDeletePool(virStoragePoolObjPtr pool,
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
g_autoptr(virCommand) cmd = NULL;
char *tmp;
virCheckFlags(0, -1);
cmd = virCommandNewArgList(ZPOOL, "destroy",
def->source.name, NULL);
tmp = strstr(def->source.name, "/");
if (tmp) {
cmd = virCommandNewArgList(ZFS, "destroy", "-r",
def->source.name, NULL);
} else {
cmd = virCommandNewArgList(ZPOOL, "destroy",
def->source.name, NULL);
}
return virCommandRun(cmd, NULL);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册