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 a VM memory dump API #1596

Merged
merged 8 commits into from
Jan 23, 2025
Merged

Conversation

SpiffyEight77
Copy link
Contributor

Description

Details

  • OS: Ubuntu 24.04
  • Arch: x86_64

Test result

CLI

root@playground:~# incus debug
Description:
  Debug commands for instances

Usage:
  incus debug [command]

Available Commands:
  get-instance-memory Export a virtual machine's memory state

Global Flags:
      --debug          Show all debug messages
      --force-local    Force using the local unix socket
  -h, --help           Print help
      --project        Override the source project
  -q, --quiet          Don't show progress information
      --sub-commands   Use with help or --help to view sub-commands
  -v, --verbose        Show all information messages
      --version        Print version number

Use "incus debug [command] --help" for more information about a command.

debug instance memory

root@playground:~# incus ls
+-----------+---------+----------------------+-------------------------------------------------+-----------------+-----------+
|   NAME    |  STATE  |         IPV4         |                      IPV6                       |      TYPE       | SNAPSHOTS |
+-----------+---------+----------------------+-------------------------------------------------+-----------------+-----------+
| ubuntu-vm | RUNNING | 10.46.82.14 (enp5s0) | fd42:a560:1040:84ee:216:3eff:fe71:18f2 (enp5s0) | VIRTUAL-MACHINE | 0         |
+-----------+---------+----------------------+-------------------------------------------------+-----------------+-----------+

root@playground:~# incus debug get-instance-memory ubuntu-vm /tmp/memory.elf
Memory dump completed successfully!

root@playground:~# ll /tmp/memory.elf
-r-------- 1 nobody nogroup 1065158131 Jan 21 15:12 /tmp/memory.elf

Analyze the memory dump file with volatility3

root@playground:~# source volatility3/venv/bin/activate
(venv) root@playground:~# vol -f /tmp/memory.elf linux.lsmod
Volatility 3 Framework 2.18.0
Progress:  100.00               Stacking attempts finished
Offset  Name    Size

0xffffc07ae8c0  kvm_amd 155648
0xffffc07896c0  ccp     110592
0xffffc072db40  kvm     1036288
0xffffc05fb240  crct10dif_pclmul        16384
0xffffc05f6240  crc32_pclmul    16384
0xffffc04e3440  ghash_clmulni_intel     16384
0xffffc05b9140  sha256_ssse3    32768
0xffffc056e8c0  sha1_ssse3      32768
0xffffc04fd480  binfmt_misc     24576
0xffffc055afc0  aesni_intel     376832
0xffffc0508100  nls_iso8859_1   16384
0xffffc0503040  crypto_simd     16384
0xffffc04f3400  virtio_gpu      73728
0xffffc04dd180  cryptd  24576
0xffffc0478000  virtio_dma_buf  16384
0xffffc04bf640  drm_kms_helper  311296
0xffffc048a6c0  joydev  32768
0xffffc0481140  input_leds      16384
0xffffc0473300  serio_raw       20480
0xffffc046b440  cec     65536
0xffffc0459ac0  rc_core 65536
0xffffc044b040  fb_sys_fops     16384
0xffffc0446000  syscopyarea     16384
0xffffc03844c0  sysfillrect     20480
0xffffc037e340  sysimgblt       16384
0xffffc0441400  vmw_vsock_virtio_transport      20480
0xffffc0439580  9p      65536
0xffffc03e0ac0  fscache 389120
0xffffc03c8580  netfs   45056
0xffffc03bbc00  vmw_vsock_virtio_transport_common       40960
0xffffc03af340  9pnet_virtio    20480
0xffffc03a5600  9pnet   90112
0xffffc038e500  vsock   49152
0xffffc03791c0  virtio_input    20480
0xffffc0304240  sch_fq_codel    20480
0xffffc02ca9c0  drm     622592
0xffffc02652c0  efi_pstore      16384
0xffffc0248780  ip_tables       32768
0xffffc023ca40  x_tables        53248
0xffffc02308c0  autofs4 49152
0xffffc0223c40  virtio_net      61440
0xffffc020f380  xhci_pci        24576
0xffffc0208080  net_failover    20480
0xffffc01fab00  ahci    49152
0xffffc01e79c0  psmouse 184320
0xffffc01b8b40  libahci 49152
0xffffc01aa100  failover        16384
0xffffc01a1580  virtio_scsi     24576
0xffffc0198340  xhci_pci_renesas        20480
0xffffc018f180  virtio_rng      16384

@SpiffyEight77
Copy link
Contributor Author

SpiffyEight77 commented Jan 21, 2025

This is my first time implementing the complete API. This feature is the minimal implementation of the dump-guest-memory command in QEMU, and there are a few issues I'm unsure about and would like to ask for help.

  • File writing through QMP is blocked by AppArmor rules. My local testing was conducted in an environment with AppArmor removed, but files can only be written to the /tmp directory.
  • In the API endpoint implementation, how should parameters be passed through query parameters for GET methods?
  • Where should the documentation for the API and CLI be added?

I would like to receive your suggestions for modifications.🙇

@SpiffyEight77 SpiffyEight77 marked this pull request as ready for review January 21, 2025 15:55
@stgraber
Copy link
Member

@SpiffyEight77 can you add the Signed-off-by line to your commits?

@SpiffyEight77
Copy link
Contributor Author

@SpiffyEight77 can you add the Signed-off-by line to your commits?

I've now added the Signed-off-by line to all commits.
Apologies for missing this requirement earlier. 🙇🏻‍♂️

@github-actions github-actions bot added Documentation Documentation needs updating API Changes to the REST API labels Jan 22, 2025
@SpiffyEight77 SpiffyEight77 force-pushed the feat/vm-memory-dump branch 4 times, most recently from 75b048d to 3c33c45 Compare January 22, 2025 13:45
@stgraber stgraber force-pushed the feat/vm-memory-dump branch 3 times, most recently from ab372e3 to 0dc9b40 Compare January 23, 2025 20:41
@stgraber stgraber force-pushed the feat/vm-memory-dump branch from 0dc9b40 to 380d000 Compare January 23, 2025 20:43
@stgraber stgraber enabled auto-merge January 23, 2025 20:43
@stgraber
Copy link
Member

Did a few tweaks:

  • Added an API extension
  • Renamed CLI command to incus debug dump-memory
  • Changed to streaming the dump directly from the VM over the network

@stgraber stgraber merged commit ee6da2a into lxc:main Jan 23, 2025
36 checks passed
@SpiffyEight77 SpiffyEight77 deleted the feat/vm-memory-dump branch January 24, 2025 02:15
@SpiffyEight77
Copy link
Contributor Author

SpiffyEight77 commented Jan 24, 2025

Did a few tweaks:

  • Added an API extension
  • Renamed CLI command to incus debug dump-memory
  • Changed to streaming the dump directly from the VM over the network

Thank you for this opportunity to learn and contribute.
I look forward to making more meaningful contributions to this project. 🙇🏻‍♂️

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jan 28, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [lxc/incus](https://github.com/lxc/incus) | minor | `v6.8.0` -> `v6.9.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>lxc/incus (lxc/incus)</summary>

### [`v6.9.0`](https://github.com/lxc/incus/releases/tag/v6.9.0): Incus 6.9

[Compare Source](lxc/incus@v6.8.0...v6.9.0)

#### What's Changed

-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1506
-   Refactor scriptlet loader and improve checks by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1507
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1511
-   incusd/storage/drivers: Force blkdiscard and ignore errors by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1513
-   incusd/auth: fix FGA online data race by [@&#8203;breml](https://github.com/breml) in lxc/incus#1515
-   incusd/storage/drivers: Log on blkdiscard failure by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1517
-   Fix issue with live-migration between storage pools by [@&#8203;presztak](https://github.com/presztak) in lxc/incus#1518
-   Add uplink addresses for OVN network by [@&#8203;winiciusallan](https://github.com/winiciusallan) in lxc/incus#1512
-   Add `--description` flag to create type CLI commands by [@&#8203;luissimas](https://github.com/luissimas) in lxc/incus#1498
-   client: Propagate HTTP TLS dialer to websocket by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1519
-   Fix QEMU scriptlet parameter name by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1524
-   Add shell.nix by [@&#8203;MadnessASAP](https://github.com/MadnessASAP) in lxc/incus#1526
-   client: add proxy host to skopoe inspect by [@&#8203;winiciusallan](https://github.com/winiciusallan) in lxc/incus#1525
-   incusd/cluster: Add missing error handling by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1528
-   incusd/instance/qemu: Fix QMP arguments typing by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1531
-   Encode mc alias for storage buckets to match allowed characters by [@&#8203;monkz](https://github.com/monkz) in lxc/incus#1535
-   doc: Contributing section restructuring by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1534
-   internal/server: allow creation of OVN network with no uplink by [@&#8203;winiciusallan](https://github.com/winiciusallan) in lxc/incus#1533
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1540
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1541
-   lxd-to-incus: Clear volatile.uuid from instances by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1546
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1548
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1550
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1551
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1553
-   Tweak Github Actions and add arm64 tests by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1555
-   Translations update from Hosted Weblate by [@&#8203;weblate](https://github.com/weblate) in lxc/incus#1556
-   incusd/networks: Tweak dnsmasq startup condition by [@&#8203;alex14641](https://github.com/alex14641) in lxc/incus#1544
-   Tweak namespace attach logic in forkproxy and forkfile by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1557
-   Expand block reset logic by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1560
-   Discard blocks on LVM resize by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1561
-   incusd/storage/lvm: Run ClearBlock on all new thick block volumes by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1565
-   Improve format flag by [@&#8203;breml](https://github.com/breml) in lxc/incus#1564
-   devcontainer: initial version by [@&#8203;breml](https://github.com/breml) in lxc/incus#1566
-   incusd/network/ovn: Skip remote peers when iterating peer networks by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1568
-   Fix discard logic on LVM resize and optimize image unpacking by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1569
-   incusd/main_cluster: Tweak to have help refer to correct command name by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1576
-   Docs: Fixed link to point to correct manpage. by [@&#8203;foxtrotcz](https://github.com/foxtrotcz) in lxc/incus#1581
-   incusd/device/disk: Better handle partitions by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1578
-   incusd/storage/drivers: Handle 4k sector sizes by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1585
-   lxd-to-incus: Be more lenient on database changes by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1582
-   incusd/dnsmasq: Don't put the project name in the DNS record by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1586
-   Remove virtfs-proxy-helper dependency by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1547
-   Add new `config` hook by [@&#8203;bensmrs](https://github.com/bensmrs) in lxc/incus#1577
-   github: Switch to Github's hosted arm64 runners by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1589
-   Support for ACLs for bridge NIC device when using nftables driver by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1587
-   doc: typo by [@&#8203;eebssk1](https://github.com/eebssk1) in lxc/incus#1591
-   Added unit for minimum ZFS blocksize by [@&#8203;Spitfireap](https://github.com/Spitfireap) in lxc/incus#1593
-   incus/file/pull: Port to SFTP by [@&#8203;HassanAlsamahi](https://github.com/HassanAlsamahi) in lxc/incus#1592
-   incusd/device/disk: Update correct mount options by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1594
-   doc: Force white background for swagger API by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1599
-   Implement a VM memory dump API by [@&#8203;SpiffyEight77](https://github.com/SpiffyEight77) in lxc/incus#1596
-   gomod: Update dependencies by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1600
-   incus/init: Add support for storage volumes in preseed init by [@&#8203;megheaiulian](https://github.com/megheaiulian) in lxc/incus#1595
-   incusd/instance/qemu: Fix device_id warning on 9.2.x by [@&#8203;stgraber](https://github.com/stgraber) in lxc/incus#1601
-   incus: Fix example description for debug dump-memory command by [@&#8203;SpiffyEight77](https://github.com/SpiffyEight77) in lxc/incus#1602

#### New Contributors

-   [@&#8203;winiciusallan](https://github.com/winiciusallan) made their first contribution in lxc/incus#1512
-   [@&#8203;luissimas](https://github.com/luissimas) made their first contribution in lxc/incus#1498
-   [@&#8203;MadnessASAP](https://github.com/MadnessASAP) made their first contribution in lxc/incus#1526
-   [@&#8203;monkz](https://github.com/monkz) made their first contribution in lxc/incus#1535
-   [@&#8203;alex14641](https://github.com/alex14641) made their first contribution in lxc/incus#1544
-   [@&#8203;foxtrotcz](https://github.com/foxtrotcz) made their first contribution in lxc/incus#1581
-   [@&#8203;eebssk1](https://github.com/eebssk1) made their first contribution in lxc/incus#1591
-   [@&#8203;Spitfireap](https://github.com/Spitfireap) made their first contribution in lxc/incus#1593
-   [@&#8203;megheaiulian](https://github.com/megheaiulian) made their first contribution in lxc/incus#1595

**Full Changelog**: lxc/incus@v6.8.0...v6.9.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMzcuMiIsInVwZGF0ZWRJblZlciI6IjM5LjEzNy4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating
Development

Successfully merging this pull request may close these issues.

Implement a VM memory dump API
2 participants