From patchwork Mon May 31 09:27:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "M. Mohan Kumar" X-Patchwork-Id: 103243 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4V9SMOd019148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 31 May 2010 09:28:58 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OJ1I5-00019j-T9; Mon, 31 May 2010 09:28:13 +0000 Received: from sfi-mx-3.v28.ch3.sourceforge.com ([172.29.28.123] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OJ1I4-00019W-VP for v9fs-developer@lists.sourceforge.net; Mon, 31 May 2010 09:28:12 +0000 Received-SPF: pass (sfi-mx-3.v28.ch3.sourceforge.com: domain of in.ibm.com designates 202.81.31.145 as permitted sender) client-ip=202.81.31.145; envelope-from=mohan@in.ibm.com; helo=e23smtp03.au.ibm.com; Received: from e23smtp03.au.ibm.com ([202.81.31.145]) by sfi-mx-3.v28.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) id 1OJ1I2-0005Az-Oi for v9fs-developer@lists.sourceforge.net; Mon, 31 May 2010 09:28:12 +0000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp03.au.ibm.com (8.14.4/8.13.1) with ESMTP id o4V9Obor016471 for ; Mon, 31 May 2010 19:24:37 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o4V9S3Nv970810 for ; Mon, 31 May 2010 19:28:03 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o4V9S294027464 for ; Mon, 31 May 2010 19:28:02 +1000 Received: from localhost.localdomain ([9.124.35.38]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o4V9S1jh027435; Mon, 31 May 2010 19:28:02 +1000 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org, v9fs-developer@lists.sourceforge.net Date: Mon, 31 May 2010 14:57:59 +0530 Message-Id: <1275298079-29141-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.6.6.1 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1OJ1I2-0005Az-Oi Subject: [V9fs-developer] [PATCH] qemu: virtio-9p: Implement TMKNOD X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 31 May 2010 09:28:58 +0000 (UTC) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index c217fa5..9307cc3 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -161,15 +161,16 @@ static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode) return s->ops->chmod(&s->ctx, path->data, &cred); } -static int v9fs_do_mknod(V9fsState *s, V9fsCreateState *vs, mode_t mode, - dev_t dev) +static int v9fs_do_mknod(V9fsState *s, char *name, + mode_t mode, dev_t dev, uid_t uid, gid_t gid) { FsCred cred; cred_init(&cred); - cred.fc_uid = vs->fidp->uid; + cred.fc_uid = uid; + cred.fc_gid = gid; cred.fc_mode = mode; cred.fc_rdev = dev; - return s->ops->mknod(&s->ctx, vs->fullname.data, &cred); + return s->ops->mknod(&s->ctx, name, &cred); } static int v9fs_do_mkdir(V9fsState *s, V9fsCreateState *vs) @@ -2043,13 +2044,16 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) } nmode |= vs->perm & 0777; - err = v9fs_do_mknod(s, vs, nmode, makedev(major, minor)); + err = v9fs_do_mknod(s, vs->fullname.data, nmode, + makedev(major, minor), vs->fidp->uid, -1); v9fs_create_post_perms(s, vs, err); } else if (vs->perm & P9_STAT_MODE_NAMED_PIPE) { - err = v9fs_do_mknod(s, vs, S_IFIFO | (vs->perm & 0777), 0); + err = v9fs_do_mknod(s, vs->fullname.data, S_IFIFO | (vs->perm & 0777), + 0, vs->fidp->uid, -1); v9fs_post_create(s, vs, err); } else if (vs->perm & P9_STAT_MODE_SOCKET) { - err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs->perm & 0777), 0); + err = v9fs_do_mknod(s, vs->fullname.data, S_IFSOCK | (vs->perm & 0777), + 0, vs->fidp->uid, -1); v9fs_post_create(s, vs, err); } else { vs->fidp->fd = v9fs_do_open2(s, vs); @@ -2461,12 +2465,70 @@ out: qemu_free(vs); } +static void v9fs_mknod_post_mknod(V9fsState *s, V9fsMknodState *vs, int err) +{ + if (err == -1) { + err = -errno; + goto out; + } + + err = v9fs_do_lstat(s, &vs->fullname, &vs->stbuf); + if (err == -1) { + err = -errno; + goto out; + } + stat_to_qid(&vs->stbuf, &vs->qid); + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Q", &vs->qid); + err = vs->offset; +out: + complete_pdu(s, vs->pdu, err); + v9fs_string_free(&vs->fullname); + v9fs_string_free(&vs->name); + qemu_free(vs); +} + +static void v9fs_mknod(V9fsState *s, V9fsPDU *pdu) +{ + int32_t fid; + V9fsMknodState *vs; + ssize_t err = 0; + V9fsFidState *fidp; + gid_t gid; + + vs = qemu_malloc(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + v9fs_string_init(&vs->fullname); + pdu_unmarshal(vs->pdu, vs->offset, "dsddd", &fid, &vs->name, &vs->mode, + &vs->rdev, &gid); + + fidp = lookup_fid(s, fid); + if (fidp == NULL) { + err = -ENOENT; + goto out; + } + + v9fs_string_sprintf(&vs->fullname, "%s/%s", fidp->path.data, vs->name.data); + err = v9fs_do_mknod(s, vs->fullname.data, vs->mode, vs->rdev, + fidp->uid, gid); + v9fs_mknod_post_mknod(s, vs, err); + return; + +out: + complete_pdu(s, vs->pdu, err); + v9fs_string_free(&vs->fullname); + v9fs_string_free(&vs->name); + qemu_free(vs); +} + typedef void (pdu_handler_t)(V9fsState *s, V9fsPDU *pdu); static pdu_handler_t *pdu_handlers[] = { [P9_TREADDIR] = v9fs_readdir, [P9_TSTATFS] = v9fs_statfs, [P9_TGETATTR] = v9fs_getattr, + [P9_TMKNOD] = v9fs_mknod, [P9_TVERSION] = v9fs_version, [P9_TATTACH] = v9fs_attach, [P9_TSTAT] = v9fs_stat, diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index cb0b0ed..9c4ab1d 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -15,6 +15,8 @@ enum { P9_TSTATFS = 8, P9_RSTATFS, + P9_TMKNOD = 18, + P9_RMKNOD, P9_TGETATTR = 24, P9_RGETATTR, P9_TREADDIR = 40, @@ -310,6 +312,17 @@ typedef struct V9fsStatStateDotl { struct stat stbuf; } V9fsStatStateDotl; +typedef struct V9fsMknodState { + V9fsPDU *pdu; + size_t offset; + V9fsQID qid; + int mode; + dev_t rdev; + struct stat stbuf; + V9fsString name; + V9fsString fullname; +} V9fsMknodState; + extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, size_t offset, size_t size, int pack);