Received: from [140.186.70.92] (port=47808 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OvA6O-0004rE-Br for qemu-devel@nongnu.org; Mon, 13 Sep 2010 10:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OvA4k-0004gC-Qy for qemu-devel@nongnu.org; Mon, 13 Sep 2010 10:32:08 -0400 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:33250) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OvA4k-0004fC-6P for qemu-devel@nongnu.org; Mon, 13 Sep 2010 10:32:06 -0400 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp08.in.ibm.com (8.14.4/8.13.1) with ESMTP id o8DEDIUj017907 for ; Mon, 13 Sep 2010 19:43:18 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8DEVwUu3395716 for ; Mon, 13 Sep 2010 20:01:59 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o8DEVwOg014679 for ; Tue, 14 Sep 2010 00:31:58 +1000 Received: from sripathi.in.ibm.com ([9.77.201.26]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o8DEVufv014594 for ; Tue, 14 Sep 2010 00:31:58 +1000 Received: from sripathi.in.ibm.com (sripathi.in.ibm.com [127.0.0.1]) by sripathi.in.ibm.com (Postfix) with ESMTP id 89EF426C2C for ; Mon, 13 Sep 2010 20:01:45 +0530 (IST) From: Sripathi Kodi Date: Mon, 13 Sep 2010 20:01:45 +0530 Message-ID: <20100913143145.14260.11537.stgit@sripathi.in.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] virtio-9p: open should not return EBADF List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org When 9P server fails to create a file due to permission problems it should return EPERM. However the current 9P2000.L code returns EBADF. EBADF is NOT a valid return value from open() call. The problem is because we do not preserve the errno variable properly. If the file open had failed, the call to close() on the fd in v9fs_post_lcreate() fails and sets errno to EBADF. We should preserve the errno that we got from open() and we should call close() only if we had a valid fd. Signed-off-by: Sripathi Kodi --- hw/virtio-9p.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 32fa3bc..fd2147e 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1758,8 +1758,10 @@ static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err) err = vs->offset; } else { vs->fidp->fid_type = P9_FID_NONE; - close(vs->fidp->fs.fd); err = -errno; + if (vs->fidp->fs.fd > 0) { + close(vs->fidp->fs.fd); + } } complete_pdu(s, vs->pdu, err);