From nobody Mon Feb 9 20:58:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487009088289259.39817798168644; Mon, 13 Feb 2017 10:04:48 -0800 (PST) Received: from localhost ([::1]:58590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKzU-00087F-Lj for importer@patchew.org; Mon, 13 Feb 2017 13:04:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKLt-0003AD-UC for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:23:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKLs-00065O-1L for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:23:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKLn-0005y3-Ga; Mon, 13 Feb 2017 12:23:43 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6E6D3B713; Mon, 13 Feb 2017 17:23:43 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-183.ams2.redhat.com [10.36.117.183]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHNC3V031842; Mon, 13 Feb 2017 12:23:42 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 13 Feb 2017 18:22:37 +0100 Message-Id: <1487006583-24350-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1487006583-24350-1-git-send-email-kwolf@redhat.com> References: <1487006583-24350-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 13 Feb 2017 17:23:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 15/41] block: Add permissions to blk_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jcody@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 yet. Instead, the usual FIXME comment is added to each place and will be addressed in individual patches. Signed-off-by: Kevin Wolf --- block/backup.c | 3 ++- block/block-backend.c | 12 ++++++------ block/commit.c | 12 ++++++++---- block/mirror.c | 3 ++- blockdev.c | 2 +- blockjob.c | 3 ++- hmp.c | 3 ++- hw/block/fdc.c | 3 ++- hw/core/qdev-properties-system.c | 3 ++- hw/ide/qdev.c | 3 ++- hw/scsi/scsi-disk.c | 3 ++- include/sysemu/block-backend.h | 2 +- migration/block.c | 3 ++- nbd/server.c | 3 ++- tests/test-blockjob.c | 3 ++- tests/test-throttle.c | 7 ++++--- 16 files changed, 42 insertions(+), 26 deletions(-) diff --git a/block/backup.c b/block/backup.c index ea38733..bb76c69 100644 --- a/block/backup.c +++ b/block/backup.c @@ -624,7 +624,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, goto error; } =20 - job->target =3D blk_new(); + /* FIXME Use real permissions */ + job->target =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(job->target, target); =20 job->on_source_error =3D on_source_error; diff --git a/block/block-backend.c b/block/block-backend.c index 8f0348d..a219f0b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -123,14 +123,14 @@ static const BdrvChildRole child_root =3D { * Store an error through @errp on failure, unless it's null. * 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; =20 blk =3D g_new0(BlockBackend, 1); blk->refcnt =3D 1; - blk->perm =3D 0; - blk->shared_perm =3D BLK_PERM_ALL; + blk->perm =3D perm; + blk->shared_perm =3D shared_perm; blk_set_enable_write_cache(blk, true); =20 qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -161,7 +161,7 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, BlockBackend *blk; BlockDriverState *bs; =20 - blk =3D blk_new(); + blk =3D blk_new(0, BLK_PERM_ALL); bs =3D bdrv_open(filename, reference, options, flags, errp); if (!bs) { blk_unref(blk); @@ -505,9 +505,9 @@ void blk_remove_bs(BlockBackend *blk) void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { bdrv_ref(bs); - /* FIXME Use real permissions */ blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - 0, BLK_PERM_ALL, blk, &error_abort); + blk->perm, blk->shared_perm, blk, + &error_abort); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { diff --git a/block/commit.c b/block/commit.c index c284e85..1897e98 100644 --- a/block/commit.c +++ b/block/commit.c @@ -275,10 +275,12 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, block_job_add_bdrv(&s->common, overlay_bs); } =20 - s->base =3D blk_new(); + /* FIXME Use real permissions */ + s->base =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->base, base); =20 - s->top =3D blk_new(); + /* FIXME Use real permissions */ + s->top =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->top, top); =20 s->active =3D bs; @@ -328,10 +330,12 @@ int bdrv_commit(BlockDriverState *bs) } } =20 - src =3D blk_new(); + /* FIXME Use real permissions */ + src =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(src, bs); =20 - backing =3D blk_new(); + /* FIXME Use real permissions */ + backing =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(backing, bs->backing->bs); =20 length =3D blk_getlength(src); diff --git a/block/mirror.c b/block/mirror.c index 301ba92..810933e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -985,7 +985,8 @@ static void mirror_start_job(const char *job_id, BlockD= riverState *bs, return; } =20 - s->target =3D blk_new(); + /* FIXME Use real permissions */ + s->target =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->target, target); =20 s->replaces =3D g_strdup(replaces); diff --git a/blockdev.c b/blockdev.c index db82ac9..2e195f1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -554,7 +554,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, if ((!file || !*file) && !qdict_size(bs_opts)) { BlockBackendRootState *blk_rs; =20 - blk =3D blk_new(); + blk =3D blk_new(0, BLK_PERM_ALL); blk_rs =3D blk_get_root_state(blk); blk_rs->open_flags =3D bdrv_flags; blk_rs->read_only =3D read_only; diff --git a/blockjob.c b/blockjob.c index abee11b..508e0e5 100644 --- a/blockjob.c +++ b/blockjob.c @@ -159,7 +159,8 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, } } =20 - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); =20 job =3D g_malloc0(driver->instance_size); diff --git a/hmp.c b/hmp.c index 2bc4f06..15fd3f7 100644 --- a/hmp.c +++ b/hmp.c @@ -2044,7 +2044,8 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, device, &err); if (bs) { - blk =3D local_blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D local_blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); } else { goto fail; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 17d29e7..74f3634 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -533,7 +533,8 @@ static int floppy_drive_init(DeviceState *qdev) =20 if (!dev->conf.blk) { /* Anonymous BlockBackend for an empty drive */ - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); ret =3D blk_attach_dev(dev->conf.blk, qdev); assert(ret =3D=3D 0); } diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 94f4d8b..cca4775 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -78,7 +78,8 @@ static void parse_drive(DeviceState *dev, const char *str= , void **ptr, if (!blk) { BlockDriverState *bs =3D bdrv_lookup_bs(NULL, str, NULL); if (bs) { - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); blk_created =3D true; } diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index dbaa75c..bb3c377 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -170,7 +170,8 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind = kind) return -1; } else { /* Anonymous BlockBackend for an empty drive */ - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } } =20 diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index cc06fe5..61c44a9 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2365,7 +2365,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); =20 if (!dev->conf.blk) { - dev->conf.blk =3D blk_new(); + /* FIXME Use real permissions */ + dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); } =20 s->qdev.blocksize =3D 2048; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 4a5783a..1bda6d7 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -78,7 +78,7 @@ typedef struct BlockBackendPublic { QLIST_ENTRY(BlockBackendPublic) round_robin; } BlockBackendPublic; =20 -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); diff --git a/migration/block.c b/migration/block.c index ebc10e6..6b7ffd4 100644 --- a/migration/block.c +++ b/migration/block.c @@ -415,7 +415,8 @@ static void init_blk_migration(QEMUFile *f) } =20 bmds =3D g_new0(BlkMigDevState, 1); - bmds->blk =3D blk_new(); + /* FIXME Use real permissions */ + bmds->blk =3D blk_new(0, BLK_PERM_ALL); bmds->blk_name =3D g_strdup(bdrv_get_device_name(bs)); bmds->bulk_completed =3D 0; bmds->total_sectors =3D sectors; diff --git a/nbd/server.c b/nbd/server.c index efe5cb8..871111c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -890,7 +890,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t d= ev_offset, off_t size, BlockBackend *blk; NBDExport *exp =3D g_malloc0(sizeof(NBDExport)); =20 - blk =3D blk_new(); + /* FIXME Use real permissions */ + blk =3D blk_new(0, BLK_PERM_ALL); blk_insert_bs(blk, bs); blk_set_enable_write_cache(blk, !writethrough); =20 diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 068c9e4..1dd1cfa 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -53,7 +53,8 @@ static BlockJob *do_test_id(BlockBackend *blk, const char= *id, * BlockDriverState inserted. */ static BlockBackend *create_blk(const char *name) { - BlockBackend *blk =3D blk_new(); + /* FIXME Use real permissions */ + BlockBackend *blk =3D blk_new(0, BLK_PERM_ALL); BlockDriverState *bs; =20 bs =3D bdrv_open("null-co://", NULL, NULL, 0, &error_abort); diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 363b59a..5846433 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -593,9 +593,10 @@ static void test_groups(void) BlockBackend *blk1, *blk2, *blk3; BlockBackendPublic *blkp1, *blkp2, *blkp3; =20 - blk1 =3D blk_new(); - blk2 =3D blk_new(); - blk3 =3D blk_new(); + /* FIXME Use real permissions */ + blk1 =3D blk_new(0, BLK_PERM_ALL); + blk2 =3D blk_new(0, BLK_PERM_ALL); + blk3 =3D blk_new(0, BLK_PERM_ALL); =20 blkp1 =3D blk_get_public(blk1); blkp2 =3D blk_get_public(blk2); --=20 1.8.3.1