diff mbox

[v2,1/1] block/gluster: add support to choose libgfapi logfile

Message ID 1467836030-3841-1-git-send-email-prasanna.kalever@redhat.com
State New
Headers show

Commit Message

Prasanna Kumar Kalever July 6, 2016, 8:13 p.m. UTC
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 <prasanna.kalever@redhat.com>
---
v1: initial patch
v2: address comments from Jeff Cody, thanks Jeff!
---
 block/gluster.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

Comments

Jeff Cody July 7, 2016, 3:34 p.m. UTC | #1
On Thu, Jul 07, 2016 at 01:43:50AM +0530, Prasanna Kumar Kalever wrote:
> 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 <prasanna.kalever@redhat.com>
> ---
> v1: initial patch
> v2: address comments from Jeff Cody, thanks Jeff!

Reviewed-by: Jeff Cody <jcody@redhat.com>

> ---
>  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",
> -- 
> 2.7.4
>
diff mbox

Patch

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",