Skip to content

Commit

Permalink
storage: Disable "Format" action for read-only devices
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Mar 18, 2024
1 parent 29e2d73 commit 294db9e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 21 deletions.
36 changes: 36 additions & 0 deletions pkg/storaged/block/actions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of Cockpit.
*
* Copyright (C) 2024 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

import cockpit from "cockpit";
import client from "../client";

import { format_dialog } from "./format-dialog.jsx";

const _ = cockpit.gettext;

export function std_format_action(backing_block, content_block) {
const excuse = backing_block.ReadOnly ? _("Device is read-only") : null;

return {
title: _("Format"),
action: () => format_dialog(client, backing_block.path),
excuse,
danger: true
};
}
5 changes: 2 additions & 3 deletions pkg/storaged/block/unformatted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/

import cockpit from "cockpit";
import client from "../client";

import { StorageCard, new_card } from "../pages.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { std_format_action } from "./actions.jsx";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;
Expand All @@ -33,7 +32,7 @@ export function make_unformatted_data_card(next, backing_block, content_block) {
component: StorageCard,
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});
}
5 changes: 2 additions & 3 deletions pkg/storaged/block/unrecognized-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

import cockpit from "cockpit";
import React from "react";
import client from "../client";

import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { StorageCard, StorageDescription, new_card } from "../pages.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { std_format_action } from "./actions.jsx";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;
Expand All @@ -38,7 +37,7 @@ export function make_unrecognized_data_card(next, backing_block, content_block)
props: { backing_block, content_block },
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/btrfs/device.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc
import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { StorageUsageBar } from "../storage-controls.jsx";
import { std_lock_action } from "../crypto/actions.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { btrfs_device_usage } from "./utils.jsx";

const _ = cockpit.gettext;
Expand Down Expand Up @@ -90,7 +90,7 @@ export function btrfs_device_actions(backing_block, content_block) {
if (backing_block && content_block)
return [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
];
else
return [];
Expand Down
5 changes: 2 additions & 3 deletions pkg/storaged/crypto/locked-encrypted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/

import cockpit from "cockpit";
import client from "../client";

import { StorageCard, new_card } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { unlock } from "./actions.jsx";

const _ = cockpit.gettext;
Expand All @@ -35,7 +34,7 @@ export function make_locked_encrypted_data_card(next, block) {
props: { block },
actions: [
{ title: _("Unlock"), action: () => unlock(block) },
{ title: _("Format"), action: () => format_dialog(client, block.path), danger: true },
std_format_action(block, null),
]
});
}
4 changes: 2 additions & 2 deletions pkg/storaged/filesystem/filesystem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { StorageLink, StorageUsageBar, StorageSize } from "../storage-controls.jsx";
import { StorageCard, StorageDescription, new_card, useIsNarrow } from "../pages.jsx";

import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { is_mounted, MountPoint, mount_point_text, edit_mount_point } from "./utils.jsx";
import { mounting_dialog } from "./mounting-dialog.jsx";
import { check_mismounted_fsys, MismountAlert } from "./mismounting.jsx";
Expand Down Expand Up @@ -101,7 +101,7 @@ export function make_filesystem_card(next, backing_block, content_block, fstab_c
content_block && mounted
? { title: _("Unmount"), action: () => mounting_dialog(client, content_block, "unmount") }
: { title: _("Mount"), action: () => mounting_dialog(client, content_block || backing_block, "mount") },
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/lvm2/physical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { std_lock_action } from "../crypto/actions.jsx";
import { StorageUsageBar } from "../storage-controls.jsx";

Expand All @@ -47,7 +47,7 @@ export function make_lvm2_physical_volume_card(next, backing_block, content_bloc
props: { backing_block, content_block },
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});

Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/mdraid/mdraid-disk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { block_short_name, fmt_size, mdraid_name } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";

Expand All @@ -44,7 +44,7 @@ export function make_mdraid_disk_card(next, backing_block, content_block) {
props: { backing_block, content_block, mdraid },
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});

Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/stratis/blockdev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import { fmt_size } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";

Expand All @@ -45,7 +45,7 @@ export function make_stratis_blockdev_card(next, backing_block, content_block) {
props: { backing_block, content_block, pool, stopped_pool },
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});

Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/swap/swap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc
import { useEvent } from "hooks";

import { StorageCard, StorageDescription, new_card } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { std_format_action } from "../block/actions.jsx";
import {
fmt_size, decode_filename, encode_filename,
parse_options, unparse_options, extract_option,
Expand Down Expand Up @@ -97,7 +97,7 @@ export function make_swap_card(next, backing_block, content_block) {
(block_swap && !block_swap.Active
? { title: _("Start"), action: start }
: null),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
std_format_action(backing_block, content_block),
]
});
}
Expand Down

0 comments on commit 294db9e

Please sign in to comment.