From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ericvh@gmail.com, aliguori@us.ibm.com, jvrao@linux.vnet.ibm.com,
aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH -V6 06/21] virtio-9p: Add fid and qid management support.
Date: Thu, 29 Apr 2010 17:44:48 +0530 [thread overview]
Message-ID: <1272543303-9830-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1272543303-9830-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
From: Anthony Liguori <aliguori@us.ibm.com>
Helper APIs for FID and QID management.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
hw/virtio-9p.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 7668e52..4467aea 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -176,6 +176,126 @@ static size_t v9fs_string_size(V9fsString *str)
return str->size;
}
+static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
+{
+ V9fsFidState *f;
+
+ for (f = s->fid_list; f; f = f->next) {
+ if (f->fid == fid) {
+ v9fs_do_setuid(s, f->uid);
+ return f;
+ }
+ }
+
+ return NULL;
+}
+
+static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
+{
+ V9fsFidState *f;
+
+ f = lookup_fid(s, fid);
+ if (f) {
+ return NULL;
+ }
+
+ f = qemu_mallocz(sizeof(V9fsFidState));
+
+ f->fid = fid;
+ f->fd = -1;
+ f->dir = NULL;
+
+ f->next = s->fid_list;
+ s->fid_list = f;
+
+ return f;
+}
+
+static int free_fid(V9fsState *s, int32_t fid)
+{
+ V9fsFidState **fidpp, *fidp;
+
+ for (fidpp = &s->fid_list; *fidpp; fidpp = &(*fidpp)->next) {
+ if ((*fidpp)->fid == fid) {
+ break;
+ }
+ }
+
+ if (*fidpp == NULL) {
+ return -ENOENT;
+ }
+
+ fidp = *fidpp;
+ *fidpp = fidp->next;
+
+ if (fidp->fd != -1) {
+ v9fs_do_close(s, fidp->fd);
+ }
+ if (fidp->dir) {
+ v9fs_do_closedir(s, fidp->dir);
+ }
+ v9fs_string_free(&fidp->path);
+ qemu_free(fidp);
+
+ return 0;
+}
+
+#define P9_QID_TYPE_DIR 0x80
+#define P9_QID_TYPE_SYMLINK 0x02
+
+#define P9_STAT_MODE_DIR 0x80000000
+#define P9_STAT_MODE_APPEND 0x40000000
+#define P9_STAT_MODE_EXCL 0x20000000
+#define P9_STAT_MODE_MOUNT 0x10000000
+#define P9_STAT_MODE_AUTH 0x08000000
+#define P9_STAT_MODE_TMP 0x04000000
+#define P9_STAT_MODE_SYMLINK 0x02000000
+#define P9_STAT_MODE_LINK 0x01000000
+#define P9_STAT_MODE_DEVICE 0x00800000
+#define P9_STAT_MODE_NAMED_PIPE 0x00200000
+#define P9_STAT_MODE_SOCKET 0x00100000
+#define P9_STAT_MODE_SETUID 0x00080000
+#define P9_STAT_MODE_SETGID 0x00040000
+#define P9_STAT_MODE_SETVTX 0x00010000
+
+#define P9_STAT_MODE_TYPE_BITS (P9_STAT_MODE_DIR | \
+ P9_STAT_MODE_SYMLINK | \
+ P9_STAT_MODE_LINK | \
+ P9_STAT_MODE_DEVICE | \
+ P9_STAT_MODE_NAMED_PIPE | \
+ P9_STAT_MODE_SOCKET)
+
+/* This is the algorithm from ufs in spfs */
+static void stat_to_qid(const struct stat *stbuf, V9fsQID *qidp)
+{
+ size_t size;
+
+ size = MIN(sizeof(stbuf->st_ino), sizeof(qidp->path));
+ memcpy(&qidp->path, &stbuf->st_ino, size);
+ qidp->version = stbuf->st_mtime ^ (stbuf->st_size << 8);
+ qidp->type = 0;
+ if (S_ISDIR(stbuf->st_mode)) {
+ qidp->type |= P9_QID_TYPE_DIR;
+ }
+ if (S_ISLNK(stbuf->st_mode)) {
+ qidp->type |= P9_QID_TYPE_SYMLINK;
+ }
+}
+
+static int fid_to_qid(V9fsState *s, V9fsFidState *fidp, V9fsQID *qidp)
+{
+ struct stat stbuf;
+ int err;
+
+ err = v9fs_do_lstat(s, &fidp->path, &stbuf);
+ if (err) {
+ return err;
+ }
+
+ stat_to_qid(&stbuf, qidp);
+ return 0;
+}
+
static V9fsPDU *alloc_pdu(V9fsState *s)
{
V9fsPDU *pdu = NULL;
@@ -477,6 +597,9 @@ static void v9fs_dummy(V9fsState *s, V9fsPDU *pdu)
(void) v9fs_do_readlink;
(void) v9fs_do_close;
(void) v9fs_do_closedir;
+ (void) alloc_fid;
+ (void) free_fid;
+ (void) fid_to_qid;
}
static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
--
1.7.0.4.360.g11766c
next prev parent reply other threads:[~2010-04-29 12:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-29 12:14 [Qemu-devel] [PATCH -V6 00/21] virtio-9p: paravirtual file system passthrough Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 01/21] virtio-9p: Create a commandline option -fsdev Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 02/21] virtio-9p: Add a virtio 9p device to qemu Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 03/21] virtio-9p: pdu processing support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 04/21] virtio-9p: Add string manipulation support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 05/21] virtio-9p: Add minimal set of FileOperations Aneesh Kumar K.V
2010-04-29 12:14 ` Aneesh Kumar K.V [this message]
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 07/21] virtio-9p: Add stat and mode related helper functions Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 08/21] virtio-9p: Add sg " Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 09/21] virtio-9p: Add P9_TVERSION support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 10/21] virtio-9p: Add P9_TATTACH support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 11/21] virtio-9p: Add P9_TSTAT support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 12/21] virtio-9p: Add P9_TWALK support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 13/21] virtio-9p: Add P9_TOPEN support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 14/21] virtio-9p: Add P9_TREAD support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 15/21] virtio-9p: Add P9_TCLUNK support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 16/21] virtio-9p: Add P9_TWRITE support Aneesh Kumar K.V
2010-04-29 12:14 ` [Qemu-devel] [PATCH -V6 17/21] virtio-9p: Add P9_TCREATE support Aneesh Kumar K.V
2010-04-29 12:15 ` [Qemu-devel] [PATCH -V6 18/21] virtio-9p: Add P9_TWSTAT support Aneesh Kumar K.V
2010-04-29 12:15 ` [Qemu-devel] [PATCH -V6 19/21] virtio-9p: Add P9_TREMOVE support Aneesh Kumar K.V
2010-04-29 12:15 ` [Qemu-devel] [PATCH -V6 20/21] virtio-9p: Add P9_TFLUSH support Aneesh Kumar K.V
2010-04-29 12:15 ` [Qemu-devel] [PATCH -V6 21/21] virtio-9p: Create a syntactic shortcut for the file-system pass-thru Aneesh Kumar K.V
2010-05-03 17:29 ` [Qemu-devel] [PATCH -V6 00/21] virtio-9p: paravirtual file system passthrough Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1272543303-9830-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=ericvh@gmail.com \
--cc=jvrao@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).