Skip to content

Commit

Permalink
WIP - move all code around
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Nov 14, 2023
1 parent 29d86b1 commit 6921848
Show file tree
Hide file tree
Showing 85 changed files with 1,899 additions and 7,275 deletions.
58 changes: 0 additions & 58 deletions pkg/storaged/block-details.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,29 @@

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

import { get_partitions, fmt_size } from "./utils.js";
import { get_fstab_config } from "./fsys-tab.jsx"; // XXX
import { get_partitions, fmt_size } from "../utils.js";
import { get_fstab_config } from "../filesystem/utils.jsx";

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

import { make_overview_page } from "./pages/overview.jsx";
import { make_unrecognized_data_page } from "./pages/unrecognized-data.jsx";
import { make_unformatted_data_page } from "./pages/unformatted-data.jsx";
import { make_locked_encrypted_data_page } from "./pages/locked-encrypted-data.jsx";
import { make_filesystem_page } from "./pages/filesystem.jsx";
import { make_lvm2_physical_volume_page } from "./pages/lvm2-physical-volume.jsx";
import { make_mdraid_disk_page } from "./pages/mdraid-disk.jsx";
import { make_stratis_blockdev_page } from "./pages/stratis-blockdev.jsx";
import { make_swap_page } from "./pages/swap.jsx";
import { make_partition_table_page } from "./pages/partition-table.jsx";
import { make_legacy_vdo_page } from "./pages/legacy-vdo.jsx";
import { make_unrecognized_data_page } from "./unrecognized-data.jsx";
import { make_unformatted_data_page } from "./unformatted-data.jsx";
import { make_locked_encrypted_data_page } from "../crypto/locked-encrypted-data.jsx";
import { make_filesystem_page } from "../filesystem/filesystem.jsx";
import { make_lvm2_physical_volume_page } from "../lvm2/physical-volume.jsx";
import { make_mdraid_disk_page } from "../mdraid/mdraid-disk.jsx";
import { make_stratis_blockdev_page } from "../stratis/blockdev.jsx";
import { make_swap_page } from "../swap/swap.jsx";
import { make_partition_table_page } from "../partitions/partition-table.jsx";
import { make_legacy_vdo_page } from "../legacy-vdo/legacy-vdo.jsx";

import { make_partition_container, delete_partition } from "./containers/partition.jsx";
import { make_encryption_container } from "./containers/encryption.jsx";
import { make_partition_container, delete_partition } from "../partitions/partition.jsx";
import { make_encryption_container } from "../crypto/encryption.jsx";

import { new_page, reset_pages } from "./pages.jsx";
import { new_page } from "../pages.jsx";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -179,8 +178,3 @@ export function make_block_page(parent, block, container) {
make_unrecognized_data_page(parent, block, content_block, container);
}
}

export function create_pages() {
reset_pages();
make_overview_page();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
*/

import cockpit from "cockpit";
import * as utils from "./utils.js";
import { edit_crypto_config, parse_options, unparse_options, extract_option } from "./utils.js";
import {
edit_crypto_config, parse_options, unparse_options, extract_option,
get_parent_blocks, is_netdev,
decode_filename, encode_filename, block_name,
get_active_usage, reload_systemd, teardown_active_usage,
validate_fsys_label,
} from "../utils.js";

import React from "react";
import { FormHelperText } from "@patternfly/react-core/dist/esm/components/Form/index.js";
Expand All @@ -31,26 +36,26 @@ import {
TextInput, PassInput, CheckBoxes, SelectOne, SizeSlider,
BlockingMessage, TeardownMessage,
init_active_usage_processes
} from "./dialog.jsx";
} from "../dialog.jsx";

import { get_fstab_config, is_valid_mount_point } from "./fsys-tab.jsx";
import { init_existing_passphrase, unlock_with_type } from "./crypto-keyslots.jsx";
import { job_progress_wrapper } from "./jobs-panel.jsx";
import { get_fstab_config, is_valid_mount_point } from "../filesystem/utils.jsx";
import { init_existing_passphrase, unlock_with_type } from "../crypto/keyslots.jsx";
import { job_progress_wrapper } from "../jobs-panel.jsx";

const _ = cockpit.gettext;

export function initial_tab_options(client, block, for_fstab) {
const options = { };

utils.get_parent_blocks(client, block.path).forEach(p => {
get_parent_blocks(client, block.path).forEach(p => {
// "nofail" is the default for new filesystems with Cockpit so
// that a failure to mount one of them will not prevent
// Cockpit from starting. This allows people to debug and fix
// these failures with Cockpit itself.
//
options.nofail = true;

if (utils.is_netdev(client, p)) {
if (is_netdev(client, p)) {
options._netdev = true;
}
// HACK - https://bugzilla.redhat.com/show_bug.cgi?id=1589541
Expand Down Expand Up @@ -126,7 +131,7 @@ export const mount_explanation = {
export function format_dialog(client, path, start, size, enable_dos_extended) {
const block = client.blocks[path];
if (block.IdUsage == "crypto") {
cockpit.spawn(["cryptsetup", "luksDump", utils.decode_filename(block.Device)], { superuser: true })
cockpit.spawn(["cryptsetup", "luksDump", decode_filename(block.Device)], { superuser: true })
.then(output => {
if (output.indexOf("Keyslots:") >= 0) // This is what luksmeta-monitor-hack looks for
return 2;
Expand Down Expand Up @@ -155,9 +160,9 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,

let title;
if (create_partition)
title = cockpit.format(_("Create partition on $0"), utils.block_name(block));
title = cockpit.format(_("Create partition on $0"), block_name(block));
else
title = cockpit.format(_("Format $0"), utils.block_name(block));
title = cockpit.format(_("Format $0"), block_name(block));

function is_filesystem(vals) {
return vals.type != "empty" && vals.type != "dos-extended";
Expand Down Expand Up @@ -206,11 +211,11 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
add_crypto_type("luks1", "LUKS1", false);
add_crypto_type("luks2", "LUKS2", true);

const usage = utils.get_active_usage(client, create_partition ? null : path, _("format"), _("delete"));
const usage = get_active_usage(client, create_partition ? null : path, _("format"), _("delete"));

if (usage.Blocking) {
dialog_open({
Title: cockpit.format(_("$0 is in use"), utils.block_name(block)),
Title: cockpit.format(_("$0 is in use"), block_name(block)),
Body: BlockingMessage(usage)
});
return;
Expand All @@ -219,7 +224,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
const crypto_config = block.Configuration.find(c => c[0] == "crypttab");
let crypto_options;
if (crypto_config) {
crypto_options = (utils.decode_filename(crypto_config[1].options.v)
crypto_options = (decode_filename(crypto_config[1].options.v)
.split(",")
.filter(function (s) { return s.indexOf("x-parent") !== 0 })
.join(","));
Expand Down Expand Up @@ -266,7 +271,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
Fields: [
TextInput("name", _("Name"),
{
validate: (name, vals) => utils.validate_fsys_label(name, vals.type),
validate: (name, vals) => validate_fsys_label(name, vals.type),
visible: is_filesystem
}),
TextInput("mount_point", _("Mount point"),
Expand Down Expand Up @@ -429,17 +434,17 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
}

opts = opts.concat(parse_options(vals.crypto_options));
new_crypto_options = { t: 'ay', v: utils.encode_filename(unparse_options(opts)) };
new_crypto_options = { t: 'ay', v: encode_filename(unparse_options(opts)) };
const item = {
options: new_crypto_options,
"track-parents": { t: 'b', v: true }
};

if (!keep_keys) {
if (vals.store_passphrase.on) {
item["passphrase-contents"] = { t: 'ay', v: utils.encode_filename(vals.passphrase) };
item["passphrase-contents"] = { t: 'ay', v: encode_filename(vals.passphrase) };
} else {
item["passphrase-contents"] = { t: 'ay', v: utils.encode_filename("") };
item["passphrase-contents"] = { t: 'ay', v: encode_filename("") };
}
config_items.push(["crypttab", item]);
options["encrypt.passphrase"] = { t: 's', v: vals.passphrase };
Expand Down Expand Up @@ -471,9 +476,9 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
mount_point = "/" + mount_point;

config_items.push(["fstab", {
dir: { t: 'ay', v: utils.encode_filename(mount_point) },
type: { t: 'ay', v: utils.encode_filename("auto") },
opts: { t: 'ay', v: utils.encode_filename(mount_options.join(",") || "defaults") },
dir: { t: 'ay', v: encode_filename(mount_point) },
type: { t: 'ay', v: encode_filename("auto") },
opts: { t: 'ay', v: encode_filename(mount_options.join(",") || "defaults") },
freq: { t: 'i', v: 0 },
passno: { t: 'i', v: 0 },
"track-parents": { t: 'b', v: true }
Expand Down Expand Up @@ -547,10 +552,10 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
.then(block_crypto => block_crypto.Lock({ })));
}

return utils.teardown_active_usage(client, usage)
.then(utils.reload_systemd)
return teardown_active_usage(client, usage)
.then(reload_systemd)
.then(format)
.then(new_path => utils.reload_systemd().then(() => new_path))
.then(new_path => reload_systemd().then(() => new_path))
.then(maybe_mount);
}
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/pages/other.jsx → pkg/storaged/block/other.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { ActionButtons, new_container, block_location } from "../pages.jsx";
import { block_name } from "../utils.js";
import { partitionable_block_actions } from "./drive.jsx";
import { partitionable_block_actions } from "../partitions/actions.jsx";

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

const _ = cockpit.gettext;

Expand Down
12 changes: 6 additions & 6 deletions pkg/storaged/resize.jsx → pkg/storaged/block/resize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

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

import {
block_name, get_active_usage, teardown_active_usage,
undo_temporary_teardown, is_mounted_synch, get_partitions
} from "./utils.js";
} from "../utils.js";
import {
existing_passphrase_fields, init_existing_passphrase,
request_passphrase_on_error_handler
} from "./crypto-keyslots.jsx";
} from "../crypto/keyslots.jsx";
import {
dialog_open, SizeSlider, BlockingMessage, TeardownMessage, SelectSpaces,
init_active_usage_processes
} from "./dialog.jsx";
import { std_reply } from "./stratis-utils.js";
import { pvs_to_spaces } from "./content-views.jsx";
} from "../dialog.jsx";
import { std_reply } from "../stratis/utils.jsx";
import { pvs_to_spaces } from "../lvm2/utils.jsx";

const _ = cockpit.gettext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
new_page, block_location, ActionButtons, page_type,
} from "../pages.jsx";
import { SCard } from "../utils/card.jsx";
import { format_dialog } from "../format-dialog.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { block_name } from "../utils.js";
import { std_lock_action } from "../actions.jsx";
import { std_lock_action } from "../crypto/actions.jsx";
import { StorageSize } from "../storage-controls.jsx";

const _ = cockpit.gettext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import {
} from "../pages.jsx";
import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { format_dialog } from "../format-dialog.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { block_name } from "../utils.js";
import { std_lock_action } from "../actions.jsx";
import { std_lock_action } from "../crypto/actions.jsx";
import { StorageSize } from "../storage-controls.jsx";

const _ = cockpit.gettext;
Expand Down
14 changes: 8 additions & 6 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import { find_warnings } from "./warnings.jsx";

import inotify_py from "inotify.py";
import mount_users_py from "./mount-users.py";
import nfs_mounts_py from "./nfs-mounts.py";
import vdo_monitor_py from "./vdo-monitor.py";
import stratis2_set_key_py from "./stratis2-set-key.py";
import stratis3_set_key_py from "./stratis3-set-key.py";
import nfs_mounts_py from "./nfs/nfs-mounts.py";
import vdo_monitor_py from "./legacy-vdo/vdo-monitor.py";
import stratis2_set_key_py from "./stratis/stratis2-set-key.py";
import stratis3_set_key_py from "./stratis/stratis3-set-key.py";

import { create_pages } from "./create-pages.jsx";
import { reset_pages } from "./pages.jsx";
import { make_overview_page } from "./overview/overview.jsx";

/* STORAGED CLIENT
*/
Expand Down Expand Up @@ -615,7 +616,8 @@ client.update = (first_time) => {
if (client.ready) {
update_indices();
client.path_warnings = find_warnings(client);
create_pages();
reset_pages();
make_overview_page();
client.dispatchEvent("changed");
}
};
Expand Down
Loading

0 comments on commit 6921848

Please sign in to comment.