Jspenguin's crappy little blog

Saturday, August 04, 2012

SATA hotplug speed fix for Linux

Like many Linux users, I'm fairly paranoid about backups. I back up all of the important data on my desktop and laptop to the RAID on my main fileserver. I have several offline backup disks which I keep unplugged most of the time. Once or twice a week, I insert one into the trayless hot-swappable SATA bay on my server and run a backup to it.

Linux has always had great support for hot-swapping drives. However, there is one problem: if a new drive is inserted too quickly after the old one is removed, the error handler may limit the link speed to 1.5 Gbps:

[7270695.660961] ata4: exception Emask 0x10 SAct 0x0 SErr 0x4050002 action 0xe frozen
[7270695.661416] ata4: irq_stat 0x00000040, connection status changed
[7270695.662327] ata4: SError: { RecovComm PHYRdyChg CommWake DevExch }
[7270695.663518] ata4: limiting SATA link speed to 1.5 Gbps
[7270695.663524] ata4: hard resetting link
[7270705.684030] ata4: softreset failed (device not ready)
[7270705.684498] ata4: hard resetting link
[7270712.632035] ata4: SATA link up 1.5 Gbps (SStatus 123 SControl 300)
[7270712.640555] ata4.00: ATA-7: Hitachi HDS721010KLA330, GKAOAB0A, max UDMA/133
[7270712.640560] ata4.00: 1953525168 sectors, multi 0: LBA48 NCQ (depth 31/32), AA
[7270712.641499] ata4.00: configured for UDMA/133
[7270712.656024] ata4: EH complete

For the longest time, the only solution was to unplug the drive, wait 5 minutes, then plug it back in. I found the function responsible for limiting the speed (sata_down_spd_limit), but since Ubuntu kernels include libata in the base image, changing it would mean patching and recompiling the kernel every time it updates.

Today, I discovered that Linux has a feature called kretprobe which allows a module to patch a running kernel without a reboot. Using this, I created a module which patches libata to prevent it from limiting SATA link speeds after link errors occur. I've tested it on all three of my systems with no problems.

If you have problems with link speeds after hot-swapping, you can download the module from here.

Labels: , ,

Tuesday, July 10, 2012

Fluttershy visits the Keeper of the Plains

This is my entry to the Ponies Around the World project.
Wichita's most famous landmark is the Keeper of the Plains, at the confluence of the Arkansas and Little Arkansas rivers.
Behind the statue is the Keeper Plaza, with various plaques and artwork detailing the lives of the Plains Indians.
Another shot, from across the river.

Labels: , ,

Wednesday, March 09, 2011

Spamming search results

In the past few months, I've noticed several blogs linking directly to images on my server. All of these blogs are hosted under the blogspot.com domain, and none of them has any real content. Each "post" on the blog seems to be just the results of a web search for a specific term. The goal is apparently to be first on the list of results for these terms, serving up relevant but stolen content, and either increasing ad revenue or serving malware.

I'm not going to list them here, but if you see one of these blogs, please report it to Google.

Monday, February 28, 2011

How to hose your Linux box, lesson 1: the power of rm -rf

If you've used Linux, you already know rm can be dangerous. Getting a newbie to run sudo rm -rf / is a cliché joke among geeks. Helpfully, GNU rm won't actually let you delete the root directory, but you can still get into trouble.

Recently, I was cleaning out an old system disk in order to use it as a backup disk. I had already copied some data onto it, so I didn't want to just wipe it out, so I explicitly deleted the directories I did not want:

I knew it was going to take a while to delete all the files, so I went back to working on the backup script. After a few minutes, something odd happened: any command I entered failed with No such file or directory. The rm process continued to run, since it had already been loaded into memory. When the most basic commands like ls and cp don't work, there's not much that can be done. I couldn't stop rm; I had detached from the screen session and screen couldn't start again. I had no choice. I pulled the plug.

Booting from a USB drive, I was relieved to find that the root drive had not been wiped. The only casualty was the /lib directory, which explains the error: The ELF interpreter, /lib/ld-linux-x86-64.so.2 was gone. I restored /lib from a recent backup, and everything was fine.

So, why was /lib singled out? The culprit was the extra slash on lib64/lib64 is a symbolic link to /lib. Normally, rm does not follow symbolic links when deleting recursively, but it does follow links to directories when resolving paths given on the command line; rm -rf lib64 means "delete the symbolic link lib64", while rm -rf lib64/ means "delete the directory lib64 points to".

Today's lesson has been brought to you by the letter "B", for backups. It doesn't matter how secure your box is, one typo on the command line can completely clean out your data.

Wednesday, February 23, 2011

An update? Unbelievable.

I started working full-time right out of high school, so I never had time or incentive to continue my education until now. I've started taking a few gen-ed classes at Butler Community College, and I'm plannng to transfer to WSU for a degree in Computer Science.

Long story short, my English professor strongly encourages me to practice writing, so I'm going to try postng here more than once every two years...

Anyway, I recently bought an HP LaserJet Professional P1102w, and was disappointed to find that there was no way to set up its wireless networking using Linux. I did some digging, and hacked together a script to access the embedded web server over USB: USB EWS gateway. It may work with other printer models, but I've only tested it on mine.

Tuesday, April 21, 2009

Man, screw KDE4.1

So I finally broke down and upgraded my laptop to Kubuntu Intrepid. Everything went great -- until I restarted, and found that my nice, neat, KDE 3.5.1 desktop had been replaced by ugly-ass KDE4. Not only did it make no attempt to import my keyboard shortcuts from KDE3, I discovered that changing the keyboard shortcuts requires you to log out and log back in. The default window decorations are ugly as sin, and even worse, the GTK integration makes all GTK apps ugly.

Edit: KDE4.2 fixes nearly all of the problems I mentioned.

Labels: , ,

Friday, April 17, 2009

Dreaming of Androids

Today I received my new HTC Dream, a.k.a. the T-Mobile G1, running Google's Android OS, and it kicks the iPhone's sorry ass.

How is it better, you ask?

1. It has more than one farking button. In fact, it has a full QWERTY keyboard.
2. It took only four taps to enable installation of "unofficial" applications. No jailbreaking needed.
3. It can run more than one goddamn app at a time.
4. I don't need to pay 99 bucks to distribute an app.
5. I don't need to send it in just to change the battery.
6. If I lose the data cable, I have a crapton of USB mini-B cables lying around that will work just as well.

And what does the iPhone have that the G1 doesn't?

1. Multitouch. Ooh, look, I can squeeze the page and it gets smaller. Big whoop.
2. A half-eaten piece of fruit stenciled on the back.
3. An aura of smugness.

iPhone fanboys, flame away.

Labels: , , , , ,