Skip to content

Commit

Permalink
WIP - treat all partitionable block devices like the Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Oct 26, 2023
1 parent 7080a08 commit b4c5886
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 81 deletions.
20 changes: 10 additions & 10 deletions pkg/storaged/content-views.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -719,16 +719,16 @@ export function format_disk(client, block) {
Title: cockpit.format(_("Create partition table on disk $0"), utils.block_name(block)),
Fields: [
SelectOneRadioVertical("type", _("Partitioning"),
{
value: "gpt",
choices: [
{ value: "dos", title: _("Compatible with all systems and devices (MBR)") },
{
value: "gpt",
title: _("Compatible with modern system and hard disks > 2TB (GPT)")
},
]
}),
{
value: "gpt",
choices: [
{ value: "dos", title: _("Compatible with all systems and devices (MBR)") },
{
value: "gpt",
title: _("Compatible with modern system and hard disks > 2TB (GPT)")
},
]
}),
],
Action: {
Title: _("Create"),
Expand Down
74 changes: 43 additions & 31 deletions pkg/storaged/pages/drive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,46 @@ import { make_block_pages } from "../create-pages.jsx";

const _ = cockpit.gettext;

export function partitionable_block_actions(block, tag) {
const is_formatted = !client.blocks_available[block.path];
const excuse = block.ReadOnly ? _("Device is read-only") : null;

return [
(is_formatted && block.Size > 0
? {
title: _("Erase"),
action: () => erase_disk(client, block),
danger: true,
excuse,
tag,
}
: null),
(!is_formatted && block.Size > 0
? {
title: _("Format as filesystem"),
action: () => format_dialog(client, block.path),
excuse,
tag
}
: null),
(!is_formatted && block.Size > 0
? {
title: _("Create partition table"),
action: () => format_disk(client, block),
excuse,
tag
}
: null)
];
}

export function make_partitionable_block_pages(parent, block) {
const is_formatted = !client.blocks_available[block.path];

if (is_formatted)
make_block_pages(parent, block, null);
}

export function make_drive_page(parent, drive) {
let block = client.drives_block[drive.path];

Expand All @@ -51,8 +91,6 @@ export function make_drive_page(parent, drive) {
if (!block)
return;

const is_formatted = !client.blocks_available[block.path];

const drive_page = new_page({
location: ["drive", block_location(block)],
parent,
Expand All @@ -62,39 +100,13 @@ export function make_drive_page(parent, drive) {
block_name(block),
block.Size > 0 ? fmt_size(block.Size) : null
],
actions: [
(is_formatted && block.Size > 0
? {
title: _("Erase"),
action: () => erase_disk(client, block),
danger: true,
excuse: block.ReadOnly ? _("Device is read-only") : null,
tag: "content",
}
: null),
(!is_formatted && block.Size > 0
? {
title: _("Format as filesystem"),
action: () => format_dialog(client, block.path),
excuse: block.ReadOnly ? _("Device is read-only") : null,
tag: "content"
}
: null),
(!is_formatted && block.Size > 0
? {
title: _("Create partition table"),
action: () => format_disk(client, block),
excuse: block.ReadOnly ? _("Device is read-only") : null,
tag: "content"
}
: null)
],
actions: partitionable_block_actions(block, "content"),
component: DrivePage,
props: { drive }
});

if (is_formatted && block.Size > 0)
make_block_pages(drive_page, block, null);
if (block.Size > 0)
make_partitionable_block_pages(drive_page, block);
}

const DrivePage = ({ page, drive }) => {
Expand Down
51 changes: 22 additions & 29 deletions pkg/storaged/pages/mdraid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ import {
init_active_usage_processes
} from "../dialog.jsx";

import { make_block_pages } from "../create-pages.jsx";

import { format_disk } from "../content-views.jsx"; // XXX
import { partitionable_block_actions, make_partitionable_block_pages } from "./drive.jsx";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -207,33 +205,27 @@ export function make_mdraid_page(parent, mdraid) {
],
component: MDRaidPage,
props: { mdraid, block, running },
actions: [
(mdraid.Level != "raid0" &&
{
title: _("Add disk"),
action: () => add_disk(mdraid),
excuse: !running && _("The RAID device must be running in order to add spare disks."),
tag: "disks",
}),
(block &&
{
title: _("Create partition table"),
action: () => format_disk(client, block),
excuse: block.ReadOnly ? _("Device is read-only") : null,
tag: "content",
}),
start_stop_action(mdraid),
{
title: _("Delete"),
action: () => mdraid_delete(mdraid, block),
danger: true,
tag: "device",
},
],
actions: (block ? partitionable_block_actions(block, "content") : [])
.concat([
(mdraid.Level != "raid0" &&
{
title: _("Add disk"),
action: () => add_disk(mdraid),
excuse: !running && _("The RAID device must be running in order to add spare disks."),
tag: "disks",
}),
start_stop_action(mdraid),
{
title: _("Delete"),
action: () => mdraid_delete(mdraid, block),
danger: true,
tag: "device",
},
]),
});

if (block)
make_block_pages(p, block);
make_partitionable_block_pages(p, block);
}

const MDRaidPage = ({ page, mdraid, block, running }) => {
Expand Down Expand Up @@ -314,8 +306,9 @@ const MDRaidPage = ({ page, mdraid, block, running }) => {
{ block &&
<StackItem>
<PageChildrenCard title={client.blocks_ptable[block.path] ? _("Partitions") : _("Content")}
actions={<ActionButtons page={page} tag="content" />}
page={page} />
actions={<ActionButtons page={page} tag="content" />}
emptyCaption={_("Device is not formatted")}
page={page} />
</StackItem>
}
</Stack>
Expand Down
15 changes: 4 additions & 11 deletions pkg/storaged/pages/other.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { PageChildrenCard, ActionButtons, new_page, page_type, block_location } from "../pages.jsx";
import { block_name, fmt_size } from "../utils.js";
import { format_disk } from "../content-views.jsx"; // XXX

import { make_block_pages } from "../create-pages.jsx";
import { partitionable_block_actions, make_partitionable_block_pages } from "./drive.jsx";

const _ = cockpit.gettext;

Expand All @@ -45,18 +43,12 @@ export function make_other_page(parent, block) {
block_name(block),
fmt_size(block.Size)
],
actions: [
{
title: _("Create partition table"),
action: () => format_disk(client, block),
excuse: block.ReadOnly ? _("Device is read-only") : null,
},
],
actions: partitionable_block_actions(block),
component: OtherPage,
props: { block }
});

make_block_pages(p, block, null);
make_partitionable_block_pages(p, block);
}

const OtherPage = ({ page, block }) => {
Expand All @@ -76,6 +68,7 @@ const OtherPage = ({ page, block }) => {
<StackItem>
<PageChildrenCard title={client.blocks_ptable[block.path] ? _("Partitions") : _("Content")}
actions={<ActionButtons page={page} />}
emptyCaption={_("Block device is not formatted")}
page={page} />
</StackItem>
</Stack>
Expand Down

0 comments on commit b4c5886

Please sign in to comment.