Re: [PATCH] Sheepdog: Auto Adding volume and correct refresh volume problem.

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

 



On 01/22/2014 04:19 PM, joel SIMOES wrote:
> From: Joel SIMOES <joel.simoes@xxxxxxxxxxx>
> 
> ---
>  src/storage/storage_backend_sheepdog.c | 91 ++++++++++++++++++++++++++++++----
>  1 file changed, 81 insertions(+), 10 deletions(-)
> 
> diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
> index a6981ce..fbed11a 100644
> --- a/src/storage/storage_backend_sheepdog.c
> +++ b/src/storage/storage_backend_sheepdog.c
> @@ -109,6 +110,71 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
>      virCommandAddArgFormat(cmd, "%d", port);
>  }
>  
> +static int
> +virStorageBackendSheepdogRefreshAllVol(virConnectPtr conn ATTRIBUTE_UNUSED,
> +                                       virStoragePoolObjPtr pool)
> +{
> +    int ret;
> +    char *output = NULL;
> +
> +    virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list", "-r", NULL);
> +    virStorageBackendSheepdogAddHostArg(cmd, pool);
> +    virCommandSetOutputBuffer(cmd, &output);
> +    ret = virCommandRun(cmd, NULL);

If the command is run succesfully, ret gets set to 0 and the function returns
0 even if something fails.

You don't use the return value of virCommandRun later, so you can just do:
if (virCommandRun(cmd, NULL) < 0)
    goto cleanup;

And set ret = 0 just before the cleanup: label, as we do in most of libvirt.

> +    char** lines;
> +    char** cells;
> +
> +    if (ret < 0)
> +        goto cleanup;
> +
> +    lines = virStringSplit(output, "\n", 0);
> +    size_t i;
> +    for (i = 0; *(lines + i); i++) {
> +        char *line = *(lines + i);
> +        cells = virStringSplit(line, " ", 0);
> +        size_t j;
> +        for (j = 0; *(cells + j); j++) {
> +
> +            char *cell = *(cells + j);
> +            if (j == 1) {
> +                virStorageVolDefPtr vol = NULL;
> +                if (VIR_ALLOC(vol) < 0)
> +                    goto cleanup;
> +
> +                if (VIR_STRDUP(vol->name, cell) < 0)
> +                    goto cleanup;
> +
> +                vol->type = VIR_STORAGE_VOL_BLOCK;
> +
> +                if (VIR_EXPAND_N(pool->volumes.objs, pool->volumes.count, 1) < 0)
> +                    goto cleanup;
> +                pool->volumes.objs[pool->volumes.count - 1] = vol;
> +
> +                if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0)
> +                    goto cleanup;
> +
> +                vol = NULL;
> +            }
> +
> +            VIR_FREE(*(cells + j));

We also have a virStringFreeList function, that frees the list generated by
virStringSplit. You wouldn't need the inner 'for' loop then.

> +        }
> +
> +        VIR_FREE(cells);
> +        VIR_FREE(*(lines + i));
> +    }
> +
> +
> +    VIR_FREE(lines);
> +
> +
> +
> +
> +cleanup:
> +    virCommandFree(cmd);
> +    VIR_FREE(lines);
> +    VIR_FREE(cells);
> +    return ret;
> +}
>  
>  static int
>  virStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,

Jan

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]