Debian Codegraph @

pkg/storaged/multipath.jsx

raw
1 /*
2 * Copyright (C) 2018 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
9 import { StackItem } from "@patternfly/react-core/dist/esm/layouts/Stack/index.js";
10 import { Alert, AlertActionLink } from "@patternfly/react-core/dist/esm/components/Alert/index.js";
11
12 import { get_multipathd_service } from "./utils.js";
13 import { dialog_open } from "./dialog.jsx";
14
15 const _ = cockpit.gettext;
16
17 export class MultipathAlert extends React.Component {
18 constructor() {
19 super();
20 this.multipathd_service = get_multipathd_service();
21 this.on_multipathd_changed = () => { this.setState({}) };
22 }
23
24 componentDidMount() {
25 this.multipathd_service.addEventListener("changed", this.on_multipathd_changed);
26 }
27
28 componentWillUnmount() {
29 this.multipathd_service.removeEventListener("changed", this.on_multipathd_changed);
30 }
31
32 render() {
33 const { client } = this.props;
34
35 // When in doubt, assume everything is alright
36 const multipathd_running = !this.multipathd_service.state || this.multipathd_service.state === "running";
37 const multipath_broken = client.broken_multipath_present === true;
38
39 function activate(event) {
40 if (!event || event.button !== 0)
41 return;
42 cockpit.spawn(["mpathconf", "--enable", "--with_multipathd", "y"],
43 { superuser: "try" })
44 .catch(function (error) {
45 dialog_open({
46 Title: _("Error"),
47 Body: error.toString()
48 });
49 });
50 }
51
52 if (multipath_broken && !multipathd_running)
53 return (
54 <StackItem>
55 <Alert isInline variant='danger'
56 actionClose={<AlertActionLink variant='secondary' onClick={activate}>{_("Start multipath")}</AlertActionLink>}
57 title={_("There are devices with multiple paths on the system, but the multipath service is not running.")}
58 />
59 </StackItem>
60 );
61 return null;
62 }
63 }