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

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