Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the snapshot commands #1054

Merged
merged 1 commit into from
May 18, 2023
Merged

Conversation

afbjorklund
Copy link
Member

@afbjorklund afbjorklund commented Sep 15, 2022

For making qcow2 snapshots of the running virtual machine.

It is possible to make multiple snapshots, in the diffdisk.

Closes #1051


limactl start

limactl snapshot create default --tag snap

limactl snapshot list default

limactl snapshot apply default --tag snap

limactl stop

limactl snapshot delete default --tag snap

@afbjorklund
Copy link
Member Author

This has similar problems to the pause commands, in that the ssh mux is not too happy about the restore ?

@afbjorklund afbjorklund marked this pull request as draft September 21, 2022 17:37
@afbjorklund

This comment was marked as outdated.

@afbjorklund afbjorklund changed the title Implement the backup and restore commands Implement the snapshot commands Oct 2, 2022
@afbjorklund afbjorklund marked this pull request as ready for review October 2, 2022 16:42
pkg/qemu/qemu.go Outdated
return err
}

func List(cfg Config) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment to clarify that the result is not machine-parsable

Copy link
Member Author

@afbjorklund afbjorklund Oct 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I think the original API just promises a list of strings (lines).

    printf("Snapshot list:\n");
    bdrv_snapshot_dump(NULL);
    printf("\n");
    for(i = 0; i < nb_sns; i++) {
        sn = &sn_tab[i];
        bdrv_snapshot_dump(sn);
        printf("\n");
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the initial heading, so now it at least looks similar to limactl ls

$ limactl snapshot create --tag snap alpine
$ limactl snapshot list alpine
ID        TAG                     VM SIZE                DATE       VM CLOCK
1         snap                        0 B 2022-10-16 11:37:23   00:00:00.000

@AkihiroSuda
Copy link
Member

Thanks, the CLI design looks good, could you update the docs and integration tests?

@afbjorklund
Copy link
Member Author

Left to do is adding integration tests, for the limactl snapshot sub-commands.

@afbjorklund
Copy link
Member Author

Some help with the integration tests for snapshots would be appreciated. 🙏

@AkihiroSuda
Copy link
Member

Integration tests can be added like this

["restart"]="1"

lima/hack/test-example.sh

Lines 240 to 267 in 4a4cc62

if [[ -n ${CHECKS["restart"]} ]]; then
INFO "Create file in the guest home directory and verify that it still exists after a restart"
# shellcheck disable=SC2016
limactl shell "$NAME" sh -c 'touch $HOME/sweet-home'
INFO "Stopping \"$NAME\""
limactl stop "$NAME"
sleep 3
export ftp_proxy=my.proxy:8021
INFO "Restarting \"$NAME\""
limactl start "$NAME"
INFO "Make sure proxy setting is updated"
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
expected="FTP_PROXY=my.proxy:8021"
INFO "FTP_PROXY: expected=${expected} got=${got}"
if [ "$got" != "$expected" ]; then
ERROR "proxy environment variable not set to correct value"
exit 1
fi
# shellcheck disable=SC2016
if ! limactl shell "$NAME" sh -c 'test -f $HOME/sweet-home'; then
ERROR "Guest home directory does not persist across restarts"
exit 1
fi
fi

@afbjorklund afbjorklund force-pushed the snapshot branch 3 times, most recently from 07879e8 to 55bb4c8 Compare November 16, 2022 19:09
@afbjorklund
Copy link
Member Author

Snapshot worked on default (and alpine, but failed on experimental/9p ?

TEST| [INFO] Testing online snapshots
time="2022-11-16T20:21:20Z" level=info msg="Sending HMP savevm command"
TEST| [INFO] snapshot list: expected=snap1 got=
Error: ERROR] snapshot list did not return expected value

Need to see if there is a better way to return errors, after running HMP/QMP...

@afbjorklund
Copy link
Member Author

afbjorklund commented Nov 18, 2022

Now it is at least logging the real problem:
"output: Error: Migration is disabled when VirtFS export path '/tmp/lima' is mounted in the guest using mount_tag 'mount1'\r\n"

So this means that snapshots won't work with 9p mounts, while the instance is still running.

EDIT: Disabled the online tests for 9p, still running offline tests.

Trimmed off the extra whitespace, from the output.

@afbjorklund afbjorklund force-pushed the snapshot branch 3 times, most recently from a6fbdb5 to 3f35ed9 Compare November 19, 2022 17:48
AkihiroSuda
AkihiroSuda previously approved these changes Nov 21, 2022
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda
Copy link
Member

Could you rebase to rerun the CI?

@afbjorklund
Copy link
Member Author

It would be nice, if the generated command help stayed out of the README....

@AkihiroSuda
Copy link
Member

Sorry needs rebase again

AkihiroSuda
AkihiroSuda previously approved these changes May 9, 2023
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda requested a review from balajiv113 May 9, 2023 05:06
@AkihiroSuda
Copy link
Member

CI failing

+ set +x
TEST| [INFO] Testing online snapshots
time="2023-05-09T05:21:18Z" level=info msg="Sending HMP savevm command"
time="2023-05-09T05:21:26Z" level=info msg="Sending HMP info command"
TEST| [INFO] snapshot list: expected=snap1 got=snap1
time="2023-05-09T05:21:26Z" level=info msg="Sending HMP loadvm command"

Timed out!

balajiv113
balajiv113 previously approved these changes May 10, 2023
Copy link
Member

@balajiv113 balajiv113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@AkihiroSuda
Copy link
Member

CI for experimental/net-user-v2.yaml seems consistenly failing

@afbjorklund
Copy link
Member Author

afbjorklund commented May 18, 2023

CI for experimental/net-user-v2.yaml seems consistenly failing

Looks like the net-user-v2 does not survive an "online" VM restore.

So it needs to be excluded.

"net-user-v2")
        CHECKS["port-forwards"]=""
        CHECKS["user-v2"]=1
        ;;

It already was, for 9p.

"9p")
        CHECKS["snapshot-online"]=""
        ;;

For handling qcow2 snapshots of the running virtual machine.

It is possible to make multiple snapshots, in the diffdisk.

* Use the new driver framework for snapshot

* Add integration test for limactl snapshot

Signed-off-by: Anders F Björklund <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@AkihiroSuda AkihiroSuda merged commit a235d10 into lima-vm:master May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does lima support checkpoint backup and restore like normal virtual machine?
3 participants