diff options
author | Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | 2011-05-24 15:10:56 +0530 |
---|---|---|
committer | Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | 2011-09-22 21:38:52 +0530 |
commit | 02cb7f3a256517cbf3136caff2863fbafc57b540 (patch) | |
tree | 1d741e85dfe584b35a4a5e69a086d7b19fafd0ad /hw/9pfs/cofs.c | |
parent | 70c18fc08bcc9e9bbd8c00ca5e694e07890687e5 (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/cofs.c')
-rw-r--r-- | hw/9pfs/cofs.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c index a78fccbe23..98860f9189 100644 --- a/hw/9pfs/cofs.c +++ b/hw/9pfs/cofs.c @@ -23,6 +23,8 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf) ssize_t len; buf->data = g_malloc(PATH_MAX); + qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_co_run_in_worker( { len = s->ops->readlink(&s->ctx, path->data, @@ -35,6 +37,7 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); if (err) { g_free(buf->data); buf->data = NULL; @@ -47,6 +50,7 @@ int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) { int err; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->statfs(&s->ctx, path->data, stbuf); @@ -54,6 +58,7 @@ int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } @@ -64,6 +69,7 @@ int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode) cred_init(&cred); cred.fc_mode = mode; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->chmod(&s->ctx, path->data, &cred); @@ -71,6 +77,7 @@ int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } @@ -79,6 +86,7 @@ int v9fs_co_utimensat(V9fsState *s, V9fsString *path, { int err; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->utimensat(&s->ctx, path->data, times); @@ -86,6 +94,7 @@ int v9fs_co_utimensat(V9fsState *s, V9fsString *path, err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } @@ -97,6 +106,7 @@ int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid) cred_init(&cred); cred.fc_uid = uid; cred.fc_gid = gid; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->chown(&s->ctx, path->data, &cred); @@ -104,6 +114,7 @@ int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } @@ -111,6 +122,7 @@ int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size) { int err; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->truncate(&s->ctx, path->data, size); @@ -118,27 +130,39 @@ int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } -int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t uid, - gid_t gid, dev_t dev, mode_t mode) +int v9fs_co_mknod(V9fsState *s, V9fsFidState *fidp, V9fsString *name, uid_t uid, + gid_t gid, dev_t dev, mode_t mode, struct stat *stbuf) { int err; FsCred cred; + V9fsString fullname; cred_init(&cred); cred.fc_uid = uid; cred.fc_gid = gid; cred.fc_mode = mode; cred.fc_rdev = dev; + 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->mknod(&s->ctx, path->data, &cred); + err = s->ops->mknod(&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; } @@ -146,6 +170,7 @@ int v9fs_co_remove(V9fsState *s, V9fsString *path) { int err; + qemu_co_rwlock_rdlock(&s->rename_lock); v9fs_co_run_in_worker( { err = s->ops->remove(&s->ctx, path->data); @@ -153,6 +178,7 @@ int v9fs_co_remove(V9fsState *s, V9fsString *path) err = -errno; } }); + qemu_co_rwlock_unlock(&s->rename_lock); return err; } @@ -170,22 +196,34 @@ int v9fs_co_rename(V9fsState *s, V9fsString *oldpath, V9fsString *newpath) return err; } -int v9fs_co_symlink(V9fsState *s, V9fsFidState *fidp, - const char *oldpath, const char *newpath, gid_t gid) +int v9fs_co_symlink(V9fsState *s, V9fsFidState *dfidp, V9fsString *name, + const char *oldpath, gid_t gid, struct stat *stbuf) { int err; FsCred cred; + V9fsString fullname; + cred_init(&cred); - cred.fc_uid = fidp->uid; + cred.fc_uid = dfidp->uid; cred.fc_gid = gid; cred.fc_mode = 0777; + v9fs_string_init(&fullname); + qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_string_sprintf(&fullname, "%s/%s", dfidp->path.data, name->data); v9fs_co_run_in_worker( { - err = s->ops->symlink(&s->ctx, oldpath, newpath, &cred); + err = s->ops->symlink(&s->ctx, oldpath, 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; } |