[libvirt] [PATCH v2 5/7] snapshot: Rework virDomainSnapshotState enum
Eric Blake
eblake at redhat.com
Wed Feb 27 20:13:11 UTC 2019
On 2/27/19 2:04 PM, Eric Blake wrote:
> The existing virDomainSnapshotState is a superset of virDomainState,
> adding one more state (disk-snapshot) on top of valid domain states.
> But as written, the enum cannot be used for gcc validation that all
> enum values are covered in a strongly-typed switch condition, because
> the enum does not explicitly include the values it is adding to.
>
> Copy the style used in qemu_blockjob.h of creating new enum names
> for every inherited value, and update all clients to use the new
> enum names anywhere snapshot state is referenced. Qemu code gains
> a fixme comment about some odd casts (which will be cleaned up in
> separate patches); the rest of the patch is mechanical.
>
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
> +/**
> + * This enum has to map all known domain states from the public enum
> + * virDomainState, before adding one additional state possible only
> + * for snapshots.
> + */
> typedef enum {
> - /* Inherit the VIR_DOMAIN_* states from virDomainState. */
> - VIR_DOMAIN_DISK_SNAPSHOT = VIR_DOMAIN_LAST,
> - VIR_DOMAIN_SNAPSHOT_STATE_LAST
> + /* Mapped to public enum */
> + VIR_SNAP_STATE_NOSTATE = VIR_DOMAIN_NOSTATE,
> + VIR_SNAP_STATE_RUNNING = VIR_DOMAIN_RUNNING,
> + VIR_SNAP_STATE_BLOCKED = VIR_DOMAIN_BLOCKED,
> + VIR_SNAP_STATE_PAUSED = VIR_DOMAIN_PAUSED,
> + VIR_SNAP_STATE_SHUTDOWN = VIR_DOMAIN_SHUTDOWN,
> + VIR_SNAP_STATE_SHUTOFF = VIR_DOMAIN_SHUTOFF,
> + VIR_SNAP_STATE_CRASHED = VIR_DOMAIN_CRASHED,
> + VIR_SNAP_STATE_PMSUSPENDED = VIR_DOMAIN_PMSUSPENDED,
> + /* Additional enum values local to qemu */
Too much copy-and-paste from qemu_blockjob.h; this comment should
mention 'local to snapshots'
> + VIR_SNAP_STATE_DISK_SNAPSHOT,
> + VIR_SNAP_STATE_LAST
> } virDomainSnapshotState;
> +verify((int)VIR_SNAP_STATE_DISK_SNAPSHOT == VIR_DOMAIN_LAST);
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
More information about the libvir-list
mailing list