public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xen.org
Cc: Daniel Kiper <daniel.kiper@oracle.com>,
	kexec@lists.infradead.org, David Vrabel <david.vrabel@citrix.com>
Subject: [PATCH 7/8] libxc: add hypercall buffer arrays
Date: Thu, 21 Feb 2013 17:48:13 +0000	[thread overview]
Message-ID: <1361468894-18655-8-git-send-email-david.vrabel@citrix.com> (raw)
In-Reply-To: <1361468894-18655-1-git-send-email-david.vrabel@citrix.com>

From: David Vrabel <david.vrabel@citrix.com>

Hypercall buffer arrays are used when a hypercall takes a variable
length array of buffers.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 tools/libxc/xc_hcall_buf.c |   73 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h      |   27 ++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/tools/libxc/xc_hcall_buf.c b/tools/libxc/xc_hcall_buf.c
index ced9abd..3e01f3f 100644
--- a/tools/libxc/xc_hcall_buf.c
+++ b/tools/libxc/xc_hcall_buf.c
@@ -228,6 +228,79 @@ void xc__hypercall_bounce_post(xc_interface *xch, xc_hypercall_buffer_t *b)
     xc__hypercall_buffer_free(xch, b);
 }
 
+struct xc_hypercall_buffer_array {
+    unsigned max_bufs;
+    xc_hypercall_buffer_t *bufs;
+};
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch,
+                                                              unsigned n)
+{
+    xc_hypercall_buffer_array_t *array;
+    xc_hypercall_buffer_t *bufs = NULL;
+
+    array = malloc(sizeof(*array));
+    if ( array == NULL )
+        goto error;
+
+    bufs = calloc(n, sizeof(*bufs));
+    if ( bufs == NULL )
+        goto error;
+
+    array->max_bufs = n;
+    array->bufs     = bufs;
+
+    return array;
+
+error:
+    free(bufs);
+    free(array);
+    return NULL;
+}
+
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch,
+                                       xc_hypercall_buffer_array_t *array,
+                                       unsigned index,
+                                       xc_hypercall_buffer_t *hbuf,
+                                       size_t size)
+{
+    void *buf;
+
+    if ( index >= array->max_bufs || array->bufs[index].hbuf )
+        abort();
+
+    buf = xc__hypercall_buffer_alloc(xch, hbuf, size);
+    if ( buf )
+        array->bufs[index] = *hbuf;
+    return buf;
+}
+
+void *xc__hypercall_buffer_array_get(xc_interface *xch,
+                                     xc_hypercall_buffer_array_t *array,
+                                     unsigned index,
+                                     xc_hypercall_buffer_t *hbuf)
+{
+    if ( index >= array->max_bufs || array->bufs[index].hbuf == NULL )
+        abort();
+
+    *hbuf = array->bufs[index];
+    return array->bufs[index].hbuf;
+}
+
+void xc_hypercall_buffer_array_destroy(xc_interface *xc,
+                                       xc_hypercall_buffer_array_t *array)
+{
+    unsigned i;
+
+    if ( array == NULL )
+        return;
+
+    for (i = 0; i < array->max_bufs; i++ )
+        xc__hypercall_buffer_free(xc, &array->bufs[i]);
+    free(array->bufs);
+    free(array);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 32122fd..c3b2c28 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -317,6 +317,33 @@ void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b
 #define xc_hypercall_buffer_free_pages(_xch, _name, _nr) xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name), _nr)
 
 /*
+ * Array of hypercall buffers.
+ *
+ * Create an array with xc_hypercall_buffer_array_create() and
+ * populate it by declaring one hypercall buffer in a loop and
+ * allocating the buffer with xc_hypercall_buffer_array_alloc().
+ *
+ * To access a previously allocated buffers, declare a new hypercall
+ * buffer and call xc_hypercall_buffer_array_get().
+ *
+ * Destroy the array with xc_hypercall_buffer_array_destroy() to free
+ * the array and all its alocated hypercall buffers.
+ */
+struct xc_hypercall_buffer_array;
+typedef struct xc_hypercall_buffer_array xc_hypercall_buffer_array_t;
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch, unsigned n);
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                       unsigned index, xc_hypercall_buffer_t *hbuf, size_t size);
+#define xc_hypercall_buffer_array_alloc(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_alloc(_xch, _array, _index, HYPERCALL_BUFFER(_name), _size)
+void *xc__hypercall_buffer_array_get(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                     unsigned index, xc_hypercall_buffer_t *hbuf);
+#define xc_hypercall_buffer_array_get(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_get(_xch, _array, _index, HYPERCALL_BUFFER(_name))
+void xc_hypercall_buffer_array_destroy(xc_interface *xc, xc_hypercall_buffer_array_t *array);
+
+/*
  * CPUMAP handling
  */
 typedef uint8_t *xc_cpumap_t;
-- 
1.7.2.5


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2013-02-21 17:48 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-21 17:48 [PATCH 0/8] kexec: extended kexec hypercall for use with pv-ops kernels David Vrabel
2013-02-21 17:48 ` [PATCH 1/8] x86: give FIX_EFI_MPF its own fixmap entry David Vrabel
2013-02-21 17:48 ` [PATCH 2/8] xen: make GUEST_HANDLE_64() and uint64_aligned_t available everywhere David Vrabel
2013-02-21 17:48 ` [PATCH 3/8] kexec: add public interface for improved load/unload sub-ops David Vrabel
2013-02-21 22:29   ` Daniel Kiper
2013-02-22 11:49     ` David Vrabel
2013-02-22  8:33   ` [Xen-devel] " Jan Beulich
2013-02-22 11:50     ` David Vrabel
2013-02-22 13:09       ` Jan Beulich
2013-03-08 10:50   ` Daniel Kiper
2013-03-08 11:52     ` David Vrabel
2013-03-08 12:28       ` Daniel Kiper
2013-03-08 12:36         ` [Xen-devel] " Jan Beulich
2013-03-08 15:34           ` Daniel Kiper
2013-02-21 17:48 ` [PATCH 4/8] kexec: add infrastructure for handling kexec images David Vrabel
2013-03-08 11:37   ` Daniel Kiper
2013-03-08 11:42     ` David Vrabel
2013-03-08 11:58       ` Daniel Kiper
2013-02-21 17:48 ` [PATCH 5/8] kexec: extend hypercall with improved load/unload ops David Vrabel
2013-02-21 22:41   ` Daniel Kiper
2013-02-22  8:42   ` [Xen-devel] " Jan Beulich
2013-02-22 11:54     ` David Vrabel
2013-02-22 13:11       ` Jan Beulich
2013-03-08 11:23   ` Daniel Kiper
2013-03-08 11:40     ` David Vrabel
2013-03-08 12:21       ` Daniel Kiper
2013-03-08 14:01         ` David Vrabel
2013-03-08 15:23           ` Daniel Kiper
2013-03-08 17:29             ` [Xen-devel] " Andrew Cooper
2013-03-08 21:45               ` Daniel Kiper
2013-03-08 23:38                 ` Andrew Cooper
2013-03-11 11:17                   ` Daniel Kiper
2013-03-11 13:21                     ` David Vrabel
2013-03-11 13:30                       ` Daniel Kiper
2013-03-11 13:43                         ` David Vrabel
2013-03-11 14:13                           ` Daniel Kiper
2013-03-11 14:27                             ` Andrew Cooper
2013-03-11 20:45                               ` Daniel Kiper
2013-03-11 21:18                                 ` Andrew Cooper
2013-03-12 11:17                                   ` Daniel Kiper
2013-03-12 11:36   ` Daniel Kiper
2013-02-21 17:48 ` [PATCH 6/8] xen: kexec crash image when dom0 crashes David Vrabel
2013-02-21 17:48 ` David Vrabel [this message]
2013-03-06 14:25   ` [Xen-devel] [PATCH 7/8] libxc: add hypercall buffer arrays Ian Jackson
2013-03-07  2:44   ` Ian Campbell
2013-02-21 17:48 ` [PATCH 8/8] libxc: add API for kexec hypercall David Vrabel
2013-03-07  2:46   ` [Xen-devel] " Ian Campbell
2013-02-21 22:47 ` [PATCH 0/8] kexec: extended kexec hypercall for use with pv-ops kernels Daniel Kiper
2013-02-22  8:17 ` [Xen-devel] " Jan Beulich
2013-02-22 11:56   ` David Vrabel
2013-02-26 13:58 ` Don Slutz
2013-03-05 11:04 ` David Vrabel
  -- strict thread matches above, loose matches on Subject: below --
2013-04-08 18:59 [PATCHv3 0/8] kexec: extend " David Vrabel
2013-04-08 18:59 ` [PATCH 7/8] libxc: add hypercall buffer arrays David Vrabel
2013-04-16 17:13 [PATCHv4 0/8] kexec: extend kexec hypercall for use with pv-ops kernels David Vrabel
2013-04-16 17:13 ` [PATCH 7/8] libxc: add hypercall buffer arrays David Vrabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1361468894-18655-8-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=daniel.kiper@oracle.com \
    --cc=kexec@lists.infradead.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox