aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs/cofs.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-09-29 13:32:05 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2011-09-29 13:32:05 -0500
commit62ec6073cd07b847c296b3a1fa19894293f8155d (patch)
tree19fc1772d9cabd7f5590e33374d58a3f4b38d0ba /hw/9pfs/cofs.c
parent0bce98df2639aef1e8af90b271aa91e16d695408 (diff)
parent5f5422258e1f50f871bafcc5bfb2b498f414a310 (diff)
Merge remote-tracking branch 'aneesh/for-upstream-5' into staging
Diffstat (limited to 'hw/9pfs/cofs.c')
-rw-r--r--hw/9pfs/cofs.c195
1 files changed, 174 insertions, 21 deletions
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index a78fccbe23..68745add1e 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -17,15 +17,20 @@
#include "qemu-coroutine.h"
#include "virtio-9p-coth.h"
-int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
{
int err;
ssize_t len;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
buf->data = g_malloc(PATH_MAX);
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- len = s->ops->readlink(&s->ctx, path->data,
+ len = s->ops->readlink(&s->ctx, path,
buf->data, PATH_MAX - 1);
if (len > -1) {
buf->size = len;
@@ -35,6 +40,7 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
err = -errno;
}
});
+ v9fs_path_unlock(s);
if (err) {
g_free(buf->data);
buf->data = NULL;
@@ -43,109 +49,162 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
return err;
}
-int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf)
+int v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path, struct statfs *stbuf)
{
int err;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->statfs(&s->ctx, path->data, stbuf);
+ err = s->ops->statfs(&s->ctx, path, stbuf);
if (err < 0) {
err = -errno;
}
});
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode)
+int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
{
int err;
FsCred cred;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
cred_init(&cred);
cred.fc_mode = mode;
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->chmod(&s->ctx, path->data, &cred);
+ err = s->ops->chmod(&s->ctx, path, &cred);
if (err < 0) {
err = -errno;
}
});
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_utimensat(V9fsState *s, V9fsString *path,
+int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
struct timespec times[2])
{
int err;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->utimensat(&s->ctx, path->data, times);
+ err = s->ops->utimensat(&s->ctx, path, times);
if (err < 0) {
err = -errno;
}
});
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
+int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid)
{
int err;
FsCred cred;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
cred_init(&cred);
cred.fc_uid = uid;
cred.fc_gid = gid;
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->chown(&s->ctx, path->data, &cred);
+ err = s->ops->chown(&s->ctx, path, &cred);
if (err < 0) {
err = -errno;
}
});
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size)
+int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
{
int err;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->truncate(&s->ctx, path->data, size);
+ err = s->ops->truncate(&s->ctx, path, size);
if (err < 0) {
err = -errno;
}
});
+ v9fs_path_unlock(s);
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(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, uid_t uid,
+ gid_t gid, dev_t dev, mode_t mode, struct stat *stbuf)
{
int err;
+ V9fsPath path;
FsCred cred;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
cred_init(&cred);
cred.fc_uid = uid;
cred.fc_gid = gid;
cred.fc_mode = mode;
cred.fc_rdev = dev;
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->mknod(&s->ctx, path->data, &cred);
+ err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
if (err < 0) {
err = -errno;
+ } else {
+ v9fs_path_init(&path);
+ err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
+ if (!err) {
+ err = s->ops->lstat(&s->ctx, &path, stbuf);
+ if (err < 0) {
+ err = -errno;
+ }
+ }
+ v9fs_path_free(&path);
}
});
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_remove(V9fsState *s, V9fsString *path)
+/* Only works with path name based fid */
+int v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
{
int err;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
err = s->ops->remove(&s->ctx, path->data);
@@ -153,13 +212,39 @@ int v9fs_co_remove(V9fsState *s, V9fsString *path)
err = -errno;
}
});
+ v9fs_path_unlock(s);
+ return err;
+}
+
+int v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path, V9fsString *name, int flags)
+{
+ int err;
+ V9fsState *s = pdu->s;
+
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_path_read_lock(s);
+ v9fs_co_run_in_worker(
+ {
+ err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
+ if (err < 0) {
+ err = -errno;
+ }
+ });
+ v9fs_path_unlock(s);
return err;
}
-int v9fs_co_rename(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
+/* Only work with path name based fid */
+int v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath, V9fsPath *newpath)
{
int err;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
v9fs_co_run_in_worker(
{
err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
@@ -170,22 +255,90 @@ 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_renameat(V9fsPDU *pdu, V9fsPath *olddirpath, V9fsString *oldname,
+ V9fsPath *newdirpath, V9fsString *newname)
+{
+ int err;
+ V9fsState *s = pdu->s;
+
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_co_run_in_worker(
+ {
+ err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
+ newdirpath, newname->data);
+ if (err < 0) {
+ err = -errno;
+ }
+ });
+ return err;
+}
+
+int v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp, V9fsString *name,
+ const char *oldpath, gid_t gid, struct stat *stbuf)
{
int err;
FsCred cred;
+ V9fsPath path;
+ V9fsState *s = pdu->s;
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
cred_init(&cred);
- cred.fc_uid = fidp->uid;
+ cred.fc_uid = dfidp->uid;
cred.fc_gid = gid;
cred.fc_mode = 0777;
+ v9fs_path_read_lock(s);
v9fs_co_run_in_worker(
{
- err = s->ops->symlink(&s->ctx, oldpath, newpath, &cred);
+ err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
+ name->data, &cred);
if (err < 0) {
err = -errno;
+ } else {
+ v9fs_path_init(&path);
+ err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
+ if (!err) {
+ err = s->ops->lstat(&s->ctx, &path, stbuf);
+ if (err < 0) {
+ err = -errno;
+ }
+ }
+ v9fs_path_free(&path);
}
});
+ v9fs_path_unlock(s);
+ return err;
+}
+
+/*
+ * For path name based fid we don't block. So we can
+ * directly call the fs driver ops.
+ */
+int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
+ const char *name, V9fsPath *path)
+{
+ int err;
+ V9fsState *s = pdu->s;
+
+ if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+ err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
+ if (err < 0) {
+ err = -errno;
+ }
+ } else {
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ v9fs_co_run_in_worker(
+ {
+ err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
+ if (err < 0) {
+ err = -errno;
+ }
+ });
+ }
return err;
}