block/gluster: add support to choose libgfapi logfile
PATCH v3 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:
-----
*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"
}
]
}
}'---
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(-)
block/gluster.c +42 -5
@@ -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 ;
qapi/block-core.json +4 -1
@@ -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
Signature · 1 line
2.7.4
Quoted 2 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
s/api, in case if/api. When the/
s/TRACE/TRACE,/
Quoted 3 lines
gfapi logs will be huge and fill/overflow the console view.
this patch provides a commandline option to mention log file path which helps
s/this/This/
Quoted 12 lines
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+++
b/block/gluster.c
block/gluster.c line 30
Quoted 6 lines
block/gluster.c +1
-1@@ -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"
Why move this line?
block/gluster.c static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, · line 592
Quoted 12 lines
block/gluster.c +3
-1#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 */ @@ -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=...]"
Why did you change absolute "/volume/path" to relative "volname/image"?
block/gluster.c static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, · line 605
Quoted 12 lines
block/gluster.c +4
-1+"[,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,"
Missing a comma between the file.logfile and file.server keys.
Quoted 13 lines
block/gluster.c +1
-1"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);
block/gluster.c static int qemu_gluster_open(BlockDriverState *bs, QDict *options, · line 725
Quoted 10 lines
block/gluster.c +7
-0@@ -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 ); + }
I might have writtens->logfile = g_strdup(logfile ? logfile : GLUSTER_LOGFILE_DEFAULT);
Quoted 6 lines
qapi/block-core.json +2
-0+++ 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)
qapi/block-core.json line 2150
Quoted 10 lines
qapi/block-core.json +3
-1+# # Since: 2.7 ## { 'struct': 'BlockdevOptionsGluster', 'data': { 'volume': 'str', 'path': 'str', 'server': ['GlusterServer'], - '*debug_level': 'int' } } + '*debug_level': 'int', + '*logfile': 'str' } }
Very borderline on whether this qualifies as a bugfix, or if it is a feature to be deferred to 2.8. I'll let the maintainer chime in.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 4 lines · Eric Blake
Quoted 2 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
Quoted 18 lines
s/api, in case if/api. When the/
s/TRACE/TRACE,/Quoted 3 lines
gfapi logs will be huge and fill/overflow the console view.
this patch provides a commandline option to mention log file path which helps
s/this/This/
Quoted 9 lines
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
done!
Quoted 11 lines
block/gluster.c line 30
Quoted 9 lines
+++
b/block/gluster.cblock/gluster.c +1
-1@@ -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"Why move this line?
Dropping
Quoted 7 lines
Quoted 6 lines
block/gluster.c +2
-0#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 */
Quoted 8 lines
block/gluster.c static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, · line 592
Quoted 6 lines
block/gluster.c +1
-1@@ -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=...]"Why did you change absolute "/volume/path" to relative "volname/image"?
you caught it :) It was unintentional, did a copy paste from v2 dropping
Quoted 15 lines
block/gluster.c static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, · line 605
Quoted 13 lines
block/gluster.c +4
-1+"[,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,"Missing a comma between the file.logfile and file.server keys.
oh yeah
Quoted 11 lines
Quoted 11 lines
block/gluster.c +1
-1"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;
Quoted 16 lines
block/gluster.c static int qemu_gluster_open(BlockDriverState *bs, QDict *options, · line 725
Quoted 13 lines
block/gluster.c +7
-0opts =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 ); + }I might have written
s->logfile=g_strdup(logfile ? logfile : GLUSTER_LOGFILE_DEFAULT);
Looks good to me, picking this up
Quoted 12 lines
Quoted 12 lines
qapi/block-core.json +3
-0+++ 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',
Quoted 8 lines
qapi/block-core.json line 2150
Quoted 5 lines
qapi/block-core.json +2
-1'path': 'str', 'server': ['GlusterServer'], - '*debug_level': 'int' } } + '*debug_level': 'int', + '*logfile': 'str' } }Very borderline on whether this qualifies as a bugfix, or if it is a feature to be deferred to 2.8. I'll let the maintainer chime in.
Not sure, but this is really needed, at least while image creation these fills all the stderr
Thanks Eric!
Cheers,
--
Prasanna
Quoted 6 lines
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org