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.
  • Loading branch information
mvollmer committed Nov 26, 2024
1 parent 52fc017 commit eba12e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
23 changes: 23 additions & 0 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,34 @@ function update_indices() {
}
}

let lvm2_poll_timer = null;

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

function poll() {
for (let 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);
} 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();
reset_pages();
make_overview_page();
export_mount_point_mapping();
Expand Down
21 changes: 0 additions & 21 deletions pkg/storaged/lvm2/volume-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,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 +288,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

0 comments on commit eba12e8

Please sign in to comment.