Blame SOURCES/kvm-qemu-nbd-Fail-earlier-for-c-d-on-non-linux.patch

7711c0
From fd123e372472179657da738e52e87897d0508812 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 27 Mar 2019 17:22:23 +0100
7711c0
Subject: [PATCH 084/163] qemu-nbd: Fail earlier for -c/-d on non-linux
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190327172308.31077-11-jsnow@redhat.com>
7711c0
Patchwork-id: 85173
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 10/55] qemu-nbd: Fail earlier for -c/-d on non-linux
7711c0
Bugzilla: 1691009
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Eric Blake <eblake@redhat.com>
7711c0
7711c0
Connecting to a /dev/nbdN device is a Linux-specific action.
7711c0
We were already masking -c and -d from 'qemu-nbd --help' on
7711c0
non-linux.  However, while -d fails with a sensible error
7711c0
message, it took hunting through a couple of files to prove
7711c0
that.  What's more, the code for -c doesn't fail until after
7711c0
it has created a pthread and tried to open a device - possibly
7711c0
even printing an error message with %m on a non-Linux platform
7711c0
in spite of the comment that %m is glibc-specific.  Make the
7711c0
failure happen sooner, then get rid of stubs that are no
7711c0
longer needed because of the early exits.
7711c0
7711c0
While at it: tweak the blank newlines in --help output to be
7711c0
consistent, whether or not built on Linux.
7711c0
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
Message-Id: <20181215135324.152629-7-eblake@redhat.com>
7711c0
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
(cherry picked from commit 3c1fa35d74aabe9c3ab642d2591b087e53d7a616)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 nbd/client.c | 18 +-----------------
7711c0
 qemu-nbd.c   | 21 +++++++++++++++++++--
7711c0
 2 files changed, 20 insertions(+), 19 deletions(-)
7711c0
7711c0
diff --git a/nbd/client.c b/nbd/client.c
7711c0
index e774147..5a03a84 100644
7711c0
--- a/nbd/client.c
7711c0
+++ b/nbd/client.c
7711c0
@@ -1031,23 +1031,7 @@ int nbd_disconnect(int fd)
7711c0
     return 0;
7711c0
 }
7711c0
 
7711c0
-#else
7711c0
-int nbd_init(int fd, QIOChannelSocket *ioc, NBDExportInfo *info,
7711c0
-	     Error **errp)
7711c0
-{
7711c0
-    error_setg(errp, "nbd_init is only supported on Linux");
7711c0
-    return -ENOTSUP;
7711c0
-}
7711c0
-
7711c0
-int nbd_client(int fd)
7711c0
-{
7711c0
-    return -ENOTSUP;
7711c0
-}
7711c0
-int nbd_disconnect(int fd)
7711c0
-{
7711c0
-    return -ENOTSUP;
7711c0
-}
7711c0
-#endif
7711c0
+#endif /* __linux__ */
7711c0
 
7711c0
 int nbd_send_request(QIOChannel *ioc, NBDRequest *request)
7711c0
 {
7711c0
diff --git a/qemu-nbd.c b/qemu-nbd.c
7711c0
index 7f078b2..652199c 100644
7711c0
--- a/qemu-nbd.c
7711c0
+++ b/qemu-nbd.c
7711c0
@@ -43,6 +43,12 @@
7711c0
 #include "trace/control.h"
7711c0
 #include "qemu-version.h"
7711c0
 
7711c0
+#ifdef __linux__
7711c0
+#define HAVE_NBD_DEVICE 1
7711c0
+#else
7711c0
+#define HAVE_NBD_DEVICE 0
7711c0
+#endif
7711c0
+
7711c0
 #define SOCKET_PATH                "/var/lock/qemu-nbd-%s"
7711c0
 #define QEMU_NBD_OPT_CACHE         256
7711c0
 #define QEMU_NBD_OPT_AIO           257
7711c0
@@ -98,11 +104,11 @@ static void usage(const char *name)
7711c0
 "                            specify tracing options\n"
7711c0
 "  --fork                    fork off the server process and exit the parent\n"
7711c0
 "                            once the server is running\n"
7711c0
-#ifdef __linux__
7711c0
+#if HAVE_NBD_DEVICE
7711c0
+"\n"
7711c0
 "Kernel NBD client support:\n"
7711c0
 "  -c, --connect=DEV         connect FILE to the local NBD device DEV\n"
7711c0
 "  -d, --disconnect          disconnect the specified device\n"
7711c0
-"\n"
7711c0
 #endif
7711c0
 "\n"
7711c0
 "Block device options:\n"
7711c0
@@ -236,6 +242,7 @@ static void termsig_handler(int signum)
7711c0
 }
7711c0
 
7711c0
 
7711c0
+#if HAVE_NBD_DEVICE
7711c0
 static void *show_parts(void *arg)
7711c0
 {
7711c0
     char *device = arg;
7711c0
@@ -321,6 +328,7 @@ out:
7711c0
     kill(getpid(), SIGTERM);
7711c0
     return (void *) EXIT_FAILURE;
7711c0
 }
7711c0
+#endif /* HAVE_NBD_DEVICE */
7711c0
 
7711c0
 static int nbd_can_accept(void)
7711c0
 {
7711c0
@@ -816,6 +824,12 @@ int main(int argc, char **argv)
7711c0
         }
7711c0
     }
7711c0
 
7711c0
+#if !HAVE_NBD_DEVICE
7711c0
+    if (disconnect || device) {
7711c0
+        error_report("Kernel /dev/nbdN support not available");
7711c0
+        exit(EXIT_FAILURE);
7711c0
+    }
7711c0
+#else /* HAVE_NBD_DEVICE */
7711c0
     if (disconnect) {
7711c0
         int nbdfd = open(argv[optind], O_RDWR);
7711c0
         if (nbdfd < 0) {
7711c0
@@ -831,6 +845,7 @@ int main(int argc, char **argv)
7711c0
 
7711c0
         return 0;
7711c0
     }
7711c0
+#endif
7711c0
 
7711c0
     if ((device && !verbose) || fork_process) {
7711c0
         int stderr_fd[2];
7711c0
@@ -1012,6 +1027,7 @@ int main(int argc, char **argv)
7711c0
     nbd_export_set_description(exp, export_description);
7711c0
 
7711c0
     if (device) {
7711c0
+#if HAVE_NBD_DEVICE
7711c0
         int ret;
7711c0
 
7711c0
         ret = pthread_create(&client_thread, NULL, nbd_client_thread, device);
7711c0
@@ -1019,6 +1035,7 @@ int main(int argc, char **argv)
7711c0
             error_report("Failed to create client thread: %s", strerror(ret));
7711c0
             exit(EXIT_FAILURE);
7711c0
         }
7711c0
+#endif
7711c0
     } else {
7711c0
         /* Shut up GCC warnings.  */
7711c0
         memset(&client_thread, 0, sizeof(client_thread));
7711c0
-- 
7711c0
1.8.3.1
7711c0