diff --git a/makefile b/makefile index e0363f5aa..03524b852 100644 --- a/makefile +++ b/makefile @@ -1,13 +1,14 @@ # -# OUTPUT PATHS +# variables shared by all child make process # -PREFIX ?= /usr/local -QBIN_DIR ?= $(PREFIX)/bin -QCONFIG_DIR ?= /etc/quark -QLOG_DIR ?= /var/log/quark - +export PREFIX ?= /usr/local +export QBIN_DIR ?= $(PREFIX)/bin +export QCONFIG_DIR ?= /etc/quark +export QLOG_DIR ?= /var/log/quark +export ARCH ?= ${shell uname -m} +export RUST_TOOLCHAIN = nightly-2023-12-11-$(ARCH)-unknown-linux-gnu # -# BUILD PATHS +# BUILD PATHS, used by this make process only # QKERNEL_BUILD = build QTARGET_RELEASE = target/release @@ -18,10 +19,6 @@ QUARK_DEBUG = $(QTARGET_DEBUG)/quark QUARK_RELEASE = $(QTARGET_RELEASE)/quark VDSO = vdso/vdso.so -ARCH := ${shell uname -m} -RUST_TOOLCHAIN = nightly-2023-12-11-$(ARCH)-unknown-linux-gnu - - .PHONY: all release debug clean install qvisor_release qvisor_debug cuda_make cuda_all cleanall all:: release debug @@ -33,16 +30,16 @@ release:: qvisor_release qkernel_release $(VDSO) debug:: qvisor_debug qkernel_debug $(VDSO) qvisor_release: - make -C ./qvisor TOOLCHAIN=$(RUST_TOOLCHAIN) release + make -C ./qvisor release qkernel_release: - make -C ./qkernel TOOLCHAIN=$(RUST_TOOLCHAIN) release + make -C ./qkernel release qvisor_debug: - make -C ./qvisor TOOLCHAIN=$(RUST_TOOLCHAIN) debug + make -C ./qvisor debug qkernel_debug: - make -C ./qkernel TOOLCHAIN=$(RUST_TOOLCHAIN) debug + make -C ./qkernel debug $(VDSO): make -C ./vdso @@ -65,21 +62,21 @@ cuda_release:: qvisor_cuda_release qkernel_release cuda_make cuda_debug:: qvisor_cuda_debug qkernel_debug cuda_make qvisor_cuda_release: - make -C ./qvisor TOOLCHAIN=$(RUST_TOOLCHAIN) cuda_release + make -C ./qvisor cuda_release qvisor_cuda_debug: - make -C ./qvisor TOOLCHAIN=$(RUST_TOOLCHAIN) cuda_debug + make -C ./qvisor cuda_debug install: - -sudo cp -f $(QKERNEL_RELEASE) $(QBIN_DIR)/ - -sudo cp -f $(QUARK_RELEASE) $(QBIN_DIR)/quark - -sudo cp -f $(QUARK_RELEASE) $(QBIN_DIR)/containerd-shim-quark-v1 - -sudo cp -f $(QKERNEL_DEBUG) $(QBIN_DIR)/ - -sudo cp -f $(QUARK_DEBUG) $(QBIN_DIR)/quark_d - -sudo cp -f $(QUARK_DEBUG) $(QBIN_DIR)/containerd-shim-quarkd-v1 - sudo cp -f $(VDSO) $(QBIN_DIR)/vdso.so - sudo mkdir -p $(QCONFIG_DIR) - sudo cp -f config.json $(QCONFIG_DIR) + -cp -f $(QKERNEL_RELEASE) $(QBIN_DIR)/ + -cp -f $(QUARK_RELEASE) $(QBIN_DIR)/quark + -cp -f $(QUARK_RELEASE) $(QBIN_DIR)/containerd-shim-quark-v1 + -cp -f $(QKERNEL_DEBUG) $(QBIN_DIR)/ + -cp -f $(QUARK_DEBUG) $(QBIN_DIR)/quark_d + -cp -f $(QUARK_DEBUG) $(QBIN_DIR)/containerd-shim-quarkd-v1 + cp -f $(VDSO) $(QBIN_DIR)/vdso.so + mkdir -p $(QCONFIG_DIR) + cp -f config.json $(QCONFIG_DIR) cuda_make: make -C cudaproxy release diff --git a/qkernel/makefile b/qkernel/makefile index a373eef84..5eb2e3f76 100644 --- a/qkernel/makefile +++ b/qkernel/makefile @@ -25,10 +25,10 @@ $(kernel_debug): kernel_debug $(assembly_object_files) $(assembly_object_files) $(qkernel_debug) kernel: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) xbuild --target $(arch)-qkernel.json --release + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) xbuild --target $(arch)-qkernel.json --release kernel_debug: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) xbuild --target $(arch)-qkernel.json + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) xbuild --target $(arch)-qkernel.json ../build/arch/$(arch)/%.o: src/qlib/kernel/arch/$(arch)/%.s @mkdir -p $(shell dirname $@) diff --git a/qvisor/Cargo.lock b/qvisor/Cargo.lock index 0173f2789..919e87b58 100644 --- a/qvisor/Cargo.lock +++ b/qvisor/Cargo.lock @@ -203,6 +203,26 @@ dependencies = [ "thiserror", ] +[[package]] +name = "const_format" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +dependencies = [ + "proc-macro2", + "quote 1.0.15", + "unicode-xid 0.2.2", +] + [[package]] name = "containerd-shim" version = "0.3.0" @@ -976,6 +996,7 @@ dependencies = [ "caps", "chrono", "clap", + "const_format", "containerd-shim", "core_affinity", "crossbeam-queue", diff --git a/qvisor/Cargo.toml b/qvisor/Cargo.toml index 3fc39df93..97e704c45 100644 --- a/qvisor/Cargo.toml +++ b/qvisor/Cargo.toml @@ -58,6 +58,7 @@ rcublas-sys = { version = "0.5.0", optional = true } cuda11-cublasLt-sys = { version = "0.3.0", optional = true } libelf = { version = "0.1.0", optional = true } io-uring = "0.6.3" +const_format = "0.2.32" [features] cuda = ["cuda-driver-sys", "cuda-runtime-sys", "libelf", "rcublas-sys", "cuda11-cublasLt-sys"] diff --git a/qvisor/makefile b/qvisor/makefile index 266736422..cc748ab5d 100644 --- a/qvisor/makefile +++ b/qvisor/makefile @@ -1,13 +1,13 @@ .PHONY: debug release cuda_debug cuda_release debug: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) build + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) build release: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) build --release + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) build --release cuda_debug: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) build --features cuda + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) build --features cuda cuda_release: - CARGO_TARGET_DIR=../target cargo +$(TOOLCHAIN) build --release --features cuda + CARGO_TARGET_DIR=../target cargo +$(RUST_TOOLCHAIN) build --release --features cuda diff --git a/qvisor/src/main.rs b/qvisor/src/main.rs index 4ab96d59d..66136cc55 100644 --- a/qvisor/src/main.rs +++ b/qvisor/src/main.rs @@ -61,6 +61,8 @@ extern crate regex; extern crate simplelog; extern crate spin; extern crate tabwriter; +#[macro_use] +extern crate const_format; #[macro_use] pub mod print; @@ -169,8 +171,6 @@ lazy_static! { ); } -pub const LOG_FILE: &'static str = "/var/log/quark/quark.log"; - pub fn InitSingleton() { self::qlib::InitSingleton(); } diff --git a/qvisor/src/print.rs b/qvisor/src/print.rs index e78c17e13..1fc7e820a 100644 --- a/qvisor/src/print.rs +++ b/qvisor/src/print.rs @@ -43,9 +43,14 @@ pub fn SetSyncPrint(syncPrint: bool) { LOG.SetSyncPrint(syncPrint); } -pub const LOG_FILE_DEFAULT: &str = "/var/log/quark/quark.log"; -pub const RAWLOG_FILE_DEFAULT: &str = "/var/log/quark/raw.log"; -pub const LOG_FILE_FORMAT: &str = "/var/log/quark/{}.log"; + +pub const LOG_DIR: &str = match option_env!("QLOG_DIR") { + Some(s) => s, + None => "/var/log/quark" +}; +pub const LOG_FILE_DEFAULT: &str = concatcp!(LOG_DIR, "/quark.log"); +pub const RAWLOG_FILE_DEFAULT: &str = concatcp!(LOG_DIR, "/raw.log"); +pub const LOG_FILE_FORMAT: &str = concatcp!(LOG_DIR, "/{}.log"); pub const TIME_FORMAT: &str = "%H:%M:%S%.3f"; pub const MEMORY_LEAK_LOG: bool = false; diff --git a/qvisor/src/runc/cmd/cmd.rs b/qvisor/src/runc/cmd/cmd.rs index fc88d694c..2778cb3ae 100644 --- a/qvisor/src/runc/cmd/cmd.rs +++ b/qvisor/src/runc/cmd/cmd.rs @@ -76,7 +76,11 @@ impl CmdCmd { } impl Config { - pub const CONFIG_FILE: &'static str = "/etc/quark/config.json"; + pub const CONFIG_DIR: &'static str = match option_env!("QCONFIG_DIR") { + Some(s) => s, + None => "/etc/quark" + }; + pub const CONFIG_FILE: &'static str = concatcp!(Config::CONFIG_DIR, "/config.json"); // if the config file exist, load file and return true; otherwise return false pub fn Load(&mut self) -> bool { diff --git a/qvisor/src/runc/runtime/vm.rs b/qvisor/src/runc/runtime/vm.rs index 49ad4c3ab..09f5016f8 100644 --- a/qvisor/src/runc/runtime/vm.rs +++ b/qvisor/src/runc/runtime/vm.rs @@ -166,13 +166,15 @@ impl VirtualMachine { ); } + pub const QUARK_BIN_DIR: &'static str = match option_env!("QBIN_DIR") { + Some(s) => s, + None => "/usr/local/bin" + }; + pub const VDSO_PATH: &'static str = concatcp!(VirtualMachine::QUARK_BIN_DIR, "/vdso.so"); #[cfg(debug_assertions)] - pub const KERNEL_IMAGE: &'static str = "/usr/local/bin/qkernel_d.bin"; - + pub const KERNEL_IMAGE: &'static str = concatcp!(VirtualMachine::QUARK_BIN_DIR, "/qkernel_d.bin"); #[cfg(not(debug_assertions))] - pub const KERNEL_IMAGE: &'static str = "/usr/local/bin/qkernel.bin"; - - pub const VDSO_PATH: &'static str = "/usr/local/bin/vdso.so"; + pub const KERNEL_IMAGE: &'static str = concatcp!(VirtualMachine::QUARK_BIN_DIR, "/qkernel.bin"); pub fn InitShareSpace( cpuCount: usize,