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: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Acked-by: Fam Zheng <famz@redhat.com>
18 files changed:
goto fail;
}
if (file_bs != NULL) {
goto fail;
}
if (file_bs != NULL) {
+ file = blk_new(BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL);
blk_insert_bs(file, file_bs);
bdrv_unref(file_bs);
blk_insert_bs(file, file_bs);
bdrv_unref(file_bs);
- 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;
blk_insert_bs(job->target, target);
job->on_source_error = on_source_error;
/*
* Create a new BlockBackend with a reference count of one.
/*
* 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.
*/
* 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;
{
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]);
blk_set_enable_write_cache(blk, true);
qemu_co_queue_init(&blk->public.throttled_reqs[0]);
BlockBackend *blk;
BlockDriverState *bs;
BlockBackend *blk;
BlockDriverState *bs;
+ blk = blk_new(0, BLK_PERM_ALL);
bs = bdrv_open(filename, reference, options, flags, errp);
if (!bs) {
blk_unref(blk);
bs = bdrv_open(filename, reference, options, flags, errp);
if (!bs) {
blk_unref(blk);
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
{
bdrv_ref(bs);
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,
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) {
notifier_list_notify(&blk->insert_bs_notifiers, blk);
if (blk->public.throttle_state) {
block_job_add_bdrv(&s->common, overlay_bs);
}
block_job_add_bdrv(&s->common, overlay_bs);
}
+ /* FIXME Use real permissions */
+ s->base = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(s->base, base);
blk_insert_bs(s->base, base);
+ /* FIXME Use real permissions */
+ s->top = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(s->top, top);
s->active = bs;
blk_insert_bs(s->top, top);
s->active = bs;
+ /* FIXME Use real permissions */
+ src = blk_new(0, BLK_PERM_ALL);
+ /* FIXME Use real permissions */
+ backing = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(backing, bs->backing->bs);
length = blk_getlength(src);
blk_insert_bs(backing, bs->backing->bs);
length = blk_getlength(src);
+ /* FIXME Use real permissions */
+ s->target = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(s->target, target);
s->replaces = g_strdup(replaces);
blk_insert_bs(s->target, target);
s->replaces = g_strdup(replaces);
- BlockBackend *blk = blk_new();
+ BlockBackend *blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
ret = blk_truncate(blk, new_size);
blk_unref(blk);
blk_insert_bs(blk, bs);
ret = blk_truncate(blk, new_size);
blk_unref(blk);
if ((!file || !*file) && !qdict_size(bs_opts)) {
BlockBackendRootState *blk_rs;
if ((!file || !*file) && !qdict_size(bs_opts)) {
BlockBackendRootState *blk_rs;
+ blk = blk_new(0, BLK_PERM_ALL);
blk_rs = blk_get_root_state(blk);
blk_rs->open_flags = bdrv_flags;
blk_rs->read_only = read_only;
blk_rs = blk_get_root_state(blk);
blk_rs->open_flags = bdrv_flags;
blk_rs->read_only = read_only;
+ blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
/* complete all in-flight operations before resizing the device */
blk_insert_bs(blk, bs);
/* complete all in-flight operations before resizing the device */
+ /* FIXME Use real permissions */
+ blk = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
job = g_malloc0(driver->instance_size);
blk_insert_bs(blk, bs);
job = g_malloc0(driver->instance_size);
if (!blk) {
BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
if (bs) {
if (!blk) {
BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
if (bs) {
- blk = local_blk = blk_new();
+ /* FIXME Use real permissions */
+ blk = local_blk = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
} else {
goto fail;
blk_insert_bs(blk, bs);
} else {
goto fail;
if (!dev->conf.blk) {
/* Anonymous BlockBackend for an empty drive */
if (!dev->conf.blk) {
/* Anonymous BlockBackend for an empty drive */
- dev->conf.blk = blk_new();
+ /* FIXME Use real permissions */
+ dev->conf.blk = blk_new(0, BLK_PERM_ALL);
ret = blk_attach_dev(dev->conf.blk, qdev);
assert(ret == 0);
}
ret = blk_attach_dev(dev->conf.blk, qdev);
assert(ret == 0);
}
if (!blk) {
BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL);
if (bs) {
if (!blk) {
BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL);
if (bs) {
+ /* FIXME Use real permissions */
+ blk = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
blk_created = true;
}
blk_insert_bs(blk, bs);
blk_created = true;
}
return -1;
} else {
/* Anonymous BlockBackend for an empty drive */
return -1;
} else {
/* Anonymous BlockBackend for an empty drive */
- dev->conf.blk = blk_new();
+ /* FIXME Use real permissions */
+ dev->conf.blk = blk_new(0, BLK_PERM_ALL);
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
if (!dev->conf.blk) {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
if (!dev->conf.blk) {
- dev->conf.blk = blk_new();
+ /* FIXME Use real permissions */
+ dev->conf.blk = blk_new(0, BLK_PERM_ALL);
}
s->qdev.blocksize = 2048;
}
s->qdev.blocksize = 2048;
QLIST_ENTRY(BlockBackendPublic) round_robin;
} BlockBackendPublic;
QLIST_ENTRY(BlockBackendPublic) round_robin;
} BlockBackendPublic;
-BlockBackend *blk_new(void);
+BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm);
BlockBackend *blk_new_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp);
int blk_get_refcnt(BlockBackend *blk);
BlockBackend *blk_new_open(const char *filename, const char *reference,
QDict *options, int flags, Error **errp);
int blk_get_refcnt(BlockBackend *blk);
}
bmds = g_new0(BlkMigDevState, 1);
}
bmds = g_new0(BlkMigDevState, 1);
+ /* FIXME Use real permissions */
+ bmds->blk = blk_new(0, BLK_PERM_ALL);
bmds->blk_name = g_strdup(bdrv_get_device_name(bs));
bmds->bulk_completed = 0;
bmds->total_sectors = sectors;
bmds->blk_name = g_strdup(bdrv_get_device_name(bs));
bmds->bulk_completed = 0;
bmds->total_sectors = sectors;
BlockBackend *blk;
NBDExport *exp = g_malloc0(sizeof(NBDExport));
BlockBackend *blk;
NBDExport *exp = g_malloc0(sizeof(NBDExport));
+ /* FIXME Use real permissions */
+ blk = blk_new(0, BLK_PERM_ALL);
blk_insert_bs(blk, bs);
blk_set_enable_write_cache(blk, !writethrough);
blk_insert_bs(blk, bs);
blk_set_enable_write_cache(blk, !writethrough);
* BlockDriverState inserted. */
static BlockBackend *create_blk(const char *name)
{
* BlockDriverState inserted. */
static BlockBackend *create_blk(const char *name)
{
- BlockBackend *blk = blk_new();
+ /* FIXME Use real permissions */
+ BlockBackend *blk = blk_new(0, BLK_PERM_ALL);
BlockDriverState *bs;
bs = bdrv_open("null-co://", NULL, NULL, 0, &error_abort);
BlockDriverState *bs;
bs = bdrv_open("null-co://", NULL, NULL, 0, &error_abort);
BlockBackend *blk1, *blk2, *blk3;
BlockBackendPublic *blkp1, *blkp2, *blkp3;
BlockBackend *blk1, *blk2, *blk3;
BlockBackendPublic *blkp1, *blkp2, *blkp3;
- blk1 = blk_new();
- blk2 = blk_new();
- blk3 = blk_new();
+ /* FIXME Use real permissions */
+ blk1 = blk_new(0, BLK_PERM_ALL);
+ blk2 = blk_new(0, BLK_PERM_ALL);
+ blk3 = blk_new(0, BLK_PERM_ALL);
blkp1 = blk_get_public(blk1);
blkp2 = blk_get_public(blk2);
blkp1 = blk_get_public(blk1);
blkp2 = blk_get_public(blk2);