From patchwork Mon Jun 6 17:49:12 2011 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: 99039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A367EB6F8E for ; Tue, 7 Jun 2011 07:05:14 +1000 (EST) Received: from localhost ([::1]:36239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTgz0-0000Kl-VB for incoming@patchwork.ozlabs.org; Mon, 06 Jun 2011 17:05:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:56249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTdva-0000NQ-H2 for qemu-devel@nongnu.org; Mon, 06 Jun 2011 13:49:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTdvY-0003hy-J6 for qemu-devel@nongnu.org; Mon, 06 Jun 2011 13:49:26 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:50618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTdvX-0003hk-Qy for qemu-devel@nongnu.org; Mon, 06 Jun 2011 13:49:24 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp08.au.ibm.com (8.14.4/8.13.1) with ESMTP id p56HiElk023122 for ; Tue, 7 Jun 2011 03:44:14 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p56HmXPR1052926 for ; Tue, 7 Jun 2011 03:48:33 +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 p56HnLgJ010129 for ; Tue, 7 Jun 2011 03:49:22 +1000 Received: from skywalker.in.ibm.com ([9.79.216.200]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p56HnHb2010047; Tue, 7 Jun 2011 03:49:20 +1000 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2011 23:19:12 +0530 Message-Id: <1307382555-3907-2-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1307382555-3907-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1307382555-3907-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) X-Received-From: 202.81.31.141 Cc: aliguori@us.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 2/5] 9p: add 9P2000.L unlinkat operation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org unlinkat - Remove a directory entry size[4] Tunlinkat tag[2] dirfid[4] name[s] flag[4] size[4] Runlinkat tag[2] older Tremove have the below request format size[4] Tremove tag[2] fid[4] The remove message is used to remove a directory entry either file or directory The remove opreation is actually a directory opertation and should ideally have dirfid, if not we cannot represent the fid on server with anything other than name. We will have to derive the directory name from fid in the Tremove request. NOTE: The operation doesn't clunk the unlink fid. Signed-off-by: Aneesh Kumar K.V --- fsdev/file-op-9p.h | 1 + hw/9pfs/cofs.c | 16 ++++++++++++++++ hw/9pfs/virtio-9p-coth.h | 1 + hw/9pfs/virtio-9p-local.c | 16 ++++++++++++++++ hw/9pfs/virtio-9p.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p.h | 2 ++ 6 files changed, 80 insertions(+), 0 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index c73ee4e..3bab550 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -104,6 +104,7 @@ typedef struct FileOperations int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, V9fsPath *newdir, const char *new_name); + int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); void *opaque; } FileOperations; diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c index 44f3ac5..233597b 100644 --- a/hw/9pfs/cofs.c +++ b/hw/9pfs/cofs.c @@ -184,6 +184,22 @@ int v9fs_co_remove(V9fsState *s, V9fsPath *path) return err; } +int v9fs_co_unlinkat(V9fsState *s, V9fsPath *path, V9fsString *name, int flags) +{ + int err; + + qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_co_run_in_worker( + { + err = s->ops->unlinkat(&s->ctx, path, name->data, flags); + if (err < 0) { + err = -errno; + } + }); + qemu_co_rwlock_unlock(&s->rename_lock); + return err; +} + /* Only work with path name based fid */ int v9fs_co_rename(V9fsState *s, V9fsPath *oldpath, V9fsPath *newpath) { diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h index d38553a..cd94571 100644 --- a/hw/9pfs/virtio-9p-coth.h +++ b/hw/9pfs/virtio-9p-coth.h @@ -77,6 +77,7 @@ extern int v9fs_co_mkdir(V9fsState *, V9fsFidState *, V9fsString *, mode_t, uid_t, gid_t, struct stat *); extern int v9fs_co_remove(V9fsState *, V9fsPath *); extern int v9fs_co_rename(V9fsState *, V9fsPath *, V9fsPath *); +extern int v9fs_co_unlinkat(V9fsState *, V9fsPath *, V9fsString *, int flags); extern int v9fs_co_renameat(V9fsState *, V9fsPath *, V9fsString *, V9fsPath *, V9fsString *); extern int v9fs_co_fstat(V9fsState *, int, struct stat *); diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index a38c619..37be2d5 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -631,6 +631,21 @@ static int local_renameat(FsContext *ctx, V9fsPath *olddir, return ret; } +static int local_unlinkat(FsContext *ctx, V9fsPath *dir, + const char *name, int flags) +{ + int ret; + V9fsString fullname; + char buffer[PATH_MAX]; + v9fs_string_init(&fullname); + + v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name); + ret = remove(rpath(ctx, fullname.data, buffer)); + v9fs_string_free(&fullname); + + return ret; +} + FileOperations local_ops = { .lstat = local_lstat, .readlink = local_readlink, @@ -664,4 +679,5 @@ FileOperations local_ops = { .lremovexattr = local_lremovexattr, .name_to_path = local_name_to_path, .renameat = local_renameat, + .unlinkat = local_unlinkat, }; diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 9127873..bc77387 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -2378,6 +2378,49 @@ out_nofid: complete_pdu(pdu->s, pdu, err); } +static void v9fs_unlinkat(void *opaque) +{ + int err = 0; + V9fsString name; + int32_t dfid, flags; + size_t offset = 7; + V9fsPath path; + V9fsFidState *dfidp; + V9fsPDU *pdu = opaque; + + pdu_unmarshal(pdu, offset, "dsd", &dfid, &name, &flags); + + dfidp = get_fid(pdu->s, dfid); + if (dfidp == NULL) { + err = -EINVAL; + goto out_nofid; + } + /* + * IF the file is unlinked, we cannot reopen + * the file later. So don't reclaim fd + */ + v9fs_path_init(&path); + err = v9fs_co_name_to_path(pdu->s, &dfidp->path, name.data, &path); + if (err < 0) { + goto out_err; + } + err = v9fs_mark_fids_unreclaim(pdu->s, &path); + if (err < 0) { + goto out_err; + } + err = v9fs_co_unlinkat(pdu->s, &dfidp->path, &name, flags); + if (!err) { + err = offset; + } +out_err: + put_fid(pdu->s, dfidp); + v9fs_path_free(&path); + v9fs_string_free(&name); +out_nofid: + complete_pdu(pdu->s, pdu, err); +} + + /* Only works with path name based fid */ static int v9fs_complete_rename(V9fsState *s, V9fsFidState *fidp, int32_t newdirfid, V9fsString *name) @@ -3058,6 +3101,7 @@ static CoroutineEntry *pdu_co_handlers[] = { [P9_TGETLOCK] = v9fs_getlock, [P9_TRENAMEAT] = v9fs_renameat, [P9_TREADLINK] = v9fs_readlink, + [P9_TUNLINKAT] = v9fs_unlinkat, [P9_TMKDIR] = v9fs_mkdir, [P9_TVERSION] = v9fs_version, [P9_TLOPEN] = v9fs_open, diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 8156568..23a0a5e 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -54,6 +54,8 @@ enum { P9_RMKDIR, P9_TRENAMEAT = 74, P9_RRENAMEAT, + P9_TUNLINKAT = 76, + P9_RUNLINKAT, P9_TVERSION = 100, P9_RVERSION, P9_TAUTH = 102,