inserting files into Thunderbird without reformatting

Let’s start with the observation that the Linux kernel community discourages sending patches as attachments (tpp, section 1a). Sending patches as attachments creates pain for the sender, regardless of what you or I might think of this fact.

Thus, it’s a shame that Thunderbird doesn’t have a trivial mechanism to insert a file in to its plain text composing interface without altering the file. There are at least three stumbling blocks: translating tabs into spaces, trimming trailing whitespace, and wrapping lines.

One suggested hack to work around this is to use an external editor extension which lets you fire up, say, vim to insert the file into the editing buffer. This doesn’t work well in OS X, for much the same reasons that it doesn’t work well for eclipse.

After some trial and error I found Quicktext, an extension for inserting signatures, which can be abused to insert files. After installing the extension, one:

  1. sets the word wrapping preference to 0 before composing the new message
  2. inserts the file as HTML, to preserve trailing whitespace
  3. restores the previous word wrapping preference

This is violently imperfect. Inserting as HTML to preserve whitespace runs the risk of escaping HTML which might be in the file. I do this so infrequently that it’ll do for now. I usually send patches with tools. (git-send-email, hg email, sendpatchset).

I was reasonably excited to find that it seems like someone who understands Mozilla extensions could build an extension to insert text without altering the input. nsIPlaintextEditor seems to have knobs to disable translation of whitespace and word wrapping. I might try my hand at this some day but would be even happier if someone beat me to it.

direct write cache invalidation failure illustrated

An associate recently berated me for not posting about work things recently. Fair enough. Here’s the start of an attempt to do more blogging about my daily work.

For me, last week ended with a thread on lkml wherein a poor user reported having actually hit the nasty case where an O_DIRECT write doesn’t invalidate the page cache after a buffered reader races to bring in stale cached data during the write.

In his case he had a writer advancing through a file writing new contents. As it wrote it’d wake a buffered reader who would read up to the point of the new content that the writer had just written.

The problem was that the reader could trigger the kernel to read-ahead up into the region where the writer is currently writing with O_DIRECT. The kernel was failing to invalidate the existing page cache after the O_DIRECT write completes. The buffered reader will then wake a read stale data which was brought in with read-ahead from its previous reads. Wackiness ensues!

So, I threw together a test case. I know you, dear readers, have been just dying to see what this terrifying corner case actually looks like. Wonder no more!

[zab@hammer c]$ ./aio-dio-invalidate-check /tmp/something
( lots of time passes )
writing 2 to 3248128
setting write_pos to to 3248128
writing 2 to 3252224
reading from 2850816 to to 3248128 looking for 1
read 3248128 write 3248128
writing 2 to 3256320
writing 2 to 3260416
writing 2 to 3264512
writing 2 to 3268608
writing 2 to 3272704
setting write_pos to to 3272704
writing 2 to 3276800
writing 2 to 3280896
setting write_pos to to 3280896
writing 2 to 3284992
writing 2 to 3289088
writing 2 to 3293184
writing 2 to 3297280
reading from 3248128 to to 3280896 looking for 1
reader found old byte at pos 3252224

[zab@hammer c]$ od -A d -x /tmp/something
0000000 0202 0202 0202 0202 0202 0202 0202 0202
*
3252224 0101 0101 0101 0101 0101 0101 0101 0101
*
3256320 0202 0202 0202 0202 0202 0202 0202 0202
*
3301376 0101 0101 0101 0101 0101 0101 0101 0101
*
8388608

[root@hammer ~]# echo 1 > /proc/sys/vm/drop_caches

[zab@hammer c]$ od -A d -x /tmp/something
0000000 0202 0202 0202 0202 0202 0202 0202 0202
*
3301376 0101 0101 0101 0101 0101 0101 0101 0101
*
8388608

That last bit shows the stale data present in the cache, the cache being purged, and then the stale data vanishing as the file is read back from disk.

Terrifying stuff, I know, but it is almost Halloween.

Bi-Mon-Sci-Fi-Con

Over the years I’ve built up a collection of badges from tech conferences. They’re an interesting record of the path my career took from UNIX sysadmin work to Linux kernel development. I noticed that the oldest of them is now 10 years old and thought it would be a fun time to show them off. I put up a Conference Badge photo set on flickr.

They come to 112MB of 600dpi scans which motivated me to shell out for a Pro flickr account. I had to crop the badge from thebazaar as its enormous speaker ribbon pushed the file size up to 17MB, compressed.

Ted vs. Infotainment

A few months ago I got an email out of the blue from a researcher at ABC News. After some prodding she admitted that she wanted to talk about background information on Hans Reiser. I happily declined, having managed to avoid that particular corner of the Linux file system world.

Today Ted mentions that he tried to help ABC understand the basics.

Let’s hope that it doesn’t end up like the disastrous piece in Wired. I’m not holding my breath.