From nobody Fri May 16 12:17:32 2025 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149665486458841.395425733656; Mon, 5 Jun 2017 02:27:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4F52796E9; Mon, 5 Jun 2017 09:27:42 +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 C2FEA7E642; Mon, 5 Jun 2017 09:27:42 +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 8214E180BAFA; Mon, 5 Jun 2017 09:27:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RDn3002078 for ; Mon, 5 Jun 2017 05:27:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46D2A8A0CC; Mon, 5 Jun 2017 09:27:13 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E84158A0AC for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A88B010CCFC; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4F52796E9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E4F52796E9 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:55 +0200 Message-Id: <3359ae1ad91246a9a3c894a8ad8d5d28869bf4b9.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/15] conf: Introduce virSaveCookie 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: , MIME-Version: 1.0 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 05 Jun 2017 09:27:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The code will be used by snapshots and domain save/restore code to store additional data for a saved running domain. It is analogous to migration cookies, but simple and one way only. Signed-off-by: Jiri Denemark --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/conf/virsavecookie.c | 144 +++++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/virsavecookie.h | 62 ++++++++++++++++++++ src/libvirt_private.syms | 7 +++ 5 files changed, 215 insertions(+) create mode 100644 src/conf/virsavecookie.c create mode 100644 src/conf/virsavecookie.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 142b4d337..1ca77a4cf 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -48,6 +48,7 @@ src/conf/virinterfaceobj.c src/conf/virnetworkobj.c src/conf/virnodedeviceobj.c src/conf/virnwfilterobj.c +src/conf/virsavecookie.c src/conf/virsecretobj.c src/conf/virstorageobj.c src/cpu/cpu.c diff --git a/src/Makefile.am b/src/Makefile.am index 0b7cfc89a..eae32dc58 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -402,6 +402,7 @@ DOMAIN_CONF_SOURCES =3D \ conf/domain_conf.c conf/domain_conf.h \ conf/domain_audit.c conf/domain_audit.h \ conf/domain_nwfilter.c conf/domain_nwfilter.h \ + conf/virsavecookie.c conf/virsavecookie.h \ conf/snapshot_conf.c conf/snapshot_conf.h \ conf/numa_conf.c conf/numa_conf.h \ conf/virdomainobjlist.c conf/virdomainobjlist.h diff --git a/src/conf/virsavecookie.c b/src/conf/virsavecookie.c new file mode 100644 index 000000000..502c04d0f --- /dev/null +++ b/src/conf/virsavecookie.c @@ -0,0 +1,144 @@ +/** + * virsavecookie.c: Save cookie handling + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virerror.h" +#include "virlog.h" +#include "virobject.h" +#include "virbuffer.h" +#include "virxml.h" +#include "virsavecookie.h" + +#define VIR_FROM_THIS VIR_FROM_CONF + +VIR_LOG_INIT("conf.savecookie"); + + +static int +virSaveCookieParseNode(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + *obj =3D NULL; + + if (!xmlStrEqual(ctxt->node->name, BAD_CAST "cookie")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("XML does not contain expected 'cookie' element")= ); + return -1; + } + + if (!saveCookie || !saveCookie->parse) + return 0; + + return saveCookie->parse(ctxt, obj); +} + + +int +virSaveCookieParse(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + xmlNodePtr node =3D ctxt->node; + int ret =3D -1; + + *obj =3D NULL; + + if (!(ctxt->node =3D virXPathNode("./cookie", ctxt))) { + ret =3D 0; + goto cleanup; + } + + ret =3D virSaveCookieParseNode(ctxt, obj, saveCookie); + + cleanup: + ctxt->node =3D node; + return ret; +} + + +int +virSaveCookieParseString(const char *xml, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int ret =3D -1; + + *obj =3D NULL; + + if (!xml) { + ret =3D 0; + goto cleanup; + } + + if (!(doc =3D virXMLParseStringCtxt(xml, _("(save cookie)"), &ctxt))) + goto cleanup; + + ret =3D virSaveCookieParseNode(ctxt, obj, saveCookie); + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + return ret; +} + + +int +virSaveCookieFormatBuf(virBufferPtr buf, + virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie) +{ + if (!obj || !saveCookie || !saveCookie->format) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + if (saveCookie->format(buf, obj) < 0) + return -1; + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + +char * +virSaveCookieFormat(virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (virSaveCookieFormatBuf(&buf, obj, saveCookie) < 0) + goto error; + + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; +} diff --git a/src/conf/virsavecookie.h b/src/conf/virsavecookie.h new file mode 100644 index 000000000..4aed18466 --- /dev/null +++ b/src/conf/virsavecookie.h @@ -0,0 +1,62 @@ +/** + * virsavecookie.h: Save cookie handling + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ +#ifndef __VIR_SAVE_COOKIE_H__ +# define __VIR_SAVE_COOKIE_H__ + +# include + +# include "internal.h" +# include "virobject.h" +# include "virbuffer.h" + + +typedef int (*virSaveCookieParseFunc)(xmlXPathContextPtr ctxt, + virObjectPtr *obj); +typedef int (*virSaveCookieFormatFunc)(virBufferPtr buf, + virObjectPtr obj); + +typedef struct _virSaveCookieCallbacks virSaveCookieCallbacks; +typedef virSaveCookieCallbacks *virSaveCookieCallbacksPtr; +struct _virSaveCookieCallbacks { + virSaveCookieParseFunc parse; + virSaveCookieFormatFunc format; +}; + + +int +virSaveCookieParse(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie); + +int +virSaveCookieParseString(const char *xml, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie); + +int +virSaveCookieFormatBuf(virBufferPtr buf, + virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie); + +char * +virSaveCookieFormat(virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie); + +#endif /*__VIR_SAVE_COOKIE_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 886245c24..863c71cf3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -991,6 +991,13 @@ virNWFilterObjUnlock; virNWFilterObjWantRemoved; =20 =20 +# conf/virsavecookie.h +virSaveCookieFormat; +virSaveCookieFormatBuf; +virSaveCookieParse; +virSaveCookieParseString; + + # conf/virsecretobj.h virSecretLoadAllConfigs; virSecretObjDeleteConfig; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list