block/gluster: add support to choose libgfapi logfile
PATCH 1/1 block/gluster: add support to choose libgfapi logfile
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
--- block/gluster.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
block/gluster.c +29 -2
@@ -24,6 +24,7 @@ typedef struct GlusterAIOCB {typedef struct BDRVGlusterState {struct glfs *glfs;struct glfs_fd *fd; +const char *logfile;bool supports_seek_data;int debug_level; }BDRVGlusterState ;
@@ -34,6 +35,7 @@ typedef struct GlusterConf {char *volname;char *image;char *transport; +const char *logfile;int debug_level; } GlusterConf;
@@ -181,7 +183,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 +200,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 +259,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 +276,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",
@@ -339,6 +349,12 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, filename =qemu_opt_get (opts,GLUSTER_OPT_FILENAME ); + s->logfile =qemu_opt_get (opts,GLUSTER_OPT_LOGFILE ); +if (!s->logfile) { + s->logfile =GLUSTER_LOGFILE_DEFAULT ; + } + gconf->logfile = s->logfile; + s->debug_level =qemu_opt_get_number (opts,GLUSTER_OPT_DEBUG ,GLUSTER_DEBUG_DEFAULT );if (s->debug_level <0 ) {
@@ -422,6 +438,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state, gconf =g_new0 (GlusterConf,1 ); + gconf->logfile = 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 +573,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 =GLUSTER_LOGFILE_DEFAULT ; + } + gconf->debug_level =qemu_opt_get_number_del (opts,GLUSTER_OPT_DEBUG ,GLUSTER_DEBUG_DEFAULT );if (gconf->debug_level <0 ) {
@@ -949,6 +971,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",
Signature · 1 line
2.7.4
Quoted 20 lines · Prasanna Kumar Kalever
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.logSigned-off-by Prasanna Kumar Kalever <[email protected]>--- block/gluster.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)block/gluster.c +0
-0
block/gluster.c typedef struct GlusterAIOCB { · line 27
Quoted 4 lines
block/gluster.c +1
-0@@ -24,6 +24,7 @@ typedef struct GlusterAIOCB { typedef struct BDRVGlusterState { struct glfs *glfs; struct glfs_fd *fd; + const char *logfile;
Having this const looks incorrect; we want a copy of the string. After the opts are deleted, the string this points to has been freed.
block/gluster.c typedef struct GlusterConf { · line 38
Quoted 8 lines
block/gluster.c +1
-0bool supports_seek_data;int debug_level; } BDRVGlusterState;@@ -34,6 +35,7 @@ typedef struct GlusterConf {char *volname;char *image;char *transport; +const char *logfile;
Here too, this is probably best not being const.
Quoted 44 lines
block/gluster.c +10
-2int debug_level; } GlusterConf;@@ -181,7 +183,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 +200,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 +259,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 +276,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",
block/gluster.c static int qemu_gluster_open(BlockDriverState *bs, QDict *options, · line 357
Quoted 9 lines
block/gluster.c +6
-0@@ -339,6 +349,12 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, filename =qemu_opt_get (opts,GLUSTER_OPT_FILENAME ); + s->logfile =qemu_opt_get (opts,GLUSTER_OPT_LOGFILE ); +if (!s->logfile) { + s->logfile =GLUSTER_LOGFILE_DEFAULT ; + } + gconf->logfile = s->logfile; +
At the end of qemu_gluster_open(), qemu_opts_del() is called, which means the const char * s->logfile will end up pointing at freed memory.
Quoted 12 lines
block/gluster.c +1
-0s->debug_level =qemu_opt_get_number (opts,GLUSTER_OPT_DEBUG ,GLUSTER_DEBUG_DEFAULT );if (s->debug_level <0 ) {@@ -422,6 +438,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state, gconf =g_new0 (GlusterConf,1 ); + gconf->logfile = s->logfile; gconf->debug_level = s->debug_level; reop_s->glfs =qemu_gluster_init (gconf, state->bs->filename, errp);if (reop_s->glfs ==NULL ) {
block/gluster.c static int qemu_gluster_create(const char *filename, · line 576
Quoted 4 lines
block/gluster.c +1
-0@@ -556,6 +573,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 );
In this case, qemu_opt_get_del() returns a malloc'ed string, so we must make sure to free it after usage.
Quoted 22 lines
block/gluster.c +9
-0+if (!gconf->logfile) { + gconf->logfile =GLUSTER_LOGFILE_DEFAULT ; + } + gconf->debug_level =qemu_opt_get_number_del (opts,GLUSTER_OPT_DEBUG ,GLUSTER_DEBUG_DEFAULT );if (gconf->debug_level <0 ) {@@ -949,6 +971,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",Signature · 1 line
2.7.4