From patchwork Fri Jul 22 12:01:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanna Kumar Kalever X-Patchwork-Id: 9243411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EF975607D3 for ; Fri, 22 Jul 2016 12:01:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF07D26861 for ; Fri, 22 Jul 2016 12:01:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D364827FA3; Fri, 22 Jul 2016 12:01:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D42426861 for ; Fri, 22 Jul 2016 12:01:46 +0000 (UTC) Received: from localhost ([::1]:46919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQZ9E-0006Gx-KB for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jul 2016 08:01:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQZ8z-0006Gb-9c for qemu-devel@nongnu.org; Fri, 22 Jul 2016 08:01:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQZ8w-0006iH-7U for qemu-devel@nongnu.org; Fri, 22 Jul 2016 08:01:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43646) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQZ8v-0006hz-Uj for qemu-devel@nongnu.org; Fri, 22 Jul 2016 08:01:26 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22F1FC05AA56 for ; Fri, 22 Jul 2016 12:01:25 +0000 (UTC) Received: from dhcp1-86.lab.eng.blr.redhat.com (pkalever.blr.redhat.com [10.70.1.86]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6MC1MWq014895; Fri, 22 Jul 2016 08:01:22 -0400 From: Prasanna Kumar Kalever To: qemu-devel@nongnu.org Date: Fri, 22 Jul 2016 17:31:14 +0530 Message-Id: <1469188874-9292-1-git-send-email-prasanna.kalever@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 22 Jul 2016 12:01:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3] block/gluster: add support to choose libgfapi logfile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasanna Kumar Kalever , vbellur@redhat.com, jcody@redhat.com, armbru@redhat.com, rtalur@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP currently all the libgfapi logs defaults to '/dev/stderr' as it was hardcoded in a call to glfs logging api, in case if debug level is chosen to DEBUG/TRACE gfapi logs will be huge and fill/overflow the console view. this patch provides a commandline option to mention log file path which helps in logging to the specified file and also help in persisting the gfapi logs. Usage: ----- *URI Style: --------- -drive file=gluster://hostname/volname/image.qcow2,file.debug=9,\ file.logfile=/var/log/qemu/qemu-gfapi.log *JSON Style: ---------- 'json:{ "driver":"qcow2", "file":{ "driver":"gluster", "volume":"volname", "path":"image.qcow2", "debug":"9", "logfile":"/var/log/qemu/qemu-gfapi.log", "server":[ { "type":"tcp", "host":"1.2.3.4", "port":24007 }, { "type":"unix", "socket":"/var/run/glusterd.socket" } ] } }' Signed-off-by: Prasanna Kumar Kalever --- v3: rebased on master, which is now QMP compatible. v2: address comments from Jeff Cody, thanks Jeff! v1: initial patch --- block/gluster.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- qapi/block-core.json | 5 ++++- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 01b479f..51a1089 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -26,10 +26,12 @@ #define GLUSTER_OPT_IPV4 "ipv4" #define GLUSTER_OPT_IPV6 "ipv6" #define GLUSTER_OPT_SOCKET "socket" -#define GLUSTER_OPT_DEBUG "debug" #define GLUSTER_DEFAULT_PORT 24007 +#define GLUSTER_OPT_DEBUG "debug" #define GLUSTER_DEBUG_DEFAULT 4 #define GLUSTER_DEBUG_MAX 9 +#define GLUSTER_OPT_LOGFILE "logfile" +#define GLUSTER_LOGFILE_DEFAULT "-" /* handled in libgfapi as /dev/stderr */ #define GERR_INDEX_HINT "hint: check in 'server' array index '%d'\n" @@ -44,6 +46,7 @@ typedef struct GlusterAIOCB { typedef struct BDRVGlusterState { struct glfs *glfs; struct glfs_fd *fd; + char *logfile; bool supports_seek_data; int debug_level; } BDRVGlusterState; @@ -73,6 +76,11 @@ static QemuOptsList qemu_gluster_create_opts = { .type = QEMU_OPT_NUMBER, .help = "Gluster log level, valid range is 0-9", }, + { + .name = GLUSTER_OPT_LOGFILE, + .type = QEMU_OPT_STRING, + .help = "Logfile path of libgfapi", + }, { /* end of list */ } } }; @@ -91,6 +99,11 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_NUMBER, .help = "Gluster log level, valid range is 0-9", }, + { + .name = GLUSTER_OPT_LOGFILE, + .type = QEMU_OPT_STRING, + .help = "Logfile path of libgfapi", + }, { /* end of list */ } }, }; @@ -341,7 +354,7 @@ static struct glfs *qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf, } } - ret = glfs_set_logging(glfs, "-", gconf->debug_level); + ret = glfs_set_logging(glfs, gconf->logfile, gconf->debug_level); if (ret < 0) { goto out; } @@ -576,7 +589,9 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, if (ret < 0) { error_setg(errp, "invalid URI"); error_append_hint(errp, "Usage: file=gluster[+transport]://" - "[host[:port]]/volume/path[?socket=...]\n"); + "[host[:port]]volname/image[?socket=...]" + "[,file.debug=N]" + "[,file.logfile=/path/filename.log]\n"); errno = -ret; return NULL; } @@ -586,7 +601,8 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, error_append_hint(errp, "Usage: " "-drive driver=qcow2,file.driver=gluster," "file.volume=testvol,file.path=/path/a.qcow2" - "[,file.debug=9],file.server.0.type=tcp," + "[,file.debug=9][,file.logfile=/path/filename.log]" + "file.server.0.type=tcp," "file.server.0.host=1.2.3.4," "file.server.0.port=24007," "file.server.1.transport=unix," @@ -677,7 +693,7 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, BlockdevOptionsGluster *gconf = NULL; QemuOpts *opts; Error *local_err = NULL; - const char *filename; + const char *filename, *logfile; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); @@ -700,6 +716,17 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, gconf = g_new0(BlockdevOptionsGluster, 1); gconf->debug_level = s->debug_level; gconf->has_debug_level = true; + + logfile = qemu_opt_get(opts, GLUSTER_OPT_LOGFILE); + if (logfile) { + s->logfile = g_strdup(logfile); + } else { + s->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT); + } + + gconf->logfile = g_strdup(s->logfile); + gconf->has_logfile = true; + s->glfs = qemu_gluster_init(gconf, filename, options, errp); if (!s->glfs) { ret = -errno; @@ -738,6 +765,7 @@ out: if (!ret) { return ret; } + g_free(s->logfile); if (s->fd) { glfs_close(s->fd); } @@ -769,6 +797,8 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state, gconf = g_new0(BlockdevOptionsGluster, 1); gconf->debug_level = s->debug_level; gconf->has_debug_level = true; + gconf->logfile = g_strdup(s->logfile); + gconf->has_logfile = true; reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, NULL, errp); if (reop_s->glfs == NULL) { ret = -errno; @@ -914,6 +944,12 @@ static int qemu_gluster_create(const char *filename, } gconf->has_debug_level = true; + gconf->logfile = qemu_opt_get_del(opts, GLUSTER_OPT_LOGFILE); + if (!gconf->logfile) { + gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT); + } + gconf->has_logfile = true; + glfs = qemu_gluster_init(gconf, filename, NULL, errp); if (!glfs) { ret = -errno; @@ -1025,6 +1061,7 @@ static void qemu_gluster_close(BlockDriverState *bs) { BDRVGlusterState *s = bs->opaque; + g_free(s->logfile); if (s->fd) { glfs_close(s->fd); s->fd = NULL; diff --git a/qapi/block-core.json b/qapi/block-core.json index f462345..bed531d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2138,13 +2138,16 @@ # # @debug-level: #optional libgfapi log level (default '4' which is Error) # +# @logfile: #optional libgfapi log file (default /dev/stderr) +# # Since: 2.7 ## { 'struct': 'BlockdevOptionsGluster', 'data': { 'volume': 'str', 'path': 'str', 'server': ['GlusterServer'], - '*debug_level': 'int' } } + '*debug_level': 'int', + '*logfile': 'str' } } ## # @BlockdevOptions