Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Sep 20, 2023
1 parent 98a2e09 commit 3480ea7
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 39 deletions.
34 changes: 34 additions & 0 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ function init_model(callback) {
}
}

client.anaconda = cockpit.manifests?.storage.anaconda;

pull_time().then(() => {
read_os_release().then(os_release => {
client.os_release = os_release;
Expand Down Expand Up @@ -1371,4 +1373,36 @@ client.get_config = (name, def) => {
}
};

client.in_anaconda_mode = () => !!client.anaconda;

client.strip_mount_point_prefix = (dir) => {
const mpp = client.anaconda?.mount_point_prefix;

if (dir && mpp) {
if (dir.indexOf(mpp) != 0)
return false;

dir = dir.substr(mpp.length);
if (dir == "")
dir = "/";
}

return dir;
}

client.add_mount_point_prefix = (dir) => {
const mpp = client.anaconda?.mount_point_prefix;
if (mpp) {
if (dir == "/")
dir = mpp;
else
dir = mpp + dir;
}
return dir;
}

client.should_ignore_device = (devname) => {
return client.anaconda && client.anaconda.ignore_devices.indexOf(devname) != -1;
}

export default client;
16 changes: 14 additions & 2 deletions pkg/storaged/content-views.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function block_description(client, block, options) {
type = cockpit.format(C_("storage-id-desc", "$0 filesystem"), block.IdType);
if (client.fsys_sizes.data[mount_point])
size = client.fsys_sizes.data[mount_point];
used_for = mount_point;
used_for = client.strip_mount_point_prefix(mount_point);
} else if (block.IdUsage == "raid") {
if (block_pvol && client.vgroups[block_pvol.VolumeGroup]) {
const vgroup = client.vgroups[block_pvol.VolumeGroup];
Expand Down Expand Up @@ -559,6 +559,18 @@ function append_row(client, rows, level, key, name, desc, tabs, job_object, opti
if (info)
info = <>{"\n"}{info}</>;

let location;
if (desc.used_for === false) {
// XXX - urks
location = _("(Not part of target)");
menu = null;
tabs.actions = null;
tabs.renderers = [];
} else if (desc.link)
location = <Button isInline variant="link" onClick={() => cockpit.location.go(desc.link)}>{desc.used_for}</Button>;
else
location = desc.used_for;

const cols = [
{
title: (
Expand All @@ -568,7 +580,7 @@ function append_row(client, rows, level, key, name, desc, tabs, job_object, opti
</span>)
},
{ title: desc.type },
{ title: desc.link ? <Button isInline variant="link" onClick={() => cockpit.location.go(desc.link)}>{desc.used_for}</Button> : desc.used_for },
{ title: location },
{
title: desc.size.length
? <StorageUsageBar stats={desc.size} critical={desc.critical_size || 0.95} block={name} />
Expand Down
11 changes: 9 additions & 2 deletions pkg/storaged/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ export const BlockingMessage = (usage) => {
pvol: _("physical volume of LVM2 volume group"),
mdraid: _("member of RAID device"),
vdo: _("backing device for VDO device"),
"stratis-pool-member": _("member of Stratis pool")
"stratis-pool-member": _("member of Stratis pool"),
mounted: _("Filesystem outside the target"),
};

const rows = [];
Expand Down Expand Up @@ -1151,9 +1152,15 @@ export const TeardownMessage = (usage) => {
const name = (fsys
? fsys.Devnode
: block_name(client.blocks[use.block.CryptoBackingDevice] || use.block));
let location = use.location;
if (use.usage == "mounted") {
location = client.strip_mount_point_prefix(location);
if (location === false)
location = _("(Not part of target)");
}
rows.push({
columns: [name,
use.location || "-",
location || "-",
use.actions.length ? use.actions.join(", ") : "-",
{
title: <UsersPopover users={use.users || []} />,
Expand Down
3 changes: 2 additions & 1 deletion pkg/storaged/drives-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class DrivesPanel extends React.Component {
const drives = drive_rows(client);

return (
<SidePanel id="drives"
<SidePanel client={client}
id="drives"
className="storage-drives-list"
title={_("Drives")}
empty_text={_("No drives attached")}
Expand Down
29 changes: 20 additions & 9 deletions pkg/storaged/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ export function extract_option(split, opt) {
export function initial_tab_options(client, block, for_fstab) {
const options = { };

utils.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.
//
// "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.
//
// In Anaconda mode however, we don't make "nofail" the
// default since people will be creating the core filesystems
// like "/", "/var", etc.

if (!client.in_anaconda_mode())
options.nofail = true;

utils.get_parent_blocks(client, block.path).forEach(p => {

if (utils.is_netdev(client, p)) {
options._netdev = true;
}
Expand Down Expand Up @@ -160,10 +166,10 @@ export function format_dialog(client, path, start, size, enable_dos_extended) {
return false;
})
.then(version => {
format_dialog_internal(client, path, start, size, enable_dos_extended, version);
return format_dialog_internal(client, path, start, size, enable_dos_extended, version);
});
} else {
format_dialog_internal(client, path, start, size, enable_dos_extended);
return format_dialog_internal(client, path, start, size, enable_dos_extended);
}
}

Expand Down Expand Up @@ -260,6 +266,10 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
if (old_opts == undefined)
old_opts = initial_mount_options(client, block);

old_dir = client.strip_mount_point_prefix(old_dir);
if (old_dir === false)
return Promise.reject(_("This device can not be used for the installation target."));

const split_options = parse_options(old_opts);
extract_option(split_options, "noauto");
const opt_ro = extract_option(split_options, "ro");
Expand Down Expand Up @@ -298,7 +308,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
value: old_dir || "",
validate: (val, values, variant) => {
if (variant !== "nomount")
return is_valid_mount_point(client, block, val);
return is_valid_mount_point(client, block, client.add_mount_point_prefix(val));
}
}),
SelectOne("type", _("Type"),
Expand Down Expand Up @@ -492,6 +502,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
if (mount_point != "") {
if (mount_point[0] != "/")
mount_point = "/" + mount_point;
mount_point = client.add_mount_point_prefix(mount_point);

config_items.push(["fstab", {
dir: { t: 'ay', v: utils.encode_filename(mount_point) },
Expand Down
20 changes: 14 additions & 6 deletions pkg/storaged/fsys-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ export class FilesystemsPanel extends React.Component {

function make_mount(path) {
const block = client.blocks[path];
const [, mount_point] = get_fstab_config(block, true);
let [, mount_point] = get_fstab_config(block, true);
const fsys_size = client.fsys_sizes.data[mount_point];
const backing_block = client.blocks[block.CryptoBackingDevice] || block;
const block_lvm2 = client.blocks_lvm2[backing_block.path];
const lvol = block_lvm2 && client.lvols[block_lvm2.LogicalVolume];
const vgroup = lvol && client.vgroups[lvol.VolumeGroup];
let name = null;

mount_point = client.strip_mount_point_prefix(mount_point);
if (mount_point === false)
return null;

if (vgroup)
name = vgroup.Name + "/" + lvol.Name;

Expand All @@ -106,7 +110,7 @@ export class FilesystemsPanel extends React.Component {
}

const mounts = Object.keys(client.blocks).filter(is_mount)
.map(make_mount);
.map(make_mount).filter(m => m != null);

function has_filesystems(path) {
return client.stratis_pool_filesystems[path].length > 0;
Expand All @@ -132,8 +136,11 @@ export class FilesystemsPanel extends React.Component {
let mount = "-";
if (block) {
const [, mp] = get_fstab_config(block, true);
if (mp)
mount = mp;
if (mp) {
mount = client.strip_mount_point_prefix(mp);
if (mount === false)
return null;
}
}
return {
props: { path, client, key: fs.path },
Expand All @@ -152,11 +159,11 @@ export class FilesystemsPanel extends React.Component {
}
]
};
});
}).filter(m => m != null);
}

const pools = Object.keys(client.stratis_pools).filter(has_filesystems)
.map(make_pool);
.map(make_pool);

function onRowClick(event, row) {
if (!event || event.button !== 0)
Expand All @@ -177,6 +184,7 @@ export class FilesystemsPanel extends React.Component {
sortBy={{ index: 0, direction: SortByDirection.asc }}
aria-label={_("Filesystems")}
onRowClick={onRowClick}
emptyCaption={_("No filesystems")}
columns={[
{ title: _("Source"), sortable: true },
{ title: _("Type"), sortable: true },
Expand Down
20 changes: 14 additions & 6 deletions pkg/storaged/fsys-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export function mounting_dialog(client, block, mode, forced_options) {
const [old_config, old_dir, old_opts, old_parents] = get_fstab_config(block, true);
const options = old_config ? old_opts : initial_tab_options(client, block, true);

const old_dir_for_display = client.strip_mount_point_prefix(old_dir);
if (old_dir_for_display === false)
return Promise.reject(_("This device can not be used for the installation target."));

const split_options = parse_options(options);
extract_option(split_options, "noauto");
const opt_never_auto = extract_option(split_options, "x-cockpit-never-auto");
Expand Down Expand Up @@ -329,8 +333,8 @@ export function mounting_dialog(client, block, mode, forced_options) {
fields = [
TextInput("mount_point", _("Mount point"),
{
value: old_dir,
validate: val => is_valid_mount_point(client, block, val)
value: old_dir_for_display,
validate: val => is_valid_mount_point(client, block, client.add_mount_point_prefix(val))
}),
CheckBoxes("mount_options", _("Mount options"),
{
Expand Down Expand Up @@ -460,7 +464,8 @@ export function mounting_dialog(client, block, mode, forced_options) {
opts = opts.concat(forced_options);
if (vals.mount_options.extra !== false)
opts = opts.concat(parse_options(vals.mount_options.extra));
return (maybe_update_config(vals.mount_point, unparse_options(opts),
return (maybe_update_config(client.add_mount_point_prefix(vals.mount_point),
unparse_options(opts),
vals.passphrase, passphrase_type)
.then(() => maybe_set_crypto_options(vals.mount_options.ro,
opts.indexOf("noauto") == -1,
Expand Down Expand Up @@ -553,6 +558,7 @@ export class FilesystemTab extends React.Component {

let mount_point_text = null;
if (old_dir) {
mount_point_text = client.strip_mount_point_prefix(old_dir);
let opt_texts = [];
if (opt_ro)
opt_texts.push(_("read only"));
Expand All @@ -564,11 +570,13 @@ export class FilesystemTab extends React.Component {
opt_texts.push(_("ignore failure"));
else
opt_texts.push(_("stop boot on failure"));
if (mount_point_text === false) {
mount_point_text = "";
opt_texzs.push(_("not part of target"));
}
opt_texts = opt_texts.concat(split_options);
if (opt_texts.length) {
mount_point_text = cockpit.format("$0 ($1)", old_dir, opt_texts.join(", "));
} else {
mount_point_text = old_dir;
mount_point_text = cockpit.format("$0 ($1)", mount_point_text, opt_texts.join(", "));
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/nfs-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class NFSPanel extends React.Component {
);

const nfs_feature = {
is_enabled: () => client.features.nfs,
package: client.get_config("nfs_client_package", false),
is_enabled: () => !client.in_anaconda_mode() && client.features.nfs,
package: !client.in_anaconda_mode() && client.get_config("nfs_client_package", false),
enable: () => {
client.features.nfs = true;
client.nfs.start();
Expand Down
5 changes: 3 additions & 2 deletions pkg/storaged/side-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class SidePanel extends React.Component {

render() {
let show_all_button = null;
let rows = this.props.rows.filter(row => !!row);
const client = this.props.client;
let rows = this.props.rows.filter(row => !!row && !(client && client.should_ignore_device(row.devname)));

// Find new items for animations
const current_keys = rows.map(row => row.key);
Expand Down Expand Up @@ -83,7 +84,7 @@ export class SidePanel extends React.Component {
feature={this.props.feature}
not_installed_text={this.props.not_installed_text}
install_title={this.props.install_title}>
{ this.props.rows.length > 0
{ rows.length > 0
? <Flex direction={{ default: 'column' }}
spaceItems={{ default: 'spaceItemsNone' }}>
{ children }
Expand Down
Loading

0 comments on commit 3480ea7

Please sign in to comment.