From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yosuke Iwamatsu Subject: Re: [PATCH] xend: open qemu-dm log files in append mode Date: Mon, 30 Jun 2008 18:20:01 +0900 Message-ID: <4868A541.40800@ab.jp.nec.com> References: <486323E3.3000407@ab.jp.nec.com> <18531.44047.726185.484243@mariner.uk.xensource.com> <20080626145100.GO20952@redhat.com> <18531.45028.236043.309416@mariner.uk.xensource.com> <4864B35C.6050403@ab.jp.nec.com> <18532.60800.698530.515126@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030109060302090507050603" Return-path: In-Reply-To: <18532.60800.698530.515126@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: Yuji Shimada , xen-devel@lists.xensource.com, berrange@redhat.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------030109060302090507050603 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Ian Jackson wrote: > It would be good if the maximum logfiles to keep would be > configurable; making it part of the ordinary xend configuration would > do. > > Also, one minor stylistic point. This idiom > if os.path.exists(self.logfile + ".%d" % nr_max_log_rotation): > is rather unusual, although not actually wrong. It combines string > concatenation and %-formatting. Surely one of > "%s.%d" % (self.logfile, nr_max_log_rotation) > self.logfile + '.' + `nr_max_log_rotation` > would be better ? (I would have used the former.) Done in qemu-log-rotate-config.patch. I've set the logrotate count default to 10. It is small enough not to annoy users by filling xen log directory with many files, I think. I also created a patch (qemu-log-append-config.patch) which opens qemu-dm logfiles in append mode if the logrotate count is 0. If this makes sense, please apply it after qemu-log-rotate-config.patch. Thanks, --Yosuke --------------030109060302090507050603 Content-Type: all/allfiles; name="qemu-log-append-config.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-log-append-config.patch" xend: open qemu-dm logfile in append mode if log rotation is disabled by config. Signed-off-by: Yosuke Iwamatsu diff -r 7e4f23538380 tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Mon Jun 30 16:55:07 2008 +0900 +++ b/tools/python/xen/xend/image.py Mon Jun 30 17:28:52 2008 +0900 @@ -380,8 +380,10 @@ class ImageHandler: self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(self.vm.info['name_label']) # rotate log + logfile_mode = os.O_WRONLY|os.O_CREAT|os.O_APPEND logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count() if logrotate_count > 0: + logfile_mode |= os.O_TRUNC if os.path.exists("%s.%d" % (self.logfile, logrotate_count)): os.unlink("%s.%d" % (self.logfile, logrotate_count)) for n in range(logrotate_count - 1, 0, -1): @@ -392,7 +394,7 @@ class ImageHandler: os.rename(self.logfile, self.logfile + ".1") null = os.open("/dev/null", os.O_RDONLY) - logfd = os.open(self.logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC|os.O_APPEND) + logfd = os.open(self.logfile, logfile_mode) sys.stderr.flush() pid = os.fork() --------------030109060302090507050603 Content-Type: all/allfiles; name="qemu-log-rotate-config.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-log-rotate-config.patch" xend: improve the rotation of qemu-dm logfiles. Signed-off-by: Yosuke Iwamatsu diff -r 10e79ad54c91 tools/examples/xend-config.sxp --- a/tools/examples/xend-config.sxp Fri Jun 27 16:08:56 2008 +0100 +++ b/tools/examples/xend-config.sxp Mon Jun 30 16:46:03 2008 +0900 @@ -242,3 +242,6 @@ # Script to run when the label of a resource has changed. #(resource-label-change-script '') + +# Rotation count of qemu-dm log file. +#(qemu-dm-logrotate-count 10) diff -r 10e79ad54c91 tools/python/xen/xend/XendOptions.py --- a/tools/python/xen/xend/XendOptions.py Fri Jun 27 16:08:56 2008 +0100 +++ b/tools/python/xen/xend/XendOptions.py Mon Jun 30 16:46:03 2008 +0900 @@ -132,6 +132,9 @@ class XendOptions: """Default script to configure a backend network interface""" vif_script = osdep.vif_script + """Default rotation count of qemu-dm log file.""" + qemu_dm_logrotate_count = 10 + def __init__(self): self.configure() @@ -350,6 +353,10 @@ class XendOptions: def get_vnc_x509_verify(self): return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify) + + def get_qemu_dm_logrotate_count(self): + return self.get_config_int("qemu-dm-logrotate-count", + self.qemu_dm_logrotate_count) class XendOptionsFile(XendOptions): diff -r 10e79ad54c91 tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Fri Jun 27 16:08:56 2008 +0100 +++ b/tools/python/xen/xend/image.py Mon Jun 30 16:46:03 2008 +0900 @@ -378,10 +378,18 @@ class ImageHandler: # keep track of pid and spawned options to kill it later self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(self.vm.info['name_label']) - if os.path.exists(self.logfile): - if os.path.exists(self.logfile + ".1"): - os.unlink(self.logfile + ".1") - os.rename(self.logfile, self.logfile + ".1") + + # rotate log + logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count() + if logrotate_count > 0: + if os.path.exists("%s.%d" % (self.logfile, logrotate_count)): + os.unlink("%s.%d" % (self.logfile, logrotate_count)) + for n in range(logrotate_count - 1, 0, -1): + if os.path.exists("%s.%d" % (self.logfile, n)): + os.rename("%s.%d" % (self.logfile, n), + "%s.%d" % (self.logfile, (n + 1))) + if os.path.exists(self.logfile): + os.rename(self.logfile, self.logfile + ".1") null = os.open("/dev/null", os.O_RDONLY) logfd = os.open(self.logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC|os.O_APPEND) --------------030109060302090507050603 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------030109060302090507050603--