Skip to contentSkip to conversation

libxl: drop bootloader output if xenconsole file descriptor is not available for writing

PATCH In review Roger Pau Monne 2 participants 4 messages Oct 10, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: drop bootloader output if xenconsole file descriptor is not available for writing

# HG changeset patch
# User Roger Pau Monne <[email protected]>
# Date 1318255452 -7200
# Node ID 1ebcb5d27ead38d6713d865704394ca99444f93c
# Parent a5b8d5c8c98e0dd17368eea1801a8edaf1e79e69
libxl: drop bootloader output if xenconsole file descriptor is not available for writing.

Drop output from bootloader if the pty buffer is full and we cannot write more data. Prevents the bootloader from getting stuck when using ptys with small buffers.

tools/libxl/libxl_bootloader.c +12 -1
diff -r a5b8d5c8c98e -r 1ebcb5d27ead tools/libxl/libxl_bootloader.c
@@ -169,6 +169,7 @@ static char * bootloader_interact(libxl_
 
     size_t nr_out = 0, size_out = 0;
     char *output = NULL;
+    struct timeval timeout;
 
     /* input from xenconsole. read on xenconsoled_fd write to bootloader_fd */
     int xenconsoled_prod = 0, xenconsoled_cons = 0;
@@ -177,9 +178,14 @@ static char * bootloader_interact(libxl_
     int bootloader_prod = 0, bootloader_cons = 0;
     char bootloader_buf[BOOTLOADER_BUF_SIZE];
 
+    /* Set timeout to 1s before starting to discard data */
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+
     while(1) {
         fd_set wsel, rsel;
         int nfds;
+        int space;
 
         if (xenconsoled_prod == xenconsoled_cons)
             xenconsoled_prod = xenconsoled_cons = 0;
@@ -208,9 +214,14 @@ static char * bootloader_interact(libxl_
             nfds = bootloader_fd + 1 > nfds ? bootloader_fd + 1 : nfds;
         }
 
-        ret = select(nfds, &rsel, &wsel, NULL, NULL);
+        ret = select(nfds, &rsel, &wsel, NULL, &timeout);
         if (ret < 0)
             goto out_err;
+        if (ret == 0) {
+            /* Timeout reached, force clear buffers */
+            xenconsoled_prod = xenconsoled_cons;
+            bootloader_prod = bootloader_cons;
+        }
 
         /* Input from xenconsole, read xenconsoled_fd, write bootloader_fd */
         if (FD_ISSET(xenconsoled_fd, &rsel)) {
#1 lore raw

PATCH 1/1 libxl: drop bootloader output if xenconsole file descriptor is not available for writing

# HG changeset patch
# User Roger Pau Monne <[email protected]>
# Date 1318255572 -7200
# Node ID 0012a80df7a0fe07497d58423ba651b302d84745
# Parent a5b8d5c8c98e0dd17368eea1801a8edaf1e79e69
libxl: drop bootloader output if xenconsole file descriptor is not available for writing.

Drop output from bootloader if the pty buffer is full and we cannot write more data. Prevents the bootloader from getting stuck when using ptys with small buffers.

tools/libxl/libxl_bootloader.c +11 -1
diff -r a5b8d5c8c98e -r 0012a80df7a0 tools/libxl/libxl_bootloader.c
@@ -169,6 +169,7 @@ static char * bootloader_interact(libxl_
 
     size_t nr_out = 0, size_out = 0;
     char *output = NULL;
+    struct timeval timeout;
 
     /* input from xenconsole. read on xenconsoled_fd write to bootloader_fd */
     int xenconsoled_prod = 0, xenconsoled_cons = 0;
@@ -177,6 +178,10 @@ static char * bootloader_interact(libxl_
     int bootloader_prod = 0, bootloader_cons = 0;
     char bootloader_buf[BOOTLOADER_BUF_SIZE];
 
+    /* Set timeout to 1s before starting to discard data */
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+
     while(1) {
         fd_set wsel, rsel;
         int nfds;
@@ -208,9 +213,14 @@ static char * bootloader_interact(libxl_
             nfds = bootloader_fd + 1 > nfds ? bootloader_fd + 1 : nfds;
         }
 
-        ret = select(nfds, &rsel, &wsel, NULL, NULL);
+        ret = select(nfds, &rsel, &wsel, NULL, &timeout);
         if (ret < 0)
             goto out_err;
+        if (ret == 0) {
+            /* Timeout reached, force clear buffers */
+            xenconsoled_prod = xenconsoled_cons;
+            bootloader_prod = bootloader_cons;
+        }
 
         /* Input from xenconsole, read xenconsoled_fd, write bootloader_fd */
         if (FD_ISSET(xenconsoled_fd, &rsel)) {
#2 lore raw
In reply to Roger Pau Monne
Quoted 24 lines · Roger Pau Monne

# HG changeset patch
# User Roger Pau Monne <[email protected]>
# Date 1318255452 -7200
# Node ID 1ebcb5d27ead38d6713d865704394ca99444f93c
# Parent a5b8d5c8c98e0dd17368eea1801a8edaf1e79e69
libxl: drop bootloader output if xenconsole file descriptor is not available for writing.

Drop output from bootloader if the pty buffer is full and we cannot write more data. Prevents the bootloader from getting stuck when using ptys with small buffers.

diff -r a5b8d5c8c98e -r 1ebcb5d27ead tools/libxl/libxl_bootloader.c

tools/libxl/libxl_bootloader.c +1 -0
@@ -169,6 +169,7 @@ static char * bootloader_interact(libxl_
 
     size_t nr_out = 0, size_out = 0;
     char *output = NULL;
+    struct timeval timeout;
 
     /* input from xenconsole. read on xenconsoled_fd write to bootloader_fd */
     int xenconsoled_prod = 0, xenconsoled_cons = 0;
@@ -177,9 +178,14 @@ static char * bootloader_interact(libxl_
     int bootloader_prod = 0, bootloader_cons = 0;

tools/libxl/libxl_bootloader.c static char * bootloader_interact(libxl_ · line 188

Quoted 10 lines
tools/libxl/libxl_bootloader.c +5 -0
     char bootloader_buf[BOOTLOADER_BUF_SIZE];
 
+    /* Set timeout to 1s before starting to discard data */
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+
     while(1) {
         fd_set wsel, rsel;
         int nfds;
+        int space;

You appear to introduce an unreferenced variable here.

Quoted 24 lines
tools/libxl/libxl_bootloader.c +6 -1
         if (xenconsoled_prod == xenconsoled_cons)
             xenconsoled_prod = xenconsoled_cons = 0;
@@ -208,9 +214,14 @@ static char * bootloader_interact(libxl_
             nfds = bootloader_fd + 1 > nfds ? bootloader_fd + 1 : nfds;
         }
 
-        ret = select(nfds, &rsel, &wsel, NULL, NULL);
+        ret = select(nfds, &rsel, &wsel, NULL, &timeout);
         if (ret < 0)
             goto out_err;
+        if (ret == 0) {
+            /* Timeout reached, force clear buffers */
+            xenconsoled_prod = xenconsoled_cons;
+            bootloader_prod = bootloader_cons;
+        }
 
         /* Input from xenconsole, read xenconsoled_fd, write bootloader_fd */
         if (FD_ISSET(xenconsoled_fd, &rsel)) {

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

Signature · 2 lines
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com
#3 lore raw

2011/10/10 Andrew Cooper <[email protected]>:

Quoted 29 lines · Roger Pau Monne
Quoted 26 lines

# HG changeset patch
# User Roger Pau Monne <[email protected]>
# Date 1318255452 -7200
# Node ID 1ebcb5d27ead38d6713d865704394ca99444f93c
# Parent  a5b8d5c8c98e0dd17368eea1801a8edaf1e79e69
libxl: drop bootloader output if xenconsole file descriptor is not available for writing.

Drop output from bootloader if the pty buffer is full and we cannot write more data. Prevents the bootloader from getting stuck when using ptys with small buffers.

diff -r a5b8d5c8c98e -r 1ebcb5d27ead tools/libxl/libxl_bootloader.c

tools/libxl/libxl_bootloader.c  Mon Oct 10 16:04:12 2011 +0200 renamed from tools/libxl/libxl_bootloader.c  Mon Oct 10 11:26:22 2011 +0200 +1 -0
@@ -169,6 +169,7 @@ static char * bootloader_interact(libxl_
 
      size_t nr_out = 0, size_out = 0;
      char *output = NULL;
+    struct timeval timeout;
 
      /* input from xenconsole. read on xenconsoled_fd write to bootloader_fd */
      int xenconsoled_prod = 0, xenconsoled_cons = 0;
@@ -177,9 +178,14 @@ static char * bootloader_interact(libxl_
      int bootloader_prod = 0, bootloader_cons = 0;
      char bootloader_buf[BOOTLOADER_BUF_SIZE];
 
Quoted 10 lines

tools/libxl/libxl_bootloader.c  Mon Oct 10 16:04:12 2011 +0200 static char * bootloader_interact(libxl_ · line 188

Quoted 8 lines
tools/libxl/libxl_bootloader.c  Mon Oct 10 16:04:12 2011 +0200 renamed from tools/libxl/libxl_bootloader.c  Mon Oct 10 11:26:22 2011 +0200 +5 -0
+    /* Set timeout to 1s before starting to discard data */
+    timeout.tv_sec = 1;
+    timeout.tv_usec = 0;
+
      while(1) {
          fd_set wsel, rsel;
          int nfds;
+        int space;

You appear to introduce an unreferenced variable here.

Yes I've missed that one, sorry, second patch is ok.