Re: [PATCH v3] storage_backend_rbd: check the return value of rados_conf_set

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

 




On 11/12/2016 04:22 AM, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao@xxxxxxxxx>
> 
> We forget to check the return value of some rados_conf_set.
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxx>
> ---
> v2: add another missing return value check
> v3: fix a copy-paste error
> 
>  src/storage/storage_backend_rbd.c | 28 ++++++++++++++++++++++++----
>  1 file changed, 24 insertions(+), 4 deletions(-)
> 

Take one more step... Rather than replicating the same message in so
many different places, why not create a helper

static int
virStorageBackendRBDRADOSConfSet(rados_t cluster,
                                 const char *option,
                                 const char *value)
{
    VIR_DEBUG("Setting RADOS option '%s' to '%s'",
              option, value);
    if (rados_conf_set(cluster, option, value) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to set RADOS option: %s"),
                       option);
        return -1;
    }
    return 0;
}


And all those other places just have:

    if (virStorageBackendRBDRADOSConfSet(ptr->cluster, arg2, arg3) < 0)
        goto cleanup;

And be sure also remove the VIR_DEBUG("Found cephx key: %s", rados_key);

Also, try to not have lines longer than 80 cols... makes it tough to
read the code.

John


> diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
> index 718c4d6..a286af0 100644
> --- a/src/storage/storage_backend_rbd.c
> +++ b/src/storage/storage_backend_rbd.c
> @@ -159,13 +159,28 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
>       * Operations in librados will return -ETIMEDOUT when the timeout is reached.
>       */
>      VIR_DEBUG("Setting RADOS option client_mount_timeout to %s", client_mount_timeout);
> -    rados_conf_set(ptr->cluster, "client_mount_timeout", client_mount_timeout);
> +    if (rados_conf_set(ptr->cluster, "client_mount_timeout", client_mount_timeout) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to set RADOS option: %s"),
> +                       "client_mount_timeout");
> +        goto cleanup;
> +    }
>  
>      VIR_DEBUG("Setting RADOS option rados_mon_op_timeout to %s", mon_op_timeout);
> -    rados_conf_set(ptr->cluster, "rados_mon_op_timeout", mon_op_timeout);
> +    if (rados_conf_set(ptr->cluster, "rados_mon_op_timeout", mon_op_timeout) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to set RADOS option: %s"),
> +                       "rados_mon_op_timeout");
> +        goto cleanup;
> +    }
>  
>      VIR_DEBUG("Setting RADOS option rados_osd_op_timeout to %s", osd_op_timeout);
> -    rados_conf_set(ptr->cluster, "rados_osd_op_timeout", osd_op_timeout);
> +    if (rados_conf_set(ptr->cluster, "rados_osd_op_timeout", osd_op_timeout) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to set RADOS option: %s"),
> +                       "rados_osd_op_timeout");
> +        goto cleanup;
> +    }
>  
>      /*
>       * Librbd supports creating RBD format 2 images. We no longer have to invoke
> @@ -173,7 +188,12 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
>       * This leaves us to simply use rbd_create() and use the default behavior of librbd
>       */
>      VIR_DEBUG("Setting RADOS option rbd_default_format to %s", rbd_default_format);
> -    rados_conf_set(ptr->cluster, "rbd_default_format", rbd_default_format);
> +    if (rados_conf_set(ptr->cluster, "rbd_default_format", rbd_default_format) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to set RADOS option: %s"),
> +                       "rbd_default_format");
> +        goto cleanup;
> +    }
>  
>      ptr->starttime = time(0);
>      if ((r = rados_connect(ptr->cluster)) < 0) {
> 

--
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]
  Powered by Linux