[PATCH] storage: zfs: split pool and volume names properly

Fabian Lesniak posted 1 patch 1 year, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220601215417.4252-1-fabian@lesniak-it.de
src/storage/storage_backend_zfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
[PATCH] storage: zfs: split pool and volume names properly
Posted by Fabian Lesniak 1 year, 11 months ago
Before, the volume name was determined as the last token after any /
character. This does not work with zvols below the top level of the
pool: /dev/zvols/pool/images/vm1 is truncated to /dev/zvols/pool/vm1.
This patch removes the pool name only, so when using the pool "pool",
the volume path "images/vm1" is used.
---
 src/storage/storage_backend_zfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c
index 2a5d74357d..397ea7f386 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -104,7 +104,7 @@ virStorageBackendZFSParseVol(virStoragePoolObj *pool,
     virStorageVolDef *volume = NULL;
     virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
     g_auto(GStrv) tokens = NULL;
-    char *tmp;
+    char *pool_name = def->source.name;
 
     if (!(tokens = g_strsplit(volume_string, "\t", 0)))
         return -1;
@@ -113,8 +113,9 @@ virStorageBackendZFSParseVol(virStoragePoolObj *pool,
         goto cleanup;
 
     vol_name = tokens[0];
-    if ((tmp = strrchr(vol_name, '/')))
-        vol_name = tmp + 1;
+    if (strlen(vol_name) > strlen(pool_name) &&
+        STRPREFIX(vol_name, pool_name))
+        vol_name += strlen(pool_name) + 1;
 
     if (vol == NULL)
         volume = virStorageVolDefFindByName(pool, vol_name);
-- 
2.36.1
Re: [PATCH] storage: zfs: split pool and volume names properly
Posted by Michal Prívozník 1 year, 11 months ago
On 6/1/22 23:54, Fabian Lesniak wrote:
> Before, the volume name was determined as the last token after any /
> character. This does not work with zvols below the top level of the
> pool: /dev/zvols/pool/images/vm1 is truncated to /dev/zvols/pool/vm1.
> This patch removes the pool name only, so when using the pool "pool",
> the volume path "images/vm1" is used.
> ---
>  src/storage/storage_backend_zfs.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Hey, the patch looks okay and I'd merge it. But it's missing your
Signed-off-by line. It's a requirement per:

https://libvirt.org/hacking.html#developer-certificate-of-origin

It's okay when you reply to this e-mail with your SoB line, I'll amend it.

Michal