Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: LVM2 RAID support #17226

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 106 additions & 1 deletion pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,24 @@ function update_indices() {
client.vgnames_vgroup[vgroup.Name] = vgroup;
}

const vgroups_with_dm_pvs = { };

client.vgroups_pvols = { };
for (path in client.vgroups) {
client.vgroups_pvols[path] = [];
}
for (path in client.blocks_pvol) {
pvol = client.blocks_pvol[path];
if (client.vgroups_pvols[pvol.VolumeGroup] !== undefined)
if (client.vgroups_pvols[pvol.VolumeGroup] !== undefined) {
client.vgroups_pvols[pvol.VolumeGroup].push(pvol);
{
// HACK - this is needed below to deal with a UDisks2 bug.
// https://github.com/storaged-project/udisks/pull/1206
const block = client.blocks[path];
if (block && utils.decode_filename(block.Device).indexOf("/dev/dm-") == 0)
vgroups_with_dm_pvs[pvol.VolumeGroup] = true;
}
}
}
function cmp_pvols(a, b) {
return utils.block_cmp(client.blocks[a.path], client.blocks[b.path]);
Expand Down Expand Up @@ -331,6 +341,101 @@ function update_indices() {
client.lvols_pool_members[path].sort(function (a, b) { return a.Name.localeCompare(b.Name) });
}

function summarize_stripe(lv_size, segments) {
const pvs = { };
let total_size = 0;
for (const [, size, pv] of segments) {
if (!pvs[pv])
pvs[pv] = 0;
pvs[pv] += size;
total_size += size;
}
if (total_size < lv_size)
pvs["/"] = lv_size - total_size;
return pvs;
}

client.lvols_stripe_summary = { };
client.lvols_status = { };
for (path in client.lvols) {
const struct = client.lvols[path].Structure;
const lvol = client.lvols[path];

// HACK - UDisks2 can't find the PVs of a segment when they
// are on a device mapper device.
//
// https://github.com/storaged-project/udisks/pull/1206

if (vgroups_with_dm_pvs[lvol.VolumeGroup])
continue;

let summary;
let status = "";
if (lvol.Layout != "thin" && struct && struct.segments) {
summary = summarize_stripe(struct.size.v, struct.segments.v);
if (summary["/"])
status = "partial";
} else if (struct && struct.data && struct.metadata &&
(struct.data.v.length == struct.metadata.v.length || struct.metadata.v.length == 0)) {
summary = [];
const n_total = struct.data.v.length;
let n_missing = 0;
for (let i = 0; i < n_total; i++) {
const data_lv = struct.data.v[i];
const metadata_lv = struct.metadata.v[i] || { size: { v: 0 }, segments: { v: [] } };

if (!data_lv.segments || (metadata_lv && !metadata_lv.segments)) {
summary = undefined;
break;
}

const s = summarize_stripe(data_lv.size.v + metadata_lv.size.v,
data_lv.segments.v.concat(metadata_lv.segments.v));
if (s["/"])
n_missing += 1;

summary.push(s);
}
if (n_missing > 0) {
status = "partial";
if (lvol.Layout == "raid1") {
if (n_total - n_missing >= 1)
status = "degraded";
}
if (lvol.Layout == "raid10") {
// This is correct for two-way mirroring, which is
// the only setup supported by lvm2.
if (n_missing > n_total / 2) {
// More than half of the PVs are gone -> at
// least one mirror has definitely lost both
// halves.
status = "partial";
} else if (n_missing > 1) {
// Two or more PVs are lost -> one mirror
// might have lost both halves
status = "degraded-maybe-partial";
} else {
// Only one PV is missing -> no mirror has
// lost both halves.
status = "degraded";
}
}
if (lvol.Layout == "raid4" || lvol.Layout == "raid5") {
if (n_missing <= 1)
status = "degraded";
}
if (lvol.Layout == "raid6") {
if (n_missing <= 2)
status = "degraded";
}
}
}
if (summary) {
client.lvols_stripe_summary[path] = summary;
client.lvols_status[path] = status;
}
}

client.stratis_poolnames_pool = { };
for (path in client.stratis_pools) {
pool = client.stratis_pools[path];
Expand Down
Loading