Archive for August, 2010

Two things I hate about debugfs

August 29, 2010 Leave a comment

I am a major fan of the Linux kernel’s debugfs filesystem. For those not familiar with its awesome power, read these LWN articles from 2004 and 2009, and the Wikipedia entry.

I’ve written IOCTLs in the past, and always felt like the sterotypical monolithic switch statement was a bit lame – so once I ran across debugfs, I kicked ioctls to the curb and never looked back. There’s something so completely elegant and awesome about a simple

$ cat /sys/kernel/debug/mymod/var1; echo 'erase' > /sys/kernel/debug/mymod/buffer2

But as I get more and more into debugfs, two things keep irritating me and hence this post.


Why in the world is debugfs exported as GPL only? Do the kernel developers really think that people who write proprietary modules don’t need debugfs? Or do they really want people abusing /sys or /proc files even further, leading to more mess and chaos?

Or, is it yet another manefestation of Linux’s split personality disorder reaction to non-GPL code? After all, the core kernel developers still can’t decide if non-GPL kernel modules are a violation of the GPL… so I shouldn’t be surprised to see something as awesome and inspiring as debugfs locked down to GPL exports.

But I am surprised, and it does grate on me. I love debugfs but hate that it’s exported GPL only.

Gripe #2: boilerplate code

Now this one is a bit more subjective, and quite possibly a sign that I’m doing something wrong… but I find myself writing a lot of boilerplate code. Sure, debugfs makes it super trivial to read/write simple variables —

struct dentry my_foo = debugfs_create_x32(name, perms, root, u32_ptr);

But creating a more complex file with custom logic requires a struct file_operations which looks quite boilerplate:

static struct file_operations file1_ops = {
    .open = file1_open,
    .release = file1_release,
    .read = file1_read,
    .write = file1_write

That’s not so bad when you’re creating one debugfs file, but try creating 5 or 10 or 20. After a while, all the structs look ver very similar, and all the functions look the same too. Open sets the file pointer’s private data to the inode’s private data, possibly allocates some RAM. Read does a simple_read_from_buffer. Write kmalloc’s, copies from users, then does a strncmp to see if the user echo’d the right magic token to kick off some logic. Close undoes whatever open did.

So while I love the flexibility and power of debugfs, the boilerplate code lends to many copy/paste errors and leaves me wishing debugfs would handle more for me in the normal boring cases. Or at least add some new file types… debugfs_create_text_buffer() anyone?

In Summary

In summary, I love debugfs. I’m a die hard Linux command line freak and debugfs fits me like a glove. But my experience with debugfs hasn’t been completely Utopian and there’s a couple of annoyances that leave me wanting a little more polish.

Hmmm…. wait… it’s open source right?

Maybe I’ll chip in some code, so I’m not just the whiny poser throwing stones from the corner.



Categories: Uncategorized Tags: , ,

Giving Time

August 24, 2010 1 comment

It’s been a long time since I posted last, and looking back I realize some of my earlier posts were crap anways… but even though work has swallowed me alive for a few months and I have more commitments than I can shake a stick at — I still want to blog about code.

So here goes, my public commitment to the world – I promise to

A) be straightforward and simple, no flowery speech
B) upload smaller, more frequent posts
C) give back

On the giving back piece… my whole life has been subtly molded (I think for the better) because some guy named Linus gave away his OS and its source code to the world for free. My brother crashed our hard drive installing (Slackware? Debian?) and I’ve been hooked on Linux ever since, tinkering and learning. I owe most of my career to there being Linux and Open Source, and I’ve always been grateful for that… just never found time to give back.

That’s not to say I haven’t tried… I can count off at least 5 projects I seriously investigated trying to learn the code, but I always bit off more than I could chew and tried to overcommit myself even further, giving up in the short term. So I always put it off for “just a few more months”, thinking someday I’ll retire early and be an open source contributor fulltime.

Starting now, I’m going to make a change. I’m going to commit a few hours each week to giving back. It’s not a ton of time, and maybe I’ll never be Jens Axboe or Linus or Andrew Morton or Scott Chacon — but I can give back. And maybe I’ll create something new and awesome, and become an code rockstar – or maybe just make some minor changes to existing projects and make the world a tiny, tiny bit better.

I can give back.

We can all give back.

Who’s with me?


Categories: Uncategorized Tags: , ,