[PATCH 4/6] nbd/server: avoid per-NBDRequest nbd_client_get/put()

Stefan Hajnoczi posted 6 patches 11 months, 1 week ago
There is a newer version of this series
[PATCH 4/6] nbd/server: avoid per-NBDRequest nbd_client_get/put()
Posted by Stefan Hajnoczi 11 months, 1 week ago
nbd_trip() processes a single NBD request from start to finish and holds
an NBDClient reference throughout. NBDRequest does not outlive the scope
of nbd_trip(). Therefore it is unnecessary to ref/unref NBDClient for
each NBDRequest.

Removing these nbd_client_get()/nbd_client_put() calls will make
thread-safety easier in the commits that follow.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 nbd/server.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 895cf0a752..0b09ccc8dc 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1557,7 +1557,6 @@ static NBDRequestData *nbd_request_get(NBDClient *client)
     client->nb_requests++;
 
     req = g_new0(NBDRequestData, 1);
-    nbd_client_get(client);
     req->client = client;
     return req;
 }
@@ -1578,8 +1577,6 @@ static void nbd_request_put(NBDRequestData *req)
     }
 
     nbd_client_receive_next_request(client);
-
-    nbd_client_put(client);
 }
 
 static void blk_aio_attached(AioContext *ctx, void *opaque)
-- 
2.43.0
Re: [PATCH 4/6] nbd/server: avoid per-NBDRequest nbd_client_get/put()
Posted by Paolo Bonzini 11 months, 1 week ago
On 12/21/23 02:49, Stefan Hajnoczi wrote:
> nbd_trip() processes a single NBD request from start to finish and holds
> an NBDClient reference throughout. NBDRequest does not outlive the scope
> of nbd_trip(). Therefore it is unnecessary to ref/unref NBDClient for
> each NBDRequest.
> 
> Removing these nbd_client_get()/nbd_client_put() calls will make
> thread-safety easier in the commits that follow.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   nbd/server.c | 3 ---
>   1 file changed, 3 deletions(-)
> 
> diff --git a/nbd/server.c b/nbd/server.c
> index 895cf0a752..0b09ccc8dc 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -1557,7 +1557,6 @@ static NBDRequestData *nbd_request_get(NBDClient *client)
>       client->nb_requests++;
>   
>       req = g_new0(NBDRequestData, 1);
> -    nbd_client_get(client);
>       req->client = client;
>       return req;
>   }
> @@ -1578,8 +1577,6 @@ static void nbd_request_put(NBDRequestData *req)
>       }
>   
>       nbd_client_receive_next_request(client);
> -
> -    nbd_client_put(client);
>   }
>   
>   static void blk_aio_attached(AioContext *ctx, void *opaque)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>