chore(xenplatform): elf loader should async load the file (#197)

* fix(build): remove unused environment variables

* chore(xenplatform): elf loader should async load the file
This commit is contained in:
Alex Zenla 2024-06-23 05:57:01 -07:00 committed by GitHub
parent 6c3fc54688
commit 9a45d754bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 25 additions and 25 deletions

View File

@ -27,16 +27,12 @@ jobs:
targets: "${{ matrix.arch }}-unknown-linux-gnu,${{ matrix.arch }}-unknown-linux-musl"
- run: ./hack/ci/install-linux-deps.sh
- run: ./hack/dist/bundle.sh
env:
KRATA_KERNEL_BUILD_JOBS: "5"
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: krata-bundle-systemd-${{ matrix.arch }}
path: "target/dist/bundle-systemd-${{ matrix.arch }}.tgz"
compression-level: 0
- run: ./hack/dist/deb.sh
env:
KRATA_KERNEL_BUILD_SKIP: "1"
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: krata-debian-${{ matrix.arch }}
@ -51,8 +47,6 @@ jobs:
path: "target/dist/*_${{ matrix.arch }}.apk"
compression-level: 0
- run: ./hack/os/build.sh
env:
KRATA_KERNEL_BUILD_SKIP: "1"
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: krata-os-${{ matrix.arch }}

View File

@ -16,10 +16,12 @@ use slice_copy::copy;
use std::collections::HashMap;
use std::io::{BufReader, Read};
use std::mem::size_of;
use std::sync::Arc;
use xz2::bufread::XzDecoder;
#[derive(Clone)]
pub struct ElfImageLoader {
data: Vec<u8>,
data: Arc<Vec<u8>>,
}
fn xen_note_value_as_u64(endian: AnyEndian, value: &[u8]) -> Option<u64> {
@ -59,7 +61,9 @@ fn xen_note_value_as_u64(endian: AnyEndian, value: &[u8]) -> Option<u64> {
impl ElfImageLoader {
pub fn new(data: Vec<u8>) -> ElfImageLoader {
ElfImageLoader { data }
ElfImageLoader {
data: Arc::new(data),
}
}
pub fn load_gz(data: &[u8]) -> Result<ElfImageLoader> {
@ -122,15 +126,8 @@ impl ElfImageLoader {
Err(Error::ElfCompressionUnknown)
}
}
struct ElfNoteValue {
value: u64,
}
#[async_trait::async_trait]
impl BootImageLoader for ElfImageLoader {
async fn parse(&self, hvm: bool) -> Result<BootImageInfo> {
fn parse_sync(&self, hvm: bool) -> Result<BootImageInfo> {
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;
let headers = elf.section_headers().ok_or(Error::ElfInvalidImage)?;
let mut linux_notes: HashMap<u64, Vec<u8>> = HashMap::new();
@ -250,6 +247,18 @@ impl BootImageLoader for ElfImageLoader {
};
Ok(image_info)
}
}
struct ElfNoteValue {
value: u64,
}
#[async_trait::async_trait]
impl BootImageLoader for ElfImageLoader {
async fn parse(&self, hvm: bool) -> Result<BootImageInfo> {
let loader = self.clone();
tokio::task::spawn_blocking(move || loader.parse_sync(hvm)).await?
}
async fn load(&self, image_info: &BootImageInfo, dst: &mut [u8]) -> Result<()> {
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;

View File

@ -38,6 +38,8 @@ pub enum Error {
GenericError(String),
#[error("failed to parse int: {0}")]
ParseIntError(#[from] std::num::ParseIntError),
#[error("failed to join async task: {0}")]
AsyncJoinError(#[from] tokio::task::JoinError),
}
pub type Result<T> = std::result::Result<T, Error>;

5
hack/dist/bundle.sh vendored
View File

@ -4,11 +4,6 @@ set -e
# shellcheck source-path=SCRIPTDIR source=common.sh
. "$(dirname "${0}")/common.sh"
if [ -z "${KRATA_KERNEL_BUILD_JOBS}" ]
then
KRATA_KERNEL_BUILD_JOBS="2"
fi
TARGET_ARCH="$("${KRATA_DIR}/hack/build/arch.sh")"
BUNDLE_TAR="${OUTPUT_DIR}/bundle-systemd-${TARGET_ARCH}.tgz"
rm -f "${BUNDLE_TAR}"

View File

@ -7,7 +7,7 @@ remove_service_if_exists() {
UNIT_PATH="$(systemctl show -P FragmentPath "${1}")"
if [ -f "${UNIT_PATH}" ]
then
echo "[WARN] disabling removing systemd unit ${UNIT_PATH}" > /dev/stderr
echo "[WARN] disabling and removing systemd unit ${UNIT_PATH}" > /dev/stderr
systemctl disable --now "${1}" || true
rm "${UNIT_PATH}"
fi

View File

@ -1,5 +1,5 @@
#!/sbin/openrc-run
description="Krata Control Daemon"
description="Krata Isolation Engine"
command="/usr/libexec/kratad"
supervisor="supervise-daemon"
output_log="/var/log/kratad.log"

View File

@ -1,5 +1,5 @@
[Unit]
Description=Krata Control Daemon
Description=Krata Isolation Engine
[Service]
Restart=on-failure

View File

@ -1,5 +1,5 @@
[Unit]
Description=Krata Networking Daemon
Description=Krata Networking Engine
[Service]
Wants=kratad.service