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

Re: [libvirt] [PATCH] test_driver: implement virDomainSetTime and update virDomainGetTime



On Tue, Aug 06, 2019 at 06:20:07PM +0200, Ilias Stamatis wrote:
> Until now, testDomainGetTime would always return the same fixed value
> everytime it was called. By using domain-private data we can make this
> API return the values previously set with testDomainSetTime, or use the
> same old fixed value in case testDomainSetTime hasn't been called at all.
> ---

As the commit subject already hints, this should be split in 2 patches.

>  src/test/test_driver.c | 45 ++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index d9a7f815d5..6a75e63429 100755
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -392,6 +392,11 @@ struct _testDomainObjPrivate {
>      testDriverPtr driver;
>
>      bool frozen[2]; /* used by file system related calls */
> +

No need for another ^extra line :).

> +
> +    /* used by get/set time APIs */
> +    long long seconds;
> +    unsigned int nseconds;

Looks like we're going to make more and more use of the private data, so at
some point it might be worth introducing helper structures to keep the master
structure (priv) tidy, but that's a patch for another day.

The code's alright, so once you split the changes it can go right in.

Erik

>  };
>
>
> @@ -406,6 +411,9 @@ testDomainObjPrivateAlloc(void *opaque)
>      priv->driver = opaque;
>      priv->frozen[0] = priv->frozen[1] = false;
>
> +    priv->seconds = 627319920;
> +    priv->nseconds = 0;
> +
>      return priv;
>  }
>
> @@ -2082,6 +2090,7 @@ testDomainGetTime(virDomainPtr dom,
>                    unsigned int flags)
>  {
>      virDomainObjPtr vm = NULL;
> +    testDomainObjPrivatePtr priv;
>      int ret = -1;
>
>      virCheckFlags(0, -1);
> @@ -2095,8 +2104,39 @@ testDomainGetTime(virDomainPtr dom,
>          goto cleanup;
>      }
>
> -    *seconds = 627319920;
> -    *nseconds = 0;
> +    priv = vm->privateData;
> +
> +    *seconds = priv->seconds;
> +    *nseconds = priv->nseconds;
> +
> +    ret = 0;
> + cleanup:
> +    virDomainObjEndAPI(&vm);
> +    return ret;
> +}
> +
> +
> +static int
> +testDomainSetTime(virDomainPtr dom,
> +                  long long seconds,
> +                  unsigned int nseconds,
> +                  unsigned int flags)
> +{
> +    virDomainObjPtr vm = NULL;
> +    testDomainObjPrivatePtr priv;
> +    int ret = -1;
> +
> +    virCheckFlags(VIR_DOMAIN_TIME_SYNC, ret);
> +
> +    if (!(vm = testDomObjFromDomain(dom)))
> +        return -1;
> +
> +    if (virDomainObjCheckActive(vm) < 0)
> +        goto cleanup;
> +
> +    priv = vm->privateData;
> +    priv->seconds = seconds;
> +    priv->nseconds = nseconds;
>
>      ret = 0;
>   cleanup:
> @@ -8891,6 +8931,7 @@ static virHypervisorDriver testHypervisorDriver = {
>      .domainGetInfo = testDomainGetInfo, /* 0.1.1 */
>      .domainGetState = testDomainGetState, /* 0.9.2 */
>      .domainGetTime = testDomainGetTime, /* 5.4.0 */
> +    .domainSetTime = testDomainSetTime, /* 5.7.0 */
>      .domainSave = testDomainSave, /* 0.3.2 */
>      .domainSaveFlags = testDomainSaveFlags, /* 0.9.4 */
>      .domainRestore = testDomainRestore, /* 0.3.2 */
> --
> 2.22.0
>
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list


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