Received: from eggs.gnu.org ([2001:4830:134:3::10]:44013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPp4q-0000X0-GM for qemu-devel@nongnu.org; Fri, 05 Sep 2014 04:41:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPp4k-0004S8-TJ for qemu-devel@nongnu.org; Fri, 05 Sep 2014 04:41:04 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:60542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPp4j-0004RY-UH for qemu-devel@nongnu.org; Fri, 05 Sep 2014 04:40:58 -0400 From: Date: Fri, 5 Sep 2014 16:37:13 +0800 Message-ID: <1409906256-11368-6-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1409906256-11368-1-git-send-email-arei.gonglei@huawei.com> References: <1409906256-11368-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v7 05/28] bootindex: rework add_boot_device_path function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: chenliang88@huawei.com, weidong.huang@huawei.com, mst@redhat.com, aik@ozlabs.ru, hutao@cn.fujitsu.com, armbru@redhat.com, kraxel@redhat.com, akong@redhat.com, agraf@suse.de, Gonglei , aliguori@amazon.com, ehabkost@redhat.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, hani@linux.com, stefanha@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com, kwolf@redhat.com, peter.crosthwaite@xilinx.com, imammedo@redhat.com, afaerber@suse.de From: Gonglei 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 --- bootdevice.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bootdevice.c b/bootdevice.c index 89aca7f..6f430ec 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -72,6 +72,34 @@ 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 (suffix) { + if (i->dev == dev && !strcmp(i->suffix, suffix)) { + QTAILQ_REMOVE(&fw_boot_order, i, link); + g_free(i->suffix); + g_free(i); + + break; + } + } else { /* host-usb and scsi devices do not have a suffix */ + if (i->dev == dev) { + QTAILQ_REMOVE(&fw_boot_order, i, link); + g_free(i); + + break; + } + } + } +} + void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix) { @@ -83,6 +111,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); -- 1.7.12.4