qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@us.ibm.com,
	stefanb@linux.vnet.ibm.com,
	Corey Bryant <coreyb@linux.vnet.ibm.com>,
	mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com,
	jschopp@linux.vnet.ibm.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 3/7] vnvram: VNVRAM bottom-half r/w scheduling support
Date: Thu, 23 May 2013 13:44:43 -0400	[thread overview]
Message-ID: <1369331087-22345-4-git-send-email-coreyb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1369331087-22345-1-git-send-email-coreyb@linux.vnet.ibm.com>

Provides support that schedules and executes VNVRAM read/write
requests.  A bottom-half is used to perform reads/writes from
the QEMU main thread.

Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
---
 vnvram.c |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/vnvram.c b/vnvram.c
index 37b7070..4157482 100644
--- a/vnvram.c
+++ b/vnvram.c
@@ -14,6 +14,7 @@
 #include "vnvram.h"
 #include "block/block.h"
 #include "monitor/monitor.h"
+#include "qemu/thread.h"
 
 /*
 #define VNVRAM_DEBUG
@@ -68,6 +69,30 @@ typedef struct VNVRAMDrvEntry {
     VNVRAM_ENTRY_DATA
 } QEMU_PACKED VNVRAMDrvEntry;
 
+/* Used to pass read/write requests to the bottom-half function */
+typedef struct VNVRAMRWRequest {
+    VNVRAM *vnvram;
+    VNVRAMEntry *entry;
+    bool is_write;
+    char **blob_r;
+    uint32_t *blob_r_size;
+    char *blob_w;
+    uint32_t blob_w_size;
+    int rc;
+
+    QemuMutex completion_mutex;
+    QemuCond completion;
+
+    QSIMPLEQ_ENTRY(VNVRAMRWRequest) list;
+} VNVRAMRWRequest;
+
+/* A mutex protected queue where read/write requests are stored */
+static QemuMutex vnvram_rwrequests_mutex;
+static QSIMPLEQ_HEAD(, VNVRAMRWRequest) vnvram_rwrequests =
+    QSIMPLEQ_HEAD_INITIALIZER(vnvram_rwrequests);
+
+static QEMUBH *vnvram_bh;
+
 static int vnvram_drv_entry_create(VNVRAM *, VNVRAMEntry *, uint64_t, uint32_t);
 static int vnvram_drv_entry_update(VNVRAM *, VNVRAMEntry *, uint64_t, uint32_t);
 static int vnvram_register_entry_internal(VNVRAM *, const VNVRAMEntryName *,
@@ -679,3 +704,120 @@ static VNVRAMEntry *vnvram_find_entry(VNVRAM *vnvram,
 
     return NULL;
 }
+
+/*********************** VNVRAM rwrequest ****************************/
+/* High-level VNVRAM functions that schedule and kick off read/write */
+/* requests.                                                         */
+/*********************************************************************/
+
+/*
+ * VNVRAMRWRequest initialization for read requests
+ */
+static VNVRAMRWRequest *vnvram_rwrequest_init_read(VNVRAM *vnvram,
+                                                   VNVRAMEntry *entry,
+                                                   char **blob,
+                                                   uint32_t *blob_size)
+{
+    VNVRAMRWRequest *rwr;
+
+    rwr = g_new0(VNVRAMRWRequest, 1);
+
+    rwr->is_write = false;
+    rwr->entry = entry;
+    rwr->vnvram = vnvram;
+    rwr->blob_r = blob;
+    rwr->blob_r_size = blob_size;
+
+    return rwr;
+}
+
+/*
+ * VNVRAMRWRequest initialization for write requests
+ */
+static VNVRAMRWRequest *vnvram_rwrequest_init_write(VNVRAM *vnvram,
+                                                    VNVRAMEntry *entry,
+                                                    char *blob,
+                                                    uint32_t blob_size)
+{
+    VNVRAMRWRequest *rwr;
+
+    rwr = g_new0(VNVRAMRWRequest, 1);
+
+    rwr->is_write = true;
+    rwr->entry = entry;
+    rwr->vnvram = vnvram;
+    rwr->blob_w = blob;
+    rwr->blob_w_size = blob_size;
+
+    return rwr;
+}
+
+/*
+ * Execute a read or write of blob data based on an VNVRAMRWRequest
+ */
+static int vnvram_rwrequest_exec(VNVRAMRWRequest *rwr)
+{
+    int rc = 0;
+
+    if (rwr->is_write) {
+        rc = vnvram_drv_entry_write_blob(rwr->vnvram, rwr->entry,
+                                         rwr->blob_w, rwr->blob_w_size);
+    } else {
+        rc = vnvram_drv_entry_read_blob(rwr->vnvram, rwr->entry,
+                                        rwr->blob_r, rwr->blob_r_size);
+    }
+
+    rwr->rc = rc;
+
+    qemu_mutex_lock(&rwr->completion_mutex);
+    qemu_cond_signal(&rwr->completion);
+    qemu_mutex_unlock(&rwr->completion_mutex);
+
+    return rc;
+}
+
+/*
+ * Bottom-half callback that is invoked by QEMU's main thread to
+ * process VNVRAM read/write requests.
+ */
+static void vnvram_rwrequest_callback(void *opaque)
+{
+    VNVRAMRWRequest *rwr, *next;
+
+    qemu_mutex_lock(&vnvram_rwrequests_mutex);
+
+    QSIMPLEQ_FOREACH_SAFE(rwr, &vnvram_rwrequests, list, next) {
+        QSIMPLEQ_REMOVE(&vnvram_rwrequests, rwr, VNVRAMRWRequest, list);
+
+        qemu_mutex_unlock(&vnvram_rwrequests_mutex);
+
+        vnvram_rwrequest_exec(rwr);
+
+        qemu_mutex_lock(&vnvram_rwrequests_mutex);
+    }
+
+    qemu_mutex_unlock(&vnvram_rwrequests_mutex);
+}
+
+/*
+ * Schedules a bottom-half to read or write a blob to the VNVRAM drive.
+ */
+static int vnvram_rwrequest_schedule(VNVRAMRWRequest *rwr)
+{
+    int rc = 0;
+
+    qemu_mutex_lock(&vnvram_rwrequests_mutex);
+    QSIMPLEQ_INSERT_TAIL(&vnvram_rwrequests, rwr, list);
+    qemu_mutex_unlock(&vnvram_rwrequests_mutex);
+
+    qemu_bh_schedule(vnvram_bh);
+
+    /* All reads/writes are synchronous so we wait for completion */
+    qemu_mutex_lock(&rwr->completion_mutex);
+    qemu_cond_wait(&rwr->completion, &rwr->completion_mutex);
+    qemu_mutex_unlock(&rwr->completion_mutex);
+
+    rc = rwr->rc;
+
+    return rc;
+}
-- 
1.7.1

  parent reply	other threads:[~2013-05-23 17:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-23 17:44 [Qemu-devel] [PATCH 0/7] VNVRAM persistent storage Corey Bryant
2013-05-23 17:44 ` [Qemu-devel] [PATCH 1/7] vnvram: VNVRAM bdrv support Corey Bryant
2013-05-24 13:06   ` Kevin Wolf
2013-05-24 15:33     ` Corey Bryant
2013-05-24 15:37       ` Kevin Wolf
2013-05-24 15:47         ` Corey Bryant
2013-05-23 17:44 ` [Qemu-devel] [PATCH 2/7] vnvram: VNVRAM in-memory support Corey Bryant
2013-05-23 17:44 ` Corey Bryant [this message]
2013-05-23 17:44 ` [Qemu-devel] [PATCH 4/7] vnvram: VNVRAM internal APIs Corey Bryant
2013-05-23 17:44 ` [Qemu-devel] [PATCH 5/7] vnvram: VNVRAM additional debug support Corey Bryant
2013-05-23 17:44 ` [Qemu-devel] [PATCH 6/7] main: Initialize VNVRAM Corey Bryant
2013-05-23 17:44 ` [Qemu-devel] [PATCH 7/7] monitor: QMP/HMP support for retrieving VNVRAM details Corey Bryant
2013-05-23 17:59   ` Eric Blake
2013-05-23 18:43     ` Corey Bryant
2013-05-29 17:15   ` Luiz Capitulino
2013-05-29 17:34     ` Corey Bryant
2013-05-23 18:03 ` [Qemu-devel] [PATCH 0/7] VNVRAM persistent storage Anthony Liguori
2013-05-23 18:41   ` Corey Bryant
2013-05-23 19:15     ` Anthony Liguori
2013-05-24 15:27       ` Corey Bryant
2013-05-29 13:34         ` Anthony Liguori
2013-05-24  9:59 ` Stefan Hajnoczi
2013-05-24 12:13   ` Stefan Berger
2013-05-24 12:36     ` Stefan Hajnoczi
2013-05-24 15:39       ` Corey Bryant
2013-05-27  8:40         ` Stefan Hajnoczi

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=1369331087-22345-4-git-send-email-coreyb@linux.vnet.ibm.com \
    --to=coreyb@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=jschopp@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).