[PATCH debugfs: implement symbolic links
From: Peter Oberparleiter <[email protected]>
debugfs: implement symbolic links
Implement a new function debugfs_create_symlink() which can be used to create symbolic links in debugfs. This function can be useful for people moving functionality from /proc to debugfs (e.g. the gcov-kernel patch).
---
fs/debugfs/file.c | 12 ++++++ fs/debugfs/inode.c | 76 ++++++++++++++++++++++++++++++++++++-- include/linux/debugfs.h | 10 +++++ 3 files changed, 94 insertions(+), 4 deletions(-)
fs/debugfs/file.c +12 -0
@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/fs.h> #include <linux/pagemap.h> +#include <linux/namei.h> #include <linux/debugfs.h> static ssize_t default_read_file(struct file *file, char __user *buf,
@@ -44,6 +45,17 @@ const struct file_operations debugfs_fil .open = default_open, }; +static void *debugfs_follow_link (struct dentry *dentry,struct nameidata *nd) +{ +nd_set_link (nd, dentry->d_inode->i_private); +return NULL ; +} + +const struct inode_operations debugfs_link_operations = { + .readlink = generic_readlink, + .follow_link = debugfs_follow_link, +}; +static void debugfs_u8_set (void *data,u64 val) { *(u8 *)data = val;
fs/debugfs/inode.c +72 -4
126 lines not on this page · raw message
include/linux/debugfs.h +10 -0
@@ -33,6 +33,9 @@ struct dentry *debugfs_create_file(conststruct dentry *debugfs_create_dir (const char *name,struct dentry *parent); +struct dentry *debugfs_create_symlink (const char *name,struct dentry *parent, +const char *dest); +void debugfs_remove (struct dentry *dentry); struct dentry *debugfs_create_u8(const char *name, mode_t mode,
@@ -70,6 +73,13 @@ static inline struct dentry *debugfs_crereturn ERR_PTR (-ENODEV ); } +static inline struct dentry *debugfs_create_symlink (const char *name, +struct dentry *parent, +const char *dest) +{ +return ERR_PTR (-ENODEV ); +} +static inline void debugfs_remove (struct dentry *dentry) { }
On Tue, 13 Feb 2007 12:13:54 +0100,
Peter Oberparleiter <[email protected]> wrote:
Not especially related to this patch (which just does the same as the other debugfs functions), but:
Quoted 4 lines
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
does not look like good advice for return code handling. Return code seems to be:
- ERR_PTR(-ENODEV) if debugfs is disabled
- NULL if debugfs is enabled and something went wrong
- !NULL and !IS_ERR if debugfs is enabled and all went fine
That makes it easy to get return code checking wrong (especially considering the comment above), and a number of callers do get it wrong.
How about changing the return code behaviour of the debugfs code, either
1. return NULL if debugfs is disabled or something went wrong, !NULL else or
2. return ERR_PTR(-ENODEV) if debugfs is disabled, ERR_PTR(-ESOMEERROR) if something went wrong or a proper dentry if everything went fine?
At the very least we should change the misleading comment.
Signature · 3 lines
Cornelia Huck Linux for zSeries Developer Tel.: +49-7031-16-4837, Mail: [email protected]
Quoted 14 lines · Cornelia Huck
On Tue, 13 Feb 2007 12:13:54 +0100,
Peter Oberparleiter <[email protected]> wrote:Not especially related to this patch (which just does the same as the other debugfs functions), but:
Quoted 4 lines
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
+ * code.does not look like good advice for return code handling. Return code seems to be:
Quoted 6 lines
-
ERR_PTR(-ENODEV)if debugfs is disabled
- NULL if debugfs is enabled and something went wrong
- !NULL and !IS_ERR if debugfs is enabled and all went fineThat makes it easy to get return code checking wrong (especially considering the comment above), and a number of callers do get it wrong.
They do?
The goal here is not to force the caller to care if debugfs is enabled or not.
Quoted 6 lines
How about changing the return code behaviour of the debugfs code, either
1. return NULL if debugfs is disabled or something went wrong, !NULL else or
2. returnERR_PTR(-ENODEV)if debugfs is disabled,ERR_PTR(-ESOMEERROR)if something went wrong or a proper dentry if everything went fine?
Your proposal changes the logic, if NULL is returned, callers will not know if this is just because debugfs is disabled (and they can continue on just fine), or if a real error happened.
Quoted 1 line
At the very least we should change the misleading comment.
agreed, patches always welcome :)
thanks,
greg k-h
Quoted 4 lines · Greg KH
Quoted 2 lines
That makes it easy to get return code checking wrong (especially considering the comment above), and a number of callers do get it wrong.
They do?
For example, fs/ocfs2/super.c only checks for NULL (while neither selecting nor depending on debugfs), or drivers/block/pktcdvd.c will only check for IS_ERR(). (Many callers don't seem to care about return codes at all.)
Quoted 2 lines
The goal here is not to force the caller to care if debugfs is enabled or not.
And that's definetly a good thing. (Looking again, not checking for IS_ERR() isn't as bad as I thought, as the code will continue to do nothing if called again for a non-existing dentry.)
Quoted 3 lines
Quoted 1 line
At the very least we should change the misleading comment.
agreed, patches always welcome :)
OK, just changing the comment looks like the most sensible thing to do. I'll roll up a patch.
PATCH 1/1 debugfs: Remove misleading comments.
[This goes on top of Peter's symlink patch.]
From: Cornelia Huck <[email protected]>
Just mention which error will be returned if debugfs is disabled. Callers should be able to figure out themselves what they need to check.
--- fs/debugfs/inode.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
fs/debugfs/inode.c +3 -9
@@ -212,9 +212,7 @@ static int debugfs_create_by_name(const* you are responsible here.) If an error occurs, %NULL will be returned. * * If debugfs is not enabled in the kernel, the value -%ENODEV will be -* returned. It is not wise to check for this value, but rather, check for -* %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling -* code. +* returned. */ struct dentry *debugfs_create_file(const char *name, mode_t mode, struct dentry *parent, void *data,
@@ -264,9 +262,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);* you are responsible here.) If an error occurs, %NULL will be returned. * * If debugfs is not enabled in the kernel, the value -%ENODEV will be -* returned. It is not wise to check for this value, but rather, check for -* %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling -* code. +* returned. */ struct dentry *debugfs_create_dir (const char *name,struct dentry *parent) {
@@ -297,9 +293,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);* returned. * * If debugfs is not enabled in the kernel, the value -%ENODEV will be -* returned. It is not wise to check for this value, but rather, check for -* %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling -* code. +* returned. */ struct dentry *debugfs_create_symlink (const char *name,struct dentry *parent,const char *target)
Quoted 8 lines · Peter Oberparleiter
From: Peter Oberparleiter <[email protected]>
debugfs: implement symbolic links
Implement a new function
debugfs_create_symlink()which can be used to create symbolic links in debugfs. This function can be useful for people moving functionality from /proc to debugfs (e.g. the gcov-kernel patch).
You aren't really creating debugfs symlinks from /sys/kernel/debug/ to the /proc directory are you? That's pretty insane...
Otherwise I have no objection to this, I'll add it to my queue...
thanks,
greg k-h
Greg KH <[email protected]> wrote on 14.02.2007 02:27:32:
Quoted 7 lines · Peter Oberparleiter
Quoted 3 lines
This function can be useful
for people moving functionality from /proc to debugfs (e.g. the gcov-kernel patch).You aren't really creating debugfs symlinks from
/sys/kernel/debug/to the /proc directory are you? That's pretty insane...
Interesting idea :) But I was thinking more along the lines of replacing existing /proc files and symlinks with files and links in debugfs.
Quoted 1 line
Otherwise I have no objection to this, I'll add it to my queue...
Great, thanks!
Regards,
Peter Oberparleiter
Quoted 11 lines · On Wed, Feb 14, 2007 at 09:03:24AM +0100, Peter 1 Oberparleiter wrote:
Greg KH <[email protected]> wrote on 14.02.2007 02:27:32:
Quoted 7 lines · Peter Oberparleiter
Quoted 3 lines
This function can be useful
for people moving functionality from /proc to debugfs (e.g. the gcov-kernel patch).You aren't really creating debugfs symlinks from
/sys/kernel/debug/to the /proc directory are you? That's pretty insane...Interesting idea :) But I was thinking more along the lines of replacing existing /proc files and symlinks with files and links in debugfs.
Ah, ok, that sounds much saner :)
thanks,
greg k-h