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

Re: [libvirt] [PATCH v3 5/5] Update the remote API



On Fri, Aug 03, 2012 at 11:18:58AM -0300, Marcelo Cerri wrote:
> Thist patch updates libvirt's API to allow applications to inspect the
> full list of security labels of a domain.
> 
> Signed-off-by: Marcelo Cerri <mhcerri linux vnet ibm com>
> ---
>  daemon/remote.c              |   63 ++++++++++++++++++++++++++++++++++++
>  include/libvirt/libvirt.h.in |    2 +
>  python/generator.py          |    1 +
>  src/driver.h                 |    4 ++
>  src/libvirt.c                |   47 +++++++++++++++++++++++++++
>  src/libvirt_public.syms      |    5 +++
>  src/qemu/qemu_driver.c       |   73 ++++++++++++++++++++++++++++++++++++++++++
>  src/remote/remote_driver.c   |   46 ++++++++++++++++++++++++++
>  src/remote/remote_protocol.x |   17 +++++++++-
>  src/remote_protocol-structs  |    1 +
>  10 files changed, 258 insertions(+), 1 deletions(-)
> 
> diff --git a/daemon/remote.c b/daemon/remote.c
> index d25717c..367180a 100644
> --- a/daemon/remote.c
> +++ b/daemon/remote.c
> @@ -1420,6 +1420,69 @@ cleanup:
>  }
>  
>  static int
> +remoteDispatchDomainGetSecurityLabelList(virNetServerPtr server ATTRIBUTE_UNUSED,
> +                                         virNetServerClientPtr client ATTRIBUTE_UNUSED,
> +                                         virNetMessagePtr msg ATTRIBUTE_UNUSED,
> +                                         virNetMessageErrorPtr rerr,
> +                                         remote_domain_get_security_label_list_args *args,
> +                                         remote_domain_get_security_label_list_ret *ret)
> +{
> +    virDomainPtr dom = NULL;
> +    virSecurityLabelPtr seclabels = NULL;
> +    int i, len, rv = -1;
> +    struct daemonClientPrivate *priv =
> +        virNetServerClientGetPrivateData(client);
> +
> +    if (!priv->conn) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
> +        goto cleanup;
> +    }
> +
> +    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
> +        goto cleanup;
> +
> +    if ((len = virDomainGetSecurityLabelList(dom, &seclabels)) < 0) {
> +        ret->ret = len;
> +        ret->labels.labels_len = 0;
> +        ret->labels.labels_val = NULL;
> +        goto done;
> +    }
> +
> +    if (VIR_ALLOC_N(ret->labels.labels_val, len) < 0) {
> +        virReportOOMError();
> +        goto cleanup;
> +    }
> +
> +    for (i = 0; i < len; i++) {
> +        size_t label_len = strlen(seclabels[i].label) + 1;
> +        remote_domain_get_security_label_ret *cur = &ret->labels.labels_val[i];
> +        if (VIR_ALLOC_N(cur->label.label_val, label_len) < 0) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +        if (virStrcpy(cur->label.label_val, seclabels[i].label, label_len) == NULL) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("failed to copy security label"));
> +            goto cleanup;
> +        }
> +        cur->label.label_len = label_len;
> +        cur->enforcing = seclabels[i].enforcing;
> +    }
> +    ret->labels.labels_len = ret->ret = len;
> +
> +done:
> +    rv = 0;
> +
> +cleanup:
> +    if (rv < 0)
> +        virNetMessageSaveError(rerr);
> +    if (dom)
> +        virDomainFree(dom);
> +    VIR_FREE(seclabels);
> +    return rv;
> +}
> +
> +static int
>  remoteDispatchNodeGetSecurityModel(virNetServerPtr server ATTRIBUTE_UNUSED,
>                                     virNetServerClientPtr client ATTRIBUTE_UNUSED,
>                                     virNetMessagePtr msg ATTRIBUTE_UNUSED,
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index d21d029..0985dd3 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -1593,6 +1593,8 @@ int                     virDomainGetSecurityLabel (virDomainPtr domain,
>                                                     virSecurityLabelPtr seclabel);
>  char *                  virDomainGetHostname    (virDomainPtr domain,
>                                                   unsigned int flags);
> +int                     virDomainGetSecurityLabelList (virDomainPtr domain,
> +                                                       virSecurityLabelPtr* seclabels);
>  
>  typedef enum {
>      VIR_DOMAIN_METADATA_DESCRIPTION = 0, /* Operate on <description> */
> diff --git a/python/generator.py b/python/generator.py
> index 6559ece..1f87195 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -448,6 +448,7 @@ skip_function = (
>      'virConnectOpenAuth', # Python C code is manually written
>      'virDefaultErrorFunc', # Python virErrorFuncHandler impl calls this from C
>      'virDomainGetSecurityLabel', # Needs investigation...
> +    'virDomainGetSecurityLabelList', # Needs investigation...
>      'virNodeGetSecurityModel', # Needs investigation...
>      'virConnectDomainEventRegister',   # overridden in virConnect.py
>      'virConnectDomainEventDeregister', # overridden in virConnect.py
> diff --git a/src/driver.h b/src/driver.h
> index aab9766..203497d 100644
> --- a/src/driver.h
> +++ b/src/driver.h
> @@ -320,6 +320,9 @@ typedef int
>          (*virDrvDomainGetSecurityLabel) (virDomainPtr domain,
>                                           virSecurityLabelPtr seclabel);
>  typedef int
> +        (*virDrvDomainGetSecurityLabelList) (virDomainPtr domain,
> +                                         virSecurityLabelPtr* seclabels);
> +typedef int
>          (*virDrvNodeGetSecurityModel)   (virConnectPtr conn,
>                                           virSecurityModelPtr secmodel);
>  typedef int
> @@ -941,6 +944,7 @@ struct _virDriver {
>      virDrvDomainGetVcpus                domainGetVcpus;
>      virDrvDomainGetMaxVcpus             domainGetMaxVcpus;
>      virDrvDomainGetSecurityLabel        domainGetSecurityLabel;
> +    virDrvDomainGetSecurityLabelList     domainGetSecurityLabelList;
>      virDrvNodeGetSecurityModel          nodeGetSecurityModel;
>      virDrvDomainGetXMLDesc              domainGetXMLDesc;
>      virDrvConnectDomainXMLFromNative    domainXMLFromNative;
> diff --git a/src/libvirt.c b/src/libvirt.c
> index 3c4bf8c..dfe49eb 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -9027,6 +9027,53 @@ error:
>  }
>  
>  /**
> + * virDomainGetSecurityLabelList:
> + * @domain: a domain object
> + * @seclabels: will be auto-allocated and filled with domains' security labels.
> + * Caller must free memory on return.
> + *
> + * Extract the security labels of an active domain. The 'label' field
> + * in the @seclabels argument will be initialized to the empty
> + * string if the domain is not running under a security model.
> + *
> + * Returns 0 in case of success, -1 in case of failure

Should this be:

  'Returns number of elemnets in @seclabels on success, -1 in case of failure'

eg see the QEMU impl:

> +        if (VIR_ALLOC_N((*seclabels), len) < 0) {
> +            virReportOOMError();
> +            VIR_FREE(mgrs);
> +            goto cleanup;
> +        }
> +        memset(*seclabels, 0, sizeof(**seclabels) * len);
> +
> +        /* Fill the array */
> +        for (i = 0; i < len; i++) {
> +            if (virSecurityManagerGetProcessLabel(mgrs[i], vm->def, vm->pid,
> +                                                  &(*seclabels)[i]) < 0) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               "%s", _("Failed to get security label"));
> +                VIR_FREE(mgrs);
> +                VIR_FREE(*seclabels);
> +                goto cleanup;
> +            }
> +        }
> +        ret = len;
> +        VIR_FREE(mgrs);
> +    }
> +
> +cleanup:
> +    if (vm)
> +        virDomainObjUnlock(vm);
> +    qemuDriverUnlock(driver);
> +    return ret;
> +}


ACK with comment fixed & the issue Michael pointed out

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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