Debian Codegraph @

pkg/storaged/lvm2/utils.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
8 import { get_block_link_parts } from "../utils.js";
9
10 export function check_partial_lvols(client, path, enter_warning) {
11 if (client.lvols_status[path] && client.lvols_status[path] != "") {
12 enter_warning(path, {
13 warning: "partial-lvol",
14 danger: client.lvols_status[path] != "degraded"
15 });
16 }
17 }
18
19 export function pvs_to_spaces(client, pvs) {
20 return pvs.map(pvol => {
21 const block = client.blocks[pvol.path];
22 const parts = get_block_link_parts(client, pvol.path);
23 const text = cockpit.format(parts.format, parts.link);
24 return { type: 'block', block, size: pvol.FreeSize, desc: text, pvol };
25 });
26 }
27
28 export function next_default_logical_volume_name(client, vgroup, prefix) {
29 function find_lvol(name) {
30 const lvols = client.vgroups_lvols[vgroup.path];
31 for (let i = 0; i < lvols.length; i++) {
32 if (lvols[i].Name == name)
33 return lvols[i];
34 }
35 return null;
36 }
37
38 let name;
39 for (let i = 0; i < 1000; i++) {
40 name = prefix + i.toFixed();
41 if (!find_lvol(name))
42 break;
43 }
44
45 return name;
46 }