From nobody Fri Mar 29 14:44:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573099432; cv=none; d=zoho.com; s=zohoarc; b=CZYHfkHNzyHWc1hTAKEKQ/t1cjVtG6Us5daHVI0ePtL0zxbsB8s/ruXTmlxbGunYhUUM+DgpLLh2OxQsLPeDBedMgLtHIcvcsQUgZ02HP01MDnad759rZbPiqznFC6NQWVHrRVRglcjHb/bxlNypU19n+yoPvzqjvVYlLw7/6W0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573099432; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=7ttPZ6NGYMrSDVj1wbIVklOIs6NyfsBR6jN3p8IHcHU=; b=aFXZdg4lJ/YYdensNHeM7Ye5cOBvSM1qcLaUtEz9dhEUJH29jiSZKEXHB3+dTF+DXt8r5mcXp56jG1gwBoWog1R+MnoOZPO/04NbqR8BeabUmBUG7ChStH0l6O15xpUDPHCYEE6AR0YgoPsaifDw2xW6Veppu0AUjbWA11SOjG0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1573099432004992.4442603419618; Wed, 6 Nov 2019 20:03:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-C5K4FwCoPySjBLcUhAicGw-1; Wed, 06 Nov 2019 23:03:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01A3E1800D6B; Thu, 7 Nov 2019 04:03:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FBB827086; Thu, 7 Nov 2019 04:03:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 890DC18034E9; Thu, 7 Nov 2019 04:03:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xA743Xpx029333 for ; Wed, 6 Nov 2019 23:03:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4E3651001B35; Thu, 7 Nov 2019 04:03:33 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 488881001B07 for ; Thu, 7 Nov 2019 04:03:30 +0000 (UTC) Received: from earth.kopka.net (earth.kopka.net [5.9.105.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4245986662 for ; Thu, 7 Nov 2019 04:03:28 +0000 (UTC) Received: from port-92-193-64-54.dynamic.qsc.de ([92.193.64.54] helo=desk.fritz.box) by earth.kopka.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1iSZ14-0000Cp-Bw; Thu, 07 Nov 2019 04:03:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573099430; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7ttPZ6NGYMrSDVj1wbIVklOIs6NyfsBR6jN3p8IHcHU=; b=JqAjUyuLGX7FO7jcO5Rubz35/qYNqgxXr8JnJhkyViKawn5GkWrVhGOAtw5XXq9n4UeKMg QYYNqWfkiD6L8HQVdMo7m600cBeYv7Li1BGPAGPbtn6qZvUDwkKE97g7sXbl3kHy70Fq94 VnyPMgK0kv/Mls5b8SPOBAD3yl/rnhE= From: Gregor Kopka To: libvir-list@redhat.com Date: Thu, 7 Nov 2019 04:03:14 +0000 Message-Id: <20191107040314.2653-1-gregor@kopka.net> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 07 Nov 2019 04:03:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 07 Nov 2019 04:03:29 +0000 (UTC) for IP:'5.9.105.85' DOMAIN:'earth.kopka.net' HELO:'earth.kopka.net' FROM:'libvir-list@kopka.net' RCPT:'' X-RedHat-Spam-Score: -0.002 (SPF_HELO_PASS, SPF_PASS) 5.9.105.85 earth.kopka.net 5.9.105.85 earth.kopka.net X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Gregor Kopka Subject: [libvirt] [PATCH] Allow a zfs pool or dataset as source for zfs storage backend X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: C5K4FwCoPySjBLcUhAicGw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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.h= tml Signed-off-by: Gregor Kopka --- src/storage/storage_backend_zfs.c | 40 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index c3057fede6..950c5234e0 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -115,10 +115,10 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr poo= l, if (count !=3D 3) goto cleanup; =20 - if (!(name_tokens =3D virStringSplit(tokens[0], "/", 2))) + if (!(name_tokens =3D virStringSplitCount(tokens[0], "/", 0, &count))) goto cleanup; =20 - vol_name =3D name_tokens[1]; + vol_name =3D name_tokens[count-1]; =20 if (vol =3D=3D NULL) volume =3D virStorageVolDefFindByName(pool, vol_name); @@ -225,6 +225,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol G_GNUC_UNUSED) g_autoptr(virCommand) cmd =3D NULL; VIR_AUTOSTRINGLIST lines =3D NULL; VIR_AUTOSTRINGLIST tokens =3D NULL; + VIR_AUTOSTRINGLIST name_tokens =3D NULL; =20 /** * $ zpool get -Hp health,size,free,allocated test @@ -236,10 +237,13 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr = pool G_GNUC_UNUSED) * * Here we just provide a list of properties we want to see */ + if (!(name_tokens =3D virStringSplit(def->source.name, "/", 0))) + goto cleanup; + cmd =3D virCommandNewArgList(ZPOOL, "get", "-Hp", "health,size,free,allocated", - def->source.name, + name_tokens[0], NULL); virCommandSetOutputBuffer(cmd, &zpool_props); if (virCommandRun(cmd, NULL) < 0) @@ -384,20 +388,27 @@ virStorageBackendZFSBuildPool(virStoragePoolObjPtr po= ol, size_t i; g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; + char *tmp; =20 virCheckFlags(0, -1); + tmp =3D strstr(def->source.name, "/"); + if (tmp) { + cmd =3D virCommandNewArgList(ZFS, "create", "-o", "mountpoint=3Dno= ne", + def->source.name, NULL); + } else { + if (def->source.ndevice =3D=3D 0) { =20 - if (def->source.ndevice =3D=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing source devices")); - return -1; - } + return -1; + } =20 - cmd =3D virCommandNewArgList(ZPOOL, "create", + cmd =3D virCommandNewArgList(ZPOOL, "create", def->source.name, NULL); =20 - for (i =3D 0; i < def->source.ndevice; i++) - virCommandAddArg(cmd, def->source.devices[i].path); + for (i =3D 0; i < def->source.ndevice; i++) + virCommandAddArg(cmd, def->source.devices[i].path); + } =20 virObjectUnlock(pool); ret =3D virCommandRun(cmd, NULL); @@ -412,11 +423,18 @@ virStorageBackendZFSDeletePool(virStoragePoolObjPtr p= ool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); g_autoptr(virCommand) cmd =3D NULL; + char *tmp; =20 virCheckFlags(0, -1); =20 - cmd =3D virCommandNewArgList(ZPOOL, "destroy", + tmp =3D strstr(def->source.name, "/"); + if (tmp) { + cmd =3D virCommandNewArgList(ZFS, "destroy", "-r", + def->source.name, NULL); + } else { + cmd =3D virCommandNewArgList(ZPOOL, "destroy", def->source.name, NULL); + } =20 return virCommandRun(cmd, NULL); } --=20 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list