All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org,
	stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH 8/8] nbd: use BlockDriverState refcnt
Date: Thu, 25 Jul 2013 09:01:41 -0400	[thread overview]
Message-ID: <20130725130141.GC19682@localhost.localdomain> (raw)
In-Reply-To: <1374742906-4489-9-git-send-email-famz@redhat.com>

On Thu, Jul 25, 2013 at 05:01:46PM +0800, Fam Zheng wrote:
> Previously, nbd calls drive_get_ref() on the drive of bs. A BDS doesn't
> always have associated dinfo, which nbd doesn't care either. We already
> have BDS ref count, so use it to make it safe for a BDS w/o blockdev.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  blockdev-nbd.c | 10 +---------
>  nbd.c          |  5 +++++
>  2 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/blockdev-nbd.c b/blockdev-nbd.c
> index 95f10c8..922cf56 100644
> --- a/blockdev-nbd.c
> +++ b/blockdev-nbd.c
> @@ -69,12 +69,6 @@ static void nbd_close_notifier(Notifier *n, void *data)
>      g_free(cn);
>  }
>  
> -static void nbd_server_put_ref(NBDExport *exp)
> -{
> -    BlockDriverState *bs = nbd_export_get_blockdev(exp);
> -    drive_put_ref(drive_get_by_blockdev(bs));
> -}
> -
>  void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
>                          Error **errp)
>  {
> @@ -105,11 +99,9 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
>          writable = false;
>      }
>  
> -    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY,
> -                         nbd_server_put_ref);
> +    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL);
>  
>      nbd_export_set_name(exp, device);
> -    drive_get_ref(drive_get_by_blockdev(bs));
>  
>      n = g_malloc0(sizeof(NBDCloseNotifier));
>      n->n.notify = nbd_close_notifier;
> diff --git a/nbd.c b/nbd.c
> index 2606403..f258cdd 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -881,6 +881,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
>      exp->nbdflags = nbdflags;
>      exp->size = size == -1 ? bdrv_getlength(bs) : size;
>      exp->close = close;
> +    bdrv_ref(bs);
>      return exp;
>  }
>  
> @@ -927,6 +928,10 @@ void nbd_export_close(NBDExport *exp)
>      }
>      nbd_export_set_name(exp, NULL);
>      nbd_export_put(exp);
> +    if (exp->bs) {
> +        bdrv_unref(exp->bs);
> +        exp->bs = NULL;
> +    }

Same thing here - if the refcnt is ever > 1, then this leaks exp->bs.

>  }
>  
>  void nbd_export_get(NBDExport *exp)
> -- 
> 1.8.3.2
> 
> 

  reply	other threads:[~2013-07-25 13:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  9:01 [Qemu-devel] [PATCH 0/8] Implement reference count for BlockDriverState Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 1/8] vvfat: use bdrv_new() to allocate BlockDriverState Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 2/8] iscsi: use bdrv_new() instead of stack structure Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 3/8] block: implement reference count for BlockDriverState Fam Zheng
2013-07-25 13:15   ` Jeff Cody
2013-07-26  1:13     ` Fam Zheng
2013-07-26  1:50       ` Jeff Cody
2013-07-26  1:56         ` Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 4/8] block: make bdrv_delete() static Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 5/8] block: use BlockDriverState refcnt for device attach/detach Fam Zheng
2013-07-25 12:49   ` Jeff Cody
2013-07-25  9:01 ` [Qemu-devel] [PATCH 6/8] migration: omit drive ref as we have bdrv_ref now Fam Zheng
2013-07-25  9:01 ` [Qemu-devel] [PATCH 7/8] xen_disk: simplify blk_disconnect with refcnt Fam Zheng
2013-07-25 12:56   ` Jeff Cody
2013-07-26  1:30     ` Jeff Cody
2013-07-25  9:01 ` [Qemu-devel] [PATCH 8/8] nbd: use BlockDriverState refcnt Fam Zheng
2013-07-25 13:01   ` Jeff Cody [this message]
2013-07-26  1:29     ` Jeff Cody

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=20130725130141.GC19682@localhost.localdomain \
    --to=jcody@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.