Re: [PATCH 15/24] maint: improve VIR_ERR_INVALID_INTERFACE usage

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

 




On 12/28/2013 11:11 AM, Eric Blake wrote:
> When checking for a valid interface, we weren't consistent on
> whether ew reported as VIR_FROM_NONE or VIR_FROM_INTERFACE.
> Similar to previous patches, use a common macro to make it nicer.
> For now, we don't need virCheckInterfaceGoto().
> 
> * src/datatypes.h (virCheckInterfaceReturn): New macro.
> (VIR_IS_INTERFACE, VIR_IS_CONNECTED_INTERFACE): Drop unused
> macros.
> * src/libvirt.c: Use macro throughout.
> (virLibInterfaceError): Drop unused macro.
> 
> Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
> ---
>  src/datatypes.h | 17 +++++++++----
>  src/libvirt.c   | 74 +++++++++++++++------------------------------------------
>  2 files changed, 32 insertions(+), 59 deletions(-)
> 

Same concern as Networks - the virInterfaceGetName() and
virInterfaceGetMACString() will require a connection...

ACK

John
> diff --git a/src/datatypes.h b/src/datatypes.h
> index 9c40f89..304e9b5 100644
> --- a/src/datatypes.h
> +++ b/src/datatypes.h
> @@ -110,10 +110,19 @@ extern virClassPtr virStoragePoolClass;
>          }                                                               \
>      } while (0)
> 
> -# define VIR_IS_INTERFACE(obj) \
> -    (virObjectIsClass((obj), virInterfaceClass))
> -# define VIR_IS_CONNECTED_INTERFACE(obj) \
> -    (VIR_IS_INTERFACE(obj) && virObjectIsClass((obj)->conn, virConnectClass))
> +# define virCheckInterfaceReturn(obj, retval)                           \
> +    do {                                                                \
> +        virInterfacePtr _iface = (obj);                                 \
> +        if (!virObjectIsClass(_iface, virInterfaceClass) ||             \
> +            !virObjectIsClass(_iface->conn, virConnectClass)) {         \
> +            virReportErrorHelper(VIR_FROM_INTERFACE,                    \
> +                                 VIR_ERR_INVALID_INTERFACE,             \
> +                                 __FILE__, __FUNCTION__, __LINE__,      \
> +                                 __FUNCTION__);                         \
> +            virDispatchError(NULL);                                     \
> +            return retval;                                              \
> +        }                                                               \
> +    } while (0)
> 
>  # define VIR_IS_STORAGE_POOL(obj) \
>      (virObjectIsClass((obj), virStoragePoolClass))
> diff --git a/src/libvirt.c b/src/libvirt.c
> index 8fca384..55c35d5 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -524,9 +524,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED,
>  #define virLibStorageVolError(code, ...)                          \
>      virReportErrorHelper(VIR_FROM_STORAGE, code, __FILE__,        \
>                           __FUNCTION__, __LINE__, __VA_ARGS__)
> -#define virLibInterfaceError(code, ...)                           \
> -    virReportErrorHelper(VIR_FROM_INTERFACE, code, __FILE__,      \
> -                         __FUNCTION__, __LINE__, __VA_ARGS__)
>  #define virLibNodeDeviceError(code, ...)                          \
>      virReportErrorHelper(VIR_FROM_NODEDEV, code, __FILE__,        \
>                           __FUNCTION__, __LINE__, __VA_ARGS__)
> @@ -11400,11 +11397,8 @@ virInterfaceGetConnect(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return NULL;
> -    }
> +    virCheckInterfaceReturn(iface, NULL);
> +
>      return iface->conn;
>  }
> 
> @@ -11711,11 +11705,8 @@ virInterfaceGetName(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return NULL;
> -    }
> +    virCheckInterfaceReturn(iface, NULL);
> +
>      return iface->name;
>  }
> 
> @@ -11738,11 +11729,8 @@ virInterfaceGetMACString(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return NULL;
> -    }
> +    virCheckInterfaceReturn(iface, NULL);
> +
>      return iface->mac;
>  }
> 
> @@ -11773,12 +11761,7 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return NULL;
> -    }
> -
> +    virCheckInterfaceReturn(iface, NULL);
>      conn = iface->conn;
> 
>      if (conn->interfaceDriver && conn->interfaceDriver->interfaceGetXMLDesc) {
> @@ -11871,12 +11854,9 @@ virInterfaceUndefine(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> +    virCheckInterfaceReturn(iface, -1);
>      conn = iface->conn;
> +
>      virCheckReadOnlyGoto(conn->flags, error);
> 
>      if (conn->interfaceDriver && conn->interfaceDriver->interfaceUndefine) {
> @@ -11917,12 +11897,9 @@ virInterfaceCreate(virInterfacePtr iface, unsigned int flags)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> +    virCheckInterfaceReturn(iface, -1);
>      conn = iface->conn;
> +
>      virCheckReadOnlyGoto(conn->flags, error);
> 
>      if (conn->interfaceDriver && conn->interfaceDriver->interfaceCreate) {
> @@ -11967,13 +11944,9 @@ virInterfaceDestroy(virInterfacePtr iface, unsigned int flags)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> -
> +    virCheckInterfaceReturn(iface, -1);
>      conn = iface->conn;
> +
>      virCheckReadOnlyGoto(conn->flags, error);
> 
>      if (conn->interfaceDriver && conn->interfaceDriver->interfaceDestroy) {
> @@ -12016,11 +11989,8 @@ virInterfaceRef(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if ((!VIR_IS_CONNECTED_INTERFACE(iface))) {
> -        virLibConnError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> +    virCheckInterfaceReturn(iface, -1);
> +
>      virObjectRef(iface);
>      return 0;
>  }
> @@ -12042,11 +12012,8 @@ virInterfaceFree(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibInterfaceError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> +    virCheckInterfaceReturn(iface, -1);
> +
>      virObjectUnref(iface);
>      return 0;
>  }
> @@ -17325,11 +17292,8 @@ virInterfaceIsActive(virInterfacePtr iface)
> 
>      virResetLastError();
> 
> -    if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
> -        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
> -        virDispatchError(NULL);
> -        return -1;
> -    }
> +    virCheckInterfaceReturn(iface, -1);
> +
>      if (iface->conn->interfaceDriver->interfaceIsActive) {
>          int ret;
>          ret = iface->conn->interfaceDriver->interfaceIsActive(iface);
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]