From nobody Mon Feb 9 07:52:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1580975644246810.4622157889778; Wed, 5 Feb 2020 23:54:04 -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-217-Q8qNphjnPSyVJD4vOOeoEA-1; Thu, 06 Feb 2020 02:52:50 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A9628024CE; Thu, 6 Feb 2020 07:52:45 +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 292AF790F5; Thu, 6 Feb 2020 07:52:45 +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 DE3691804744; Thu, 6 Feb 2020 07:52:44 +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 0167qNjZ010029 for ; Thu, 6 Feb 2020 02:52:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5E7BF1001B09; Thu, 6 Feb 2020 07:52:23 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB8921001B07 for ; Thu, 6 Feb 2020 07:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580975642; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WeAkZSFRFKeMduXbGac2LwdWD73QDC9+iDhFMFzqb90=; b=gWqoF7JZcy5gNr84md9Sl2et1FAqjg8nihrT3keXSZYVHg/bLtgphLh3JSoiICsC4sCGcH nAGJi7Wgdon6dkMkYRwlicjmLvW7hU9TJh7+tVubcWc8PmW/JgjrvEgmP7o2orLFcOQ5Jl drrZOLXnfvfvLqq22RCI4c9rWjTS9oU= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/15] conf: Implement support for of disk source Date: Thu, 6 Feb 2020 08:52:05 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.15 X-MC-Unique: Q8qNphjnPSyVJD4vOOeoEA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Implement parsing and formatting of the 'source' and 'format' slices. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c95bd34fb5..4d1bace700 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9467,6 +9467,62 @@ virDomainStorageSourceParseBase(const char *type, } +static virStorageSourceSlicePtr +virDomainStorageSourceParseSlice(xmlNodePtr node, + xmlXPathContextPtr ctxt) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt); + g_autofree char *offset =3D NULL; + g_autofree char *size =3D NULL; + g_autofree virStorageSourceSlicePtr ret =3D g_new0(virStorageSourceSli= ce, 1); + + ctxt->node =3D node; + + if (!(offset =3D virXPathString("string(./@offset)", ctxt)) || + !(size =3D virXPathString("string(./@size)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing offset or size attribute of slice")); + return NULL; + } + + if (virStrToLong_ullp(offset, NULL, 10, &ret->offset) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed value '%s' of 'offset' attribute of sl= ice"), + offset); + return NULL; + } + + if (virStrToLong_ullp(size, NULL, 10, &ret->size) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed value '%s' of 'size' attribute of slic= e"), + size); + return NULL; + } + + return g_steal_pointer(&ret); +} + + +static int +virDomainStorageSourceParseSlices(virStorageSourcePtr src, + xmlXPathContextPtr ctxt) +{ + xmlNodePtr node; + + if ((node =3D virXPathNode("./slices/slice[@type=3D'storage']", ctxt))= ) { + if (!(src->sliceStorage =3D virDomainStorageSourceParseSlice(node,= ctxt))) + return -1; + } + + if ((node =3D virXPathNode("./slices/slice[@type=3D'format']", ctxt)))= { + if (!(src->sliceFormat =3D virDomainStorageSourceParseSlice(node, = ctxt))) + return -1; + } + + return 0; +} + + /** * virDomainStorageSourceParse: * @node: XML node pointing to the source element to parse @@ -9532,6 +9588,9 @@ virDomainStorageSourceParse(xmlNodePtr node, if (virDomainDiskSourcePRParse(node, ctxt, &src->pr) < 0) return -1; + if (virDomainStorageSourceParseSlices(src, ctxt) < 0) + return -1; + if (virSecurityDeviceLabelDefParseXML(&src->seclabels, &src->nseclabel= s, ctxt, flags) < 0) return -1; @@ -24373,6 +24432,37 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr = buf, } +static void +virDomainDiskSourceFormatSlice(virBufferPtr buf, + const char *slicetype, + virStorageSourceSlicePtr slice) +{ + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + + if (!slice) + return; + + virBufferAsprintf(&attrBuf, " type=3D'%s'", slicetype); + virBufferAsprintf(&attrBuf, " offset=3D'%llu'", slice->offset); + virBufferAsprintf(&attrBuf, " size=3D'%llu'", slice->size); + + virXMLFormatElement(buf, "slice", &attrBuf, NULL); +} + + +static void +virDomainDiskSourceFormatSlices(virBufferPtr buf, + virStorageSourcePtr src) +{ + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + virDomainDiskSourceFormatSlice(&childBuf, "format", src->sliceFormat); + virDomainDiskSourceFormatSlice(&childBuf, "storage", src->sliceStorage= ); + + virXMLFormatElement(buf, "slices", NULL, &childBuf); +} + + /** * virDomainDiskSourceFormat: * @buf: output buffer @@ -24443,6 +24533,8 @@ virDomainDiskSourceFormat(virBufferPtr buf, return -1; } + virDomainDiskSourceFormatSlices(&childBuf, src); + if (src->type !=3D VIR_STORAGE_TYPE_NETWORK) virDomainSourceDefFormatSeclabel(&childBuf, src->nseclabels, src->seclabels, flags); --=20 2.24.1