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:
Ryan Harper 2015-11-13 13:42:36 -06:00
parent 0385e754ab
commit 75a3171d57
3 changed files with 22 additions and 10 deletions

View File

@ -130,7 +130,7 @@ class Blockdev():
self._mountactions = {}
self.bcache = []
self.lvm = []
self.holder = {}
self.holders = []
self.baseaction = DiskAction(os.path.basename(self.disk.devpath),
self.disk.model, self.disk.serial,
self.disk.parttype)
@ -143,7 +143,7 @@ class Blockdev():
self._mountactions == other._mountactions and
self.bcache == other.bcache and
self.lvm == other.lvm and
self.holder == other.holder and
self.holders == other.holders and
self.baseaction == other.baseaction)
else:
return False
@ -164,7 +164,7 @@ class Blockdev():
self._mountactions = {}
self.bcache = []
self.lvm = []
self.holder = {}
self.holders = []
@property
def id(self):
@ -231,8 +231,9 @@ class Blockdev():
@property
def available(self):
''' return True if has free space or partitions not
assigned '''
if not self.is_mounted() and self.percent_free > 0:
assigned, and no holders '''
if not self.is_mounted() and self.percent_free > 0 \
and len(self.holders) == 0:
return True
return False
@ -350,8 +351,13 @@ class Blockdev():
[partnum] = re.findall('\d+$', devpath)
return self.disk.partitions[int(partnum)]
def set_holder(self, devpath, holdtype):
self.holder[holdtype] = devpath
def set_holder(self, 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):
with open('/proc/mounts') as pm:
@ -438,7 +444,7 @@ class Bcachedev(Blockdev):
def sort_actions(actions):
def type_index(t):
order = ['disk', 'partition', 'raid', 'format', 'mount']
order = ['disk', 'partition', 'raid', 'bcache', 'format', 'mount']
return order.index(t.get('type'))
def path_count(p):

View File

@ -293,10 +293,12 @@ class FilesystemModel(ModelPolicy):
# create a Raiddev (pass in only the names)
raid_parts = []
for dev in raid_devices:
dev.set_holder(raid_dev_name)
for num, action in dev.partitions.items():
raid_parts.append(action.action_id)
spare_parts = []
for dev in spare_devices:
dev.set_holder(raid_dev_name)
for num, action in dev.partitions.items():
spare_parts.append(action.action_id)
@ -351,7 +353,11 @@ class FilesystemModel(ModelPolicy):
# create a Bcachedev (pass in only the names)
bcache_dev = Bcachedev(bcache_dev_name, bcache_serial, bcache_model,
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
bcache_dev_info = {

View File

@ -591,7 +591,7 @@ class FilesystemView(ViewPolicy):
height=len(col_1))
col_2 = BoxAdapter(SimpleList(col_2, is_selectable=False),
height=len(col_2))
return Columns([(15, col_1), col_2], 2)
return Columns([(16, col_1), col_2], 2)
def _build_menu(self):
log.debug('FileSystemView: building menu')