Skip to contentSkip to conversation

PATCH: Use name instead of pid in QEMU logs

PATCH Daniel P. Berrange 4 participants 7 messages Jun 1, 2007 – Jun 12, 2007

lore
Share & tools
lore
#0 lore raw

The attached patch changes the logfile name generated by qemu-dm to use the pattern qemu-dm-[NAME].log instead of qemu-dm-[PID].log. This makes it easier for the adminsitrator to figure out which log corresponds to which guest (particularly after a crash where you no long know what PID the qemu-dm process for your guest had). It also prevents the number of log files from growing unbounded.

Dan.

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
tools/ioemu/target-i386-dm/exec-dm.c +19 -21
diff -r 089696e0c603 tools/ioemu/target-i386-dm/exec-dm.c
@@ -124,7 +124,6 @@ static int io_mem_nb = 1;
 static int io_mem_nb = 1;
 
 /* log support */
-char *logfilename = "/tmp/qemu.log";
 FILE *logfile;
 int loglevel;
 
@@ -166,29 +165,28 @@ void cpu_set_log(int log_flags)
 void cpu_set_log(int log_flags)
 {
     loglevel = log_flags;
+    if (!logfile)
+      logfile = stderr;
+}
+
+void cpu_set_log_filename(const char *filename)
+{
+    logfile = fopen(filename, "w");
     if (!logfile) {
-        logfile = fopen(logfilename, "w");
-        if (!logfile) {
-            perror(logfilename);
-            _exit(1);
-        }
+        perror(filename);
+	_exit(1);
+    }
 #if !defined(CONFIG_SOFTMMU)
-        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
-        {
-            static uint8_t logfile_buf[4096];
-            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
-        }
+    /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
+    {
+        static uint8_t logfile_buf[4096];
+	setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
+    }
 #else
-        setvbuf(logfile, NULL, _IOLBF, 0);
-#endif
-        stdout = logfile;
-        stderr = logfile;
-    }
-}
-
-void cpu_set_log_filename(const char *filename)
-{
-    logfilename = strdup(filename);
+    setvbuf(logfile, NULL, _IOLBF, 0);
+#endif
+    stdout = logfile;
+    stderr = logfile;
 }
 
 /* mask must never be zero, except for A20 change call */
tools/ioemu/vl.c +6 -4
diff -r 089696e0c603 tools/ioemu/vl.c
@@ -7144,9 +7144,7 @@ int main(int argc, char **argv)
     nb_nics = 0;
     /* default mac address of the first network interface */
     
-    /* init debug */
-    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
-    cpu_set_log_filename(qemu_dm_logfilename);
+    /* Init logs to stderr to start with */
     cpu_set_log(0);
     
     optind = 1;
@@ -7525,7 +7523,7 @@ int main(int argc, char **argv)
                 semihosting_enabled = 1;
                 break;
             case QEMU_OPTION_domainname:
-                strncat(domain_name, optarg, sizeof(domain_name) - 20);
+                strncpy(domain_name, optarg, sizeof(domain_name) - 1);
                 break;
             case QEMU_OPTION_d:
                 domid = atoi(optarg);
@@ -7547,6 +7545,10 @@ int main(int argc, char **argv)
             }
         }
     }
+
+    /* Now send logs to our named config */
+    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm-%s.log", domain_name);
+    cpu_set_log_filename(qemu_dm_logfilename);
 
 #ifndef _WIN32
     if (daemonize && !nographic && vnc_display == NULL && vncunused == 0) {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Hurrah! Sounds like a brilliant idea to me (shuddering as remember the hundreds of qemu dm log files sitting around on my system).

Cheers,
Mark

Quoted 10 lines · Daniel P. Berrange

The attached patch changes the logfile name generated by qemu-dm to use the pattern qemu-dm-[NAME].log instead of qemu-dm-[PID].log. This makes it easier for the adminsitrator to figure out which log corresponds to which guest (particularly after a crash where you no long know what PID the qemu-dm process for your guest had). It also prevents the number of log files from growing unbounded.

Dan.

Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat?  And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!
#2 lore raw
In reply to Daniel P. Berrange
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Daniel P. Berrange
Sent: 01 June 2007 01:56
To: [email protected]
Subject: [Xen-devel] PATCH: Use name instead of pid in QEMU logs

Quoted 10 lines

The attached patch changes the logfile name generated by qemu-dm to use the
pattern qemu-dm-[NAME].log instead of qemu-dm-[PID].log. This makes it
easier for the adminsitrator to figure out which log corresponds to which
guest (particularly after a crash where you no long know what PID the qemu-dm process for your guest had). It also prevents the number of log
files from growing unbounded.

Great stuff. I'll buy you a beer (or alternative beverage of your choice) next time we're in the same place...

--
Mats

Quoted 14 lines

Dan.

Signature · 8 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 
978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/  
            -=|
|=-               Projects: http://freshmeat.net/~danielpb/   
            -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF 
F742 7D3B 9505  -=| 
#3 lore raw
In reply to Daniel P. Berrange
Quoted 8 lines · Daniel P. Berrange

The attached patch changes the logfile name generated by qemu-dm to use the pattern qemu-dm-[NAME].log instead of qemu-dm-[PID].log. This makes it easier for the adminsitrator to figure out which log corresponds to which guest (particularly after a crash where you no long know what PID the qemu-dm process for your guest had). It also prevents the number of log files from growing unbounded.

I've just seen that this patch having been included in 15212:fc8e40692690 was then effectively reverted in 15219:f45c84dd5f41 by switching QEMU to use Domain ID in log files.

This causes just as much pain for support purposes as the original naming based on PID. Now when a user reports problems with domain 'foo' crashing, instead of just asking them to send /var/log/xen/qemu-foo.log we're back to having users to dig around in /var/log/xen/xend.log to try and figure out what domain ID their guest was running with before it crashed and then find the qemu-[DOMAIN ID].log file that matches.

  changeset:   15219:f45c84dd5f41
  user:        [email protected]
  date:        Tue Jun 05 09:59:34 2007 +0100
  files:       tools/ioemu/vl.c

description:
qemu: Use domid in qemu log name. Can be related back to domain name or uuid via xend logs, less unique than pids to prevent excessive number of log files hanging around, yet not immediately reused (unlike e.g., after domain crash or reboot) where previous log file is immediately overwritten. Not using domain names in logs avoids and chance of unprintable charcatres becoming embedded in filenames.

All domain names should be validated by XenD to contain printable characters only - they are displayed & used all over the place in numerous tools where having non-printale characters will cause plenty of trouble.

As for overwriting the log file with a domain autorestart after a crash, the logfile ought to be opened in append mode (w+ instead of w) - logrotate scripts can handle cleanup of logfiles

I am happy to submit further patches to validate domain names in XenD and switch to opening the file in append mode, if changeset 15219 were to be reverted.

Regards,
Dan.

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
#4 lore raw
Quoted 6 lines

This causes just as much pain for support purposes as the original naming based on PID. Now when a user reports problems with domain 'foo' crashing, instead of just asking them to send /var/log/xen/qemu-foo.log we're back to having users to dig around in /var/log/xen/xend.log to try and figure out what domain ID their guest was running with before it crashed and then find the qemu-[DOMAIN ID].log file that matches.

+1 to that

Quoted 3 lines

As for overwriting the log file with a domain autorestart after a crash, the logfile ought to be opened in append mode (w+ instead of w) - logrotate scripts can handle cleanup of logfiles

Or just rename on restart e.g. mydomain.log -> mydomain.log.old or mydomain.log.1 etc.

Quoted 3 lines

I am happy to submit further patches to validate domain names in XenD and switch to opening the file in append mode, if changeset 15219 were to be reverted.

I think this is a better solution for users, plus I'd find it handy during debugging. Sure, I'm more than qualified to poke in the xend.log file to figure out the domain ID, but it'd be nice to not need to bother.

Cheers,
Mark

Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat?  And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!
#5 lore raw
In reply to Daniel P. Berrange
Quoted 11 lines · Daniel P. Berrange

All domain names should be validated by XenD to contain printable characters only - they are displayed & used all over the place in numerous tools where having non-printale characters will cause plenty of trouble.

As for overwriting the log file with a domain autorestart after a crash, the logfile ought to be opened in append mode (w+ instead of w) - logrotate scripts can handle cleanup of logfiles

I am happy to submit further patches to validate domain names in XenD and switch to opening the file in append mode, if changeset 15219 were to be reverted.

Personally I don't much care either way. Christian didn't like the names in log filenames, and he maintains the qemu patchset. :-)

-- Keir

#6 lore raw
Quoted 6 lines · Keir Fraser
Quoted 3 lines

I am happy to submit further patches to validate domain names in XenD and switch to opening the file in append mode, if changeset 15219 were to be reverted.

Personally I don't much care either way. Christian didn't like the names in log filenames, and he maintains the qemu patchset. :-)

I'll elaborate a bit: imo the qemu logs are second only to xend-debug.log for uselessness, particularly for ordinary users. I would support sending the few lines of output that usually get written there to /dev/null instead by default.

-- Keir