diff mbox

[v9,05/30] bootindex: rework add_boot_device_path function

Message ID 1410352286-2736-6-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) Sept. 10, 2014, 12:31 p.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

Add the function of updating bootindex about fw_boot_order list
in add_boot_device_path(). We should delete the old one if a
device has existed in global fw_boot_order list.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 bootdevice.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Gerd Hoffmann Sept. 11, 2014, 6:58 a.m. UTC | #1
> +static void del_original_boot_device(DeviceState *dev, const char *suffix)

Hmm, now we have two simliar delete functions.  One which deletes all
entries belonging to a device, and one deleting only in case the suffix
matches (the later being needed to handle the floppy case I guess?).

Can't we combine the two into one, to avoid code duplication?
For example by deleting all entries for a device in case suffix == NULL?

cheers,
  Gerd
Gonglei (Arei) Sept. 11, 2014, 7:27 a.m. UTC | #2
Hi,

> Subject: Re: [PATCH v9 05/30] bootindex: rework add_boot_device_path

> function

> 

> > +static void del_original_boot_device(DeviceState *dev, const char *suffix)

> 

> Hmm, now we have two simliar delete functions.  One which deletes all

> entries belonging to a device, and one deleting only in case the suffix

> matches (the later being needed to handle the floppy case I guess?).

> 

Yes.

> Can't we combine the two into one, to avoid code duplication?


Yes, we can. :)

> For example by deleting all entries for a device in case suffix == NULL?

> 

Good point. When we hot-unplug a device we can pass 'suffix == NULL'
to del_original_boot_device(DeviceState *dev, const char *suffix), and
then remove all entries belonging to this device.

Thanks! Will rework it.

Best regards,
-Gonglei
diff mbox

Patch

diff --git a/bootdevice.c b/bootdevice.c
index 89aca7f..628596d 100644
--- a/bootdevice.c
+++ b/bootdevice.c
@@ -72,6 +72,25 @@  void del_boot_device_path(DeviceState *dev)
     }
 }
 
+static void del_original_boot_device(DeviceState *dev, const char *suffix)
+{
+    FWBootEntry *i;
+
+    if (dev == NULL) {
+        return;
+    }
+
+    QTAILQ_FOREACH(i, &fw_boot_order, link) {
+        if (i->dev == dev && !g_strcmp0(i->suffix, suffix)) {
+            QTAILQ_REMOVE(&fw_boot_order, i, link);
+            g_free(i->suffix);
+            g_free(i);
+
+            break;
+        }
+    }
+}
+
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
                           const char *suffix)
 {
@@ -83,6 +102,8 @@  void add_boot_device_path(int32_t bootindex, DeviceState *dev,
 
     assert(dev != NULL || suffix != NULL);
 
+    del_original_boot_device(dev, suffix);
+
     node = g_malloc0(sizeof(FWBootEntry));
     node->bootindex = bootindex;
     node->suffix = g_strdup(suffix);