qemu-commits
[Top][All Lists]
Advanced

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

[Qemu-commits] [qemu/qemu] c72bb9: async: the main AioContext is only "c


From: Peter Maydell
Subject: [Qemu-commits] [qemu/qemu] c72bb9: async: the main AioContext is only "current" if un...
Date: Thu, 17 Jun 2021 02:02:47 -0700

  Branch: refs/heads/staging
  Home:   https://github.com/qemu/qemu
  Commit: c72bb9d05259d2096b94d7bc03d9e80ee67982e5
      
https://github.com/qemu/qemu/commit/c72bb9d05259d2096b94d7bc03d9e80ee67982e5
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M include/block/aio.h
    M iothread.c
    M stubs/iothread-lock.c
    R stubs/iothread.c
    M stubs/meson.build
    M tests/unit/iothread.c
    M util/async.c
    M util/main-loop.c

  Log Message:
  -----------
  async: the main AioContext is only "current" if under the BQL

If we want to wake up a coroutine from a worker thread, aio_co_wake()
currently does not work.  In that scenario, aio_co_wake() calls
aio_co_enter(), but there is no current AioContext and therefore
qemu_get_current_aio_context() returns the main thread.  aio_co_wake()
then attempts to call aio_context_acquire() instead of going through
aio_co_schedule().

The default case of qemu_get_current_aio_context() was added to cover
synchronous I/O started from the vCPU thread, but the main and vCPU
threads are quite different.  The main thread is an I/O thread itself,
only running a more complicated event loop; the vCPU thread instead
is essentially a worker thread that occasionally calls
qemu_mutex_lock_iothread().  It is only in those critical sections
that it acts as if it were the home thread of the main AioContext.

Therefore, this patch detaches qemu_get_current_aio_context() from
iothreads, which is a useless complication.  The AioContext pointer
is stored directly in the thread-local variable, including for the
main loop.  Worker threads (including vCPU threads) optionally behave
as temporary home threads if they have taken the big QEMU lock,
but if that is not the case they will always schedule coroutines
on remote threads via aio_co_schedule().

With this change, the stub qemu_mutex_iothread_locked() must be changed
from true to false.  The previous value of true was needed because the
main thread did not have an AioContext in the thread-local variable,
but now it does have one.

Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210609122234.544153-1-pbonzini@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Tested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[eblake: tweak commit message per Vladimir's review]
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: d78fa4b2f45863d62450f30717de1154163cf2b1
      
https://github.com/qemu/qemu/commit/d78fa4b2f45863d62450f30717de1154163cf2b1
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M tests/unit/test-aio.c

  Log Message:
  -----------
  tests: cover aio_co_enter from a worker thread without BQL taken

Add a testcase for the test fixed by commit 'async: the main AioContext
is only "current" if under the BQL.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210614110214.726722-1-pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 2a50bd8b44f8d8364087ad0365f76a1ebef32e22
      
https://github.com/qemu/qemu/commit/2a50bd8b44f8d8364087ad0365f76a1ebef32e22
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M include/qemu/coroutine.h

  Log Message:
  -----------
  co-queue: drop extra coroutine_fn marks

qemu_co_queue_next() and qemu_co_queue_restart_all() just call
aio_co_wake() which works well in non-coroutine context. So these
functions can be called from non-coroutine context as well. And
actually qemu_co_queue_restart_all() is called from
nbd_cancel_in_flight(), which is called from non-coroutine context.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-2-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 3895f32f9f63895fb5ff7b7a3f71f601f3b4303a
      
https://github.com/qemu/qemu/commit/3895f32f9f63895fb5ff7b7a3f71f601f3b4303a
  Author: Roman Kagan <rvkagan@yandex-team.ru>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: fix channel object leak

nbd_free_connect_thread leaks the channel object if it hasn't been
stolen.

Unref it and fix the leak.

Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-3-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: c2eb3ffb525f64c75f9a331d2bdb23bae6925b6d
      
https://github.com/qemu/qemu/commit/c2eb3ffb525f64c75f9a331d2bdb23bae6925b6d
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: fix how state is cleared on nbd_open() failure paths

We have two "return error" paths in nbd_open() after
nbd_process_options(). Actually we should call nbd_clear_bdrvstate()
on these paths. Interesting that nbd_process_options() calls
nbd_clear_bdrvstate() by itself.

Let's fix leaks and refactor things to be more obvious:

- intialize yank at top of nbd_open()
- move yank cleanup to nbd_clear_bdrvstate()
- refactor nbd_open() so that all failure paths except for
  yank-register goes through nbd_clear_bdrvstate()

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-4-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: ee0bb521f1faba089f2ef4ba77bb8c432c8983c7
      
https://github.com/qemu/qemu/commit/ee0bb521f1faba089f2ef4ba77bb8c432c8983c7
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: connect_thread_func(): do qio_channel_set_delay(false)

nbd_open() does it (through nbd_establish_connection()).
Actually we lost that call on reconnect path in 1dc4718d849e1a1fe
"block/nbd: use non-blocking connect: fix vm hang on connect()"
when we have introduced reconnect thread.

Fixes: 1dc4718d849e1a1fe665ce5241ed79048cfa2cfc
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-5-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: c8332c3b08e131c8282757fe1b97ff9d736262ef
      
https://github.com/qemu/qemu/commit/c8332c3b08e131c8282757fe1b97ff9d736262ef
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M include/qemu/sockets.h
    M util/qemu-sockets.c

  Log Message:
  -----------
  qemu-sockets: introduce socket_address_parse_named_fd()

Add function that transforms named fd inside SocketAddress structure
into number representation. This way it may be then used in a context
where current monitor is not available.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-6-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: comment tweak]
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 5be11cdcb26b037a6ee49807da6308bd01c4ed30
      
https://github.com/qemu/qemu/commit/5be11cdcb26b037a6ee49807da6308bd01c4ed30
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: call socket_address_parse_named_fd() in advance

Detecting monitor by current coroutine works bad when we are not in
coroutine context. And that's exactly so in nbd reconnect code, where
qio_channel_socket_connect_sync() is called from thread.

Monitor is needed only to parse named file descriptor. So, let's just
parse it during nbd_open(), so that all further users of s->saddr don't
need to access monitor.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-7-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: dd84c63e5c2bbcdfe06a047caaa9e5465ac2e065
      
https://github.com/qemu/qemu/commit/dd84c63e5c2bbcdfe06a047caaa9e5465ac2e065
  Author: Roman Kagan <rvkagan@yandex-team.ru>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: ensure ->connection_thread is always valid

Simplify lifetime management of BDRVNBDState->connect_thread by
delaying the possible cleanup of it until the BDRVNBDState itself goes
away.

This also reverts
 0267101af6 "block/nbd: fix possible use after free of s->connect_thread"
as now s->connect_thread can't be cleared until the very end.

Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
 [vsementsov: rebase, revert 0267101af6 changes]
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
 [eblake: tweak comment]
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-8-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 3d44d6606b5a008fa0187e14e0072e1be93e0627
      
https://github.com/qemu/qemu/commit/3d44d6606b5a008fa0187e14e0072e1be93e0627
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: nbd_client_handshake(): fix leak of s->ioc

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20210610100802.5888-9-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 93620a6637b58cb1a25692c7c09cdd19bbb7595e
      
https://github.com/qemu/qemu/commit/93620a6637b58cb1a25692c7c09cdd19bbb7595e
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: BDRVNBDState: drop unused connect_err and connect_status

These fields are write-only. Drop them.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-10-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: f501f5e8af6003c5a00b77c39d4580005a445703
      
https://github.com/qemu/qemu/commit/f501f5e8af6003c5a00b77c39d4580005a445703
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: simplify waking of nbd_co_establish_connection()

Instead of managing connect_bh, bh_ctx, and wait_connect fields, we
can use a single link to the waiting coroutine with proper mutex
protection.

So new logic is:

nbd_co_establish_connection() sets wait_co under the mutex, releases
the mutex, then yield()s.  Note that wait_co may be scheduled by the
thread immediately after unlocking the mutex.  Still, the main thread
(or iothread) will not reach the code for entering the coroutine until
the yield(), so we are safe.

connect_thread_func() and nbd_co_establish_connection_cancel() do
the following to handle wait_co:

Under the mutex, if thr->wait_co is not NULL, make it NULL and
schedule it. This way, we avoid scheduling the coroutine twice.

Still scheduling is a bit different:

In connect_thread_func() we can just call aio_co_wake under mutex,
after commit
   [async: the main AioContext is only "current" if under the BQL]
we are sure that aio_co_wake() will not try to acquire the aio context
and do qemu_aio_coroutine_enter() but simply schedule the coroutine by
aio_co_schedule().

nbd_co_establish_connection_cancel() will be called from non-coroutine
context in further patch and will be able to go through
qemu_aio_coroutine_enter() path of aio_co_wake(). So keep current
behavior of waking the coroutine after the critical section.

Also, this commit reduces the dependence of
nbd_co_establish_connection() on the internals of bs (we now use a
generic pointer to the coroutine, instead of direct use of
s->connection_co).  This is a step towards splitting the connection
API out of nbd.c.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-11-vsementsov@virtuozzo.com>
Reviewied-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 8847eda76e5082e5949e39b0e6f88d018001553f
      
https://github.com/qemu/qemu/commit/8847eda76e5082e5949e39b0e6f88d018001553f
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: drop thr->state

We don't need all these states. The code refactored to use two boolean
variables looks simpler.

While moving the comment in nbd_co_establish_connection() rework it to
give better information. Also, we are going to move the connection code
to separate file and mentioning drained section would be confusing.

Improve also the comment in NBDConnectThread, while dropping removed
state names from it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-12-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: comment tweak]
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: e21341b0f6b0c63698f9fe26771b0b19300991c3
      
https://github.com/qemu/qemu/commit/e21341b0f6b0c63698f9fe26771b0b19300991c3
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: bs-independent interface for nbd_co_establish_connection()

We are going to split connection code to a separate file. Now we are
ready to give nbd_co_establish_connection() clean and bs-independent
interface.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-13-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 257b357b5c2df04a526c1238d4de036fbe4ded80
      
https://github.com/qemu/qemu/commit/257b357b5c2df04a526c1238d4de036fbe4ded80
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: make nbd_co_establish_connection_cancel() bs-independent

nbd_co_establish_connection_cancel() actually needs only pointer to
NBDConnectThread. So, make it clean.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-14-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 3df4ed58e62c7ab9067282d5a0c599ce28e98345
      
https://github.com/qemu/qemu/commit/3df4ed58e62c7ab9067282d5a0c599ce28e98345
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: rename NBDConnectThread to NBDClientConnection

We are going to move the connection code to its own file, and want
clear names and APIs first.

The structure is shared between user and (possibly) several runs of
connect-thread. So it's wrong to call it "thread". Let's rename to
something more generic.

Appropriately rename connect_thread and thr variables to conn.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-15-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: bbad55e0844257dafafadc47ecdb32e45ac16719
      
https://github.com/qemu/qemu/commit/bbad55e0844257dafafadc47ecdb32e45ac16719
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: introduce nbd_client_connection_new()

This is a step of creating bs-independent nbd connection interface.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-16-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 597d4384b9c74e35e2ce0ccf1adb34811f33834f
      
https://github.com/qemu/qemu/commit/597d4384b9c74e35e2ce0ccf1adb34811f33834f
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: introduce nbd_client_connection_release()

This is a last step of creating bs-independent nbd connection
interface. With next commit we can finally move it to separate file.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-17-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 996623e5c827ae095ee76d0a279a36d2fc9b95f6
      
https://github.com/qemu/qemu/commit/996623e5c827ae095ee76d0a279a36d2fc9b95f6
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c
    M include/block/nbd.h
    A nbd/client-connection.c
    M nbd/meson.build

  Log Message:
  -----------
  nbd: move connection code from block/nbd to nbd/client-connection

We now have bs-independent connection API, which consists of four
functions:

  nbd_client_connection_new()
  nbd_client_connection_release()
  nbd_co_establish_connection()
  nbd_co_establish_connection_cancel()

Move them to a separate file together with NBDClientConnection
structure which becomes private to the new API.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-18-vsementsov@virtuozzo.com>
[eblake: comment tweaks]
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 237f81b383dea387db39e1e510b09d2513f74061
      
https://github.com/qemu/qemu/commit/237f81b383dea387db39e1e510b09d2513f74061
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: use QEMU_LOCK_GUARD

We don't update connect_thread_func() to use QEMU_LOCK_GUARD, as it
will get more complex critical sections logic in further commit, where
QEMU_LOCK_GUARD doesn't help.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-19-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 77e3ef245a5d6e7e13b17061dcebc72b8e50d795
      
https://github.com/qemu/qemu/commit/77e3ef245a5d6e7e13b17061dcebc72b8e50d795
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c
    M include/block/nbd.h
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: add possibility of negotiation

Add arguments and logic to support nbd negotiation in the same thread
after successful connection.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-20-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 5ff4c65ded049c14d7a28238aa1a7ea7b6d3ff78
      
https://github.com/qemu/qemu/commit/5ff4c65ded049c14d7a28238aa1a7ea7b6d3ff78
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M include/block/nbd.h
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: implement connection retry

Add an option for a thread to retry connecting until it succeeds. We'll
use nbd/client-connection both for reconnect and for initial connection
in nbd_open(), so we need a possibility to use same NBDClientConnection
instance to connect once in nbd_open() and then use retry semantics for
reconnect.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-21-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: grammar tweak]
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 40e66e5a83842aa2f39519dbac31788c44dc9891
      
https://github.com/qemu/qemu/commit/40e66e5a83842aa2f39519dbac31788c44dc9891
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: shutdown connection on release

Now, when a thread can do negotiation and retry, it may run relatively
long. We need a mechanism to stop it, when the user is not interested
in a result any more. So, on nbd_client_connection_release() let's
shutdown the socket, and do not retry connection if thread is detached.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-22-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 77641a2910e7db30f01b4d952e83f132d3027876
      
https://github.com/qemu/qemu/commit/77641a2910e7db30f01b4d952e83f132d3027876
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: split nbd_handle_updated_info out of nbd_client_handshake()

To be reused in the following patch.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-23-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: fb9a768157563783146dcc8515eafe0160fe986a
      
https://github.com/qemu/qemu/commit/fb9a768157563783146dcc8515eafe0160fe986a
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: use negotiation of NBDClientConnection

Now that we can opt in to negotiation as part of the client connection
thread, use that to simplify connection_co.  This is another step on
the way to moving all reconnect code into NBDClientConnection.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-24-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 6ebde6eb85df539b6785ee91428c568c7fe08131
      
https://github.com/qemu/qemu/commit/6ebde6eb85df539b6785ee91428c568c7fe08131
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: don't touch s->sioc in nbd_teardown_connection()

Negotiation during reconnect is now done in a thread, and s->sioc is
not available during negotiation. Negotiation in thread will be
cancelled by nbd_client_connection_release() called from
nbd_clear_bdrvstate().  So, we don't need this code chunk anymore.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-25-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 18521b29d4c324c19d44c4f50704f69e98de1b7d
      
https://github.com/qemu/qemu/commit/18521b29d4c324c19d44c4f50704f69e98de1b7d
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: drop BDRVNBDState::sioc

Currently sioc pointer is used just to pass from socket-connection to
nbd negotiation. Drop the field, and use local variables instead. With
next commit we'll update nbd/client-connection.c to behave
appropriately (return only top-most ioc, not two channels).

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-26-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 4ed45fe3fa32b42fe48656fa454eb37359664bb9
      
https://github.com/qemu/qemu/commit/4ed45fe3fa32b42fe48656fa454eb37359664bb9
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c
    M include/block/nbd.h
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: return only one io channel

block/nbd doesn't need underlying sioc channel anymore. So, we can
update nbd/client-connection interface to return only one top-most io
channel, which is more straight forward.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-27-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: a698d3eb4324898bafa2db70d3c129e70a16acdf
      
https://github.com/qemu/qemu/commit/a698d3eb4324898bafa2db70d3c129e70a16acdf
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block-coroutine-wrapper: allow non bdrv_ prefix

We are going to reuse the script to generate a nbd_ function in
further commit. Prepare the script now.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-28-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: eb45878d7445eebe81b396c24457826634f18c98
      
https://github.com/qemu/qemu/commit/eb45878d7445eebe81b396c24457826634f18c98
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt

Split out the part that we want to reuse for nbd_open().

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210610100802.5888-29-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 729f341988ec69c7755c4ede078a02f0adda9264
      
https://github.com/qemu/qemu/commit/729f341988ec69c7755c4ede078a02f0adda9264
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c
    M include/block/nbd.h
    M nbd/client-connection.c

  Log Message:
  -----------
  nbd/client-connection: add option for non-blocking connection attempt

We'll need a possibility of non-blocking nbd_co_establish_connection(),
so that it returns immediately, and it returns success only if a
connections was previously established in background.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-30-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: e3885a8d55b9783e8a0518c82e088f0d901df882
      
https://github.com/qemu/qemu/commit/e3885a8d55b9783e8a0518c82e088f0d901df882
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/coroutines.h
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: reuse nbd_co_do_establish_connection() in nbd_open()

The only last step we need to reuse the function is coroutine-wrapper.
nbd_open() may be called from non-coroutine context. So, generate the
wrapper and use it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-31-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 3ffc4acc9976d8d4c52c94e504be06ad49d906a8
      
https://github.com/qemu/qemu/commit/3ffc4acc9976d8d4c52c94e504be06ad49d906a8
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: add nbd_client_connected() helper

We already have two similar helpers for other state. Let's add another
one for convenience.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-32-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: 788b68b57dea4ddd0038f73b96c147eb406c386d
      
https://github.com/qemu/qemu/commit/788b68b57dea4ddd0038f73b96c147eb406c386d
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   2021-06-15 (Tue, 15 Jun 2021)

  Changed paths:
    M block/nbd.c

  Log Message:
  -----------
  block/nbd: safer transition to receiving request

req->receiving is a flag of request being in one concrete yield point
in nbd_co_do_receive_one_chunk().

Such kind of boolean flag is always better to unset before scheduling
the coroutine, to avoid double scheduling. So, let's be more careful.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-33-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>


  Commit: f419a436fcf3c6aade8ae976c21d9352df8dce76
      
https://github.com/qemu/qemu/commit/f419a436fcf3c6aade8ae976c21d9352df8dce76
  Author: Peter Maydell <peter.maydell@linaro.org>
  Date:   2021-06-17 (Thu, 17 Jun 2021)

  Changed paths:
    M block/coroutines.h
    M block/nbd.c
    M include/block/aio.h
    M include/block/nbd.h
    M include/qemu/coroutine.h
    M include/qemu/sockets.h
    M iothread.c
    A nbd/client-connection.c
    M nbd/meson.build
    M scripts/block-coroutine-wrapper.py
    M stubs/iothread-lock.c
    R stubs/iothread.c
    M stubs/meson.build
    M tests/unit/iothread.c
    M tests/unit/test-aio.c
    M util/async.c
    M util/main-loop.c
    M util/qemu-sockets.c

  Log Message:
  -----------
  Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2021-06-15' into 
staging

nbd patches for 2021-06-15

- bug fixes in coroutine aio context handling
- rework NBD client connection logic to perform more work in coroutine
rather than blocking main loop

# gpg: Signature made Tue 15 Jun 2021 21:45:17 BST
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) 
<ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2021-06-15: (34 commits)
  block/nbd: safer transition to receiving request
  block/nbd: add nbd_client_connected() helper
  block/nbd: reuse nbd_co_do_establish_connection() in nbd_open()
  nbd/client-connection: add option for non-blocking connection attempt
  block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt
  block-coroutine-wrapper: allow non bdrv_ prefix
  nbd/client-connection: return only one io channel
  block/nbd: drop BDRVNBDState::sioc
  block/nbd: don't touch s->sioc in nbd_teardown_connection()
  block/nbd: use negotiation of NBDClientConnection
  block/nbd: split nbd_handle_updated_info out of nbd_client_handshake()
  nbd/client-connection: shutdown connection on release
  nbd/client-connection: implement connection retry
  nbd/client-connection: add possibility of negotiation
  nbd/client-connection: use QEMU_LOCK_GUARD
  nbd: move connection code from block/nbd to nbd/client-connection
  block/nbd: introduce nbd_client_connection_release()
  block/nbd: introduce nbd_client_connection_new()
  block/nbd: rename NBDConnectThread to NBDClientConnection
  block/nbd: make nbd_co_establish_connection_cancel() bs-independent
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Compare: https://github.com/qemu/qemu/compare/38848ce56584...f419a436fcf3



reply via email to

[Prev in Thread] Current Thread [Next in Thread]