Skip to content

Commit

Permalink
storage: More robust volume group polling
Browse files Browse the repository at this point in the history
Previously the polling was done as part of the React component for the
volume group details. This of course means that no polling happens
when that component is not on the screen.

Do all the polling in the client, regardless of what is displayed.

This improved polling makes it necessary to mock the thin pool
statistics when pixel testing.
  • Loading branch information
mvollmer committed Nov 27, 2024
1 parent fcea42c commit a988918
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
26 changes: 26 additions & 0 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,36 @@ function update_indices() {
}
}

let lvm2_poll_timer = null;

function update_lvm2_polling(for_visibility) {
const need_polling = !cockpit.hidden && !!Object.values(client.vgroups).find(vg => vg.NeedsPolling);

function poll() {
for (const path in client.vgroups) {
const vg = client.vgroups[path];
if (vg.NeedsPolling) {
vg.Poll();
}
}
}

if (need_polling && lvm2_poll_timer == null) {
lvm2_poll_timer = window.setInterval(poll, 2000);
if (for_visibility)
poll();
} else if (!need_polling && lvm2_poll_timer) {
window.clearInterval(lvm2_poll_timer);
lvm2_poll_timer = null;
}
}

client.update = (first_time) => {
if (first_time)
client.ready = true;
if (client.ready) {
update_indices();
update_lvm2_polling(false);
reset_pages();
make_overview_page();
export_mount_point_mapping();
Expand Down Expand Up @@ -1010,6 +1035,7 @@ function init_model(callback) {
client.storaged_client.addEventListener('notify', () => client.update());

update_indices();
cockpit.addEventListener("visibilitychange", () => update_lvm2_polling(true));
btrfs_poll().then(() => {
client.update(true);
callback();
Expand Down
23 changes: 0 additions & 23 deletions pkg/storaged/lvm2/volume-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { Alert } from "@patternfly/react-core/dist/esm/components/Alert/index.js
import { CardHeader, CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { useObject } from "hooks";

import { VolumeIcon } from "../icons/gnome-icons.jsx";
import { StorageButton, StorageLink } from "../storage-controls.jsx";
import {
Expand Down Expand Up @@ -273,23 +271,6 @@ export function make_lvm2_volume_group_page(parent, vgroup) {
make_logical_volume_pages(vgroup_page, vgroup);
}

function vgroup_poller(vgroup) {
let timer = null;

if (vgroup.NeedsPolling) {
timer = window.setInterval(() => { vgroup.Poll() }, 2000);
}

function stop() {
if (timer)
window.clearInterval(timer);
}

return {
stop
};
}

const LVM2LogicalVolumesCard = ({ card, vgroup }) => {
return (
<StorageCard card={card}>
Expand All @@ -305,10 +286,6 @@ const LVM2LogicalVolumesCard = ({ card, vgroup }) => {
const LVM2VolumeGroupCard = ({ card, vgroup }) => {
const has_missing_pvs = vgroup.MissingPhysicalVolumes && vgroup.MissingPhysicalVolumes.length > 0;

useObject(() => vgroup_poller(vgroup),
poller => poller.stop(),
[vgroup]);

function is_partial_linear_lvol(block) {
const lvm2 = client.blocks_lvm2[block.path];
const lvol = lvm2 && client.lvols[lvm2.LogicalVolume];
Expand Down
8 changes: 7 additions & 1 deletion test/verify/check-storage-lvm2
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ class TestStorageLvm2(storagelib.StorageCase):
b.wait_text(self.card_row_col("Thinly provisioned LVM2 logical volumes", 1, 3), mount_point_thin)

# prevent unstable usage numbers from failing the pixel test
b.assert_pixels('body', "pool-page", mock={".usage-text": "1 / 100 MB"},
b.assert_pixels('body', "pool-page",
mock={
".usage-text": "1 / 100 MB",
self.card_desc("Pool for thinly provisioned LVM2 logical volumes", "Data used"): "43%",
self.card_desc("Pool for thinly provisioned LVM2 logical volumes", "Metadata used"): "20%",
},

ignore=[".usage-bar"])

# remove pool
Expand Down

0 comments on commit a988918

Please sign in to comment.