Commit 6d0eb64d authored by Kevin Wolf's avatar Kevin Wolf
Browse files

block: Add permissions to blk_new()



We want every user to be specific about the permissions it needs, so
we'll pass the initial permissions as parameters to blk_new(). A user
only needs to call blk_set_perm() if it wants to change the permissions
after the fact.

The permissions are stored in the BlockBackend and applied whenever a
BlockDriverState should be attached in blk_insert_bs().

This does not include actually choosing the right set of permissions
everywhere yet. Instead, the usual FIXME comment is added to each place
and will be addressed in individual patches.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Acked-by: default avatarFam Zheng <famz@redhat.com>
parent 981776b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2193,7 +2193,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
            goto fail;
        }
        if (file_bs != NULL) {
            file = blk_new();
            file = blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL);
            blk_insert_bs(file, file_bs);
            bdrv_unref(file_bs);

+2 −1
Original line number Diff line number Diff line
@@ -624,7 +624,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
        goto error;
    }

    job->target = blk_new();
    /* FIXME Use real permissions */
    job->target = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(job->target, target);

    job->on_source_error = on_source_error;
+14 −7
Original line number Diff line number Diff line
@@ -120,17 +120,23 @@ static const BdrvChildRole child_root = {

/*
 * Create a new BlockBackend with a reference count of one.
 * Store an error through @errp on failure, unless it's null.
 *
 * @perm is a bitmasks of BLK_PERM_* constants which describes the permissions
 * to request for a block driver node that is attached to this BlockBackend.
 * @shared_perm is a bitmask which describes which permissions may be granted
 * to other users of the attached node.
 * Both sets of permissions can be changed later using blk_set_perm().
 *
 * Return the new BlockBackend on success, null on failure.
 */
BlockBackend *blk_new(void)
BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm)
{
    BlockBackend *blk;

    blk = g_new0(BlockBackend, 1);
    blk->refcnt = 1;
    blk->perm = 0;
    blk->shared_perm = BLK_PERM_ALL;
    blk->perm = perm;
    blk->shared_perm = shared_perm;
    blk_set_enable_write_cache(blk, true);

    qemu_co_queue_init(&blk->public.throttled_reqs[0]);
@@ -161,7 +167,7 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
    BlockBackend *blk;
    BlockDriverState *bs;

    blk = blk_new();
    blk = blk_new(0, BLK_PERM_ALL);
    bs = bdrv_open(filename, reference, options, flags, errp);
    if (!bs) {
        blk_unref(blk);
@@ -505,9 +511,10 @@ void blk_remove_bs(BlockBackend *blk)
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
{
    bdrv_ref(bs);
    /* FIXME Use real permissions */
    /* FIXME Error handling */
    blk->root = bdrv_root_attach_child(bs, "root", &child_root,
                                       0, BLK_PERM_ALL, blk, &error_abort);
                                       blk->perm, blk->shared_perm, blk,
                                       &error_abort);

    notifier_list_notify(&blk->insert_bs_notifiers, blk);
    if (blk->public.throttle_state) {
+8 −4
Original line number Diff line number Diff line
@@ -275,10 +275,12 @@ void commit_start(const char *job_id, BlockDriverState *bs,
        block_job_add_bdrv(&s->common, overlay_bs);
    }

    s->base = blk_new();
    /* FIXME Use real permissions */
    s->base = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(s->base, base);

    s->top = blk_new();
    /* FIXME Use real permissions */
    s->top = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(s->top, top);

    s->active = bs;
@@ -328,10 +330,12 @@ int bdrv_commit(BlockDriverState *bs)
        }
    }

    src = blk_new();
    /* FIXME Use real permissions */
    src = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(src, bs);

    backing = blk_new();
    /* FIXME Use real permissions */
    backing = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(backing, bs->backing->bs);

    length = blk_getlength(src);
+2 −1
Original line number Diff line number Diff line
@@ -1017,7 +1017,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
        return;
    }

    s->target = blk_new();
    /* FIXME Use real permissions */
    s->target = blk_new(0, BLK_PERM_ALL);
    blk_insert_bs(s->target, target);

    s->replaces = g_strdup(replaces);
Loading