From patchwork Thu Aug 4 10:06:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsh Prateek Bora X-Patchwork-Id: 108403 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 94716B6F7C for ; Thu, 4 Aug 2011 20:07:44 +1000 (EST) Received: from localhost ([::1]:36576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qouq5-0001Je-8t for incoming@patchwork.ozlabs.org; Thu, 04 Aug 2011 06:07:41 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qoupz-0001JI-1Z for qemu-devel@nongnu.org; Thu, 04 Aug 2011 06:07:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qoupw-00058l-LB for qemu-devel@nongnu.org; Thu, 04 Aug 2011 06:07:35 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:52597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qoupv-00058M-TX for qemu-devel@nongnu.org; Thu, 04 Aug 2011 06:07:32 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp06.au.ibm.com (8.14.4/8.13.1) with ESMTP id p74A6elw022625 for ; Thu, 4 Aug 2011 20:06:40 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p74A5PtX741484 for ; Thu, 4 Aug 2011 20:05:26 +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 p74A6EMV000685 for ; Thu, 4 Aug 2011 20:06:14 +1000 Received: from harshbora.in.ibm.com ([9.124.46.158]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p74A6Cqu000643; Thu, 4 Aug 2011 20:06:13 +1000 From: Harsh Prateek Bora To: qemu-devel@nongnu.org Date: Thu, 4 Aug 2011 15:36:10 +0530 Message-Id: <1312452371-10375-2-git-send-email-harsh@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: <1312452371-10375-1-git-send-email-harsh@linux.vnet.ibm.com> References: <1312452371-10375-1-git-send-email-harsh@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.148 Cc: aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1/2] i_generation / st_gen support for local fs type 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 This patch provides support for st_gen for local fs type server. Currently the support is provided for ext4, btrfs, reiserfs and xfs. Signed-off-by: Harsh Prateek Bora --- fsdev/file-op-9p.h | 7 +++++++ hw/9pfs/cofile.c | 22 ++++++++++++++++++++++ hw/9pfs/virtio-9p-coth.h | 2 ++ hw/9pfs/virtio-9p-device.c | 1 + hw/9pfs/virtio-9p-local.c | 32 +++++++++++++++++++++++++++++++- hw/9pfs/virtio-9p.c | 9 +++++++++ 6 files changed, 72 insertions(+), 1 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index a6940bb..e6a5055 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -49,6 +49,12 @@ typedef struct FsCred } FsCred; struct xattr_operations; +struct FsContext; +struct V9fsPath; + +typedef struct extended_ops { + int (*get_st_gen)(struct FsContext *, struct V9fsPath *, uint64_t *); +} extended_ops; /* FsContext flag values */ #define PATHNAME_FSCONTEXT 0x1 @@ -62,6 +68,7 @@ typedef struct FsContext int open_flags; int cache_model; struct xattr_operations **xops; + struct extended_ops exops; /* fs driver specific data */ void *private; } FsContext; diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c index 7ad4bec..bf7c44b 100644 --- a/hw/9pfs/cofile.c +++ b/hw/9pfs/cofile.c @@ -17,6 +17,28 @@ #include "qemu-coroutine.h" #include "virtio-9p-coth.h" +int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, V9fsStatDotl *v9stat) +{ + int err; + V9fsState *s = pdu->s; + + if (v9fs_request_cancelled(pdu)) { + return -EINTR; + } + if (s->ctx.exops.get_st_gen) { + v9fs_path_read_lock(s); + v9fs_co_run_in_worker( + { + err = s->ctx.exops.get_st_gen(&s->ctx, path, &v9stat->st_gen); + if (err < 0) { + err = -errno; + } + }); + v9fs_path_unlock(s); + } + return err; +} + int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf) { int err; diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h index 4630080..c9e9325 100644 --- a/hw/9pfs/virtio-9p-coth.h +++ b/hw/9pfs/virtio-9p-coth.h @@ -101,4 +101,6 @@ extern int v9fs_co_preadv(V9fsPDU *, V9fsFidState *, struct iovec *, int, int64_t); extern int v9fs_co_name_to_path(V9fsPDU *, V9fsPath *, const char *, V9fsPath *); +extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, V9fsStatDotl *v9stat); + #endif diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 246da23..6a969ba 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -122,6 +122,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) } s->ctx.cache_model = fse->cache_model; s->ctx.fs_root = qemu_strdup(fse->path); + s->ctx.exops.get_st_gen = NULL; len = strlen(conf->tag); if (len > MAX_TAG_LEN) { len = MAX_TAG_LEN; diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 1b6c323..2a2ddfa 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) { @@ -645,10 +648,37 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir, return ret; } +static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, uint64_t *st_gen) +{ + int mode = 0600; + int fd; + + fd = local_open(ctx, path, mode); + if(fd < 0) { + return fd; + } + return ioctl(fd, FS_IOC_GETVERSION, st_gen); + +} +/* XFS_SUPER_MAGIC not available in linux/fs.h */ +#define XFS_SUPER_MAGIC 0x58465342 static int local_init(FsContext *ctx) { + int err; + struct statfs stbuf; ctx->flags |= PATHNAME_FSCONTEXT; - return 0; + err = statfs(ctx->fs_root, &stbuf); + if(!err) { + switch (stbuf.f_type) { + case EXT4_SUPER_MAGIC: /* same magic val for ext2/3 */ + case BTRFS_SUPER_MAGIC: + case REISERFS_SUPER_MAGIC: + case XFS_SUPER_MAGIC: + ctx->exops.get_st_gen = local_ioc_getversion; + break; + } + } + return err; } FileOperations local_ops = { diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 8b5e711..469668f 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -1357,6 +1357,15 @@ static void v9fs_getattr(void *opaque) goto out; } stat_to_v9stat_dotl(s, &stbuf, &v9stat_dotl); + + /* fill st_gen if requested and supported by underlying fs */ + if (request_mask & P9_STATS_GEN) { + retval = v9fs_co_st_gen(pdu, &fidp->path, &v9stat_dotl); + if (retval < 0) { + goto out; + } + v9stat_dotl.st_result_mask |= P9_STATS_GEN; + } retval = offset; retval += pdu_marshal(pdu, offset, "A", &v9stat_dotl); out: