* Re: [PATCH 1/4] driver core: add root_device_register() [not found] ` <1229012216-4211-1-git-send-email-markmc@redhat.com> @ 2008-12-11 16:56 ` Cornelia Huck [not found] ` <1229012216-4211-2-git-send-email-markmc@redhat.com> [not found] ` <20081211175604.511fc6ae@gondolin> 2 siblings, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-11 16:56 UTC (permalink / raw) Cc: Mark McLoughlin, Anthony Liguori, Greg KH, Kay Sievers, linux-kernel, virtualization On Thu, 11 Dec 2008 16:16:53 +0000, Mark McLoughlin <markmc@redhat.com> wrote: > Add support for allocating root device objects which group > device objects under /sys/devices directories. > > Also add a sysfs 'module' symlink which points to the owner > of the root device object. This will be used in virtio to > allow userspace to determine which virtio bus implementation > a given device is associated with. I was just hacking up a similar patch :) > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> > --- > drivers/base/core.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/device.h | 11 ++++++ > 2 files changed, 99 insertions(+), 0 deletions(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 8c2cc26..db160a2 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1196,6 +1196,94 @@ EXPORT_SYMBOL_GPL(put_device); > EXPORT_SYMBOL_GPL(device_create_file); > EXPORT_SYMBOL_GPL(device_remove_file); > > +struct root_device > +{ > + struct device dev; > + struct module *owner; > +}; > + > +static void root_device_release(struct device *dev) > +{ > + struct root_device *root = container_of(dev, struct root_device, dev); > + > + if (root->owner) > + sysfs_remove_link(&root->dev.kobj, "module"); I'd rather remove the link before you unregister. > + > + kfree(root); > +} > + > +/** > + * __root_device_register - allocate and register a root device > + * @name: root device name > + * @owner: owner module of the root device, usually THIS_MODULE > + * > + * This function allocates a root device and registers it > + * using device_register(). In order to free the returned > + * device, use root_device_unregister(). > + * > + * Root devices are dummy devices which allow other devices > + * to be grouped under /sys/devices. Use this function to > + * allocate a root device and then use it as the parent of > + * any device which should appear under /sys/devices/{name} > + * > + * The /sys/devices/{name} directory will also contain a > + * 'module' symlink which points to the @owner directory > + * in sysfs. * Note: You probably want to use root_device_register(). > + */ > +struct device *__root_device_register(const char *name, struct module *owner) > +{ > + struct root_device *root; > + int err = -ENOMEM; > + > + root = kzalloc(sizeof(struct root_device), GFP_KERNEL); > + if (!root) > + return ERR_PTR(err); > + > + err = dev_set_name(&root->dev, name); > + if (err) { > + kfree(root); > + return ERR_PTR(err); > + } > + > + root->dev.release = root_device_release; > + > + err = device_register(&root->dev); > + if (err) { > + put_device(&root->dev); > + return ERR_PTR(err); > + } > + > + if (owner) { > + struct module_kobject *mk = &owner->mkobj; > + > + err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module"); > + if (err) {; Stray ';' > + device_unregister(&root->dev); > + return ERR_PTR(err); > + } > + root->owner = owner; > + } > + > + return &root->dev; > +} > +EXPORT_SYMBOL_GPL(__root_device_register); > + > +/** > + * root_device_unregister - unregister and free a root device > + * @root: device going away. > + * > + * We simply release @root using device_unregister(). If @root > + * has a reference count of one, the device will be freed > + * after it has been unregistered. Otherwise, the structure > + * will stick around until the final reference is dropped > + * using put_device(). I don't think you'll need to explain device handling here. How about this: root_device_unregister - unregister a root device @root: device going away This function unregisters and cleans up a device that was created by root_device_register(). > + */ > +void root_device_unregister(struct device *root) > +{ Clean up the symlink here. > + device_unregister(root); > +} > +EXPORT_SYMBOL_GPL(root_device_unregister); > + > > static void device_create_release(struct device *dev) > { > diff --git a/include/linux/device.h b/include/linux/device.h > index 1a3686d..9e02980 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -483,6 +483,17 @@ extern int device_rename(struct device *dev, char *new_name); > extern int device_move(struct device *dev, struct device *new_parent); > > /* > + * Root device objects for grouping under /sys/devices > + */ > +extern struct device *__root_device_register(const char *name, > + struct module *owner); > +static inline struct device *root_device_register(const char *name) > +{ > + return __root_device_register(name, THIS_MODULE); > +} > +extern void root_device_unregister(struct device *root); > + > +/* > * Manual binding of a device to driver. See drivers/base/bus.c > * for information on use. > */ > -- > 1.5.4.3 > ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <1229012216-4211-2-git-send-email-markmc@redhat.com>]
[parent not found: <1229012216-4211-3-git-send-email-markmc@redhat.com>]
[parent not found: <1229012216-4211-4-git-send-email-markmc@redhat.com>]
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <1229012216-4211-4-git-send-email-markmc@redhat.com> @ 2008-12-11 17:00 ` Cornelia Huck [not found] ` <20081211180025.045b9b4a@gondolin> 1 sibling, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-11 17:00 UTC (permalink / raw) Cc: Mark McLoughlin, Anthony Liguori, Greg KH, Kay Sievers, linux-s390, Heiko Carstens, linux-kernel, virtualization, Martin Schwidefsky (adding cc:s) On Thu, 11 Dec 2008 16:16:56 +0000, Mark McLoughlin <markmc@redhat.com> wrote: > Replace s390_root_dev_register() with root_device_register() etc. Nice, one more special case generalized :) I'll give it a run. > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> > --- > arch/s390/include/asm/s390_rdev.h | 15 ----------- > drivers/s390/Makefile | 2 +- > drivers/s390/block/dcssblk.c | 11 +++---- > drivers/s390/crypto/ap_bus.c | 7 ++--- > drivers/s390/kvm/kvm_virtio.c | 5 +-- > drivers/s390/net/cu3088.c | 7 ++--- > drivers/s390/net/qeth_core_main.c | 7 ++--- > drivers/s390/net/qeth_l2_main.c | 2 - > drivers/s390/net/qeth_l3_main.c | 2 - > drivers/s390/s390_rdev.c | 51 ------------------------------------- > net/iucv/iucv.c | 5 +-- > 11 files changed, 19 insertions(+), 95 deletions(-) > delete mode 100644 arch/s390/include/asm/s390_rdev.h > delete mode 100644 drivers/s390/s390_rdev.c > > diff --git a/arch/s390/include/asm/s390_rdev.h b/arch/s390/include/asm/s390_rdev.h > deleted file mode 100644 > index 6fa2044..0000000 > --- a/arch/s390/include/asm/s390_rdev.h > +++ /dev/null > @@ -1,15 +0,0 @@ > -/* > - * include/asm-s390/ccwdev.h > - * > - * Copyright (C) 2002,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation > - * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> > - * Carsten Otte <cotte@de.ibm.com> > - * > - * Interface for s390 root device > - */ > - > -#ifndef _S390_RDEV_H_ > -#define _S390_RDEV_H_ > -extern struct device *s390_root_dev_register(const char *); > -extern void s390_root_dev_unregister(struct device *); > -#endif /* _S390_RDEV_H_ */ > diff --git a/drivers/s390/Makefile b/drivers/s390/Makefile > index 4f4e7cf..d0eae59 100644 > --- a/drivers/s390/Makefile > +++ b/drivers/s390/Makefile > @@ -4,7 +4,7 @@ > > CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w > > -obj-y += s390mach.o sysinfo.o s390_rdev.o > +obj-y += s390mach.o sysinfo.o > obj-y += cio/ block/ char/ crypto/ net/ scsi/ kvm/ > > drivers-y += drivers/s390/built-in.o > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > index 63f26a1..20fca50 100644 > --- a/drivers/s390/block/dcssblk.c > +++ b/drivers/s390/block/dcssblk.c > @@ -15,7 +15,6 @@ > #include <asm/io.h> > #include <linux/completion.h> > #include <linux/interrupt.h> > -#include <asm/s390_rdev.h> > > //#define DCSSBLK_DEBUG /* Debug messages on/off */ > #define DCSSBLK_NAME "dcssblk" > @@ -951,7 +950,7 @@ dcssblk_check_params(void) > static void __exit > dcssblk_exit(void) > { > - s390_root_dev_unregister(dcssblk_root_dev); > + root_device_unregister(dcssblk_root_dev); > unregister_blkdev(dcssblk_major, DCSSBLK_NAME); > } > > @@ -960,22 +959,22 @@ dcssblk_init(void) > { > int rc; > > - dcssblk_root_dev = s390_root_dev_register("dcssblk"); > + dcssblk_root_dev = root_device_register("dcssblk"); > if (IS_ERR(dcssblk_root_dev)) > return PTR_ERR(dcssblk_root_dev); > rc = device_create_file(dcssblk_root_dev, &dev_attr_add); > if (rc) { > - s390_root_dev_unregister(dcssblk_root_dev); > + root_device_unregister(dcssblk_root_dev); > return rc; > } > rc = device_create_file(dcssblk_root_dev, &dev_attr_remove); > if (rc) { > - s390_root_dev_unregister(dcssblk_root_dev); > + root_device_unregister(dcssblk_root_dev); > return rc; > } > rc = register_blkdev(0, DCSSBLK_NAME); > if (rc < 0) { > - s390_root_dev_unregister(dcssblk_root_dev); > + root_device_unregister(dcssblk_root_dev); > return rc; > } > dcssblk_major = rc; > diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c > index e3fe683..0689c22 100644 > --- a/drivers/s390/crypto/ap_bus.c > +++ b/drivers/s390/crypto/ap_bus.c > @@ -32,7 +32,6 @@ > #include <linux/notifier.h> > #include <linux/kthread.h> > #include <linux/mutex.h> > -#include <asm/s390_rdev.h> > #include <asm/reset.h> > #include <linux/hrtimer.h> > #include <linux/ktime.h> > @@ -1358,7 +1357,7 @@ int __init ap_module_init(void) > } > > /* Create /sys/devices/ap. */ > - ap_root_device = s390_root_dev_register("ap"); > + ap_root_device = root_device_register("ap"); > rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0; > if (rc) > goto out_bus; > @@ -1401,7 +1400,7 @@ out_work: > hrtimer_cancel(&ap_poll_timer); > destroy_workqueue(ap_work_queue); > out_root: > - s390_root_dev_unregister(ap_root_device); > + root_device_unregister(ap_root_device); > out_bus: > while (i--) > bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); > @@ -1432,7 +1431,7 @@ void ap_module_exit(void) > hrtimer_cancel(&ap_poll_timer); > destroy_workqueue(ap_work_queue); > tasklet_kill(&ap_tasklet); > - s390_root_dev_unregister(ap_root_device); > + root_device_unregister(ap_root_device); > while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, > __ap_match_all))) > { > diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c > index c79cf05..db61252 100644 > --- a/drivers/s390/kvm/kvm_virtio.c > +++ b/drivers/s390/kvm/kvm_virtio.c > @@ -24,7 +24,6 @@ > #include <asm/kvm_virtio.h> > #include <asm/setup.h> > #include <asm/s390_ext.h> > -#include <asm/s390_rdev.h> > > #define VIRTIO_SUBCODE_64 0x0D00 > > @@ -335,7 +334,7 @@ static int __init kvm_devices_init(void) > if (!MACHINE_IS_KVM) > return -ENODEV; > > - kvm_root = s390_root_dev_register("kvm_s390"); > + kvm_root = root_device_register("kvm_s390"); > if (IS_ERR(kvm_root)) { > rc = PTR_ERR(kvm_root); > printk(KERN_ERR "Could not register kvm_s390 root device"); > @@ -344,7 +343,7 @@ static int __init kvm_devices_init(void) > > rc = vmem_add_mapping(real_memory_size, PAGE_SIZE); > if (rc) { > - s390_root_dev_unregister(kvm_root); > + root_device_unregister(kvm_root); > return rc; > } > > diff --git a/drivers/s390/net/cu3088.c b/drivers/s390/net/cu3088.c > index f4a3237..4838345 100644 > --- a/drivers/s390/net/cu3088.c > +++ b/drivers/s390/net/cu3088.c > @@ -25,7 +25,6 @@ > #include <linux/module.h> > #include <linux/err.h> > > -#include <asm/s390_rdev.h> > #include <asm/ccwdev.h> > #include <asm/ccwgroup.h> > > @@ -120,12 +119,12 @@ cu3088_init (void) > { > int rc; > > - cu3088_root_dev = s390_root_dev_register("cu3088"); > + cu3088_root_dev = root_device_register("cu3088"); > if (IS_ERR(cu3088_root_dev)) > return PTR_ERR(cu3088_root_dev); > rc = ccw_driver_register(&cu3088_driver); > if (rc) > - s390_root_dev_unregister(cu3088_root_dev); > + root_device_unregister(cu3088_root_dev); > > return rc; > } > @@ -134,7 +133,7 @@ static void __exit > cu3088_exit (void) > { > ccw_driver_unregister(&cu3088_driver); > - s390_root_dev_unregister(cu3088_root_dev); > + root_device_unregister(cu3088_root_dev); > } > > MODULE_DEVICE_TABLE(ccw,cu3088_ids); > diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c > index 52d2659..ffeb47b 100644 > --- a/drivers/s390/net/qeth_core_main.c > +++ b/drivers/s390/net/qeth_core_main.c > @@ -21,7 +21,6 @@ > > #include <asm/ebcdic.h> > #include <asm/io.h> > -#include <asm/s390_rdev.h> > > #include "qeth_core.h" > #include "qeth_core_offl.h" > @@ -4465,7 +4464,7 @@ static int __init qeth_core_init(void) > &driver_attr_group); > if (rc) > goto driver_err; > - qeth_core_root_dev = s390_root_dev_register("qeth"); > + qeth_core_root_dev = root_device_register("qeth"); > rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0; > if (rc) > goto register_err; > @@ -4479,7 +4478,7 @@ static int __init qeth_core_init(void) > > return 0; > slab_err: > - s390_root_dev_unregister(qeth_core_root_dev); > + root_device_unregister(qeth_core_root_dev); > register_err: > driver_remove_file(&qeth_core_ccwgroup_driver.driver, > &driver_attr_group); > @@ -4496,7 +4495,7 @@ out_err: > > static void __exit qeth_core_exit(void) > { > - s390_root_dev_unregister(qeth_core_root_dev); > + root_device_unregister(qeth_core_root_dev); > driver_remove_file(&qeth_core_ccwgroup_driver.driver, > &driver_attr_group); > ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver); > diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c > index 1b1e803..33c8fe2 100644 > --- a/drivers/s390/net/qeth_l2_main.c > +++ b/drivers/s390/net/qeth_l2_main.c > @@ -17,8 +17,6 @@ > #include <linux/mii.h> > #include <linux/ip.h> > > -#include <asm/s390_rdev.h> > - > #include "qeth_core.h" > #include "qeth_core_offl.h" > > diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c > index ed59fed..5dd2210 100644 > --- a/drivers/s390/net/qeth_l3_main.c > +++ b/drivers/s390/net/qeth_l3_main.c > @@ -23,8 +23,6 @@ > #include <net/ip.h> > #include <net/arp.h> > > -#include <asm/s390_rdev.h> > - > #include "qeth_l3.h" > #include "qeth_core_offl.h" > > diff --git a/drivers/s390/s390_rdev.c b/drivers/s390/s390_rdev.c > deleted file mode 100644 > index 64371c0..0000000 > --- a/drivers/s390/s390_rdev.c > +++ /dev/null > @@ -1,51 +0,0 @@ > -/* > - * drivers/s390/s390_rdev.c > - * s390 root device > - * > - * Copyright (C) 2002, 2005 IBM Deutschland Entwicklung GmbH, > - * IBM Corporation > - * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) > - * Carsten Otte (cotte@de.ibm.com) > - */ > - > -#include <linux/slab.h> > -#include <linux/err.h> > -#include <linux/device.h> > -#include <asm/s390_rdev.h> > - > -static void > -s390_root_dev_release(struct device *dev) > -{ > - kfree(dev); > -} > - > -struct device * > -s390_root_dev_register(const char *name) > -{ > - struct device *dev; > - int ret; > - > - if (!strlen(name)) > - return ERR_PTR(-EINVAL); > - dev = kzalloc(sizeof(struct device), GFP_KERNEL); > - if (!dev) > - return ERR_PTR(-ENOMEM); > - dev_set_name(dev, name); > - dev->release = s390_root_dev_release; > - ret = device_register(dev); > - if (ret) { > - kfree(dev); > - return ERR_PTR(ret); > - } > - return dev; > -} > - > -void > -s390_root_dev_unregister(struct device *dev) > -{ > - if (dev) > - device_unregister(dev); > -} > - > -EXPORT_SYMBOL(s390_root_dev_register); > -EXPORT_SYMBOL(s390_root_dev_unregister); > diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c > index d7b54b5..6314e1b 100644 > --- a/net/iucv/iucv.c > +++ b/net/iucv/iucv.c > @@ -47,7 +47,6 @@ > #include <asm/ebcdic.h> > #include <asm/io.h> > #include <asm/s390_ext.h> > -#include <asm/s390_rdev.h> > #include <asm/smp.h> > > /* > @@ -1609,7 +1608,7 @@ static int __init iucv_init(void) > rc = register_external_interrupt(0x4000, iucv_external_interrupt); > if (rc) > goto out; > - iucv_root = s390_root_dev_register("iucv"); > + iucv_root = root_device_register("iucv"); > if (IS_ERR(iucv_root)) { > rc = PTR_ERR(iucv_root); > goto out_int; > @@ -1653,7 +1652,7 @@ out_free: > kfree(iucv_irq_data[cpu]); > iucv_irq_data[cpu] = NULL; > } > - s390_root_dev_unregister(iucv_root); > + root_device_unregister(iucv_root); > out_int: > unregister_external_interrupt(0x4000, iucv_external_interrupt); > out: > -- > 1.5.4.3 > -- Cornelia Huck Linux for zSeries Developer Tel.: +49-7031-16-4837, Mail: cornelia.huck@de.ibm.com ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20081211180025.045b9b4a@gondolin>]
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <20081211180025.045b9b4a@gondolin> @ 2008-12-12 9:29 ` Cornelia Huck [not found] ` <20081212102951.01446f22@gondolin> 1 sibling, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-12 9:29 UTC (permalink / raw) To: Mark McLoughlin Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization, Martin Schwidefsky On Thu, 11 Dec 2008 18:00:25 +0100, Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > On Thu, 11 Dec 2008 16:16:56 +0000, > Mark McLoughlin <markmc@redhat.com> wrote: > > > Replace s390_root_dev_register() with root_device_register() etc. > > Nice, one more special case generalized :) I'll give it a run. You missed one occurrence in iucv (see below); with that patch applied, everything seems to work as expected, both for root devices created by built-ins and by modules. --- net/iucv/iucv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- linux-2.6.orig/net/iucv/iucv.c +++ linux-2.6/net/iucv/iucv.c @@ -1682,7 +1682,7 @@ static void __exit iucv_exit(void) kfree(iucv_irq_data[cpu]); iucv_irq_data[cpu] = NULL; } - s390_root_dev_unregister(iucv_root); + root_device_unregister(iucv_root); bus_unregister(&iucv_bus); unregister_external_interrupt(0x4000, iucv_external_interrupt); } ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20081212102951.01446f22@gondolin>]
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <20081212102951.01446f22@gondolin> @ 2008-12-12 9:35 ` Mark McLoughlin [not found] ` <1229074546.4041.8.camel@blaa> 1 sibling, 0 replies; 13+ messages in thread From: Mark McLoughlin @ 2008-12-12 9:35 UTC (permalink / raw) To: Cornelia Huck Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization, Martin Schwidefsky On Fri, 2008-12-12 at 10:29 +0100, Cornelia Huck wrote: > On Thu, 11 Dec 2008 18:00:25 +0100, > Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > > On Thu, 11 Dec 2008 16:16:56 +0000, > > Mark McLoughlin <markmc@redhat.com> wrote: > > > > > Replace s390_root_dev_register() with root_device_register() etc. > > > > Nice, one more special case generalized :) I'll give it a run. > > You missed one occurrence in iucv (see below); Oops. > with that patch applied, > everything seems to work as expected, both for root devices created by > built-ins and by modules. Thanks, Mark. From: Mark McLoughlin <markmc@redhat.com> Subject: [PATCH] s390: remove s390_root_dev_*() Replace s390_root_dev_register() with root_device_register() etc. [Includes fix from Cornelia Huck] Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- arch/s390/include/asm/s390_rdev.h | 15 ----------- drivers/s390/Makefile | 2 +- drivers/s390/block/dcssblk.c | 11 +++---- drivers/s390/crypto/ap_bus.c | 7 ++--- drivers/s390/kvm/kvm_virtio.c | 5 +-- drivers/s390/net/cu3088.c | 7 ++--- drivers/s390/net/qeth_core_main.c | 7 ++--- drivers/s390/net/qeth_l2_main.c | 2 - drivers/s390/net/qeth_l3_main.c | 2 - drivers/s390/s390_rdev.c | 51 ------------------------------------- net/iucv/iucv.c | 7 ++--- 11 files changed, 20 insertions(+), 96 deletions(-) delete mode 100644 arch/s390/include/asm/s390_rdev.h delete mode 100644 drivers/s390/s390_rdev.c diff --git a/arch/s390/include/asm/s390_rdev.h b/arch/s390/include/asm/s390_rdev.h deleted file mode 100644 index 6fa2044..0000000 --- a/arch/s390/include/asm/s390_rdev.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * include/asm-s390/ccwdev.h - * - * Copyright (C) 2002,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation - * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> - * Carsten Otte <cotte@de.ibm.com> - * - * Interface for s390 root device - */ - -#ifndef _S390_RDEV_H_ -#define _S390_RDEV_H_ -extern struct device *s390_root_dev_register(const char *); -extern void s390_root_dev_unregister(struct device *); -#endif /* _S390_RDEV_H_ */ diff --git a/drivers/s390/Makefile b/drivers/s390/Makefile index 4f4e7cf..d0eae59 100644 --- a/drivers/s390/Makefile +++ b/drivers/s390/Makefile @@ -4,7 +4,7 @@ CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w -obj-y += s390mach.o sysinfo.o s390_rdev.o +obj-y += s390mach.o sysinfo.o obj-y += cio/ block/ char/ crypto/ net/ scsi/ kvm/ drivers-y += drivers/s390/built-in.o diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c index 63f26a1..20fca50 100644 --- a/drivers/s390/block/dcssblk.c +++ b/drivers/s390/block/dcssblk.c @@ -15,7 +15,6 @@ #include <asm/io.h> #include <linux/completion.h> #include <linux/interrupt.h> -#include <asm/s390_rdev.h> //#define DCSSBLK_DEBUG /* Debug messages on/off */ #define DCSSBLK_NAME "dcssblk" @@ -951,7 +950,7 @@ dcssblk_check_params(void) static void __exit dcssblk_exit(void) { - s390_root_dev_unregister(dcssblk_root_dev); + root_device_unregister(dcssblk_root_dev); unregister_blkdev(dcssblk_major, DCSSBLK_NAME); } @@ -960,22 +959,22 @@ dcssblk_init(void) { int rc; - dcssblk_root_dev = s390_root_dev_register("dcssblk"); + dcssblk_root_dev = root_device_register("dcssblk"); if (IS_ERR(dcssblk_root_dev)) return PTR_ERR(dcssblk_root_dev); rc = device_create_file(dcssblk_root_dev, &dev_attr_add); if (rc) { - s390_root_dev_unregister(dcssblk_root_dev); + root_device_unregister(dcssblk_root_dev); return rc; } rc = device_create_file(dcssblk_root_dev, &dev_attr_remove); if (rc) { - s390_root_dev_unregister(dcssblk_root_dev); + root_device_unregister(dcssblk_root_dev); return rc; } rc = register_blkdev(0, DCSSBLK_NAME); if (rc < 0) { - s390_root_dev_unregister(dcssblk_root_dev); + root_device_unregister(dcssblk_root_dev); return rc; } dcssblk_major = rc; diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c index e3fe683..0689c22 100644 --- a/drivers/s390/crypto/ap_bus.c +++ b/drivers/s390/crypto/ap_bus.c @@ -32,7 +32,6 @@ #include <linux/notifier.h> #include <linux/kthread.h> #include <linux/mutex.h> -#include <asm/s390_rdev.h> #include <asm/reset.h> #include <linux/hrtimer.h> #include <linux/ktime.h> @@ -1358,7 +1357,7 @@ int __init ap_module_init(void) } /* Create /sys/devices/ap. */ - ap_root_device = s390_root_dev_register("ap"); + ap_root_device = root_device_register("ap"); rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0; if (rc) goto out_bus; @@ -1401,7 +1400,7 @@ out_work: hrtimer_cancel(&ap_poll_timer); destroy_workqueue(ap_work_queue); out_root: - s390_root_dev_unregister(ap_root_device); + root_device_unregister(ap_root_device); out_bus: while (i--) bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); @@ -1432,7 +1431,7 @@ void ap_module_exit(void) hrtimer_cancel(&ap_poll_timer); destroy_workqueue(ap_work_queue); tasklet_kill(&ap_tasklet); - s390_root_dev_unregister(ap_root_device); + root_device_unregister(ap_root_device); while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, __ap_match_all))) { diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c index c79cf05..db61252 100644 --- a/drivers/s390/kvm/kvm_virtio.c +++ b/drivers/s390/kvm/kvm_virtio.c @@ -24,7 +24,6 @@ #include <asm/kvm_virtio.h> #include <asm/setup.h> #include <asm/s390_ext.h> -#include <asm/s390_rdev.h> #define VIRTIO_SUBCODE_64 0x0D00 @@ -335,7 +334,7 @@ static int __init kvm_devices_init(void) if (!MACHINE_IS_KVM) return -ENODEV; - kvm_root = s390_root_dev_register("kvm_s390"); + kvm_root = root_device_register("kvm_s390"); if (IS_ERR(kvm_root)) { rc = PTR_ERR(kvm_root); printk(KERN_ERR "Could not register kvm_s390 root device"); @@ -344,7 +343,7 @@ static int __init kvm_devices_init(void) rc = vmem_add_mapping(real_memory_size, PAGE_SIZE); if (rc) { - s390_root_dev_unregister(kvm_root); + root_device_unregister(kvm_root); return rc; } diff --git a/drivers/s390/net/cu3088.c b/drivers/s390/net/cu3088.c index f4a3237..4838345 100644 --- a/drivers/s390/net/cu3088.c +++ b/drivers/s390/net/cu3088.c @@ -25,7 +25,6 @@ #include <linux/module.h> #include <linux/err.h> -#include <asm/s390_rdev.h> #include <asm/ccwdev.h> #include <asm/ccwgroup.h> @@ -120,12 +119,12 @@ cu3088_init (void) { int rc; - cu3088_root_dev = s390_root_dev_register("cu3088"); + cu3088_root_dev = root_device_register("cu3088"); if (IS_ERR(cu3088_root_dev)) return PTR_ERR(cu3088_root_dev); rc = ccw_driver_register(&cu3088_driver); if (rc) - s390_root_dev_unregister(cu3088_root_dev); + root_device_unregister(cu3088_root_dev); return rc; } @@ -134,7 +133,7 @@ static void __exit cu3088_exit (void) { ccw_driver_unregister(&cu3088_driver); - s390_root_dev_unregister(cu3088_root_dev); + root_device_unregister(cu3088_root_dev); } MODULE_DEVICE_TABLE(ccw,cu3088_ids); diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c index 52d2659..ffeb47b 100644 --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c @@ -21,7 +21,6 @@ #include <asm/ebcdic.h> #include <asm/io.h> -#include <asm/s390_rdev.h> #include "qeth_core.h" #include "qeth_core_offl.h" @@ -4465,7 +4464,7 @@ static int __init qeth_core_init(void) &driver_attr_group); if (rc) goto driver_err; - qeth_core_root_dev = s390_root_dev_register("qeth"); + qeth_core_root_dev = root_device_register("qeth"); rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0; if (rc) goto register_err; @@ -4479,7 +4478,7 @@ static int __init qeth_core_init(void) return 0; slab_err: - s390_root_dev_unregister(qeth_core_root_dev); + root_device_unregister(qeth_core_root_dev); register_err: driver_remove_file(&qeth_core_ccwgroup_driver.driver, &driver_attr_group); @@ -4496,7 +4495,7 @@ out_err: static void __exit qeth_core_exit(void) { - s390_root_dev_unregister(qeth_core_root_dev); + root_device_unregister(qeth_core_root_dev); driver_remove_file(&qeth_core_ccwgroup_driver.driver, &driver_attr_group); ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver); diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c index 1b1e803..33c8fe2 100644 --- a/drivers/s390/net/qeth_l2_main.c +++ b/drivers/s390/net/qeth_l2_main.c @@ -17,8 +17,6 @@ #include <linux/mii.h> #include <linux/ip.h> -#include <asm/s390_rdev.h> - #include "qeth_core.h" #include "qeth_core_offl.h" diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c index ed59fed..5dd2210 100644 --- a/drivers/s390/net/qeth_l3_main.c +++ b/drivers/s390/net/qeth_l3_main.c @@ -23,8 +23,6 @@ #include <net/ip.h> #include <net/arp.h> -#include <asm/s390_rdev.h> - #include "qeth_l3.h" #include "qeth_core_offl.h" diff --git a/drivers/s390/s390_rdev.c b/drivers/s390/s390_rdev.c deleted file mode 100644 index 64371c0..0000000 --- a/drivers/s390/s390_rdev.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * drivers/s390/s390_rdev.c - * s390 root device - * - * Copyright (C) 2002, 2005 IBM Deutschland Entwicklung GmbH, - * IBM Corporation - * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) - * Carsten Otte (cotte@de.ibm.com) - */ - -#include <linux/slab.h> -#include <linux/err.h> -#include <linux/device.h> -#include <asm/s390_rdev.h> - -static void -s390_root_dev_release(struct device *dev) -{ - kfree(dev); -} - -struct device * -s390_root_dev_register(const char *name) -{ - struct device *dev; - int ret; - - if (!strlen(name)) - return ERR_PTR(-EINVAL); - dev = kzalloc(sizeof(struct device), GFP_KERNEL); - if (!dev) - return ERR_PTR(-ENOMEM); - dev_set_name(dev, name); - dev->release = s390_root_dev_release; - ret = device_register(dev); - if (ret) { - kfree(dev); - return ERR_PTR(ret); - } - return dev; -} - -void -s390_root_dev_unregister(struct device *dev) -{ - if (dev) - device_unregister(dev); -} - -EXPORT_SYMBOL(s390_root_dev_register); -EXPORT_SYMBOL(s390_root_dev_unregister); diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c index d7b54b5..22bb67e 100644 --- a/net/iucv/iucv.c +++ b/net/iucv/iucv.c @@ -47,7 +47,6 @@ #include <asm/ebcdic.h> #include <asm/io.h> #include <asm/s390_ext.h> -#include <asm/s390_rdev.h> #include <asm/smp.h> /* @@ -1609,7 +1608,7 @@ static int __init iucv_init(void) rc = register_external_interrupt(0x4000, iucv_external_interrupt); if (rc) goto out; - iucv_root = s390_root_dev_register("iucv"); + iucv_root = root_device_register("iucv"); if (IS_ERR(iucv_root)) { rc = PTR_ERR(iucv_root); goto out_int; @@ -1653,7 +1652,7 @@ out_free: kfree(iucv_irq_data[cpu]); iucv_irq_data[cpu] = NULL; } - s390_root_dev_unregister(iucv_root); + root_device_unregister(iucv_root); out_int: unregister_external_interrupt(0x4000, iucv_external_interrupt); out: @@ -1683,7 +1682,7 @@ static void __exit iucv_exit(void) kfree(iucv_irq_data[cpu]); iucv_irq_data[cpu] = NULL; } - s390_root_dev_unregister(iucv_root); + root_device_unregister(iucv_root); bus_unregister(&iucv_bus); unregister_external_interrupt(0x4000, iucv_external_interrupt); } -- 1.6.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
[parent not found: <1229074546.4041.8.camel@blaa>]
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <1229074546.4041.8.camel@blaa> @ 2008-12-12 9:45 ` Martin Schwidefsky 2008-12-12 9:45 ` Cornelia Huck ` (2 subsequent siblings) 3 siblings, 0 replies; 13+ messages in thread From: Martin Schwidefsky @ 2008-12-12 9:45 UTC (permalink / raw) To: Mark McLoughlin Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization On Fri, 2008-12-12 at 09:35 +0000, Mark McLoughlin wrote: > From: Mark McLoughlin <markmc@redhat.com> > Subject: [PATCH] s390: remove s390_root_dev_*() > > Replace s390_root_dev_register() with root_device_register() etc. > > [Includes fix from Cornelia Huck] > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> I can carry the patch in my patch queue. Thanks. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <1229074546.4041.8.camel@blaa> 2008-12-12 9:45 ` Martin Schwidefsky @ 2008-12-12 9:45 ` Cornelia Huck [not found] ` <1229075116.28887.4.camel@localhost> 2008-12-12 19:07 ` Greg KH 3 siblings, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-12 9:45 UTC (permalink / raw) To: Mark McLoughlin Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization, Martin Schwidefsky On Fri, 12 Dec 2008 09:35:46 +0000, Mark McLoughlin <markmc@redhat.com> wrote: > From: Mark McLoughlin <markmc@redhat.com> > Subject: [PATCH] s390: remove s390_root_dev_*() > > Replace s390_root_dev_register() with root_device_register() etc. > > [Includes fix from Cornelia Huck] > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <1229075116.28887.4.camel@localhost>]
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <1229075116.28887.4.camel@localhost> @ 2008-12-12 9:54 ` Martin Schwidefsky 0 siblings, 0 replies; 13+ messages in thread From: Martin Schwidefsky @ 2008-12-12 9:54 UTC (permalink / raw) To: Mark McLoughlin Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization On Fri, 2008-12-12 at 10:45 +0100, Martin Schwidefsky wrote: > On Fri, 2008-12-12 at 09:35 +0000, Mark McLoughlin wrote: > > From: Mark McLoughlin <markmc@redhat.com> > > Subject: [PATCH] s390: remove s390_root_dev_*() > > > > Replace s390_root_dev_register() with root_device_register() etc. > > > > [Includes fix from Cornelia Huck] > > > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> > > I can carry the patch in my patch queue. Thanks. Oops, this depends on another patch. If the other patch is missing it doesn't compile.. So I better not add that patch to my queue. It should be sent together with the patch it depends on. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/4] s390: remove s390_root_dev_*() [not found] ` <1229074546.4041.8.camel@blaa> ` (2 preceding siblings ...) [not found] ` <1229075116.28887.4.camel@localhost> @ 2008-12-12 19:07 ` Greg KH [not found] ` <1229345909-27229-1-git-send-email-markmc@redhat.com> 3 siblings, 1 reply; 13+ messages in thread From: Greg KH @ 2008-12-12 19:07 UTC (permalink / raw) To: Mark McLoughlin Cc: linux-s390, Anthony Liguori, Greg KH, Kay Sievers, Heiko Carstens, linux-kernel, virtualization, Martin Schwidefsky On Fri, Dec 12, 2008 at 09:35:46AM +0000, Mark McLoughlin wrote: > On Fri, 2008-12-12 at 10:29 +0100, Cornelia Huck wrote: > > On Thu, 11 Dec 2008 18:00:25 +0100, > > Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > > > On Thu, 11 Dec 2008 16:16:56 +0000, > > > Mark McLoughlin <markmc@redhat.com> wrote: > > > > > > > Replace s390_root_dev_register() with root_device_register() etc. > > > > > > Nice, one more special case generalized :) I'll give it a run. > > > > You missed one occurrence in iucv (see below); > > Oops. > > > with that patch applied, > > everything seems to work as expected, both for root devices created by > > built-ins and by modules. > > Thanks, > Mark. > > From: Mark McLoughlin <markmc@redhat.com> > Subject: [PATCH] s390: remove s390_root_dev_*() > > Replace s390_root_dev_register() with root_device_register() etc. Can you resend this whole series, I see lots of replacements in this thread and it would be good to know exactly what I should be reviewing/applying. thanks, greg k-h ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <1229345909-27229-1-git-send-email-markmc@redhat.com>]
[parent not found: <1229345909-27229-2-git-send-email-markmc@redhat.com>]
* Re: [PATCH 2/4] virtio: do not statically allocate root device [not found] ` <1229345909-27229-2-git-send-email-markmc@redhat.com> @ 2008-12-15 22:27 ` Rusty Russell 0 siblings, 0 replies; 13+ messages in thread From: Rusty Russell @ 2008-12-15 22:27 UTC (permalink / raw) To: Mark McLoughlin Cc: Anthony Liguori, Kay Sievers, Greg KH, linux-kernel, virtualization On Monday 15 December 2008 23:28:27 Mark McLoughlin wrote: > We shouldn't be statically allocating the root device object, > so dynamically allocate it using root_device_register() > instead. This and 3/4 which would normally go through me: Acked-by: Rusty Russell <rusty@rustcorp.com.au> Thanks Greg, Rusty. ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20081211175604.511fc6ae@gondolin>]
* Re: [PATCH 1/4] driver core: add root_device_register() [not found] ` <20081211175604.511fc6ae@gondolin> @ 2008-12-11 18:23 ` Mark McLoughlin [not found] ` <1229019807.7968.87.camel@blaa> 1 sibling, 0 replies; 13+ messages in thread From: Mark McLoughlin @ 2008-12-11 18:23 UTC (permalink / raw) To: Greg KH; +Cc: Anthony Liguori, Kay Sievers, linux-kernel, virtualization Add support for allocating root device objects which group device objects under /sys/devices directories. Also add a sysfs 'module' symlink which points to the owner of the root device object. This symlink will be used in virtio to allow userspace to determine which virtio bus implementation a given device is associated with. [Includes suggestions from Cornelia Huck] Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- drivers/base/core.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 11 ++++++ 2 files changed, 98 insertions(+), 0 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8c2cc26..20e5825 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1196,6 +1196,93 @@ EXPORT_SYMBOL_GPL(put_device); EXPORT_SYMBOL_GPL(device_create_file); EXPORT_SYMBOL_GPL(device_remove_file); +struct root_device +{ + struct device dev; + struct module *owner; +}; + +static void root_device_release(struct device *dev) +{ + kfree(dev); +} + +/** + * __root_device_register - allocate and register a root device + * @name: root device name + * @owner: owner module of the root device, usually THIS_MODULE + * + * This function allocates a root device and registers it + * using device_register(). In order to free the returned + * device, use root_device_unregister(). + * + * Root devices are dummy devices which allow other devices + * to be grouped under /sys/devices. Use this function to + * allocate a root device and then use it as the parent of + * any device which should appear under /sys/devices/{name} + * + * The /sys/devices/{name} directory will also contain a + * 'module' symlink which points to the @owner directory + * in sysfs. + * + * Note: You probably want to use root_device_register(). + */ +struct device *__root_device_register(const char *name, struct module *owner) +{ + struct root_device *root; + int err = -ENOMEM; + + root = kzalloc(sizeof(struct root_device), GFP_KERNEL); + if (!root) + return ERR_PTR(err); + + err = dev_set_name(&root->dev, name); + if (err) { + kfree(root); + return ERR_PTR(err); + } + + root->dev.release = root_device_release; + + err = device_register(&root->dev); + if (err) { + put_device(&root->dev); + return ERR_PTR(err); + } + + if (owner) { + struct module_kobject *mk = &owner->mkobj; + + err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module"); + if (err) { + device_unregister(&root->dev); + return ERR_PTR(err); + } + root->owner = owner; + } + + return &root->dev; +} +EXPORT_SYMBOL_GPL(__root_device_register); + +/** + * root_device_unregister - unregister and free a root device + * @root: device going away. + * + * This function unregisters and cleans up a device that was created by + * root_device_register(). + */ +void root_device_unregister(struct device *dev) +{ + struct root_device *root = container_of(dev, struct root_device, dev); + + if (root->owner) + sysfs_remove_link(&root->dev.kobj, "module"); + + device_unregister(dev); +} +EXPORT_SYMBOL_GPL(root_device_unregister); + static void device_create_release(struct device *dev) { diff --git a/include/linux/device.h b/include/linux/device.h index 1a3686d..9e02980 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -483,6 +483,17 @@ extern int device_rename(struct device *dev, char *new_name); extern int device_move(struct device *dev, struct device *new_parent); /* + * Root device objects for grouping under /sys/devices + */ +extern struct device *__root_device_register(const char *name, + struct module *owner); +static inline struct device *root_device_register(const char *name) +{ + return __root_device_register(name, THIS_MODULE); +} +extern void root_device_unregister(struct device *root); + +/* * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ -- 1.5.4.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
[parent not found: <1229019807.7968.87.camel@blaa>]
* Re: [PATCH 1/4] driver core: add root_device_register() [not found] ` <1229019807.7968.87.camel@blaa> @ 2008-12-12 8:42 ` Cornelia Huck [not found] ` <20081212094246.5692d0ca@gondolin> 1 sibling, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-12 8:42 UTC (permalink / raw) To: Mark McLoughlin Cc: Anthony Liguori, Greg KH, Kay Sievers, linux-kernel, virtualization On Thu, 11 Dec 2008 18:23:27 +0000, Mark McLoughlin <markmc@redhat.com> wrote: > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 8c2cc26..20e5825 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1196,6 +1196,93 @@ EXPORT_SYMBOL_GPL(put_device); > EXPORT_SYMBOL_GPL(device_create_file); > EXPORT_SYMBOL_GPL(device_remove_file); > > +struct root_device > +{ > + struct device dev; > + struct module *owner; > +}; > + > +static void root_device_release(struct device *dev) > +{ You need to get the root device here and free that. > + kfree(dev); > +} ^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20081212094246.5692d0ca@gondolin>]
* Re: [PATCH 1/4] driver core: add root_device_register() [not found] ` <20081212094246.5692d0ca@gondolin> @ 2008-12-12 8:56 ` Mark McLoughlin 2008-12-12 9:23 ` Cornelia Huck 0 siblings, 1 reply; 13+ messages in thread From: Mark McLoughlin @ 2008-12-12 8:56 UTC (permalink / raw) To: Cornelia Huck Cc: Anthony Liguori, Greg KH, Kay Sievers, linux-kernel, virtualization On Fri, 2008-12-12 at 09:42 +0100, Cornelia Huck wrote: > On Thu, 11 Dec 2008 18:23:27 +0000, > Mark McLoughlin <markmc@redhat.com> wrote: > > > diff --git a/drivers/base/core.c b/drivers/base/core.c > > index 8c2cc26..20e5825 100644 > > --- a/drivers/base/core.c > > +++ b/drivers/base/core.c > > @@ -1196,6 +1196,93 @@ EXPORT_SYMBOL_GPL(put_device); > > EXPORT_SYMBOL_GPL(device_create_file); > > EXPORT_SYMBOL_GPL(device_remove_file); > > > > +struct root_device > > +{ > > + struct device dev; > > + struct module *owner; > > +}; > > + > > +static void root_device_release(struct device *dev) > > +{ > > You need to get the root device here and free that. > > > + kfree(dev); > > +} Yeah, I just figured it was a little overkill given the structure definition is three lines away. Here it is, though. Cheers, Mark. From: Mark McLoughlin <markmc@redhat.com> Subject: [PATCH] driver core: add root_device_register() Add support for allocating root device objects which group device objects under /sys/devices directories. Also add a sysfs 'module' symlink which points to the owner of the root device object. This symlink will be used in virtio to allow userspace to determine which virtio bus implementation a given device is associated with. [Includes suggestions from Cornelia Huck] Signed-off-by: Mark McLoughlin <markmc@redhat.com> --- drivers/base/core.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 11 ++++++ 2 files changed, 100 insertions(+), 0 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8c2cc26..05320af 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1196,6 +1196,95 @@ EXPORT_SYMBOL_GPL(put_device); EXPORT_SYMBOL_GPL(device_create_file); EXPORT_SYMBOL_GPL(device_remove_file); +struct root_device +{ + struct device dev; + struct module *owner; +}; + +#define to_root_device(dev) container_of(dev, struct root_device, dev) + +static void root_device_release(struct device *dev) +{ + kfree(to_root_device(dev)); +} + +/** + * __root_device_register - allocate and register a root device + * @name: root device name + * @owner: owner module of the root device, usually THIS_MODULE + * + * This function allocates a root device and registers it + * using device_register(). In order to free the returned + * device, use root_device_unregister(). + * + * Root devices are dummy devices which allow other devices + * to be grouped under /sys/devices. Use this function to + * allocate a root device and then use it as the parent of + * any device which should appear under /sys/devices/{name} + * + * The /sys/devices/{name} directory will also contain a + * 'module' symlink which points to the @owner directory + * in sysfs. + * + * Note: You probably want to use root_device_register(). + */ +struct device *__root_device_register(const char *name, struct module *owner) +{ + struct root_device *root; + int err = -ENOMEM; + + root = kzalloc(sizeof(struct root_device), GFP_KERNEL); + if (!root) + return ERR_PTR(err); + + err = dev_set_name(&root->dev, name); + if (err) { + kfree(root); + return ERR_PTR(err); + } + + root->dev.release = root_device_release; + + err = device_register(&root->dev); + if (err) { + put_device(&root->dev); + return ERR_PTR(err); + } + + if (owner) { + struct module_kobject *mk = &owner->mkobj; + + err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module"); + if (err) { + device_unregister(&root->dev); + return ERR_PTR(err); + } + root->owner = owner; + } + + return &root->dev; +} +EXPORT_SYMBOL_GPL(__root_device_register); + +/** + * root_device_unregister - unregister and free a root device + * @root: device going away. + * + * This function unregisters and cleans up a device that was created by + * root_device_register(). + */ +void root_device_unregister(struct device *dev) +{ + struct root_device *root = to_root_device(dev); + + if (root->owner) + sysfs_remove_link(&root->dev.kobj, "module"); + + device_unregister(dev); +} +EXPORT_SYMBOL_GPL(root_device_unregister); + static void device_create_release(struct device *dev) { diff --git a/include/linux/device.h b/include/linux/device.h index 1a3686d..9e02980 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -483,6 +483,17 @@ extern int device_rename(struct device *dev, char *new_name); extern int device_move(struct device *dev, struct device *new_parent); /* + * Root device objects for grouping under /sys/devices + */ +extern struct device *__root_device_register(const char *name, + struct module *owner); +static inline struct device *root_device_register(const char *name) +{ + return __root_device_register(name, THIS_MODULE); +} +extern void root_device_unregister(struct device *root); + +/* * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ -- 1.6.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] driver core: add root_device_register() 2008-12-12 8:56 ` Mark McLoughlin @ 2008-12-12 9:23 ` Cornelia Huck 0 siblings, 0 replies; 13+ messages in thread From: Cornelia Huck @ 2008-12-12 9:23 UTC (permalink / raw) To: Mark McLoughlin Cc: Anthony Liguori, Greg KH, Kay Sievers, linux-kernel, virtualization On Fri, 12 Dec 2008 08:56:49 +0000, Mark McLoughlin <markmc@redhat.com> wrote: > Yeah, I just figured it was a little overkill given the structure > definition is three lines away. Here it is, though. As you use it twice, I think it makes the code more readable. > > Cheers, > Mark. > > From: Mark McLoughlin <markmc@redhat.com> > Subject: [PATCH] driver core: add root_device_register() > > Add support for allocating root device objects which group > device objects under /sys/devices directories. > > Also add a sysfs 'module' symlink which points to the owner > of the root device object. This symlink will be used in virtio > to allow userspace to determine which virtio bus implementation > a given device is associated with. > > [Includes suggestions from Cornelia Huck] > > Signed-off-by: Mark McLoughlin <markmc@redhat.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> > --- > drivers/base/core.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/device.h | 11 ++++++ > 2 files changed, 100 insertions(+), 0 deletions(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 8c2cc26..05320af 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1196,6 +1196,95 @@ EXPORT_SYMBOL_GPL(put_device); > EXPORT_SYMBOL_GPL(device_create_file); > EXPORT_SYMBOL_GPL(device_remove_file); > > +struct root_device > +{ > + struct device dev; > + struct module *owner; > +}; > + > +#define to_root_device(dev) container_of(dev, struct root_device, dev) > + > +static void root_device_release(struct device *dev) > +{ > + kfree(to_root_device(dev)); > +} > + > +/** > + * __root_device_register - allocate and register a root device > + * @name: root device name > + * @owner: owner module of the root device, usually THIS_MODULE > + * > + * This function allocates a root device and registers it > + * using device_register(). In order to free the returned > + * device, use root_device_unregister(). > + * > + * Root devices are dummy devices which allow other devices > + * to be grouped under /sys/devices. Use this function to > + * allocate a root device and then use it as the parent of > + * any device which should appear under /sys/devices/{name} > + * > + * The /sys/devices/{name} directory will also contain a > + * 'module' symlink which points to the @owner directory > + * in sysfs. > + * > + * Note: You probably want to use root_device_register(). > + */ > +struct device *__root_device_register(const char *name, struct module *owner) > +{ > + struct root_device *root; > + int err = -ENOMEM; > + > + root = kzalloc(sizeof(struct root_device), GFP_KERNEL); > + if (!root) > + return ERR_PTR(err); > + > + err = dev_set_name(&root->dev, name); > + if (err) { > + kfree(root); > + return ERR_PTR(err); > + } > + > + root->dev.release = root_device_release; > + > + err = device_register(&root->dev); > + if (err) { > + put_device(&root->dev); > + return ERR_PTR(err); > + } > + > + if (owner) { > + struct module_kobject *mk = &owner->mkobj; > + > + err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module"); > + if (err) { > + device_unregister(&root->dev); > + return ERR_PTR(err); > + } > + root->owner = owner; > + } > + > + return &root->dev; > +} > +EXPORT_SYMBOL_GPL(__root_device_register); > + > +/** > + * root_device_unregister - unregister and free a root device > + * @root: device going away. > + * > + * This function unregisters and cleans up a device that was created by > + * root_device_register(). > + */ > +void root_device_unregister(struct device *dev) > +{ > + struct root_device *root = to_root_device(dev); > + > + if (root->owner) > + sysfs_remove_link(&root->dev.kobj, "module"); > + > + device_unregister(dev); > +} > +EXPORT_SYMBOL_GPL(root_device_unregister); > + > > static void device_create_release(struct device *dev) > { > diff --git a/include/linux/device.h b/include/linux/device.h > index 1a3686d..9e02980 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -483,6 +483,17 @@ extern int device_rename(struct device *dev, char *new_name); > extern int device_move(struct device *dev, struct device *new_parent); > > /* > + * Root device objects for grouping under /sys/devices > + */ > +extern struct device *__root_device_register(const char *name, > + struct module *owner); > +static inline struct device *root_device_register(const char *name) > +{ > + return __root_device_register(name, THIS_MODULE); > +} > +extern void root_device_unregister(struct device *root); > + > +/* > * Manual binding of a device to driver. See drivers/base/bus.c > * for information on use. > */ > -- > 1.6.0.3 > ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2008-12-15 22:27 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1229012203.7968.79.camel@blaa>
[not found] ` <1229012216-4211-1-git-send-email-markmc@redhat.com>
2008-12-11 16:56 ` [PATCH 1/4] driver core: add root_device_register() Cornelia Huck
[not found] ` <1229012216-4211-2-git-send-email-markmc@redhat.com>
[not found] ` <1229012216-4211-3-git-send-email-markmc@redhat.com>
[not found] ` <1229012216-4211-4-git-send-email-markmc@redhat.com>
2008-12-11 17:00 ` [PATCH 4/4] s390: remove s390_root_dev_*() Cornelia Huck
[not found] ` <20081211180025.045b9b4a@gondolin>
2008-12-12 9:29 ` Cornelia Huck
[not found] ` <20081212102951.01446f22@gondolin>
2008-12-12 9:35 ` Mark McLoughlin
[not found] ` <1229074546.4041.8.camel@blaa>
2008-12-12 9:45 ` Martin Schwidefsky
2008-12-12 9:45 ` Cornelia Huck
[not found] ` <1229075116.28887.4.camel@localhost>
2008-12-12 9:54 ` Martin Schwidefsky
2008-12-12 19:07 ` Greg KH
[not found] ` <1229345909-27229-1-git-send-email-markmc@redhat.com>
[not found] ` <1229345909-27229-2-git-send-email-markmc@redhat.com>
2008-12-15 22:27 ` [PATCH 2/4] virtio: do not statically allocate root device Rusty Russell
[not found] ` <20081211175604.511fc6ae@gondolin>
2008-12-11 18:23 ` [PATCH 1/4] driver core: add root_device_register() Mark McLoughlin
[not found] ` <1229019807.7968.87.camel@blaa>
2008-12-12 8:42 ` Cornelia Huck
[not found] ` <20081212094246.5692d0ca@gondolin>
2008-12-12 8:56 ` Mark McLoughlin
2008-12-12 9:23 ` Cornelia Huck
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox