blockDevices() added groups for raid (linux)

This commit is contained in:
Sebastian Hildebrandt 2022-11-18 17:44:59 +01:00
parent c544e80c20
commit b1b017a95f

View File

@ -369,16 +369,18 @@ function decodeMdabmData(lines) {
function raidMatchLunix(data) {
// for all block devices of type "raid%"
let result = data;
try {
data.forEach(element => {
if (element.type.startsWith('raid')) {
const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n');
const mdData = decodeMdabmData(lines);
if (mdData && mdData.members && mdData.members.length && mdData.raid === element.type) {
data.forEach(blockdevice => {
if (blockDevices.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) {
result = result.map(blockdevice => {
if (blockdevice.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) {
blockdevice.group = element.name;
}
return blockdevice;
});
}
}
@ -386,6 +388,7 @@ function raidMatchLunix(data) {
} catch (e) {
util.noop();
}
return result;
}
function blkStdoutToObject(stdout) {
@ -420,7 +423,7 @@ function blockDevices(callback) {
if (!error) {
let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines);
raidMatchLunix(data);
data = raidMatchLunix(data);
if (callback) {
callback(data);
}
@ -430,7 +433,7 @@ function blockDevices(callback) {
if (!error) {
let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines);
raidMatchLunix(data);
data = raidMatchLunix(data);
}
if (callback) {
callback(data);