All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arun R Bharadwaj <arun@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/9] Introduce lock fid_list_lock to protect the fid list.
Date: Thu, 14 Oct 2010 17:53:48 +0530	[thread overview]
Message-ID: <20101014122348.2238.88570.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20101014122217.2238.94995.stgit@localhost6.localdomain6>

From: Sripathi Kodi <sripathik@in.ibm.com>

Currently it is a normal mutex, but I will change it into a rw mutex.
This should be held in read mode while looking up and in write mode
while updating the list.

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
 hw/virtio-9p.c |   32 +++++++++++++++++++++++++++++---
 hw/virtio-9p.h |    2 ++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 174300d..02a4ec4 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -18,7 +18,6 @@
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-debug.h"
 #include "virtio-9p-xattr.h"
-#include "qemu-threadlets.h"
 
 int debug_9p_pdu;
 
@@ -552,7 +551,8 @@ static size_t v9fs_string_size(V9fsString *str)
     return str->size;
 }
 
-static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
+/* fid_list_lock should be held on entry */
+static V9fsFidState *__lookup_fid(V9fsState *s, int32_t fid)
 {
     V9fsFidState *f;
 
@@ -565,12 +565,26 @@ static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
     return NULL;
 }
 
+static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
+{
+    V9fsFidState *f;
+
+    qemu_rwmutex_rdlock(&s->fid_list_lock);
+    f = __lookup_fid(s, fid);
+    qemu_rwmutex_unlock(&s->fid_list_lock);
+
+    return f;
+}
+
+
 static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
 {
     V9fsFidState *f;
 
-    f = lookup_fid(s, fid);
+    qemu_rwmutex_wrlock(&s->fid_list_lock);
+    f = __lookup_fid(s, fid);
     if (f) {
+        qemu_rwmutex_unlock(&s->fid_list_lock);
         return NULL;
     }
 
@@ -582,6 +596,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
     f->next = s->fid_list;
     s->fid_list = f;
 
+    qemu_rwmutex_unlock(&(s->fid_list_lock));
     return f;
 }
 
@@ -619,11 +634,13 @@ free_value:
     return retval;
 }
 
+/* On entry, fid_list_lock and fid_lock should NOT be held */
 static int free_fid(V9fsState *s, int32_t fid)
 {
     int retval = 0;
     V9fsFidState **fidpp, *fidp;
 
+    qemu_rwmutex_wrlock(&s->fid_list_lock);
     for (fidpp = &s->fid_list; *fidpp; fidpp = &(*fidpp)->next) {
         if ((*fidpp)->fid == fid) {
             break;
@@ -631,12 +648,18 @@ static int free_fid(V9fsState *s, int32_t fid)
     }
 
     if (*fidpp == NULL) {
+        qemu_rwmutex_unlock(&s->fid_list_lock);
         return -ENOENT;
     }
 
     fidp = *fidpp;
     *fidpp = fidp->next;
 
+    /* We have removed the node from the list, so we can release
+     * the fid_list_lock now
+     */
+    qemu_rwmutex_unlock(&s->fid_list_lock);
+
     if (fidp->fid_type == P9_FID_FILE) {
         v9fs_do_close(s, fidp->fs.fd);
     } else if (fidp->fid_type == P9_FID_DIR) {
@@ -2922,6 +2945,7 @@ static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
             * Fixup fid's pointing to the old name to
             * start pointing to the new name
             */
+            qemu_rwmutex_rdlock(&s->fid_list_lock);
             for (fidp = s->fid_list; fidp; fidp = fidp->next) {
                 if (vs->fidp == fidp) {
                     /*
@@ -2937,6 +2961,7 @@ static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
                                   strlen(vs->fidp->path.data));
                 }
             }
+            qemu_rwmutex_unlock(&s->fid_list_lock);
             v9fs_string_copy(&vs->fidp->path, &vs->name);
         }
     }
@@ -3880,6 +3905,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     qemu_set_fd_handler(fds[0], v9fs_process_post_ops, NULL, NULL);
     QTAILQ_INIT(&v9fs_async_struct.post_op_list);
     qemu_mutex_init(&(v9fs_async_struct.lock));
+    qemu_rwmutex_init(&(s->fid_list_lock));
     /* Create async queue. */
 
     (void)v9fs_do_async_posix;
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 6c23319..f58d3d8 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -7,6 +7,7 @@
 #include <utime.h>
 
 #include "file-op-9p.h"
+#include "qemu-threadlets.h"
 
 /* The feature bitmap for virtio 9P */
 /* The mount point is specified in a config variable */
@@ -206,6 +207,7 @@ typedef struct V9fsState
     V9fsPDU pdus[MAX_REQ];
     QLIST_HEAD(, V9fsPDU) free_list;
     V9fsFidState *fid_list;
+    QemuRWMutex fid_list_lock;
     FileOperations *ops;
     FsContext ctx;
     uint16_t tag_len;

  parent reply	other threads:[~2010-10-14 12:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-14 12:23 [Qemu-devel] [RFC PATCH 0/9] Second threading model Arun R Bharadwaj
2010-10-14 12:23 ` [Qemu-devel] [PATCH 1/9] Add read-write lock to QEMU Arun R Bharadwaj
2010-10-14 12:23 ` Arun R Bharadwaj [this message]
2010-10-14 12:24 ` [Qemu-devel] [PATCH 3/9] Global rename lock Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 4/9] Convert stat into 2nd threading model Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 5/9] Convert wstat " Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 6/9] Convert open " Arun R Bharadwaj
2010-10-14 12:25 ` [Qemu-devel] [PATCH 7/9] Convert walk " Arun R Bharadwaj
2010-10-14 12:25 ` [Qemu-devel] [PATCH 8/9] Convert read " Arun R Bharadwaj
2010-10-14 12:25 ` [Qemu-devel] [PATCH 9/9] Convert write " Arun R Bharadwaj

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=20101014122348.2238.88570.stgit@localhost6.localdomain6 \
    --to=arun@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.