Message ID | 20181025085256.20522-2-kraxel@redhat.com |
---|---|
State | New |
Headers | show |
Series | RfC: add support for deprecated devices. | expand |
+-- On Thu, 25 Oct 2018, Gerd Hoffmann wrote --+ | Simliar to deprecated machine types. | Print a warning when creating a deprecated device. | Add deprecation notice to -device help. | | TODO: add to intospection. s/intospection/introspection ..? | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | index 046d8f1..3b27a74 100644 | --- a/hw/core/qdev.c | +++ b/hw/core/qdev.c | @@ -133,11 +133,18 @@ DeviceState *qdev_create(BusState *bus, const char *name) | | DeviceState *qdev_try_create(BusState *bus, const char *type) | { | + DeviceClass *dc; | DeviceState *dev; | | - if (object_class_by_name(type) == NULL) { | + dc = DEVICE_CLASS(object_class_by_name(type)); | + if (dc == NULL) { | return NULL; | } | + if (dc->deprecation_reason) { | + warn_report("device %s is deprecated (%s)", | + type, dc->deprecation_reason); | + } | + | dev = DEVICE(object_new(type)); | if (!dev) { | return NULL; | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | index a24d0dd..a352eaa 100644 | --- a/include/hw/qdev-core.h | +++ b/include/hw/qdev-core.h | @@ -105,6 +105,7 @@ typedef struct DeviceClass { | */ | bool user_creatable; | bool hotpluggable; | + const char *deprecation_reason; | | /* callbacks */ | DeviceReset reset; | diff --git a/qdev-monitor.c b/qdev-monitor.c | index 802c18a..bbba2bc 100644 | --- a/qdev-monitor.c | +++ b/qdev-monitor.c | @@ -128,6 +128,9 @@ static void qdev_print_devinfo(DeviceClass *dc) | if (!dc->user_creatable) { | out_printf(", no-user"); | } | + if (!dc->deprecation_reason) { | + out_printf(", deprecated"); | + } | out_printf("\n"); | } | | @@ -579,6 +582,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) | if (!dc) { | return NULL; | } | + if (dc->deprecation_reason) { | + warn_report("device %s is deprecated (%s)", | + driver, dc->deprecation_reason); | + } | | /* find bus */ | path = qemu_opt_get(opts, "bus"); | Looks good. Should 'deprecation_reason' be listed in qdev_device_help()? Thank you. -- Prasad J Pandit / Red Hat Product Security Team 47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
Hi Gerd, On 25/10/18 10:52, Gerd Hoffmann wrote: > Simliar to deprecated machine types. "Similar" > Print a warning when creating a deprecated device. > Add deprecation notice to -device help. > > TODO: add to intospection. "introspection" Do we want the TODO in the git history? > > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> > --- > hw/core/qdev.c | 9 ++++++++- > include/hw/qdev-core.h | 1 + > qdev-monitor.c | 7 +++++++ > 3 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 046d8f1..3b27a74 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -133,11 +133,18 @@ DeviceState *qdev_create(BusState *bus, const char *name) > > DeviceState *qdev_try_create(BusState *bus, const char *type) > { > + DeviceClass *dc; > DeviceState *dev; > > - if (object_class_by_name(type) == NULL) { > + dc = DEVICE_CLASS(object_class_by_name(type)); > + if (dc == NULL) { > return NULL; > } > + if (dc->deprecation_reason) { > + warn_report("device %s is deprecated (%s)", > + type, dc->deprecation_reason); > + } > + > dev = DEVICE(object_new(type)); > if (!dev) { > return NULL; > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index a24d0dd..a352eaa 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -105,6 +105,7 @@ typedef struct DeviceClass { > */ > bool user_creatable; > bool hotpluggable; > + const char *deprecation_reason; > > /* callbacks */ > DeviceReset reset; > diff --git a/qdev-monitor.c b/qdev-monitor.c > index 802c18a..bbba2bc 100644 > --- a/qdev-monitor.c > +++ b/qdev-monitor.c > @@ -128,6 +128,9 @@ static void qdev_print_devinfo(DeviceClass *dc) > if (!dc->user_creatable) { > out_printf(", no-user"); > } > + if (!dc->deprecation_reason) { This is the opposite condition: if (dc->deprecation_reason) { out_printf(", deprecated"); With it fixed: Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > + out_printf(", deprecated"); > + } > out_printf("\n"); > } > > @@ -579,6 +582,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) > if (!dc) { > return NULL; > } > + if (dc->deprecation_reason) { > + warn_report("device %s is deprecated (%s)", > + driver, dc->deprecation_reason); > + } > > /* find bus */ > path = qemu_opt_get(opts, "bus"); >
On Thu, Oct 25, 2018 at 01:12:15PM +0200, Philippe Mathieu-Daudé wrote: > Hi Gerd, > > On 25/10/18 10:52, Gerd Hoffmann wrote: > > Simliar to deprecated machine types. > > "Similar" > > > Print a warning when creating a deprecated device. > > Add deprecation notice to -device help. > > > > TODO: add to intospection. > > "introspection" > > Do we want the TODO in the git history? No. It's RfC because of the missing introspection bits ;) cheers, Gerd
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 046d8f1..3b27a74 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -133,11 +133,18 @@ DeviceState *qdev_create(BusState *bus, const char *name) DeviceState *qdev_try_create(BusState *bus, const char *type) { + DeviceClass *dc; DeviceState *dev; - if (object_class_by_name(type) == NULL) { + dc = DEVICE_CLASS(object_class_by_name(type)); + if (dc == NULL) { return NULL; } + if (dc->deprecation_reason) { + warn_report("device %s is deprecated (%s)", + type, dc->deprecation_reason); + } + dev = DEVICE(object_new(type)); if (!dev) { return NULL; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index a24d0dd..a352eaa 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -105,6 +105,7 @@ typedef struct DeviceClass { */ bool user_creatable; bool hotpluggable; + const char *deprecation_reason; /* callbacks */ DeviceReset reset; diff --git a/qdev-monitor.c b/qdev-monitor.c index 802c18a..bbba2bc 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -128,6 +128,9 @@ static void qdev_print_devinfo(DeviceClass *dc) if (!dc->user_creatable) { out_printf(", no-user"); } + if (!dc->deprecation_reason) { + out_printf(", deprecated"); + } out_printf("\n"); } @@ -579,6 +582,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) if (!dc) { return NULL; } + if (dc->deprecation_reason) { + warn_report("device %s is deprecated (%s)", + driver, dc->deprecation_reason); + } /* find bus */ path = qemu_opt_get(opts, "bus");
Simliar to deprecated machine types. Print a warning when creating a deprecated device. Add deprecation notice to -device help. TODO: add to intospection. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/core/qdev.c | 9 ++++++++- include/hw/qdev-core.h | 1 + qdev-monitor.c | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-)