qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com,
	vsementsov@virtuozzo.com, eblake@redhat.com,
	rvkagan@yandex-team.ru, den@openvz.org
Subject: [PATCH 08/14] block/nbd: move nbd connect-thread to nbd/client-connect.c
Date: Wed,  7 Apr 2021 13:46:31 +0300	[thread overview]
Message-ID: <20210407104637.36033-9-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20210407104637.36033-1-vsementsov@virtuozzo.com>

connect-thread part is not directly connected to  block-layer. Good
place for it is nbd/ directory.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/nbd.h  |  6 ++++
 block/nbd.c          | 46 ----------------------------
 nbd/client-connect.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
 nbd/meson.build      |  1 +
 4 files changed, 79 insertions(+), 46 deletions(-)
 create mode 100644 nbd/client-connect.c

diff --git a/include/block/nbd.h b/include/block/nbd.h
index 5f34d23bb0..660ab4c266 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -406,4 +406,10 @@ const char *nbd_info_lookup(uint16_t info);
 const char *nbd_cmd_lookup(uint16_t info);
 const char *nbd_err_lookup(int err);
 
+
+typedef void (*NBDConnectThreadCallback)(QIOChannelSocket *sioc, int ret,
+                                         void *opaque);
+void nbd_connect_thread_start(const SocketAddress *saddr,
+                              NBDConnectThreadCallback cb, void *cb_opaque);
+
 #endif
diff --git a/block/nbd.c b/block/nbd.c
index 4e669d762a..ba281e2d5a 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -101,15 +101,6 @@ typedef struct NBDConnectCB {
     AioContext *bh_ctx; /* where to schedule bh (NULL means don't schedule) */
 } NBDConnectCB;
 
-typedef void (*NBDConnectThreadCallback)(QIOChannelSocket *sioc, int ret,
-                                         void *opaque);
-
-typedef struct NBDConnectThread {
-    SocketAddress *saddr; /* address to connect to */
-    NBDConnectThreadCallback cb;
-    void *cb_opaque;
-} NBDConnectThread;
-
 typedef struct BDRVNBDState {
     QIOChannelSocket *sioc; /* The master data channel */
     QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
@@ -415,43 +406,6 @@ static void connect_thread_cb(QIOChannelSocket *sioc, int ret, void *opaque)
     }
 }
 
-static void *connect_thread_func(void *opaque)
-{
-    NBDConnectThread *thr = opaque;
-    int ret;
-    QIOChannelSocket *sioc = qio_channel_socket_new();
-
-    ret = qio_channel_socket_connect_sync(sioc, thr->saddr, NULL);
-    if (ret < 0) {
-        object_unref(OBJECT(sioc));
-        sioc = NULL;
-    }
-
-    thr->cb(sioc, ret, thr->cb_opaque);
-
-    qapi_free_SocketAddress(thr->saddr);
-    g_free(thr);
-
-    return NULL;
-}
-
-static void nbd_connect_thread_start(const SocketAddress *saddr,
-                                     NBDConnectThreadCallback cb,
-                                     void *cb_opaque)
-{
-    QemuThread thread;
-    NBDConnectThread *thr = g_new(NBDConnectThread, 1);
-
-    *thr = (NBDConnectThread) {
-        .saddr = QAPI_CLONE(SocketAddress, saddr),
-        .cb = cb,
-        .cb_opaque = cb_opaque,
-    };
-
-    qemu_thread_create(&thread, "nbd-connect",
-                       connect_thread_func, thr, QEMU_THREAD_DETACHED);
-}
-
 static int coroutine_fn
 nbd_co_establish_connection(BlockDriverState *bs)
 {
diff --git a/nbd/client-connect.c b/nbd/client-connect.c
new file mode 100644
index 0000000000..9f22c41a34
--- /dev/null
+++ b/nbd/client-connect.c
@@ -0,0 +1,72 @@
+/*
+ * QEMU Block driver for  NBD
+ *
+ * Copyright (c) 2020 Virtuozzo International GmbH.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+
+#include "qapi/qapi-visit-sockets.h"
+#include "qapi/clone-visitor.h"
+
+#include "block/nbd.h"
+
+typedef struct NBDConnectThread {
+    SocketAddress *saddr; /* address to connect to */
+    NBDConnectThreadCallback cb;
+    void *cb_opaque;
+} NBDConnectThread;
+
+static void *connect_thread_func(void *opaque)
+{
+    NBDConnectThread *thr = opaque;
+    int ret;
+    QIOChannelSocket *sioc = qio_channel_socket_new();
+
+    ret = qio_channel_socket_connect_sync(sioc, thr->saddr, NULL);
+    if (ret < 0) {
+        object_unref(OBJECT(sioc));
+        sioc = NULL;
+    }
+
+    thr->cb(sioc, ret, thr->cb_opaque);
+
+    qapi_free_SocketAddress(thr->saddr);
+    g_free(thr);
+
+    return NULL;
+}
+
+void nbd_connect_thread_start(const SocketAddress *saddr,
+                              NBDConnectThreadCallback cb, void *cb_opaque)
+{
+    QemuThread thread;
+    NBDConnectThread *thr = g_new(NBDConnectThread, 1);
+
+    *thr = (NBDConnectThread) {
+        .saddr = QAPI_CLONE(SocketAddress, saddr),
+        .cb = cb,
+        .cb_opaque = cb_opaque,
+    };
+
+    qemu_thread_create(&thread, "nbd-connect",
+                       connect_thread_func, thr, QEMU_THREAD_DETACHED);
+}
diff --git a/nbd/meson.build b/nbd/meson.build
index 2baaa36948..da8c65ae59 100644
--- a/nbd/meson.build
+++ b/nbd/meson.build
@@ -1,5 +1,6 @@
 block_ss.add(files(
   'client.c',
+  'client-connect.c',
   'common.c',
 ))
 blockdev_ss.add(files(
-- 
2.29.2



  parent reply	other threads:[~2021-04-07 10:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 10:46 [PATCH 00/14] nbd: move reconnect-thread to separate file Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 01/14] block/nbd: BDRVNBDState: drop unused connect_err Vladimir Sementsov-Ogievskiy
2021-04-07 11:13   ` Roman Kagan
2021-04-07 10:46 ` [PATCH 02/14] block/nbd: nbd_co_establish_connection(): drop unused errp Vladimir Sementsov-Ogievskiy
2021-04-07 11:28   ` Roman Kagan
2021-04-07 10:46 ` [PATCH 03/14] block/nbd: drop unused NBDConnectThread::err field Vladimir Sementsov-Ogievskiy
2021-04-07 11:42   ` Roman Kagan
2021-04-07 11:55     ` Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 04/14] block/nbd: split connect_thread_cb() out of connect_thread_func() Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 05/14] block/nbd: rename NBDConnectThread to NBDConnectCB Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 06/14] block/nbd: further segregation of connect-thread Vladimir Sementsov-Ogievskiy
2021-04-08 10:44   ` Roman Kagan
2021-04-07 10:46 ` [PATCH 07/14] block/nbd: drop nbd_free_connect_thread() Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` Vladimir Sementsov-Ogievskiy [this message]
2021-04-07 10:46 ` [PATCH 09/14] block/nbd: NBDConnectCB: drop bh_* fields Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 10/14] block/nbd: move wait_connect field under mutex protection Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 11/14] block/nbd: refactor connect_bh() Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 12/14] block/nbd: refactor nbd_co_establish_connection Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 13/14] block/nbd: nbd_co_establish_connection_cancel(): rename wake to do_wake Vladimir Sementsov-Ogievskiy
2021-04-07 10:46 ` [PATCH 14/14] block/nbd: drop thr->state Vladimir Sementsov-Ogievskiy
2021-04-08 10:03 ` DROP THIS Re: [PATCH 00/14] nbd: move reconnect-thread to separate file Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210407104637.36033-9-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rvkagan@yandex-team.ru \
    --subject='Re: [PATCH 08/14] block/nbd: move nbd connect-thread to nbd/client-connect.c' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).