Use a bare-bones environment for LVM and blkdiscard
They don’t need much!
This commit is contained in:
parent
0c943dfcd6
commit
b7b6d1907c
@ -30,6 +30,8 @@ import qubes
|
|||||||
import qubes.storage
|
import qubes.storage
|
||||||
import qubes.utils
|
import qubes.utils
|
||||||
|
|
||||||
|
_sudo, _dd, _lvm = 'sudo', 'dd', 'lvm'
|
||||||
|
|
||||||
class ThinPool(qubes.storage.Pool):
|
class ThinPool(qubes.storage.Pool):
|
||||||
''' LVM Thin based pool implementation
|
''' LVM Thin based pool implementation
|
||||||
|
|
||||||
@ -199,9 +201,11 @@ class ThinPool(qubes.storage.Pool):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
_init_cache_cmd = ['lvs', '--noheadings', '-o',
|
_init_cache_cmd = [_lvm, 'lvs', '--noheadings', '-o',
|
||||||
'vg_name,pool_lv,name,lv_size,data_percent,lv_attr,origin,lv_metadata_size,'
|
'vg_name,pool_lv,name,lv_size,data_percent,lv_attr,origin,lv_metadata_size,'
|
||||||
'metadata_percent', '--units', 'b', '--separator', ';']
|
'metadata_percent', '--units', 'b', '--separator', ';']
|
||||||
|
if os.getuid() != 0:
|
||||||
|
_init_cache_cmd.insert(0, _sudo)
|
||||||
|
|
||||||
def _parse_lvm_cache(lvm_output):
|
def _parse_lvm_cache(lvm_output):
|
||||||
result = {}
|
result = {}
|
||||||
@ -228,10 +232,7 @@ def _parse_lvm_cache(lvm_output):
|
|||||||
|
|
||||||
def init_cache(log=logging.getLogger('qubes.storage.lvm')):
|
def init_cache(log=logging.getLogger('qubes.storage.lvm')):
|
||||||
cmd = _init_cache_cmd
|
cmd = _init_cache_cmd
|
||||||
if os.getuid() != 0:
|
environ={'LC_ALL': 'C.UTF-8', 'PATH': '/usr/sbin:/usr/bin'}
|
||||||
cmd = ['sudo'] + cmd
|
|
||||||
environ = os.environ.copy()
|
|
||||||
environ['LC_ALL'] = 'C.utf8'
|
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
close_fds=True, env=environ)
|
close_fds=True, env=environ)
|
||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
@ -246,10 +247,7 @@ def init_cache(log=logging.getLogger('qubes.storage.lvm')):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def init_cache_coro(log=logging.getLogger('qubes.storage.lvm')):
|
def init_cache_coro(log=logging.getLogger('qubes.storage.lvm')):
|
||||||
cmd = _init_cache_cmd
|
cmd = _init_cache_cmd
|
||||||
if os.getuid() != 0:
|
environ={'LC_ALL': 'C.UTF-8', 'PATH': '/usr/sbin:/usr/bin'}
|
||||||
cmd = ['sudo'] + cmd
|
|
||||||
environ = os.environ.copy()
|
|
||||||
environ['LC_ALL'] = 'C.utf8'
|
|
||||||
p = yield from asyncio.create_subprocess_exec(*cmd,
|
p = yield from asyncio.create_subprocess_exec(*cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
@ -502,11 +500,11 @@ class ThinVolume(qubes.storage.Volume):
|
|||||||
yield from qubes_lvm_coro(cmd, self.log)
|
yield from qubes_lvm_coro(cmd, self.log)
|
||||||
src_path = yield from qubes.utils.coro_maybe(src_volume.export())
|
src_path = yield from qubes.utils.coro_maybe(src_volume.export())
|
||||||
try:
|
try:
|
||||||
cmd = ['dd', 'if=' + src_path, 'of=/dev/' + self._vid_import,
|
cmd = [_dd, 'if=' + src_path, 'of=/dev/' + self._vid_import,
|
||||||
'conv=sparse', 'status=none', 'bs=128K']
|
'conv=sparse', 'status=none', 'bs=128K']
|
||||||
if not os.access('/dev/' + self._vid_import, os.W_OK) or \
|
if not os.access('/dev/' + self._vid_import, os.W_OK) or \
|
||||||
not os.access(src_path, os.R_OK):
|
not os.access(src_path, os.R_OK):
|
||||||
cmd.insert(0, 'sudo')
|
cmd.insert(0, _sudo)
|
||||||
|
|
||||||
p = yield from asyncio.create_subprocess_exec(*cmd)
|
p = yield from asyncio.create_subprocess_exec(*cmd)
|
||||||
yield from p.wait()
|
yield from p.wait()
|
||||||
@ -754,9 +752,9 @@ def _get_lvm_cmdline(cmd):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError('unsupported action: ' + action)
|
raise NotImplementedError('unsupported action: ' + action)
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
cmd = ['sudo', 'lvm'] + lvm_cmd
|
cmd = [_sudo, _lvm] + lvm_cmd
|
||||||
else:
|
else:
|
||||||
cmd = ['lvm'] + lvm_cmd
|
cmd = [_lvm] + lvm_cmd
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
@ -782,8 +780,7 @@ def qubes_lvm(cmd, log=logging.getLogger('qubes.storage.lvm')):
|
|||||||
''' Call :program:`lvm` to execute an LVM operation '''
|
''' Call :program:`lvm` to execute an LVM operation '''
|
||||||
# the only caller for this non-coroutine version is ThinVolume.export()
|
# the only caller for this non-coroutine version is ThinVolume.export()
|
||||||
cmd = _get_lvm_cmdline(cmd)
|
cmd = _get_lvm_cmdline(cmd)
|
||||||
environ = os.environ.copy()
|
environ={'LC_ALL': 'C.UTF-8', 'PATH': '/usr/sbin:/usr/bin'}
|
||||||
environ['LC_ALL'] = 'C.utf8'
|
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
close_fds=True, env=environ)
|
close_fds=True, env=environ)
|
||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
@ -794,8 +791,7 @@ def qubes_lvm_coro(cmd, log=logging.getLogger('qubes.storage.lvm')):
|
|||||||
''' Call :program:`lvm` to execute an LVM operation
|
''' Call :program:`lvm` to execute an LVM operation
|
||||||
|
|
||||||
Coroutine version of :py:func:`qubes_lvm`'''
|
Coroutine version of :py:func:`qubes_lvm`'''
|
||||||
environ = os.environ.copy()
|
environ={'LC_ALL': 'C.UTF-8', 'PATH': '/usr/sbin:/usr/bin'}
|
||||||
environ['LC_ALL'] = 'C.utf8'
|
|
||||||
if cmd[0] == "remove":
|
if cmd[0] == "remove":
|
||||||
pre_cmd = ['blkdiscard', '-p', '1G', '/dev/'+cmd[1]]
|
pre_cmd = ['blkdiscard', '-p', '1G', '/dev/'+cmd[1]]
|
||||||
p = yield from asyncio.create_subprocess_exec(*pre_cmd,
|
p = yield from asyncio.create_subprocess_exec(*pre_cmd,
|
||||||
|
Loading…
Reference in New Issue
Block a user