cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From 2efca7904a7a71d44bdf715208899e3bb29711df Mon Sep 17 00:00:00 2001
34b321
From: Fam Zheng <famz@redhat.com>
34b321
Date: Thu, 10 Mar 2016 04:00:51 +0100
34b321
Subject: [PATCH 2/5] nbd: Always call "close_fn" in nbd_client_new
34b321
34b321
RH-Author: Fam Zheng <famz@redhat.com>
34b321
Message-id: <1457582453-13835-2-git-send-email-famz@redhat.com>
34b321
Patchwork-id: 69757
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 1/3] nbd: Always call "close_fn" in nbd_client_new
34b321
Bugzilla: 1285453
34b321
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
34b321
34b321
Rename the parameter "close" to "close_fn" to disambiguous with
34b321
close(2).
34b321
34b321
This unifies error handling paths of NBDClient allocation:
34b321
nbd_client_new will shutdown the socket and call the "close_fn" callback
34b321
if negotiation failed, so the caller don't need a different path than
34b321
the normal close.
34b321
34b321
The returned pointer is never used, make it void in preparation for the
34b321
next patch.
34b321
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Message-Id: <1452760863-25350-2-git-send-email-famz@redhat.com>
34b321
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
(cherry picked from commit ee7d7aabdaea4484e069cb99c9fc54e8cb24b56f)
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
    include/block/nbd.h
34b321
    nbd.c
34b321
    qemu-nbd.c
34b321
* nbd_update_server_fd_handler not in downstream;
34b321
* Context around the changed line is different.
34b321
---
34b321
 include/block/nbd.h |  3 +--
34b321
 nbd.c               | 11 +++++------
34b321
 qemu-nbd.c          |  4 ++--
34b321
 3 files changed, 8 insertions(+), 10 deletions(-)
34b321
34b321
diff --git a/include/block/nbd.h b/include/block/nbd.h
34b321
index c90f5e4..92e360e 100644
34b321
--- a/include/block/nbd.h
34b321
+++ b/include/block/nbd.h
34b321
@@ -92,8 +92,7 @@ NBDExport *nbd_export_find(const char *name);
34b321
 void nbd_export_set_name(NBDExport *exp, const char *name);
34b321
 void nbd_export_close_all(void);
34b321
 
34b321
-NBDClient *nbd_client_new(NBDExport *exp, int csock,
34b321
-                          void (*close)(NBDClient *));
34b321
+void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *));
34b321
 void nbd_client_close(NBDClient *client);
34b321
 void nbd_client_get(NBDClient *client);
34b321
 void nbd_client_put(NBDClient *client);
34b321
diff --git a/nbd.c b/nbd.c
34b321
index f258cdd..ba97270 100644
34b321
--- a/nbd.c
34b321
+++ b/nbd.c
34b321
@@ -1232,8 +1232,7 @@ static void nbd_restart_write(void *opaque)
34b321
     qemu_coroutine_enter(client->send_coroutine, NULL);
34b321
 }
34b321
 
34b321
-NBDClient *nbd_client_new(NBDExport *exp, int csock,
34b321
-                          void (*close)(NBDClient *))
34b321
+void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *))
34b321
 {
34b321
     NBDClient *client;
34b321
     client = g_malloc0(sizeof(NBDClient));
34b321
@@ -1241,10 +1240,11 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
34b321
     client->exp = exp;
34b321
     client->sock = csock;
34b321
     if (nbd_send_negotiate(client) < 0) {
34b321
-        g_free(client);
34b321
-        return NULL;
34b321
+        shutdown(client->sock, 2);
34b321
+        close_fn(client);
34b321
+        return;
34b321
     }
34b321
-    client->close = close;
34b321
+    client->close = close_fn;
34b321
     qemu_co_mutex_init(&client->send_lock);
34b321
     qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
34b321
 
34b321
@@ -1252,5 +1252,4 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
34b321
         QTAILQ_INSERT_TAIL(&exp->clients, client, next);
34b321
         nbd_export_get(exp);
34b321
     }
34b321
-    return client;
34b321
 }
34b321
diff --git a/qemu-nbd.c b/qemu-nbd.c
34b321
index ff792ef..047dd49 100644
34b321
--- a/qemu-nbd.c
34b321
+++ b/qemu-nbd.c
34b321
@@ -297,9 +297,9 @@ static void nbd_accept(void *opaque)
34b321
         close(fd);
34b321
         return;
34b321
     }
34b321
-
34b321
-    if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) {
34b321
+    if (fd >= 0) {
34b321
         nb_fds++;
34b321
+        nbd_client_new(exp, fd, nbd_client_closed);
34b321
     }
34b321
 }
34b321
 
34b321
-- 
34b321
1.8.3.1
34b321