Commit 4f6fd349 authored by Fam Zheng's avatar Fam Zheng Committed by Stefan Hajnoczi
Browse files

block: make bdrv_delete() static



Manage BlockDriverState lifecycle with refcnt, so bdrv_delete() is no
longer public and should be called by bdrv_unref() if refcnt is
decreased to 0.

This is an identical change because effectively, there's no multiple
reference of BDS now: no caller of bdrv_ref() yet, only bdrv_new() sets
bs->refcnt to 1, so all bdrv_unref() now actually delete the BDS.

Signed-off-by: default avatarFam Zheng <famz@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 9fcb0251
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -903,7 +903,7 @@ fail:
    if (!bs->drv) {
        QDECREF(bs->options);
    }
    bdrv_delete(bs);
    bdrv_unref(bs);
    return ret;
}

@@ -954,7 +954,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)
                    *backing_filename ? backing_filename : NULL, options,
                    back_flags, back_drv);
    if (ret < 0) {
        bdrv_delete(bs->backing_hd);
        bdrv_unref(bs->backing_hd);
        bs->backing_hd = NULL;
        bs->open_flags |= BDRV_O_NO_BACKING;
        return ret;
@@ -1029,12 +1029,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
        bs1 = bdrv_new("");
        ret = bdrv_open(bs1, filename, NULL, 0, drv);
        if (ret < 0) {
            bdrv_delete(bs1);
            bdrv_unref(bs1);
            goto fail;
        }
        total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;

        bdrv_delete(bs1);
        bdrv_unref(bs1);

        ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
        if (ret < 0) {
@@ -1108,7 +1108,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
    }

    if (bs->file != file) {
        bdrv_delete(file);
        bdrv_unref(file);
        file = NULL;
    }

@@ -1143,7 +1143,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,

unlink_and_fail:
    if (file != NULL) {
        bdrv_delete(file);
        bdrv_unref(file);
    }
    if (bs->is_temporary) {
        unlink(filename);
@@ -1404,7 +1404,7 @@ void bdrv_close(BlockDriverState *bs)

    if (bs->drv) {
        if (bs->backing_hd) {
            bdrv_delete(bs->backing_hd);
            bdrv_unref(bs->backing_hd);
            bs->backing_hd = NULL;
        }
        bs->drv->bdrv_close(bs);
@@ -1429,7 +1429,7 @@ void bdrv_close(BlockDriverState *bs)
        bs->options = NULL;

        if (bs->file != NULL) {
            bdrv_delete(bs->file);
            bdrv_unref(bs->file);
            bs->file = NULL;
        }
    }
@@ -1653,11 +1653,12 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
            bs_new->drv ? bs_new->drv->format_name : "");
}

void bdrv_delete(BlockDriverState *bs)
static void bdrv_delete(BlockDriverState *bs)
{
    assert(!bs->dev);
    assert(!bs->job);
    assert(!bs->in_use);
    assert(!bs->refcnt);

    bdrv_close(bs);

@@ -2173,7 +2174,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
    QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) {
        /* so that bdrv_close() does not recursively close the chain */
        intermediate_state->bs->backing_hd = NULL;
        bdrv_delete(intermediate_state->bs);
        bdrv_unref(intermediate_state->bs);
    }
    ret = 0;

@@ -4531,7 +4532,7 @@ out:
    free_option_parameters(param);

    if (bs) {
        bdrv_delete(bs);
        bdrv_unref(bs);
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ static void coroutine_fn backup_run(void *opaque)
    hbitmap_free(job->bitmap);

    bdrv_iostatus_disable(target);
    bdrv_delete(target);
    bdrv_unref(target);

    block_job_completed(&job->common, ret);
}
+2 −2
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags)
    s->test_file = bdrv_new("");
    ret = bdrv_open(s->test_file, filename, NULL, flags, NULL);
    if (ret < 0) {
        bdrv_delete(s->test_file);
        bdrv_unref(s->test_file);
        s->test_file = NULL;
        goto fail;
    }
@@ -169,7 +169,7 @@ static void blkverify_close(BlockDriverState *bs)
{
    BDRVBlkverifyState *s = bs->opaque;

    bdrv_delete(s->test_file);
    bdrv_unref(s->test_file);
    s->test_file = NULL;
}

+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options)
    }

exit:
    bdrv_delete(cow_bs);
    bdrv_unref(cow_bs);
    return ret;
}

+1 −1
Original line number Diff line number Diff line
@@ -1286,7 +1286,7 @@ out:
    }
    g_free(bs->opaque);
    bs->opaque = NULL;
    bdrv_delete(bs);
    bdrv_unref(bs);
    return ret;
}

Loading