From patchwork Wed Jul 6 20:13:50 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: 9216997 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 5066360467 for ; Wed, 6 Jul 2016 20:14:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39C192844C for ; Wed, 6 Jul 2016 20:14:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A1C428451; Wed, 6 Jul 2016 20:14:35 +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 7D6A52844C for ; Wed, 6 Jul 2016 20:14:34 +0000 (UTC) Received: from localhost ([::1]:35642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKtDM-0004X7-IF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 16:14:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKtD4-0004Wt-3f for qemu-devel@nongnu.org; Wed, 06 Jul 2016 16:14:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKtCw-0001vR-R2 for qemu-devel@nongnu.org; Wed, 06 Jul 2016 16:14:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40930) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKtCw-0001uV-JH for qemu-devel@nongnu.org; Wed, 06 Jul 2016 16:14:06 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 1587BC04B303; Wed, 6 Jul 2016 20:14:05 +0000 (UTC) Received: from dhcp1-86.lab.eng.blr.redhat.com (vpn1-5-72.sin2.redhat.com [10.67.5.72]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u66KE0IX021136; Wed, 6 Jul 2016 16:14:01 -0400 From: Prasanna Kumar Kalever To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 01:43:50 +0530 Message-Id: <1467836030-3841-1-git-send-email-prasanna.kalever@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Jul 2016 20:14:05 +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 v2 1/1] 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: kwolf@redhat.com, Prasanna Kumar Kalever , pgurusid@redhat.com, jcody@redhat.com, gluster-devel@gluster.org, 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: -drive file=gluster://hostname/volname/image.qcow2,file.debug=9,\ file.logfile=/var/log/qemu/qemu-gfapi.log Signed-off-by: Prasanna Kumar Kalever Reviewed-by: Jeff Cody --- v1: initial patch v2: address comments from Jeff Cody, thanks Jeff! --- block/gluster.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 16f7778..bf6a134 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -24,6 +24,7 @@ typedef struct GlusterAIOCB { typedef struct BDRVGlusterState { struct glfs *glfs; struct glfs_fd *fd; + char *logfile; bool supports_seek_data; int debug_level; } BDRVGlusterState; @@ -34,6 +35,7 @@ typedef struct GlusterConf { char *volname; char *image; char *transport; + char *logfile; int debug_level; } GlusterConf; @@ -44,6 +46,7 @@ static void qemu_gluster_gconf_free(GlusterConf *gconf) g_free(gconf->volname); g_free(gconf->image); g_free(gconf->transport); + g_free(gconf->logfile); g_free(gconf); } } @@ -181,7 +184,8 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename, ret = qemu_gluster_parseuri(gconf, filename); if (ret < 0) { error_setg(errp, "Usage: file=gluster[+transport]://[server[:port]]/" - "volname/image[?socket=...]"); + "volname/image[?socket=...][,file.debug=N]" + "[,file.logfile=/path/filename.log]"); errno = -ret; goto out; } @@ -197,7 +201,7 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename, goto out; } - ret = glfs_set_logging(glfs, "-", gconf->debug_level); + ret = glfs_set_logging(glfs, gconf->logfile, gconf->debug_level); if (ret < 0) { goto out; } @@ -256,6 +260,8 @@ static void gluster_finish_aiocb(struct glfs_fd *fd, ssize_t ret, void *arg) } #define GLUSTER_OPT_FILENAME "filename" +#define GLUSTER_OPT_LOGFILE "logfile" +#define GLUSTER_LOGFILE_DEFAULT "-" /* '-' handled in libgfapi as /dev/stderr */ #define GLUSTER_OPT_DEBUG "debug" #define GLUSTER_DEBUG_DEFAULT 4 #define GLUSTER_DEBUG_MAX 9 @@ -271,6 +277,11 @@ static QemuOptsList runtime_opts = { .help = "URL to the gluster image", }, { + .name = GLUSTER_OPT_LOGFILE, + .type = QEMU_OPT_STRING, + .help = "Logfile path of libgfapi", + }, + { .name = GLUSTER_OPT_DEBUG, .type = QEMU_OPT_NUMBER, .help = "Gluster log level, valid range is 0-9", @@ -327,7 +338,7 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, GlusterConf *gconf = g_new0(GlusterConf, 1); 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); @@ -339,6 +350,15 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, filename = qemu_opt_get(opts, GLUSTER_OPT_FILENAME); + 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); + s->debug_level = qemu_opt_get_number(opts, GLUSTER_OPT_DEBUG, GLUSTER_DEBUG_DEFAULT); if (s->debug_level < 0) { @@ -386,6 +406,7 @@ out: if (!ret) { return ret; } + g_free(s->logfile); if (s->fd) { glfs_close(s->fd); } @@ -422,6 +443,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state, gconf = g_new0(GlusterConf, 1); + gconf->logfile = g_strdup(s->logfile); gconf->debug_level = s->debug_level; reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, errp); if (reop_s->glfs == NULL) { @@ -556,6 +578,11 @@ static int qemu_gluster_create(const char *filename, char *tmp = NULL; GlusterConf *gconf = g_new0(GlusterConf, 1); + gconf->logfile = qemu_opt_get_del(opts, GLUSTER_OPT_LOGFILE); + if (!gconf->logfile) { + gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT); + } + gconf->debug_level = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG, GLUSTER_DEBUG_DEFAULT); if (gconf->debug_level < 0) { @@ -672,6 +699,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; @@ -949,6 +977,11 @@ static QemuOptsList qemu_gluster_create_opts = { .help = "Preallocation mode (allowed values: off, full)" }, { + .name = GLUSTER_OPT_LOGFILE, + .type = QEMU_OPT_STRING, + .help = "Logfile path of libgfapi", + }, + { .name = GLUSTER_OPT_DEBUG, .type = QEMU_OPT_NUMBER, .help = "Gluster log level, valid range is 0-9",