From 37ba9ce7ca3bdeea1de03a0652087c829b3d0c28 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Wed, 28 Aug 2024 10:28:01 +0300 Subject: [PATCH] WIP - teardown before locking We should have done this anyway, and now we need it to get rid of the tmp mountpoint. --- pkg/storaged/crypto/actions.jsx | 31 +++++++++++++++++++++++++++--- test/verify/check-storage-anaconda | 10 ++-------- test/verify/check-storage-luks | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/pkg/storaged/crypto/actions.jsx b/pkg/storaged/crypto/actions.jsx index ad7a8ec19ef..31c1727ed33 100644 --- a/pkg/storaged/crypto/actions.jsx +++ b/pkg/storaged/crypto/actions.jsx @@ -21,8 +21,8 @@ import cockpit from "cockpit"; import client from "../client"; import { get_existing_passphrase, unlock_with_type } from "./keyslots.jsx"; -import { set_crypto_auto_option } from "../utils.js"; -import { dialog_open, PassInput } from "../dialog.jsx"; +import { set_crypto_auto_option, get_active_usage, teardown_active_usage, block_name } from "../utils.js"; +import { dialog_open, PassInput, init_teardown_usage, TeardownMessage, BlockingMessage } from "../dialog.jsx"; const _ = cockpit.gettext; @@ -63,7 +63,32 @@ export function lock(block) { if (!crypto) return; - return crypto.Lock({}).then(() => set_crypto_auto_option(block, false)); + const name = block_name(block); + const usage = get_active_usage(client, block.path, _("lock")); + + if (usage.Blocking) { + dialog_open({ + Title: cockpit.format(_("$0 is in use"), name), + Body: BlockingMessage(usage) + }); + return; + } + + dialog_open({ + Title: cockpit.format(_("Lock $0?"), name), + Teardown: TeardownMessage(usage), + Action: { + Title: _("Lock"), + action: async function () { + await teardown_active_usage(client, usage); + await crypto.Lock({}); + await set_crypto_auto_option(block, false); + } + }, + Inits: [ + init_teardown_usage(client, usage) + ] + }); } export function std_lock_action(backing_block, content_block) { diff --git a/test/verify/check-storage-anaconda b/test/verify/check-storage-anaconda index 79331969985..48b38f90b5c 100755 --- a/test/verify/check-storage-anaconda +++ b/test/verify/check-storage-anaconda @@ -283,11 +283,6 @@ class TestStorageAnaconda(storagelib.StorageCase): self.dialog_apply() self.dialog_wait_close() - # Mount so that we can create subvolumes - b.wait_text(self.card_row_col("Storage", 1, 3), "btrfs filesystem (encrypted)") - self.click_dropdown(self.card_row("Storage", location="/mnt/butter"), "Mount") - self.dialog({}) - # Create two subvolumes self.click_dropdown(self.card_row("Storage", location="/mnt/butter"), "Create subvolume") self.dialog_wait_open() @@ -306,11 +301,10 @@ class TestStorageAnaconda(storagelib.StorageCase): self.dialog_apply() self.dialog_wait_close() - # Unmount and lock, mount point exporting should still work + # Lock, mount point exporting should still work - self.click_dropdown(self.card_row("Storage", location="/mnt/butter"), "Unmount") - self.dialog({}) self.click_dropdown(self.card_row("Storage", name=disk), "Lock") + self.confirm() b.wait_text(self.card_row_col("Storage", 1, 3), "Locked data (encrypted)") self.expectExportedDevice(disk, diff --git a/test/verify/check-storage-luks b/test/verify/check-storage-luks index e8790e19378..115f8bc2b84 100755 --- a/test/verify/check-storage-luks +++ b/test/verify/check-storage-luks @@ -267,6 +267,7 @@ class TestStorageLuks(storagelib.StorageCase): # Lock it b.click(self.card_button("Unformatted data", "Lock")) + self.confirm() b.wait_visible(self.card("Locked data")) # Make it readonly