From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51796 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6Mql-0007Mk-6S for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:24:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6Mqj-0003Rh-T0 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:23:59 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:44850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6Mqj-0003RK-Bw for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:23:57 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp01.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9ECKobB030186 for ; Thu, 14 Oct 2010 23:20:50 +1100 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9ECNtuK3174644 for ; Thu, 14 Oct 2010 23:23:55 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9ECNtmt009066 for ; Thu, 14 Oct 2010 23:23:55 +1100 Received: from localhost6.localdomain6 ([9.77.206.195]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9ECNpdS009042 for ; Thu, 14 Oct 2010 23:23:54 +1100 From: Arun R Bharadwaj Date: Thu, 14 Oct 2010 17:53:48 +0530 Message-ID: <20101014122348.2238.88570.stgit@localhost6.localdomain6> In-Reply-To: <20101014122217.2238.94995.stgit@localhost6.localdomain6> References: <20101014122217.2238.94995.stgit@localhost6.localdomain6> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 2/9] Introduce lock fid_list_lock to protect the fid list. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Sripathi Kodi 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 --- 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 #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;