diff options
Diffstat (limited to 'nova/virt/libvirt/volume')
-rw-r--r-- | nova/virt/libvirt/volume/quobyte.py | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/nova/virt/libvirt/volume/quobyte.py b/nova/virt/libvirt/volume/quobyte.py index e0885931cd..7c7724c5ff 100644 --- a/nova/virt/libvirt/volume/quobyte.py +++ b/nova/virt/libvirt/volume/quobyte.py @@ -25,6 +25,7 @@ import six import nova.conf from nova import exception as nova_exception from nova.i18n import _ +from nova.privsep import libvirt from nova import utils from nova.virt.libvirt import utils as libvirt_utils from nova.virt.libvirt.volume import fs @@ -37,35 +38,60 @@ SOURCE_PROTOCOL = 'quobyte' SOURCE_TYPE = 'file' DRIVER_CACHE = 'none' DRIVER_IO = 'native' +VALID_SYSD_STATES = ["starting", "running", "degraded"] +SYSTEMCTL_CHECK_PATH = "/run/systemd/system" + +sysd_checked = False +found_sysd = False + + +def is_systemd(): + """Checks if the host is running systemd""" + global sysd_checked + global found_sysd + if psutil.Process(1).name() == "systemd" or os.path.exists( + SYSTEMCTL_CHECK_PATH): + # NOTE(kaisers): exit code might be >1 in theory but in practice this + # is hard coded to 1. Due to backwards compatibility and systemd + # CODING_STYLE this is unlikely to change. + sysdout, sysderr = processutils.execute("systemctl", + "is-system-running", + check_exit_code=[0, 1]) + for state in VALID_SYSD_STATES: + if state == sysdout.strip(): + found_sysd = True + sysd_checked = True + return found_sysd + + sysd_checked = True + return False def mount_volume(volume, mnt_base, configfile=None): """Wraps execute calls for mounting a Quobyte volume""" fileutils.ensure_tree(mnt_base) - # NOTE(kaisers): disable xattrs to speed up io as this omits - # additional metadata requests in the backend. xattrs can be - # enabled without issues but will reduce performance. - command = ['mount.quobyte', '--disable-xattrs', volume, mnt_base] - if os.path.exists(" /run/systemd/system"): - # Note(kaisers): with systemd this requires a separate CGROUP to - # prevent Nova service stop/restarts from killing the mount. - command = ['systemd-run', '--scope', '--user', 'mount.quobyte', - '--disable-xattrs', volume, mnt_base] - if configfile: - command.extend(['-c', configfile]) - - LOG.debug('Mounting volume %s at mount point %s ...', - volume, - mnt_base) - processutils.execute(*command) + # Note(kaisers): with systemd this requires a separate CGROUP to + # prevent Nova service stop/restarts from killing the mount. + if found_sysd: + LOG.debug('Mounting volume %s at mount point %s via systemd-run', + volume, mnt_base) + libvirt.systemd_run_qb_mount(volume, mnt_base, cfg_file=configfile) + else: + LOG.debug('Mounting volume %s at mount point %s via mount.quobyte', + volume, mnt_base, cfg_file=configfile) + + libvirt.unprivileged_qb_mount(volume, mnt_base, cfg_file=configfile) LOG.info('Mounted volume: %s', volume) def umount_volume(mnt_base): """Wraps execute calls for unmouting a Quobyte volume""" try: - processutils.execute('umount.quobyte', mnt_base) + if found_sysd: + libvirt.umount(mnt_base) + else: + libvirt.unprivileged_umount(mnt_base) except processutils.ProcessExecutionError as exc: if 'Device or resource busy' in six.text_type(exc): LOG.error("The Quobyte volume at %s is still in use.", mnt_base) @@ -105,6 +131,9 @@ def validate_volume(mount_path): class LibvirtQuobyteVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver): """Class implements libvirt part of volume driver for Quobyte.""" + def __init__(self, host): + super(LibvirtQuobyteVolumeDriver, self).__init__(host) + def _get_mount_point_base(self): return CONF.libvirt.quobyte_mount_point_base @@ -125,6 +154,11 @@ class LibvirtQuobyteVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver): @utils.synchronized('connect_qb_volume') def connect_volume(self, connection_info, instance): """Connect the volume.""" + if is_systemd(): + LOG.debug("systemd detected.") + else: + LOG.debug("No systemd detected.") + data = connection_info['data'] quobyte_volume = self._normalize_export(data['export']) mount_path = self._get_mount_path(connection_info) |