diff mbox series

nvme: expose 'bootindex' property

Message ID 20210322082444.12916-1-j@getutm.app (mailing list archive)
State New, archived
Headers show
Series nvme: expose 'bootindex' property | expand

Commit Message

Joelle van Dyne March 22, 2021, 8:24 a.m. UTC
The check for `n->namespace.blkconf.blk` always fails because
this is in the initialization function.

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 hw/block/nvme.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé March 22, 2021, 9:58 a.m. UTC | #1
On 3/22/21 9:24 AM, Joelle van Dyne wrote:
> The check for `n->namespace.blkconf.blk` always fails because
> this is in the initialization function.

This usually mean the code depends to some state only available
during the QOM 'realization' step, so this code should be in
nvme_realize(). Maybe in this case we don't need it there and
can add the property regardless a block drive is provided, I
haven't checked.

> 
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  hw/block/nvme.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 6842b01ab5..42605fc55d 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -6330,11 +6330,9 @@ static void nvme_instance_init(Object *obj)
>  {
>      NvmeCtrl *n = NVME(obj);
>  
> -    if (n->namespace.blkconf.blk) {
> -        device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> -                                      "bootindex", "/namespace@1,0",
> -                                      DEVICE(obj));
> -    }
> +    device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> +                                  "bootindex", "/namespace@1,0",
> +                                  DEVICE(obj));
>  
>      object_property_add(obj, "smart_critical_warning", "uint8",
>                          nvme_get_smart_warning,
>
Klaus Jensen March 22, 2021, 12:37 p.m. UTC | #2
On Mar 22 10:58, Philippe Mathieu-Daudé wrote:
> On 3/22/21 9:24 AM, Joelle van Dyne wrote:
> > The check for `n->namespace.blkconf.blk` always fails because
> > this is in the initialization function.
> 
> This usually mean the code depends to some state only available
> during the QOM 'realization' step, so this code should be in
> nvme_realize(). Maybe in this case we don't need it there and
> can add the property regardless a block drive is provided, I
> haven't checked.
> 

If we defer to realization, it won't be available as a parameter on the
command line, but as far as I can test, adding it unconditionally
doesn't break anything when there is no drive attached to the controller
device.

> > 
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >  hw/block/nvme.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> > index 6842b01ab5..42605fc55d 100644
> > --- a/hw/block/nvme.c
> > +++ b/hw/block/nvme.c
> > @@ -6330,11 +6330,9 @@ static void nvme_instance_init(Object *obj)
> >  {
> >      NvmeCtrl *n = NVME(obj);
> >  
> > -    if (n->namespace.blkconf.blk) {
> > -        device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> > -                                      "bootindex", "/namespace@1,0",
> > -                                      DEVICE(obj));
> > -    }
> > +    device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> > +                                  "bootindex", "/namespace@1,0",
> > +                                  DEVICE(obj));
> >  
> >      object_property_add(obj, "smart_critical_warning", "uint8",
> >                          nvme_get_smart_warning,
> > 
> 
>
Philippe Mathieu-Daudé March 22, 2021, 1:10 p.m. UTC | #3
On 3/22/21 1:37 PM, Klaus Jensen wrote:
> On Mar 22 10:58, Philippe Mathieu-Daudé wrote:
>> On 3/22/21 9:24 AM, Joelle van Dyne wrote:
>>> The check for `n->namespace.blkconf.blk` always fails because
>>> this is in the initialization function.
>>
>> This usually mean the code depends to some state only available
>> during the QOM 'realization' step, so this code should be in
>> nvme_realize(). Maybe in this case we don't need it there and
>> can add the property regardless a block drive is provided, I
>> haven't checked.
>>
> 
> If we defer to realization, it won't be available as a parameter on the
> command line, but as far as I can test, adding it unconditionally
> doesn't break anything when there is no drive attached to the controller
> device.

Patch is good then :)
Klaus Jensen March 22, 2021, 1:19 p.m. UTC | #4
On Mar 22 14:10, Philippe Mathieu-Daudé wrote:
> On 3/22/21 1:37 PM, Klaus Jensen wrote:
> > On Mar 22 10:58, Philippe Mathieu-Daudé wrote:
> >> On 3/22/21 9:24 AM, Joelle van Dyne wrote:
> >>> The check for `n->namespace.blkconf.blk` always fails because
> >>> this is in the initialization function.
> >>
> >> This usually mean the code depends to some state only available
> >> during the QOM 'realization' step, so this code should be in
> >> nvme_realize(). Maybe in this case we don't need it there and
> >> can add the property regardless a block drive is provided, I
> >> haven't checked.
> >>
> > 
> > If we defer to realization, it won't be available as a parameter on the
> > command line, but as far as I can test, adding it unconditionally
> > doesn't break anything when there is no drive attached to the controller
> > device.
> 
> Patch is good then :)
> 

Agreed :)

Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Klaus Jensen March 30, 2021, 6:10 p.m. UTC | #5
On Mar 22 01:24, Joelle van Dyne wrote:
> The check for `n->namespace.blkconf.blk` always fails because
> this is in the initialization function.
> 
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  hw/block/nvme.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 6842b01ab5..42605fc55d 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -6330,11 +6330,9 @@ static void nvme_instance_init(Object *obj)
>  {
>      NvmeCtrl *n = NVME(obj);
>  
> -    if (n->namespace.blkconf.blk) {
> -        device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> -                                      "bootindex", "/namespace@1,0",
> -                                      DEVICE(obj));
> -    }
> +    device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
> +                                  "bootindex", "/namespace@1,0",
> +                                  DEVICE(obj));
>  
>      object_property_add(obj, "smart_critical_warning", "uint8",
>                          nvme_get_smart_warning,
> -- 
> 2.28.0
> 

Applied on nvme-fixes, thanks!
diff mbox series

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 6842b01ab5..42605fc55d 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -6330,11 +6330,9 @@  static void nvme_instance_init(Object *obj)
 {
     NvmeCtrl *n = NVME(obj);
 
-    if (n->namespace.blkconf.blk) {
-        device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
-                                      "bootindex", "/namespace@1,0",
-                                      DEVICE(obj));
-    }
+    device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex,
+                                  "bootindex", "/namespace@1,0",
+                                  DEVICE(obj));
 
     object_property_add(obj, "smart_critical_warning", "uint8",
                         nvme_get_smart_warning,