From patchwork Thu Mar 25 16:43:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 48571 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 92B0FB7BFA for ; Fri, 26 Mar 2010 05:12:26 +1100 (EST) Received: from localhost ([127.0.0.1]:42005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NurXa-0000kW-FS for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 14:12:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuqAo-0007GT-7D for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:46 -0400 Received: from [140.186.70.92] (port=50687 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuqAg-0007FA-96 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuqAb-0005Br-Jz for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:37 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:51734) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuqAb-0005BZ-2p for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:33 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp06.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2PGiLMC021515 for ; Fri, 26 Mar 2010 03:44:21 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PGcTYJ1634354 for ; Fri, 26 Mar 2010 03:38:29 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PGiVrw031632 for ; Fri, 26 Mar 2010 03:44:31 +1100 Received: from localhost.localdomain ([9.77.125.24]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2PGhgOv030935; Fri, 26 Mar 2010 03:44:29 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 25 Mar 2010 22:13:30 +0530 Message-Id: <1269535420-31206-23-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.323.g0d092 In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH -V3 22/32] virtio-9p: Update existing fid path on rename 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 We need to make sure that we update the path component of the existing fid's when we rename a file. The client is not expected to clunk these fids pointing to the old name. If we don't update any operation on the old unopened fid will point to the old name and will fail Add BUG_ON to make sure when we clone a fid, we don't have open descriptor attached to the fid. We also need to make sure that when we open a fid, the specified fid should not already be opened. Capture the case by adding a BUG_ON Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index c8ab6b6..9aa4b72 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -955,6 +955,9 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu) /* FIXME: is this really valid? */ if (fid == newfid) { + + BUG_ON(vs->fidp->fd != -1); + BUG_ON(vs->fidp->dir); v9fs_string_init(&vs->path); vs->name_idx = 0; @@ -1120,6 +1123,9 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu) goto out; } + BUG_ON(vs->fidp->fd != -1); + BUG_ON(vs->fidp->dir); + err = posix_lstat(s, &vs->fidp->path, &vs->stbuf); v9fs_open_post_lstat(s, vs, err); @@ -1877,8 +1883,19 @@ out: qemu_free(vs); } +static void v9fs_fix_path(V9fsString *dst, V9fsString *src, int len) +{ + V9fsString str; + v9fs_string_init(&str); + v9fs_string_copy(&str, dst); + v9fs_string_sprintf(dst, "%s%s", src->data, str.data+len); + v9fs_string_free(&str); +} + + static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err) { + V9fsFidState *fidp; if (err < 0) { goto out; } @@ -1905,6 +1922,28 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err) if (strcmp(new_name, vs->fidp->path.data) != 0) { if (posix_rename(s, &vs->fidp->path, &vs->nname)) { err = -errno; + } else { + /* + * Fixup fid's pointing to the old name to + * start pointing to the new name + */ + for (fidp = s->fid_list; fidp; fidp = fidp->next) { + + if (vs->fidp == fidp) { + /* + * we replace name of this fid towards the end + * so that our below strcmp will work + */ + continue; + } + if (!strncmp(vs->fidp->path.data, fidp->path.data, + strlen(vs->fidp->path.data))) { + /* replace the name */ + v9fs_fix_path(&fidp->path, &vs->nname, + strlen(vs->fidp->path.data)); + } + } + v9fs_string_copy(&vs->fidp->path, &vs->nname); } } }