Page MenuHomeFreeBSD

Bhyve - Using JSON format for saving and restoring the state
Needs ReviewPublic

Authored by ionut.mihalache1506_gmail.com on Mar 14 2021, 5:37 PM.

Details

Reviewers
jhb
Group Reviewers
bhyve
Summary

I made the necessary modification in order for the hypervisor to save and restore the state of the guest using two files (.ckp for RAM and .meta for the state of each device) instead of three files (.ckp for RAM, .kern for the data of each device, .meta for the necessary information to extract the data from the .kern file). The feature is useful in order to make the interpretation of the data that represents a state easier for a human, the binary data is hard to understand and debug when it is needed.

In order to store the data I used base64 encoding for the array types and I kept the actual type if it can be easy to understand(ex: int type). I used the encoding in order to keep the file type "text" and not write pure binary data(the data from the frame buffer for example).
The usual types, that are human friendly, such as int, long, etc, I just used the corresponding format(%d, %ld, etc.) in order to avoid doing more computations and make the file harder to read.

Here is an example of the file.ckp.meta file generated with the implementation:

"device_params": [
  {
    "vcpus": [
      {
        "vcpus@0": [
          {
            "x2apic_state$uint32": 0,
            "exitintinfo$uint64": "0",
            "exc_vector$int32": 0,
            "exc_errcode_valid$int32": 0,
            "exc_errcode$uint32": 0,
            "guest_xcr0$uint64": "7",
            "exitinfo$b64": "FQAAAAAAAACWXQiB/////wCwHDsBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPYSsBAAAAAAAAAAAAwAAAAMAAAAAAAAAiYGAAwAAMcBdw2YuDx+EDwZIAAgBAAQAAAAAAAIAAAAtAAAALQAAAIADAAAAAAAAAAAAAAAAAAABAIkBAAAAAA==",
            "nextrip$uint64": "ffffffff81085d96",
            "tsc_offset$uint64": "15063e03a9f0"
          }
        ],
Test Plan

Started the guest vm with: bhyve -c 1 -m 1024M -H -A -P -s 0:0,hostbridge -s 1:0,lpc -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd -s 2:0,virtio-net,tap0 -s 3:0,ahci-hd,main.img -l com1,stdio freebsd_guest

For testing the functionality I opened two processes at the same time on the guest vm:

  • one copy process of a 500MB file
  • one ping process

While the processes mentioned above are running:

  • I suspended the guest with the command: bhyvectl --suspend file.ckp --vm=freebsd_guestand
  • then I restored its state with the command: bhyve -c 1 -m 1024M -H -A -P -s 0:0,hostbridge -s 1:0,lpc -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd -s 2:0,virtio-net,tap0 -s 3:0,ahci-hd,main.img -l com1,stdio -r file.ckp freebsd_guest.

After the restore command, both processes should finish successfully and the guest can be used without errors.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped