[libvirt] [PATCHv2 2/3] snapshot: split snapshot conf code into own file

Daniel Veillard veillard at redhat.com
Fri Aug 24 06:58:18 UTC 2012


On Thu, Aug 23, 2012 at 02:54:15PM -0600, Eric Blake wrote:
> This has several benefits:
> 1. Future snapshot-related code has a definite place to go (and I
> _will_ be adding some)
> 2. Snapshot errors now use the VIR_FROM_DOMAIN_SNAPSHOT error
> classification, which has been underutilized (previously only in
> libvirt.c)
> 
> * src/conf/domain_conf.h, domain_conf.c: Split...
> * src/conf/snapshot_conf.h, snapshot_conf.c: ...into new files.
> * src/Makefile.am (DOMAIN_CONF_SOURCES): Build new files.
> * po/POTFILES.in: Mark new file for translation.
> * src/vbox/vbox_tmpl.c: Update caller.
> * src/esx/esx_driver.c: Likewise.
> * src/qemu/qemu_command.c: Likewise.
> * src/qemu/qemu_domain.h: Likewise.
[...]
> diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
> new file mode 100644
> index 0000000..894a74c
> --- /dev/null
> +++ b/src/conf/snapshot_conf.c
> @@ -0,0 +1,970 @@
> +/*
> + * snapshot_conf.c: domain snapshot XML processing
> + *
> + * Copyright (C) 2006-2012 Red Hat, Inc.
> + * Copyright (C) 2006-2008 Daniel P. Berrange
> + *
> + * 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
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Author: Daniel P. Berrange <berrange at redhat.com>

  Hum ... I would have guessed you're the author of most of that
  snapshot related code, not Dan, so i would probably adjust this
  accordingly

> + */
> +
> +#include <config.h>
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <sys/time.h>
> +
> +#include "internal.h"
> +#include "virterror_internal.h"
> +#include "datatypes.h"
> +#include "domain_conf.h"
> +#include "snapshot_conf.h"
> +#include "memory.h"
> +#include "xml.h"
> +#include "uuid.h"
> +#include "util.h"
> +#include "buf.h"
> +#include "logging.h"
> +#include "nwfilter_conf.h"
> +#include "storage_file.h"
> +#include "virfile.h"
> +#include "bitmap.h"
> +#include "count-one-bits.h"
> +#include "secret_conf.h"
> +#include "netdev_vport_profile_conf.h"
> +#include "netdev_bandwidth_conf.h"

  I assume from there everything is just moved around

[...]
> diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
> new file mode 100644
> index 0000000..314c4d1
> --- /dev/null
> +++ b/src/conf/snapshot_conf.h
> @@ -0,0 +1,157 @@
> +/*
> + * snapshot_conf.h: domain snapshot XML processing
> + *
> + * Copyright (C) 2006-2012 Red Hat, Inc.
> + * Copyright (C) 2006-2008 Daniel P. Berrange
> + *
> + * 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
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Author: Daniel P. Berrange <berrange at redhat.com>

 idem

> + */
> +
> +#ifndef __SNAPSHOT_CONF_H
> +# define __SNAPSHOT_CONF_H
> +
> +# include "internal.h"
> +# include "domain_conf.h"
> +
> +/* Items related to snapshot state */
> +
> +enum virDomainDiskSnapshot {
> +    VIR_DOMAIN_DISK_SNAPSHOT_DEFAULT = 0,
> +    VIR_DOMAIN_DISK_SNAPSHOT_NO,
> +    VIR_DOMAIN_DISK_SNAPSHOT_INTERNAL,
> +    VIR_DOMAIN_DISK_SNAPSHOT_EXTERNAL,
> +
> +    VIR_DOMAIN_DISK_SNAPSHOT_LAST
> +};
> +
> +enum virDomainSnapshotState {
> +    /* Inherit the VIR_DOMAIN_* states from virDomainState.  */
> +    VIR_DOMAIN_DISK_SNAPSHOT = VIR_DOMAIN_LAST,
> +    VIR_DOMAIN_SNAPSHOT_STATE_LAST
> +};
> +
> +/* Stores disk-snapshot information */
> +typedef struct _virDomainSnapshotDiskDef virDomainSnapshotDiskDef;
> +typedef virDomainSnapshotDiskDef *virDomainSnapshotDiskDefPtr;
> +struct _virDomainSnapshotDiskDef {
> +    char *name; /* name matching the <target dev='...' of the domain */
> +    int index; /* index within snapshot->dom->disks that matches name */
> +    int snapshot; /* enum virDomainDiskSnapshot */
> +    char *file; /* new source file when snapshot is external */
> +    char *driverType; /* file format type of new file */
> +};
> +
> +/* Stores the complete snapshot metadata */
> +typedef struct _virDomainSnapshotDef virDomainSnapshotDef;
> +typedef virDomainSnapshotDef *virDomainSnapshotDefPtr;
> +struct _virDomainSnapshotDef {
> +    /* Public XML.  */
> +    char *name;
> +    char *description;
> +    char *parent;
> +    long long creationTime; /* in seconds */
> +    int state; /* enum virDomainSnapshotState */
> +
> +    size_t ndisks; /* should not exceed dom->ndisks */
> +    virDomainSnapshotDiskDef *disks;
> +
> +    virDomainDefPtr dom;
> +
> +    /* Internal use.  */
> +    bool current; /* At most one snapshot in the list should have this set */
> +};
> +
> +struct _virDomainSnapshotObj {
> +    virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */
> +
> +    virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before
> +                                       virDomainSnapshotUpdateRelations, or
> +                                       after virDomainSnapshotDropParent */
> +    virDomainSnapshotObjPtr sibling; /* NULL if last child of parent */
> +    size_t nchildren;
> +    virDomainSnapshotObjPtr first_child; /* NULL if no children */
> +};
> +
> +virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void);
> +void virDomainSnapshotObjListFree(virDomainSnapshotObjListPtr snapshots);
> +
> +typedef enum {
> +    VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE = 1 << 0,
> +    VIR_DOMAIN_SNAPSHOT_PARSE_DISKS    = 1 << 1,
> +    VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL = 1 << 2,
> +} virDomainSnapshotParseFlags;
> +
> +virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
> +                                                        virCapsPtr caps,
> +                                                        unsigned int expectedVirtTypes,
> +                                                        unsigned int flags);
> +void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
> +char *virDomainSnapshotDefFormat(const char *domain_uuid,
> +                                 virDomainSnapshotDefPtr def,
> +                                 unsigned int flags,
> +                                 int internal);
> +int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
> +                                int default_snapshot,
> +                                bool require_match);
> +virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr snapshots,
> +                                                   const virDomainSnapshotDefPtr def);
> +
> +int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
> +                                     virDomainSnapshotObjPtr from,
> +                                     char **const names, int maxnames,
> +                                     unsigned int flags);
> +int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
> +                                virDomainSnapshotObjPtr from,
> +                                unsigned int flags);
> +virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
> +                                                    const char *name);
> +void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
> +                                    virDomainSnapshotObjPtr snapshot);
> +int virDomainSnapshotForEach(virDomainSnapshotObjListPtr snapshots,
> +                             virHashIterator iter,
> +                             void *data);
> +int virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
> +                                  virHashIterator iter,
> +                                  void *data);
> +int virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot,
> +                                       virHashIterator iter,
> +                                       void *data);
> +int virDomainSnapshotUpdateRelations(virDomainSnapshotObjListPtr snapshots);
> +void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot);
> +
> +# define VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA           \
> +               (VIR_DOMAIN_SNAPSHOT_LIST_METADATA     | \
> +                VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)
> +
> +# define VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES             \
> +               (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES       | \
> +                VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
> +
> +# define VIR_DOMAIN_SNAPSHOT_FILTERS_ALL                \
> +               (VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA  | \
> +                VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES)
> +
> +int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
> +                           virDomainSnapshotObjPtr from,
> +                           virDomainPtr dom,
> +                           virDomainSnapshotPtr **snaps,
> +                           unsigned int flags);
> +
> +VIR_ENUM_DECL(virDomainDiskSnapshot)
> +VIR_ENUM_DECL(virDomainSnapshotState)
> +
> +#endif /* __SNAPSHOT_CONF_H */

  okay

> index 72a7acc..e57296a 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -26,6 +26,7 @@
> 
>  #include "internal.h"
>  #include "domain_conf.h"
> +#include "snapshot_conf.h"
>  #include "virauth.h"
>  #include "util.h"
>  #include "memory.h"
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index ca62f0c..8c32a4d 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -38,6 +38,7 @@
>  #include "domain_nwfilter.h"
>  #include "domain_audit.h"
>  #include "domain_conf.h"
> +#include "snapshot_conf.h"
>  #include "network/bridge_driver.h"
>  #include "virnetdevtap.h"
>  #include "base64.h"
> diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
> index b96087e..dff53cf 100644
> --- a/src/qemu/qemu_domain.h
> +++ b/src/qemu/qemu_domain.h
> @@ -1,7 +1,7 @@
>  /*
>   * qemu_domain.h: QEMU domain private state
>   *
> - * Copyright (C) 2006-2011 Red Hat, Inc.
> + * Copyright (C) 2006-2012 Red Hat, Inc.
>   * Copyright (C) 2006 Daniel P. Berrange
>   *
>   * This library is free software; you can redistribute it and/or
> @@ -26,6 +26,7 @@
> 
>  # include "threads.h"
>  # include "domain_conf.h"
> +# include "snapshot_conf.h"
>  # include "qemu_monitor.h"
>  # include "qemu_agent.h"
>  # include "qemu_conf.h"
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index 4cdb11c..48f371f 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> @@ -43,6 +43,7 @@
>  #include "internal.h"
>  #include "datatypes.h"
>  #include "domain_conf.h"
> +#include "snapshot_conf.h"
>  #include "network_conf.h"
>  #include "virterror_internal.h"
>  #include "domain_event.h"

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list