From nobody Wed May 1 07:38:24 2024 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 149396540572755.749755077857344; Thu, 4 May 2017 23:23:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E95AC05973B; Fri, 5 May 2017 06:23:24 +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 12A4353C68; Fri, 5 May 2017 06:23: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 BAF6418523D4; Fri, 5 May 2017 06:23:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456MvmO021887 for ; Fri, 5 May 2017 02:22:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8BC2077C8D; Fri, 5 May 2017 06:22:57 +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 8643518653 for ; Fri, 5 May 2017 06:22:57 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 530F880C06 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456Mlh6011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6E95AC05973B Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx08.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 6E95AC05973B DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 530F880C06 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 530F880C06 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:22 +0300 Message-Id: <1493965351-117429-2-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:46 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 01/10] api: backup: add api to create backup 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 05 May 2017 06:23:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- include/libvirt/libvirt-domain-backup.h | 59 +++++++++++++++++++++++++++++= ++++ include/libvirt/libvirt.h | 1 + 2 files changed, 60 insertions(+) create mode 100644 include/libvirt/libvirt-domain-backup.h diff --git a/include/libvirt/libvirt-domain-backup.h b/include/libvirt/libv= irt-domain-backup.h new file mode 100644 index 0000000..b3bd925 --- /dev/null +++ b/include/libvirt/libvirt-domain-backup.h @@ -0,0 +1,59 @@ +/* + * libvirt-domain-backup.h + * Summary: APIs for management of domain backups + * Description: Provides APIs for the management of domain backups + * Author: Nikolay Shirokovskiy + * + * Copyright (C) 2017 Parallels International GmbH + * + * 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_LIBVIRT_DOMAIN_BACKUP_H__ +# define __VIR_LIBVIRT_DOMAIN_BACKUP_H__ + +# ifndef __VIR_LIBVIRT_H_INCLUDES__ +# error "Don't include this file directly, only use libvirt/libvirt.h" +# endif + +/** + * virDomainBackup: + * + * a virDomainBackup is a private structure representing a backup of + * a domain. + */ +typedef struct _virDomainBackup virDomainBackup; + +/** + * virDomainBackupPtr: + * + * a virDomainBackupPtr is pointer to a virDomainBackup private structure, + * and is the type used to reference a domain backup in the API. + */ +typedef virDomainBackup *virDomainBackupPtr; + +const char *virDomainBackupGetName(virDomainBackupPtr backup); +virDomainPtr virDomainBackupGetDomain(virDomainBackupPtr backup); +virConnectPtr virDomainBackupGetConnect(virDomainBackupPtr backup); + +/* Take a backup of the current VM state */ +virDomainBackupPtr virDomainBackupCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); + +int virDomainBackupRef(virDomainBackupPtr backup); +int virDomainBackupFree(virDomainBackupPtr backup); + +#endif /* __VIR_LIBVIRT_DOMAIN_BACKUP_H__ */ diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 36f6d60..be0d570 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -37,6 +37,7 @@ extern "C" { # include # include # include +# include # include # include # include --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965407547967.9158370538507; Thu, 4 May 2017 23:23:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE81B448D6F; Fri, 5 May 2017 06:23: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 9A71C779E3; Fri, 5 May 2017 06:23:25 +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 3EBE618523D9; Fri, 5 May 2017 06:23:25 +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 v456MsQs021823 for ; Fri, 5 May 2017 02:22:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 24C574FA27; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F0144FA4F for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EA8C4E357 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456Mlh7011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EE81B448D6F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx05.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 EE81B448D6F DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4EA8C4E357 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4EA8C4E357 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:23 +0300 Message-Id: <1493965351-117429-3-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:46 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:22:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:22:51 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 02/10] api: backup: add driver based implementation 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 05 May 2017 06:23:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- include/libvirt/virterror.h | 2 + src/Makefile.am | 2 + src/datatypes.c | 60 +++++++++++++ src/datatypes.h | 29 +++++++ src/driver-hypervisor.h | 5 ++ src/libvirt-domain-backup.c | 202 ++++++++++++++++++++++++++++++++++++++++= ++++ src/libvirt_private.syms | 2 + src/libvirt_public.syms | 10 +++ src/util/virerror.c | 6 ++ 9 files changed, 318 insertions(+) create mode 100644 src/libvirt-domain-backup.c diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 2efee8f..c9ae10e 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -132,6 +132,7 @@ typedef enum { =20 VIR_FROM_PERF =3D 65, /* Error from perf */ VIR_FROM_LIBSSH =3D 66, /* Error from libssh connection transpor= t */ + VIR_FROM_DOMAIN_BACKUP =3D 67,/* Error from domain backup */ =20 # ifdef VIR_ENUM_SENTINELS VIR_ERR_DOMAIN_LAST @@ -319,6 +320,7 @@ typedef enum { VIR_ERR_AGENT_UNSYNCED =3D 97, /* guest agent replies with wron= g id to guest-sync command */ VIR_ERR_LIBSSH =3D 98, /* error in libssh transport dri= ver */ + VIR_ERR_INVALID_DOMAIN_BACKUP =3D 99, /* invalid domain backup */ } virErrorNumber; =20 /** diff --git a/src/Makefile.am b/src/Makefile.am index f68fc1d..615ad60 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -288,6 +288,7 @@ DRIVER_SOURCES =3D \ libvirt.c libvirt_internal.h \ libvirt-domain.c \ libvirt-domain-snapshot.c \ + libvirt-domain-backup.c \ libvirt-host.c \ libvirt-interface.c \ libvirt-network.c \ @@ -2684,6 +2685,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ libvirt.c \ libvirt-domain.c \ libvirt-domain-snapshot.c \ + libvirt-domain-backup.c \ libvirt-host.c \ libvirt-interface.c \ libvirt-network.c \ diff --git a/src/datatypes.c b/src/datatypes.c index 59ba956..365687c 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -37,6 +37,7 @@ virClassPtr virConnectClass; virClassPtr virConnectCloseCallbackDataClass; virClassPtr virDomainClass; virClassPtr virDomainSnapshotClass; +virClassPtr virDomainBackupClass; virClassPtr virInterfaceClass; virClassPtr virNetworkClass; virClassPtr virNodeDeviceClass; @@ -50,6 +51,7 @@ static void virConnectDispose(void *obj); static void virConnectCloseCallbackDataDispose(void *obj); static void virDomainDispose(void *obj); static void virDomainSnapshotDispose(void *obj); +static void virDomainBackupDispose(void *obj); static void virInterfaceDispose(void *obj); static void virNetworkDispose(void *obj); static void virNodeDeviceDispose(void *obj); @@ -88,6 +90,7 @@ virDataTypesOnceInit(void) DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData); DECLARE_CLASS(virDomain); DECLARE_CLASS(virDomainSnapshot); + DECLARE_CLASS(virDomainBackup); DECLARE_CLASS(virInterface); DECLARE_CLASS(virNetwork); DECLARE_CLASS(virNodeDevice); @@ -891,6 +894,63 @@ virDomainSnapshotDispose(void *obj) } =20 =20 +/** + * virGetDomainBackup: + * @domain: the domain to backup + * @name: pointer to the domain backup name + * + * Allocates a new domain backup object. When the object is no longer need= ed, + * virObjectUnref() must be called in order to not leak data. + * + * Returns a pointer to the domain backup object, or NULL on error. + */ +virDomainBackupPtr +virGetDomainBackup(virDomainPtr domain, const char *name) +{ + virDomainBackupPtr ret =3D NULL; + + if (virDataTypesInitialize() < 0) + return NULL; + + virCheckDomainGoto(domain, error); + virCheckNonNullArgGoto(name, error); + + if (!(ret =3D virObjectNew(virDomainBackupClass))) + goto error; + if (VIR_STRDUP(ret->name, name) < 0) + goto error; + + ret->domain =3D virObjectRef(domain); + + return ret; + + error: + virObjectUnref(ret); + return NULL; +} + + +/** + * virDomainBackupDispose: + * @obj: the domain backup to release + * + * Unconditionally release all memory associated with a backup. + * The backup object must not be used once this method returns. + * + * It will also unreference the associated connection object, + * which may also be released if its ref count hits zero. + */ +static void +virDomainBackupDispose(void *obj) +{ + virDomainBackupPtr backup =3D obj; + VIR_DEBUG("release backup %p %s", backup, backup->name); + + VIR_FREE(backup->name); + virObjectUnref(backup->domain); +} + + virAdmConnectPtr virAdmConnectNew(void) { diff --git a/src/datatypes.h b/src/datatypes.h index 288e057..54006ef 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -32,6 +32,7 @@ extern virClassPtr virConnectClass; extern virClassPtr virDomainClass; extern virClassPtr virDomainSnapshotClass; +extern virClassPtr virDomainBackupClass; extern virClassPtr virInterfaceClass; extern virClassPtr virNetworkClass; extern virClassPtr virNodeDeviceClass; @@ -292,6 +293,21 @@ extern virClassPtr virAdmClientClass; } \ } while (0) =20 +# define virCheckDomainBackupReturn(obj, retval) \ + do { \ + virDomainBackupPtr _back =3D (obj); \ + if (!virObjectIsClass(_back, virDomainBackupClass) || \ + !virObjectIsClass(_back->domain, virDomainClass) || \ + !virObjectIsClass(_back->domain->conn, virConnectClass)) { \ + virReportErrorHelper(VIR_FROM_DOMAIN_BACKUP, \ + VIR_ERR_INVALID_DOMAIN_BACKUP, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + virDispatchError(NULL); \ + return retval; \ + } \ + } while (0) + =20 /* Helper macros to implement VIR_DOMAIN_DEBUG using just C99. This * assumes you pass fewer than 15 arguments to VIR_DOMAIN_DEBUG, but @@ -675,6 +691,17 @@ struct _virNWFilter { unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique iden= tifier */ }; =20 +/** + * _virDomainBackup + * + * Internal structure associated with a domain backup + */ +struct _virDomainBackup { + virObject object; + char *name; + virDomainPtr domain; +}; + =20 /* * Helper APIs for allocating new object instances @@ -714,6 +741,8 @@ virNWFilterPtr virGetNWFilter(virConnectPtr conn, const unsigned char *uuid); virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain, const char *name); +virDomainBackupPtr virGetDomainBackup(virDomainPtr domain, + const char *name); =20 virAdmConnectPtr virAdmConnectNew(void); =20 diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 3053d7a..9c1756f 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1263,6 +1263,10 @@ typedef int unsigned long long threshold, unsigned int flags); =20 +typedef virDomainBackupPtr +(*virDrvDomainBackupCreateXML)(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); =20 typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1504,6 +1508,7 @@ struct _virHypervisorDriver { virDrvDomainSetGuestVcpus domainSetGuestVcpus; virDrvDomainSetVcpu domainSetVcpu; virDrvDomainSetBlockThreshold domainSetBlockThreshold; + virDrvDomainBackupCreateXML domainBackupCreateXML; }; =20 =20 diff --git a/src/libvirt-domain-backup.c b/src/libvirt-domain-backup.c new file mode 100644 index 0000000..67b31c2 --- /dev/null +++ b/src/libvirt-domain-backup.c @@ -0,0 +1,202 @@ +/* + * libvirt-domain-backup.c: entry points for virDomainBackupPtr APIs + + * Copyright (C) 2017 Parallels International GmbH + * + * 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 "datatypes.h" +#include "virlog.h" + +VIR_LOG_INIT("libvirt.domain-backup"); + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_BACKUP + +/** + * virDomainBackupGetName: + * @backup: a backup object + * + * Get the public name for that backup + * + * Returns a pointer to the name or NULL, the string need not be deallocat= ed + * as its lifetime will be the same as the backup object. + */ +const char * +virDomainBackupGetName(virDomainBackupPtr backup) +{ + VIR_DEBUG("backup=3D%p", backup); + + virResetLastError(); + + virCheckDomainBackupReturn(backup, NULL); + + return backup->name; +} + + +/** + * virDomainBackupGetDomain: + * @backup: a backup object + * + * Provides the domain pointer associated with a backup. The + * reference counter on the domain is not increased by this + * call. + * + * WARNING: When writing libvirt bindings in other languages, do not use t= his + * function. Instead, store the domain and the backup object together. + * + * Returns the domain or NULL. + */ +virDomainPtr +virDomainBackupGetDomain(virDomainBackupPtr backup) +{ + VIR_DEBUG("backup=3D%p", backup); + + virResetLastError(); + + virCheckDomainBackupReturn(backup, NULL); + + return backup->domain; +} + + +/** + * virDomainBackupGetConnect: + * @backup: a backup object + * + * Provides the connection pointer associated with a backup. The + * reference counter on the connection is not increased by this + * call. + * + * WARNING: When writing libvirt bindings in other languages, do not use t= his + * function. Instead, store the connection and the backup object together. + * + * Returns the connection or NULL. + */ +virConnectPtr +virDomainBackupGetConnect(virDomainBackupPtr backup) +{ + VIR_DEBUG("backup=3D%p", backup); + + virResetLastError(); + + virCheckDomainBackupReturn(backup, NULL); + + return backup->domain->conn; +} + + +/** + * virDomainBackupCreateXML + * @domain: a domain object + * @xmlDesc: domain backup XML description + * @flags: reserved, must be 0 + * + * Starts a new backup of a domain based on the xml + * description in xmlDesc. + * + * Starts backup blockjobs for disks based onl xml description. + * Backup is finished when all the mentioned blockjobs are finished. + * + * Returns an (opaque) virDomainBackupPtr on success, NULL on failure. + */ +virDomainBackupPtr +virDomainBackupCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "xmlDesc=3D%s, flags=3D%x", xmlDesc, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(xmlDesc, error); + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->driver->domainBackupCreateXML) { + virDomainBackupPtr ret; + ret =3D conn->driver->domainBackupCreateXML(domain, xmlDesc, flags= ); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainBackupRef: + * @backup: the backup to hold a reference on + * + * Increment the reference count on the backup. For each + * additional call to this method, there shall be a corresponding + * call to virDomainBackupFree to release the reference count, once + * the caller no longer needs the reference to this object. + * + * This method is typically useful for applications where multiple + * threads are using a connection, and it is required that the + * connection and domain remain open until all threads have finished + * using the backup. ie, each new thread using a backup would + * increment the reference count. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainBackupRef(virDomainBackupPtr backup) +{ + VIR_DEBUG("backup=3D%p, refs=3D%d", backup, + backup ? backup->object.u.s.refs : 0); + + virResetLastError(); + + virCheckDomainBackupReturn(backup, -1); + + virObjectRef(backup); + return 0; +} + + +/** + * virDomainBackupFree: + * @backup: a domain backup object + * + * Free the domain backup object. The backup itself is not modified. + * The data structure is freed and should not be used thereafter. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainBackupFree(virDomainBackupPtr backup) +{ + VIR_DEBUG("backup=3D%p", backup); + + virResetLastError(); + + virCheckDomainBackupReturn(backup, -1); + + virObjectUnref(backup); + return 0; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e6901a8..fdb0106 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1067,10 +1067,12 @@ virConnectCloseCallbackDataClass; virConnectCloseCallbackDataGetCallback; virConnectCloseCallbackDataRegister; virConnectCloseCallbackDataUnregister; +virDomainBackupClass; virDomainClass; virDomainSnapshotClass; virGetConnect; virGetDomain; +virGetDomainBackup; virGetDomainSnapshot; virGetInterface; virGetNetwork; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 428cf2e..e3ee083 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -759,4 +759,14 @@ LIBVIRT_3.1.0 { virDomainSetVcpu; } LIBVIRT_3.0.0; =20 +LIBVIRT_3.4.0 { + global: + virDomainBackupRef; + virDomainBackupFree; + virDomainBackupGetName; + virDomainBackupGetDomain; + virDomainBackupGetConnect; + virDomainBackupCreateXML; +} LIBVIRT_3.1.0; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index ef17fb5..f666e6e 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -139,6 +139,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST, =20 "Perf", /* 65 */ "Libssh transport layer", + "Domain Backup", ) =20 =20 @@ -1400,6 +1401,11 @@ virErrorMsg(virErrorNumber error, const char *info) errmsg =3D _("guest agent replied with wrong id to guest-s= ync command"); else errmsg =3D _("guest agent replied with wrong id to guest-s= ync command: %s"); + case VIR_ERR_INVALID_DOMAIN_BACKUP: + if (info =3D=3D NULL) + errmsg =3D _("Invalid backup"); + else + errmsg =3D _("Invalid backup: %s"); break; case VIR_ERR_LIBSSH: if (info =3D=3D NULL) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965401230549.8867896442767; Thu, 4 May 2017 23:23:21 -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 30405C054C4C; Fri, 5 May 2017 06:23:19 +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 0B71C7FB49; Fri, 5 May 2017 06:23:19 +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 B576618523CD; Fri, 5 May 2017 06:23:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456Ms79021842 for ; Fri, 5 May 2017 02:22:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7804C18EC1; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 711411878C for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 521597AE93 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456Mlh8011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30405C054C4C Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx08.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 30405C054C4C DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 521597AE93 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 521597AE93 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:24 +0300 Message-Id: <1493965351-117429-4-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:46 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 03/10] remote: backup: add create backup implementation 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.32]); Fri, 05 May 2017 06:23:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- daemon/remote.c | 8 ++++++++ src/access/viraccessperm.c | 3 ++- src/access/viraccessperm.h | 6 ++++++ src/remote/remote_driver.c | 7 +++++++ src/remote/remote_protocol.x | 23 ++++++++++++++++++++++- src/rpc/gendispatch.pl | 29 ++++++++++++++++++++++------- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 0dbb250..6c601ff 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -101,6 +101,7 @@ static void make_nonnull_node_device(remote_nonnull_nod= e_device *dev_dst, virNod static void make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecr= etPtr secret_src); static void make_nonnull_nwfilter(remote_nonnull_nwfilter *net_dst, virNWF= ilterPtr nwfilter_src); static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *s= napshot_dst, virDomainSnapshotPtr snapshot_src); +static void make_nonnull_domain_backup(remote_nonnull_domain_backup *backu= p_dst, virDomainBackupPtr backup_src); =20 static int remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, @@ -7039,6 +7040,13 @@ make_nonnull_domain_snapshot(remote_nonnull_domain_s= napshot *snapshot_dst, virDo make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain); } =20 +static void +make_nonnull_domain_backup(remote_nonnull_domain_backup *backup_dst, virDo= mainBackupPtr backup_src) +{ + ignore_value(VIR_STRDUP_QUIET(backup_dst->name, backup_src->name)); + make_nonnull_domain(&backup_dst->dom, backup_src->domain); +} + static int remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, int nerrors, diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 0f58290..16216c0 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -43,7 +43,8 @@ VIR_ENUM_IMPL(virAccessPermDomain, "fs_trim", "fs_freeze", "block_read", "block_write", "mem_read", "open_graphics", "open_device", "screenshot", - "open_namespace", "set_time", "set_password"); + "open_namespace", "set_time", "set_password", + "backup"); =20 VIR_ENUM_IMPL(virAccessPermInterface, VIR_ACCESS_PERM_INTERFACE_LAST, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index 1817da7..06d5184 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -306,6 +306,12 @@ typedef enum { */ VIR_ACCESS_PERM_DOMAIN_SET_PASSWORD, =20 + /** + * @desc: Backup domain + * @message: Backing domain up requires authorization + */ + VIR_ACCESS_PERM_DOMAIN_BACKUP, /* Backup domain */ + VIR_ACCESS_PERM_DOMAIN_LAST, } virAccessPermDomain; =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 77250ea..86b03ec 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -148,6 +148,7 @@ static virStorageVolPtr get_nonnull_storage_vol(virConn= ectPtr conn, remote_nonnu static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_= secret secret); static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domai= n, remote_nonnull_domain_snapshot snapshot); +static virDomainBackupPtr get_nonnull_domain_backup(virDomainPtr dom, remo= te_nonnull_domain_backup backup); static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainP= tr dom_src); static void make_nonnull_network(remote_nonnull_network *net_dst, virNetwo= rkPtr net_src); static void make_nonnull_interface(remote_nonnull_interface *interface_dst= , virInterfacePtr interface_src); @@ -8133,6 +8134,11 @@ get_nonnull_domain_snapshot(virDomainPtr domain, rem= ote_nonnull_domain_snapshot return virGetDomainSnapshot(domain, snapshot.name); } =20 +static virDomainBackupPtr +get_nonnull_domain_backup(virDomainPtr dom, remote_nonnull_domain_backup b= ackup) +{ + return virGetDomainBackup(dom, backup.name); +} =20 /* Make remote_nonnull_domain and remote_nonnull_network. */ static void @@ -8434,6 +8440,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSetGuestVcpus =3D remoteDomainSetGuestVcpus, /* 2.0.0 */ .domainSetVcpu =3D remoteDomainSetVcpu, /* 3.1.0 */ .domainSetBlockThreshold =3D remoteDomainSetBlockThreshold, /* 3.2.0 */ + .domainBackupCreateXML =3D remoteDomainBackupCreateXML, /* 3.4.0 */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 87b2bd3..92bcfce 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -312,6 +312,12 @@ struct remote_nonnull_domain_snapshot { remote_nonnull_domain dom; }; =20 +/* A backup which may not be NULL. */ +struct remote_nonnull_domain_backup { + remote_nonnull_string name; + remote_nonnull_domain dom; +}; + /* A domain or network which may be NULL. */ typedef remote_nonnull_domain *remote_domain; typedef remote_nonnull_network *remote_network; @@ -2691,6 +2697,16 @@ struct remote_domain_snapshot_delete_args { unsigned int flags; }; =20 +struct remote_domain_backup_create_xml_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + unsigned int flags; +}; + +struct remote_domain_backup_create_xml_ret { + remote_nonnull_domain_backup back; +}; + struct remote_domain_open_console_args { remote_nonnull_domain dom; remote_string dev_name; @@ -6062,7 +6078,12 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_SET_BLOCK_THRESHOLD =3D 386 + REMOTE_PROC_DOMAIN_SET_BLOCK_THRESHOLD =3D 386, =20 =20 + /** + * @generate: both + * @acl: domain:backup + */ + REMOTE_PROC_DOMAIN_BACKUP_CREATE_XML =3D 387 }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 173189c..cd0ca83 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -523,6 +523,19 @@ elsif ($mode eq "server") { push(@free_list, " virObjectUnref(snapshot);\n" . " virObjectUnref(dom);"); + } elsif ($args_member =3D~ m/^remote_nonnull_domain_backup= (\S+);$/) { + push(@vars_list, "virDomainPtr dom =3D NULL"); + push(@vars_list, "virDomainBackupPtr backup =3D NULL"); + push(@getters_list, + " if (!(dom =3D get_nonnull_domain(priv->conn,= args->${1}.dom)))\n" . + " goto cleanup;\n" . + "\n" . + " if (!(backup =3D get_nonnull_domain_backup(d= om, args->${1})))\n" . + " goto cleanup;\n"); + push(@args_list, "backup"); + push(@free_list, + " virObjectUnref(backup);\n" . + " virObjectUnref(dom);"); } elsif ($args_member =3D~ m/^(?:(?:admin|remote)_string|r= emote_uuid) (\S+)<\S+>;/) { push_privconn(\@args_list); push(@args_list, "args->$1.$1_val"); @@ -665,7 +678,7 @@ elsif ($mode eq "server") { if (!$modern_ret_as_list) { push(@ret_list, "ret->$3 =3D tmp.$3;"); } - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|node_device|interface|network|storage_vol|storage_pool|doma= in_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|node_device|interface|network|storage_vol|storage_pool|doma= in_snapshot|domain_backup|domain|server|client) (\S+)<(\S+)>;/) { $modern_ret_struct_name =3D $1; $single_ret_list_error_msg_type =3D $1; $single_ret_list_name =3D $2; @@ -723,7 +736,7 @@ elsif ($mode eq "server") { $single_ret_var =3D $1; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|domain_sna= pshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|domain_sna= pshot|domain_backup) (\S+);/) { my $type_name =3D name_to_TypeName($1); =20 if ($call->{ProcName} eq "DomainCreateWithFlags") { @@ -1268,7 +1281,7 @@ elsif ($mode eq "client") { $priv_src =3D "dev->conn"; push(@args_list, "virNodeDevicePtr dev"); push(@setters_list, "args.name =3D dev->name;"); - } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|domain_snapshot) (\S+= );/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|domain_snapshot|domai= n_backup) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1276,6 +1289,8 @@ elsif ($mode eq "client") { if ($is_first_arg) { if ($name eq "domain_snapshot") { $priv_src =3D "$arg_name->domain->conn"; + } elsif ($name eq "domain_backup") { + $priv_src =3D "$arg_name->domain->conn"; } else { $priv_src =3D "$arg_name->conn"; } @@ -1461,7 +1476,7 @@ elsif ($mode eq "client") { } =20 push(@ret_list, "memcpy(result->$3, ret.$3, sizeof= (result->$3));"); - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|node_device|interface|network|storage_vol|storage_pool|doma= in_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|node_device|interface|network|storage_vol|storage_pool|doma= in_snapshot|domain_backup|domain|server|client) (\S+)<(\S+)>;/) { my $proc_name =3D name_to_TypeName($1); =20 if ($structprefix eq "admin") { @@ -1513,7 +1528,7 @@ elsif ($mode eq "client") { push(@ret_list, "VIR_FREE(ret.$1);"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|domain_sna= pshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|domain_sna= pshot|domain_backup) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1527,7 +1542,7 @@ elsif ($mode eq "client") { $single_ret_var =3D "int rv =3D -1"; $single_ret_type =3D "int"; } else { - if ($name eq "domain_snapshot") { + if ($name =3D~ m/domain_snapshot|domain_backup/) { my $dom =3D "$priv_src"; $dom =3D~ s/->conn//; push(@ret_list, "rv =3D get_nonnull_$name($dom= , ret.$arg_name);"); @@ -1863,7 +1878,7 @@ elsif ($mode eq "client") { print " }\n"; print "\n"; } elsif ($modern_ret_as_list) { - if ($modern_ret_struct_name =3D~ m/domain_snapshot|client/) { + if ($modern_ret_struct_name =3D~ m/domain_snapshot|domain_back= up|client/) { $priv_src =3D~ s/->conn//; } print " if (result) {\n"; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965400616393.1413954608729; Thu, 4 May 2017 23:23:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93C036644; Fri, 5 May 2017 06:23:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 663D24F6DF; Fri, 5 May 2017 06:23:18 +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 18C6A4ED2F; Fri, 5 May 2017 06:23:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456Mr7G021811 for ; Fri, 5 May 2017 02:22:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id B30657FB43; Fri, 5 May 2017 06:22:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC7897FB4B for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 380A8C054908 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456Mlh9011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93C036644 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx09.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 93C036644 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 380A8C054908 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 380A8C054908 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:25 +0300 Message-Id: <1493965351-117429-5-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 04/10] backup: qemu: monitor: add drive-backup command 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:23:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- src/qemu/qemu_monitor.c | 14 ++++++++++++++ src/qemu/qemu_monitor.h | 5 +++++ src/qemu/qemu_monitor_json.c | 34 ++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 5 +++++ 4 files changed, 58 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 1d40d52..934a2c8 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4316,3 +4316,17 @@ qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicI= nfoPtr info) =20 VIR_FREE(info); } + + +int +qemuMonitorDriveBackup(virJSONValuePtr actions, + const char *device, const char *target, + const char *bitmap, const char *format, + unsigned long long speed, bool reuse) +{ + VIR_DEBUG("actions=3D%p, device=3D%s, target=3D%s, bitmap=3D%s format= =3D%s speed=3D=3D%llu", + actions, device, target, bitmap, format, speed); + + return qemuMonitorJSONDriveBackup(actions, device, target, bitmap, for= mat, + speed, reuse); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 12f98be..f0196b8 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1125,4 +1125,9 @@ int qemuMonitorSetBlockThreshold(qemuMonitorPtr mon, =20 virJSONValuePtr qemuMonitorQueryNamedBlockNodes(qemuMonitorPtr mon); =20 +int qemuMonitorDriveBackup(virJSONValuePtr actions, + const char *device, const char *target, + const char *bitmap, const char *format, + unsigned long long speed, bool reuse); + #endif /* QEMU_MONITOR_H */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 0837290..b3446ee 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7647,5 +7647,39 @@ qemuMonitorJSONQueryNamedBlockNodes(qemuMonitorPtr m= on) virJSONValueFree(cmd); virJSONValueFree(reply); =20 + return ret; +} + + +int +qemuMonitorJSONDriveBackup(virJSONValuePtr actions, + const char *device, const char *target, + const char *bitmap, const char *format, + unsigned long long speed, bool reuse) +{ + int ret =3D -1; + virJSONValuePtr cmd; + + cmd =3D qemuMonitorJSONMakeCommandRaw(true, + "drive-backup", + "s:device", device, + "s:target", target, + "S:bitmap", bitmap, + "s:sync", bitmap ? "incremental" := "full", + "S:format", format, + "Y:speed", speed, + "S:mode", reuse ? "existing" : NUL= L, + NULL); + if (!cmd) + return -1; + + if (virJSONValueArrayAppend(actions, cmd) < 0) + goto cleanup; + + ret =3D 0; + cmd =3D NULL; + + cleanup: + virJSONValueFree(cmd); return ret; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index d090d57..24c4fba 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -522,4 +522,9 @@ int qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon, virJSONValuePtr qemuMonitorJSONQueryNamedBlockNodes(qemuMonitorPtr mon) ATTRIBUTE_NONNULL(1); =20 +int qemuMonitorJSONDriveBackup(virJSONValuePtr actions, + const char *device, const char *target, + const char *bitmap, const char *format, + unsigned long long speed, bool reuse) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); #endif /* QEMU_MONITOR_JSON_H */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965400149310.41653779967544; Thu, 4 May 2017 23:23:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 875E1770C; Fri, 5 May 2017 06:23:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FF5D77CA5; Fri, 5 May 2017 06:23:18 +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 1653F4ED27; Fri, 5 May 2017 06:23:18 +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 v456Ms17021824 for ; Fri, 5 May 2017 02:22:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 241EC4FA08; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EFCC4FA4E for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 636EE61BA9 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhA011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 875E1770C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx09.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 875E1770C DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 636EE61BA9 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 636EE61BA9 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:26 +0300 Message-Id: <1493965351-117429-6-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:50 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 05/10] backup: misc: add backup block job type 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:23:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- examples/object-events/event-test.c | 3 +++ include/libvirt/libvirt-domain.h | 3 +++ src/conf/domain_conf.c | 2 +- src/qemu/qemu_monitor_json.c | 2 ++ tools/virsh-domain.c | 3 ++- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index 12690ca..592df09 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -877,6 +877,9 @@ blockJobTypeToStr(int type) =20 case VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT: return "active layer block commit"; + + case VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP: + return "block backup"; } =20 return "unknown"; diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index c9e96a6..1501405 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2325,6 +2325,9 @@ typedef enum { /* Active Block Commit (virDomainBlockCommit with flags), job * exists as long as sync is active */ =20 + VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP =3D 5, + /* Block Backup */ + # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_BLOCK_JOB_TYPE_LAST # endif diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0ff216e..5179527 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -863,7 +863,7 @@ VIR_ENUM_IMPL(virDomainLoader, * XML (remaining types are not two-phase). */ VIR_ENUM_DECL(virDomainBlockJob) VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, - "", "", "copy", "", "active-commit") + "", "", "copy", "", "active-commit", "") =20 VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index b3446ee..5ca0b19 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -885,6 +885,8 @@ qemuMonitorJSONHandleBlockJobImpl(qemuMonitorPtr mon, type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT; else if (STREQ(type_str, "mirror")) type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; + else if (STREQ(type_str, "backup")) + type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP; =20 switch ((virConnectDomainEventBlockJobStatus) event) { case VIR_DOMAIN_BLOCK_JOB_COMPLETED: diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0d19d0e..d18e1f9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2454,7 +2454,8 @@ VIR_ENUM_IMPL(virshDomainBlockJob, N_("Block Pull"), N_("Block Copy"), N_("Block Commit"), - N_("Active Block Commit")) + N_("Active Block Commit"), + N_("Block Backup")) =20 static const char * virshDomainBlockJobToString(int type) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965403867435.4875614709748; Thu, 4 May 2017 23:23:23 -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 81957C054C5C; Fri, 5 May 2017 06:23:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F15C5C546; Fri, 5 May 2017 06:23:22 +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 E51F95EC66; Fri, 5 May 2017 06:23:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456Msdu021822 for ; Fri, 5 May 2017 02:22:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23F1D77C8D; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E4AA18653 for ; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B7374E047 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhB011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 81957C054C5C Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx08.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 81957C054C5C DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B7374E047 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6B7374E047 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:27 +0300 Message-Id: <1493965351-117429-7-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:22:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 May 2017 06:22:51 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 06/10] conf: backup: add backup xml definition 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 05 May 2017 06:23:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Backup xml description is like this: backup name - element is optional. - disk @type attribute is optional, default to 'file'. Valid values are 'file', 'block', 'dir', 'network', 'volume' just as usual for specifing domain disk sources. It specifies backup type. - element has same attributes and its values as element in domain disk description. - target @format attribute is optional. If it is not specified then hypervisor will choose format by its default rule (for qemu it same format as disk to be backed up). Elements that are not explicitly mentioned as optional are mandatory. Current description does not support implicitly specified disks to be backed up like snapshot xml description for example. --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/conf/backup_conf.c | 267 +++++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/backup_conf.h | 65 ++++++++++++ src/libvirt_private.syms | 6 ++ src/qemu/qemu_conf.h | 1 + 6 files changed, 341 insertions(+) create mode 100644 src/conf/backup_conf.c create mode 100644 src/conf/backup_conf.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 5077857..cb9831e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -20,6 +20,7 @@ src/bhyve/bhyve_driver.c src/bhyve/bhyve_monitor.c src/bhyve/bhyve_parse_command.c src/bhyve/bhyve_process.c +src/conf/backup_conf.c src/conf/capabilities.c src/conf/cpu_conf.c src/conf/device_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index 615ad60..5b14826 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -404,6 +404,7 @@ DOMAIN_CONF_SOURCES =3D \ conf/domain_audit.c conf/domain_audit.h \ conf/domain_nwfilter.c conf/domain_nwfilter.h \ conf/snapshot_conf.c conf/snapshot_conf.h \ + conf/backup_conf.c conf/backup_conf.h \ conf/numa_conf.c conf/numa_conf.h \ conf/virdomainobjlist.c conf/virdomainobjlist.h =20 diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c new file mode 100644 index 0000000..a5bd995 --- /dev/null +++ b/src/conf/backup_conf.c @@ -0,0 +1,267 @@ +/* + * backup_conf.c: domain backup XML processing + * + * Copyright (C) 2017 Parallels International GmbH + * + * 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 +#include +#include +#include + +#include "internal.h" +#include "virbitmap.h" +#include "virbuffer.h" +#include "count-one-bits.h" +#include "datatypes.h" +#include "domain_conf.h" +#include "virlog.h" +#include "viralloc.h" +#include "netdev_bandwidth_conf.h" +#include "netdev_vport_profile_conf.h" +#include "nwfilter_conf.h" +#include "secret_conf.h" +#include "backup_conf.h" +#include "virstoragefile.h" +#include "viruuid.h" +#include "virfile.h" +#include "virerror.h" +#include "virxml.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_BACKUP + +VIR_LOG_INIT("conf.backup_conf"); + + +/* Backup Def functions */ +static void +virDomainBackupDiskDefClear(virDomainBackupDiskDefPtr disk) +{ + VIR_FREE(disk->name); + virStorageSourceFree(disk->target); + disk->target =3D NULL; +} + + +static int +virDomainBackupDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainBackupDiskDefPtr def) +{ + int ret =3D -1; + char *type =3D NULL; + char *format =3D NULL; + xmlNodePtr cur; + xmlNodePtr saved =3D ctxt->node; + virStorageSourcePtr target; + + ctxt->node =3D node; + + if (!(def->name =3D virXMLPropString(node, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing name from disk backup element")); + goto cleanup; + } + + if (!(cur =3D virXPathNode("./target", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, + _("missing target for disk '%s'"), def->name); + goto cleanup; + } + + if (VIR_ALLOC(def->target) < 0) + goto cleanup; + target =3D def->target; + + if ((type =3D virXMLPropString(node, "type"))) { + if ((target->type =3D virStorageTypeFromString(type)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown disk '%s' backup type '%s'"), + def->name, type); + goto cleanup; + } + } else { + target->type =3D VIR_STORAGE_TYPE_FILE; + } + + if (virDomainDiskSourceParse(cur, ctxt, target) < 0) + goto cleanup; + + if ((format =3D virXPathString("string(./target/@format)", ctxt)) && + (target->format =3D virStorageFileFormatTypeFromString(format)) <= =3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown disk '%s' backup format '%s'"), + def->name, format); + goto cleanup; + } + + if (virStorageSourceIsLocalStorage(def->target)) { + if (!target->path) { + virReportError(VIR_ERR_XML_ERROR, + _("disk '%s' backup path is not specified"), + def->name); + goto cleanup; + } + if (target->path[0] !=3D '/') { + virReportError(VIR_ERR_XML_ERROR, + _("disk '%s' backup path '%s' must be absolute"= ), + def->name, target->path); + goto cleanup; + } + } + + ret =3D 0; + cleanup: + ctxt->node =3D saved; + + VIR_FREE(format); + VIR_FREE(type); + if (ret < 0) + virDomainBackupDiskDefClear(def); + + return ret; +} + + +static virDomainBackupDefPtr +virDomainBackupDefParse(xmlXPathContextPtr ctxt, + virCapsPtr caps ATTRIBUTE_UNUSED, + virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, + unsigned int fflags ATTRIBUTE_UNUSED) +{ + virDomainBackupDefPtr def; + virDomainBackupDefPtr ret =3D NULL; + xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + struct timeval tv; + + if (VIR_ALLOC(def) < 0) + return NULL; + + gettimeofday(&tv, NULL); + + if (!(def->name =3D virXPathString("string(./name)", ctxt)) && + virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + + def->description =3D virXPathString("string(./description)", ctxt); + def->creationTime =3D tv.tv_sec; + + if ((n =3D virXPathNodeSet("./disk", ctxt, &nodes)) < 0) + goto cleanup; + + if (n =3D=3D 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("no disk is specified to be backed up")); + goto cleanup; + } + + if (VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + def->ndisks =3D n; + + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainBackupDiskDefParseXML(nodes[i], ctxt, &def->disks[i])= < 0) + goto cleanup; + } + + ret =3D def; + def =3D NULL; + + cleanup: + VIR_FREE(nodes); + virDomainBackupDefFree(def); + + return ret; +} + + +virDomainBackupDefPtr +virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainBackupDefPtr def =3D NULL; + + if (!xmlStrEqual(root->name, BAD_CAST "domainbackup")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainBackupDefParse(ctxt, caps, xmlopt, flags); + + cleanup: + xmlXPathFreeContext(ctxt); + + return def; +} + + +virDomainBackupDefPtr +virDomainBackupDefParseString(const char *xmlStr, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainBackupDefPtr ret =3D NULL; + xmlDocPtr xml; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)")))) { + xmlKeepBlanksDefault(keepBlanksDefault); + ret =3D virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml), + caps, xmlopt, flags); + xmlFreeDoc(xml); + } + xmlKeepBlanksDefault(keepBlanksDefault); + + return ret; +} + + +void +virDomainBackupDefFree(virDomainBackupDefPtr def) +{ + size_t i; + + if (!def) + return; + + VIR_FREE(def->name); + VIR_FREE(def->description); + + for (i =3D 0; i < def->ndisks; i++) + virDomainBackupDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); + + VIR_FREE(def); +} diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h new file mode 100644 index 0000000..6f689e3 --- /dev/null +++ b/src/conf/backup_conf.h @@ -0,0 +1,65 @@ +/* + * backup_conf.h: domain backup XML processing + * + * Copyright (C) 2017 Parallels International GmbH + * + * 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 __BACKUP_CONF_H +# define __BACKUP_CONF_H + +# include "internal.h" +# include "domain_conf.h" + +/* Items related to backup state */ + +/* Stores disk-backup information */ +typedef struct _virDomainBackupDiskDef virDomainBackupDiskDef; +typedef virDomainBackupDiskDef *virDomainBackupDiskDefPtr; +struct _virDomainBackupDiskDef { + char *name; /* name matching the ndisks */ + virDomainBackupDiskDef *disks; +}; + +virDomainBackupDefPtr +virDomainBackupDefParseString(const char *xmlStr, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +virDomainBackupDefPtr +virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +void +virDomainBackupDefFree(virDomainBackupDefPtr def); + +#endif /* __BACKUP_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fdb0106..e2ffc91 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -42,6 +42,12 @@ virAccessPermStorageVolTypeFromString; virAccessPermStorageVolTypeToString; =20 =20 +# conf/backup_conf.h +virDomainBackupDefFree; +virDomainBackupDefParseNode; +virDomainBackupDefParseString; + + # conf/capabilities.h virCapabilitiesAddGuest; virCapabilitiesAddGuestDomain; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 1407eef..0626729 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -32,6 +32,7 @@ # include "network_conf.h" # include "domain_conf.h" # include "snapshot_conf.h" +# include "backup_conf.h" # include "domain_event.h" # include "virthread.h" # include "security/security_manager.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965412002418.981796660897; Thu, 4 May 2017 23:23:32 -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 649D03B709; Fri, 5 May 2017 06:23:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418A47FB5E; Fri, 5 May 2017 06:23:29 +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 0112F5EC68; Fri, 5 May 2017 06:23:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456MsAq021843 for ; Fri, 5 May 2017 02:22:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 786FB18EC4; Fri, 5 May 2017 06:22:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7120718C7B for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69DE13DD47 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhC011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 649D03B709 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx06.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 649D03B709 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69DE13DD47 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69DE13DD47 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:28 +0300 Message-Id: <1493965351-117429-8-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:46 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 07/10] qemu: backup: add qemuDomainBackupCreateXML implementation 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.30]); Fri, 05 May 2017 06:23:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Supported options - backup to file or block device - specify format of backup --- src/conf/backup_conf.c | 32 ++++++++++++++ src/conf/backup_conf.h | 5 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 112 +++++++++++++++++++++++++++++++++++++++++++= +++- 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index a5bd995..49f1370 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -265,3 +265,35 @@ virDomainBackupDefFree(virDomainBackupDefPtr def) =20 VIR_FREE(def); } + + +int +virDomainBackupDefResolveDisks(virDomainBackupDefPtr def, + virDomainDefPtr vmdef) +{ + int ret =3D -1; + size_t i, j; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDefPtr disk =3D &def->disks[i]; + + for (j =3D 0; j < i; j++) { + if (STREQ(def->disks[j].name, disk->name)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' specified twice"), disk->name); + goto cleanup; + } + } + + if (!(disk->vmdisk =3D virDomainDiskByName(vmdef, disk->name, fals= e))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("no disk named '%s'"), disk->name); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + return ret; +} diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h index 6f689e3..ae7411e 100644 --- a/src/conf/backup_conf.h +++ b/src/conf/backup_conf.h @@ -33,6 +33,7 @@ typedef virDomainBackupDiskDef *virDomainBackupDiskDefPtr; struct _virDomainBackupDiskDef { char *name; /* name matching the conn->privateData; + qemuDomainObjPrivatePtr priv; + virDomainBackupDefPtr def =3D NULL; + virDomainBackupPtr backup =3D NULL; + virDomainBackupPtr ret =3D NULL; + virJSONValuePtr actions =3D NULL; + virDomainObjPtr vm =3D NULL; + char *path =3D NULL, *device =3D NULL; + bool job =3D false; + int rc; + size_t i; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainBackupCreateXMLEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (!(def =3D virDomainBackupDefParseString(xmlDesc, NULL, NULL, 0))) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + job =3D true; + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("backing up inactive domains is not support= ed")); + goto cleanup; + } + + if (virDomainBackupDefResolveDisks(def, vm->def) < 0) + goto cleanup; + + if (!(actions =3D virJSONValueNewArray())) + goto cleanup; + + for (i =3D 0; i < def->ndisks; i++) { + virStorageSourcePtr target =3D def->disks[i].target; + virDomainDiskDefPtr disk =3D def->disks[i].vmdisk; + const char *format_str =3D NULL; + + if (target->type !=3D VIR_STORAGE_TYPE_FILE && + target->type !=3D VIR_STORAGE_TYPE_BLOCK) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' backup type '%s' is not supported"= ), + def->disks[i].name, + virStorageTypeToString(target->type)); + goto cleanup; + } + + if (qemuDomainDiskBlockJobIsActive(disk)) + goto cleanup; + + if (qemuGetDriveSourceString(target, NULL, &path) < 0) + goto cleanup; + + if (!(device =3D qemuAliasFromDisk(disk))) + goto cleanup; + + if (target->format) + format_str =3D virStorageFileFormatTypeToString(target->format= ); + + if (qemuMonitorDriveBackup(actions, device, path, NULL, format_str= , 0, + false) < 0) + goto cleanup; + + VIR_FREE(path); + VIR_FREE(device); + } + + priv =3D vm->privateData; + if (!(backup =3D virGetDomainBackup(domain, def->name))) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorTransaction(priv->mon, actions); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + + ret =3D backup; + backup =3D NULL; + + for (i =3D 0; i < def->ndisks; i++) + QEMU_DOMAIN_DISK_PRIVATE(def->disks->vmdisk)->blockjob =3D true; + + cleanup: + if (job) + qemuDomainObjEndJob(driver, vm); + + VIR_FREE(path); + VIR_FREE(device); + + virDomainBackupDefFree(def); + virJSONValueFree(actions); + virDomainObjEndAPI(&vm); + virObjectUnref(backup); + + return ret; +} + + static virHypervisorDriver qemuHypervisorDriver =3D { .name =3D QEMU_DRIVER_NAME, .connectOpen =3D qemuConnectOpen, /* 0.2.0 */ @@ -20663,7 +20772,8 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainGetGuestVcpus =3D qemuDomainGetGuestVcpus, /* 2.0.0 */ .domainSetGuestVcpus =3D qemuDomainSetGuestVcpus, /* 2.0.0 */ .domainSetVcpu =3D qemuDomainSetVcpu, /* 3.1.0 */ - .domainSetBlockThreshold =3D qemuDomainSetBlockThreshold /* 3.2.0 */ + .domainSetBlockThreshold =3D qemuDomainSetBlockThreshold, /* 3.2.0 */ + .domainBackupCreateXML =3D qemuDomainBackupCreateXML, /* 3.4.0 */ }; =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965381345443.4882279984547; Thu, 4 May 2017 23:23:01 -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 9B3793D95E; Fri, 5 May 2017 06:22:59 +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 29557171EE; Fri, 5 May 2017 06:22:59 +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 2F4C018523CC; Fri, 5 May 2017 06:22:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456Mril021807 for ; Fri, 5 May 2017 02:22:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B42377C8D; Fri, 5 May 2017 06:22:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75CFE18653 for ; Fri, 5 May 2017 06:22:51 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00141757E4 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhD011727 for ; Fri, 5 May 2017 09:22:47 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9B3793D95E Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx06.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 9B3793D95E DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00141757E4 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00141757E4 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:29 +0300 Message-Id: <1493965351-117429-9-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 68:15:46 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 08/10] qemu: backup: check backup destination before start 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 05 May 2017 06:23:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If backup target is file then check it is not present or regular empty file otherwise. If backup target is block device then check that it is present and block device actually. --- src/qemu/qemu_driver.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 73 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 91bad28..dd1cf6a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20449,6 +20449,76 @@ qemuDomainSetBlockThreshold(virDomainPtr dom, } =20 =20 +static int +qemuDomainBackupCheckTarget(virDomainBackupDiskDefPtr disk) +{ + int ret =3D -1; + struct stat st; + virStorageSourcePtr target =3D disk->target; + + if (virStorageFileInit(target) < 0) + return -1; + + if (virStorageFileStat(target, &st) < 0) { + if (errno !=3D ENOENT) { + virReportSystemError(errno, + _("unable to stat target path '%s' for di= sk '%s'"), + target->path, disk->name); + goto cleanup; + } + switch (target->type) { + case VIR_STORAGE_TYPE_FILE: + break; + + case VIR_STORAGE_TYPE_BLOCK: + virReportError(VIR_ERR_INVALID_ARG, + _("missing target block device '%s' for disk '%= s'"), + target->path, disk->name); + goto cleanup; + + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected backup target type '%s' for disk = '%s'"), + virStorageTypeToString(target->type), + disk->name); + goto cleanup; + } + } else { + switch (target->type) { + case VIR_STORAGE_TYPE_FILE: + if (!S_ISREG(st.st_mode) || st.st_size > 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid existing target file '%s' for di= sk '%s'"), + target->path, disk->name); + goto cleanup; + } + break; + + case VIR_STORAGE_TYPE_BLOCK: + if (!S_ISBLK(st.st_mode)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("target file '%s' for disk '%s' is not a = block device"), + target->path, disk->name); + goto cleanup; + } + break; + + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected backup target type '%s' for disk = '%s'"), + virStorageTypeToString(target->type), disk->nam= e); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virStorageFileDeinit(target); + return ret; +} + + static virDomainBackupPtr qemuDomainBackupCreateXML(virDomainPtr domain, const char *xmlDesc, @@ -20510,6 +20580,9 @@ qemuDomainBackupCreateXML(virDomainPtr domain, if (qemuDomainDiskBlockJobIsActive(disk)) goto cleanup; =20 + if (qemuDomainBackupCheckTarget(&def->disks[i]) < 0) + goto cleanup; + if (qemuGetDriveSourceString(target, NULL, &path) < 0) goto cleanup; =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965380855153.7963289808822; Thu, 4 May 2017 23:23:00 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 260EA61BB8; Fri, 5 May 2017 06:22:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 665E977C9B; Fri, 5 May 2017 06:22:58 +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 31EE94EBD7; Fri, 5 May 2017 06:22:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456Mrq0021810 for ; Fri, 5 May 2017 02:22:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id B309A7FB44; Fri, 5 May 2017 06:22:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC29A7FB49 for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 995B261BB8 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhE011727 for ; Fri, 5 May 2017 09:22:48 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 260EA61BB8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx10.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 260EA61BB8 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 995B261BB8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 995B261BB8 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:30 +0300 Message-Id: <1493965351-117429-10-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 09/10] qemu: backup: prepare backup destination 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 May 2017 06:22:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Prepare here is usual preparation for a disk to be used by qemu made by qemuDomainDiskChainElementPrepare. That is set security labels, add to lock manager and whitelist in cgroups. All three are related to backup target too. Adding to a lock manager is less obvious but can be useful if mirations with a running backup will be possible. Also create file in case of backup to file if it is not exist in order to set securitly labels etc. --- src/qemu/qemu_driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index dd1cf6a..68747f1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20449,8 +20449,17 @@ qemuDomainSetBlockThreshold(virDomainPtr dom, } =20 =20 +typedef struct _qemuDomainBackupDiskTrackInfo qemuDomainBackupDiskTrackInf= o; +typedef qemuDomainBackupDiskTrackInfo *qemuDomainBackupDiskTrackInfoPtr; +struct _qemuDomainBackupDiskTrackInfo { + bool created; + bool prepared; +}; + + static int -qemuDomainBackupCheckTarget(virDomainBackupDiskDefPtr disk) +qemuDomainBackupCheckTarget(virDomainBackupDiskDefPtr disk, + bool *created) { int ret =3D -1; struct stat st; @@ -20468,6 +20477,12 @@ qemuDomainBackupCheckTarget(virDomainBackupDiskDef= Ptr disk) } switch (target->type) { case VIR_STORAGE_TYPE_FILE: + if (virStorageFileCreate(target) < 0) { + virReportSystemError(errno, _("failed to create image file= '%s'"), + target->path); + goto cleanup; + } + *created =3D true; break; =20 case VIR_STORAGE_TYPE_BLOCK: @@ -20519,6 +20534,22 @@ qemuDomainBackupCheckTarget(virDomainBackupDiskDef= Ptr disk) } =20 =20 +static void +qemuDomainBackupDiskUnlink(virDomainBackupDiskDefPtr disk) +{ + virStorageSourcePtr target =3D disk->target; + + if (virStorageFileInit(target) < 0) + return; + + if (virStorageFileUnlink(target) < 0) + VIR_WARN("unable to unlink target path '%s' for disk '%s', errno: = %d", + target->path, disk->name, errno); + + virStorageFileDeinit(target); +} + + static virDomainBackupPtr qemuDomainBackupCreateXML(virDomainPtr domain, const char *xmlDesc, @@ -20531,6 +20562,7 @@ qemuDomainBackupCreateXML(virDomainPtr domain, virDomainBackupPtr ret =3D NULL; virJSONValuePtr actions =3D NULL; virDomainObjPtr vm =3D NULL; + qemuDomainBackupDiskTrackInfoPtr track_disks =3D NULL; char *path =3D NULL, *device =3D NULL; bool job =3D false; int rc; @@ -20563,6 +20595,9 @@ qemuDomainBackupCreateXML(virDomainPtr domain, if (!(actions =3D virJSONValueNewArray())) goto cleanup; =20 + if (VIR_ALLOC_N(track_disks, def->ndisks) < 0) + goto cleanup; + for (i =3D 0; i < def->ndisks; i++) { virStorageSourcePtr target =3D def->disks[i].target; virDomainDiskDefPtr disk =3D def->disks[i].vmdisk; @@ -20580,9 +20615,15 @@ qemuDomainBackupCreateXML(virDomainPtr domain, if (qemuDomainDiskBlockJobIsActive(disk)) goto cleanup; =20 - if (qemuDomainBackupCheckTarget(&def->disks[i]) < 0) + if (qemuDomainBackupCheckTarget(&def->disks[i], + &track_disks[i].created) < 0) goto cleanup; =20 + if (qemuDomainDiskChainElementPrepare(driver, vm, def->disks[i].ta= rget, + false) < 0) + goto cleanup; + track_disks[i].prepared =3D true; + if (qemuGetDriveSourceString(target, NULL, &path) < 0) goto cleanup; =20 @@ -20616,11 +20657,24 @@ qemuDomainBackupCreateXML(virDomainPtr domain, QEMU_DOMAIN_DISK_PRIVATE(def->disks->vmdisk)->blockjob =3D true; =20 cleanup: + if (!ret && track_disks) { + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDefPtr backup_disk =3D &def->disks[i]; + + if (track_disks[i].prepared) + qemuDomainDiskChainElementRevoke(driver, vm, + backup_disk->target); + if (track_disks[i].created) + qemuDomainBackupDiskUnlink(backup_disk); + } + } + if (job) qemuDomainObjEndJob(driver, vm); =20 VIR_FREE(path); VIR_FREE(device); + VIR_FREE(track_disks); =20 virDomainBackupDefFree(def); virJSONValueFree(actions); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 07:38:24 2024 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 1493965404460524.48134685568; Thu, 4 May 2017 23:23:24 -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 1E005C04B948; Fri, 5 May 2017 06:23:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA157171EE; Fri, 5 May 2017 06:23:22 +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 A81D45EC66; Fri, 5 May 2017 06:23:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v456MtWk021856 for ; Fri, 5 May 2017 02:22:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C8E281881; Fri, 5 May 2017 06:22:55 +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 13D8181B40 for ; Fri, 5 May 2017 06:22:52 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A402E80C04 for ; Fri, 5 May 2017 06:22:49 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v456MlhF011727 for ; Fri, 5 May 2017 09:22:48 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1E005C04B948 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx07.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 1E005C04B948 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A402E80C04 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A402E80C04 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 5 May 2017 09:22:31 +0300 Message-Id: <1493965351-117429-11-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1493965351-117429-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 May 2017 06:22:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 May 2017 06:22:50 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH REBASE 10/10] virsh: backup: add backup-create command 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 05 May 2017 06:23:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- po/POTFILES.in | 1 + tools/Makefile.am | 1 + tools/virsh-backup.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-backup.h | 29 +++++++++++++++ tools/virsh-util.c | 11 ++++++ tools/virsh-util.h | 3 ++ tools/virsh.c | 2 ++ tools/virsh.h | 1 + 8 files changed, 148 insertions(+) create mode 100644 tools/virsh-backup.c create mode 100644 tools/virsh-backup.h diff --git a/po/POTFILES.in b/po/POTFILES.in index cb9831e..2f6d594 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -300,6 +300,7 @@ src/xenconfig/xen_xl.c src/xenconfig/xen_xm.c tests/virpolkittest.c tools/libvirt-guests.sh.in +tools/virsh-backup.c tools/virsh-console.c tools/virsh-domain-monitor.c tools/virsh-domain.c diff --git a/tools/Makefile.am b/tools/Makefile.am index 56691c2..7e0283f 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -228,6 +228,7 @@ virsh_SOURCES =3D \ virsh-snapshot.c virsh-snapshot.h \ virsh-util.c virsh-util.h \ virsh-volume.c virsh-volume.h \ + virsh-backup.c virsh-backup.h \ $(NULL) =20 virsh_LDFLAGS =3D \ diff --git a/tools/virsh-backup.c b/tools/virsh-backup.c new file mode 100644 index 0000000..0f72444 --- /dev/null +++ b/tools/virsh-backup.c @@ -0,0 +1,100 @@ +/* + * virsh-backup.c: Commands to manage domain backup + * + * Copyright (C) 2017 Parallels International GmbH + * + * 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 "virsh-backup.h" + +#include "internal.h" +#include "virfile.h" +#include "viralloc.h" +#include "virsh-domain.h" +#include "virsh-util.h" + +#define VIRSH_COMMON_OPT_DOMAIN_FULL \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) \ + +/* + * "backup-create" command + */ +static const vshCmdInfo info_backup_create[] =3D { + {.name =3D "help", + .data =3D N_("Create a backup from XML") + }, + {.name =3D "desc", + .data =3D N_("Create a disks backup from XML description") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_create[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL, + {.name =3D "xmlfile", + .type =3D VSH_OT_STRING, + .help =3D N_("domain backup XML") + }, + {.name =3D NULL} +}; + +static bool +cmdBackupCreate(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *from =3D NULL; + char *buffer =3D NULL; + unsigned int flags =3D 0; + virDomainBackupPtr backup =3D NULL; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0) + goto cleanup; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + + if (!(backup =3D virDomainBackupCreateXML(dom, buffer, flags))) + goto cleanup; + + vshPrint(ctl, _("Domain backup started from '%s'"), from); + + ret =3D true; + + cleanup: + VIR_FREE(buffer); + virshDomainFree(dom); + virshDomainBackupFree(backup); + + return ret; +} + +const vshCmdDef backupCmds[] =3D { + {.name =3D "backup-create", + .handler =3D cmdBackupCreate, + .opts =3D opts_backup_create, + .info =3D info_backup_create, + .flags =3D 0 + }, + {.name =3D NULL} +}; diff --git a/tools/virsh-backup.h b/tools/virsh-backup.h new file mode 100644 index 0000000..da7ec22 --- /dev/null +++ b/tools/virsh-backup.h @@ -0,0 +1,29 @@ +/* + * virsh-backup.h: Commands to manage domain backup + * + * Copyright (C) 2017 Parallels International GmbH + * + * 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 VIRSH_BACKUP_H +# define VIRSH_BACKUP_H + +# include "virsh.h" + +extern const vshCmdDef backupCmds[]; + +#endif /* VIRSH_BACKUP_H */ diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 4b86e29..66eb61a 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -175,6 +175,17 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) } =20 =20 +void +virshDomainBackupFree(virDomainBackupPtr backup) +{ + if (!backup) + return; + + vshSaveLibvirtHelperError(); + virDomainBackupFree(backup); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + int virshDomainGetXMLFromDom(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 64cef23..ebbac5d 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -46,6 +46,9 @@ virshDomainFree(virDomainPtr dom); void virshDomainSnapshotFree(virDomainSnapshotPtr snap); =20 +void +virshDomainBackupFree(virDomainBackupPtr backup); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh.c b/tools/virsh.c index 90f8125..f68edc3 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -71,6 +71,7 @@ #include "virsh-secret.h" #include "virsh-snapshot.h" #include "virsh-volume.h" +#include "virsh-backup.h" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -844,6 +845,7 @@ static const vshCmdGrp cmdGroups[] =3D { {VIRSH_CMD_GRP_NODEDEV, "nodedev", nodedevCmds}, {VIRSH_CMD_GRP_SECRET, "secret", secretCmds}, {VIRSH_CMD_GRP_SNAPSHOT, "snapshot", snapshotCmds}, + {VIRSH_CMD_GRP_BACKUP, "backup", backupCmds}, {VIRSH_CMD_GRP_STORAGE_POOL, "pool", storagePoolCmds}, {VIRSH_CMD_GRP_STORAGE_VOL, "volume", storageVolCmds}, {VIRSH_CMD_GRP_VIRSH, "virsh", virshCmds}, diff --git a/tools/virsh.h b/tools/virsh.h index 9e42ef9..d7a192b 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -57,6 +57,7 @@ # define VIRSH_CMD_GRP_NWFILTER "Network Filter" # define VIRSH_CMD_GRP_SECRET "Secret" # define VIRSH_CMD_GRP_SNAPSHOT "Snapshot" +# define VIRSH_CMD_GRP_BACKUP "Backup" # define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor" # define VIRSH_CMD_GRP_VIRSH "Virsh itself" =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list