Re: [libvirt] [PATCH] fix trailing blanks

2008-05-29 Thread Daniel Veillard
On Thu, May 29, 2008 at 01:35:55PM +0900, Atsushi SAKAI wrote:
 Hi, Rich
 
 Fix trailing blanks.
 
 http://builder.virt-manager.org/module-libvirt--devel.html

  +1 , please push the fix,

   thanks !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] fix trailing blanks

2008-05-29 Thread Atsushi SAKAI
Hi, Daniel

Thank you.
I already commited.

By the way, Test-AutoBuild is great tool ,
since it generates RSS for failed module only.

Thanks
Atsushi SAKAI


Daniel Veillard [EMAIL PROTECTED] wrote:

 On Thu, May 29, 2008 at 01:35:55PM +0900, Atsushi SAKAI wrote:
  Hi, Rich
  
  Fix trailing blanks.
  
  http://builder.virt-manager.org/module-libvirt--devel.html
 
   +1 , please push the fix,
 
thanks !
 
 Daniel
 
 -- 
 Red Hat Virtualization group http://redhat.com/virtualization/
 Daniel Veillard  | virtualization library  http://libvirt.org/
 [EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
 http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] fix trailing blanks

2008-05-29 Thread Daniel P. Berrange
On Thu, May 29, 2008 at 01:35:55PM +0900, Atsushi SAKAI wrote:
 Hi, Rich
 
 Fix trailing blanks.

This patch broke the test suite - the virsh command was generating data
with trailing blanks.

So I've added the following patch too, which stops it generating blanks

Dan.

Index: src/virsh.c
===
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.154
diff -u -p -r1.154 virsh.c
--- src/virsh.c 27 May 2008 09:41:26 -  1.154
+++ src/virsh.c 29 May 2008 14:54:35 -
@@ -1535,7 +1535,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cm
 vshPrint(ctl, %-15s %lu kB\n, _(Max memory:),
  info.maxMem);
 else
-vshPrint(ctl, %-15s %-15s\n, _(Max memory:),
+vshPrint(ctl, %-15s %s\n, _(Max memory:),
  _(no limit));
 
 vshPrint(ctl, %-15s %lu kB\n, _(Used memory:),
@@ -1546,7 +1546,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cm
 }
 
 if (!virDomainGetAutostart(dom, autostart)) {
-vshPrint(ctl, %-15s %-15s\n, _(Autostart:),
+vshPrint(ctl, %-15s %s\n, _(Autostart:),
  autostart ? _(enable) : _(disable) );
 }
 


-- 
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/4] lxc: ignore ECHILD errors during vm cleanup

2008-05-29 Thread Dave Leskovec
This patch ignores ECHILD from waitpid().  This can happen if libvirtd was
restarted and the container processes are no longer the children of libvirtd.

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization

---
 src/lxc_driver.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: b/src/lxc_driver.c
===
--- a/src/lxc_driver.c	2008-05-29 14:34:27.0 -0700
+++ b/src/lxc_driver.c	2008-05-29 14:34:45.0 -0700
@@ -943,7 +943,7 @@
 while (((waitRc = waitpid(vm-def-id, childStatus, 0)) == -1) 
errno == EINTR);
 
-if (waitRc != vm-def-id) {
+if ((waitRc != vm-def-id)  (errno != ECHILD)) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
  _(waitpid failed to wait for container %d: %d %s),
  vm-def-id, waitRc, strerror(errno));
@@ -976,7 +976,7 @@
 while (((waitRc = waitpid(vm-pid, childStatus, 0)) == -1) 
errno == EINTR);
 
-if (waitRc != vm-pid) {
+if ((waitRc != vm-pid)  (errno != ECHILD)) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
  _(waitpid failed to wait for tty %d: %d %s),
  vm-pid, waitRc, strerror(errno));

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/4] lxc: validate tty pid before kill()

2008-05-29 Thread Dave Leskovec
This patch adds a check of the tty forwarding process pid before kill()'ing it
when destroying a domain.  If the pid value stored in the the vm structure is
invalid, sending a SIGKILL may be very bad if the value in question is something
like -1 (which just happens to be it's initial value).

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization

---
 src/lxc_driver.c |5 +
 1 file changed, 5 insertions(+)

Index: b/src/lxc_driver.c
===
--- a/src/lxc_driver.c	2008-05-12 23:30:58.0 -0700
+++ b/src/lxc_driver.c	2008-05-29 14:34:27.0 -0700
@@ -958,6 +958,11 @@
 }
 
 kill_tty:
+if (2  vm-pid) {
+DEBUG(not killing tty process with pid %d, vm-pid);
+goto tty_error_out;
+}
+
 if (0  (kill(vm-pid, SIGKILL))) {
 if (ESRCH != errno) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/4] lxc: cope with libvirtd restart

2008-05-29 Thread Dave Leskovec
This set of patches fixes a few items that occur as a result of a restart of
libvirtd when containers are running.  While this may not be a common situation,
the consequences of some of these (particularly losing the tty forwarding
process pid and later trying to kill it) can be quite severe.

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/4] lxc: store tty pid

2008-05-29 Thread Dave Leskovec
This patch will use a file in the lxc configuration directory to store the tty
forwarding process pid.  The pid is stored after the process is fork()'d.  It's
loaded during startup when the config for a running container is loaded.  The
file is deleted when the domain is undefined.  This should avoid losing the
tty pid over a libvirtd restart.

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization


--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 4/4] lxc: store tty pid

2008-05-29 Thread Dave Leskovec
er, this time with the patch

Dave Leskovec wrote:
 This patch will use a file in the lxc configuration directory to store the tty
 forwarding process pid.  The pid is stored after the process is fork()'d.  
 It's
 loaded during startup when the config for a running container is loaded.  The
 file is deleted when the domain is undefined.  This should avoid losing the
 tty pid over a libvirtd restart.
 

-- 
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
---
 src/lxc_conf.c   |  157 +++
 src/lxc_conf.h   |5 +
 src/lxc_driver.c |6 ++
 3 files changed, 168 insertions(+)

Index: b/src/lxc_conf.h
===
--- a/src/lxc_conf.h	2008-05-29 14:34:48.0 -0700
+++ b/src/lxc_conf.h	2008-05-29 14:34:51.0 -0700
@@ -71,6 +71,8 @@
 char configFile[PATH_MAX];
 char configFileBase[PATH_MAX];
 
+char ttyPidFile[PATH_MAX];
+
 int parentTty;
 int containerTtyFd;
 char *containerTty;
@@ -134,6 +136,9 @@
 lxc_driver_t *driver,
 const char *configFile,
 const char *name);
+int lxcStoreTtyPid(lxc_driver_t *driver, lxc_vm_t *vm);
+int lxcLoadTtyPid(lxc_driver_t *driver, lxc_vm_t *vm);
+int lxcDeleteTtyPid(lxc_vm_t *vm);
 
 void lxcError(virConnectPtr conn,
   virDomainPtr dom,
Index: b/src/lxc_conf.c
===
--- a/src/lxc_conf.c	2008-05-29 14:34:48.0 -0700
+++ b/src/lxc_conf.c	2008-05-29 14:34:51.0 -0700
@@ -650,6 +650,10 @@
 strncpy(vm-configFileBase, file, PATH_MAX);
 vm-configFile[PATH_MAX-1] = '\0';
 
+if (lxcLoadTtyPid(driver, vm)  0) {
+DEBUG0(failed to load tty pid);
+}
+
 return vm;
 }
 
@@ -883,4 +887,157 @@
 return 0;
 }
 
+/**
+ * lxcStoreTtyPid:
+ * @driver: pointer to driver
+ * @vm: Ptr to VM
+ *
+ * Stores the pid of the tty forward process contained in vm-pid
+ * SYSCONFIG_DIR/libvirt/lxc/{container_name}.pid
+ *
+ * Returns 0 on success or -1 in case of error
+ */
+int lxcStoreTtyPid(lxc_driver_t *driver, lxc_vm_t *vm)
+{
+int rc = -1;
+int fd = -1;
+FILE *file = NULL;
+
+if (vm-ttyPidFile[0] == 0x00) {
+if (virFileBuildPath(driver-configDir, vm-def-name, .pid,
+ vm-ttyPidFile, PATH_MAX)  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot construct tty pid file path));
+goto error_out;
+}
+}
+
+if ((fd = open(vm-ttyPidFile,
+   O_WRONLY | O_CREAT | O_TRUNC,
+   S_IRUSR | S_IWUSR))  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot create tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+goto error_out;
+}
+
+if (!(file = fdopen(fd, w))) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot fdopen tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+
+if (close(fd)  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(failed to close tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+}
+
+goto error_out;
+}
+
+if (fprintf(file, %d, vm-pid)  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot write tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+
+goto fclose_error_out;
+}
+
+rc = 0;
+
+fclose_error_out:
+if (fclose(file)  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(failed to close tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+}
+
+error_out:
+return rc;
+}
+
+/**
+ * lxcLoadTtyPid:
+ * @driver: pointer to driver
+ * @vm: Ptr to VM
+ *
+ * Loads the pid of the tty forward process from the pid file.
+ * SYSCONFIG_DIR/libvirt/lxc/{container_name}.pid
+ *
+ * Returns
+ *  0 - pid of tty process
+ *   0 - no tty pid file
+ *  -1 - error
+ */
+int lxcLoadTtyPid(lxc_driver_t *driver, lxc_vm_t *vm)
+{
+int rc = -1;
+FILE *file;
+
+if (vm-ttyPidFile[0] == 0x00) {
+if (virFileBuildPath(driver-configDir, vm-def-name, .pid,
+ vm-ttyPidFile, PATH_MAX)  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot construct tty pid file path));
+goto cleanup;
+}
+}
+
+if (!(file = fopen(vm-ttyPidFile, r))) {
+if (ENOENT == errno) {
+rc = 0;
+goto cleanup;
+}
+
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(cannot open tty pid file %s: %s),
+ vm-ttyPidFile, strerror(errno));
+goto cleanup;
+}
+
+if (fscanf(file, %d, (vm-pid))  0) {
+