* [PATCH] block: rbd: switch to dynamic root device
@ 2026-04-24 10:39 Johan Hovold
2026-04-24 18:48 ` Viacheslav Dubeyko
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2026-04-24 10:39 UTC (permalink / raw)
To: Ilya Dryomov
Cc: Dongsheng Yang, Jens Axboe, ceph-devel, linux-block, linux-kernel,
Johan Hovold
Driver core expects devices to be dynamically allocated and will, for
example, complain loudly when no release function has been provided.
Use root_device_register() to allocate and register the root device
instead of open coding using a static device.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/block/rbd.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index e7da06200c1e..ffab1b4e7c25 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -580,14 +580,7 @@ static const struct bus_type rbd_bus_type = {
.bus_groups = rbd_bus_groups,
};
-static void rbd_root_dev_release(struct device *dev)
-{
-}
-
-static struct device rbd_root_dev = {
- .init_name = "rbd",
- .release = rbd_root_dev_release,
-};
+static struct device *rbd_root_dev;
static __printf(2, 3)
void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)
@@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec)
rbd_dev->dev.bus = &rbd_bus_type;
rbd_dev->dev.type = &rbd_device_type;
- rbd_dev->dev.parent = &rbd_root_dev;
+ rbd_dev->dev.parent = rbd_root_dev;
device_initialize(&rbd_dev->dev);
return rbd_dev;
@@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void)
{
int ret;
- ret = device_register(&rbd_root_dev);
- if (ret < 0) {
- put_device(&rbd_root_dev);
- return ret;
- }
+ rbd_root_dev = root_device_register("rbd");
+ if (IS_ERR(rbd_root_dev))
+ return PTR_ERR(rbd_root_dev);
ret = bus_register(&rbd_bus_type);
if (ret < 0)
- device_unregister(&rbd_root_dev);
+ root_device_unregister(rbd_root_dev);
return ret;
}
@@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void)
static void __exit rbd_sysfs_cleanup(void)
{
bus_unregister(&rbd_bus_type);
- device_unregister(&rbd_root_dev);
+ root_device_unregister(rbd_root_dev);
}
static int __init rbd_slab_init(void)
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] block: rbd: switch to dynamic root device
2026-04-24 10:39 [PATCH] block: rbd: switch to dynamic root device Johan Hovold
@ 2026-04-24 18:48 ` Viacheslav Dubeyko
2026-04-27 15:21 ` Johan Hovold
0 siblings, 1 reply; 3+ messages in thread
From: Viacheslav Dubeyko @ 2026-04-24 18:48 UTC (permalink / raw)
To: idryomov@gmail.com, johan@kernel.org
Cc: dongsheng.yang@linux.dev, ceph-devel@vger.kernel.org,
axboe@kernel.dk, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org
On Fri, 2026-04-24 at 12:39 +0200, Johan Hovold wrote:
> Driver core expects devices to be dynamically allocated and will, for
> example, complain loudly when no release function has been provided.
>
> Use root_device_register() to allocate and register the root device
> instead of open coding using a static device.
I think the approach makes sense. Ilya, what do you think? Do we have any
objection?
>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/block/rbd.c | 23 +++++++----------------
> 1 file changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index e7da06200c1e..ffab1b4e7c25 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -580,14 +580,7 @@ static const struct bus_type rbd_bus_type = {
> .bus_groups = rbd_bus_groups,
> };
>
> -static void rbd_root_dev_release(struct device *dev)
> -{
> -}
> -
> -static struct device rbd_root_dev = {
> - .init_name = "rbd",
> - .release = rbd_root_dev_release,
> -};
> +static struct device *rbd_root_dev;
>
> static __printf(2, 3)
> void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)
> @@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec)
>
> rbd_dev->dev.bus = &rbd_bus_type;
> rbd_dev->dev.type = &rbd_device_type;
> - rbd_dev->dev.parent = &rbd_root_dev;
> + rbd_dev->dev.parent = rbd_root_dev;
> device_initialize(&rbd_dev->dev);
>
> return rbd_dev;
> @@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void)
> {
> int ret;
>
> - ret = device_register(&rbd_root_dev);
> - if (ret < 0) {
> - put_device(&rbd_root_dev);
> - return ret;
> - }
> + rbd_root_dev = root_device_register("rbd");
> + if (IS_ERR(rbd_root_dev))
> + return PTR_ERR(rbd_root_dev);
>
> ret = bus_register(&rbd_bus_type);
> if (ret < 0)
> - device_unregister(&rbd_root_dev);
> + root_device_unregister(rbd_root_dev);
I think we need to assign NULL here:
rbd_root_dev = NULL;
>
> return ret;
> }
> @@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void)
> static void __exit rbd_sysfs_cleanup(void)
> {
> bus_unregister(&rbd_bus_type);
> - device_unregister(&rbd_root_dev);
> + root_device_unregister(rbd_root_dev);
The same issue here:
rbd_root_dev = NULL;
Thanks,
Slava.
> }
>
> static int __init rbd_slab_init(void)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] block: rbd: switch to dynamic root device
2026-04-24 18:48 ` Viacheslav Dubeyko
@ 2026-04-27 15:21 ` Johan Hovold
0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-04-27 15:21 UTC (permalink / raw)
To: Viacheslav Dubeyko
Cc: idryomov@gmail.com, dongsheng.yang@linux.dev,
ceph-devel@vger.kernel.org, axboe@kernel.dk,
linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
On Fri, Apr 24, 2026 at 06:48:32PM +0000, Viacheslav Dubeyko wrote:
> On Fri, 2026-04-24 at 12:39 +0200, Johan Hovold wrote:
> > Driver core expects devices to be dynamically allocated and will, for
> > example, complain loudly when no release function has been provided.
> >
> > Use root_device_register() to allocate and register the root device
> > instead of open coding using a static device.
> > @@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec)
> >
> > rbd_dev->dev.bus = &rbd_bus_type;
> > rbd_dev->dev.type = &rbd_device_type;
> > - rbd_dev->dev.parent = &rbd_root_dev;
> > + rbd_dev->dev.parent = rbd_root_dev;
> > device_initialize(&rbd_dev->dev);
> >
> > return rbd_dev;
> > @@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void)
> > {
> > int ret;
> >
> > - ret = device_register(&rbd_root_dev);
> > - if (ret < 0) {
> > - put_device(&rbd_root_dev);
> > - return ret;
> > - }
> > + rbd_root_dev = root_device_register("rbd");
> > + if (IS_ERR(rbd_root_dev))
> > + return PTR_ERR(rbd_root_dev);
> >
> > ret = bus_register(&rbd_bus_type);
> > if (ret < 0)
> > - device_unregister(&rbd_root_dev);
> > + root_device_unregister(rbd_root_dev);
>
> I think we need to assign NULL here:
>
> rbd_root_dev = NULL;
From what I can tell these devices are only created from the bus sysfs
attribute so this pointer will not be accessed if bus registration
fails and there is no need to clear it (or add a sanity check to
__rbd_dev_create()).
> > return ret;
> > }
> > @@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void)
> > static void __exit rbd_sysfs_cleanup(void)
> > {
> > bus_unregister(&rbd_bus_type);
> > - device_unregister(&rbd_root_dev);
> > + root_device_unregister(rbd_root_dev);
>
> The same issue here:
>
> rbd_root_dev = NULL;
So this is not needed either.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-27 15:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24 10:39 [PATCH] block: rbd: switch to dynamic root device Johan Hovold
2026-04-24 18:48 ` Viacheslav Dubeyko
2026-04-27 15:21 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox