diff mbox

[v2,37/36] qdev: device_del: search for to be unplugged device in 'peripheral' container

Message ID 1412244525-7153-1-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov Oct. 2, 2014, 10:08 a.m. UTC
device_add puts every device with 'id' inside of 'peripheral'
container using id's value as the last component name.
Use it by replacing recursive search on sysbus with path
lookup in 'peripheral' container, which could handle both
BUS and BUS-less device cases.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 qdev-monitor.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Zhu Guihua Oct. 7, 2014, 11:59 a.m. UTC | #1
On Thu, 2014-10-02 at 10:08 +0000, Igor Mammedov wrote:
> device_add puts every device with 'id' inside of 'peripheral'
> container using id's value as the last component name.
> Use it by replacing recursive search on sysbus with path
> lookup in 'peripheral' container, which could handle both
> BUS and BUS-less device cases.
> 

If I want to delete device without id inside of 'peripheral-anon'
container, the command 'device_del' does not work. 
My suggestion is deleting device by the last component name, is this
feasiable?
Thanks.

Zhu

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  qdev-monitor.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index c721451..754437b 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -686,15 +686,20 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
>  
>  void qmp_device_del(const char *id, Error **errp)
>  {
> -    DeviceState *dev;
> +    Object *obj;
> +    char *root_path = object_get_canonical_path(qdev_get_peripheral());
> +    char *path = g_strdup_printf("%s/%s", root_path, id);
>  
> -    dev = qdev_find_recursive(sysbus_get_default(), id);
> -    if (!dev) {
> +    g_free(root_path);
> +    obj = object_resolve_path_type(path, TYPE_DEVICE, NULL);
> +    g_free(path);
> +
> +    if (!obj) {
>          error_set(errp, QERR_DEVICE_NOT_FOUND, id);
>          return;
>      }
>  
> -    qdev_unplug(dev, errp);
> +    qdev_unplug(DEVICE(obj), errp);
>  }
>  
>  void qdev_machine_init(void)
Igor Mammedov Oct. 7, 2014, 12:10 p.m. UTC | #2
On Tue, 7 Oct 2014 19:59:51 +0800
Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:

> On Thu, 2014-10-02 at 10:08 +0000, Igor Mammedov wrote:
> > device_add puts every device with 'id' inside of 'peripheral'
> > container using id's value as the last component name.
> > Use it by replacing recursive search on sysbus with path
> > lookup in 'peripheral' container, which could handle both
> > BUS and BUS-less device cases.
> > 
> 
> If I want to delete device without id inside of 'peripheral-anon'
> container, the command 'device_del' does not work. 
> My suggestion is deleting device by the last component name, is this
> feasiable?
So far device_del was designed to work only with id-ed devices.

What's a use-case for unplugging unnamed device from peripheral-anon?

> Thanks.
> 
> Zhu
> 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  qdev-monitor.c | 13 +++++++++----
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> > 
> > diff --git a/qdev-monitor.c b/qdev-monitor.c
> > index c721451..754437b 100644
> > --- a/qdev-monitor.c
> > +++ b/qdev-monitor.c
> > @@ -686,15 +686,20 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
> >  
> >  void qmp_device_del(const char *id, Error **errp)
> >  {
> > -    DeviceState *dev;
> > +    Object *obj;
> > +    char *root_path = object_get_canonical_path(qdev_get_peripheral());
> > +    char *path = g_strdup_printf("%s/%s", root_path, id);
> >  
> > -    dev = qdev_find_recursive(sysbus_get_default(), id);
> > -    if (!dev) {
> > +    g_free(root_path);
> > +    obj = object_resolve_path_type(path, TYPE_DEVICE, NULL);
> > +    g_free(path);
> > +
> > +    if (!obj) {
> >          error_set(errp, QERR_DEVICE_NOT_FOUND, id);
> >          return;
> >      }
> >  
> > -    qdev_unplug(dev, errp);
> > +    qdev_unplug(DEVICE(obj), errp);
> >  }
> >  
> >  void qdev_machine_init(void)
> 
>
Andreas Färber Oct. 7, 2014, 1:23 p.m. UTC | #3
Am 07.10.2014 um 14:10 schrieb Igor Mammedov:
> On Tue, 7 Oct 2014 19:59:51 +0800
> Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:
> 
>> On Thu, 2014-10-02 at 10:08 +0000, Igor Mammedov wrote:
>>> device_add puts every device with 'id' inside of 'peripheral'
>>> container using id's value as the last component name.
>>> Use it by replacing recursive search on sysbus with path
>>> lookup in 'peripheral' container, which could handle both
>>> BUS and BUS-less device cases.
>>>
>>
>> If I want to delete device without id inside of 'peripheral-anon'
>> container, the command 'device_del' does not work. 
>> My suggestion is deleting device by the last component name, is this
>> feasiable?
> So far device_del was designed to work only with id-ed devices.
> 
> What's a use-case for unplugging unnamed device from peripheral-anon?

I can think of use cases where you may want to balloon memory or CPUs.

But that seems orthogonal to this series.

Regards,
Andreas
Igor Mammedov Oct. 7, 2014, 1:53 p.m. UTC | #4
On Tue, 07 Oct 2014 15:23:45 +0200
Andreas Färber <afaerber@suse.de> wrote:

> Am 07.10.2014 um 14:10 schrieb Igor Mammedov:
> > On Tue, 7 Oct 2014 19:59:51 +0800
> > Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:
> > 
> >> On Thu, 2014-10-02 at 10:08 +0000, Igor Mammedov wrote:
> >>> device_add puts every device with 'id' inside of 'peripheral'
> >>> container using id's value as the last component name.
> >>> Use it by replacing recursive search on sysbus with path
> >>> lookup in 'peripheral' container, which could handle both
> >>> BUS and BUS-less device cases.
> >>>
> >>
> >> If I want to delete device without id inside of 'peripheral-anon'
> >> container, the command 'device_del' does not work. 
> >> My suggestion is deleting device by the last component name, is this
> >> feasiable?
> > So far device_del was designed to work only with id-ed devices.
> > 
> > What's a use-case for unplugging unnamed device from peripheral-anon?
> 
> I can think of use cases where you may want to balloon memory or CPUs.
yep currently initial CPUs are created without dev->id and even without
device_add help.
However if/when it's switched to device_add we can make them use
auto-generated IDs so they would go into peripheral section.
That would let us keep peripheral-anon for devices that shouldn't
be unplugged.

> 
> But that seems orthogonal to this series.
> 
> Regards,
> Andreas
>
Zhu Guihua Oct. 8, 2014, 3:49 a.m. UTC | #5
On Tue, 2014-10-07 at 15:53 +0200, Igor Mammedov wrote:
> On Tue, 07 Oct 2014 15:23:45 +0200
> Andreas Färber <afaerber@suse.de> wrote:
> 
> > Am 07.10.2014 um 14:10 schrieb Igor Mammedov:
> > > On Tue, 7 Oct 2014 19:59:51 +0800
> > > Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:
> > > 
> > >> On Thu, 2014-10-02 at 10:08 +0000, Igor Mammedov wrote:
> > >>> device_add puts every device with 'id' inside of 'peripheral'
> > >>> container using id's value as the last component name.
> > >>> Use it by replacing recursive search on sysbus with path
> > >>> lookup in 'peripheral' container, which could handle both
> > >>> BUS and BUS-less device cases.
> > >>>
> > >>
> > >> If I want to delete device without id inside of 'peripheral-anon'
> > >> container, the command 'device_del' does not work. 
> > >> My suggestion is deleting device by the last component name, is this
> > >> feasiable?
> > > So far device_del was designed to work only with id-ed devices.
> > > 
> > > What's a use-case for unplugging unnamed device from peripheral-anon?
> > 
> > I can think of use cases where you may want to balloon memory or CPUs.
> yep currently initial CPUs are created without dev->id and even without
> device_add help.
> However if/when it's switched to device_add we can make them use
> auto-generated IDs so they would go into peripheral section.
> That would let us keep peripheral-anon for devices that shouldn't
> be unplugged.

when device_add pc-dimm, only 'memdev' property is necessary, but the
'id' property is optional. 

So I execute the command as followings:
object_add memory-backend-ram,id=ram0,size=128M
device_add pc-dimm,memdev=ram0

Now it is impossible to delete the pc-dimm, because it has no id, and it
is inside of 'peripheral-anon' container. 

Regards,
Zhu

> 
> > 
> > But that seems orthogonal to this series.
> > 
> > Regards,
> > Andreas
> > 
>
Paolo Bonzini Oct. 8, 2014, 8:01 a.m. UTC | #6
Il 08/10/2014 05:49, Zhu Guihua ha scritto:
> when device_add pc-dimm, only 'memdev' property is necessary, but the
> 'id' property is optional. 
> 
> So I execute the command as followings:
> object_add memory-backend-ram,id=ram0,size=128M
> device_add pc-dimm,memdev=ram0
> 
> Now it is impossible to delete the pc-dimm, because it has no id, and it
> is inside of 'peripheral-anon' container. 

Sure; but that was an explicit choice when you issued device_add.

Paolo
Zhu Guihua Oct. 9, 2014, 1:50 a.m. UTC | #7
On Wed, 2014-10-08 at 10:01 +0200, Paolo Bonzini wrote:
> Il 08/10/2014 05:49, Zhu Guihua ha scritto:
> > when device_add pc-dimm, only 'memdev' property is necessary, but the
> > 'id' property is optional. 
> > 
> > So I execute the command as followings:
> > object_add memory-backend-ram,id=ram0,size=128M
> > device_add pc-dimm,memdev=ram0
> > 
> > Now it is impossible to delete the pc-dimm, because it has no id, and it
> > is inside of 'peripheral-anon' container. 
> 
> Sure; but that was an explicit choice when you issued device_add.

Thanks for your patient explanation。
And I think it is better to make memory-devices without dev->id use
auto-generated IDs.

Regards,
Zhu
> 
> Paolo
Markus Armbruster Oct. 9, 2014, 6:21 a.m. UTC | #8
Zhu Guihua <zhugh.fnst@cn.fujitsu.com> writes:

> On Wed, 2014-10-08 at 10:01 +0200, Paolo Bonzini wrote:
>> Il 08/10/2014 05:49, Zhu Guihua ha scritto:
>> > when device_add pc-dimm, only 'memdev' property is necessary, but the
>> > 'id' property is optional. 
>> > 
>> > So I execute the command as followings:
>> > object_add memory-backend-ram,id=ram0,size=128M
>> > device_add pc-dimm,memdev=ram0
>> > 
>> > Now it is impossible to delete the pc-dimm, because it has no id, and it
>> > is inside of 'peripheral-anon' container. 
>> 
>> Sure; but that was an explicit choice when you issued device_add.
>
> Thanks for your patient explanation。
> And I think it is better to make memory-devices without dev->id use
> auto-generated IDs.

Auto-generated IDs have been discussed and rejected several times.  At
the very least, clashes with user-specified IDs must be impossible.
diff mbox

Patch

diff --git a/qdev-monitor.c b/qdev-monitor.c
index c721451..754437b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -686,15 +686,20 @@  int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
 void qmp_device_del(const char *id, Error **errp)
 {
-    DeviceState *dev;
+    Object *obj;
+    char *root_path = object_get_canonical_path(qdev_get_peripheral());
+    char *path = g_strdup_printf("%s/%s", root_path, id);
 
-    dev = qdev_find_recursive(sysbus_get_default(), id);
-    if (!dev) {
+    g_free(root_path);
+    obj = object_resolve_path_type(path, TYPE_DEVICE, NULL);
+    g_free(path);
+
+    if (!obj) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, id);
         return;
     }
 
-    qdev_unplug(dev, errp);
+    qdev_unplug(DEVICE(obj), errp);
 }
 
 void qdev_machine_init(void)