From b4c5886cdf41373815d3aae674c3096dab0bed96 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Thu, 26 Oct 2023 15:07:35 +0300 Subject: [PATCH] WIP - treat all partitionable block devices like the Drive --- pkg/storaged/content-views.jsx | 20 ++++----- pkg/storaged/pages/drive.jsx | 74 ++++++++++++++++++++-------------- pkg/storaged/pages/mdraid.jsx | 51 ++++++++++------------- pkg/storaged/pages/other.jsx | 15 ++----- 4 files changed, 79 insertions(+), 81 deletions(-) diff --git a/pkg/storaged/content-views.jsx b/pkg/storaged/content-views.jsx index 5b4206291cee..98d2074c5afb 100644 --- a/pkg/storaged/content-views.jsx +++ b/pkg/storaged/content-views.jsx @@ -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"), diff --git a/pkg/storaged/pages/drive.jsx b/pkg/storaged/pages/drive.jsx index 85b747ceb839..54f535e6cd82 100644 --- a/pkg/storaged/pages/drive.jsx +++ b/pkg/storaged/pages/drive.jsx @@ -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]; @@ -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, @@ -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 }) => { diff --git a/pkg/storaged/pages/mdraid.jsx b/pkg/storaged/pages/mdraid.jsx index 4307340f3341..e786645d4ab5 100644 --- a/pkg/storaged/pages/mdraid.jsx +++ b/pkg/storaged/pages/mdraid.jsx @@ -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; @@ -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 }) => { @@ -314,8 +306,9 @@ const MDRaidPage = ({ page, mdraid, block, running }) => { { block && } - page={page} /> + actions={} + emptyCaption={_("Device is not formatted")} + page={page} /> } diff --git a/pkg/storaged/pages/other.jsx b/pkg/storaged/pages/other.jsx index 390c37345538..26d7c608b38d 100644 --- a/pkg/storaged/pages/other.jsx +++ b/pkg/storaged/pages/other.jsx @@ -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; @@ -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 }) => { @@ -76,6 +68,7 @@ const OtherPage = ({ page, block }) => { } + emptyCaption={_("Block device is not formatted")} page={page} />