Re: [PATCH] qemu_block: Refactor qemuBlockExportAddNBD()

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

 



On Tue, Oct 26, 2021 at 16:58:22 +0200, Kristina Hanicova wrote:
> I think this patch improves readability of the function by
> removing unnecessary 'else' branches after 'return' and reworking
> the code a bit.
> 
> Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
> ---
>  src/qemu/qemu_block.c | 33 +++++++++++++--------------------
>  1 file changed, 13 insertions(+), 20 deletions(-)
> 
> diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
> index 34fdec2c4b..4e532d29c0 100644
> --- a/src/qemu/qemu_block.c
> +++ b/src/qemu/qemu_block.c
> @@ -3592,28 +3592,21 @@ qemuBlockExportAddNBD(virDomainObj *vm,
>                        const char *bitmap)
>  {
>      qemuDomainObjPrivate *priv = vm->privateData;
> +    g_autoptr(virJSONValue) nbdprops = NULL;
> +    const char *bitmaps[2] = { bitmap, NULL };
>  
> -    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
> -        if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD)) {
> -            g_autoptr(virJSONValue) nbdprops = NULL;
> -            const char *bitmaps[2] = { bitmap, NULL };
> +    /* older qemu versions didn't support configuring the exportname and
> +     * took the 'drivealias' as the export name */
> +    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
> +        return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writable, NULL);
>  
> -            if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat,
> -                                                        exportname,
> -                                                        writable,
> -                                                        bitmaps)))
> -                return -1;
> +    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD))
> +        return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat,
> +                                       exportname, writable, bitmap);

These two are okay, they invoke a different code path when features are
not supported ...

It will indeed help as we can simply delete them when the caps become
obsolete ...

>  
> -            return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
> -        } else {
> -            return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat,
> -                                           exportname, writable, bitmap);
> -        }
> -    } else {
> -        /* older qemu versions didn't support configuring the exportname and
> -         * took the 'drivealias' as the export name */
> -        return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writable, NULL);
> -    }
> +    if ((nbdprops = qemuBlockExportGetNBDProps(src->nodeformat, exportname,
> +                                               writable, bitmaps)))
> +        return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);

but this is weird and doesn't conform to what we usually do. Write it
as:

    if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat, exportname,
                                                writable, bitmaps)))
        return -1;

    return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);


>  
> -    return 0;
> +    return -1;

And get rid of the above.

>  }
> -- 
> 2.31.1
> 




[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