[libvirt] [PATCH] test_driver: implement virDomainMemoryPeek
Ján Tomko
jtomko at redhat.com
Fri May 24 12:39:41 UTC 2019
On Thu, May 23, 2019 at 01:37:01PM +0200, Ilias Stamatis wrote:
>Begins by writing a @start byte in the first position of @buffer and
>then for every next byte it stores the value of its previous one
>incremented by one.
>
>Behaves the same for both supported flags.
>
>Signed-off-by: Ilias Stamatis <stamatis.iliass at gmail.com>
>---
>
>Initially I thought about checking whether start+size exceeds the
>available physical or virtual memory. However I noticed that even when
>I pass -1 as @start the qemu driver doesn't complain and it fills the
>buffer with data. So I left it as is, without performing any additional
>checks.
>
> src/test/test_driver.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
>diff --git a/src/test/test_driver.c b/src/test/test_driver.c
>index a4c17ef0df..04fdf7a4b8 100644
>--- a/src/test/test_driver.c
>+++ b/src/test/test_driver.c
>@@ -6000,6 +6000,42 @@ testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
> return 0;
> }
>
>+static int
>+testDomainMemoryPeek(virDomainPtr dom,
>+ unsigned long long start,
>+ size_t size,
>+ void *buffer,
>+ unsigned int flags)
>+{
>+ int ret = -1;
>+ size_t i;
>+ unsigned char b = start;
>+ virDomainObjPtr vm = NULL;
>+
>+ virCheckFlags(VIR_MEMORY_VIRTUAL | VIR_MEMORY_PHYSICAL, -1);
>+
>+ if (flags != VIR_MEMORY_VIRTUAL && flags != VIR_MEMORY_PHYSICAL) {
>+ virReportError(VIR_ERR_INVALID_ARG,
>+ "%s", _("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL"));
>+ goto cleanup;
>+ }
You can use VIR_EXCLUSIVE_FLAGS_RET instead of open-coding it.
Jano
>+
>+ if (!(vm = testDomObjFromDomain(dom)))
>+ goto cleanup;
>+
>+ if (virDomainObjCheckActive(vm) < 0)
>+ goto cleanup;
>+
>+ for (i = 0; i < size; i++)
>+ ((unsigned char *) buffer)[i] = b++;
>+
>+ ret = 0;
>+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190524/6a23722c/attachment-0001.sig>
More information about the libvir-list
mailing list