-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: Robustify btrfs polling #19853
Merged
mvollmer
merged 1 commit into
cockpit-project:main
from
mvollmer:storage-robustify-btrfs-polling
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,6 @@ export async function btrfs_poll() { | |
}).map(block_fsys => block_fsys.MountPoints).reduce((accum, current) => accum.concat(current)); | ||
const mp = MountPoints[0]; | ||
if (mp) { | ||
let output; | ||
const mount_point = utils.decode_filename(mp); | ||
try { | ||
// HACK: UDisks GetSubvolumes method uses `subvolume list -p` which | ||
|
@@ -258,50 +257,47 @@ export async function btrfs_poll() { | |
// ID 256 gen 7 parent 5 top level 5 path <FS_TREE>/one | ||
// ID 257 gen 7 parent 256 top level 256 path one/two | ||
// ID 258 gen 7 parent 257 top level 257 path <FS_TREE>/one/two/three/four | ||
output = await cockpit.spawn(["btrfs", "subvolume", "list", "-ap", mount_point], { superuser: true, err: "message" }); | ||
const output = await cockpit.spawn(["btrfs", "subvolume", "list", "-ap", mount_point], { superuser: true, err: "message" }); | ||
const subvols = [{ pathname: "/", id: 5 }]; | ||
for (const line of output.split("\n")) { | ||
const m = line.match(/ID (\d+).*parent (\d+).*path (<FS_TREE>\/)?(.*)/); | ||
if (m) | ||
subvols.push({ pathname: m[4], id: Number(m[1]) }); | ||
} | ||
uuids_subvols[uuid] = subvols; | ||
} catch (err) { | ||
console.error(`unable to obtain subvolumes for mount point ${mount_point}`, err); | ||
return; | ||
} | ||
const subvols = [{ pathname: "/", id: 5 }]; | ||
for (const line of output.split("\n")) { | ||
const m = line.match(/ID (\d+).*parent (\d+).*path (<FS_TREE>\/)?(.*)/); | ||
if (m) | ||
subvols.push({ pathname: m[4], id: Number(m[1]) }); | ||
console.warn(`unable to obtain subvolumes for mount point ${mount_point}`, err); | ||
} | ||
uuids_subvols[uuid] = subvols; | ||
|
||
// HACK: Obtain the default subvolume, required for mounts in which do not specify a subvol and subvolid. | ||
// In the future can be obtained via UDisks, it requires the btrfs partition to be mounted somewhere. | ||
// https://github.com/storaged-project/udisks/commit/b6966b7076cd837f9d307eef64beedf01bc863ae | ||
try { | ||
output = await cockpit.spawn(["btrfs", "subvolume", "get-default", mount_point], { superuser: true, err: "message" }); | ||
const output = await cockpit.spawn(["btrfs", "subvolume", "get-default", mount_point], { superuser: true, err: "message" }); | ||
const id_match = output.match(/ID (\d+).*/); | ||
if (id_match) | ||
btrfs_default_subvol[uuid] = Number(id_match[1]); | ||
} catch (err) { | ||
console.error(`unable to obtain default subvolume for mount point ${mount_point}`, err); | ||
console.warn(`unable to obtain default subvolume for mount point ${mount_point}`, err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
} | ||
|
||
// HACK: UDisks should expose a better btrfs API with btrfs device information | ||
// https://github.com/storaged-project/udisks/issues/1232 | ||
// TODO: optimise into just parsing one `btrfs filesystem show`? | ||
const usages = {}; | ||
let usage_output; | ||
try { | ||
usage_output = await cockpit.spawn(["btrfs", "filesystem", "show", "--raw", uuid], { superuser: true, err: "message" }); | ||
} catch (err) { | ||
console.error(`btrfs filesystem show ${uuid}`, err); | ||
return; | ||
} | ||
for (const line of usage_output.split("\n")) { | ||
const match = usage_regex.exec(line); | ||
if (match) { | ||
const { used, device } = match.groups; | ||
usages[device] = used; | ||
const usage_output = await cockpit.spawn(["btrfs", "filesystem", "show", "--raw", uuid], { superuser: true, err: "message" }); | ||
const usages = {}; | ||
for (const line of usage_output.split("\n")) { | ||
const match = usage_regex.exec(line); | ||
if (match) { | ||
const { used, device } = match.groups; | ||
usages[device] = used; | ||
} | ||
} | ||
uuids_usage[uuid] = usages; | ||
} catch (err) { | ||
console.warn(`btrfs filesystem show ${uuid}`, err); | ||
Comment on lines
+298
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 2 added lines are not executed by any test. Details |
||
} | ||
uuids_usage[uuid] = usages; | ||
} else { | ||
uuids_subvols[uuid] = null; | ||
uuids_usage[uuid] = null; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details