Debian Codegraph @

pkg/storaged/drive/drive.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 { HDDIcon, SSDIcon, MediaDriveIcon } from "../icons/gnome-icons.jsx";
14 import { StorageCard, StorageDescription, new_card, new_page } from "../pages.jsx";
15 import { block_name, drive_name, fmt_size_long, should_ignore } from "../utils.js";
16 import { make_block_page } from "../block/create-pages.jsx";
17 import { partitionable_block_actions } from "../partitions/actions.jsx";
18 import { isSmartOK, SmartCard } from "./smart-details.jsx";
19
20 const _ = cockpit.gettext;
21
22 export function make_drive_page(parent, drive) {
23 let block = client.drives_block[drive.path];
24
25 if (!block) {
26 // A drive without a primary block device might be
27 // a unconfigured multipath device. Try to hobble
28 // along here by arbitrarily picking one of the
29 // multipath devices.
30 block = client.drives_multipath_blocks[drive.path][0];
31 }
32
33 if (!block)
34 return;
35
36 if (should_ignore(client, block.path))
37 return;
38
39 let cls;
40 if (client.drives_iscsi_session[drive.path])
41 cls = "iscsi";
42 else if (drive.MediaRemovable || drive.Media)
43 cls = "media";
44 else
45 cls = (drive.RotationRate === 0) ? "ssd" : "hdd";
46
47 const drive_title = {
48 media: _("Media drive"),
49 ssd: _("Solid State Drive"),
50 hdd: _("Hard Disk Drive"),
51 iscsi: _("iSCSI Drive"),
52 };
53
54 const drive_icon = {
55 media: MediaDriveIcon,
56 ssd: SSDIcon,
57 hdd: HDDIcon,
58 };
59
60 let card = new_card({
61 title: drive_title[cls] || _("Drive"),
62 next: null,
63 page_block: block,
64 page_icon: drive_icon[cls],
65 for_summary: true,
66 id_extra: drive_name(drive),
67 job_path: drive.path,
68 component: DriveCard,
69 props: { drive },
70 actions: block.Size > 0 ? partitionable_block_actions(block) : [],
71 });
72
73 let smart_info, drive_type;
74 if (client.drives_ata[drive.path]) {
75 smart_info = client.drives_ata[drive.path];
76 drive_type = "ata";
77 } else if (client.nvme_controller[drive.path]) {
78 smart_info = client.nvme_controller[drive.path];
79 drive_type = "nvme";
80 }
81
82 if (smart_info !== undefined && (cls === "hdd" || cls === "ssd")) {
83 card = new_card({
84 title: _("Device health (SMART)"),
85 next: card,
86 has_danger: !isSmartOK(drive_type, smart_info),
87 has_warning: (smart_info.SmartNumBadSectors > 0 || smart_info.SmartNumAttributesFailing > 0),
88 component: SmartCard,
89 props: { smart_info, drive_type },
90 });
91 }
92
93 if (block.Size > 0) {
94 make_block_page(parent, block, card, { partitionable: true });
95 } else {
96 new_page(parent, card);
97 }
98 }
99
100 const DriveCard = ({ card, page, drive }) => {
101 const block = client.drives_block[drive.path];
102 const multipath_blocks = client.drives_multipath_blocks[drive.path];
103
104 return (
105 <StorageCard card={card}>
106 <CardBody>
107 <DescriptionList className="pf-m-horizontal-on-sm">
108 <StorageDescription title={_("Vendor")} value={drive.Vendor} />
109 <StorageDescription title={_("Model")} value={drive.Model} />
110 <StorageDescription title={_("Firmware version")} value={drive.Revision} />
111 <StorageDescription title={_("Serial number")} value={drive.Serial} />
112 <StorageDescription title={_("World wide name")} value={drive.WWN} />
113 <StorageDescription title={_("Capacity")}>
114 {drive.Size
115 ? fmt_size_long(drive.Size)
116 : _("No media inserted")
117 }
118 </StorageDescription>
119 <StorageDescription title={_("Device file")}
120 value={block ? block_name(block) : "-"} />
121 { multipath_blocks.length > 0 &&
122 <StorageDescription title={_("Multipathed devices")}
123 value={multipath_blocks.map(block_name).join(" ")} />
124 }
125 </DescriptionList>
126 </CardBody>
127 </StorageCard>
128 );
129 };