create: Use emulation when /dev/kvm is not available
Signed-off-by: Alberto Faria <afaria@redhat.com>
This commit is contained in:
parent
ee504a43a2
commit
3a724ec6bc
|
@ -35,10 +35,19 @@ fn generate(
|
|||
.perform_indent(true)
|
||||
.create_writer(File::create(path.as_ref())?);
|
||||
|
||||
s(&mut w, "domain", &[("type", "kvm")], |w| {
|
||||
let has_kvm = Utf8Path::new("/dev/kvm").exists();
|
||||
let domain_type = if has_kvm { "kvm" } else { "qemu" };
|
||||
|
||||
s(&mut w, "domain", &[("type", domain_type)], |w| {
|
||||
st(w, "name", &[], "domain")?;
|
||||
|
||||
se(w, "cpu", &[("mode", "host-passthrough")])?;
|
||||
let cpu_mode = if has_kvm {
|
||||
"host-passthrough"
|
||||
} else {
|
||||
"host-model"
|
||||
};
|
||||
se(w, "cpu", &[("mode", cpu_mode)])?;
|
||||
|
||||
let vcpus = get_vcpu_count(spec).to_string();
|
||||
if let Some(cpu_set) = get_cpu_set(spec) {
|
||||
st(w, "vcpu", &[("cpuset", cpu_set.as_str())], vcpus.as_str())?;
|
||||
|
|
|
@ -526,8 +526,10 @@ fn set_up_extra_container_mounts_and_devices(spec: &mut oci_spec::runtime::Spec)
|
|||
.unwrap(),
|
||||
);
|
||||
|
||||
add_bind_mount(spec, "/dev/kvm");
|
||||
add_char_dev(spec, "/dev/kvm")?;
|
||||
if Utf8Path::new("/dev/kvm").exists() {
|
||||
add_bind_mount(spec, "/dev/kvm");
|
||||
add_char_dev(spec, "/dev/kvm")?;
|
||||
}
|
||||
|
||||
// in case user sets up VFIO passthrough by overriding the libvirt XML
|
||||
for entry in fs::read_dir("/dev/vfio")? {
|
||||
|
|
Loading…
Reference in New Issue