提交 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, ...@@ -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) ...@@ -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) ...@@ -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,20 +376,27 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr pool, ...@@ -372,20 +376,27 @@ 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", cmd = virCommandNewArgList(ZPOOL, "create",
def->source.name, NULL); def->source.name, NULL);
for (i = 0; i < def->source.ndevice; i++) for (i = 0; i < def->source.ndevice; i++)
virCommandAddArg(cmd, def->source.devices[i].path); virCommandAddArg(cmd, def->source.devices[i].path);
}
virObjectUnlock(pool); virObjectUnlock(pool);
ret = virCommandRun(cmd, NULL); ret = virCommandRun(cmd, NULL);
...@@ -400,11 +411,18 @@ virStorageBackendZFSDeletePool(virStoragePoolObjPtr 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);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册