All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: jim@groklearning.com, Joel Stanley <joel@jms.id.au>,
	Peter Maydell <peter.maydell@linaro.org>,
	Subbaraya Sundeep <sundeep.lkml@gmail.com>,
	qemu-arm@nongnu.org, jusual@mail.ru,
	Alistair Francis <alistair@alistair23.me>,
	mail@steffen-goertz.de, ilg@livius.net,
	Su Hang <suhang16@mails.ucas.ac.cn>,
	Steffen Gortz <qemu.ml@steffen-goertz.de>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v4 4/6] loader: add rom transaction API
Date: Fri,  3 Aug 2018 15:47:19 +0100	[thread overview]
Message-ID: <20180803144721.17036-5-stefanha@redhat.com> (raw)
In-Reply-To: <20180803144721.17036-1-stefanha@redhat.com>

Image file loaders may add a series of roms.  If an error occurs partway
through loading there is no easy way to drop previously added roms.

This patch adds a transaction mechanism that works like this:

  rom_transaction_begin();
  ...call rom_add_*()...
  rom_transaction_end(ok);

If ok is false then roms added in this transaction are dropped.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/hw/loader.h | 19 +++++++++++++++++++
 hw/core/loader.c    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/hw/loader.h b/include/hw/loader.h
index e98b84b8f9..5235f119a3 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -225,6 +225,25 @@ int rom_check_and_register_reset(void);
 void rom_set_fw(FWCfgState *f);
 void rom_set_order_override(int order);
 void rom_reset_order_override(void);
+
+/**
+ * rom_transaction_begin:
+ *
+ * Call this before of a series of rom_add_*() calls.  Call
+ * rom_transaction_end() afterwards to commit or abort.  These functions are
+ * useful for undoing a series of rom_add_*() calls if image file loading fails
+ * partway through.
+ */
+void rom_transaction_begin(void);
+
+/**
+ * rom_transaction_end:
+ * @commit: true to commit added roms, false to drop added roms
+ *
+ * Call this after a series of rom_add_*() calls.  See rom_transaction_begin().
+ */
+void rom_transaction_end(bool commit);
+
 int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
 void *rom_ptr(hwaddr addr, size_t size);
 void hmp_info_roms(Monitor *mon, const QDict *qdict);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 0c72e7c05a..612420b870 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -840,6 +840,8 @@ struct Rom {
     char *fw_dir;
     char *fw_file;
 
+    bool committed;
+
     hwaddr addr;
     QTAILQ_ENTRY(Rom) next;
 };
@@ -877,6 +879,8 @@ static void rom_insert(Rom *rom)
         rom->as = &address_space_memory;
     }
 
+    rom->committed = false;
+
     /* List is ordered by load address in the same address space */
     QTAILQ_FOREACH(item, &roms, next) {
         if (rom_order_compare(rom, item)) {
@@ -1168,6 +1172,34 @@ void rom_reset_order_override(void)
     fw_cfg_reset_order_override(fw_cfg);
 }
 
+void rom_transaction_begin(void)
+{
+    Rom *rom;
+
+    /* Ignore ROMs added without the transaction API */
+    QTAILQ_FOREACH(rom, &roms, next) {
+        rom->committed = true;
+    }
+}
+
+void rom_transaction_end(bool commit)
+{
+    Rom *rom;
+    Rom *tmp;
+
+    QTAILQ_FOREACH_SAFE(rom, &roms, next, tmp) {
+        if (rom->committed) {
+            continue;
+        }
+        if (commit) {
+            rom->committed = true;
+        } else {
+            QTAILQ_REMOVE(&roms, rom, next);
+            rom_free(rom);
+        }
+    }
+}
+
 static Rom *find_rom(hwaddr addr, size_t size)
 {
     Rom *rom;
-- 
2.17.1

  parent reply	other threads:[~2018-08-03 14:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03 14:47 [Qemu-devel] [PATCH v4 0/6] arm: add Cortex M0 CPU model and hex file loader Stefan Hajnoczi
2018-08-03 14:47 ` [Qemu-devel] [PATCH v4 1/6] hw/arm: make bitbanded IO optional on ARMv7-M Stefan Hajnoczi
2018-08-10  3:31   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-03 14:47 ` [Qemu-devel] [PATCH v4 2/6] target/arm: add "cortex-m0" CPU model Stefan Hajnoczi
2018-08-10  3:38   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-03 14:47 ` [Qemu-devel] [PATCH v4 3/6] loader: extract rom_free() function Stefan Hajnoczi
2018-08-08 21:32   ` Alistair Francis
2018-08-10  3:39   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-03 14:47 ` Stefan Hajnoczi [this message]
2018-08-08 21:31   ` [Qemu-devel] [PATCH v4 4/6] loader: add rom transaction API Alistair Francis
2018-08-13  9:58     ` Stefan Hajnoczi
2018-08-03 14:47 ` [Qemu-devel] [PATCH v4 5/6] loader: Implement .hex file loader Stefan Hajnoczi
2018-08-10  5:00   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-10 10:25     ` sail darcy
2018-08-13 15:56     ` Stefan Hajnoczi
2018-08-15 14:18       ` Philippe Mathieu-Daudé
2018-08-15 17:52         ` Stefan Hajnoczi
2018-08-16 16:10           ` Philippe Mathieu-Daudé
2018-08-03 14:47 ` [Qemu-devel] [PATCH v4 6/6] Add QTest testcase for the Intel Hexadecimal Stefan Hajnoczi
2018-08-10  4:26   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-13 18:49     ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180803144721.17036-5-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=alistair@alistair23.me \
    --cc=ilg@livius.net \
    --cc=jim@groklearning.com \
    --cc=joel@jms.id.au \
    --cc=jusual@mail.ru \
    --cc=mail@steffen-goertz.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu.ml@steffen-goertz.de \
    --cc=suhang16@mails.ucas.ac.cn \
    --cc=sundeep.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.