From nobody Mon Feb 9 20:58:47 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 1487009371204835.9195087023504; Mon, 13 Feb 2017 10:09:31 -0800 (PST) Received: from localhost ([::1]:58618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdL44-00043u-A6 for importer@patchew.org; Mon, 13 Feb 2017 13:09:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKM0-0003IK-D7 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:23:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKLy-0006AF-LR for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:23:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51102) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKLt-000663-7f; Mon, 13 Feb 2017 12:23:49 -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 4AE737E9E3; Mon, 13 Feb 2017 17:23:49 +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 v1DHNC3Y031842; Mon, 13 Feb 2017 12:23:47 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 13 Feb 2017 18:22:40 +0100 Message-Id: <1487006583-24350-19-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.26]); Mon, 13 Feb 2017 17:23:49 +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 18/41] block: Allow error return in BlockDevOps.change_media_cb() 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" Some devices allow a media change between read-only and read-write media. They need to adapt the permissions in their .change_media_cb() implementation, which can fail. So add an Error parameter to the function. Signed-off-by: Kevin Wolf --- block/block-backend.c | 12 +++++++++--- blockdev.c | 19 +++++++++++++++---- hw/block/fdc.c | 2 +- hw/ide/core.c | 2 +- hw/scsi/scsi-disk.c | 2 +- hw/sd/sd.c | 2 +- include/block/block_int.h | 2 +- include/sysemu/block-backend.h | 2 +- 8 files changed, 30 insertions(+), 13 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index e10a278..0c23add 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -671,15 +671,21 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDe= vOps *ops, * Else, notify of media eject. * Also send DEVICE_TRAY_MOVED events as appropriate. */ -void blk_dev_change_media_cb(BlockBackend *blk, bool load) +void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp) { if (blk->dev_ops && blk->dev_ops->change_media_cb) { bool tray_was_open, tray_is_open; + Error *local_err =3D NULL; =20 assert(!blk->legacy_dev); =20 tray_was_open =3D blk_dev_is_tray_open(blk); - blk->dev_ops->change_media_cb(blk->dev_opaque, load); + blk->dev_ops->change_media_cb(blk->dev_opaque, load, &local_err); + if (local_err) { + assert(load =3D=3D true); + error_propagate(errp, local_err); + return; + } tray_is_open =3D blk_dev_is_tray_open(blk); =20 if (tray_was_open !=3D tray_is_open) { @@ -693,7 +699,7 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool lo= ad) =20 static void blk_root_change_media(BdrvChild *child, bool load) { - blk_dev_change_media_cb(child->opaque, load); + blk_dev_change_media_cb(child->opaque, load, NULL); } =20 /* diff --git a/blockdev.c b/blockdev.c index c590e67..8c30084 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2307,7 +2307,7 @@ static int do_open_tray(const char *blk_name, const c= har *qdev_id, } =20 if (!locked || force) { - blk_dev_change_media_cb(blk, false); + blk_dev_change_media_cb(blk, false, &error_abort); } =20 if (locked && !force) { @@ -2345,6 +2345,7 @@ void qmp_blockdev_close_tray(bool has_device, const c= har *device, Error **errp) { BlockBackend *blk; + Error *local_err =3D NULL; =20 device =3D has_device ? device : NULL; id =3D has_id ? id : NULL; @@ -2368,7 +2369,11 @@ void qmp_blockdev_close_tray(bool has_device, const = char *device, return; } =20 - blk_dev_change_media_cb(blk, true); + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 void qmp_x_blockdev_remove_medium(bool has_device, const char *device, @@ -2421,7 +2426,7 @@ void qmp_x_blockdev_remove_medium(bool has_device, co= nst char *device, * called at all); therefore, the medium needs to be ejected here. * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the= @load * value passed here (i.e. false). */ - blk_dev_change_media_cb(blk, false); + blk_dev_change_media_cb(blk, false, &error_abort); } =20 out: @@ -2431,6 +2436,7 @@ out: static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, BlockDriverState *bs, Error **= errp) { + Error *local_err =3D NULL; bool has_device; int ret; =20 @@ -2463,7 +2469,12 @@ static void qmp_blockdev_insert_anon_medium(BlockBac= kend *blk, * slot here. * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the= @load * value passed here (i.e. true). */ - blk_dev_change_media_cb(blk, true); + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + blk_remove_bs(blk); + return; + } } } =20 diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 74f3634..5f6c496 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -469,7 +469,7 @@ static void fd_revalidate(FDrive *drv) } } =20 -static void fd_change_cb(void *opaque, bool load) +static void fd_change_cb(void *opaque, bool load, Error **errp) { FDrive *drive =3D opaque; =20 diff --git a/hw/ide/core.c b/hw/ide/core.c index 43709e5..f88b1e5 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1120,7 +1120,7 @@ static void ide_cfata_metadata_write(IDEState *s) } =20 /* called when the inserted state of the media has changed */ -static void ide_cd_change_cb(void *opaque, bool load) +static void ide_cd_change_cb(void *opaque, bool load, Error **errp) { IDEState *s =3D opaque; uint64_t nb_sectors; diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 61c44a9..f3f20da 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2225,7 +2225,7 @@ static void scsi_disk_resize_cb(void *opaque) } } =20 -static void scsi_cd_change_media_cb(void *opaque, bool load) +static void scsi_cd_change_media_cb(void *opaque, bool load, Error **errp) { SCSIDiskState *s =3D opaque; =20 diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8e88e83..8e31491 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -458,7 +458,7 @@ static bool sd_get_readonly(SDState *sd) return sd->wp_switch; } =20 -static void sd_cardchange(void *opaque, bool load) +static void sd_cardchange(void *opaque, bool load, Error **errp) { SDState *sd =3D opaque; DeviceState *dev =3D DEVICE(sd); diff --git a/include/block/block_int.h b/include/block/block_int.h index 46f51a6..7558f99 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -895,7 +895,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, Bd= rvChild *c, uint64_t *nperm, uint64_t *nshared); =20 const char *bdrv_get_parent_name(const BlockDriverState *bs); -void blk_dev_change_media_cb(BlockBackend *blk, bool load); +void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); bool blk_dev_has_tray(BlockBackend *blk); void blk_dev_eject_request(BlockBackend *blk, bool force); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 6f21508..65bd081 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -34,7 +34,7 @@ typedef struct BlockDevOps { * changes. Sure would be useful if it did. * Device models with removable media must implement this callback. */ - void (*change_media_cb)(void *opaque, bool load); + void (*change_media_cb)(void *opaque, bool load, Error **errp); /* * Runs when an eject request is issued from the monitor, the tray * is closed, and the medium is locked. --=20 1.8.3.1