From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF388-0008E8-8M for qemu-devel@nongnu.org; Wed, 27 Apr 2011 07:42:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QF384-0005fp-8g for qemu-devel@nongnu.org; Wed, 27 Apr 2011 07:42:04 -0400 Received: from mail-ww0-f67.google.com ([74.125.82.67]:34873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF384-0005fb-42 for qemu-devel@nongnu.org; Wed, 27 Apr 2011 07:42:00 -0400 Received: by wwa36 with SMTP id 36so210301wwa.10 for ; Wed, 27 Apr 2011 04:41:58 -0700 (PDT) From: Sassan Panahinejad Date: Wed, 27 Apr 2011 12:41:44 +0100 Message-Id: <1303904504-8729-1-git-send-email-sassan@sassan.me.uk> In-Reply-To: <4DB7354D.4040005@linux.vnet.ibm.com> References: <4DB7354D.4040005@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] Fix bug with virtio-9p fsync List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Sassan Panahinejad , jvrao@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com JV: I hope I have correctly understood your description of how lock/getlock should behave. v9fs_fsync and possibly others break when asked to operate on a directory. It does not check fid_type to see if it is operating on a directory and therefore accesses the wrong element of the fs union. This error can result in guest applications failing (in my case it was dpkg). This patch fixes the issue and implements correct behaviour for fsync, wstat, lock and getlock. Signed-off-by: Sassan Panahinejad --- hw/virtio-9p.c | 36 ++++++++++++++++++++++++++++++++---- 1 files changed, 32 insertions(+), 4 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 7e29535..2530f6d 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1875,7 +1875,13 @@ static void v9fs_fsync(V9fsState *s, V9fsPDU *pdu) v9fs_post_do_fsync(s, pdu, err); return; } - err = v9fs_do_fsync(s, fidp->fs.fd, datasync); + if (fidp->fid_type == P9_FID_FILE) { + err = v9fs_do_fsync(s, fidp->fs.fd, datasync); + } else if (fidp->fid_type == P9_FID_DIR) { + err = v9fs_do_fsync(s, dirfd(fidp->fs.dir), datasync); + } else { + err = -EINVAL; + } v9fs_post_do_fsync(s, pdu, err); } @@ -2999,7 +3005,13 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu) /* do we need to sync the file? */ if (donttouch_stat(&vs->v9stat)) { - err = v9fs_do_fsync(s, vs->fidp->fs.fd, 0); + if (vs->fidp->fid_type == P9_FID_FILE) { + err = v9fs_do_fsync(s, vs->fidp->fs.fd, 0); + } else if (vs->fidp->fid_type == P9_FID_DIR) { + err = v9fs_do_fsync(s, dirfd(vs->fidp->fs.dir), 0); + } else { + err = -EINVAL; + } v9fs_wstat_post_fsync(s, vs, err); return; } @@ -3199,7 +3211,15 @@ static void v9fs_lock(V9fsState *s, V9fsPDU *pdu) goto out; } - err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); + if (vs->fidp->fid_type == P9_FID_FILE) { + err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); + } else if (vs->fidp->fid_type == P9_FID_DIR) { + err = -EISDIR; + goto out; + } else { + err = -EINVAL; + goto out; + } if (err < 0) { err = -errno; goto out; @@ -3237,7 +3257,15 @@ static void v9fs_getlock(V9fsState *s, V9fsPDU *pdu) goto out; } - err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); + if (vs->fidp->fid_type == P9_FID_FILE) { + err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); + } else if (vs->fidp->fid_type == P9_FID_DIR) { + err = -EISDIR; + goto out; + } else { + err = -EINVAL; + goto out; + } if (err < 0) { err = -errno; goto out; -- 1.7.0.4