[libvirt] [PATCH 1/2] Add VIR_TYPED_PARAM_STRING

Daniel Veillard veillard at redhat.com
Tue Sep 6 10:44:57 UTC 2011


On Tue, Sep 06, 2011 at 06:18:40PM +0800, Hu Tao wrote:
> ---
>  daemon/remote.c              |   15 +++++++++++++++
>  include/libvirt/libvirt.h.in |    4 +++-
>  src/remote/remote_driver.c   |   15 +++++++++++++++
>  src/remote/remote_protocol.x |    2 ++
>  4 files changed, 35 insertions(+), 1 deletions(-)
> 
> diff --git a/daemon/remote.c b/daemon/remote.c
> index 0f088c6..afceab7 100644
> --- a/daemon/remote.c
> +++ b/daemon/remote.c
> @@ -615,6 +615,13 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
>          case VIR_TYPED_PARAM_BOOLEAN:
>              val[i].value.remote_typed_param_value_u.b = params[i].value.b;
>              break;
> +        case VIR_TYPED_PARAM_STRING:
> +            val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s);
> +            if (val[i].value.remote_typed_param_value_u.s == NULL) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }
> +            break;
>          default:
>              virNetError(VIR_ERR_RPC, _("unknown parameter type: %d"),
>                          params[i].type);
> @@ -693,6 +700,14 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
>              params[i].value.b =
>                  args_params_val[i].value.remote_typed_param_value_u.b;
>              break;
> +        case VIR_TYPED_PARAM_STRING:
> +            params[i].value.s =
> +                strdup(args_params_val[i].value.remote_typed_param_value_u.s);
> +            if (params[i].value.s == NULL) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }
> +            break;
>          default:
>              virNetError(VIR_ERR_INTERNAL_ERROR, _("unknown parameter type: %d"),
>                          params[i].type);
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 53a2f7d..da2080e 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -481,7 +481,8 @@ typedef enum {
>      VIR_TYPED_PARAM_LLONG   = 3, /* long long case */
>      VIR_TYPED_PARAM_ULLONG  = 4, /* unsigned long long case */
>      VIR_TYPED_PARAM_DOUBLE  = 5, /* double case */
> -    VIR_TYPED_PARAM_BOOLEAN = 6  /* boolean(character) case */
> +    VIR_TYPED_PARAM_BOOLEAN = 6, /* boolean(character) case */
> +    VIR_TYPED_PARAM_STRING  = 7  /* string case */
>  } virTypedParameterType;
>  
>  /**
> @@ -512,6 +513,7 @@ struct _virTypedParameter {
>          unsigned long long int ul;  /* type is ULLONG */
>          double d;                   /* type is DOUBLE */
>          char b;                     /* type is BOOLEAN */
> +        char *s;                    /* type is STRING */
>      } value; /* parameter value */
>  };
>  
> diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
> index 603d589..8f9d09c 100644
> --- a/src/remote/remote_driver.c
> +++ b/src/remote/remote_driver.c
> @@ -1276,6 +1276,13 @@ remoteSerializeTypedParameters(virTypedParameterPtr params,
>          case VIR_TYPED_PARAM_BOOLEAN:
>              val[i].value.remote_typed_param_value_u.b = params[i].value.b;
>              break;
> +        case VIR_TYPED_PARAM_STRING:
> +            val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s);
> +            if (val[i].value.remote_typed_param_value_u.s == NULL) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }
> +            break;
>          default:
>              remoteError(VIR_ERR_RPC, _("unknown parameter type: %d"),
>                  params[i].type);
> @@ -1347,6 +1354,14 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
>              params[i].value.b =
>                  ret_params_val[i].value.remote_typed_param_value_u.b;
>              break;
> +        case VIR_TYPED_PARAM_STRING:
> +            params[i].value.s =
> +                strdup(ret_params_val[i].value.remote_typed_param_value_u.s);
> +            if (params[i].value.s == NULL) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }
> +            break;
>          default:
>              remoteError(VIR_ERR_RPC, _("unknown parameter type: %d"),
>                          params[i].type);
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index 8f68808..c22a566 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -314,6 +314,8 @@ union remote_typed_param_value switch (int type) {
>       double d;
>   case VIR_TYPED_PARAM_BOOLEAN:
>       int b;
> + case VIR_TYPED_PARAM_STRING:
> +     remote_nonnull_string s;
>  };
>  
>  struct remote_typed_param {

  Ohhh, good point and better to add this before the first official
release to avoid possible ABI breakages in the future if we need it !
My only concern is remote actually working, we don't have any API yet
exercizing this (I mean string values) and I wonder how to test this,

  In any case, ACK,

  Wen would you mind pushing this ?

 thanks !

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