Received: from eggs.gnu.org ([2001:4830:134:3::10]:44066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpwfq-0008G8-3B for qemu-devel@nongnu.org; Fri, 30 Sep 2016 08:12:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpwfo-0006ri-0p for qemu-devel@nongnu.org; Fri, 30 Sep 2016 08:12:16 -0400 From: Fam Zheng Date: Fri, 30 Sep 2016 20:09:49 +0800 Message-Id: <1475237406-26917-20-git-send-email-famz@redhat.com> In-Reply-To: <1475237406-26917-1-git-send-email-famz@redhat.com> References: <1475237406-26917-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v8 19/36] pflash: Add "lock-mode" property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: berrange@redhat.com, John Snow , qemu-block@nongnu.org, Kevin Wolf , rjones@redhat.com, Jeff Cody , Max Reitz , Markus Armbruster , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, eblake@redhat.com Signed-off-by: Fam Zheng --- hw/block/pflash_cfi01.c | 10 ++++++++++ hw/block/pflash_cfi02.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 62d7a56..df82471 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -76,6 +76,7 @@ struct pflash_t { /*< public >*/ BlockBackend *blk; + ImageLockMode lock_mode; uint32_t nb_blocs; uint64_t sector_len; uint8_t bank_width; @@ -738,6 +739,14 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->blk) { + Error *local_err = NULL; + + blk_lock_image(pfl->blk, pfl->lock_mode, &local_err); + if (local_err) { + vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); + error_propagate(errp, local_err); + return; + } /* read the initial flash content */ ret = blk_pread(pfl->blk, 0, pfl->storage, total_len); @@ -852,6 +861,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) static Property pflash_cfi01_properties[] = { DEFINE_PROP_DRIVE("drive", struct pflash_t, blk), + DEFINE_PROP_LOCK_MODE("lock-mode", struct pflash_t, lock_mode), /* num-blocks is the number of blocks actually visible to the guest, * ie the total size of the device divided by the sector length. * If we're emulating flash devices wired in parallel the actual diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 4f6105c..ff6a9fb 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -620,6 +620,14 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem); pfl->chip_len = chip_len; if (pfl->blk) { + Error *local_err = NULL; + + blk_lock_image(pfl->blk, pfl->lock_mode, &local_err); + if (local_err) { + vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); + error_propagate(errp, local_err); + return; + } /* read the initial flash content */ ret = blk_pread(pfl->blk, 0, pfl->storage, chip_len); if (ret < 0) { @@ -724,6 +732,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) static Property pflash_cfi02_properties[] = { DEFINE_PROP_DRIVE("drive", struct pflash_t, blk), + DEFINE_PROP_LOCK_MODE("lock-mode", struct pflash_t, lock_mode), DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0), DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0), DEFINE_PROP_UINT8("width", struct pflash_t, width, 0), -- 2.7.4