Skip to content

Commit

Permalink
nbd: use BlockDriverState refcnt
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
Fam Zheng authored and stefanhaRH committed Sep 6, 2013
1 parent c0777fe commit 38b54b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 1 addition & 9 deletions blockdev-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,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;
}

Expand Down Expand Up @@ -928,6 +929,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;
}
}

void nbd_export_get(NBDExport *exp)
Expand Down

0 comments on commit 38b54b6

Please sign in to comment.