Driver Core and sysfs patches for 2.6.17-rc1
Subsystems (9)
PATCH 1/1 Driver Core and sysfs patches for 2.6.17-rc1
Here are some driver core and sysfs patches for 2.6.17-rc1. They contain the following changes:
- allow sysfs files to be polled (this missed the initial 2.6.16-git merge due to the patch being reworked by Neil. It has been included in the -mm tree for a number of months now with no reported issues. Sorry for missing this one the first time around this cycle)
- fix bug in manual binding of devices to drivers.
- report the offending driver when suspend fails
- fix partition scanning and reporting to userspace (was being reported before the scanning was finished, which isn't very nice.)
- few other minor bugfixes and build fixes.
All of these patches have been in the -mm tree for a number of weeks, if not months (in the case of the sysfs poll patch).
Please pull from:
rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
or if master.kernel.org hasn't synced up yet:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
Patches will be sent as a follow-on to this message to lkml for people to see.
thanks,
greg k-h
arch/i386/kernel/Makefile | 2 - arch/ia64/kernel/Makefile | 3 - arch/x86_64/kernel/Makefile | 4 -- drivers/base/bus.c | 5 ++ drivers/base/class.c | 13 +++---- drivers/base/dd.c | 2 - drivers/base/power/suspend.c | 12 ++++++ drivers/firmware/Makefile | 3 + drivers/firmware/dmi_scan.c | 12 +++--- drivers/md/md.c | 1 drivers/pci/pci-driver.c | 6 ++- drivers/pci/pci.c | 6 ++- drivers/usb/core/hcd-pci.c | 7 +-- fs/partitions/check.c | 38 ++++++++++++++++----- fs/sysfs/dir.c | 1 fs/sysfs/file.c | 76 +++++++++++++++++++++++++++++++++++++++++++ fs/sysfs/sysfs.h | 1 include/linux/genhd.h | 1 include/linux/kobject.h | 2 + include/linux/pm.h | 8 ++++ include/linux/sysfs.h | 6 +++ lib/kobject.c | 1 22 files changed, 173 insertions(+), 37 deletions(-)
---------------
Alan Stern:
driver core: safely unbind drivers for devices not on a bus
Andrew Morton:
pm: print name of failed suspend function
Bjorn Helgaas:
DMI: move dmi_scan.c from arch/i386 to drivers/firmware/
Jayachandran C:
driver core: fix unnecessary NULL check in drivers/base/class.c
Kay Sievers:
BLOCK: delay all uevents until partition table is scanned
NeilBrown:
sysfs: Allow sysfs attribute files to be pollable
Ryan Wilson:
driver core: driver_bind attribute returns incorrect value
PATCH 1/7 sysfs: Allow sysfs attribute files to be pollable
It works like this:
Open the file
Read all the contents.
Call poll requesting POLLERR or POLLPRI (so select/exceptfds works) When poll returns,
close the file and go to top of loop.
or lseek to start of file and go back to the 'read'.
Events are signaled by an object manager calling
sysfs_notify(kobj, dir, attr);
If the dir is non-NULL, it is used to find a subdirectory which contains the attribute (presumably created by sysfs_create_group).
This has a cost of one int per attribute, one wait_queuehead per kobject, one int per open file.
The name "sysfs_notify" may be confused with the inotify functionality. Maybe it would be nice to support inotify for sysfs attributes as well?
This patch also uses sysfs_notify to allow /sys/block/md*/md/sync_action to be pollable
---
drivers/md/md.c | 1 + fs/sysfs/dir.c | 1 + fs/sysfs/file.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ fs/sysfs/sysfs.h | 1 + include/linux/kobject.h | 2 + include/linux/sysfs.h | 6 ++++ lib/kobject.c | 1 + 7 files changed, 88 insertions(+), 0 deletions(-)
4508a7a734b111b8b7e39986237d84acb1168dd0
drivers/md/md.c +1 -0
@@ -163,6 +163,7 @@ void md_new_event(mddev_t *mddev) {atomic_inc (&md_event_count);wake_up (&md_event_waiters); +sysfs_notify (&mddev->kobj,NULL ,"sync_action" ); }EXPORT_SYMBOL_GPL (md_new_event);
fs/sysfs/dir.c +1 -0
@@ -43,6 +43,7 @@ static struct sysfs_dirent * sysfs_new_dmemset (sd,0 ,sizeof (*sd));atomic_set (&sd->s_count,1 ); +atomic_set (&sd->s_event,0 );INIT_LIST_HEAD (&sd->s_children);list_add (&sd->s_sibling, &parent_sd->s_children); sd->s_element = element;
fs/sysfs/file.c +76 -0
112 lines not on this page · raw message
fs/sysfs/sysfs.h +1 -0
@@ -11,6 +11,7 @@ extern int sysfs_make_dirent(struct sysfextern int sysfs_add_file (struct dentry *,const struct attribute *,int );extern void sysfs_hash_and_remove (struct dentry * dir,const char * name); +extern struct sysfs_dirent *sysfs_find (struct sysfs_dirent *dir,const char * name);extern int sysfs_create_subdir (struct kobject *,const char *,struct dentry **);extern void sysfs_remove_subdir (struct dentry *);
include/linux/kobject.h +2 -0
@@ -24,6 +24,7 @@#include <linux/rwsem.h> #include <linux/kref.h> #include <linux/kernel.h> +#include <linux/wait.h> #include <asm/atomic.h> #define KOBJ_NAME_LEN 20
@@ -56,6 +57,7 @@ struct kobject {struct kset * kset;struct kobj_type * ktype;struct dentry * dentry; +wait_queue_head_t poll; };extern int kobject_set_name (struct kobject *,const char *, ...)
include/linux/sysfs.h +6 -0
@@ -74,6 +74,7 @@ struct sysfs_dirent {umode_t s_mode;struct dentry * s_dentry;struct iattr * s_iattr; +atomic_t s_event; };#define SYSFS_ROOT 0x0001
@@ -117,6 +118,7 @@ int sysfs_remove_bin_file(struct kobjectint sysfs_create_group (struct kobject *,const struct attribute_group *);void sysfs_remove_group (struct kobject *,const struct attribute_group *); +void sysfs_notify (struct kobject * k,char *dir,char *attr);#else /* CONFIG_SYSFS */
@@ -185,6 +187,10 @@ static inline void sysfs_remove_group(st ; } +static inline void sysfs_notify (struct kobject * k,char *dir,char *attr) +{ +} +#endif /* CONFIG_SYSFS */ #endif /* _SYSFS_H_ */
lib/kobject.c +1 -0
@@ -128,6 +128,7 @@ void kobject_init(struct kobject * kobj) {kref_init (&kobj->kref);INIT_LIST_HEAD (&kobj->entry); +init_waitqueue_head (&kobj->poll); kobj->kset =kset_get (kobj->kset); }
Signature · 1 line
1.2.6
PATCH 2/7 driver core: safely unbind drivers for devices not on a bus
This patch (as667) changes the __device_release_driver() routine to prevent it from crashing when it runs across a device not on any bus. This seems logical, inasmuch as the corresponding bus_add_device() routine has an explicit check allowing it to accept such devices.
---
drivers/base/dd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
0f836ca4c122f4ef096110d652a6326fe34e6961
drivers/base/dd.c +1 -1
@@ -209,7 +209,7 @@ static void __device_release_driver(strusysfs_remove_link (&dev->kobj,"driver" );klist_remove (&dev->knode_driver); -if (dev->bus->remove) +if (dev->bus && dev->bus->remove) dev->bus->remove (dev);else if (drv->remove) drv->remove (dev);
Signature · 1 line
1.2.6
PATCH 3/7 BLOCK: delay all uevents until partition table is scanned
[BLOCK] delay all uevents until partition table is scanned
Here we delay the annoucement of all block device events until the disk's partition table is scanned and all partition devices are already created and sysfs is populated.
We have a bunch of old bugs for removable storage handling where we probe successfully for a filesystem on the raw disk, but at the same time the kernel recognizes a partition table and creates partition devices.
Currently there is no sane way to tell if partitions will show up or not at the time the disk device is announced to userspace. With the delayed events we can simply skip any probe for a filesystem on the raw disk when we find already present partitions.
---
fs/partitions/check.c | 38 ++++++++++++++++++++++++++++++-------- include/linux/genhd.h | 1 + 2 files changed, 31 insertions(+), 8 deletions(-)
d4d7e5dffc4844ef51fe11f497bd774c04413a00
fs/partitions/check.c +30 -8
@@ -331,7 +331,9 @@ void delete_partition(struct gendisk *didevfs_remove ("%s/part%d" , disk->devfs_name, part);if (p->holder_dir)kobject_unregister (p->holder_dir); -kobject_unregister (&p->kobj); +kobject_uevent (&p->kobj,KOBJ_REMOVE ); +kobject_del (&p->kobj); +kobject_put (&p->kobj); }void add_partition (struct gendisk *disk,int part,sector_t start,sector_t len)
@@ -357,7 +359,10 @@ void add_partition(struct gendisk *disk,snprintf (p->kobj.name,KOBJ_NAME_LEN ,"%s%d" ,disk->kobj.name,part); p->kobj.parent = &disk->kobj; p->kobj.ktype = &ktype_part; -kobject_register (&p->kobj); +kobject_init (&p->kobj); +kobject_add (&p->kobj); +if (!disk->part_uevent_suppress) +kobject_uevent (&p->kobj,KOBJ_ADD );partition_sysfs_add_subdir (p); disk->part[part-1 ] = p; }
@@ -395,6 +400,8 @@ void register_disk(struct gendisk *disk) {struct block_device *bdev;char *s; +int i; +struct hd_struct *p;int err;strlcpy (disk->kobj.name,disk->disk_name,KOBJ_NAME_LEN );
@@ -406,13 +413,12 @@ void register_disk(struct gendisk *disk)return ;disk_sysfs_symlinks (disk);disk_sysfs_add_subdirs (disk); -kobject_uevent (&disk->kobj,KOBJ_ADD );/* No minors to use for partitions */ if (disk->minors ==1 ) {if (disk->devfs_name[0 ] !='\0' )devfs_add_disk (disk); -return ; + goto exit; }/* always add handle for the whole disk */
@@ -420,16 +426,32 @@ void register_disk(struct gendisk *disk)/* No such device (e.g., media were just removed) */ if (!get_capacity (disk)) -return ; + goto exit; bdev =bdget_disk (disk,0 );if (!bdev) -return ; + goto exit; +/* scan partition table, but suppress uevents */ bdev->bd_invalidated =1 ; -if (blkdev_get (bdev,FMODE_READ ,0 ) <0 ) -return ; + disk->part_uevent_suppress =1 ; + err =blkdev_get (bdev,FMODE_READ ,0 ); + disk->part_uevent_suppress =0 ; +if (err <0 ) + goto exit;blkdev_put (bdev); + +exit: +/* announce disk after possible partitions are already created */ +kobject_uevent (&disk->kobj,KOBJ_ADD ); + +/* announce possible partitions */ +for (i =1 ; i < disk->minors; i++) { + p = disk->part[i-1 ]; +if (!p || !p->nr_sects) +continue ; +kobject_uevent (&p->kobj,KOBJ_ADD ); + } }int rescan_partitions (struct gendisk *disk,struct block_device *bdev)
include/linux/genhd.h +1 -0
@@ -105,6 +105,7 @@ struct gendisk {* disks that can't be partitioned. */ char disk_name[32 ];/* name of major driver */ struct hd_struct **part;/* [indexed by minor] */ +int part_uevent_suppress;struct block_device_operations *fops;struct request_queue *queue;void *private_data;
Signature · 1 line
1.2.6
PATCH 4/7 driver core: fix unnecessary NULL check in drivers/base/class.c
This patch tries to fix an issue in drivers/base/class.c, please review and apply if correct.
Patch Description:
"parent_class" is checked for NULL already, so removed the unnecessary check.
---
drivers/base/class.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
a14388904ca67197c9a531dba2358d8131697865
drivers/base/class.c +6 -7
@@ -562,14 +562,13 @@ int class_device_add(struct class_devicekobject_uevent (&class_dev->kobj,KOBJ_ADD );/* notify any interfaces this device is now here */ -if (parent_class) { -down (&parent_class->sem); -list_add_tail (&class_dev->node, &parent_class->children); -list_for_each_entry (class_intf, &parent_class->interfaces, node) -if (class_intf->add) - class_intf->add (class_dev, class_intf); -up (&parent_class->sem); +down (&parent_class->sem); +list_add_tail (&class_dev->node, &parent_class->children); +list_for_each_entry (class_intf, &parent_class->interfaces, node) { +if (class_intf->add) + class_intf->add (class_dev, class_intf); } +up (&parent_class->sem); register_done:if (error) {
Signature · 1 line
1.2.6
PATCH 5/7 driver core: driver_bind attribute returns incorrect value
The manual driver <-> device binding attribute in sysfs doesn't return the correct value on failure or success of driver_probe_device. driver_probe_device returns 1 on success (the driver accepted the device) or 0 on probe failure (when the driver didn't accept the device but no real error occured). However, the attribute can't just return 0 or 1, it must return the number of bytes consumed from buf or an error value. Returning 0 indicates to userspace that nothing was written (even though the kernel has tried to do the bind/probe and failed). Returning 1 indicates that only one character was accepted in which case userspace will re-try the write with a partial string.
A more correct version of driver_bind would return count (to indicate the entire string was consumed) when driver_probe_device returns 1 and -ENODEV when driver_probe_device returns 0. This patch makes that change.
---
drivers/base/bus.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
372254018eb1b65ee69210d11686bfc65c8d84db
drivers/base/bus.c +5 -0
@@ -188,6 +188,11 @@ static ssize_t driver_bind(struct deviceup (&dev->sem);if (dev->parent)up (&dev->parent->sem); + +if (err >0 )/* success */ + err = count; +else if (err ==0 )/* driver didn't accept device */ + err = -ENODEV ; }put_device (dev);put_bus (bus);
Signature · 1 line
1.2.6
PATCH 6/7 pm: print name of failed suspend function
Print more diagnostic info to help identify the source of power management suspend failures.
Example:
usb_hcd_pci_suspend(): pci_set_power_state+0x0/0x1af() returns -22 pci_device_suspend(): usb_hcd_pci_suspend+0x0/0x11b() returns -22 suspend_device(): pci_device_suspend+0x0/0x34() returns -22
Work-in-progress. It needs lots more suspend_report_result() calls sprinkled everywhere.
---
drivers/base/power/suspend.c | 12 ++++++++++++ drivers/pci/pci-driver.c | 6 ++++-- drivers/pci/pci.c | 6 ++++-- drivers/usb/core/hcd-pci.c | 7 +++---- include/linux/pm.h | 8 ++++++++ 5 files changed, 31 insertions(+), 8 deletions(-)
026694920579590c73b5c56705d543568ed5ad41
drivers/base/power/suspend.c +12 -0
@@ -10,6 +10,8 @@#include <linux/vt_kern.h> #include <linux/device.h> +#include <linux/kallsyms.h> +#include <linux/pm.h> #include "../base.h" #include "power.h"
@@ -58,6 +60,7 @@ int suspend_device(struct device * dev,if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) {dev_dbg (dev,"suspending\n" ); error = dev->bus->suspend (dev, state); +suspend_report_result (dev->bus->suspend, error); }up (&dev->sem);return error;
@@ -169,3 +172,12 @@ int device_power_down(pm_message_t stateEXPORT_SYMBOL_GPL (device_power_down); +void __suspend_report_result (const char *function,void *fn,int ret) +{ +if (ret) { +printk (KERN_ERR "%s(): " , function); +print_fn_descriptor_symbol ("%s() returns " , (unsigned long )fn); +printk ("%d\n" , ret); + } +} +EXPORT_SYMBOL_GPL (__suspend_report_result);
drivers/pci/pci-driver.c +4 -2
@@ -271,10 +271,12 @@ static int pci_device_suspend(struct devstruct pci_driver * drv = pci_dev->driver;int i =0 ; -if (drv && drv->suspend) +if (drv && drv->suspend) { i = drv->suspend (pci_dev, state); -else +suspend_report_result (drv->suspend, i); + }else {pci_save_state (pci_dev); + }return i; }
drivers/pci/pci.c +4 -2
@@ -307,9 +307,11 @@ pci_set_power_state(struct pci_dev *dev,* Can enter D0 from any state, but if we can only go deeper * to sleep if we're already in a low power state */ -if (state !=PCI_D0 && dev->current_state > state) +if (state !=PCI_D0 && dev->current_state > state) { +printk (KERN_ERR "%s(): %s: state=%d, current state=%d\n" , + __FUNCTION__,pci_name (dev), state, dev->current_state);return -EINVAL ; -else if (dev->current_state == state) + }else if (dev->current_state == state)return 0 ;/* we're already there */ /* find PCI PM capability in list */
drivers/usb/core/hcd-pci.c +3 -4
@@ -213,11 +213,9 @@ int usb_hcd_pci_suspend (struct pci_devif (hcd->driver->suspend) { retval = hcd->driver->suspend (hcd, message); -if (retval) { -dev_dbg (&dev->dev,"PCI pre-suspend fail, %d\n" , - retval); +suspend_report_result (hcd->driver->suspend, retval); +if (retval) goto done; - } }synchronize_irq (dev->irq);
@@ -263,6 +261,7 @@ int usb_hcd_pci_suspend (struct pci_dev* some device state (e.g. as part of clock reinit). */ retval =pci_set_power_state (dev, PCI_D3hot); +suspend_report_result (pci_set_power_state, retval);if (retval ==0 ) {int wake =device_can_wakeup (&hcd->self.root_hub->dev);
include/linux/pm.h +8 -0
@@ -199,6 +199,12 @@ extern int device_suspend(pm_message_t sextern int dpm_runtime_suspend (struct device *,pm_message_t );extern void dpm_runtime_resume (struct device *); +extern void __suspend_report_result (const char *function,void *fn,int ret); + +#define suspend_report_result (fn, ret) \ + do { \ + __suspend_report_result(__FUNCTION__, fn, ret); \ + } while (0)#else /* !CONFIG_PM */
@@ -219,6 +225,8 @@ static inline void dpm_runtime_resume(st { } +#define suspend_report_result (fn, ret) do { } while (0) +#endif /* changes to device_may_wakeup take effect on the next pm state change.
Signature · 1 line
1.2.6
PATCH 7/7 DMI: move dmi_scan.c from arch/i386 to drivers/firmware/
dmi_scan.c is arch-independent and is used by i386, x86_64, and ia64. Currently all three arches compile it from arch/i386, which means that ia64 and x86_64 depend on things in arch/i386 that they wouldn't otherwise care about.
This is simply "mv arch/i386/kernel/dmi_scan.c drivers/firmware/" (removing trailing whitespace) and the associated Makefile changes. All three architectures already set CONFIG_DMI in their top-level Kconfig files.
---
arch/i386/kernel/Makefile | 2 arch/i386/kernel/dmi_scan.c | 358 ------------------------------------------- arch/ia64/kernel/Makefile | 3 arch/x86_64/kernel/Makefile | 4 drivers/firmware/Makefile | 3 drivers/firmware/dmi_scan.c | 358 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 363 insertions(+), 365 deletions(-) delete mode 100644 arch/i386/kernel/dmi_scan.c create mode 100644 drivers/firmware/dmi_scan.c
4f705ae3e94ffaafe8d35f71ff4d5c499bb06814
arch/i386/kernel/Makefile +1 -1
@@ -6,7 +6,7 @@ extra-y := head.o init_task.o vmlinux.ld obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o \ ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \ - pci-dma.o i386_ksyms.o i387.o dmi_scan.o bootflag.o \ + pci-dma.o i386_ksyms.o i387.o bootflag.o \ quirks.o i8237.o topology.o alternative.o obj-y += cpu/
arch/i386/kernel/dmi_scan.c deleted +0 -358
358 lines not on this page · raw message
arch/ia64/kernel/Makefile +1 -2
@@ -7,7 +7,7 @@ extra-y := head.o init_task.o vmlinux.ld obj-y := acpi.o entry.o efi.o efi_stub.o gate-data.o fsys.o ia64_ksyms.o irq.o irq_ia64.o \ irq_lsapic.o ivt.o machvec.o pal.o patch.o process.o perfmon.o ptrace.o sal.o \ salinfo.o semaphore.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \ - unwind.o mca.o mca_asm.o topology.o dmi_scan.o + unwind.o mca.o mca_asm.o topology.o obj-$(CONFIG_IA64_BRL_EMU) += brl_emu.o obj-$(CONFIG_IA64_GENERIC) += acpi-ext.o
@@ -30,7 +30,6 @@ obj-$(CONFIG_IA64_MCA_RECOVERY) += mca_r obj-$(CONFIG_KPROBES) += kprobes.o jprobes.o obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o mca_recovery-y += mca_drv.o mca_drv_asm.o -dmi_scan-y += ../../i386/kernel/dmi_scan.o # The gate DSO image is built using a special linker script. targets += gate.so gate-syms.o
arch/x86_64/kernel/Makefile +1 -3
@@ -8,7 +8,7 @@ obj-y := process.o signal.o entry.o trap ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \ x8664_ksyms.o i387.o syscall.o vsyscall.o \ setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \ - dmi_scan.o pci-dma.o pci-nommu.o + pci-dma.o pci-nommu.o obj-$(CONFIG_X86_MCE) += mce.o obj-$(CONFIG_X86_MCE_INTEL) += mce_intel.o
@@ -49,5 +49,3 @@ intel_cacheinfo-y += ../../i386/kernel/ quirks-y += ../../i386/kernel/quirks.o i8237-y += ../../i386/kernel/i8237.o msr-$(subst m,y,$(CONFIG_X86_MSR)) += ../../i386/kernel/msr.o -dmi_scan-y += ../../i386/kernel/dmi_scan.o -
drivers/firmware/Makefile +2 -1
@@ -1,7 +1,8 @@ # # Makefile for the linux kernel. # -obj-$(CONFIG_EDD) += edd.o +obj-$(CONFIG_DMI) += dmi_scan.o +obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_PCDP) += pcdp.o obj-$(CONFIG_DELL_RBU) += dell_rbu.o
drivers/firmware/dmi_scan.c new file +358 -0
358 lines not on this page · raw message
Signature · 1 line
1.2.6