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

Add LXD VM Guest Agent Support #2145

Merged
merged 4 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildroot-external/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ source "$BR2_EXTERNAL_HASSOS_PATH/package/khadas-boot/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/os-agent/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/pi-bluetooth/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/qemu-guest-agent/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/lxd-guest-agent/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/rpi-eeprom/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/rpi-rf-mod/Config.in"
source "$BR2_EXTERNAL_HASSOS_PATH/package/rtl88x2bu/Config.in"
Expand Down
10 changes: 10 additions & 0 deletions buildroot-external/board/pc/ova/kernel.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ CONFIG_VMWARE_VMCI=y
CONFIG_VMWARE_BALLOON=y
CONFIG_VMWARE_PVSCSI=y

# These options are for LXD Guest Support
CONFIG_NET_9P=m
CONFIG_NET_9P_VIRTIO=m
CONFIG_9P_FS=m
CONFIG_9P_FS_POSIX_ACL=m
CONFIG_PCI=y
CONFIG_VSOCKETS=m
CONFIG_VIRTIO_VSOCKETS_COMMON=m
CONFIG_VHOST_VSOCK=m

# VirtualBox
CONFIG_VBOXGUEST=m

Expand Down
1 change: 1 addition & 0 deletions buildroot-external/configs/ova_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ BR2_PACKAGE_HASSIO_ARCH="amd64"
BR2_PACKAGE_HASSIO_MACHINE="qemux86-64"
BR2_PACKAGE_OS_AGENT=y
BR2_PACKAGE_QEMU_GUEST_AGENT=y
BR2_PACKAGE_LXD_GUEST_AGENT=y
BR2_PACKAGE_RPI_RF_MOD=y
BR2_PACKAGE_RTL88X2BU=y
BR2_PACKAGE_RTL8821CU=y
Expand Down
9 changes: 9 additions & 0 deletions buildroot-external/package/lxd-guest-agent/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config BR2_PACKAGE_LXD_GUEST_AGENT
bool "LXD Guest Agent"
depends on BR2_USE_MMU # libglib2
depends on BR2_USE_WCHAR # libglib2
depends on BR2_TOOLCHAIN_HAS_THREADS # libglib2
select BR2_PACKAGE_LIBGLIB2
select BR2_PACKAGE_ZLIB
help
LXD guest agent for LXD based virtualisations
39 changes: 39 additions & 0 deletions buildroot-external/package/lxd-guest-agent/lxd-agent-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
set -eu
PREFIX="/run/lxd_agent"

# Functions.
mount_virtiofs() {
mount -t virtiofs config "${PREFIX}/.mnt" >/dev/null 2>&1
}

mount_9p() {
/sbin/modprobe 9pnet_virtio >/dev/null 2>&1 || true
/bin/mount -t 9p config "${PREFIX}/.mnt" -o access=0,trans=virtio >/dev/null 2>&1
}

fail() {
umount -l "${PREFIX}" >/dev/null 2>&1 || true
rmdir "${PREFIX}" >/dev/null 2>&1 || true
echo "${1}"
exit 1
}

# Setup the mount target.
umount -l "${PREFIX}" >/dev/null 2>&1 || true
mkdir -p "${PREFIX}"
mount -t tmpfs tmpfs "${PREFIX}" -o mode=0700,size=50M
mkdir -p "${PREFIX}/.mnt"

# Try virtiofs first.
mount_virtiofs || mount_9p || fail "Couldn't mount virtiofs or 9p, failing."

# Copy the data.
cp -Ra "${PREFIX}/.mnt/"* "${PREFIX}"

# Unmount the temporary mount.
umount "${PREFIX}/.mnt"
rmdir "${PREFIX}/.mnt"

# Fix up permissions.
chown -R root:root "${PREFIX}"
17 changes: 17 additions & 0 deletions buildroot-external/package/lxd-guest-agent/lxd-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=LXD - agent
After=syslog.target network.target
ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd

[Service]
Type=notify
WorkingDirectory=-/run/lxd_agent
ExecStartPre=/usr/lib/systemd/lxd-agent-setup
ExecStart=/run/lxd_agent/lxd-agent
Restart=on-failure
RestartSec=5s
StartLimitInterval=60
StartLimitBurst=10

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions buildroot-external/package/lxd-guest-agent/lxd-guest-agent.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
################################################################################
#
# lxd-guest-agent
#
################################################################################

LXD_GUEST_AGENT_DEPENDENCIES = host-pkgconf

define LXD_GUEST_AGENT_INSTALL_INIT_SYSTEMD
$(INSTALL) -D -m 644 $(LXD_GUEST_AGENT_PKGDIR)/lxd-agent.service \
$(TARGET_DIR)/usr/lib/systemd/system/lxd-agent.service
$(INSTALL) -D -m 755 $(LXD_GUEST_AGENT_PKGDIR)/lxd-agent-setup \
$(TARGET_DIR)/usr/lib/systemd/lxd-agent-setup
$(INSTALL) -d $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -fs /usr/lib/systemd/system/lxd-agent.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/lxd-agent.service
endef

$(eval $(generic-package))
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=QEMU Guest Agent
After=syslog.target network.target
ConditionVirtualization=|kvm
ConditionVirtualization=|qemu
ConditionPathExists=!/dev/virtio-ports/org.linuxcontainers.lxd
agners marked this conversation as resolved.
Show resolved Hide resolved

[Service]
ExecStart=/usr/libexec/qemu-ga -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0
Expand Down