From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: harsh@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/2] 9p-synth: fix read-side critical sections
Date: Wed, 8 Aug 2012 13:55:43 +0200 [thread overview]
Message-ID: <1344426944-7638-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1344426944-7638-1-git-send-email-pbonzini@redhat.com>
The read-side critical sections in 9p-synth currently only include the
navigation of the list. This is incorrect; it works for two reasons,
first obviously because rcu_read_lock/unlock are still no-ops; second,
because elements of the list are never deleted from the list (only added).
In fact, only adding items is the reason why rcu_read_lock/unlock can
be left as no-ops.
If items were deleted, they could be reclaimed as soon as the read-side
critical section ends. So, the read-side critical section must include
all _usage_ of the node we got from the list too.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/9pfs/virtio-9p-synth.c | 35 ++++++++++++++++++++---------------
1 file modificato, 20 inserzioni(+), 15 rimozioni(-)
diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/virtio-9p-synth.c
index 92e0b09..a91ebe1 100644
--- a/hw/9pfs/virtio-9p-synth.c
+++ b/hw/9pfs/virtio-9p-synth.c
@@ -237,14 +237,15 @@ static int v9fs_synth_get_dentry(V9fsSynthNode *dir, struct dirent *entry,
}
i++;
}
- rcu_read_unlock();
if (!node) {
/* end of directory */
*result = NULL;
- return 0;
+ goto out;
}
v9fs_synth_direntry(node, entry, off);
*result = entry;
+out:
+ rcu_read_unlock();
return 0;
}
@@ -466,6 +467,7 @@ static int v9fs_synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
{
V9fsSynthNode *node;
V9fsSynthNode *dir_node;
+ int ret = 0;
/* "." and ".." are not allowed */
if (!strcmp(name, ".") || !strcmp(name, "..")) {
@@ -473,34 +475,37 @@ static int v9fs_synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
return -1;
}
+
+ rcu_read_lock();
if (!dir_path) {
dir_node = &v9fs_synth_root;
} else {
dir_node = *(V9fsSynthNode **)dir_path->data;
}
- if (!strcmp(name, "/")) {
- node = dir_node;
- goto out;
- }
- /* search for the name in the childern */
- rcu_read_lock();
- QLIST_FOREACH(node, &dir_node->child, sibling) {
- if (!strcmp(node->name, name)) {
- break;
+
+ node = dir_node;
+ if (strcmp(name, "/") != 0) {
+ /* search for the name in the childern */
+ QLIST_FOREACH(node, &dir_node->child, sibling) {
+ if (!strcmp(node->name, name)) {
+ break;
+ }
}
}
- rcu_read_unlock();
if (!node) {
errno = ENOENT;
- return -1;
+ ret = -1;
+ goto err_out;
}
-out:
+
/* Copy the node pointer to fid */
target->data = g_malloc(sizeof(void *));
memcpy(target->data, &node, sizeof(void *));
target->size = sizeof(void *);
- return 0;
+err_out:
+ rcu_read_unlock();
+ return ret;
}
static int v9fs_synth_renameat(FsContext *ctx, V9fsPath *olddir,
--
1.7.11.2
next prev parent reply other threads:[~2012-08-08 11:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-08 11:55 [Qemu-devel] [PATCH 0/2] 9p-synth: remove poor-man RCU Paolo Bonzini
2012-08-08 11:55 ` Paolo Bonzini [this message]
2012-08-13 18:47 ` [Qemu-devel] [PATCH 1/2] 9p-synth: fix read-side critical sections Harsh Bora
2012-08-08 11:55 ` [Qemu-devel] [PATCH 2/2] 9p-synth: use mutex on read-side Paolo Bonzini
2012-08-13 19:13 ` Harsh Bora
2012-08-18 18:46 ` Paolo Bonzini
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=1344426944-7638-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=harsh@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 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).