procfs overflow fixes and seq_file conversions
The following changes since commit 113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizes
are available in the git repository at:
git://git.xenomai.org/xenomai-jki.git queues/proc
This series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in /proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.
The future belongs to seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."
Jan Kiszka (9):
hal: Mark file ops of rthal_add_proc_seq const
RTDM: Plug race between proc_read_dev_info and device deregistration
RTDM: Properly clean up on proc setup errors
RTDM: Convert fildes proc to single-seq
RTDM: Convert device information proc entry to single-seq
RTDM: Convert open_fildes reading to seq_file
RTDM: Extend device name space in open_fildes proc output
RTDM: Convert device listings to seq_file
nucleus: Convert heap proc entry to seq_file
Wolfgang Mauerer (14):
nucleus: Convert irq proc entry to seqfile
nucleus: Convert faults proc entry to seq_file mechanism
nucleus: Convert apc proc file to the seq_file mechanism
nucleus: Add infrastructure for supporting the seq_file mechanism in
registry objects
native: Convert the alarm registry proc entry to seq_single
native: Convert buffer registry proc entry to the seq_file mechanism
native: Convert cond registry proc entry to the seq_file mechanism
native: convert the proc entry for the semaphore registry to seq_file
native: Convert intr registry proc files to seq_file
native: Convert event registry proc file to seq_file
native: Convert heap registry proc file to seq_file
native: Convert mutex registry proc entry to seq_file
native: Convert queue registry proc entry to seq_file
nucleus: Convert timebases proc entry to seq_file
include/asm-generic/hal.h | 8 +- include/nucleus/registry.h | 19 +- ksrc/arch/generic/hal.c | 269 +++++++++++++++++++------ ksrc/nucleus/heap.c | 121 +++++++++-- ksrc/nucleus/intr.c | 149 ++++++++------ ksrc/nucleus/registry.c | 14 ++- ksrc/nucleus/timebase.c | 64 +++--- ksrc/skins/native/alarm.c | 43 ++-- ksrc/skins/native/buffer.c | 46 +++-- ksrc/skins/native/cond.c | 36 ++-- ksrc/skins/native/event.c | 40 ++-- ksrc/skins/native/heap.c | 50 +++--- ksrc/skins/native/intr.c | 44 ++-- ksrc/skins/native/mutex.c | 42 ++-- ksrc/skins/native/queue.c | 44 ++-- ksrc/skins/native/sem.c | 38 ++-- ksrc/skins/rtdm/device.c | 21 +-- ksrc/skins/rtdm/internal.h | 19 ++ ksrc/skins/rtdm/proc.c | 481 +++++++++++++++++++++++++++++--------------- 19 files changed, 1008 insertions(+), 540 deletions(-)
PATCH 1/23 hal: Mark file ops of rthal_add_proc_seq const
From: Jan Kiszka <[email protected]>
Older kernels do not have this tag but do not touch them as well, so perform a type cast when assigning them to proc_dir_entry.
--- include/asm-generic/hal.h | 2 +- ksrc/arch/generic/hal.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/asm-generic/hal.h +1 -1
@@ -554,7 +554,7 @@ struct proc_dir_entry *rthal_add_proc_leaf(const char *name, struct proc_dir_entry *parent);struct proc_dir_entry *rthal_add_proc_seq (const char *name, -struct file_operations *fops, +const struct file_operations *fops,size_t size,struct proc_dir_entry *parent);#endif /* CONFIG_PROC_FS */
ksrc/arch/generic/hal.c +2 -2
@@ -748,7 +748,7 @@ struct proc_dir_entry *rthal_add_proc_leaf(const char *name,EXPORT_SYMBOL_GPL (rthal_add_proc_leaf);struct proc_dir_entry *rthal_add_proc_seq (const char *name, -struct file_operations *fops, +const struct file_operations *fops,size_t size,struct proc_dir_entry *parent) {
@@ -758,7 +758,7 @@ struct proc_dir_entry *rthal_add_proc_seq(const char *name,if (entry ==NULL )return NULL ; - entry->proc_fops = fops; + entry->proc_fops = (struct file_operations *)fops;wrap_proc_dir_entry_owner (entry);if (size)
Signature · 1 line
1.6.0.2
PATCH 2/23 RTDM: Plug race between proc_read_dev_info and device deregistration
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
As the device references passed to proc_read_dev_info may become invalid while we dereference it, we need to acquire nrt_dev_lock and check the pointer against our list of registered devices.
--- ksrc/skins/rtdm/proc.c | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-)
ksrc/skins/rtdm/proc.c +26 -3
@@ -203,11 +203,33 @@ static int proc_read_fildes(char *buf, char **start, off_t offset, static int proc_read_dev_info(char *buf, char **start, off_t offset, int count, int *eof, void *data) { - /* accessing the device during unregister (remove_proc_entry) might be - racy, but no official workaround is known yet */ - struct rtdm_device *device = data; + struct rtdm_device *device; + int i; RTDM_PROC_PRINT_VARS(256); + if (down_interruptible(&nrt_dev_lock)) + return -ERESTARTSYS; + + /* + * As the device may have disappeared while the handler was called, + * first match the pointer against registered devices. + */ + for (i = 0; i < devname_hashtab_size; i++) + list_for_each_entry(device, &rtdm_named_devices[i], + reserved.entry) + if (device == data) + goto found; + + for (i = 0; i < protocol_hashtab_size; i++) + list_for_each_entry(device, &rtdm_protocol_devices[i], + reserved.entry) + if (device == data) + goto found; + + up(&nrt_dev_lock); + return -ENODEV; + +found: if (!RTDM_PROC_PRINT("driver:\t\t%s\nversion:\t%d.%d.%d\n", device->driver_name, RTDM_DRIVER_MAJOR_VER(device->driver_version),
@@ -232,6 +254,7 @@ static int proc_read_dev_info(char *buf, char **start, off_t offset, atomic_read(&device->reserved.refcount)); done: +up (&nrt_dev_lock);RTDM_PROC_PRINT_DONE ; }
Signature · 1 line
1.6.0.2
PATCH 3/23 RTDM: Properly clean up on proc setup errors
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
--- ksrc/skins/rtdm/proc.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
ksrc/skins/rtdm/proc.c +9 -5
@@ -292,34 +292,38 @@ int __init rtdm_proc_init(void)/* Initialise /proc entries */ rtdm_proc_root =create_proc_entry ("xenomai/rtdm" ,S_IFDIR ,NULL );if (!rtdm_proc_root) -return -EAGAIN ; + goto error; proc_entry =create_proc_entry ("named_devices" ,S_IFREG |S_IRUGO , rtdm_proc_root);if (!proc_entry) -return -EAGAIN ; + goto error; proc_entry->read_proc = proc_read_named_devs; proc_entry =create_proc_entry ("protocol_devices" ,S_IFREG |S_IRUGO , rtdm_proc_root);if (!proc_entry) -return -EAGAIN ; + goto error; proc_entry->read_proc = proc_read_proto_devs; proc_entry =create_proc_entry ("open_fildes" ,S_IFREG |S_IRUGO , rtdm_proc_root);if (!proc_entry) -return -EAGAIN ; + goto error; proc_entry->read_proc = proc_read_open_fildes; proc_entry->write_proc = proc_kill_open_fildes; proc_entry =create_proc_entry ("fildes" ,S_IFREG |S_IRUGO , rtdm_proc_root);if (!proc_entry) -return -EAGAIN ; + goto error; proc_entry->read_proc = proc_read_fildes;return 0 ; + +error: +rtdm_proc_cleanup (); +return -EAGAIN ; }void rtdm_proc_cleanup (void )
Signature · 1 line
1.6.0.2
PATCH 4/23 RTDM: Convert fildes proc to single-seq
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
As read_proc is deprecated and will die soon, we have to convert to single-seq. Start with RTDM's fildes proc entry.
--- ksrc/skins/rtdm/proc.c | 31 ++++++++++++++++++++----------- 1 files changed, 20 insertions(+), 11 deletions(-)
ksrc/skins/rtdm/proc.c +20 -11
@@ -17,6 +17,8 @@* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <linux/seq_file.h> +#include "rtdm/internal.h" /* Derived from Erwin Rol's rtai_proc_fs.h.
@@ -189,17 +191,26 @@ static int proc_kill_open_fildes(struct file *file, const char __user *buffer,return count; } -static int proc_read_fildes (char *buf,char **start,off_t offset, -int count,int *eof,void *data) +static int fildes_show (struct seq_file *seq,void *v) { -RTDM_PROC_PRINT_VARS (80 ); - -RTDM_PROC_PRINT ("total=%d:open=%d:free=%d\n" ,RTDM_FD_MAX , - open_fildes,RTDM_FD_MAX - open_fildes); +seq_printf (seq,"total=%d:open=%d:free=%d\n" , +RTDM_FD_MAX , open_fildes,RTDM_FD_MAX - open_fildes); +return 0 ; +} -RTDM_PROC_PRINT_DONE ; +static int fildes_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, fildes_show,NULL ); } +static const struct file_operations fildes_operations = { + .owner =THIS_MODULE , + .open = fildes_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static int proc_read_dev_info (char *buf,char **start,off_t offset,int count,int *eof,void *data) {
@@ -313,11 +324,9 @@ int __init rtdm_proc_init(void) proc_entry->read_proc = proc_read_open_fildes; proc_entry->write_proc = proc_kill_open_fildes; - proc_entry = -create_proc_entry ("fildes" ,S_IFREG |S_IRUGO , rtdm_proc_root); -if (!proc_entry) +if (!rthal_add_proc_seq ("fildes" , &fildes_operations,0 , + rtdm_proc_root)) goto error; - proc_entry->read_proc = proc_read_fildes;return 0 ;
Signature · 1 line
1.6.0.2
PATCH 5/23 RTDM: Convert device information proc entry to single-seq
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
--- ksrc/skins/rtdm/proc.c | 77 ++++++++++++++++++++++++++++-------------------- 1 files changed, 45 insertions(+), 32 deletions(-)
ksrc/skins/rtdm/proc.c +45 -32
@@ -211,12 +211,10 @@ static const struct file_operations fildes_operations = { .release = single_release, }; -static int proc_read_dev_info (char *buf,char **start,off_t offset, -int count,int *eof,void *data) +static int dev_info_show (struct seq_file *seq,void *v) {struct rtdm_device *device;int i; -RTDM_PROC_PRINT_VARS (256 );if (down_interruptible (&nrt_dev_lock))return -ERESTARTSYS ;
@@ -228,47 +226,63 @@ static int proc_read_dev_info(char *buf, char **start, off_t offset,for (i =0 ; i < devname_hashtab_size; i++)list_for_each_entry (device, &rtdm_named_devices[i], reserved.entry) -if (device == data) +if (device == seq->private) goto found;for (i =0 ; i < protocol_hashtab_size; i++)list_for_each_entry (device, &rtdm_protocol_devices[i], reserved.entry) -if (device == data) +if (device == seq->private) goto found;up (&nrt_dev_lock);return -ENODEV ; found: -if (!RTDM_PROC_PRINT ("driver:\t\t%s\nversion:\t%d.%d.%d\n" , - device->driver_name, -RTDM_DRIVER_MAJOR_VER (device->driver_version), -RTDM_DRIVER_MINOR_VER (device->driver_version), -RTDM_DRIVER_PATCH_VER (device->driver_version))) - goto done; -if (!RTDM_PROC_PRINT ("peripheral:\t%s\nprovider:\t%s\n" , - device->peripheral_name, device->provider_name)) - goto done; -if (!RTDM_PROC_PRINT ("class:\t\t%d\nsub-class:\t%d\n" , - device->device_class, device->device_sub_class)) - goto done; -if (!RTDM_PROC_PRINT ("flags:\t\t%s%s%s\n" , - (device->device_flags &RTDM_EXCLUSIVE ) ? -"EXCLUSIVE " :"" , - (device->device_flags &RTDM_NAMED_DEVICE ) ? -"NAMED_DEVICE " :"" , - (device->device_flags &RTDM_PROTOCOL_DEVICE ) ? -"PROTOCOL_DEVICE " :"" )) - goto done; -RTDM_PROC_PRINT ("lock count:\t%d\n" , -atomic_read (&device->reserved.refcount)); +seq_printf (seq,"driver:\t\t%-64s\nversion:\t%d.%d.%d\n" , + device->driver_name, +RTDM_DRIVER_MAJOR_VER (device->driver_version), +RTDM_DRIVER_MINOR_VER (device->driver_version), +RTDM_DRIVER_PATCH_VER (device->driver_version)); +seq_printf (seq,"peripheral:\t%-64s\nprovider:\t%-64s\n" , + device->peripheral_name, device->provider_name); +seq_printf (seq,"class:\t\t%d\nsub-class:\t%d\n" , + device->device_class, device->device_sub_class); +seq_printf (seq,"flags:\t\t%s%s%s\n" , + (device->device_flags &RTDM_EXCLUSIVE ) ? +"EXCLUSIVE " :"" , + (device->device_flags &RTDM_NAMED_DEVICE ) ? +"NAMED_DEVICE " :"" , + (device->device_flags &RTDM_PROTOCOL_DEVICE ) ? +"PROTOCOL_DEVICE " :"" ); +seq_printf (seq,"lock count:\t%d\n" , +atomic_read (&device->reserved.refcount)); - done:up (&nrt_dev_lock); -RTDM_PROC_PRINT_DONE ; +return 0 ; +} + +static int dev_info_proc_open (struct inode *inode,struct file *file) +{ +struct seq_file *seq; +int err; + + err =single_open (file, dev_info_show,NULL ); +if (!err) { + seq = file->private_data; + seq->private =PDE (inode)->data; + } +return err; } +static const struct file_operations dev_info_operations = { + .owner =THIS_MODULE , + .open = dev_info_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +int rtdm_proc_register_device (struct rtdm_device *device) {struct proc_dir_entry *dev_dir;
@@ -278,14 +292,13 @@ int rtdm_proc_register_device(struct rtdm_device *device)if (!dev_dir) goto err_out; - proc_entry =create_proc_entry ("information" ,S_IFREG |S_IRUGO , - dev_dir); + proc_entry =rthal_add_proc_seq ("information" , &dev_info_operations, +0 , dev_dir);if (!proc_entry) {remove_proc_entry (device->proc_name, rtdm_proc_root); goto err_out; } proc_entry->data = device; - proc_entry->read_proc = proc_read_dev_info; device->proc_entry = dev_dir;
Signature · 1 line
1.6.0.2
PATCH 6/23 RTDM: Convert open_fildes reading to seq_file
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This avoids overflows in case the number of open file descriptors gets too high.
--- ksrc/skins/rtdm/proc.c | 119 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 80 insertions(+), 39 deletions(-)
ksrc/skins/rtdm/proc.c +80 -39
@@ -76,6 +76,10 @@ static int proc_read_named_devs(char *buf, char **start, off_t offset,RTDM_PROC_PRINT_DONE ; } +static void dummy_seq_stop (struct seq_file *seq,void *v) +{ +} +static int proc_read_proto_devs (char *buf,char **start,off_t offset,int count,int *eof,void *data) {
@@ -111,61 +115,90 @@ static int proc_read_proto_devs(char *buf, char **start, off_t offset,RTDM_PROC_PRINT_DONE ; } -static int proc_read_open_fildes (char *buf,char **start,off_t offset, -int count,int *eof,void *data) +static void *open_fildes_seq_start (struct seq_file *seq,loff_t *pos) { -int i; -int close_lock_count; +if (*pos >RTDM_FD_MAX ) +return NULL ; + +if (*pos ==0 ) +return SEQ_START_TOKEN ; + +return &fildes_table[*pos -1 ]; +} + +static void *open_fildes_seq_next (struct seq_file *seq,void *v,loff_t *pos) +{ + ++*pos; + +if (*pos >RTDM_FD_MAX ) +return NULL ; + +return &fildes_table[*pos -1 ]; +} + +static int open_fildes_seq_show (struct seq_file *seq,void *v) +{ +struct rtdm_fildes *fildes = v; +struct rtdm_dev_context *context;struct rtdm_device *device;struct rtdm_process owner; +int close_lock_count;spl_t s; -RTDM_PROC_PRINT_VARS (80 ); -if (!RTDM_PROC_PRINT ("Index\tLocked\tDevice\t\tOwner [PID]\n" )) - goto done; +if (v ==SEQ_START_TOKEN ) { +seq_printf (seq,"Index\tLocked\tDevice\t\tOwner [PID]\n" ); +return 0 ; + }if (down_interruptible (&nrt_dev_lock))return -ERESTARTSYS ; -for (i =0 ; i <RTDM_FD_MAX ; i++) { -struct rtdm_dev_context *context; - -xnlock_get_irqsave (&rt_fildes_lock, s); +xnlock_get_irqsave (&rt_fildes_lock, s); - context = fildes_table[i].context; -if (!context) { -xnlock_put_irqrestore (&rt_fildes_lock, s); -continue ; - } + context = fildes->context; +if (!context) { +xnlock_put_irqrestore (&rt_fildes_lock, s); + goto unlock_out; + } - close_lock_count =atomic_read (&context->close_lock_count); - device = context->device; + close_lock_count =atomic_read (&context->close_lock_count); + device = context->device; -if (context->reserved.owner) -memcpy (&owner, context->reserved.owner,sizeof (owner)); -else { -strcpy (owner.name,"<kernel>" ); - owner.pid =-1 ; - } +if (context->reserved.owner) +memcpy (&owner, context->reserved.owner,sizeof (owner)); +else { +strcpy (owner.name,"<kernel>" ); + owner.pid =-1 ; + } -xnlock_put_irqrestore (&rt_fildes_lock, s); +xnlock_put_irqrestore (&rt_fildes_lock, s); -if (!RTDM_PROC_PRINT ("%d\t%d\t%-15s %s [%d]\n" , i, - close_lock_count, - (device->device_flags&RTDM_NAMED_DEVICE ) ? - device->device_name : device->proc_name, - owner.name, owner.pid)) -break ; - } +seq_printf (seq,"%d\t%d\t%-15s %s [%d]\n" , + (int )(fildes - fildes_table), close_lock_count, + (device->device_flags &RTDM_NAMED_DEVICE ) ? + device->device_name : device->proc_name, + owner.name, owner.pid); +unlock_out:up (&nrt_dev_lock); +return 0 ; +} - done: -RTDM_PROC_PRINT_DONE ; +static const struct seq_operations open_fildes_op = { + .start = open_fildes_seq_start, + .next = open_fildes_seq_next, + .stop = dummy_seq_stop, + .show = open_fildes_seq_show +}; + +static int open_fildes_seq_open (struct inode *inode,struct file *file) +{ +return seq_open (file, &open_fildes_op); } -static int proc_kill_open_fildes (struct file *file,const char __user *buffer, -unsigned long count,void *data) +static ssize_t +proc_kill_open_fildes (struct file *file,const char __user *buffer, +size_t count,loff_t *ppos) {char krnl_buf[32 ];int fd;
@@ -191,6 +224,15 @@ static int proc_kill_open_fildes(struct file *file, const char __user *buffer,return count; } +static const struct file_operations open_fildes_operations = { + .owner =THIS_MODULE , + .open = open_fildes_seq_open, + .read = seq_read, + .write = proc_kill_open_fildes, + .llseek = seq_lseek, + .release = seq_release_private, +}; +static int fildes_show (struct seq_file *seq,void *v) { seq_printf(seq, "total=%d:open=%d:free=%d\n",
@@ -331,11 +373,10 @@ int __init rtdm_proc_init(void) proc_entry->read_proc = proc_read_proto_devs; proc_entry = -create_proc_entry ("open_fildes" ,S_IFREG |S_IRUGO , rtdm_proc_root); +rthal_add_proc_seq ("open_fildes" , &open_fildes_operations,0 , + rtdm_proc_root);if (!proc_entry) goto error; - proc_entry->read_proc = proc_read_open_fildes; - proc_entry->write_proc = proc_kill_open_fildes;if (!rthal_add_proc_seq ("fildes" , &fildes_operations,0 , rtdm_proc_root))
Signature · 1 line
1.6.0.2
PATCH 7/23 RTDM: Extend device name space in open_fildes proc output
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Device names can be up to 31 characters long.
--- ksrc/skins/rtdm/proc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
ksrc/skins/rtdm/proc.c +2 -2
@@ -146,7 +146,7 @@ static int open_fildes_seq_show(struct seq_file *seq, void *v)spl_t s;if (v ==SEQ_START_TOKEN ) { -seq_printf (seq,"Index\tLocked\tDevice\t\tOwner [PID]\n" ); +seq_printf (seq,"Index\tLocked\tDevice\t\t\t\tOwner [PID]\n" );return 0 ; }
@@ -173,7 +173,7 @@ static int open_fildes_seq_show(struct seq_file *seq, void *v)xnlock_put_irqrestore (&rt_fildes_lock, s); - seq_printf(seq, "%d\t%d\t%-15s %s [%d]\n", + seq_printf(seq, "%d\t%d\t%-31s %s [%d]\n", (int)(fildes - fildes_table), close_lock_count, (device->device_flags & RTDM_NAMED_DEVICE) ? device->device_name : device->proc_name,
Signature · 1 line
1.6.0.2
PATCH 8/23 RTDM: Convert device listings to seq_file
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Given a large amount of devices, we could overflow the output page so far. Fix it by moving to seq_file operations. This also allows us to drop the RTDM_PROC_PRINT macros, now that the last user is converted.
--- ksrc/skins/rtdm/device.c | 21 +---- ksrc/skins/rtdm/internal.h | 19 ++++ ksrc/skins/rtdm/proc.c | 221 +++++++++++++++++++++++++++++--------------- 3 files changed, 168 insertions(+), 93 deletions(-)
ksrc/skins/rtdm/device.c +2 -19
@@ -55,8 +55,8 @@ MODULE_PARM_DESC(protocol_hashtab_size,struct list_head *rtdm_named_devices;/* hash table */ struct list_head *rtdm_protocol_devices;/* hash table */ -static int name_hashkey_mask; -static int proto_hashkey_mask; +int name_hashkey_mask; +int proto_hashkey_mask;DECLARE_MUTEX (nrt_dev_lock);DEFINE_XNLOCK (rt_dev_lock);
@@ -77,23 +77,6 @@ int rtdm_select_bind_no_support(struct rtdm_dev_context *context, {return -EBADF ; } - -static inline int get_name_hash (const char *str,int limit,int hashkey_mask) -{ -int hash =0 ; - -while (*str !=0 ) { - hash += *str++; -if (--limit ==0 ) -break ; - } -return hash & hashkey_mask; -} - -static inline int get_proto_hash (int protocol_family,int socket_type) -{ -return protocol_family & proto_hashkey_mask; -}static inline void rtdm_reference_device (struct rtdm_device *device) {
ksrc/skins/rtdm/internal.h +19 -0
@@ -59,6 +59,8 @@ extern int open_fildes;extern struct semaphore nrt_dev_lock;extern unsigned int devname_hashtab_size;extern unsigned int protocol_hashtab_size; +extern int name_hashkey_mask; +extern int proto_hashkey_mask;extern struct list_head *rtdm_named_devices;extern struct list_head *rtdm_protocol_devices;extern struct proc_dir_entry *rtdm_proc_root;
@@ -79,6 +81,23 @@ static inline void rtdm_dereference_device(struct rtdm_device *device)atomic_dec (&device->reserved.refcount); } +static inline int get_name_hash (const char *str,int limit,int hashkey_mask) +{ +int hash =0 ; + +while (*str !=0 ) { + hash += *str++; +if (--limit ==0 ) +break ; + } +return hash & hashkey_mask; +} + +static inline int get_proto_hash (int protocol_family,int socket_type) +{ +return protocol_family & proto_hashkey_mask; +} +int __init rtdm_dev_init (void );static inline void rtdm_dev_cleanup (void )
ksrc/skins/rtdm/proc.c +147 -74
264 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 9/23 nucleus: Convert heap proc entry to seq_file
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This fixes buffer overflows when large number of heaps are registered.
--- ksrc/nucleus/heap.c | 121 +++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 98 insertions(+), 23 deletions(-)
ksrc/nucleus/heap.c +98 -23
@@ -1409,16 +1409,69 @@ void xnheap_destroy_mapped(xnheap_t *heap,#ifdef CONFIG_PROC_FS -#include <linux/proc_fs.h> +#include <linux/seq_file.h> + +struct heap_seq_iterator { +int nentries; +struct heap_seq_info { +u_long usable_mem; +u_long used_mem; +u_long page_size; +char label[XNOBJECT_NAME_LEN ]; + } heap_info[1 ]; +}; + +static void *heap_seq_start (struct seq_file *seq,loff_t *pos) +{ +struct heap_seq_iterator *iter = seq->private; + +if (*pos >= iter->nentries) +return NULL ; + +return iter->heap_info + *pos; +} + +static void *heap_seq_next (struct seq_file *seq,void *v,loff_t *pos) +{ +struct heap_seq_iterator *iter = seq->private; + + ++*pos; -static int heap_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +if (*pos >= iter->nentries) +return NULL ; + +return iter->heap_info + *pos; +} + +static void heap_seq_stop (struct seq_file *seq,void *v) +{ +} + +static int heap_seq_show (struct seq_file *seq,void *v) { +struct heap_seq_info *p = v; + +seq_printf (seq,"size=%lu:used=%lu:pagesz=%lu (%s)\n" , + p->usable_mem, p->used_mem, p->page_size, p->label); +return 0 ; +} + +static const struct seq_operations heap_op = { + .start = heap_seq_start, + .next = heap_seq_next, + .stop = heap_seq_stop, + .show = heap_seq_show +}; + +static int heap_seq_open (struct inode *inode,struct file *file) +{ +struct heap_seq_iterator *iter =NULL ; +struct heap_seq_info *heap_info; +struct seq_file *seq;unsigned long rev;xnholder_t *entry;xnheap_t *heap; -int len; +int count, err;spl_t s;if (!xnpod_active_p ())
@@ -1427,17 +1480,38 @@ static int heap_read_proc(char *page,xnlock_get_irqsave (&nklock, s); restart: - len =0 ; + count =countq (&heapq);/* Cannot be empty (system heap) */ + rev = heapq_rev; + +xnlock_put_irqrestore (&nklock, s); + +kfree (iter); + iter =kmalloc (sizeof (*iter) + + (count -1 ) *sizeof (struct heap_seq_info ), +GFP_KERNEL ); +if (!iter) +return -ENOMEM ; + + err =seq_open (file, &heap_op); +if (err) { +kfree (iter); +return err; + } + + iter->nentries =0 ; + +xnlock_get_irqsave (&nklock, s); entry =getheadq (&heapq);while (entry) { heap =container_of (entry, xnheap_t, stat_link); - len +=sprintf (page + len, -"size=%lu:used=%lu:pagesz=%lu (%s)\n" , -xnheap_usable_mem (heap), -xnheap_used_mem (heap), -xnheap_page_size (heap), - heap->label); + heap_info = &iter->heap_info[iter->nentries++]; + + heap_info->usable_mem =xnheap_usable_mem (heap); + heap_info->used_mem =xnheap_used_mem (heap); + heap_info->page_size =xnheap_page_size (heap); +memcpy (heap_info->label, heap->label, +sizeof (heap_info->label)); rev = heapq_rev;
@@ -1451,22 +1525,23 @@ restart:xnlock_put_irqrestore (&nklock, s); - len -= off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; + seq = file->private_data; + seq->private = iter; -return len; +return 0 ; } +static const struct file_operations heap_operations = { + .owner =THIS_MODULE , + .open = heap_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release_private, +}; +void xnheap_init_proc (void ) { -rthal_add_proc_leaf ("heap" , &heap_read_proc,NULL ,NULL , - rthal_proc_root); +rthal_add_proc_seq ("heap" , &heap_operations,0 , rthal_proc_root); }void xnheap_cleanup_proc (void )
Signature · 1 line
1.6.0.2
PATCH 10/23 nucleus: Convert irq proc entry to seqfile
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
On a system with many CPUs, the size of the data can exceed a single page.
--- ksrc/nucleus/intr.c | 149 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 90 insertions(+), 59 deletions(-)
ksrc/nucleus/intr.c +90 -59
@@ -984,27 +984,27 @@ int xnintr_query_next(int irq, xnintr_iterator_t *iterator, char *name_buf)#ifdef CONFIG_PROC_FS #include <linux/proc_fs.h> +#include <linux/seq_file.h> #include <linux/ctype.h> -static int format_irq_proc (unsigned int irq,char *str) +static void format_irq_proc (unsigned int irq,struct seq_file *f) {xnintr_t *intr; -char *p = str;spl_t s;if (rthal_virtual_irq_p (irq)) { - p +=sprintf (p," [virtual]" ); -return p - str; +seq_puts (f," [virtual]" ); +return ; }else if (irq ==XNARCH_TIMER_IRQ ) { - p +=sprintf (p," [timer]" ); -return p - str; +seq_puts (f," [timer]" ); +return ; #ifdef CONFIG_SMP }else if (irq ==RTHAL_SERVICE_IPI0 ) { - p +=sprintf (p," [IPI]" ); -return p - str; +seq_puts (f," [IPI]" ); +return ; }else if (irq ==RTHAL_CRITICAL_IPI ) { - p +=sprintf (p," [critical sync]" ); -return p - str; +seq_puts (f," [critical sync]" ); +return ;#endif /* CONFIG_SMP */ }
@@ -1012,61 +1012,17 @@ static int format_irq_proc(unsigned int irq, char *str) intr =xnintr_shirq_first (irq);if (intr) { -strcpy (p," " ); p +=8 ; +seq_puts (f," " );do { - *p =' ' ; p +=1 ; -strcpy (p, intr->name); p +=strlen (intr->name); +seq_putc (f,' ' ); +seq_printf (f,"%s" , intr->name); intr =xnintr_shirq_next (intr); }while (intr); }xnlock_put_irqrestore (&intrlock, s); - -return p - str; -} - -static int irq_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) -{ -int len =0 , cpu, irq; -char *p = page; - - p +=sprintf (p,"IRQ " ); - -for_each_online_cpu (cpu) { - p +=sprintf (p," CPU%d" , cpu); - } - -for (irq =0 ; irq <XNARCH_NR_IRQS ; irq++) { -if (rthal_irq_handler (&rthal_domain, irq) ==NULL ) -continue ; - - p +=sprintf (p,"\n%3d:" , irq); - -for_each_online_cpu (cpu) { - p +=sprintf (p,"%12lu" , -rthal_cpudata_irq_hits (&rthal_domain, cpu, - irq)); - } - - p +=format_irq_proc (irq, p); - } - - p +=sprintf (p,"\n" ); - - len = p - page - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; - -return len; }#ifdef CONFIG_SMP
@@ -1094,6 +1050,75 @@ static int affinity_read_proc(char *page,return len; } +static void *irq_seq_start (struct seq_file *seq,loff_t *pos) +{ +/* +* Note: Position 0 is the header, so we need to +* use <= instead of < +*/ +return (*pos <=XNARCH_NR_IRQS ) ? pos :NULL ; +} + +static void irq_seq_stop (struct seq_file *f,void *v) +{ +/* Nothing to do */ +} + +static void *irq_seq_next (struct seq_file *f,void *v,loff_t *pos) +{ + (*pos)++; + +if (*pos >XNARCH_NR_IRQS ) +return NULL ; + +return pos; +} + +static int irq_seq_show (struct seq_file *f,void *v) +{ +unsigned int i = *(loff_t *) v; +unsigned int irq, cpu; + +if (i ==0 ) { +seq_puts (f,"IRQ " ); +for_each_online_cpu (cpu) { +seq_printf (f," CPU%u" , cpu); + } +seq_putc (f,'\n' ); + +return 0 ; + } + + irq = i -1 ; +if (rthal_irq_handler (&rthal_domain, irq) ==NULL ) +return 0 ; + +seq_printf (f,"%3d:" , irq); + +for_each_online_cpu (cpu) { +seq_printf (f,"%12lu" , +rthal_cpudata_irq_hits (&rthal_domain, cpu, + irq)); + } + +format_irq_proc (irq, f); +seq_putc (f,'\n' ); + +return 0 ; +} + +static struct seq_operations irq_seq_ops = { + .start = irq_seq_start, + .next = irq_seq_next, + .stop = irq_seq_stop, + .show = irq_seq_show, +}; + +static int irq_open (struct inode *inode,struct file *filp) +{ +return seq_open (filp, &irq_seq_ops); +} +static int affinity_write_proc (struct file *file,const char __user * buffer,unsigned long count,void *data)
@@ -1124,10 +1149,16 @@ static int affinity_write_proc(struct file *file, }#endif /* CONFIG_SMP */ +static struct file_operations irq_seq_operations = { + .open = irq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; +void xnintr_init_proc (void ) { -rthal_add_proc_leaf ("irq" , &irq_read_proc,NULL ,NULL , - rthal_proc_root); +rthal_add_proc_seq ("irq" , &irq_seq_operations,0 , rthal_proc_root);#ifdef CONFIG_SMP rthal_add_proc_leaf ("affinity" , &affinity_read_proc, &affinity_write_proc,NULL , rthal_proc_root);
Signature · 1 line
1.6.0.2
PATCH 11/23 nucleus: Convert faults proc entry to seq_file mechanism
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
The entries depend on the number of CPUs and can thus overflow a single page.
--- ksrc/arch/generic/hal.c | 148 +++++++++++++++++++++++++++++++++++++---------- 1 files changed, 118 insertions(+), 30 deletions(-)
ksrc/arch/generic/hal.c +118 -30
@@ -47,6 +47,7 @@#include <asm/xenomai/hal.h> #ifdef CONFIG_PROC_FS #include <linux/proc_fs.h> +#include <linux/seq_file.h> #endif /* CONFIG_PROC_FS */ #include <stdarg.h>
@@ -642,46 +643,133 @@ static int hal_read_proc(char *page,return len; } -static int faults_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +struct faults_seq_iterator { +unsigned int nentries; +struct faults_seq_info { +unsigned int trap; + } faults_info[0 ]; +}; + +static int __faults_seq_open (struct inode *inode, +struct file *file,struct seq_operations *ops) { -int len =0 , cpu, trap; -char *p = page; +struct faults_seq_iterator *iter =NULL ; +struct faults_seq_info *faults_info; +struct seq_file *seq; +unsigned int ntraps =0 ; +unsigned int trap; +int err; + +for (trap =0 ; rthal_fault_labels[trap] !=NULL ; trap++) { +if (!*rthal_fault_labels[trap]) +continue ; + ntraps++; + } - p +=sprintf (p,"TRAP " ); + iter =kmalloc (sizeof (*iter) + + ntraps *sizeof (struct faults_seq_info ), +GFP_KERNEL ); +if (!iter) +return -ENOMEM ; -for_each_online_cpu (cpu) { - p +=sprintf (p," CPU%d" , cpu); - } + err =seq_open (file, ops); -for (trap =0 ; rthal_fault_labels[trap] !=NULL ; trap++) { +if (err) { +kfree (iter); +return err; + } -if (!*rthal_fault_labels[trap]) -continue ; + iter->nentries =0 ; - p +=sprintf (p,"\n%3d: " , trap); +for (trap =0 ; rthal_fault_labels[trap] !=NULL ; trap++) { +if (!*rthal_fault_labels[trap]) +continue ; -for_each_online_cpu (cpu) { - p +=sprintf (p,"%12u" , rthal_realtime_faults[cpu][trap]); - } + faults_info = &iter->faults_info[iter->nentries++]; - p +=sprintf (p," (%s)" , rthal_fault_labels[trap]); - } + faults_info->trap = trap; + } - p +=sprintf (p,"\n" ); + seq = file->private_data; + seq->private = iter; - len = p - page - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static void *faults_seq_start (struct seq_file *seq,loff_t *pos) +{ +struct faults_seq_iterator *iter = seq->private; + +if (*pos > iter->nentries) +return NULL ; + +if (*pos ==0 ) +return SEQ_START_TOKEN ; + +return iter->faults_info + *pos -1 ; } +static void *faults_seq_next (struct seq_file *seq,void *v,loff_t *pos) +{ +struct faults_seq_iterator *iter = seq->private; + + (*pos)++; + +if (*pos > iter->nentries) +return NULL ; + +return iter->faults_info + *pos -1 ; +} + +static void faults_seq_stop (struct seq_file *f,void *v) +{ +/* Nothing to do */ +} + +static int faults_seq_show (struct seq_file *f,void *v) +{ +unsigned int cpu; +struct faults_seq_info *p = v; + +if (v ==SEQ_START_TOKEN ) { +seq_puts (f,"TRAP " ); + +for_each_online_cpu (cpu) { +seq_printf (f," CPU%d\n" , cpu); + } + } +else { +seq_printf (f,"%3d: " , p->trap); + +for_each_online_cpu (cpu) { +seq_printf (f,"%12u" , + rthal_realtime_faults[cpu][p->trap]); + } + +seq_printf (f," (%s)\n" , rthal_fault_labels[p->trap]); + } + +return 0 ; +} + +static struct seq_operations faults_op = { + .start = faults_seq_start, + .next = faults_seq_next, + .stop = faults_seq_stop, + .show = faults_seq_show +}; + +static int faults_seq_open (struct inode *inode,struct file *file) +{ +return __faults_seq_open (inode, file, &faults_op); +} + +static struct file_operations faults_seq_operations = { + .owner =THIS_MODULE , + .open = faults_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release_private, +}; static int apc_read_proc(char *page, char **start,
@@ -779,8 +867,8 @@ static int rthal_proc_register(void)wrap_proc_dir_entry_owner (rthal_proc_root);rthal_add_proc_leaf ("hal" , &hal_read_proc,NULL ,NULL , rthal_proc_root); -rthal_add_proc_leaf ("faults" , - &faults_read_proc,NULL ,NULL , rthal_proc_root); +rthal_add_proc_seq ("faults" , &faults_seq_operations,0 , + rthal_proc_root);rthal_add_proc_leaf ("apc" , &apc_read_proc,NULL ,NULL , rthal_proc_root);rthal_nmi_proc_register ();
Signature · 1 line
1.6.0.2
PATCH 12/23 nucleus: Convert apc proc file to the seq_file mechanism
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
Same procedure as last year, Miss Sophie?
Same procedure as every year, James.
--- ksrc/arch/generic/hal.c | 99 ++++++++++++++++++++++++++++++++++------------- 1 files changed, 72 insertions(+), 27 deletions(-)
ksrc/arch/generic/hal.c +72 -27
@@ -771,47 +771,92 @@ static struct file_operations faults_seq_operations = { .release = seq_release_private, }; -static int apc_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +static inline void *apc_seq_find_valid_pos (loff_t *pos) { -int len =0 , cpu, apc; -char *p = page; +while (!(*pos >BITS_PER_LONG ) && + !test_bit (*pos -1 , &rthal_apc_map)) { + (*pos)++; + } - p +=sprintf (p,"APC " ); +if (*pos >BITS_PER_LONG ) { +return NULL ; + } -for_each_online_cpu (cpu) { - p +=sprintf (p," CPU%d" , cpu); - } +return pos; +} -for (apc =0 ; apc <BITS_PER_LONG ; apc++) { -if (!test_bit (apc, &rthal_apc_map)) -continue ;/* Not hooked. */ +static void *apc_seq_start (struct seq_file *seq,loff_t *pos) +{ +/* The header is valid, naturally */ +if (*pos ==0 ) +return pos; - p +=sprintf (p,"\n%3d: " , apc); +return apc_seq_find_valid_pos (pos); +} + +static void apc_seq_stop (struct seq_file *f,void *v) +{ +/* Nothing to do */ +} + +static void *apc_seq_next (struct seq_file *f,void *v,loff_t *pos) +{ + (*pos)++; + +return apc_seq_find_valid_pos (pos); +} + +static int apc_seq_show (struct seq_file *f,void *v) +{ +unsigned int i = *(loff_t *) v; +unsigned int apc, cpu; + +if (i ==0 ) { +seq_puts (f,"APC " ); +for_each_online_cpu (cpu) { +seq_printf (f," CPU%u" , cpu); + } +seq_putc (f,'\n' ); + +return 0 ; + } + + apc = i -1 ; + +seq_printf (f,"%3d: " , apc);for_each_online_cpu (cpu) { - p +=sprintf (p,"%12lu" , rthal_apc_table[apc].hits[cpu]); +seq_printf (f,"%12lu" , rthal_apc_table[apc].hits[cpu]); }if (rthal_apc_table[apc].name) - p +=sprintf (p," (%s)" , rthal_apc_table[apc].name); - } +seq_printf (f," (%s)" , rthal_apc_table[apc].name); - p +=sprintf (p,"\n" ); +seq_putc (f,'\n' ); - len = p - page - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static struct seq_operations apc_seq_ops = { + .start = apc_seq_start, + .next = apc_seq_next, + .stop = apc_seq_stop, + .show = apc_seq_show, +}; + +static int apc_open (struct inode *inode,struct file *filp) +{ +return seq_open (filp, &apc_seq_ops); } +static struct file_operations apc_seq_operations = { + .open = apc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + + struct proc_dir_entry *rthal_add_proc_leaf(const char *name, read_proc_t rdproc, write_proc_t wrproc,
@@ -869,7 +914,7 @@ static int rthal_proc_register(void)rthal_add_proc_leaf ("hal" , &hal_read_proc,NULL ,NULL , rthal_proc_root);rthal_add_proc_seq ("faults" , &faults_seq_operations,0 , rthal_proc_root); -rthal_add_proc_leaf ("apc" , &apc_read_proc,NULL ,NULL , rthal_proc_root); +rthal_add_proc_seq ("apc" , &apc_seq_operations,0 , rthal_proc_root);rthal_nmi_proc_register ();
Signature · 1 line
1.6.0.2
PATCH 13/23 nucleus: Add infrastructure for supporting the seq_file mechanism in registry objects
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
We augment struct xnpnode with a new element for representing file_operations that allow for using more generic file system methods than read_proc. However, we have to retain read_proc and write_proc for now since not all proc entries are immediately converted. However, we should be able to get rid of them in the future because writing can as well be implemented in conjunction to the seq_file mechanism.
NOTE: When the proc file depends on a data argument given to registry_enter, it can be obtained in seq_open via PDE(inode)->data. In turn, it should be associated with the seq_file instance, which is easy enough for single_open (just use it as third argument). It must be done manually for seq_open; note that seq_file is available as file->private after the call. ((struct seq_file *)file->private)->private = PDE(inode)->data is your friend.
--- include/asm-generic/hal.h | 6 ++++++ include/nucleus/registry.h | 19 ++++++++++++------- ksrc/arch/generic/hal.c | 18 ++++++++++++++++++ ksrc/nucleus/registry.c | 14 +++++++++++++- 4 files changed, 49 insertions(+), 8 deletions(-)
include/asm-generic/hal.h +6 -0
@@ -557,6 +557,12 @@ struct proc_dir_entry *rthal_add_proc_seq(const char *name,const struct file_operations *fops, size_t size, struct proc_dir_entry *parent); + +struct proc_dir_entry *rthal_add_proc_seq_data (const char *name, +const struct file_operations *fops, +size_t size, +void *data, +struct proc_dir_entry *parent);#endif /* CONFIG_PROC_FS */ #ifdef CONFIG_IPIPE_TRACE
include/nucleus/registry.h +12 -7
@@ -73,6 +73,7 @@ void xnregistry_cleanup(void);#ifdef CONFIG_PROC_FS #include <linux/proc_fs.h> +#include <linux/fs.h> #define XNOBJECT_PROC_RESERVED1 ((struct proc_dir_entry *)1)#define XNOBJECT_PROC_RESERVED2 ((struct proc_dir_entry *)2)
@@ -90,13 +91,17 @@ typedef struct xnptree {typedef struct xnpnode { -struct proc_dir_entry *dir; -const char *type; -int entries; -read_proc_t *read_proc; -write_proc_t *write_proc; -link_proc_t *link_proc; -xnptree_t *root; +struct proc_dir_entry *dir; +const char *type; +int entries; + +/* NOTE: Use either read_proc/write_proc, link_proc or fops. */ +read_proc_t *read_proc; +write_proc_t *write_proc; +link_proc_t *link_proc; +struct file_operations *fops; + +xnptree_t *root; }xnpnode_t ;
ksrc/arch/generic/hal.c +18 -0
@@ -901,6 +901,24 @@ struct proc_dir_entry *rthal_add_proc_seq(const char *name, }EXPORT_SYMBOL_GPL (rthal_add_proc_seq); +struct proc_dir_entry +*rthal_add_proc_seq_data (const char *name, +const struct file_operations *fops, +size_t size, +void *data, +struct proc_dir_entry *parent) +{ +struct proc_dir_entry *entry; + + entry =rthal_add_proc_seq (name, fops, size, parent); + +if (entry) + entry->data = data; + +return entry; +} +EXPORT_SYMBOL_GPL (rthal_add_proc_seq_data); +static int rthal_proc_register (void ) { rthal_proc_root =create_proc_entry ("xenomai" ,S_IFDIR ,0 );
ksrc/nucleus/registry.c +13 -1
@@ -338,8 +338,20 @@ static DECLARE_WORK_FUNC(registry_proc_callback) object->proc =add_proc_link (object->key, pnode->link_proc, object->objaddr, dir); + else if (pnode->fops) +/* Entry is a proper file */ + object->proc = rthal_add_proc_seq_data(object->key, + pnode->fops, +0 , + object->objaddr, + dir); else -/* Entry allows to get/set object properties. */ +/* +* Entry allows us to get/set object properties +* via read/write_proc. Note that this type +* is deprecated since support in the Linux kernel +* will go away. +*/ object->proc = rthal_add_proc_leaf(object->key, pnode->read_proc, pnode->write_proc,
Signature · 1 line
1.6.0.2
PATCH 14/23 native: Convert the alarm registry proc entry to seq_single
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/alarm.c | 43 +++++++++++++++++++++++-------------------- 1 files changed, 23 insertions(+), 20 deletions(-)
ksrc/skins/native/alarm.c +23 -20
@@ -45,20 +45,18 @@#ifdef CONFIG_PROC_FS -static int __alarm_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int alarm_seq_show (struct seq_file *f,void *v) { -RT_ALARM *alarm = (RT_ALARM *)data; -char *p = page; -int len; +RT_ALARM *alarm = (RT_ALARM *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s); - p +=sprintf (p,"interval=%Lu:expiries=%lu\n" , -rt_timer_tsc2ns (xntimer_interval (&alarm->timer_base)), - alarm->expiries); +seq_printf (f,"interval=%Lu:expiries=%lu\n" , +rt_timer_tsc2ns (xntimer_interval (&alarm->timer_base)), + alarm->expiries);#ifdef CONFIG_XENO_OPT_PERVASIVE {
@@ -67,7 +65,7 @@ static int __alarm_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&alarm->synch_base), holder);
@@ -77,18 +75,22 @@ static int __alarm_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int alarm_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, alarm_seq_show,PDE (inode)->data); } +static struct file_operations alarm_proc_fops = { + .owner =THIS_MODULE , + .open = alarm_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; + +extern xnptree_t __native_ptree;static xnpnode_t __alarm_pnode = {
@@ -96,8 +98,9 @@ static xnpnode_t __alarm_pnode = { .dir = NULL, .type = "alarms", .entries = 0, - .read_proc = &__alarm_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &alarm_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 15/23 native: Convert buffer registry proc entry to the seq_file mechanism
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/buffer.c | 46 ++++++++++++++++++++++--------------------- 1 files changed, 24 insertions(+), 22 deletions(-)
ksrc/skins/native/buffer.c +24 -22
@@ -50,21 +50,19 @@#ifdef CONFIG_PROC_FS -static int __buffer_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int buffer_seq_show (struct seq_file *f,void *v) { -RT_BUFFER *bf = (RT_BUFFER *)data; -char *p = page; -int len; +RT_BUFFER *bf = (RT_BUFFER *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s); - p +=sprintf (p,"type=%s:size=%zu:used=%zu\n" , - bf->mode &B_PRIO ?"PRIO" :"FIFO" , - bf->bufsz, - bf->fillsz); +seq_printf (f,"type=%s:size=%zu:used=%zu\n" , + bf->mode &B_PRIO ?"PRIO" :"FIFO" , + bf->bufsz, + bf->fillsz);if (xnsynch_nsleepers (&bf->isynch_base) >0 ) {xnpholder_t *holder;
@@ -73,7 +71,7 @@ static int __buffer_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s (input)\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s (input)\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&bf->isynch_base), holder);
@@ -87,7 +85,7 @@ static int __buffer_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s (output)\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s (output)\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&bf->osynch_base), holder);
@@ -96,18 +94,21 @@ static int __buffer_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int buffer_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, buffer_seq_show,PDE (inode)->data); } +static struct file_operations buffer_proc_fops = { + .owner =THIS_MODULE , + .open = buffer_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __buffer_pnode = {
@@ -115,8 +116,9 @@ static xnpnode_t __buffer_pnode = { .dir = NULL, .type = "buffers", .entries = 0, - .read_proc = &__buffer_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &buffer_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 16/23 native: Convert cond registry proc entry to the seq_file mechanism
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/cond.c | 36 +++++++++++++++++++----------------- 1 files changed, 19 insertions(+), 17 deletions(-)
ksrc/skins/native/cond.c +19 -17
@@ -50,13 +50,11 @@#ifdef CONFIG_PROC_FS -static int __cond_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int cond_seq_show (struct seq_file *f,void *v) { -RT_COND *cond = (RT_COND *)data; -char *p = page; -int len; +RT_COND *cond = (RT_COND *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s);
@@ -70,7 +68,7 @@ static int __cond_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&cond->synch_base), holder);
@@ -79,18 +77,21 @@ static int __cond_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int cond_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, cond_seq_show,PDE (inode)->data); } +static struct file_operations cond_proc_fops = { + .owner =THIS_MODULE , + .open = cond_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __cond_pnode = {
@@ -98,8 +99,9 @@ static xnpnode_t __cond_pnode = { .dir = NULL, .type = "condvars", .entries = 0, - .read_proc = &__cond_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &cond_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 17/23 native: convert the proc entry for the semaphore registry to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/sem.c | 38 ++++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 18 deletions(-)
ksrc/skins/native/sem.c +20 -18
@@ -50,20 +50,18 @@#ifdef CONFIG_PROC_FS -static int __sem_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int sem_seq_show (struct seq_file *f,void *v) { -RT_SEM *sem = (RT_SEM *)data; -char *p = page; -int len; +RT_SEM *sem = (RT_SEM *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s);if (xnsynch_nsleepers (&sem->synch_base) ==0 )/* Idle/posted semaphore -- dump count. */ - p +=sprintf (p,"=%lu\n" , sem->count); +seq_printf (f,"=%lu\n" , sem->count);else {xnpholder_t *holder;
@@ -73,7 +71,7 @@ static int __sem_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&sem->synch_base), holder);
@@ -82,18 +80,21 @@ static int __sem_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int sem_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, sem_seq_show,PDE (inode)->data); } +static struct file_operations sem_proc_fops = { + .owner =THIS_MODULE , + .open = sem_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __sem_pnode = {
@@ -101,8 +102,9 @@ static xnpnode_t __sem_pnode = { .dir = NULL, .type = "semaphores", .entries = 0, - .read_proc = &__sem_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &sem_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 18/23 native: Convert intr registry proc files to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/intr.c | 44 +++++++++++++++++++++++--------------------- 1 files changed, 23 insertions(+), 21 deletions(-)
ksrc/skins/native/intr.c +23 -21
@@ -58,13 +58,11 @@ static unsigned long __intr_get_hits(RT_INTR *intr)#ifdef CONFIG_PROC_FS -static int __intr_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int intr_seq_show (struct seq_file *f,void *v) { -RT_INTR *intr = (RT_INTR *)data; -char *p = page; -int len; +RT_INTR *intr = (RT_INTR *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s);
@@ -73,9 +71,9 @@ static int __intr_read_proc(char *page, {xnpholder_t *holder; - p +=sprintf (p,"hits=%lu, pending=%u, mode=0x%x\n" , -__intr_get_hits (intr), intr->pending, - intr->mode); +seq_printf (f,"hits=%lu, pending=%u, mode=0x%x\n" , +__intr_get_hits (intr), intr->pending, + intr->mode);/* Pended interrupt -- dump waiters. */
@@ -83,30 +81,33 @@ static int __intr_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&intr->synch_base), holder); } }#else /* !CONFIG_XENO_OPT_PERVASIVE */ - p +=sprintf (p,"hits=%lu\n" ,__intr_get_hits (intr)); +seq_printf (f,"hits=%lu\n" ,__intr_get_hits (intr));#endif /* CONFIG_XENO_OPT_PERVASIVE */ xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int intr_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, intr_seq_show,PDE (inode)->data); } +static struct file_operations intr_proc_fops = { + .owner =THIS_MODULE , + .open = intr_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree; static xnpnode_t __intr_pnode = {
@@ -114,8 +115,9 @@ static xnpnode_t __intr_pnode = { .dir = NULL, .type = "interrupts", .entries = 0, - .read_proc = &__intr_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &intr_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 19/23 native: Convert event registry proc file to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/event.c | 40 +++++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 19 deletions(-)
ksrc/skins/native/event.c +21 -19
@@ -47,18 +47,16 @@#ifdef CONFIG_PROC_FS -static int __event_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int event_seq_show (struct seq_file *f,void *v) { -RT_EVENT *event = (RT_EVENT *)data; -char *p = page; -int len; +RT_EVENT *event = (RT_EVENT *)f->private;spl_t s;xnlock_get_irqsave (&nklock, s); - p +=sprintf (p,"=0x%lx\n" , event->value); +seq_printf (f,"=0x%lx\n" , event->value);if (xnsynch_nsleepers (&event->synch_base) >0 ) {xnpholder_t *holder;
@@ -74,8 +72,8 @@ static int __event_read_proc(char *page, (task->wait_args.event. mode &EV_ANY ) ?"any" :"all" ;unsigned long mask = task->wait_args.event.mask; - p +=sprintf (p,"+%s (mask=0x%lx, %s)\n" , -xnthread_name (sleeper), mask, mode); +seq_printf (f,"+%s (mask=0x%lx, %s)\n" , +xnthread_name (sleeper), mask, mode); holder =nextpq (xnsynch_wait_queue (&event->synch_base), holder);
@@ -84,18 +82,21 @@ static int __event_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int event_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, event_seq_show,PDE (inode)->data); } +static struct file_operations event_proc_fops = { + .owner =THIS_MODULE , + .open = event_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __event_pnode = {
@@ -103,8 +104,9 @@ static xnpnode_t __event_pnode = { .dir = NULL, .type = "events", .entries = 0, - .read_proc = &__event_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &event_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 20/23 native: Convert heap registry proc file to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/heap.c | 50 +++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 24 deletions(-)
ksrc/skins/native/heap.c +26 -24
@@ -51,21 +51,19 @@#ifdef CONFIG_PROC_FS -static int __heap_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int heap_seq_show (struct seq_file *f,void *v) { -RT_HEAP *heap = (RT_HEAP *)data; -char *p = page; -int len; +RT_HEAP *heap = (RT_HEAP *)f->private;spl_t s; - p +=sprintf (p,"type=%s:size=%lu:used=%lu:numaps=%lu\n" , - (heap->mode &H_SHARED ) ==H_SHARED ?"shared" : - (heap->mode &H_MAPPABLE ) ?"mappable" :"kernel" , -xnheap_usable_mem (&heap->heap_base), -xnheap_used_mem (&heap->heap_base), - heap->heap_base.archdep.numaps); +seq_printf (f,"type=%s:size=%lu:used=%lu:numaps=%lu\n" , + (heap->mode &H_SHARED ) ==H_SHARED ?"shared" : + (heap->mode &H_MAPPABLE ) ?"mappable" :"kernel" , +xnheap_usable_mem (&heap->heap_base), +xnheap_used_mem (&heap->heap_base), + heap->heap_base.archdep.numaps);xnlock_get_irqsave (&nklock, s);
@@ -79,8 +77,8 @@ static int __heap_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink);size_t size = sleeper->wait_u.buffer.size; - p +=sprintf (p,"+%s (size=%zd)\n" , -xnthread_name (sleeper), size); +seq_printf (f,"+%s (size=%zd)\n" , +xnthread_name (sleeper), size); holder =nextpq (xnsynch_wait_queue (&heap->synch_base), holder);
@@ -89,18 +87,21 @@ static int __heap_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int heap_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, heap_seq_show,PDE (inode)->data); } +static struct file_operations heap_proc_fops = { + .owner =THIS_MODULE , + .open = heap_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __heap_pnode = {
@@ -108,8 +109,9 @@ static xnpnode_t __heap_pnode = { .dir = NULL, .type = "heaps", .entries = 0, - .read_proc = &__heap_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &heap_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 21/23 native: Convert mutex registry proc entry to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/mutex.c | 42 ++++++++++++++++++++++-------------------- 1 files changed, 22 insertions(+), 20 deletions(-)
ksrc/skins/native/mutex.c +22 -20
@@ -53,17 +53,15 @@#ifdef CONFIG_PROC_FS -static int __mutex_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int mutex_seq_show (struct seq_file *f,void *v) { -RT_MUTEX *mutex = (RT_MUTEX *)data; +RT_MUTEX *mutex = (RT_MUTEX *)f->private;#ifdef CONFIG_XENO_FASTSYNCH xnhandle_t lock_state;#endif /* CONFIG_XENO_FASTSYNCH */ xnthread_t *owner; -char *p = page; -int len;spl_t s;xnlock_get_irqsave (&nklock, s);
@@ -77,42 +75,45 @@ static int __mutex_read_proc(char *page,xnthread_lookup (xnsynch_fast_mask_claimed (lock_state));if (!owner && lock_state !=XN_NO_HANDLE ) - p +=sprintf (p,"=<DAMAGED HANDLE!>" ); +seq_printf (f,"=<DAMAGED HANDLE!>" ); else#endif /* CONFIG_XENO_FASTSYNCH */ if (owner) {/* Locked mutex -- dump owner and waiters, if any. */ xnpholder_t *holder; - p +=sprintf (p,"=locked by %s\n" ,xnthread_name (owner)); +seq_printf (f,"=locked by %s\n" ,xnthread_name (owner)); holder =getheadpq (xnsynch_wait_queue (&mutex->synch_base));while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&mutex->synch_base), holder); } }else /* Mutex unlocked. */ - p +=sprintf (p,"=unlocked\n" ); +seq_printf (f,"=unlocked\n" );xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int mutex_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, mutex_seq_show,PDE (inode)->data); } +static struct file_operations mutex_proc_fops = { + .owner =THIS_MODULE , + .open = mutex_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __mutex_pnode = {
@@ -120,8 +121,9 @@ static xnpnode_t __mutex_pnode = { .dir = NULL, .type = "mutexes", .entries = 0, - .read_proc = &__mutex_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &mutex_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 22/23 native: Convert queue registry proc entry to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
--- ksrc/skins/native/queue.c | 44 +++++++++++++++++++++++--------------------- 1 files changed, 23 insertions(+), 21 deletions(-)
ksrc/skins/native/queue.c +23 -21
@@ -49,19 +49,17 @@#ifdef CONFIG_PROC_FS -static int __queue_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +#include <linux/seq_file.h> + +static int queue_seq_show (struct seq_file *f,void *v) { -RT_QUEUE *q = (RT_QUEUE *)data; -char *p = page; -int len; +RT_QUEUE *q = (RT_QUEUE *)f->private;spl_t s; - p +=sprintf (p,"type=%s:poolsz=%lu:usedmem=%lu:limit=%d:mcount=%d\n" , - q->mode &Q_SHARED ?"shared" :"local" , -xnheap_usable_mem (&q->bufpool),xnheap_used_mem (&q->bufpool), - q->qlimit,countq (&q->pendq)); +seq_printf (f,"type=%s:poolsz=%lu:usedmem=%lu:limit=%d:mcount=%d\n" , + q->mode &Q_SHARED ?"shared" :"local" , +xnheap_usable_mem (&q->bufpool),xnheap_used_mem (&q->bufpool), + q->qlimit,countq (&q->pendq));xnlock_get_irqsave (&nklock, s);
@@ -74,7 +72,7 @@ static int __queue_read_proc(char *page,while (holder) {xnthread_t *sleeper =link2thread (holder, plink); - p +=sprintf (p,"+%s\n" ,xnthread_name (sleeper)); +seq_printf (f,"+%s\n" ,xnthread_name (sleeper)); holder =nextpq (xnsynch_wait_queue (&q->synch_base), holder); }
@@ -82,18 +80,21 @@ static int __queue_read_proc(char *page,xnlock_put_irqrestore (&nklock, s); - len = (p - page) - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +return 0 ; +} -return len; +static int queue_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, queue_seq_show,PDE (inode)->data); } +static struct file_operations queue_proc_fops = { + .owner =THIS_MODULE , + .open = queue_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +extern xnptree_t __native_ptree;static xnpnode_t __queue_pnode = {
@@ -101,8 +102,9 @@ static xnpnode_t __queue_pnode = { .dir = NULL, .type = "queues", .entries = 0, - .read_proc = &__queue_read_proc, + .read_proc = NULL, .write_proc = NULL, + .fops = &queue_proc_fops, .root = &__native_ptree, };
Signature · 1 line
1.6.0.2
PATCH 23/23 nucleus: Convert timebases proc entry to seq_file
In reply to Jan KiszkaFrom: Wolfgang Mauerer <[email protected]>
Admittedly, the proc page cannot overflow right now, but since the number of time bases is at least in theory unlimited, let's convert the file while we are at it. Also properly take the nklock when accessing the nktimebase list.
--- ksrc/nucleus/timebase.c | 64 +++++++++++++++++++++++++---------------------- 1 files changed, 34 insertions(+), 30 deletions(-)
ksrc/nucleus/timebase.c +34 -30
@@ -810,57 +810,61 @@ void xntbase_remove_proc(xntbase_t *base)#endif /* CONFIG_XENO_OPT_STATS */ -static int timebase_read_proc (char *page, -char **start, -off_t off,int count,int *eof,void *data) +static int timebase_seq_show (struct seq_file *f,void *v) {xnholder_t *holder;xntbase_t *tbase; -char *p = page; -int len =0 ; +spl_t s; + +seq_printf (f,"%-10s %10s %10s %s\n" , +"NAME" ,"RESOLUTION" ,"JIFFIES" ,"STATUS" ); - p +=sprintf (p,"%-10s %10s %10s %s\n" , -"NAME" ,"RESOLUTION" ,"JIFFIES" ,"STATUS" ); +xnlock_get_irqsave (&nklock, s);for (holder =getheadq (&nktimebaseq); holder !=NULL ; holder =nextq (&nktimebaseq, holder)) { tbase =link2tbase (holder);if (xntbase_periodic_p (tbase)) - p +=sprintf (p,"%-10s %10lu %10Lu %s%s%s\n" , - tbase->name, - tbase->tickvalue, - tbase->jiffies, -xntbase_enabled_p (tbase) ?"enabled" :"disabled" , -xntbase_timeset_p (tbase) ?",set" :",unset" , -xntbase_isolated_p (tbase) ?",isolated" :"" ); +seq_printf (f,"%-10s %10lu %10Lu %s%s%s\n" , + tbase->name, + tbase->tickvalue, + tbase->jiffies, +xntbase_enabled_p (tbase) ?"enabled" :"disabled" , +xntbase_timeset_p (tbase) ?",set" :",unset" , +xntbase_isolated_p (tbase) ?",isolated" :"" );else - p +=sprintf (p,"%-10s %10s %10s %s\n" , - tbase->name, -"1" , -"n/a" , -"enabled,set" ); +seq_printf (f,"%-10s %10s %10s %s\n" , + tbase->name, +"1" , +"n/a" , +"enabled,set" ); } - len = p - page - off; -if (len <= off + count) - *eof =1 ; - *start = page + off; -if (len > count) - len = count; -if (len <0 ) - len =0 ; +xnlock_put_irqrestore (&nklock, s); + +return 0 ; +} -return len; +static int timebase_seq_open (struct inode *inode,struct file *file) +{ +return single_open (file, timebase_seq_show,NULL ); } +static struct file_operations timebase_proc_fops = { + .owner =THIS_MODULE , + .open = timebase_seq_open, + .read = seq_read, + .llseek = seq_lseek, +}; +void xntbase_init_proc (void ) {#ifdef CONFIG_XENO_OPT_STATS tmstat_proc_root =create_proc_entry ("timerstat" ,S_IFDIR , rthal_proc_root);#endif /* CONFIG_XENO_OPT_STATS */ -rthal_add_proc_leaf ("timebases" , &timebase_read_proc,NULL ,NULL , - rthal_proc_root); +rthal_add_proc_seq ("timebases" , &timebase_proc_fops,0 , + rthal_proc_root); }void xntbase_cleanup_proc (void )
Signature · 1 line
1.6.0.2
Quoted 15 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.
Quoted 6 lines
The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."
Did you already have a chance to look into this series?
Jan
Quoted 16 lines · Jan Kiszka
Quoted 15 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.
Quoted 8 lines
Quoted 6 lines
The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."Did you already have a chance to look into this series?
Not yet, that is a big series. With a high potential for kernel crashes, memory leaks and other things like that. I am trying to find a way to test it. Maybe we can try and run it with kmemcheck?
Signature · 1 line
Gilles.
Quoted 23 lines · Gilles Chanteperdrix
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."
Quoted 5 lines
Quoted 1 line
Did you already have a chance to look into this series?
Not yet, that is a big series. With a high potential for kernel crashes, memory leaks and other things like that. I am trying to find a way to test it. Maybe we can try and run it with kmemcheck?
It's mostly ordinary kernel code - should work. The boring thing will be to populate every entry with some content. Most were already stressed, but likely not every corner or the native skin tree.
Jan
Quoted 24 lines · Gilles Chanteperdrix
Quoted 23 lines · Jan Kiszka
Quoted 21 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."
Quoted 6 lines
Quoted 1 line
Did you already have a chance to look into this series?
Not yet, that is a big series. With a high potential for kernel crashes, memory leaks and other things like that. I am trying to find a way to test it. Maybe we can try and run it with kmemcheck?
Looking at this series, I eventually made my mind about the kind of support I'd wish in this area. It boils down to:
- getting rid of the PAGE_SIZE limitation on read as this series does,
- reducing the impact on latency of large outputs,
- hiding discrepancies between linux kernel
releases, regarding the proper way to export kernel object states to userland (like the planned deprecation of read procs).
- providing a common encapsulation to do that, which brings all the previous properties in a normalized way, and helps removing direct dependencies of other core code on PROC_FS
- rebasing the registry support on top of this feature, so that skins are automatically feature-enabled when going through the registry to export stuff to userland (as they should).
To this end, I came up with the so-called "virtual file" (aka vfile) support for the nucleus, and have toyed with those ideas here:git://git.xenomai.org/xenomai-rpm.git queue/vfile
This is still early work in progress, not all the codebase was converted to use the vfiles (registry and native API were), and I tested the result only in a very limited manner; so this is not for inclusion into 2.5.x given the amount of code that touches anyway. But I will likely submit this for inclusion at some point into any upcoming 2.6.x, if vfiles turn out to fit the job.
Signature · 1 line
Philippe.
Quoted 49 lines · Philippe Gerum
Quoted 23 lines · Gilles Chanteperdrix
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."Quoted 5 lines
Quoted 1 line
Did you already have a chance to look into this series?
Not yet, that is a big series. With a high potential for kernel crashes, memory leaks and other things like that. I am trying to find a way to test it. Maybe we can try and run it with kmemcheck?
Looking at this series, I eventually made my mind about the kind of support I'd wish in this area. It boils down to:
- getting rid of the
PAGE_SIZElimitation on read as this series does,
- reducing the impact on latency of large outputs,
- hiding discrepancies between linux kernel
releases, regarding the proper way to export kernel object states to userland (like the planned deprecation of read procs).
- providing a common encapsulation to do that, which brings all the previous properties in a normalized way, and helps removing direct dependencies of other core code onPROC_FS
- rebasing the registry support on top of this feature, so that skins are automatically feature-enabled when going through the registry to export stuff to userland (as they should).To this end, I came up with the so-called "virtual file" (aka vfile) support for the nucleus, and have toyed with those ideas here:
git://git.xenomai.org/xenomai-rpm.gitqueue/vfile
Quoted 7 lines
This is still early work in progress, not all the codebase was converted to use the vfiles (registry and native API were), and I tested the result only in a very limited manner; so this is not for inclusion into 2.5.x given the amount of code that touches anyway. But I will likely submit this for inclusion at some point into any upcoming 2.6.x, if vfiles turn out to fit the job.
Looks good on first sight to simplify all our revision-based list walks (and those that should better work like that). To make it a universal abstraction for /proc/xenomai (or what ever it will be in the future), I think just a bit more flexibility is required.
Specifically, we a way to modify the locking and data acquisition strategy. We have nodes that do not require any locking at all but still want to use the seq_file pattern. And we have some nodes that use different locks, including Linux semaphores/mutexes. I think if you allow to specify the lock to be used and its type (xnlock or Linux mutex
- BTW, a good chance to wrap away semaphores for legacy kernels), all required use cases should be covered:
- xnlock -> revision-based ahead-of-print data acquisition
- Linux mutex -> simply hold the lock while printing
- NULL -> provide lockless seq_file printing
Jan
Quoted 63 lines · Jan Kiszka
Quoted 49 lines · Philippe Gerum
Quoted 23 lines · Gilles Chanteperdrix
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Jan Kiszka
The following changes since commit
113ea4d56e8b215cb56ae7673013163ea5a5987d:
Gilles Chanteperdrix (1):
switchtest: increase stack sizesare available in the git repository at:
git://git.xenomai.org/xenomai-jki.gitqueues/procThis series fixes some of the potential (but when they happen fatal) overflows in our procfs outputs. Specifically, it fixes all issues in RTDM (one of them hit us in the field) and the recently reported overflow in
/proc/xenomai/heap. Moreover, Wolfgang started the lengthy conversion of the registry by introducing a new seq_file-based interface and already moving the native skin over.The future belongs to
seq_file, so some of the patches are strictly spoken not yet required. But we better start this effort before the last legacy interface user was converted and the old interface is suddenly dropped from the kernel. This may not be that far away. A patch of mine to improve error reporting of the old interface was rejected with "->read_proc is going to be removed, so there is no point."Quoted 5 lines
Quoted 1 line
Did you already have a chance to look into this series?
Not yet, that is a big series. With a high potential for kernel crashes, memory leaks and other things like that. I am trying to find a way to test it. Maybe we can try and run it with kmemcheck?
Looking at this series, I eventually made my mind about the kind of support I'd wish in this area. It boils down to:
- getting rid of the
PAGE_SIZElimitation on read as this series does,
- reducing the impact on latency of large outputs,
- hiding discrepancies between linux kernel
releases, regarding the proper way to export kernel object states to userland (like the planned deprecation of read procs).
- providing a common encapsulation to do that, which brings all the previous properties in a normalized way, and helps removing direct dependencies of other core code onPROC_FS
- rebasing the registry support on top of this feature, so that skins are automatically feature-enabled when going through the registry to export stuff to userland (as they should).To this end, I came up with the so-called "virtual file" (aka vfile) support for the nucleus, and have toyed with those ideas here:
git://git.xenomai.org/xenomai-rpm.gitqueue/vfileQuoted 7 lines
This is still early work in progress, not all the codebase was converted to use the vfiles (registry and native API were), and I tested the result only in a very limited manner; so this is not for inclusion into 2.5.x given the amount of code that touches anyway. But I will likely submit this for inclusion at some point into any upcoming 2.6.x, if vfiles turn out to fit the job.
Looks good on first sight to simplify all our revision-based list walks (and those that should better work like that). To make it a universal abstraction for
/proc/xenomai(or what ever it will be in the future), I think just a bit more flexibility is required.
Quoted 10 lines
Specifically, we a way to modify the locking and data acquisition strategy. We have nodes that do not require any locking at all but still want to use the
seq_filepattern. And we have some nodes that use different locks, including Linux semaphores/mutexes. I think if you allow to specify the lock to be used and its type (xnlock or Linux mutex
- BTW, a good chance to wrap away semaphores for legacy kernels), all required use cases should be covered:
- xnlock -> revision-based ahead-of-print data acquisition
- Linux mutex -> simply hold the lock while printing
- NULL -> provide locklessseq_fileprinting
That makes sense. To do this sanely, I will have to raise the abstraction level a bit more to specialize the vfile base, for deriving both a snapshot-driven vfile (the current one), and a regular one (the linux kind of seqfile), for which a locking resource may be specified. I will extend this code accordingly.
Quoted 3 lines
Jan
Signature · 1 line
Philippe.