[Qemu-devel] [PATCH] virtio-9p: getattr server implementation for 9P2000.L protocol.

2010-07-12 Thread Sripathi Kodi
From: M. Mohan Kumar mo...@in.ibm.com

This is a new version of getattr patch for 9P2000.L that I posted some
time ago. This version adds 3 fields to the on-the-wire data:
file creation time
generation number
data version

It also adds a bit field to indicate which fields of the structure have
valid data. Usually the server fills in at least all the basic fields, but
it may fill in the additional fields if possible. The server will use
the bit field to tell the client which fields it has populated. Currently
there is no clean way for the server to obtain these additional fields, so
it sends back just the basic fields.

The client (Linux kernel) patch corresponding to this is at
http://sourceforge.net/mailarchive/forum.php?thread_name=20100712143815.6665.35892.stgit%40localhost.localdomainforum_name=v9fs-developer

Comments welcome.


   SYNOPSIS

  size[4] Tgetattr tag[2] fid[4] request_mask[8]

  size[4] Rgetattr tag[2] lstat[n]

   DESCRIPTION

  The getattr transaction inquires about the file identified by fid.
  request_mask is a bit mask that specifies which fields of the
  stat structure is the client interested in.

  The reply will contain a machine-independent directory entry,
  laid out as follows:

 st_result_mask[8]
Bit mask that indicates which fields in the stat structure
have been populated by the server

 qid.type[1]
the type of the file (directory, etc.), represented as a bit
vector corresponding to the high 8 bits of the file's mode
word.

 qid.vers[4]
version number for given path

 qid.path[8]
the file server's unique identification for the file

 st_mode[4]
Permission and flags

 st_uid[4]
User id of owner

 st_gid[4]
Group ID of owner

 st_nlink[8]
Number of hard links

 st_rdev[8]
Device ID (if special file)

 st_size[8]
Size, in bytes

 st_blksize[8]
Block size for file system IO

 st_blocks[8]
Number of file system blocks allocated

 st_atime_sec[8]
Time of last access, seconds

 st_atime_nsec[8]
Time of last access, nanoseconds

 st_mtime_sec[8]
Time of last modification, seconds

 st_mtime_nsec[8]
Time of last modification, nanoseconds

 st_ctime_sec[8]
Time of last status change, seconds

 st_ctime_nsec[8]
Time of last status change, nanoseconds

 st_btime_sec[8]
Time of creation (birth) of file, seconds

 st_btime_nsec[8]
Time of creation (birth) of file, nanoseconds

 st_gen[8]
Inode generation

 st_data_version[8]
Data version number

  request_mask and result_mask bit masks contain the following bits
 #define P9_STATS_MODE  0x0001ULL
 #define P9_STATS_NLINK 0x0002ULL
 #define P9_STATS_UID   0x0004ULL
 #define P9_STATS_GID   0x0008ULL
 #define P9_STATS_RDEV  0x0010ULL
 #define P9_STATS_ATIME 0x0020ULL
 #define P9_STATS_MTIME 0x0040ULL
 #define P9_STATS_CTIME 0x0080ULL
 #define P9_STATS_INO   0x0100ULL
 #define P9_STATS_SIZE  0x0200ULL
 #define P9_STATS_BLOCKS0x0400ULL

 #define P9_STATS_BTIME 0x0800ULL
 #define P9_STATS_GEN   0x1000ULL
 #define P9_STATS_DATA_VERSION  0x2000ULL

 #define P9_STATS_BASIC 0x07ffULL
 #define P9_STATS_ALL   0x3fffULL


This patch implements the client side of getattr implementation for 
9P2000.L.
It introduces a new structure p9_stat_dotl for getting Linux stat 
information
along with QID. The data layout is similar to stat structure in Linux 
user
space with the following major differences:

inode (st_ino) is not part of data. Instead qid is.

device (st_dev) is not part of data because this doesn't make sense on 
the
client.

All time variables are 64 bit wide on the wire. The kernel seems to use

[Qemu-devel] [PATCH] virtio-9p: getattr server implementation for 9P2000.L protocol.

2010-05-28 Thread Sripathi Kodi
From: M. Mohan Kumar mo...@in.ibm.com

SYNOPSIS

  size[4] Tgetattr tag[2] fid[4]

  size[4] Rgetattr tag[2] lstat[n]

   DESCRIPTION

  The getattr transaction inquires about the file identified by fid.
  The reply will contain a machine-independent directory entry,
  laid out as follows:

 qid.type[1]
the type of the file (directory, etc.), represented as a bit
vector corresponding to the high 8 bits of the file's mode
word.

 qid.vers[4]
version number for given path

 qid.path[8]
the file server's unique identification for the file

 st_mode[4]
Permission and flags

 st_nlink[8]
Number of hard links

 st_uid[4]
User id of owner

 st_gid[4]
Group ID of owner

 st_rdev[8]
Device ID (if special file)

 st_size[8]
Size, in bytes

 st_blksize[8]
Block size for file system IO

 st_blocks[8]
Number of file system blocks allocated

 st_atime_sec[8]
Time of last access, seconds

 st_atime_nsec[8]
Time of last access, nanoseconds

 st_mtime_sec[8]
Time of last modification, seconds

 st_mtime_nsec[8]
Time of last modification, nanoseconds

 st_ctime_sec[8]
Time of last status change, seconds

 st_ctime_nsec[8]
Time of last status change, nanoseconds


This patch implements the client side of getattr implementation for 9P2000.L.
It introduces a new structure p9_stat_dotl for getting Linux stat information
along with QID. The data layout is similar to stat structure in Linux user
space with the following major differences:

inode (st_ino) is not part of data. Instead qid is.

device (st_dev) is not part of data because this doesn't make sense on the
client.

All time variables are 64 bit wide on the wire. The kernel seems to use
32 bit variables for these variables. However, some of the architectures
have used 64 bit variables and glibc exposes 64 bit variables to user
space on some architectures. Hence to be on the safer side we have made
these 64 bit in the protocol. Refer to the comments in
include/asm-generic/stat.h


Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
---

 hw/virtio-9p-debug.c |   32 
 hw/virtio-9p.c   |   82 ++
 hw/virtio-9p.h   |   28 +
 3 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index a82b771..8bb817d 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -178,6 +178,30 @@ static void pprint_stat(V9fsPDU *pdu, int rx, size_t 
*offsetp, const char *name)
 fprintf(llogfile, });
 }
 
+static void pprint_stat_dotl(V9fsPDU *pdu, int rx, size_t *offsetp,
+  const char *name)
+{
+fprintf(llogfile, %s={, name);
+pprint_qid(pdu, rx, offsetp, qid);
+pprint_int32(pdu, rx, offsetp, , st_mode);
+pprint_int64(pdu, rx, offsetp, , st_nlink);
+pprint_int32(pdu, rx, offsetp, , st_uid);
+pprint_int32(pdu, rx, offsetp, , st_gid);
+pprint_int64(pdu, rx, offsetp, , st_rdev);
+pprint_int64(pdu, rx, offsetp, , st_size);
+pprint_int64(pdu, rx, offsetp, , st_blksize);
+pprint_int64(pdu, rx, offsetp, , st_blocks);
+pprint_int64(pdu, rx, offsetp, , atime);
+pprint_int64(pdu, rx, offsetp, , atime_nsec);
+pprint_int64(pdu, rx, offsetp, , mtime);
+pprint_int64(pdu, rx, offsetp, , mtime_nsec);
+pprint_int64(pdu, rx, offsetp, , ctime);
+pprint_int64(pdu, rx, offsetp, , ctime_nsec);
+fprintf(llogfile, });
+}
+
+
+
 static void pprint_strs(V9fsPDU *pdu, int rx, size_t *offsetp, const char 
*name)
 {
 int sg_count = get_sg_count(pdu, rx);
@@ -351,6 +375,14 @@ void pprint_pdu(V9fsPDU *pdu)
 pprint_int32(pdu, 1, offset, msize);
 pprint_str(pdu, 1, offset, , version);
 break;
+case P9_TGETATTR:
+fprintf(llogfile, TGETATTR: ();
+pprint_int32(pdu, 0, offset, fid);
+break;
+case P9_RGETATTR:
+fprintf(llogfile, RGETATTR: ();
+pprint_stat_dotl(pdu, 1, offset, getattr);
+break;
 case P9_TAUTH:
 fprintf(llogfile, TAUTH: ();
 pprint_int32(pdu, 0, offset, afid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 097dce8..23ae8b8 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -737,6 +737,17 @@ static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, 
const char *fmt, ...)
 statp-n_gid, statp-n_muid);
 break;
 }
+case 'A': {
+V9fsStatDotl *statp = va_arg(ap, V9fsStatDotl *);
+offset += pdu_marshal(pdu, offset, Qdqddqq,
+