* [Qemu-devel] [PATCH 0/2] virtio-9p: Setattr for 9P2000.L
@ 2010-06-03 15:16 Sripathi Kodi
2010-06-03 15:16 ` [Qemu-devel] [PATCH 1/2] Make v9fs_do_utimensat accept timespec structures instead of v9stat Sripathi Kodi
2010-06-03 15:17 ` [Qemu-devel] [PATCH 2/2] virtio-9p: Implement server side of setattr for 9P2000.L protocol Sripathi Kodi
0 siblings, 2 replies; 3+ messages in thread
From: Sripathi Kodi @ 2010-06-03 15:16 UTC (permalink / raw)
To: qemu-devel; +Cc: v9fs-developer
The following series implements setattr support for 9P2000.L protocol.
---
Sripathi Kodi (2):
virtio-9p: Implement server side of setattr for 9P2000.L protocol.
Make v9fs_do_utimensat accept timespec structures instead of v9stat.
hw/virtio-9p.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++------
hw/virtio-9p.h | 23 +++++++
2 files changed, 178 insertions(+), 19 deletions(-)
--
-Sripathi
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] Make v9fs_do_utimensat accept timespec structures instead of v9stat.
2010-06-03 15:16 [Qemu-devel] [PATCH 0/2] virtio-9p: Setattr for 9P2000.L Sripathi Kodi
@ 2010-06-03 15:16 ` Sripathi Kodi
2010-06-03 15:17 ` [Qemu-devel] [PATCH 2/2] virtio-9p: Implement server side of setattr for 9P2000.L protocol Sripathi Kodi
1 sibling, 0 replies; 3+ messages in thread
From: Sripathi Kodi @ 2010-06-03 15:16 UTC (permalink / raw)
To: qemu-devel; +Cc: v9fs-developer
One of Mohan's recent patches (Message-Id:
<1275286613-16757-1-git-send-email-mohan@in.ibm.com>) implements
v9fs_do_utimensat function. Currently v9fs_do_utimensat takes a V9fsStat
argument and builds timespec structures. It sets tv_nsec values to 0 by
default. Instead of this it should take struct timespec[2] and pass it
down to the system directly. This will make it more generic and useful
elsewhere.
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
hw/virtio-9p.c | 37 ++++++++++++++++++-------------------
1 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 1c7a428..8c1cdfb 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -239,25 +239,10 @@ static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
return s->ops->chown(&s->ctx, path->data, &cred);
}
-static int v9fs_do_utimensat(V9fsState *s, V9fsString *path, V9fsStat v9stat)
+static int v9fs_do_utimensat(V9fsState *s, V9fsString *path,
+ const struct timespec times[2])
{
- struct timespec ts[2];
-
- if (v9stat.atime != -1) {
- ts[0].tv_sec = v9stat.atime;
- ts[0].tv_nsec = 0;
- } else {
- ts[0].tv_nsec = UTIME_OMIT;
- }
-
- if (v9stat.mtime != -1) {
- ts[1].tv_sec = v9stat.mtime;
- ts[1].tv_nsec = 0;
- } else {
- ts[1].tv_nsec = UTIME_OMIT;
- }
-
- return s->ops->utimensat(&s->ctx, path->data, ts);
+ return s->ops->utimensat(&s->ctx, path->data, times);
}
static int v9fs_do_remove(V9fsState *s, V9fsString *path)
@@ -2345,7 +2330,21 @@ static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err)
}
if (vs->v9stat.mtime != -1 || vs->v9stat.atime != -1) {
- if (v9fs_do_utimensat(s, &vs->fidp->path, vs->v9stat)) {
+ struct timespec times[2];
+ if (vs->v9stat.atime != -1) {
+ times[0].tv_sec = vs->v9stat.atime;
+ times[0].tv_nsec = 0;
+ } else {
+ times[0].tv_nsec = UTIME_OMIT;
+ }
+ if (vs->v9stat.mtime != -1) {
+ times[1].tv_sec = vs->v9stat.mtime;
+ times[1].tv_nsec = 0;
+ } else {
+ times[1].tv_nsec = UTIME_OMIT;
+ }
+
+ if (v9fs_do_utimensat(s, &vs->fidp->path, times)) {
err = -errno;
}
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] virtio-9p: Implement server side of setattr for 9P2000.L protocol.
2010-06-03 15:16 [Qemu-devel] [PATCH 0/2] virtio-9p: Setattr for 9P2000.L Sripathi Kodi
2010-06-03 15:16 ` [Qemu-devel] [PATCH 1/2] Make v9fs_do_utimensat accept timespec structures instead of v9stat Sripathi Kodi
@ 2010-06-03 15:17 ` Sripathi Kodi
1 sibling, 0 replies; 3+ messages in thread
From: Sripathi Kodi @ 2010-06-03 15:17 UTC (permalink / raw)
To: qemu-devel; +Cc: v9fs-developer
SYNOPSIS
size[4] Tsetattr tag[2] attr[n]
size[4] Rsetattr tag[2]
DESCRIPTION
The setattr command changes some of the file status information.
attr resembles the iattr structure used in Linux kernel. It
specifies which status parameter is to be changed and to what
value. It is laid out as follows:
valid[4]
specifies which status information is to be changed. Possible
values are:
ATTR_MODE (1 << 0)
ATTR_UID (1 << 1)
ATTR_GID (1 << 2)
ATTR_SIZE (1 << 3)
ATTR_ATIME (1 << 4)
ATTR_MTIME (1 << 5)
mode[4]
File permission bits
uid[4]
Owner id of file
gid[4]
Group id of the file
size[8]
File size
atime_sec[8]
Time of last file access, seconds
atime_nsec[8]
Time of last file access, nanoseconds
mtime_sec[8]
Time of last file modification, seconds
mtime_nsec[8]
Time of last file modification, nanoseconds
Explanation of the patches:
--------------------------
*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
structure and passes it down to the client. The only check it has is calling
inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters because
I don't think these are needed in our case.
*) The server currently supports changing mode, time, ownership and size of the
file.
*) 9P RFC says "Either all the changes in wstat request happen, or none of them
does: if the request succeeds, all changes were made; if it fails, none were."
I have not implemented this as I think this is not needed.
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
hw/virtio-9p.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/virtio-9p.h | 23 +++++++++
2 files changed, 160 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 8c1cdfb..a51f5ac 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -662,6 +662,15 @@ static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
&statp->n_muid);
break;
}
+ case 'I': {
+ V9fsIattr *iattr = va_arg(ap, V9fsIattr *);
+ offset += pdu_unmarshal(pdu, offset, "ddddqqqqq",
+ &iattr->valid, &iattr->mode,
+ &iattr->uid, &iattr->gid, &iattr->size,
+ &iattr->atime_sec, &iattr->atime_nsec,
+ &iattr->mtime_sec, &iattr->mtime_nsec);
+ break;
+ }
default:
break;
}
@@ -1208,6 +1217,133 @@ out:
qemu_free(vs);
}
+/* From Linux kernel code */
+#define ATTR_MODE (1 << 0)
+#define ATTR_UID (1 << 1)
+#define ATTR_GID (1 << 2)
+#define ATTR_SIZE (1 << 3)
+#define ATTR_ATIME (1 << 4)
+#define ATTR_MTIME (1 << 5)
+
+static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
+ int err)
+{
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
+ err = vs->offset;
+
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_setattr_post_chown(V9fsState *s, V9fsSetattrState *vs, int err)
+{
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
+
+ if (vs->v9iattr.valid & (ATTR_SIZE)) {
+ err = v9fs_do_truncate(s, &vs->fidp->path, vs->v9iattr.size);
+ }
+ v9fs_setattr_post_truncate(s, vs, err);
+ return;
+
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_setattr_post_utimensat(V9fsState *s, V9fsSetattrState *vs,
+ int err)
+{
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
+
+ if (vs->v9iattr.valid & (ATTR_UID | ATTR_GID)) {
+ if (! (vs->v9iattr.valid & ATTR_UID)) {
+ vs->v9iattr.uid = -1;
+ }
+ if (! (vs->v9iattr.valid & ATTR_GID)) {
+ vs->v9iattr.gid = -1;
+ }
+ err = v9fs_do_chown(s, &vs->fidp->path, vs->v9iattr.uid,
+ vs->v9iattr.gid);
+ }
+ v9fs_setattr_post_chown(s, vs, err);
+ return;
+
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_setattr_post_chmod(V9fsState *s, V9fsSetattrState *vs, int err)
+{
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
+
+ if (vs->v9iattr.valid & (ATTR_ATIME | ATTR_MTIME)) {
+ struct timespec times[2];
+ if (vs->v9iattr.valid & ATTR_ATIME) {
+ times[0].tv_sec = vs->v9iattr.atime_sec;
+ times[0].tv_nsec = vs->v9iattr.atime_nsec;
+ } else {
+ times[0].tv_nsec = UTIME_OMIT;
+ }
+ if (vs->v9iattr.valid & ATTR_MTIME) {
+ times[1].tv_sec = vs->v9iattr.mtime_sec;
+ times[1].tv_nsec = vs->v9iattr.mtime_nsec;
+ } else {
+ times[1].tv_nsec = UTIME_OMIT;
+ }
+ err = v9fs_do_utimensat(s, &vs->fidp->path, times);
+ }
+ v9fs_setattr_post_utimensat(s, vs, err);
+ return;
+
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_setattr(V9fsState *s, V9fsPDU *pdu)
+{
+ int32_t fid;
+ V9fsSetattrState *vs;
+ int err = 0;
+
+ vs = qemu_malloc(sizeof(*vs));
+ vs->pdu = pdu;
+ vs->offset = 7;
+
+ pdu_unmarshal(pdu, vs->offset, "dI", &fid, &vs->v9iattr);
+
+ vs->fidp = lookup_fid(s, fid);
+ if (vs->fidp == NULL) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ if (vs->v9iattr.valid & ATTR_MODE) {
+ err = v9fs_do_chmod(s, &vs->fidp->path, vs->v9iattr.mode);
+ }
+
+ v9fs_setattr_post_chmod(s, vs, err);
+ return;
+
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
static void v9fs_walk_complete(V9fsState *s, V9fsWalkState *vs, int err)
{
complete_pdu(s, vs->pdu, err);
@@ -2507,6 +2643,7 @@ static pdu_handler_t *pdu_handlers[] = {
[P9_TREADDIR] = v9fs_readdir,
[P9_TSTATFS] = v9fs_statfs,
[P9_TGETATTR] = v9fs_getattr,
+ [P9_TSETATTR] = v9fs_setattr,
[P9_TSYMLINK] = v9fs_symlink,
[P9_TVERSION] = v9fs_version,
[P9_TATTACH] = v9fs_attach,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index d033271..dafbd06 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -19,6 +19,8 @@ enum {
P9_RSYMLINK,
P9_TGETATTR = 24,
P9_RGETATTR,
+ P9_TSETATTR = 26,
+ P9_RSETATTR,
P9_TREADDIR = 40,
P9_RREADDIR,
P9_TLINK = 70,
@@ -280,6 +282,27 @@ typedef struct V9fsWstatState
V9fsString nname;
} V9fsWstatState;
+typedef struct V9fsIattr
+{
+ int32_t valid;
+ int32_t mode;
+ int32_t uid;
+ int32_t gid;
+ int64_t size;
+ int64_t atime_sec;
+ int64_t atime_nsec;
+ int64_t mtime_sec;
+ int64_t mtime_nsec;
+} V9fsIattr;
+
+typedef struct V9fsSetattrState
+{
+ V9fsPDU *pdu;
+ size_t offset;
+ V9fsIattr v9iattr;
+ V9fsFidState *fidp;
+} V9fsSetattrState;
+
typedef struct V9fsSymlinkState
{
V9fsPDU *pdu;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-03 15:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-03 15:16 [Qemu-devel] [PATCH 0/2] virtio-9p: Setattr for 9P2000.L Sripathi Kodi
2010-06-03 15:16 ` [Qemu-devel] [PATCH 1/2] Make v9fs_do_utimensat accept timespec structures instead of v9stat Sripathi Kodi
2010-06-03 15:17 ` [Qemu-devel] [PATCH 2/2] virtio-9p: Implement server side of setattr for 9P2000.L protocol Sripathi Kodi
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).