aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs/codir.c
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2011-05-24 15:10:56 +0530
committerAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2011-09-22 21:38:52 +0530
commit02cb7f3a256517cbf3136caff2863fbafc57b540 (patch)
tree1d741e85dfe584b35a4a5e69a086d7b19fafd0ad /hw/9pfs/codir.c
parent70c18fc08bcc9e9bbd8c00ca5e694e07890687e5 (diff)
hw/9pfs: Use read-write lock for protecting fid path.
On rename we take the write lock and this ensure path doesn't change as we operate on them. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Diffstat (limited to 'hw/9pfs/codir.c')
-rw-r--r--hw/9pfs/codir.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index f17f927c10..c9a88ecb60 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -65,22 +65,34 @@ void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
});
}
-int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, uid_t uid, gid_t gid)
+int v9fs_co_mkdir(V9fsState *s, V9fsFidState *fidp, V9fsString *name,
+ mode_t mode, uid_t uid, gid_t gid, struct stat *stbuf)
{
int err;
FsCred cred;
+ V9fsString fullname;
cred_init(&cred);
cred.fc_mode = mode;
cred.fc_uid = uid;
cred.fc_gid = gid;
+ v9fs_string_init(&fullname);
+ qemu_co_rwlock_rdlock(&s->rename_lock);
+ v9fs_string_sprintf(&fullname, "%s/%s", fidp->path.data, name->data);
v9fs_co_run_in_worker(
{
- err = s->ops->mkdir(&s->ctx, name, &cred);
+ err = s->ops->mkdir(&s->ctx, fullname.data, &cred);
if (err < 0) {
err = -errno;
+ } else {
+ err = s->ops->lstat(&s->ctx, fullname.data, stbuf);
+ if (err < 0) {
+ err = -errno;
+ }
}
});
+ qemu_co_rwlock_unlock(&s->rename_lock);
+ v9fs_string_free(&fullname);
return err;
}
@@ -88,6 +100,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
{
int err;
+ qemu_co_rwlock_rdlock(&s->rename_lock);
v9fs_co_run_in_worker(
{
fidp->fs.dir = s->ops->opendir(&s->ctx, fidp->path.data);
@@ -97,6 +110,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
err = 0;
}
});
+ qemu_co_rwlock_unlock(&s->rename_lock);
if (!err) {
total_open_fd++;
if (total_open_fd > open_fd_hw) {