[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] blktap2: update connection handling to fix build with gcc5



blktap2 fails to build with gcc5 because it fails to recognize that
there can be just one active connection (enforced in ctl_accept).

Rearrange the code to handle just a single connection.
Adjust two strerror calls to use errno instead -1 as input.

[  198s] block-log.c: In function 'ctl_close_sock':
[  198s] block-log.c:363:23: error: array subscript is above array bounds 
[-Werror=array-bounds]
[  198s]      if (s->connections[i].fd == fd) {
[  198s]                        ^
[  198s] block-log.c: In function 'ctl_request':
[  198s] block-log.c:549:23: error: array subscript is above array bounds 
[-Werror=array-bounds]
[  198s]      if (s->connections[i].id == id)
[  198s]                        ^
[  198s] cc1: all warnings being treated as errors
[  198s] 
/home/abuild/rpmbuild/BUILD/xen-4.6.31382/non-dbg/tools/blktap2/drivers/../../../tools/Rules.mk:107:
 recipe for target 'block-log.o' failed
[  198s] make[5]: *** [block-log.o] Error 1

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
---

This is just compile tested.


 tools/blktap2/drivers/block-log.c | 49 +++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/tools/blktap2/drivers/block-log.c 
b/tools/blktap2/drivers/block-log.c
index 5330cdc..10a6966 100644
--- a/tools/blktap2/drivers/block-log.c
+++ b/tools/blktap2/drivers/block-log.c
@@ -54,8 +54,6 @@
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
 
-#define MAX_CONNECTIONS 1
-
 typedef struct poll_fd {
   int          fd;
   event_id_t   id;
@@ -69,8 +67,7 @@ struct tdlog_state {
   char*        ctlpath;
   poll_fd_t    ctl;
 
-  int          connected;
-  poll_fd_t    connections[MAX_CONNECTIONS];
+  poll_fd_t    connection;
 
   char*        shmpath;
   void*        shm;
@@ -305,7 +302,7 @@ static int ctl_open(struct tdlog_state* s, const char* name)
   s->ctl.id = tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
                                            s->ctl.fd, 0, ctl_accept, s);
   if (s->ctl.id < 0) {
-    BWPRINTF("error register event handler: %s", strerror(s->ctl.id));
+    BWPRINTF("error register event handler: %s", strerror(errno));
     goto err_sock;
   }
 
@@ -323,12 +320,11 @@ static int ctl_open(struct tdlog_state* s, const char* 
name)
 
 static int ctl_close(struct tdlog_state* s)
 {
-  while (s->connected) {
-    s->connected--;
-    tapdisk_server_unregister_event(s->connections[s->connected].id);
-    close(s->connections[s->connected].fd);
-    s->connections[s->connected].fd = -1;
-    s->connections[s->connected].id = 0;
+  if (s->connection.fd >= 0) {
+    tapdisk_server_unregister_event(s->connection.id);
+    close(s->connection.fd);
+    s->connection.fd = -1;
+    s->connection.id = 0;
   }
 
   if (s->ctl.fd >= 0) {
@@ -359,15 +355,12 @@ static int ctl_close_sock(struct tdlog_state* s, int fd)
 {
   int i;
 
-  for (i = 0; i < s->connected; i++) {
-    if (s->connections[i].fd == fd) {
-      tapdisk_server_unregister_event(s->connections[i].id);
-      close(s->connections[i].fd);
-      s->connections[i].fd = -1;
-      s->connections[i].id = 0;
-      s->connected--;
-      return 0;
-    }
+  if (fd >= 0 && s->connection.fd == fd) {
+    tapdisk_server_unregister_event(s->connection.id);
+    close(s->connection.fd);
+    s->connection.fd = -1;
+    s->connection.id = 0;
+    return 0;
   }
 
   BWPRINTF("requested to close unknown socket %d", fd);
@@ -385,7 +378,7 @@ static void ctl_accept(event_id_t id, char mode, void 
*private)
     return;
   }
 
-  if (s->connected) {
+  if (s->connection.fd >= 0) {
     BWPRINTF("control session in progress, closing new connection");
     close(fd);
     return;
@@ -394,14 +387,13 @@ static void ctl_accept(event_id_t id, char mode, void 
*private)
   cid = tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
                                      fd, 0, ctl_request, s);
   if (cid < 0) {
-    BWPRINTF("error registering connection event handler: %s", strerror(cid));
+    BWPRINTF("error registering connection event handler: %s", 
strerror(errno));
     close(fd);
     return;
   }
 
-  s->connections[s->connected].fd = fd;
-  s->connections[s->connected].id = cid;
-  s->connected++;
+  s->connection.fd = fd;
+  s->connection.id = cid;
 }
 
 /* response format: 4 bytes shmsize, 0-terminated path */
@@ -545,9 +537,8 @@ static inline int ctl_find_connection(struct tdlog_state 
*s, event_id_t id)
 {
   int i;
 
-  for (i = 0; i < s->connected; i++)
-    if (s->connections[i].id == id)
-      return s->connections[i].fd;
+  if (s->connection.fd >= 0 && s->connection.id == id)
+      return s->connection.fd;
 
   BWPRINTF("unrecognized event callback id %d", id);
   return -1;
@@ -593,6 +584,8 @@ static int tdlog_open(td_driver_t* driver, const char* 
name, td_flag_t flags)
   memset(s, 0, sizeof(*s));
 
   s->size = driver->info.size;
+  s->connection.fd = -1;
+  s->ctl.fd = -1;
 
   if ((rc = writelog_create(s))) {
     tdlog_close(driver);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.