Skip to content

Commit

Permalink
initial commit of add_pool - disk role filter rockstor#1494
Browse files Browse the repository at this point in the history
By examining the role of a disk we can rule it out as
a prospective pool member, or include it in the case of
an openLUKS device.
  • Loading branch information
phillxnet committed Nov 14, 2016
1 parent bdbafbb commit 8cb7563
Showing 1 changed file with 38 additions and 1 deletion.
Expand Up @@ -57,7 +57,10 @@ AddPoolView = Backbone.View.extend({
$(this.el).empty();
var _this = this;
this.filteredCollection = _.reject(this.collection.models, function (disk) {
return _.isNull(disk.get('pool')) && !disk.get('parted') && !disk.get('offline') && _.isNull(disk.get('btrfs_uuid')) && isSerialUsable(disk.get('serial'));
return _.isNull(disk.get('pool')) && !disk.get('parted') &&
!disk.get('offline') && _.isNull(disk.get('btrfs_uuid')) &&
isSerialUsable(disk.get('serial')) &&
isRoleUsable(disk.get('role'));
});

// N.B. the isSerialUsable() code below is now duplicated in the
Expand All @@ -80,6 +83,40 @@ AddPoolView = Backbone.View.extend({
return true;
}

// Using the disk.role system we can filter drives on their usability.
// Roles for inclusion: openLUKS containers
// Roles to dismiss: LUKS containers, mdraid members, the 'root' role,
// and partitioned.
// Defaults to reject (return false)
function isRoleUsable(role) {
// check if our role is null = db default
// A drive with no role shouldn't present a problem for use.
if (role == null) {
console.log("add_pool ACCEPTING ROLE OF null")
return true;
}
// try json conversion and return false if it fails
// @todo not sure if this is redundant?
try {
var roleAsJson = JSON.parse(role);
} catch (e) {
// as we can't read this drives role we play save and exclude
// it's isRoleUsable status by false
return false;
}
// We have a json object, look for acceptable roles in the keys
//
// Accept use of 'openLUKS' device
if (roleAsJson.hasOwnProperty('openLUKS')) {
console.log("add_pool ACCEPTING ROLE OF openLUKS json = " + role);
return true;
}
// In all other cases return false, ie:
// reject roles of for example root, mdraid, LUKS, partitioned etc
console.log("add_pool REJECTING ROLE with json = " + role);
return false;
}

this.collection.remove(this.filteredCollection);
$(_this.el).append(_this.template({
disks: this.collection.toJSON(),
Expand Down

0 comments on commit 8cb7563

Please sign in to comment.