Blame SOURCES/kvm-block-gluster-add-support-for-selecting-debug-loggin.patch

619821
From 2ffc3b31eafe39cc11678ef0e0ea39cdfef0469d Mon Sep 17 00:00:00 2001
619821
From: Jeffrey Cody <jcody@redhat.com>
619821
Date: Tue, 17 Jan 2017 19:51:32 +0100
619821
Subject: [PATCH 3/3] block/gluster: add support for selecting debug logging
619821
 level
619821
619821
RH-Author: Jeffrey Cody <jcody@redhat.com>
619821
Message-id: <87a60937c8dfa4bee63e59871811dbda7794e818.1484682588.git.jcody@redhat.com>
619821
Patchwork-id: 73255
619821
O-Subject: [RHEL-7.4 qemu-kvm 3/3] block/gluster: add support for selecting debug logging level
619821
Bugzilla: 1151859
619821
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
619821
RH-Acked-by: Fam Zheng <famz@redhat.com>
619821
RH-Acked-by: Thomas Huth <thuth@redhat.com>
619821
619821
This adds commandline support for the logging level of the
619821
gluster protocol driver, output to stdout.  The option is 'debug',
619821
e.g.:
619821
619821
-drive filename=gluster://192.168.15.180/gv2/test.qcow2,debug=9
619821
619821
Debug levels are 0-9, with 9 being the most verbose, and 0 representing
619821
no debugging output.  The default is the same as it was before, which
619821
is a level of 4.  The current logging levels defined in the gluster
619821
source are:
619821
619821
    0 - None
619821
    1 - Emergency
619821
    2 - Alert
619821
    3 - Critical
619821
    4 - Error
619821
    5 - Warning
619821
    6 - Notice
619821
    7 - Info
619821
    8 - Debug
619821
    9 - Trace
619821
619821
(From: glusterfs/logging.h)
619821
619821
Reviewed-by: Niels de Vos <ndevos@redhat.com>
619821
Signed-off-by: Jeff Cody <jcody@redhat.com>
619821
(cherry picked from commit 7eac868a508cdbf4cccef5c2084941b63fa3aded)
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 block/gluster.c | 61 +++++++++++++++++++++++++++++++++++++++++++++------------
619821
 1 file changed, 48 insertions(+), 13 deletions(-)
619821
619821
diff --git a/block/gluster.c b/block/gluster.c
619821
index 5266dce..86e136d 100644
619821
--- a/block/gluster.c
619821
+++ b/block/gluster.c
619821
@@ -35,6 +35,7 @@ typedef struct BDRVGlusterState {
619821
     int qemu_aio_count;
619821
     int event_reader_pos;
619821
     GlusterAIOCB *event_acb;
619821
+    int debug_level;
619821
 } BDRVGlusterState;
619821
 
619821
 #define GLUSTER_FD_READ  0
619821
@@ -46,6 +47,7 @@ typedef struct GlusterConf {
619821
     char *volname;
619821
     char *image;
619821
     char *transport;
619821
+    int debug_level;
619821
 } GlusterConf;
619821
 
619821
 static void qemu_gluster_gconf_free(GlusterConf *gconf)
619821
@@ -208,11 +210,7 @@ static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename,
619821
         goto out;
619821
     }
619821
 
619821
-    /*
619821
-     * TODO: Use GF_LOG_ERROR instead of hard code value of 4 here when
619821
-     * GlusterFS makes GF_LOG_* macros available to libgfapi users.
619821
-     */
619821
-    ret = glfs_set_logging(glfs, "-", 4);
619821
+    ret = glfs_set_logging(glfs, "-", gconf->debug_level);
619821
     if (ret < 0) {
619821
         goto out;
619821
     }
619821
@@ -292,16 +290,26 @@ static int qemu_gluster_aio_flush_cb(void *opaque)
619821
     return (s->qemu_aio_count > 0);
619821
 }
619821
 
619821
+#define GLUSTER_OPT_FILENAME "filename"
619821
+#define GLUSTER_OPT_DEBUG "debug"
619821
+#define GLUSTER_DEBUG_DEFAULT 4
619821
+#define GLUSTER_DEBUG_MAX 9
619821
+
619821
 /* TODO Convert to fine grained options */
619821
 static QemuOptsList runtime_opts = {
619821
     .name = "gluster",
619821
     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
619821
     .desc = {
619821
         {
619821
-            .name = "filename",
619821
+            .name = GLUSTER_OPT_FILENAME,
619821
             .type = QEMU_OPT_STRING,
619821
             .help = "URL to the gluster image",
619821
         },
619821
+        {
619821
+            .name = GLUSTER_OPT_DEBUG,
619821
+            .type = QEMU_OPT_NUMBER,
619821
+            .help = "Gluster log level, valid range is 0-9",
619821
+        },
619821
         { /* end of list */ }
619821
     },
619821
 };
619821
@@ -342,8 +350,17 @@ static int qemu_gluster_open(BlockDriverState *bs,  QDict *options,
619821
         goto out;
619821
     }
619821
 
619821
-    filename = qemu_opt_get(opts, "filename");
619821
+    filename = qemu_opt_get(opts, GLUSTER_OPT_FILENAME);
619821
 
619821
+    s->debug_level = qemu_opt_get_number(opts, GLUSTER_OPT_DEBUG,
619821
+                                         GLUSTER_DEBUG_DEFAULT);
619821
+    if (s->debug_level < 0) {
619821
+        s->debug_level = 0;
619821
+    } else if (s->debug_level > GLUSTER_DEBUG_MAX) {
619821
+        s->debug_level = GLUSTER_DEBUG_MAX;
619821
+    }
619821
+
619821
+    gconf->debug_level = s->debug_level;
619821
     s->glfs = qemu_gluster_init(gconf, filename, errp);
619821
     if (!s->glfs) {
619821
         ret = -errno;
619821
@@ -398,6 +415,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
619821
                                        BlockReopenQueue *queue, Error **errp)
619821
 {
619821
     int ret = 0;
619821
+    BDRVGlusterState *s;
619821
     BDRVGlusterReopenState *reop_s;
619821
     GlusterConf *gconf = NULL;
619821
     int open_flags = 0;
619821
@@ -405,6 +423,8 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
619821
     assert(state != NULL);
619821
     assert(state->bs != NULL);
619821
 
619821
+    s = state->bs->opaque;
619821
+
619821
     state->opaque = g_malloc0(sizeof(BDRVGlusterReopenState));
619821
     reop_s = state->opaque;
619821
 
619821
@@ -412,6 +432,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
619821
 
619821
     gconf = g_malloc0(sizeof(GlusterConf));
619821
 
619821
+    gconf->debug_level = s->debug_level;
619821
     reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, errp);
619821
     if (reop_s->glfs == NULL) {
619821
         ret = -errno;
619821
@@ -487,19 +508,28 @@ static int qemu_gluster_create(const char *filename,
619821
     int64_t total_size = 0;
619821
     GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
619821
 
619821
-    glfs = qemu_gluster_init(gconf, filename, errp);
619821
-    if (!glfs) {
619821
-        ret = -errno;
619821
-        goto out;
619821
-    }
619821
-
619821
+    gconf->debug_level = GLUSTER_DEBUG_DEFAULT;
619821
     while (options && options->name) {
619821
         if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
619821
             total_size = options->value.n / BDRV_SECTOR_SIZE;
619821
         }
619821
+        if (!strcmp(options->name, GLUSTER_OPT_DEBUG)) {
619821
+            gconf->debug_level = options->value.n;
619821
+            if (gconf->debug_level < 0) {
619821
+                gconf->debug_level = 0;
619821
+            } else if (gconf->debug_level > GLUSTER_DEBUG_MAX) {
619821
+                gconf->debug_level = GLUSTER_DEBUG_MAX;
619821
+            }
619821
+        }
619821
         options++;
619821
     }
619821
 
619821
+    glfs = qemu_gluster_init(gconf, filename, errp);
619821
+    if (!glfs) {
619821
+        ret = -errno;
619821
+        goto out;
619821
+    }
619821
+
619821
     fd = glfs_creat(glfs, gconf->image,
619821
         O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
619821
     if (!fd) {
619821
@@ -732,6 +762,11 @@ static QEMUOptionParameter qemu_gluster_create_options[] = {
619821
         .type = OPT_SIZE,
619821
         .help = "Virtual disk size"
619821
     },
619821
+    {
619821
+        .name = GLUSTER_OPT_DEBUG,
619821
+        .type = QEMU_OPT_NUMBER,
619821
+        .help = "Gluster log level, valid range is 0-9",
619821
+    },
619821
     { NULL }
619821
 };
619821
 
619821
-- 
619821
1.8.3.1
619821