Sometimes there may arise a need to make your own watchdog for your virtual machine. The process itself is really a simple one, I will base this example on Intel's 6300esb watchdog.
Let's first start by getting the latest source code for Qemu:
git clone git://git.qemu.org/qemu.git && cd qemu
Now it is reasonable to switch to your own git branch in case you want to roll out some patches later on.
git checkout -b custom-watchdog
All of the existing watchdog sources are located at hw folder.
Make a copy of existing watchdog and include it in the build path.
cp hw/wdt_i6300esb.c hw/wdt_custom_watchdog.c
Now lets plug the new watchdog into the build process. For doing that we need to edit Makefile.objs and add a new line hw-obj-$(CONFIG_PCI) += wdt_custom_watchdog.o
right after the "hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o" line.
Next step is to dig into the code and start modifying the new and improved watchdog. For the sake of simplicity I will leave the core functionality unchanged. I will only change the important parts of the code to enable the registering the new watchdog with Qemu. Replace every reference to i3600esb and alike with your version of the name. If you skip some of the code then there is a chance that custom watchdog will not behave as expected. Most of the tedious replacement is easily done with sed commands similar to this.
sed -e 's/i6300esb/custom_watchdog/g' hw/wdt_i6300esb.c > hw/wdt_custom_watchdog.c
Now open up the code of the custom watchdog and fill in it's name and description with your own such as:
.wdt_description = "Super Custom Watchdog"
Recompile now and see if the new watchdog is visible and loading with Qemu.
qemu (custom-watchdog)$ ./i386-softmmu/qemu-system-i386 -watchdog ?
custom_watchdog Super Custom Watchdog
i6300esb Intel 6300ESB
ib700 iBASE 700
As it turns out, the new watchdog is visible for Qemu.
Let's run some VM with our new watchdog:
./i386-softmmu/qemu-system-i386 -watchdog custom_watchdog ~/debian.qcow2
If everything goes well and the virtual machine comes up without any errors regarding the watchdog, the next step would be to replace some of the old variable names in the source code with more appropriate ones, otherwise the new watchdog is ready for further customization.
Software versions used:
- Qemu sources for version 1.0