Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: Action redesign #19882

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions pkg/storaged/block/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,74 @@
import cockpit from "cockpit";
import client from "../client";

import { initialize_disk_dialog } from "../partitions/initialize-disk-dialog.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { format_swap_dialog } from "../swap/format-dialog.jsx";
import { erase_dialog } from "./erase-dialog.jsx";

const _ = cockpit.gettext;

export function std_format_action(backing_block, content_block) {
const excuse = backing_block.ReadOnly ? _("Device is read-only") : null;
export function block_actions(block, kind) {
if (!block || block.Size === 0)
return [];

return {
title: _("Format"),
action: () => format_dialog(client, backing_block.path),
excuse,
danger: true
};
const excuse = block.ReadOnly ? _("Device is read-only") : null;
const actions = [];

if (client.blocks_available[block.path]) {
if (kind == "part") {
actions.push({
title: _("Initialize for partitions"),
action: () => initialize_disk_dialog(block),
primary: true,
excuse,
});
}

if (kind == "crypto") {
actions.push({
title: _("Format as encrypted filesystem"),
action: () => format_dialog(block, { is_encrypted: true }),
excuse,
});
actions.push({
title: _("Format as encrypted swap"),
action: () => format_swap_dialog(block),
excuse,
});
} else {
actions.push({
title: _("Format as filesystem"),
action: () => format_dialog(block),
excuse,
});
actions.push({
title: _("Format as swap"),
action: () => format_swap_dialog(block),
excuse,
});
actions.push({
title: _("Format with encryption only"),
action: () => format_dialog(block, { add_encryption: true }),
excuse,
});
}
} else {
actions.push({
title: kind == "crypto" ? _("Erase encrypted device") : _("Erase"),
action: () => erase_dialog(block),
danger: true,
excuse,
});
}

return actions;
}

export function partitionable_block_actions(block) {
return block_actions(block, "part");
}

export function encrypted_block_actions(block) {
return block_actions(block, "crypto");
}
11 changes: 6 additions & 5 deletions pkg/storaged/block/create-pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ 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_locked_encrypted_data_card(card, block);
card = make_encryption_card(card, block, false);
}
} 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 && !(block_btrfs_blockdev && !single_device_volume));

if (block_btrfs_blockdev) {
if (single_device_volume)
card = make_btrfs_filesystem_card(card, block, content_block);
Expand All @@ -114,7 +115,7 @@ export function make_block_page(parent, block, card) {
(content_block.IdUsage == "other" && content_block.IdType == "swap")) {
card = make_swap_card(card, block, content_block);
} else if (client.blocks_available[content_block.path]) {
card = make_unformatted_data_card(card, block, content_block);
// No card for unformatted data
} else {
card = make_unrecognized_data_card(card, block, content_block);
}
Expand Down
70 changes: 70 additions & 0 deletions pkg/storaged/block/erase-dialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.js";

import {
block_name, get_active_usage, teardown_active_usage,
} from "../utils.js";

import {
dialog_open,
CheckBoxes,
BlockingMessage, TeardownMessage,
init_teardown_usage,
} from "../dialog.jsx";
Comment on lines +27 to +32

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import CheckBoxes.

import { job_progress_wrapper } from "../jobs-panel.jsx";

const _ = cockpit.gettext;

export function erase_dialog(block) {
const usage = get_active_usage(client, block.path, _("erase"), _("delete"));

if (usage.Blocking) {
dialog_open({
Title: cockpit.format(_("$0 is in use"), block_name(block)),
Body: BlockingMessage(usage)
});
return;
}

dialog_open({
Title: cockpit.format(_("Erase $0"), block_name(block)),
Teardown: TeardownMessage(usage),
Action: {
Title: _("Erase"),
Danger: _("This will erase all data on the storage device."),
wrapper: job_progress_wrapper(client, block.path),
disable_on_error: usage.Teardown,
action: async function (vals) {
const options = {
'tear-down': { t: 'b', v: true }
};

await teardown_active_usage(client, usage);
await block.Format("empty", options);
}
},
Inits: [
init_teardown_usage(client, usage),
]
});
}
Loading
Loading