From patchwork Mon Jan 9 17:02:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9505609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 537FA606E1 for ; Mon, 9 Jan 2017 17:19:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D7EB27569 for ; Mon, 9 Jan 2017 17:19:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 303A62823D; Mon, 9 Jan 2017 17:19:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD2FC27569 for ; Mon, 9 Jan 2017 17:19:38 +0000 (UTC) Received: from localhost ([::1]:41467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQdbe-0006gx-10 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Jan 2017 12:19:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQdLT-0000fp-RC for qemu-devel@nongnu.org; Mon, 09 Jan 2017 12:02:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cQdLR-0005V8-7l for qemu-devel@nongnu.org; Mon, 09 Jan 2017 12:02:55 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:32890) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cQdLR-0005Uz-2z for qemu-devel@nongnu.org; Mon, 09 Jan 2017 12:02:53 -0500 Received: by mail-pf0-x243.google.com with SMTP id 127so24926160pfg.0 for ; Mon, 09 Jan 2017 09:02:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=laLhOCdLzTkmQ9RGnaogRjZJq9TLUueIwyT7X3Bvhsg=; b=fU6S5tIOCCWWxPFL3MsICxbrf5JffqHwmxC1abLj/q8CyXTxU/fqRSsEPNnkPfyS4u j56zR52bfyAoxt0oBxN1BBgMuPDvq1f4w1PAZ1hAGbnf5GZuUYtI+3gXBfubaBhU7Mqs UO3mLCLntQI0Afy9U8OH2bFvPhqQKRKIhzxY/R+GhdhCmbfHgA+Nm7lpkmYiVZNb+JjR jVfCcRxXXsVe8kydOg4oZB4MrcXXKxh4VpkEvM9z0KOSmlx/QhwJVZ9AWVVs+VfPw+8f puWYz0vs7CNGeUiXxfwtOVEgWLOwpLiXMOpUf76StL9gTg3mWoRVdxKZ3OnD6Tjy5bX7 gehQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=laLhOCdLzTkmQ9RGnaogRjZJq9TLUueIwyT7X3Bvhsg=; b=FG284SBJh6/WyJOQIJ/KUq8Ll1k6m7YIP/67ybO4msPJHeuCWTaUu9Qy0f/YoNSTYV BGkAZAXzVAXAdiy6diIAO2/k/837cpfTnBUWB/9Ot7WKenFWCIN/lFHVgsfYVdomxbJk FPdbkikp8bZafPvutWQ7kJLnVTPVK0Ci2faMy6iYzfE5dFvBV5ni455byiSqVMKKkDIG aTlL6CRRru88PJZPZH+CF03BPXBNjSlOxIINT6xfVNbRCKrbvBwPgCwANLp5UX5s46vt kIoTWyH9xpnZuPMoJrKQnQfKyQaGvL/P2Hmgaz48Lz1UbB025K92tbmExcwrZkQMXOlM BxJg== X-Gm-Message-State: AIkVDXJY5v1IQm/02Z1YZh0ahhMG6k18xAIoeN8uZqZNsEtTJuUxSqsTnuceIC9RVXN5xg== X-Received: by 10.84.233.132 with SMTP id l4mr11779668plk.15.1483981372007; Mon, 09 Jan 2017 09:02:52 -0800 (PST) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id 72sm180907325pfw.37.2017.01.09.09.02.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jan 2017 09:02:51 -0800 (PST) From: Ashijeet Acharya To: dgilbert@redhat.com Date: Mon, 9 Jan 2017 22:32:46 +0530 Message-Id: <1483981368-9965-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1483981368-9965-1-git-send-email-ashijeetacharya@gmail.com> References: <1483981368-9965-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v4 2/4] migration: Allow "device add" options to only add migratable devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, qemu-devel@nongnu.org, mst@redhat.com, armbru@redhat.com, groug@kaod.org, aneesh.kumar@linux.vnet.ibm.com, Ashijeet Acharya , marcandre.lureau@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce checks for the unmigratable flag in the VMStateDescription structs of respective devices when user attempts to add them. If the "--only-migratable" was specified, all unmigratable devices will rightly fail to add. This feature is made compatible for both "-device" and "-usbdevice" command line options and covers their hmp and qmp counterparts as well. Signed-off-by: Ashijeet Acharya --- hw/usb/bus.c | 18 ++++++++++++++++++ qdev-monitor.c | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 25913ad..3d26103 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -8,6 +8,7 @@ #include "monitor/monitor.h" #include "trace.h" #include "qemu/cutils.h" +#include "migration/migration.h" static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); @@ -686,6 +687,8 @@ USBDevice *usbdevice_create(const char *cmdline) const char *params; int len; USBDevice *dev; + ObjectClass *klass; + DeviceClass *dc; params = strchr(cmdline,':'); if (params) { @@ -720,6 +723,21 @@ USBDevice *usbdevice_create(const char *cmdline) return NULL; } + klass = object_class_by_name(f->name); + if (klass == NULL) { + return NULL; + } + + dc = DEVICE_CLASS(klass); + + if (only_migratable) { + if (dc->vmsd->unmigratable) { + error_report("Device %s is not migratable, but --only-migratable " + "was specified", f->name); + return NULL; + } + } + if (f->usbdevice_init) { dev = f->usbdevice_init(bus, params); } else { diff --git a/qdev-monitor.c b/qdev-monitor.c index c73410c..81d01df 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -29,6 +29,7 @@ #include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" +#include "migration/migration.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -577,6 +578,14 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) return NULL; } + if (only_migratable) { + if (dc->vmsd->unmigratable) { + error_setg(errp, "Device %s is not migratable, but " + "--only-migratable was specified", driver); + return NULL; + } + } + /* find bus */ path = qemu_opt_get(opts, "bus"); if (path != NULL) {