Debian Codegraph @

pkg/storaged/lvm2/thin-pool-logical-volume.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
13 import { StorageCard, StorageDescription, ChildrenTable, new_page, new_card } from "../pages.jsx";
14 import { fmt_size, validate_lvm2_name } from "../utils.js";
15 import { dialog_open, TextInput, SizeSlider } from "../dialog.jsx";
16 import { StorageLink } from "../storage-controls.jsx";
17 import { grow_dialog } from "../block/resize.jsx";
18
19 import { next_default_logical_volume_name } from "./utils.jsx";
20 import { lvol_rename, lvol_delete } from "./block-logical-volume.jsx";
21 import { make_lvm2_logical_volume_page } from "./volume-group.jsx";
22
23 const _ = cockpit.gettext;
24
25 export function make_thin_pool_logical_volume_page(parent, vgroup, lvol) {
26 function create_thin() {
27 dialog_open({
28 Title: _("Create thin volume"),
29 Fields: [
30 TextInput("name", _("Name"),
31 {
32 value: next_default_logical_volume_name(client, vgroup, "lvol"),
33 validate: validate_lvm2_name
34 }),
35 SizeSlider("size", _("Size"),
36 {
37 value: lvol.Size,
38 max: lvol.Size * 3,
39 allow_infinite: true,
40 round: vgroup.ExtentSize
41 })
42 ],
43 Action: {
44 Title: _("Create"),
45 action: function (vals) {
46 return vgroup.CreateThinVolume(vals.name, vals.size, lvol.path, { });
47 }
48 }
49 });
50 }
51
52 const pool_card = make_lvm2_thin_pool_card(null, vgroup, lvol);
53
54 const thin_vols_card = new_card({
55 title: _("Thinly provisioned LVM2 logical volumes"),
56 next: pool_card,
57 page_location: ["vg", vgroup.Name, lvol.Name],
58 page_name: lvol.Name,
59 page_size: lvol.Size,
60 component: LVM2ThinPoolLogicalVolumeCard,
61 props: { vgroup, lvol },
62 actions: [
63 {
64 title: _("Create new thinly provisioned logical volume"),
65 action: create_thin,
66 tag: "pool",
67 },
68 ]
69 });
70
71 const p = new_page(parent, thin_vols_card);
72
73 client.lvols_pool_members[lvol.path].forEach(member_lvol => {
74 make_lvm2_logical_volume_page(p, vgroup, member_lvol);
75 });
76 }
77
78 function make_lvm2_thin_pool_card(next, vgroup, lvol) {
79 let grow_excuse = null;
80 if (vgroup.FreeSize == 0)
81 grow_excuse = _("Not enough space");
82
83 const card = new_card({
84 title: _("Pool for thinly provisioned LVM2 logical volumes"),
85 next,
86 component: LVM2ThinPoolCard,
87 props: { vgroup, lvol },
88 actions: [
89 {
90 title: _("Grow"),
91 action: () => grow_dialog(client, lvol, { }),
92 excuse: grow_excuse,
93 },
94 {
95 title: _("Delete"),
96 action: () => lvol_delete(lvol, card),
97 danger: true,
98 },
99 ],
100 });
101 return card;
102 }
103
104 function perc(ratio) {
105 return (ratio * 100).toFixed(0) + "%";
106 }
107
108 export const LVM2ThinPoolLogicalVolumeCard = ({ card, vgroup, lvol }) => {
109 return (
110 <StorageCard card={card}>
111 <ChildrenTable
112 emptyCaption={_("No logical volumes")}
113 aria-label={_("Thinly provisioned LVM2 logical volumes")}
114 page={card.page} />
115 </StorageCard>);
116 };
117
118 export const LVM2ThinPoolCard = ({ card, vgroup, lvol }) => {
119 return (
120 <StorageCard card={card}>
121 <CardBody>
122 <DescriptionList className="pf-m-horizontal-on-sm">
123 <StorageDescription title={_("Name")}
124 value={lvol.Name}
125 action={<StorageLink onClick={() => lvol_rename(lvol)}>
126 {_("edit")}
127 </StorageLink>} />
128 <StorageDescription title={_("Size")} value={fmt_size(lvol.Size)} />
129 <StorageDescription title={_("Data used")} value={perc(lvol.DataAllocatedRatio)} />
130 <StorageDescription title={_("Metadata used")} value={perc(lvol.MetadataAllocatedRatio)} />
131 </DescriptionList>
132 </CardBody>
133 </StorageCard>);
134 };