From nobody Mon Feb 9 04:15:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562250626; cv=none; d=zoho.com; s=zohoarc; b=C7ZIgFeHThQ3v1q/k0tkh3XKgmbDvu3homG/dbjNh9arAGBWm7CWFB+TRVtFecL882TgZE1t2nlaUTRuW9RhOGCuMfBVutEim5LVhdh/OyDZVt9rejB3UXkOt4zLmyXtPx7tYXegGcXoIYuayW5cVK0dXltfA9sxHEE1CTC1ZFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562250626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yRHLvfOWkadjybfbM5sPkT2BABd/Cd+zrn8iI69XaWc=; b=PZbf+58gXZocpLaEKItBmvRLVp/uO1UIYAvqGxhe5gmBzQqqrdic9/84zay/Y0ruqUVswRDUqhKEckNoXZfuB5HNUSkZk4xvokMUEiMIUdRp1U2G9syKBvQ4CY6HZ3u7sKmK7HY6G0ptX/B4BfmOrSe8f0XPwwXOGltmCqft6+A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562250626759283.6230297473386; Thu, 4 Jul 2019 07:30:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26BE5307D871; Thu, 4 Jul 2019 14:30:25 +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 E6B6B79808; Thu, 4 Jul 2019 14:30:24 +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 98F641833001; Thu, 4 Jul 2019 14:30:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x64EQkeG029998 for ; Thu, 4 Jul 2019 10:26:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0AC7D5B2FE; Thu, 4 Jul 2019 14:26:46 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 647535B2D2; Thu, 4 Jul 2019 14:26:45 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 4 Jul 2019 16:26:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Kevin Wolf Subject: [libvirt] [PATCH 07/11] qemu: block: Add generator for creating storage with blockdev-create 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 04 Jul 2019 14:30:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" QEMU allows us to create storage on certain network protocols which allow image creation through their API. Wire up the generator for using it with libvirt as well as for local files. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 88 +++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 5 +++ 2 files changed, 93 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 54dd2b5328..709ed29375 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -2187,3 +2187,91 @@ qemuBlockStorageSourceCreateGetFormatProps(virStorag= eSourcePtr src, virReportEnumRangeError(virStorageFileFormat, src->format); return -1; } + + +/** + * qemuBlockStorageSourceCreateGetStorageProps: + * @src: storage source to create + * @props: filled with props to be used with 'blockdev-create' to create @= src + * + * This function should be used only if @src->type is VIR_STORAGE_TYPE_NET= WORK. + * Note that @props may be NULL if qemu does not support creation storage + * on given protocol. @src->physical is used as size for the storage. + */ +int +qemuBlockStorageSourceCreateGetStorageProps(virStorageSourcePtr src, + virJSONValuePtr *props) +{ + int actualType =3D virStorageSourceGetActualType(src); + VIR_AUTOPTR(virJSONValue) location =3D NULL; + const char *driver =3D NULL; + const char *filename =3D NULL; + + switch ((virStorageType) actualType) { + case VIR_STORAGE_TYPE_FILE: + driver =3D "file"; + filename =3D src->path; + break; + + case VIR_STORAGE_TYPE_NETWORK: + switch ((virStorageNetProtocol) src->protocol) { + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + driver =3D "gluster"; + if (!(location =3D qemuBlockStorageSourceGetGlusterProps(src, = false, false))) + return -1; + break; + + case VIR_STORAGE_NET_PROTOCOL_RBD: + driver =3D "rbd"; + if (!(location =3D qemuBlockStorageSourceGetRBDProps(src, fals= e))) + return -1; + break; + + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + driver =3D "sheepdog"; + if (!(location =3D qemuBlockStorageSourceGetSheepdogProps(src)= )) + return -1; + break; + + case VIR_STORAGE_NET_PROTOCOL_SSH: + driver =3D "ssh"; + if (!(location =3D qemuBlockStorageSourceGetSshProps(src))) + return -1; + break; + + /* unsupported/impossible */ + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_VXHS: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_NONE: + case VIR_STORAGE_NET_PROTOCOL_LAST: + return 0; + } + break; + + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + return 0; + + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_LAST: + virReportEnumRangeError(virStorageType, actualType); + return -1; + } + + if (virJSONValueObjectCreate(props, + "s:driver", driver, + "S:filename", filename, + "A:location", &location, + "u:size", src->physical, + NULL) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 738ef9e8b0..a5f6a3c75b 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -168,3 +168,8 @@ qemuBlockStorageSourceCreateGetFormatProps(virStorageSo= urcePtr src, virStorageSourcePtr backing, virJSONValuePtr *props) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; + +int +qemuBlockStorageSourceCreateGetStorageProps(virStorageSourcePtr src, + virJSONValuePtr *props) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list