From patchwork Mon May 19 15:03:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lijun X-Patchwork-Id: 350282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4A30714001A for ; Tue, 20 May 2014 01:04:28 +1000 (EST) Received: from localhost ([::1]:48622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmP73-0008K2-7v for incoming@patchwork.ozlabs.org; Mon, 19 May 2014 11:04:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmP6X-0007Zg-5H for qemu-devel@nongnu.org; Mon, 19 May 2014 11:04:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmP6O-0002Od-4G for qemu-devel@nongnu.org; Mon, 19 May 2014 11:03:53 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:33442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmP6N-0002OO-TT for qemu-devel@nongnu.org; Mon, 19 May 2014 11:03:44 -0400 Received: by mail-pa0-f44.google.com with SMTP id ld10so5921148pab.3 for ; Mon, 19 May 2014 08:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=YXB4745pz+yK9Ya8152agZ4QKI55qYr5mXPu9PNy1BM=; b=yiAe/Fj9CpzHSvfcxmCPQkbZ0+P0XWiPM1newyBwyx+YJH2jWn3j6qqXhq/nXTFDwm VuVxOcmnRtRa16mL7A+DabWOslxZI3oMqmeJSCukh1CzglTI8jBjlGPHD62OtUIx4zLn 58FJoeHzw2/zH6OAmEMboKvR/HX6M2VCtON6/bJQ/vayiCDU8rHMr2okNTqfF1S5KSND SiwMldXUwlqmSI8qzHnLb6nu0h6pmmciuPiCgT7S3A0tjx7/km8Ly1qGICh7SDgW20Fe 0ELewZikIvN3eq4vZ8mVrud2ZJOUfChZnfec8S0W6Q8icR+nJba2geciK0NtoBELfxX8 8pAA== X-Received: by 10.68.202.230 with SMTP id kl6mr43474130pbc.55.1400511822833; Mon, 19 May 2014 08:03:42 -0700 (PDT) Received: from localhost ([125.39.9.128]) by mx.google.com with ESMTPSA id zq5sm30559438pbb.37.2014.05.19.08.03.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 May 2014 08:03:42 -0700 (PDT) From: Jun Li To: qemu-devel@nongnu.org Date: Mon, 19 May 2014 23:03:28 +0800 Message-Id: <1400511808-16929-1-git-send-email-junmuzi@gmail.com> X-Mailer: git-send-email 1.9.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::22c Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com, mst@redhat.com, marcel.a@redhat.com, juli@redhat.com, aliguori@amazon.com, pbonzini@redhat.com, Jun Li , afaerber@suse.de Subject: [Qemu-devel] [PATCH v3] Add remove_boot_device_path() function for hot-unplug device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add remove_boot_device_path() function to remove bootindex when hot-unplug a device. This patch fixed virtio-blk/virtio-net/scsi-disk/scsi-generic device. Signed-off-by: Jun Li --- This patch also fixed bug1086603, ref: https://bugzilla.redhat.com/show_bug.cgi?id=1086603 This version of patch delete dev and suffix parameter from function remove_boot_device_path(). --- hw/block/virtio-blk.c | 1 + hw/net/virtio-net.c | 1 + hw/scsi/scsi-disk.c | 1 + hw/scsi/scsi-generic.c | 1 + include/sysemu/sysemu.h | 1 + vl.c | 15 +++++++++++++++ 6 files changed, 20 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8a568e5..497eb40 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -752,6 +752,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) unregister_savevm(dev, "virtio-blk", s); blockdev_mark_auto_del(s->bs); virtio_cleanup(vdev); + remove_boot_device_path(s->conf->bootindex); } static Property virtio_blk_properties[] = { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 940a7cf..6afb1ca 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1645,6 +1645,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) g_free(n->vqs); qemu_del_nic(n->nic); virtio_cleanup(vdev); + remove_boot_device_path(n->nic_conf.bootindex); } static void virtio_net_instance_init(Object *obj) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4bcef55..d33df2e 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2156,6 +2156,7 @@ static void scsi_destroy(SCSIDevice *dev) scsi_device_purge_requests(&s->qdev, SENSE_CODE(NO_SENSE)); blockdev_mark_auto_del(s->qdev.conf.bs); + remove_boot_device_path(s->qdev.conf.bootindex); } static void scsi_disk_resize_cb(void *opaque) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 3733d2c..d387f3e 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -390,6 +390,7 @@ static void scsi_destroy(SCSIDevice *s) { scsi_device_purge_requests(s, SENSE_CODE(NO_SENSE)); blockdev_mark_auto_del(s->conf.bs); + remove_boot_device_path(s->conf.bootindex); } static int scsi_generic_initfn(SCSIDevice *s) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index ba5c7f8..2510e3b 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -193,6 +193,7 @@ void rtc_change_mon_event(struct tm *tm); void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix); +void remove_boot_device_path(int32_t bootindex); char *get_boot_devices_list(size_t *size, bool ignore_suffixes); DeviceState *get_boot_device(uint32_t position); diff --git a/vl.c b/vl.c index 709d8cd..f31d008 100644 --- a/vl.c +++ b/vl.c @@ -1189,6 +1189,21 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev, QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); } +void remove_boot_device_path(int32_t bootindex) +{ + FWBootEntry *node, *next_node; + + if (bootindex == -1) { + return; + } + + QTAILQ_FOREACH_SAFE(node, &fw_boot_order, link, next_node) + if (node->bootindex == bootindex) { + QTAILQ_REMOVE(&fw_boot_order, node, link); + return; + } +} + DeviceState *get_boot_device(uint32_t position) { uint32_t counter = 0;