[libvirt] [PATCH v2 09/10] viriscsitest: Introduce testIscsiadmCbData struct

John Ferlan jferlan at redhat.com
Tue Jul 17 18:56:19 UTC 2018



On 07/04/2018 05:23 AM, Michal Privoznik wrote:
> Some tests will want to pass their own callback data into the
> testIscsiadmCbData callback. Introduce testIscsiadmCbData struct
> to give this some form and order.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  tests/viriscsitest.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c
> index 361bf6a8da..c6e0e3b8ff 100644
> --- a/tests/viriscsitest.c
> +++ b/tests/viriscsitest.c
> @@ -60,6 +60,10 @@ const char *iscsiadmSendtargetsOutput =
>      "10.20.30.40:3260,1 iqn.2008-04.example:example1:iscsi.bar\n"
>      "10.20.30.40:3260,1 iqn.2009-04.example:example1:iscsi.seven\n";
>  
> +struct testIscsiadmCbData {
> +    bool output_version;
> +};
> +
>  static void testIscsiadmCb(const char *const*args,
>                             const char *const*env ATTRIBUTE_UNUSED,
>                             const char *input ATTRIBUTE_UNUSED,
> @@ -68,12 +72,13 @@ static void testIscsiadmCb(const char *const*args,
>                             int *status,
>                             void *opaque)
>  {
> -    int *output_version = opaque;
> +    struct testIscsiadmCbData *data = opaque;
> +
>      if (args[0] && STREQ(args[0], ISCSIADM) &&
>          args[1] && STREQ(args[1], "--mode") &&
>          args[2] && STREQ(args[2], "session") &&
>          args[3] == NULL) {
> -        if (*output_version == 1)
> +        if (data->output_version)
>              ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutputNonFlash));
>          else
>              ignore_value(VIR_STRDUP(*output, iscsiadmSessionOutput));
> @@ -113,11 +118,13 @@ static int
>  testISCSIGetSession(const void *data)
>  {
>      const struct testSessionInfo *info = data;
> -    int ver = info->output_version;
> +    struct testIscsiadmCbData cbData = { 0 };
>      char *actual_session = NULL;
>      int ret = -1;
>  
> -    virCommandSetDryRun(NULL, testIscsiadmCb, &ver);
> +    cbData.output_version = info->output_version;

Should this be "= info->output_version == 1" instead?

Alternatively you could change testSessionInfo->output_version to be a
bool and then DO_SESSION_TEST to use 'False' and 'True' appropriately.

One way or the other,

Reviewed-by: John Ferlan <jferlan at redhat.com>

John

> +
> +    virCommandSetDryRun(NULL, testIscsiadmCb, &cbData);
>  
>      actual_session = virISCSIGetSession(info->device_path, true);
>  
> 




More information about the libvir-list mailing list