qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Peter Lieven <pl@kamp.de>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 5/5] nbd: Use BlockBackend internally
Date: Mon, 17 Nov 2014 18:29:02 +0100	[thread overview]
Message-ID: <546A305E.9040709@redhat.com> (raw)
In-Reply-To: <1416238250-414-6-git-send-email-mreitz@redhat.com>



On 17/11/2014 16:30, Max Reitz wrote:
> With all externally visible functions changed to use BlockBackend, this
> patch makes nbd use BlockBackend for everything internally as well.
> 
> While touching them, substitute 512 by BDRV_SECTOR_SIZE in the calls to
> blk_read(), blk_write() and blk_co_discard().
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

qemu-nbd.c has more uses of "bs" that probably should be changed to
"blk".  Not sure if it should be in this patch, patch 4 or an additional
patch 6 though.

If the third possibility, series

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

Paolo

> ---
>  nbd.c | 56 ++++++++++++++++++++++++++++----------------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/nbd.c b/nbd.c
> index 3fd5743..53cf82b 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -17,8 +17,6 @@
>   */
>  
>  #include "block/nbd.h"
> -#include "block/block.h"
> -#include "block/block_int.h"
>  #include "sysemu/block-backend.h"
>  
>  #include "block/coroutine.h"
> @@ -102,7 +100,7 @@ struct NBDExport {
>      int refcount;
>      void (*close)(NBDExport *exp);
>  
> -    BlockDriverState *bs;
> +    BlockBackend *blk;
>      char *name;
>      off_t dev_offset;
>      off_t size;
> @@ -930,7 +928,7 @@ static void nbd_request_put(NBDRequest *req)
>      nbd_client_put(client);
>  }
>  
> -static void bs_aio_attached(AioContext *ctx, void *opaque)
> +static void blk_aio_attached(AioContext *ctx, void *opaque)
>  {
>      NBDExport *exp = opaque;
>      NBDClient *client;
> @@ -944,7 +942,7 @@ static void bs_aio_attached(AioContext *ctx, void *opaque)
>      }
>  }
>  
> -static void bs_aio_detach(void *opaque)
> +static void blk_aio_detach(void *opaque)
>  {
>      NBDExport *exp = opaque;
>      NBDClient *client;
> @@ -961,24 +959,23 @@ static void bs_aio_detach(void *opaque)
>  NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
>                            uint32_t nbdflags, void (*close)(NBDExport *))
>  {
> -    BlockDriverState *bs = blk_bs(blk);
>      NBDExport *exp = g_malloc0(sizeof(NBDExport));
>      exp->refcount = 1;
>      QTAILQ_INIT(&exp->clients);
> -    exp->bs = bs;
> +    exp->blk = blk;
>      exp->dev_offset = dev_offset;
>      exp->nbdflags = nbdflags;
> -    exp->size = size == -1 ? bdrv_getlength(bs) : size;
> +    exp->size = size == -1 ? blk_getlength(blk) : size;
>      exp->close = close;
> -    exp->ctx = bdrv_get_aio_context(bs);
> -    bdrv_ref(bs);
> -    bdrv_add_aio_context_notifier(bs, bs_aio_attached, bs_aio_detach, exp);
> +    exp->ctx = blk_get_aio_context(blk);
> +    blk_ref(blk);
> +    blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp);
>      /*
>       * NBD exports are used for non-shared storage migration.  Make sure
>       * that BDRV_O_INCOMING is cleared and the image is ready for write
>       * access since the export could be available before migration handover.
>       */
> -    bdrv_invalidate_cache(bs, NULL);
> +    blk_invalidate_cache(blk, NULL);
>      return exp;
>  }
>  
> @@ -1025,11 +1022,11 @@ void nbd_export_close(NBDExport *exp)
>      }
>      nbd_export_set_name(exp, NULL);
>      nbd_export_put(exp);
> -    if (exp->bs) {
> -        bdrv_remove_aio_context_notifier(exp->bs, bs_aio_attached,
> -                                         bs_aio_detach, exp);
> -        bdrv_unref(exp->bs);
> -        exp->bs = NULL;
> +    if (exp->blk) {
> +        blk_remove_aio_context_notifier(exp->blk, blk_aio_attached,
> +                                        blk_aio_detach, exp);
> +        blk_unref(exp->blk);
> +        exp->blk = NULL;
>      }
>  }
>  
> @@ -1059,7 +1056,7 @@ void nbd_export_put(NBDExport *exp)
>  
>  BlockBackend *nbd_export_get_blockdev(NBDExport *exp)
>  {
> -    return exp->bs->blk;
> +    return exp->blk;
>  }
>  
>  void nbd_export_close_all(void)
> @@ -1138,7 +1135,7 @@ static ssize_t nbd_co_receive_request(NBDRequest *req, struct nbd_request *reque
>  
>      command = request->type & NBD_CMD_MASK_COMMAND;
>      if (command == NBD_CMD_READ || command == NBD_CMD_WRITE) {
> -        req->data = qemu_blockalign(client->exp->bs, request->len);
> +        req->data = blk_blockalign(client->exp->blk, request->len);
>      }
>      if (command == NBD_CMD_WRITE) {
>          TRACE("Reading %u byte(s)", request->len);
> @@ -1204,7 +1201,7 @@ static void nbd_trip(void *opaque)
>          TRACE("Request type is READ");
>  
>          if (request.type & NBD_CMD_FLAG_FUA) {
> -            ret = bdrv_co_flush(exp->bs);
> +            ret = blk_co_flush(exp->blk);
>              if (ret < 0) {
>                  LOG("flush failed");
>                  reply.error = -ret;
> @@ -1212,8 +1209,9 @@ static void nbd_trip(void *opaque)
>              }
>          }
>  
> -        ret = bdrv_read(exp->bs, (request.from + exp->dev_offset) / 512,
> -                        req->data, request.len / 512);
> +        ret = blk_read(exp->blk,
> +                       (request.from + exp->dev_offset) / BDRV_SECTOR_SIZE,
> +                       req->data, request.len / BDRV_SECTOR_SIZE);
>          if (ret < 0) {
>              LOG("reading from file failed");
>              reply.error = -ret;
> @@ -1235,8 +1233,9 @@ static void nbd_trip(void *opaque)
>  
>          TRACE("Writing to device");
>  
> -        ret = bdrv_write(exp->bs, (request.from + exp->dev_offset) / 512,
> -                         req->data, request.len / 512);
> +        ret = blk_write(exp->blk,
> +                        (request.from + exp->dev_offset) / BDRV_SECTOR_SIZE,
> +                        req->data, request.len / BDRV_SECTOR_SIZE);
>          if (ret < 0) {
>              LOG("writing to file failed");
>              reply.error = -ret;
> @@ -1244,7 +1243,7 @@ static void nbd_trip(void *opaque)
>          }
>  
>          if (request.type & NBD_CMD_FLAG_FUA) {
> -            ret = bdrv_co_flush(exp->bs);
> +            ret = blk_co_flush(exp->blk);
>              if (ret < 0) {
>                  LOG("flush failed");
>                  reply.error = -ret;
> @@ -1263,7 +1262,7 @@ static void nbd_trip(void *opaque)
>      case NBD_CMD_FLUSH:
>          TRACE("Request type is FLUSH");
>  
> -        ret = bdrv_co_flush(exp->bs);
> +        ret = blk_co_flush(exp->blk);
>          if (ret < 0) {
>              LOG("flush failed");
>              reply.error = -ret;
> @@ -1274,8 +1273,9 @@ static void nbd_trip(void *opaque)
>          break;
>      case NBD_CMD_TRIM:
>          TRACE("Request type is TRIM");
> -        ret = bdrv_co_discard(exp->bs, (request.from + exp->dev_offset) / 512,
> -                              request.len / 512);
> +        ret = blk_co_discard(exp->blk, (request.from + exp->dev_offset)
> +                                       / BDRV_SECTOR_SIZE,
> +                             request.len / BDRV_SECTOR_SIZE);
>          if (ret < 0) {
>              LOG("discard failed");
>              reply.error = -ret;
> 

  reply	other threads:[~2014-11-17 17:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 15:30 [Qemu-devel] [PATCH 0/5] nbd: Use BlockBackend Max Reitz
2014-11-17 15:30 ` [Qemu-devel] [PATCH 1/5] block: Lift more functions into BlockBackend Max Reitz
2014-11-17 15:30 ` [Qemu-devel] [PATCH 2/5] block: Add AioContextNotifier functions to BB Max Reitz
2014-11-17 17:26   ` Paolo Bonzini
2014-11-18  9:26     ` Max Reitz
2014-11-18  9:44       ` Paolo Bonzini
2014-11-17 15:30 ` [Qemu-devel] [PATCH 3/5] block: Add blk_add_close_notifier() for BB Max Reitz
2014-11-17 15:30 ` [Qemu-devel] [PATCH 4/5] nbd: Change external interface to BlockBackend Max Reitz
2014-11-17 15:30 ` [Qemu-devel] [PATCH 5/5] nbd: Use BlockBackend internally Max Reitz
2014-11-17 17:29   ` Paolo Bonzini [this message]
2014-11-18  9:32     ` Max Reitz

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=546A305E.9040709@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).