libxl: open logs with O_APPEND
PATCH 1/2 libxl: open logs with O_APPEND
Logfiles should always be opened for append.
tools/libxl/libxl_dm.c +1 -1
@@ -830,7 +830,7 @@ int libxl__create_device_model(libxl__gclibxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"%s/disable_pf" , path),"%d" , !info->xen_platform_pci);libxl_create_logfile (ctx,libxl__sprintf (gc,"qemu-dm-%s" , info->dom_name), &logfile); - logfile_w =open (logfile,O_WRONLY |O_CREAT ,0644 ); + logfile_w =open (logfile,O_WRONLY |O_CREAT |O_APPEND ,0644 );free (logfile); null =open ("/dev/null" ,O_RDONLY );
tools/libxl/xl_cmdimpl.c +2 -1
@@ -1597,7 +1597,8 @@ start:exit (-1 ); } -CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT ,0644 ) )<0 ); +CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND , +0644 ) )<0 );free (fullname);free (name);
PATCH 2/2 qemu-dm: open char devices "file:..." with O_APPEND
The "file:..." character open method is used by serial and parallel ports, to divert the output to a file (and these devices never produce any input). This is like a logfile, and so should be opened for append.
In qemu-xen-unstable, this is used only for the qemu stderr by libxl.
qemu-char.c +1 -1
@@ -588,7 +588,7 @@ static CharDriverState *qemu_chr_open_file_out(const char *file_out) {int fd_out; -TFR (fd_out =open (file_out,O_WRONLY |O_TRUNC |O_CREAT |O_BINARY ,0666 )); +TFR (fd_out =open (file_out,O_WRONLY |O_TRUNC |O_CREAT |O_BINARY |O_APPEND ,0666 ));if (fd_out <0 )return NULL ;return qemu_chr_open_fd (-1 , fd_out);
Re: [PATCH 2/2] qemu-dm: open char devices "file:..." with O_APPEND
Quoted 6 lines · Ian Jackson
The "file:..." character open method is used by serial and parallel ports, to divert the output to a file (and these devices never produce any input). This is like a logfile, and so should be opened for append.
In qemu-xen-unstable, this is used only for the qemu stderr by libxl.
Do we need a similar patch for qemu upstream?
Quoted 21 lines
Signed-off-by Ian Jackson <[email protected]>qemu-char.c +1
-1@@ -588,7 +588,7 @@ static CharDriverState *qemu_chr_open_file_out(const char *file_out) {int fd_out; -TFR (fd_out =open (file_out,O_WRONLY |O_TRUNC |O_CREAT |O_BINARY ,0666 )); +TFR (fd_out =open (file_out,O_WRONLY |O_TRUNC |O_CREAT |O_BINARY |O_APPEND ,0666 ));if (fd_out <0 )return NULL ;return qemu_chr_open_fd (-1 , fd_out);_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Ian Jackson
Logfiles should always be opened for append.
Signed-off-by Ian Jackson <[email protected]>
Both this and the 2/2 patch look sensible to me and are:
Quoted 16 lines
diff -r
a9c67c2daf4btools/libxl/libxl_dm.ctools/libxl/libxl_dm.c +1
-1@@ -830,7 +830,7 @@ int libxl__create_device_model(libxl__gclibxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"%s/disable_pf" , path),"%d" , !info->xen_platform_pci);libxl_create_logfile (ctx,libxl__sprintf (gc,"qemu-dm-%s" , info->dom_name), &logfile); - logfile_w =open (logfile,O_WRONLY |O_CREAT ,0644 ); + logfile_w =open (logfile,O_WRONLY |O_CREAT |O_APPEND ,0644 );free (logfile); null =open ("/dev/null" ,O_RDONLY );diff -r
a9c67c2daf4btools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.c start: · line 1601
Quoted 6 lines
tools/libxl/xl_cmdimpl.c +2
-1@@ -1597,7 +1597,8 @@ start:exit (-1 ); } -CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT ,0644 ) )<0 ); +CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND , +0644 ) )<0 );
fullname here came from libxl_create_logfile so has been rotated such that the file will be empty. I don't think O_APPEND is harmful or wrong given this though.
Do we need to arrange for libxl_create_logfile to be called for some of these others though?
Ian.
Quoted 8 lines
tools/libxl/xl_cmdimpl.c +0
-0free (fullname);free (name);_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ian Campbell writes ("Re: [Xen-devel] [PATCH 1/2] libxl: open logs with O_APPEND"):
Quoted 8 lines · Ian Jackson
Quoted 3 lines
Logfiles should always be opened for append.
Signed-off-by Ian Jackson <[email protected]>Both this and the 2/2 patch look sensible to me and are:
Acked-by Ian Campbell <[email protected]>
Thanks. I will apply then.
Quoted 7 lines
tools/libxl/xl_cmdimpl.c start: · line 1601
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +2
-1-CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT ,0644 ) )<0 ); +CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND , +0644 ) )<0 );fullname here came from
libxl_create_logfileso has been rotated such that the file will be empty. I don't thinkO_APPENDis harmful or wrong given this though.
O_APPEND sets a flag which applies throughout the future life of the open-file, so that even if the file later grows for some reason, writes will never overwrite existing data.
Quoted 2 lines
Do we need to arrange for
libxl_create_logfileto be called for some of these others though?
The one in libxl_create_device_model came from libxl_create_logfile too.
Obviously the one in qemu can't call libxl_create_logfile but in our setup it's fed /dev/stderr anyway.
Ian.