Message ID | 1467710186-8792-1-git-send-email-prasanna.kalever@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Jul 05, 2016 at 02:46:26PM +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> > --- > block/gluster.c | 31 +++++++++++++++++++++++++++++-- > 1 file changed, 29 insertions(+), 2 deletions(-) > > diff --git a/block/gluster.c b/block/gluster.c > index 16f7778..6875429 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; > + 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. > bool 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. > 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; > + 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. > 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); In this case, qemu_opt_get_del() returns a malloc'ed string, so we must make sure to free it after usage. > + 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", > -- > 2.7.4 >
diff --git a/block/gluster.c b/block/gluster.c index 16f7778..6875429 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; + 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",
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> --- block/gluster.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)