Skip to content

Commit

Permalink
storage: Move "Lock" and "Unlock" actions to "Encryption" card
Browse files Browse the repository at this point in the history
That's where they belong. Filesystems are still automatically locked
and unlocked when mounting and unmounting them.
  • Loading branch information
mvollmer committed Apr 5, 2024
1 parent c2ab4ae commit 7985233
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 46 deletions.
8 changes: 5 additions & 3 deletions pkg/storaged/block/create-pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,26 @@ export function make_block_page(parent, block, card) {
content_block = block;
}

if (is_crypto)
card = make_encryption_card(card, block);

if (!content_block) {
if (!is_crypto) {
// can not happen unless there is a bug in the code above.
console.error("Assertion failure: is_crypto == false");
}
if (fstab_config.length > 0 && !is_btrfs) {
card = make_encryption_card(card, block, true);
card = make_filesystem_card(card, block, null, fstab_config);
} else {
card = make_encryption_card(card, block, false);
card = make_locked_encrypted_data_card(card, block);
}
} else {
const is_filesystem = content_block.IdUsage == 'filesystem';
const block_pvol = client.blocks_pvol[content_block.path];
const block_swap = client.blocks_swap[content_block.path];

if (is_crypto)
card = make_encryption_card(card, block, is_filesystem);

if (block_btrfs_blockdev) {
if (single_device_volume)
card = make_btrfs_filesystem_card(card, block, content_block);
Expand Down
4 changes: 0 additions & 4 deletions pkg/storaged/block/unformatted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import cockpit from "cockpit";

import { StorageCard, new_card } from "../pages.jsx";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -29,8 +28,5 @@ export function make_unformatted_data_card(next, backing_block, content_block) {
title: _("Unformatted data"),
next,
component: StorageCard,
actions: [
std_lock_action(backing_block, content_block),
]
});
}
4 changes: 0 additions & 4 deletions pkg/storaged/block/unrecognized-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 } from "../pages.jsx";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -34,9 +33,6 @@ export function make_unrecognized_data_card(next, backing_block, content_block)
next,
component: UnrecognizedDataCard,
props: { backing_block, content_block },
actions: [
std_lock_action(backing_block, content_block),
]
});
}

Expand Down
11 changes: 0 additions & 11 deletions pkg/storaged/btrfs/device.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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 { btrfs_device_usage } from "./utils.jsx";

const _ = cockpit.gettext;
Expand All @@ -43,7 +42,6 @@ export function make_btrfs_device_card(next, backing_block, content_block, block
next,
component: BtrfsDeviceCard,
props: { backing_block, content_block },
actions: btrfs_device_actions(backing_block, content_block),
});

register_crossref({
Expand Down Expand Up @@ -84,12 +82,3 @@ export const BtrfsDeviceCard = ({ card, backing_block, content_block }) => {
</CardBody>
</StorageCard>);
};

export function btrfs_device_actions(backing_block, content_block) {
if (backing_block && content_block)
return [
std_lock_action(backing_block, content_block),
];
else
return [];
}
2 changes: 0 additions & 2 deletions pkg/storaged/btrfs/filesystem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from "../pages.jsx";
import { StorageUsageBar, StorageLink } from "../storage-controls.jsx";
import { btrfs_device_usage, btrfs_is_volume_mounted } from "./utils.jsx";
import { btrfs_device_actions } from "./device.jsx";
import { rename_dialog } from "./volume.jsx";

const _ = cockpit.gettext;
Expand All @@ -43,7 +42,6 @@ export function make_btrfs_filesystem_card(next, backing_block, content_block) {
return new_card({
title: _("btrfs filesystem"),
next,
actions: btrfs_device_actions(backing_block, content_block),
component: BtrfsFilesystemCard,
props: { backing_block, content_block },
});
Expand Down
2 changes: 0 additions & 2 deletions pkg/storaged/btrfs/volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { fmt_size_long, validate_fsys_label, should_ignore } from "../utils.js";
import { btrfs_usage, btrfs_is_volume_mounted } from "./utils.jsx";
import { dialog_open, TextInput } from "../dialog.jsx";
import { make_btrfs_subvolume_pages } from "./subvolume.jsx";
import { btrfs_device_actions } from "./device.jsx";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -145,7 +144,6 @@ export function make_btrfs_subvolumes_card(next, block, backing_block) {
return new_card({
title: _("btrfs subvolumes"),
next,
actions: btrfs_device_actions(block, backing_block),
component: BtrfsSubVolumesCard,
});
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/storaged/crypto/encryption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,32 @@ import luksmeta_monitor_hack_py from "./luksmeta-monitor-hack.py";
import { is_mounted } from "../filesystem/utils.jsx";
import { StorageLink } from "../storage-controls.jsx";
import { CryptoKeyslots } from "./keyslots.jsx";
import { lock, unlock } from "./actions.jsx";

const _ = cockpit.gettext;

export function make_encryption_card(next, block) {
export function make_encryption_card(next, block, is_filesystem) {
const content_block = client.blocks_cleartext[block.path];

return new_card({
title: _("Encryption"),
next,
type_extra: _("encrypted"),
component: EncryptionCard,
props: { block },
actions: [
(content_block && !is_filesystem) &&
{
title: _("Lock"),
action: () => lock(block),
},
!content_block &&
{
title: _("Unlock"),
primary: !is_filesystem,
action: () => unlock(block),
},
]
});
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/storaged/crypto/locked-encrypted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import cockpit from "cockpit";

import { StorageCard, new_card } from "../pages.jsx";
import { unlock } from "./actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -31,8 +30,5 @@ export function make_locked_encrypted_data_card(next, block) {
page_block: block,
component: StorageCard,
props: { block },
actions: [
{ title: _("Unlock"), action: () => unlock(block) },
]
});
}
4 changes: 0 additions & 4 deletions pkg/storaged/lvm2/physical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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 { std_lock_action } from "../crypto/actions.jsx";
import { StorageUsageBar } from "../storage-controls.jsx";

const _ = cockpit.gettext;
Expand All @@ -44,9 +43,6 @@ export function make_lvm2_physical_volume_card(next, backing_block, content_bloc
: backing_block.Size),
component: LVM2PhysicalVolumeCard,
props: { backing_block, content_block },
actions: [
std_lock_action(backing_block, content_block),
]
});

function pvol_remove() {
Expand Down
6 changes: 1 addition & 5 deletions pkg/storaged/mdraid/mdraid-disk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc

import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { block_short_name, fmt_size, mdraid_name } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -40,10 +39,7 @@ export function make_mdraid_disk_card(next, backing_block, content_block) {
next,
location: mdraid_block ? block_short_name(mdraid_block) : (mdraid ? mdraid_name(mdraid) : null),
component: MDRaidDiskCard,
props: { backing_block, content_block, mdraid },
actions: [
std_lock_action(backing_block, content_block),
]
props: { backing_block, content_block, mdraid }
});

if (mdraid) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/storaged/stratis/blockdev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc

import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx";
import { fmt_size } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -42,9 +41,6 @@ export function make_stratis_blockdev_card(next, backing_block, content_block) {
next,
component: StratisBlockdevCard,
props: { backing_block, content_block, pool, stopped_pool },
actions: [
std_lock_action(backing_block, content_block),
]
});

if (pool || stopped_pool) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/storaged/swap/swap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
fmt_size, decode_filename, encode_filename,
parse_options, unparse_options, extract_option,
} from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -89,7 +88,6 @@ export function make_swap_card(next, backing_block, content_block) {
component: SwapCard,
props: { block: content_block, block_swap },
actions: [
std_lock_action(backing_block, content_block),
(block_swap && block_swap.Active
? { title: _("Stop"), action: stop }
: null),
Expand Down

0 comments on commit 7985233

Please sign in to comment.