From: "Aneesh Kumar K.V" Subject: [PATCH] tools/kvm/9p: Add error protocol reply Date: Sun, 19 Jun 2011 14:39:59 +0530 Message-ID: <1308474599-9832-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Cc: kvm@vger.kernel.org, "Aneesh Kumar K.V" To: penberg@kernel.org Return-path: Received: from e23smtp07.au.ibm.com ([202.81.31.140]:35968 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752713Ab1FSJKM (ORCPT ); Sun, 19 Jun 2011 05:10:12 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp07.au.ibm.com (8.14.4/8.13.1) with ESMTP id p5J9A3HJ025229 for ; Sun, 19 Jun 2011 19:10:03 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5J98vuu921626 for ; Sun, 19 Jun 2011 19:08:57 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5J9A2ja031063 for ; Sun, 19 Jun 2011 19:10:03 +1000 Sender: kvm-owner@vger.kernel.org List-ID: Add RERROR and use that in open on failure NOTE: All the protocol operation should handle like this. Signed-off-by: Aneesh Kumar K.V --- tools/kvm/virtio/9p.c | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index 558a713..0e885b5 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -209,6 +209,22 @@ static u16 virtio_p9_update_iov_cnt(struct iovec iov[], u32 count, int iov_cnt) return i; } +static void virtio_p9_error_reply(struct p9_dev *p9dev, + struct p9_pdu *pdu, int err, u32 *outlen) +{ + char *err_str; + struct p9_msg *inmsg = pdu->in_iov[0].iov_base; + struct p9_msg *outmsg = pdu->out_iov[0].iov_base; + struct p9_rerror *rerror = (struct p9_rerror *)inmsg->msg; + + err_str = strerror(err); + rerror->error.len = strlen(err_str); + memcpy(&rerror->error.str, err_str, rerror->error.len); + + *outlen = VIRTIO_P9_HDR_LEN + rerror->error.len + sizeof(u16); + set_p9msg_hdr(inmsg, *outlen, P9_RERROR, outmsg->tag); +} + static bool virtio_p9_version(struct p9_dev *p9dev, struct p9_pdu *pdu, u32 *outlen) { @@ -253,19 +269,26 @@ static bool virtio_p9_open(struct p9_dev *p9dev, struct p9_fid *new_fid = &p9dev->fids[topen->fid]; if (lstat(new_fid->abs_path, &st) < 0) - return false; + goto err_out; st2qid(&st, &ropen->qid); ropen->iounit = 0; - if (new_fid->is_dir) - new_fid->dir = opendir(new_fid->abs_path); - else - new_fid->fd = open(new_fid->abs_path, omode2uflags(topen->mode)); - + if (new_fid->is_dir) { + new_fid->dir = opendir(new_fid->abs_path); + if (!new_fid->dir) + goto err_out; + } else { + new_fid->fd = open(new_fid->abs_path, + omode2uflags(topen->mode) | O_NOFOLLOW); + if (new_fid->fd < 0) + goto err_out; + } *outlen = VIRTIO_P9_HDR_LEN + sizeof(*ropen); set_p9msg_hdr(inmsg, *outlen, P9_ROPEN, outmsg->tag); - + return true; +err_out: + virtio_p9_error_reply(p9dev, pdu, errno, outlen); return true; } -- 1.7.4.1