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