Fix up blockdev holder support to mark raid and bcache holders
Fixing this prevents devices that are part of a bcache from being presented as available. Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
parent
0385e754ab
commit
75a3171d57
|
@ -130,7 +130,7 @@ class Blockdev():
|
||||||
self._mountactions = {}
|
self._mountactions = {}
|
||||||
self.bcache = []
|
self.bcache = []
|
||||||
self.lvm = []
|
self.lvm = []
|
||||||
self.holder = {}
|
self.holders = []
|
||||||
self.baseaction = DiskAction(os.path.basename(self.disk.devpath),
|
self.baseaction = DiskAction(os.path.basename(self.disk.devpath),
|
||||||
self.disk.model, self.disk.serial,
|
self.disk.model, self.disk.serial,
|
||||||
self.disk.parttype)
|
self.disk.parttype)
|
||||||
|
@ -143,7 +143,7 @@ class Blockdev():
|
||||||
self._mountactions == other._mountactions and
|
self._mountactions == other._mountactions and
|
||||||
self.bcache == other.bcache and
|
self.bcache == other.bcache and
|
||||||
self.lvm == other.lvm and
|
self.lvm == other.lvm and
|
||||||
self.holder == other.holder and
|
self.holders == other.holders and
|
||||||
self.baseaction == other.baseaction)
|
self.baseaction == other.baseaction)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -164,7 +164,7 @@ class Blockdev():
|
||||||
self._mountactions = {}
|
self._mountactions = {}
|
||||||
self.bcache = []
|
self.bcache = []
|
||||||
self.lvm = []
|
self.lvm = []
|
||||||
self.holder = {}
|
self.holders = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self):
|
def id(self):
|
||||||
|
@ -231,8 +231,9 @@ class Blockdev():
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
''' return True if has free space or partitions not
|
''' return True if has free space or partitions not
|
||||||
assigned '''
|
assigned, and no holders '''
|
||||||
if not self.is_mounted() and self.percent_free > 0:
|
if not self.is_mounted() and self.percent_free > 0 \
|
||||||
|
and len(self.holders) == 0:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -350,8 +351,13 @@ class Blockdev():
|
||||||
[partnum] = re.findall('\d+$', devpath)
|
[partnum] = re.findall('\d+$', devpath)
|
||||||
return self.disk.partitions[int(partnum)]
|
return self.disk.partitions[int(partnum)]
|
||||||
|
|
||||||
def set_holder(self, devpath, holdtype):
|
def set_holder(self, devpath):
|
||||||
self.holder[holdtype] = devpath
|
if devpath not in self.holders:
|
||||||
|
self.holders.append(devpath)
|
||||||
|
|
||||||
|
def clear_holder(self, devpath):
|
||||||
|
if devpath in self.holder:
|
||||||
|
self.holders.remove(devpath)
|
||||||
|
|
||||||
def is_mounted(self):
|
def is_mounted(self):
|
||||||
with open('/proc/mounts') as pm:
|
with open('/proc/mounts') as pm:
|
||||||
|
@ -438,7 +444,7 @@ class Bcachedev(Blockdev):
|
||||||
|
|
||||||
def sort_actions(actions):
|
def sort_actions(actions):
|
||||||
def type_index(t):
|
def type_index(t):
|
||||||
order = ['disk', 'partition', 'raid', 'format', 'mount']
|
order = ['disk', 'partition', 'raid', 'bcache', 'format', 'mount']
|
||||||
return order.index(t.get('type'))
|
return order.index(t.get('type'))
|
||||||
|
|
||||||
def path_count(p):
|
def path_count(p):
|
||||||
|
|
|
@ -293,10 +293,12 @@ class FilesystemModel(ModelPolicy):
|
||||||
# create a Raiddev (pass in only the names)
|
# create a Raiddev (pass in only the names)
|
||||||
raid_parts = []
|
raid_parts = []
|
||||||
for dev in raid_devices:
|
for dev in raid_devices:
|
||||||
|
dev.set_holder(raid_dev_name)
|
||||||
for num, action in dev.partitions.items():
|
for num, action in dev.partitions.items():
|
||||||
raid_parts.append(action.action_id)
|
raid_parts.append(action.action_id)
|
||||||
spare_parts = []
|
spare_parts = []
|
||||||
for dev in spare_devices:
|
for dev in spare_devices:
|
||||||
|
dev.set_holder(raid_dev_name)
|
||||||
for num, action in dev.partitions.items():
|
for num, action in dev.partitions.items():
|
||||||
spare_parts.append(action.action_id)
|
spare_parts.append(action.action_id)
|
||||||
|
|
||||||
|
@ -351,7 +353,11 @@ class FilesystemModel(ModelPolicy):
|
||||||
# create a Bcachedev (pass in only the names)
|
# create a Bcachedev (pass in only the names)
|
||||||
bcache_dev = Bcachedev(bcache_dev_name, bcache_serial, bcache_model,
|
bcache_dev = Bcachedev(bcache_dev_name, bcache_serial, bcache_model,
|
||||||
bcache_parttype, bcache_size,
|
bcache_parttype, bcache_size,
|
||||||
backing_device, cache_device)
|
backing_device.devpath, cache_device.devpath)
|
||||||
|
|
||||||
|
# mark bcache holders
|
||||||
|
backing_device.set_holder(bcache_dev_name)
|
||||||
|
cache_device.set_holder(bcache_dev_name)
|
||||||
|
|
||||||
# add it to the model's info dict
|
# add it to the model's info dict
|
||||||
bcache_dev_info = {
|
bcache_dev_info = {
|
||||||
|
|
|
@ -591,7 +591,7 @@ class FilesystemView(ViewPolicy):
|
||||||
height=len(col_1))
|
height=len(col_1))
|
||||||
col_2 = BoxAdapter(SimpleList(col_2, is_selectable=False),
|
col_2 = BoxAdapter(SimpleList(col_2, is_selectable=False),
|
||||||
height=len(col_2))
|
height=len(col_2))
|
||||||
return Columns([(15, col_1), col_2], 2)
|
return Columns([(16, col_1), col_2], 2)
|
||||||
|
|
||||||
def _build_menu(self):
|
def _build_menu(self):
|
||||||
log.debug('FileSystemView: building menu')
|
log.debug('FileSystemView: building menu')
|
||||||
|
|
Loading…
Reference in New Issue