|
|
bda387 |
From 1d9dc59ab2c471d7dcc39cd6982bd14380d5f726 Mon Sep 17 00:00:00 2001
|
|
|
bda387 |
From: David Lehman <dlehman@redhat.com>
|
|
|
bda387 |
Date: Thu, 13 Jun 2019 11:22:16 -0400
|
|
|
bda387 |
Subject: [PATCH 1/3] Add a function to detect if running in a vm.
|
|
|
bda387 |
|
|
|
bda387 |
Related: rhbz#1676935
|
|
|
bda387 |
---
|
|
|
bda387 |
blivet/util.py | 14 ++++++++++++++
|
|
|
bda387 |
1 file changed, 14 insertions(+)
|
|
|
bda387 |
|
|
|
bda387 |
diff --git a/blivet/util.py b/blivet/util.py
|
|
|
bda387 |
index 542bc93f..fa5e9e35 100644
|
|
|
bda387 |
--- a/blivet/util.py
|
|
|
bda387 |
+++ b/blivet/util.py
|
|
|
bda387 |
@@ -1,4 +1,5 @@
|
|
|
bda387 |
import copy
|
|
|
bda387 |
+from distutils.spawn import find_executable
|
|
|
bda387 |
import functools
|
|
|
bda387 |
import glob
|
|
|
bda387 |
import itertools
|
|
|
bda387 |
@@ -1100,3 +1101,16 @@ def decorated(*args, **kwargs):
|
|
|
bda387 |
return None
|
|
|
bda387 |
return decorated
|
|
|
bda387 |
return decorator
|
|
|
bda387 |
+
|
|
|
bda387 |
+
|
|
|
bda387 |
+def detect_virt():
|
|
|
bda387 |
+ """ Return True if we are running in a virtual machine. """
|
|
|
bda387 |
+ in_vm = False
|
|
|
bda387 |
+ detect_virt_prog = find_executable('systemd-detect-virt')
|
|
|
bda387 |
+ if detect_virt_prog:
|
|
|
bda387 |
+ try:
|
|
|
bda387 |
+ in_vm = run_program([detect_virt_prog, "--vm"]) == 0
|
|
|
bda387 |
+ except OSError:
|
|
|
bda387 |
+ pass
|
|
|
bda387 |
+
|
|
|
bda387 |
+ return in_vm
|
|
|
bda387 |
|
|
|
bda387 |
From 26d4b48ab5eca44695dced52c6170ec04610bc1d Mon Sep 17 00:00:00 2001
|
|
|
bda387 |
From: David Lehman <dlehman@redhat.com>
|
|
|
bda387 |
Date: Thu, 13 Jun 2019 10:57:48 -0400
|
|
|
bda387 |
Subject: [PATCH 2/3] Use dasd disklabel for vm disks backed by dasds.
|
|
|
bda387 |
|
|
|
bda387 |
Resolves: rhbz#1676935
|
|
|
bda387 |
---
|
|
|
bda387 |
blivet/formats/disklabel.py | 9 +++++++++
|
|
|
bda387 |
1 file changed, 9 insertions(+)
|
|
|
bda387 |
|
|
|
bda387 |
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
|
|
|
bda387 |
index 8186d1a1..0c4fce35 100644
|
|
|
bda387 |
--- a/blivet/formats/disklabel.py
|
|
|
bda387 |
+++ b/blivet/formats/disklabel.py
|
|
|
bda387 |
@@ -261,6 +261,15 @@ def _get_best_label_type(self):
|
|
|
bda387 |
elif self.parted_device.type == parted.DEVICE_DASD:
|
|
|
bda387 |
# the device is DASD
|
|
|
bda387 |
return "dasd"
|
|
|
bda387 |
+ elif util.detect_virt():
|
|
|
bda387 |
+ # check for dasds exported into qemu as normal virtio/scsi disks
|
|
|
bda387 |
+ try:
|
|
|
bda387 |
+ _parted_disk = parted.Disk(device=self.parted_device)
|
|
|
bda387 |
+ except (_ped.DiskLabelException, _ped.IOException, NotImplementedError):
|
|
|
bda387 |
+ pass
|
|
|
bda387 |
+ else:
|
|
|
bda387 |
+ if _parted_disk.type == "dasd":
|
|
|
bda387 |
+ return "dasd"
|
|
|
bda387 |
|
|
|
bda387 |
for lt in label_types:
|
|
|
bda387 |
if self._label_type_size_check(lt):
|
|
|
bda387 |
|
|
|
bda387 |
From c93d1207bb2942736a390bd58adafda3deb1c25c Mon Sep 17 00:00:00 2001
|
|
|
bda387 |
From: David Lehman <dlehman@redhat.com>
|
|
|
bda387 |
Date: Thu, 13 Jun 2019 12:04:23 -0400
|
|
|
bda387 |
Subject: [PATCH 3/3] Use DBus call to see if we're in a vm.
|
|
|
bda387 |
|
|
|
bda387 |
---
|
|
|
bda387 |
blivet/util.py | 22 +++++++++++++---------
|
|
|
bda387 |
1 file changed, 13 insertions(+), 9 deletions(-)
|
|
|
bda387 |
|
|
|
bda387 |
diff --git a/blivet/util.py b/blivet/util.py
|
|
|
bda387 |
index fa5e9e35..2932e8b5 100644
|
|
|
bda387 |
--- a/blivet/util.py
|
|
|
bda387 |
+++ b/blivet/util.py
|
|
|
bda387 |
@@ -1,5 +1,4 @@
|
|
|
bda387 |
import copy
|
|
|
bda387 |
-from distutils.spawn import find_executable
|
|
|
bda387 |
import functools
|
|
|
bda387 |
import glob
|
|
|
bda387 |
import itertools
|
|
|
bda387 |
@@ -20,6 +19,7 @@
|
|
|
bda387 |
from enum import Enum
|
|
|
bda387 |
|
|
|
bda387 |
from .errors import DependencyError
|
|
|
bda387 |
+from . import safe_dbus
|
|
|
bda387 |
|
|
|
bda387 |
import gi
|
|
|
bda387 |
gi.require_version("BlockDev", "2.0")
|
|
|
bda387 |
@@ -39,6 +39,12 @@
|
|
|
bda387 |
program_log_lock = Lock()
|
|
|
bda387 |
|
|
|
bda387 |
|
|
|
bda387 |
+SYSTEMD_SERVICE = "org.freedesktop.systemd1"
|
|
|
bda387 |
+SYSTEMD_MANAGER_PATH = "/org/freedesktop/systemd1/Manager"
|
|
|
bda387 |
+SYSTEMD_MANAGER_IFACE = "org.freedesktop.systemd1.Manager"
|
|
|
bda387 |
+VIRT_PROP_NAME = "Virtualization"
|
|
|
bda387 |
+
|
|
|
bda387 |
+
|
|
|
bda387 |
class Path(str):
|
|
|
bda387 |
|
|
|
bda387 |
""" Path(path, root=None) provides a filesystem path object, which
|
|
|
bda387 |
@@ -1105,12 +1111,10 @@ def decorated(*args, **kwargs):
|
|
|
bda387 |
|
|
|
bda387 |
def detect_virt():
|
|
|
bda387 |
""" Return True if we are running in a virtual machine. """
|
|
|
bda387 |
- in_vm = False
|
|
|
bda387 |
- detect_virt_prog = find_executable('systemd-detect-virt')
|
|
|
bda387 |
- if detect_virt_prog:
|
|
|
bda387 |
- try:
|
|
|
bda387 |
- in_vm = run_program([detect_virt_prog, "--vm"]) == 0
|
|
|
bda387 |
- except OSError:
|
|
|
bda387 |
- pass
|
|
|
bda387 |
+ try:
|
|
|
bda387 |
+ vm = safe_dbus.get_property_sync(SYSTEMD_SERVICE, SYSTEMD_MANAGER_PATH,
|
|
|
bda387 |
+ SYSTEMD_MANAGER_IFACE, VIRT_PROP_NAME)
|
|
|
bda387 |
+ except (safe_dbus.DBusCallError, safe_dbus.DBusPropertyError):
|
|
|
bda387 |
+ vm = None
|
|
|
bda387 |
|
|
|
bda387 |
- return in_vm
|
|
|
bda387 |
+ return vm in ('qemu', 'kvm')
|