[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v2 3/7] conf: Introduce virDomainDiskSourceIsBlockType



On 07/18/2013 11:02 AM, John Ferlan wrote:
> Introduce a new helper to check if the disk source is of block type
> ---
>  src/conf/domain_conf.c   | 41 +++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   |  3 +++
>  src/libvirt_private.syms |  1 +
>  src/qemu/qemu_command.c  |  5 ++---
>  src/qemu/qemu_conf.c     | 23 +++++------------------
>  5 files changed, 52 insertions(+), 21 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 06b44b1..4f24ecf 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -41,6 +41,7 @@
>  #include "virbuffer.h"
>  #include "virlog.h"
>  #include "nwfilter_conf.h"
> +#include "storage_conf.h"
>  #include "virstoragefile.h"
>  #include "virfile.h"
>  #include "virbitmap.h"
> @@ -18334,3 +18335,43 @@ virDomainDiskDefGenSecurityLabelDef(const char *model)
>  
>      return seclabel;
>  }
> +
> +/**
> + * virDomainDiskSourceIsBlockType:
> + *
> + * Check if the disk *source* is of block type. This just tries
> + * to check from the type of disk def, not to probe the underlying
> + * storage.
> + *
> + * Return true if its source is block type, or false otherwise.
> + */
> +bool
> +virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
> +{
> +    /* No reason to think the disk source is block type if
> +     * the source is empty
> +     */
> +    if (!def->src)
> +        return false;
> +
> +    if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK)
> +        return true;
> +
> +    /* For volume types, check the srcpool.
> +     * If it's a block type source pool, then it's possible
> +     */
> +    if (def->type == VIR_DOMAIN_DISK_TYPE_VOLUME && def->srcpool &&
> +        def->srcpool->voltype == VIR_STORAGE_VOL_BLOCK) {
> +        /* We don't think the volume accessed by remote URI is
> +         * block type source, since we can't/shouldn't manage it
> +         * (e.g. set sgio=filtered|unfiltered for it) in libvirt.
> +         */
> +         if (def->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI &&
> +             def->srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_URI)
> +             return false;

UG... I messed up the split the above 7 lines have to go in the next
patch...

I also found out that I forgot to update my branch before sending and I
have a couple of merges to handle...

John
> +
> +        return true;
> +    }
> +
> +    return false;
> +}
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index c21d1e2..05400ce 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2710,4 +2710,7 @@ virDomainDefMaybeAddController(virDomainDefPtr def,
>  
>  char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
>  
> +bool virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
> +    ATTRIBUTE_NONNULL(1);
> +
>  #endif /* __DOMAIN_CONF_H */
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index fc4e750..047d2db 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -204,6 +204,7 @@ virDomainDiskProtocolTransportTypeToString;
>  virDomainDiskProtocolTypeToString;
>  virDomainDiskRemove;
>  virDomainDiskRemoveByName;
> +virDomainDiskSourceIsBlockType;
>  virDomainDiskTypeFromString;
>  virDomainDiskTypeToString;
>  virDomainEmulatorPinAdd;
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 71e37f3..591279b 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -42,6 +42,7 @@
>  #include "domain_audit.h"
>  #include "domain_conf.h"
>  #include "snapshot_conf.h"
> +#include "storage_conf.h"
>  #include "network/bridge_driver.h"
>  #include "virnetdevtap.h"
>  #include "base64.h"
> @@ -3490,9 +3491,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
>                                 virDomainDiskProtocolTypeToString(disk->protocol));
>                  goto error;
>              }
> -        } else if (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
> -                   !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
> -                     disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)) {
> +        } else if (!virDomainDiskSourceIsBlockType(disk)) {
>              virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>                             _("disk device='lun' is only valid for block type disk source"));
>              goto error;
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index c91551f..4fa0055 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -52,6 +52,7 @@
>  #include "virfile.h"
>  #include "virstring.h"
>  #include "viratomic.h"
> +#include "storage_conf.h"
>  #include "configmake.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_QEMU
> @@ -1160,12 +1161,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
>      if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
>          disk = dev->data.disk;
>  
> -        if (!disk->shared ||
> -            !disk->src ||
> -            (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
> -             !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
> -               disk->srcpool &&
> -               disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)))
> +        if (!disk->shared || !virDomainDiskSourceIsBlockType(disk))
>              return 0;
>      } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
>          hostdev = dev->data.hostdev;
> @@ -1271,12 +1267,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
>      if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
>          disk = dev->data.disk;
>  
> -        if (!disk->shared ||
> -            !disk->src ||
> -            (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
> -             !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
> -               disk->srcpool &&
> -               disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)))
> +        if (!disk->shared || !virDomainDiskSourceIsBlockType(disk))
>              return 0;
>      } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
>          hostdev = dev->data.hostdev;
> @@ -1366,12 +1357,8 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
>      if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
>          disk = dev->data.disk;
>  
> -        if (!disk->src ||
> -            disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
> -            (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
> -             !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
> -               disk->srcpool &&
> -               disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK)))
> +        if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
> +            virDomainDiskSourceIsBlockType(disk))
>              return 0;
>  
>          path = disk->src;
> 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]