Compliance with new coding style
cover Compliance with new coding style
This patchset brings the file libxl_utils.c mostly into compliance with the new coding style involving the convenience macros LOG, LOGE, and GCSPRINTF.
[PATCH 1/4] opw: libxl: use GCSPRINTF instead of libxl__sprintf [PATCH 2/4] opw: libxl: use LOGE instead of LIBXL__LOG_ERRNO in [PATCH 3/4] opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in [PATCH 4/4] opw: libxl: use LOG instead of LIBXL__LOG in
PATCH 1/4 opw: libxl: use GCSPRINTF instead of libxl__sprintf
Code cleanup - no functional changes
The convenience macro GCSPRINTF has been written to be used in place of libxl__sprintf(). Replace all calls to libxl__sprintf() in libxl_utils.c with invocations of the new macro.
--- tools/libxl/libxl_utils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tools/libxl/libxl_utils.c +8 -8
@@ -173,7 +173,7 @@ int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid)int ret; stubdom_id_s =libxl__xs_read (gc,XBT_NULL , -libxl__sprintf (gc,"%s/image/device-model-domid" , +GCSPRINTF ("%s/image/device-model-domid" ,libxl__xs_get_dompath (gc, guest_domid)));if (stubdom_id_s) ret =atoi (stubdom_id_s);
@@ -190,7 +190,7 @@ int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid)uint32_t value;int ret =0 ; - target =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/target" ,libxl__xs_get_dompath (gc, domid))); + target =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/target" ,libxl__xs_get_dompath (gc, domid)));if (!target) goto out; value =strtol (target, &endptr,10 );
@@ -227,20 +227,20 @@ int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name)char *logfile, *logfile_new;int i, rc; - logfile =libxl__sprintf (gc,"/var/log/xen/%s.log" , name); + logfile =GCSPRINTF ("/var/log/xen/%s.log" , name);if (stat (logfile, &stat_buf) ==0 ) {/* file exists, rotate */ - logfile =libxl__sprintf (gc,"/var/log/xen/%s.log.10" , name); + logfile =GCSPRINTF ("/var/log/xen/%s.log.10" , name);unlink (logfile);for (i =9 ; i >0 ; i--) { - logfile =libxl__sprintf (gc,"/var/log/xen/%s.log.%d" , name, i); - logfile_new =libxl__sprintf (gc,"/var/log/xen/%s.log.%d" , name, i +1 ); + logfile =GCSPRINTF ("/var/log/xen/%s.log.%d" , name, i); + logfile_new =GCSPRINTF ("/var/log/xen/%s.log.%d" , name, i +1 ); rc =logrename (gc, logfile, logfile_new);if (rc) goto out; } - logfile =libxl__sprintf (gc,"/var/log/xen/%s.log" , name); - logfile_new =libxl__sprintf (gc,"/var/log/xen/%s.log.1" , name); + logfile =GCSPRINTF ("/var/log/xen/%s.log" , name); + logfile_new =GCSPRINTF ("/var/log/xen/%s.log.1" , name); rc =logrename (gc, logfile, logfile_new);if (rc)
Signature · 1 line
1.8.1.2
Re: [PATCH 1/4] opw: libxl: use GCSPRINTF instead of libxl__sprintf
Quoted 17 lines · Kelley Nielsen
Code cleanup - no functional changes
The convenience macro GCSPRINTF has been written to be used in place of
libxl__sprintf(). Replace all calls tolibxl__sprintf()inlibxl_utils.cwith invocations of the new macro.Signed-off-by Kelley Nielsen <[email protected]>Suggested-by Ian Campbell <[email protected]>--- tools/libxl/libxl_utils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)tools/libxl/libxl_utils.c +0
-0
tools/libxl/libxl_utils.c int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid) · line 177
Quoted 6 lines
tools/libxl/libxl_utils.c +1
-1@@ -173,7 +173,7 @@ int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid)int ret; stubdom_id_s =libxl__xs_read (gc,XBT_NULL , -libxl__sprintf (gc,"%s/image/device-model-domid" , +GCSPRINTF ("%s/image/device-model-domid" ,libxl__xs_get_dompath (gc, guest_domid)));
If you reindent this trailing line then:
BTW, it looks like you are going to be resending a few minor revs of both libxl_qmp.c and libxl_utils.c cleanup. Feel free to put them into a single overarching "cleanup libxl" series for the resend. I assume it'll be easier for you and it'll certainly be easier for us reviewers/committers.
Thanks,
Ian.
PATCH 2/4 opw: libxl: use LOGE instead of LIBXL__LOG_ERRNO in libxl_utils.c
In reply to Kelley NielsenCode cleanup - no functional changes
The convenience macro LOGE has been written to take the place of LIBXL__LOG_ERRNO. LOGE depends on the existence of a local libgl__gc *gc. Replace two invocations of LIBXL__LOG_ERRNO, which are in functions that already have a libxl__gc *gc present, to invocations of the new macro.
--- tools/libxl/libxl_utils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/libxl/libxl_utils.c +2 -3
@@ -206,14 +206,13 @@ out:static int logrename (libxl__gc *gc,const char *old,const char *new) { -libxl_ctx *ctx =libxl__gc_owner (gc);int r; r =rename (old, new);if (r) {if (errno ==ENOENT )return 0 ;/* ok */ -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to rotate logfile - could not" +LOGE (ERROR ,"failed to rotate logfile - could not" " rename %s to %s" , old, new);return ERROR_FAIL ; }
@@ -247,7 +246,7 @@ int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name) goto out; }else {if (errno !=ENOENT ) -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_WARNING ,"problem checking existence of" +LOGE (WARN ,"problem checking existence of" " logfile %s, which might have needed to be rotated" , name); }
Signature · 1 line
1.8.1.2
Re: [PATCH 2/4] opw: libxl: use LOGE instead of LIBXL__LOG_ERRNO in libxl_utils.c
Quoted 35 lines · Kelley Nielsen
Code cleanup - no functional changes
The convenience macro LOGE has been written to take the place of
LIBXL__LOG_ERRNO. LOGE depends on the existence of a locallibgl__gc*gc. Replace two invocations ofLIBXL__LOG_ERRNO, which are in functions that already have alibxl__gc*gc present, to invocations of the new macro.Signed-off-by Kelley Nielsen <[email protected]>Suggested-by Ian Campbell <[email protected]>--- tools/libxl/libxl_utils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)tools/libxl/libxl_utils.c +1
-2@@ -206,14 +206,13 @@ out:static int logrename (libxl__gc *gc,const char *old,const char *new) { -libxl_ctx *ctx =libxl__gc_owner (gc);int r; r =rename (old, new);if (r) {if (errno ==ENOENT )return 0 ;/* ok */ -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to rotate logfile - could not" +LOGE (ERROR ,"failed to rotate logfile - could not" " rename %s to %s" , old, new);return ERROR_FAIL ; }
tools/libxl/libxl_utils.c int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name) · line 251
Quoted 7 lines
tools/libxl/libxl_utils.c +1
-1@@ -247,7 +246,7 @@ int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name) goto out; }else {if (errno !=ENOENT ) -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_WARNING ,"problem checking existence of" +LOGE (WARN ,"problem checking existence of" " logfile %s, which might have needed to be rotated" , name);
Please can you reindent the trailing lines too.
Assuming they don't now fit into 80-columns perhaps you could also rebreak the line at the clause boundary (i.e. on the comma) to aid grep.
Thanks,
Ian.
PATCH 3/4 opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in libxl_utils.c
In reply to Kelley NielsenCode cleanup - no functional changes
The convenience macros LOG and LOGE have been written to take the place of the old macros in the LIBXL__LOG* family. Replace the invocations of the old macros in the function libxl_read_file_contents() with invocations of the corresponding new ones. Create a local libxl__gc gc* for the new macros to use by invoking GC_INIT(ctx) at the top of the function, and clean it up by invoking GC_FREE at the two exit points.
--- tools/libxl/libxl_utils.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
tools/libxl/libxl_utils.c +10 -7
@@ -289,6 +289,7 @@ out:int libxl_read_file_contents (libxl_ctx *ctx,const char *filename,void **data_r,int *datalen_r) { +GC_INIT (ctx);FILE *f =0 ;uint8_t *data =0 ;int datalen =0 ;
@@ -299,23 +300,23 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, f =fopen (filename,"r" );if (!f) {if (errno ==ENOENT )return ENOENT ; -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to open %s" , filename); +LOGE (ERROR ,"failed to open %s" , filename); goto xe; }if (fstat (fileno (f), &stab)) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to fstat %s" , filename); +LOGE (ERROR ,"failed to fstat %s" , filename); goto xe; }if (!S_ISREG (stab.st_mode)) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is not a plain file" , filename); +LOGE (ERROR ,"%s is not a plain file" , filename); errno =ENOTTY ; goto xe; }if (stab.st_size >INT_MAX ) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"file %s is far too large" , filename); +LOG (ERROR ,"file %s is far too large" , filename); errno =EFBIG ; goto xe; }
@@ -329,9 +330,9 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, rs =fread (data,1 , datalen, f);if (rs != datalen) {if (ferror (f)) -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to read %s" , filename); +LOGE (ERROR ,"failed to read %s" , filename);else if (feof (f)) -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"%s changed size while we" +LOG (ERROR ,"%s changed size while we" " were reading it" , filename);else abort ();
@@ -341,16 +342,18 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,if (fclose (f)) { f =0 ; -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"failed to close %s" , filename); +LOGE (ERROR ,"failed to close %s" , filename); goto xe; }if (data_r) *data_r = data;if (datalen_r) *datalen_r = datalen; +GC_FREE ;return 0 ; xe: +GC_FREE ; e = errno;assert (e !=ENOENT );if (f)fclose (f);
Signature · 1 line
1.8.1.2
Re: [PATCH 3/4] opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in libxl_utils.c
Quoted 9 lines · Kelley Nielsen
Code cleanup - no functional changes
The convenience macros LOG and LOGE have been written to take the place of the old macros in the LIBXL__LOG* family. Replace the invocations of the old macros in the function
libxl_read_file_contents()with invocations of the corresponding new ones. Create a locallibxl__gcgc* for the new macros to use by invokingGC_INIT(ctx)at the top of the function, and clean it up by invokingGC_FREEat the two exit points.
In this case adding the GC_INIT was the correct approach, thanks.
tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 336
Quoted 4 lines
else if (feof(f))
tools/libxl/libxl_utils.c +1
-1-LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"%s changed size while we" +LOG (ERROR ,"%s changed size while we" " were reading it" , filename);
Please unwrap or reindent this one. With that changed:
PATCH 4/4 opw: libxl: use LOG instead of LIBXL__LOG in libxl_utils.c
In reply to Kelley NielsenTo conform to the new coding style, replace the invocation of LIBXL__LOG in the function libxl_pipe() in the file libxl_utils.c with an invocation of LOG. Create a local libxl__gc gc* for LOG to use by invoking GC_INIT(ctx) at the top of the function, and clean it up by invoking GC_FREE at the exit. Create a variable, ret, to consolidate exits in one place and avoid invoking GC_FREE twice.
--- tools/libxl/libxl_utils.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/libxl/libxl_utils.c +6 -3
@@ -477,11 +477,14 @@ int libxl__remove_directory(libxl__gc *gc, const char *dirpath)int libxl_pipe (libxl_ctx *ctx,int pipes[2 ]) { +GC_INIT (ctx); +int ret =0 ;if (pipe (pipes) <0 ) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Failed to create a pipe" ); -return -1 ; +LOG (ERROR ,"Failed to create a pipe" ); + ret =-1 ; } -return 0 ; +GC_FREE ; +return ret; } int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
Signature · 1 line
1.8.1.2
Re: [PATCH 4/4] opw: libxl: use LOG instead of LIBXL__LOG in libxl_utils.c
Quoted 10 lines · Kelley Nielsen
To conform to the new coding style, replace the invocation of
LIBXL__LOGin the functionlibxl_pipe()in the filelibxl_utils.cwith an invocation of LOG. Create a locallibxl__gcgc* for LOG to use by invokingGC_INIT(ctx)at the top of the function, and clean it up by invokingGC_FREEat the exit. Create a variable, ret, to consolidate exits in one place and avoid invokingGC_FREEtwice.Signed-off-by Kelley Nielsen <[email protected]>Suggested-by Ian Campbell <[email protected]>
I'll apply along with the other 3 as part of the resend.
Ian.
Quoted 8 lines · Kelley Nielsen
This patchset brings the file
libxl_utils.cmostly into compliance with the new coding style involving the convenience macros LOG, LOGE, and GCSPRINTF.[PATCH 1/4] opw: libxl: use GCSPRINTF instead of
libxl__sprintf[PATCH 2/4] opw: libxl: use LOGE instead ofLIBXL__LOG_ERRNOin [PATCH 3/4] opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in [PATCH 4/4] opw: libxl: use LOG instead ofLIBXL__LOGin
I think you should drop the "opw:" prefix from the subject.
David
Yes, Ian suggested that I put it in the subject prefix. I just wanted to give you a heads up that it was coming from someone who might not know what they're doing :-)
Quoted 5 lines · David Vrabel
Quoted 4 lines · Kelley Nielsen
This patchset brings the file
libxl_utils.cmostly into compliance with the new coding style involving the convenience macros LOG, LOGE, and GCSPRINTF.
Quoted 9 lines
Quoted 4 lines
[PATCH 1/4] opw: libxl: use GCSPRINTF instead of
libxl__sprintf[PATCH 2/4] opw: libxl: use LOGE instead ofLIBXL__LOG_ERRNOin [PATCH 3/4] opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in [PATCH 4/4] opw: libxl: use LOG instead ofLIBXL__LOGinI think you should drop the "opw:" prefix from the subject.
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 3 lines · Kelley Nielsen
Yes, Ian suggested that I put it in the subject prefix. I just wanted to give you a heads up that it was coming from someone who might not know what they're doing :-)
You can use git-format-patch --subject-prefix "OPW PATCH" and that would nicely make the '[OPW PATCH] libxl'.. and when one uses git-am it strips out the '[*]' part.
Quoted 23 lines · David Vrabel
Quoted 6 lines · Kelley Nielsen
Quoted 4 lines
This patchset brings the file
libxl_utils.cmostly into compliance with the new coding style involving the convenience macros LOG, LOGE, and GCSPRINTF.Quoted 9 lines
Quoted 4 lines
[PATCH 1/4] opw: libxl: use GCSPRINTF instead of
libxl__sprintf[PATCH 2/4] opw: libxl: use LOGE instead ofLIBXL__LOG_ERRNOin [PATCH 3/4] opw: libxl: use LOG and LOGE instead of LIBXL__LOG* in [PATCH 4/4] opw: libxl: use LOG instead ofLIBXL__LOGinI think you should drop the "opw:" prefix from the subject.
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel