From patchwork Mon Jun 28 21:55:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 57203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 20356B6EE9 for ; Tue, 29 Jun 2010 08:06:13 +1000 (EST) Received: from localhost ([127.0.0.1]:52372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTMSs-0004pe-13 for incoming@patchwork.ozlabs.org; Mon, 28 Jun 2010 18:06:06 -0400 Received: from [140.186.70.92] (port=59010 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTMF2-00055o-JE for qemu-devel@nongnu.org; Mon, 28 Jun 2010 17:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTMF0-0006oR-OR for qemu-devel@nongnu.org; Mon, 28 Jun 2010 17:51:48 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:48139) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OTMF0-0006oB-EB for qemu-devel@nongnu.org; Mon, 28 Jun 2010 17:51:46 -0400 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e35.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o5SLiFJg026783 for ; Mon, 28 Jun 2010 15:44:16 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5SLpf5M124864 for ; Mon, 28 Jun 2010 15:51:43 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5SLpfHH026677 for ; Mon, 28 Jun 2010 15:51:41 -0600 Received: from localhost.localdomain (elm9m80.beaverton.ibm.com [9.47.81.80]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o5SLpX88026203; Mon, 28 Jun 2010 15:51:41 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Mon, 28 Jun 2010 14:55:09 -0700 Message-Id: <1277762117-11212-12-git-send-email-jvrao@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1277762117-11212-1-git-send-email-jvrao@linux.vnet.ibm.com> References: <1277762117-11212-1-git-send-email-jvrao@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: aliguori@us.ibm.com, "Venkateswararao Jujjuri \(JV\)" Subject: [Qemu-devel] [PATCH 12/20] [virtio-9p] This patch implements TLCREATE for 9p2000.L protocol. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org SYNOPSIS size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4] size[4] Rlcreate tag[2] qid[13] iounit[4] DESCRIPTION The Tlreate request asks the file server to create a new regular file with the name supplied, in the directory (dir) represented by fid. The mode argument specifies the permissions to use. New file is created with the uid if the fid and with supplied gid. The flags argument represent Linux access mode flags with which the caller is requesting to open the file with. Protocol allows all the Linux access modes but it is upto the server to allow/disallow any of these acess modes. If the server doesn't support any of the access mode, it is expected to return error. To start with we will not restricit/limit any Linux flags on this server. If needed, We can start restricting as we move forward with various use cases. Signed-off-by: Venkateswararao Jujjuri --- hw/virtio-9p-debug.c | 13 ++++++ hw/virtio-9p.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++--- hw/virtio-9p.h | 13 ++++++ 3 files changed, 119 insertions(+), 7 deletions(-) diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c index e389959..a9680df 100644 --- a/hw/virtio-9p-debug.c +++ b/hw/virtio-9p-debug.c @@ -473,6 +473,19 @@ void pprint_pdu(V9fsPDU *pdu) fprintf(llogfile, "RSYMLINK: ("); pprint_qid(pdu, 1, &offset, "qid"); break; + case P9_TLCREATE: + fprintf(llogfile, "TLCREATE: ("); + pprint_int32(pdu, 0, &offset, "dfid"); + pprint_str(pdu, 0, &offset, ", name"); + pprint_int32(pdu, 0, &offset, ", flags"); + pprint_int32(pdu, 0, &offset, ", mode"); + pprint_int32(pdu, 0, &offset, ", gid"); + break; + case P9_RLCREATE: + fprintf(llogfile, "RLCREATE: ("); + pprint_qid(pdu, 1, &offset, "qid"); + pprint_int32(pdu, 1, &offset, ", iounit"); + break; case P9_TREAD: fprintf(llogfile, "TREAD: ("); pprint_int32(pdu, 0, &offset, "fid"); diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 60ad0fb..4073551 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -187,17 +187,18 @@ static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf) return s->ops->fstat(&s->ctx, fd, stbuf); } -static int v9fs_do_open2(V9fsState *s, V9fsCreateState *vs) +static int v9fs_do_open2(V9fsState *s, char *fullname, uid_t uid, gid_t gid, + int flags, int mode) { FsCred cred; - int flags; cred_init(&cred); - cred.fc_uid = vs->fidp->uid; - cred.fc_mode = vs->perm & 0777; - flags = omode_to_uflags(vs->mode) | O_CREAT; + cred.fc_uid = uid; + cred.fc_gid = gid; + cred.fc_mode = mode & 0777; + flags = flags; - return s->ops->open2(&s->ctx, vs->fullname.data, flags, &cred); + return s->ops->open2(&s->ctx, fullname, flags, &cred); } static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp, @@ -1641,6 +1642,88 @@ out: qemu_free(vs); } +static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err) +{ + if (err == 0) { + v9fs_string_copy(&vs->fidp->path, &vs->fullname); + stat_to_qid(&vs->stbuf, &vs->qid); + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, + &vs->iounit); + err = vs->offset; + } else { + err = -errno; + } + + complete_pdu(s, vs->pdu, err); + v9fs_string_free(&vs->name); + v9fs_string_free(&vs->fullname); + qemu_free(vs); +} + +static void v9fs_lcreate_post_get_iounit(V9fsState *s, V9fsLcreateState *vs, + int err) +{ + if (err) { + err = -errno; + goto out; + } + err = v9fs_do_lstat(s, &vs->fullname, &vs->stbuf); + +out: + v9fs_post_lcreate(s, vs, err); +} + +static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs, + int err) +{ + if (vs->fidp->fd == -1) { + err = -errno; + goto out; + } + vs->iounit = get_iounit(s, &vs->fullname); + v9fs_lcreate_post_get_iounit(s, vs, err); + return; + +out: + v9fs_post_lcreate(s, vs, err); +} + +static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu) +{ + int32_t dfid, flags, mode; + gid_t gid; + V9fsLcreateState *vs; + ssize_t err = 0; + + vs = qemu_malloc(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + v9fs_string_init(&vs->fullname); + + pdu_unmarshal(vs->pdu, vs->offset, "dsddd", &dfid, &vs->name, &flags, + &mode, &gid); + + vs->fidp = lookup_fid(s, dfid); + if (vs->fidp == NULL) { + err = -ENOENT; + goto out; + } + + v9fs_string_sprintf(&vs->fullname, "%s/%s", vs->fidp->path.data, + vs->name.data); + + vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid, + gid, flags, mode); + v9fs_lcreate_post_do_open2(s, vs, err); + return; + +out: + complete_pdu(s, vs->pdu, err); + v9fs_string_free(&vs->name); + qemu_free(vs); +} + static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu) { int32_t fid; @@ -2228,7 +2311,9 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs->perm & 0777), 0); v9fs_post_create(s, vs, err); } else { - vs->fidp->fd = v9fs_do_open2(s, vs); + vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid, + -1, omode_to_uflags(vs->mode)|O_CREAT, vs->perm); + v9fs_create_post_open2(s, vs, err); } @@ -2756,6 +2841,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TLINK] = v9fs_link, [P9_TSYMLINK] = v9fs_symlink, [P9_TCREATE] = v9fs_create, + [P9_TLCREATE] = v9fs_lcreate, [P9_TWRITE] = v9fs_write, [P9_TWSTAT] = v9fs_wstat, [P9_TREMOVE] = v9fs_remove, diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 90ff58c..dc428c1 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -15,6 +15,8 @@ enum { P9_TSTATFS = 8, P9_RSTATFS, + P9_TLCREATE = 14, + P9_RLCREATE, P9_TSYMLINK = 16, P9_RSYMLINK, P9_TGETATTR = 24, @@ -185,6 +187,17 @@ typedef struct V9fsCreateState { int iounit; } V9fsCreateState; +typedef struct V9fsLcreateState { + V9fsPDU *pdu; + size_t offset; + V9fsFidState *fidp; + V9fsQID qid; + int32_t iounit; + struct stat stbuf; + V9fsString name; + V9fsString fullname; +} V9fsLcreateState; + typedef struct V9fsStatState { V9fsPDU *pdu; size_t offset;