WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] libxl: reimplement buffer for bootloading

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: reimplement buffer for bootloading and drop data if buffer is full.
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Wed, 02 Nov 2011 22:00:16 +0000
Delivery-date: Wed, 02 Nov 2011 15:03:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1320248814 0
# Node ID f6f7506c5efb250102038e202cf2b836c8b0c550
# Parent  698693ac8bca009470c1044f917882824546a893
libxl: reimplement buffer for bootloading and drop data if buffer is full.

Implement a buffer for the bootloading process that appends data to
the end until it's full. Drop the whole buffer if a timeout has
occurred and the buffer is full. Prevents the bootloader from getting
stuck when using ptys with small buffers.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 698693ac8bca -r f6f7506c5efb tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c    Thu Oct 27 11:54:16 2011 +0200
+++ b/tools/libxl/libxl_bootloader.c    Wed Nov 02 15:46:54 2011 +0000
@@ -28,7 +28,8 @@
 #include "flexarray.h"
 
 #define XENCONSOLED_BUF_SIZE 16
-#define BOOTLOADER_BUF_SIZE 1024
+#define BOOTLOADER_BUF_SIZE 4096
+#define BOOTLOADER_TIMEOUT 1
 
 static char **make_bootloader_args(libxl__gc *gc,
                                    libxl_domain_build_info *info,
@@ -169,6 +170,7 @@
 
     size_t nr_out = 0, size_out = 0;
     char *output = NULL;
+    struct timeval wait;
 
     /* input from xenconsole. read on xenconsoled_fd write to bootloader_fd */
     int xenconsoled_prod = 0, xenconsoled_cons = 0;
@@ -181,39 +183,67 @@
         fd_set wsel, rsel;
         int nfds;
 
-        if (xenconsoled_prod == xenconsoled_cons)
-            xenconsoled_prod = xenconsoled_cons = 0;
-        if (bootloader_prod == bootloader_cons)
-            bootloader_prod = bootloader_cons = 0;
+        /* Set timeout to 1s before starting to discard data */
+        wait.tv_sec = BOOTLOADER_TIMEOUT;
+        wait.tv_usec = 0;
+
+        /* Move buffers around to drop already consumed data */
+        if (xenconsoled_cons > 0) {
+            xenconsoled_prod -= xenconsoled_cons;
+            memmove(xenconsoled_buf, &xenconsoled_buf[xenconsoled_cons],
+                    xenconsoled_prod);
+            xenconsoled_cons = 0;
+        }
+        if (bootloader_cons > 0) {
+            bootloader_prod -= bootloader_cons;
+            memmove(bootloader_buf, &bootloader_buf[bootloader_cons],
+                    bootloader_prod);
+            bootloader_cons = 0;
+        }
 
         FD_ZERO(&rsel);
         FD_SET(fifo_fd, &rsel);
         nfds = fifo_fd + 1;
-        if (xenconsoled_prod == 0 || (xenconsoled_prod < BOOTLOADER_BUF_SIZE 
&& xenconsoled_cons == 0)) {
+        if (xenconsoled_prod < XENCONSOLED_BUF_SIZE) {
+            /* The buffer is not full, try to read more data */
             FD_SET(xenconsoled_fd, &rsel);
             nfds = xenconsoled_fd + 1 > nfds ? xenconsoled_fd + 1 : nfds;
-        }
-        if (bootloader_prod == 0 || (bootloader_prod < BOOTLOADER_BUF_SIZE && 
bootloader_cons == 0)) {
+        } 
+        if (bootloader_prod < BOOTLOADER_BUF_SIZE) {
+            /* The buffer is not full, try to read more data */
             FD_SET(bootloader_fd, &rsel);
             nfds = bootloader_fd + 1 > nfds ? bootloader_fd + 1 : nfds;
         }
 
         FD_ZERO(&wsel);
-        if (bootloader_prod != bootloader_cons) {
+        if (bootloader_prod > 0) {
+            /* The buffer has data to consume */
             FD_SET(xenconsoled_fd, &wsel);
             nfds = xenconsoled_fd + 1 > nfds ? xenconsoled_fd + 1 : nfds;
         }
-        if (xenconsoled_prod != xenconsoled_cons) {
+        if (xenconsoled_prod > 0) {
+            /* The buffer has data to consume */
             FD_SET(bootloader_fd, &wsel);
             nfds = bootloader_fd + 1 > nfds ? bootloader_fd + 1 : nfds;
         }
 
-        ret = select(nfds, &rsel, &wsel, NULL, NULL);
-        if (ret < 0)
+        if (xenconsoled_prod == XENCONSOLED_BUF_SIZE ||
+            bootloader_prod == BOOTLOADER_BUF_SIZE)
+            ret = select(nfds, &rsel, &wsel, NULL, &wait);
+        else
+            ret = select(nfds, &rsel, &wsel, NULL, NULL);
+        if (ret < 0) {
+            if (errno == EINTR)
+                continue;
             goto out_err;
+        }
 
         /* Input from xenconsole, read xenconsoled_fd, write bootloader_fd */
-        if (FD_ISSET(xenconsoled_fd, &rsel)) {
+        if (ret == 0 && xenconsoled_prod == XENCONSOLED_BUF_SIZE) {
+            /* Drop the buffer */
+            xenconsoled_prod = 0;
+            xenconsoled_cons = 0;
+        } else if (FD_ISSET(xenconsoled_fd, &rsel)) {
             ret = read(xenconsoled_fd, &xenconsoled_buf[xenconsoled_prod], 
XENCONSOLED_BUF_SIZE - xenconsoled_prod);
             if (ret < 0 && errno != EIO && errno != EAGAIN)
                 goto out_err;
@@ -229,7 +259,11 @@
         }
 
         /* Input from bootloader, read bootloader_fd, write xenconsoled_fd */
-        if (FD_ISSET(bootloader_fd, &rsel)) {
+        if (ret == 0 && bootloader_prod == BOOTLOADER_BUF_SIZE) {
+            /* Drop the buffer */
+            bootloader_prod = 0;
+            bootloader_cons = 0;
+        } else if (FD_ISSET(bootloader_fd, &rsel)) {
             ret = read(bootloader_fd, &bootloader_buf[bootloader_prod], 
BOOTLOADER_BUF_SIZE - bootloader_prod);
             if (ret < 0 && errno != EIO && errno != EAGAIN)
                 goto out_err;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: reimplement buffer for bootloading and drop data if buffer is full., Xen patchbot-unstable <=