From patchwork Wed Dec 14 13:20:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohan Kumar M X-Patchwork-Id: 131386 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 26A211007D6 for ; Thu, 15 Dec 2011 00:57:04 +1100 (EST) Received: from localhost ([::1]:40963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RapKP-0001at-2F for incoming@patchwork.ozlabs.org; Wed, 14 Dec 2011 08:57:01 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaomD-00014p-6Y for qemu-devel@nongnu.org; Wed, 14 Dec 2011 08:21:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Raom2-0003vn-MR for qemu-devel@nongnu.org; Wed, 14 Dec 2011 08:21:35 -0500 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:36079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Raom1-0003vR-SO for qemu-devel@nongnu.org; Wed, 14 Dec 2011 08:21:30 -0500 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Dec 2011 13:19:05 +1000 Received: from d23relay05.au.ibm.com ([202.81.31.247]) by e23smtp05.au.ibm.com ([202.81.31.211]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Dec 2011 13:18:29 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBEDH5983223778 for ; Thu, 15 Dec 2011 00:17:05 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBEDKpmr029009 for ; Thu, 15 Dec 2011 00:20:52 +1100 Received: from explorer.in.ibm.com (explorer.in.ibm.com [9.124.35.162]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pBEDKY9T028542; Thu, 15 Dec 2011 00:20:50 +1100 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com, stefanha@gmail.com Date: Wed, 14 Dec 2011 18:50:30 +0530 Message-Id: <1323868833-541-12-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1323868833-541-1-git-send-email-mohan@in.ibm.com> References: <1323868833-541-1-git-send-email-mohan@in.ibm.com> x-cbid: 11121403-1396-0000-0000-00000064F514 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.147 Cc: "M. Mohan Kumar" Subject: [Qemu-devel] [PATCH V5 11/14] hw/9pfs: Proxy getversion 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 From: "M. Mohan Kumar" Add proxy getversion to get generation number Signed-off-by: M. Mohan Kumar --- fsdev/virtfs-proxy-helper.c | 80 +++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p-proxy.c | 32 +++++++++++++++++ hw/9pfs/virtio-9p-proxy.h | 1 + 3 files changed, 113 insertions(+), 0 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 10dd337..3beed25 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -28,6 +28,11 @@ #include #include #include +#include +#include +#ifdef CONFIG_LINUX_MAGIC_H +#include +#endif #include "qemu-common.h" #include "virtio-9p-marshal.h" #include "hw/9pfs/virtio-9p-proxy.h" @@ -35,6 +40,19 @@ #define PROGNAME "virtfs-proxy-helper" +#ifndef XFS_SUPER_MAGIC +#define XFS_SUPER_MAGIC 0x58465342 +#endif +#ifndef EXT2_SUPER_MAGIC +#define EXT2_SUPER_MAGIC 0xEF53 +#endif +#ifndef REISERFS_SUPER_MAGIC +#define REISERFS_SUPER_MAGIC 0x52654973 +#endif +#ifndef BTRFS_SUPER_MAGIC +#define BTRFS_SUPER_MAGIC 0x9123683E +#endif + static struct option helper_opts[] = { {"fd", required_argument, NULL, 'f'}, {"path", required_argument, NULL, 'p'}, @@ -42,6 +60,7 @@ static struct option helper_opts[] = { }; static bool is_daemon; +static bool get_version; /* IOC getversion IOCTL supported */ static void do_log(int loglevel, const char *format, ...) { @@ -330,6 +349,45 @@ static int send_response(int sock, struct iovec *iovec, int size) return 0; } +/* + * gets generation number + * returns -errno on failure and sizeof(generation number) on success + */ +static int do_getversion(struct iovec *iovec, struct iovec *out_iovec) +{ + V9fsString path; + uint64_t version; + int fd, retval = -ENOTTY; + + /* no need to issue ioctl */ + if (!get_version) { + version = 0; + retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "q", version); + return retval; + } +#ifdef FS_IOC_GETVERSION + retval = proxy_unmarshal(iovec, PROXY_HDR_SZ, "s", &path); + if (retval < 0) { + return retval; + } + + fd = open(path.data, O_RDONLY); + if (fd < 0) { + retval = -errno; + goto err_out; + } + if (ioctl(fd, FS_IOC_GETVERSION, &version) < 0) { + retval = -errno; + } else { + retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "q", version); + } + close(fd); +err_out: + v9fs_string_free(&path); +#endif + return retval; +} + static int do_getxattr(int type, struct iovec *iovec, struct iovec *out_iovec) { int size = 0, offset, retval; @@ -672,6 +730,7 @@ static int process_reply(int sock, int type, case T_READLINK: case T_LGETXATTR: case T_LLISTXATTR: + case T_GETVERSION: if (send_response(sock, out_iovec, retval) < 0) { return -1; } @@ -854,6 +913,9 @@ static int process_requests(int sock) v9fs_string_free(&path); v9fs_string_free(&name); break; + case T_GETVERSION: + retval = do_getversion(&in_iovec, &out_iovec); + break; default: goto err_out; break; @@ -875,6 +937,8 @@ int main(int argc, char **argv) char *rpath = NULL; struct stat stbuf; int c, option_index; + int retval; + struct statfs st_fs; is_daemon = true; sock = -1; @@ -931,6 +995,22 @@ int main(int argc, char **argv) do_log(LOG_INFO, "Started\n"); + get_version = false; +#ifdef FS_IOC_GETVERSION + /* check whether underlying FS support IOC_GETVERSION */ + retval = statfs(rpath, &st_fs); + if (!retval) { + switch (st_fs.f_type) { + case EXT2_SUPER_MAGIC: + case BTRFS_SUPER_MAGIC: + case REISERFS_SUPER_MAGIC: + case XFS_SUPER_MAGIC: + get_version = true; + break; + } + } +#endif + if (chdir("/") < 0) { do_perror("chdir"); goto error; diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index 983d319..e782c4f 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -243,6 +243,9 @@ static int v9fs_receive_response(V9fsProxy *proxy, int type, v9fs_string_free(&xattr); break; } + case T_GETVERSION: + proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response); + break; default: return -1; } @@ -509,6 +512,14 @@ static int v9fs_request(V9fsProxy *proxy, int type, header.type = T_LREMOVEXATTR; } break; + case T_GETVERSION: + path = va_arg(ap, V9fsString *); + retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); + if (retval > 0) { + header.size = retval; + header.type = T_GETVERSION; + } + break; default: error_report("Invalid type %d\n", type); retval = -EINVAL; @@ -559,6 +570,7 @@ static int v9fs_request(V9fsProxy *proxy, int type, case T_LSTAT: case T_READLINK: case T_STATFS: + case T_GETVERSION: if (v9fs_receive_response(proxy, type, &retval, response) < 0) { goto close_error; } @@ -1064,6 +1076,25 @@ static int proxy_unlinkat(FsContext *ctx, V9fsPath *dir, return ret; } +static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path, + mode_t st_mode, uint64_t *st_gen) +{ + int err; + + /* Do not try to open special files like device nodes, fifos etc + * we can get fd for regular files and directories only + */ + if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) { + return 0; + } + err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, "s", path); + if (err < 0) { + errno = -err; + err = -1; + } + return err; +} + static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs) { const char *sock_fd = qemu_opt_get(opts, "sock_fd"); @@ -1098,6 +1129,7 @@ static int proxy_init(FsContext *ctx) qemu_mutex_init(&proxy->mutex); ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; + ctx->exops.get_st_gen = proxy_ioc_getversion; return 0; } diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/virtio-9p-proxy.h index 7b3b0a9..005c1ad 100644 --- a/hw/9pfs/virtio-9p-proxy.h +++ b/hw/9pfs/virtio-9p-proxy.h @@ -58,6 +58,7 @@ enum { T_LLISTXATTR, T_LSETXATTR, T_LREMOVEXATTR, + T_GETVERSION, }; typedef struct {