Debian Codegraph @

pkg/storaged/lvm2/vdo-pool.jsx

raw
1 /*
2 * Copyright (C) 2023 Red Hat, Inc.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 import cockpit from "cockpit";
7 import React from "react";
8 import client from "../client";
9
10 import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
11 import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";
12 import { StorageOnOff } from "../storage-controls.jsx";
13
14 import { grow_dialog } from "../block/resize.jsx";
15 import { StorageCard, StorageDescription, new_card } from "../pages.jsx";
16 import { fmt_size } from "../utils.js";
17
18 const _ = cockpit.gettext;
19
20 export function make_vdo_pool_card(next, vgroup, lvol) {
21 const vdo_iface = client.vdo_vols[lvol.path];
22 const vdo_pool_vol = client.lvols[vdo_iface.VDOPool];
23
24 if (!vdo_pool_vol)
25 return null;
26
27 return new_card({
28 title: _("LVM2 VDO pool"),
29 next,
30 component: LVM2VDOPoolCard,
31 props: { vgroup, lvol, vdo_iface, vdo_pool_vol },
32 actions: [
33 {
34 title: _("Grow"),
35 action: () => grow_dialog(client, vdo_pool_vol, { }),
36 }
37 ],
38 });
39 }
40
41 const LVM2VDOPoolCard = ({ card, vgroup, lvol, vdo_iface, vdo_pool_vol }) => {
42 function toggle_compression() {
43 const new_state = !vdo_iface.Compression;
44 return vdo_iface.EnableCompression(new_state, {})
45 .then(() => client.wait_for(() => vdo_iface.Compression === new_state));
46 }
47
48 function toggle_deduplication() {
49 const new_state = !vdo_iface.Deduplication;
50 return vdo_iface.EnableDeduplication(new_state, {})
51 .then(() => client.wait_for(() => vdo_iface.Deduplication === new_state));
52 }
53
54 function perc(ratio) {
55 return (ratio * 100).toFixed(0) + "%";
56 }
57
58 const used_pct = perc(vdo_iface.UsedSize / vdo_pool_vol.Size);
59
60 return (
61 <StorageCard card={card}>
62 <CardBody>
63 <DescriptionList className="pf-m-horizontal-on-sm">
64 <StorageDescription title={_("Name")} value={vdo_pool_vol.Name} />
65 <StorageDescription title={_("Size")} value={fmt_size(vdo_pool_vol.Size)} />
66 <StorageDescription title={_("Data used")}>
67 {fmt_size(vdo_iface.UsedSize)} ({used_pct})
68 </StorageDescription>
69 <StorageDescription title={_("Metadata used")} value={perc(lvol.MetadataAllocatedRatio)} />
70 <StorageDescription title={_("Compression")}>
71 <StorageOnOff state={vdo_iface.Compression} aria-label={_("Use compression")}
72 onChange={toggle_compression} />
73 </StorageDescription>
74 <StorageDescription title={_("Deduplication")}>
75 <StorageOnOff state={vdo_iface.Deduplication} aria-label={_("Use deduplication")}
76 onChange={toggle_deduplication} />
77 </StorageDescription>
78 </DescriptionList>
79 </CardBody>
80 </StorageCard>);
81 };