From 9718ac32f35873bdce6ad6fd2fbad6cbe95be081 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Fri, 26 May 2023 15:56:51 +0300 Subject: [PATCH] storage: Allow adding cache to encrypted pools This requires moving to "r5" of the D-Bus API, but arch is still on "r4". So let's fall back, and let's fall all the way back to "r2" since that is all we need for the rest of the features. --- pkg/storaged/client.js | 40 +++++++++++++++++++++++-------- pkg/storaged/stratis-details.jsx | 6 ++++- test/reference | 2 +- test/verify/check-storage-stratis | 29 +++++++++++++++++++--- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/pkg/storaged/client.js b/pkg/storaged/client.js index ccf2895c7fa4..4a05e0f52a94 100644 --- a/pkg/storaged/client.js +++ b/pkg/storaged/client.js @@ -945,11 +945,13 @@ client.stratis_start = () => { // not allowed. If we need to bump it, it should be bumped here for all // of them at the same time. // -const stratis3_interface_revision = "r2"; +const stratis3_interface_revision_newest = 5; +const stratis3_interface_revision_fallback = 2; +let stratis3_interface_revision = stratis3_interface_revision_newest; function stratis3_start() { const stratis = cockpit.dbus("org.storage.stratis3", { superuser: "try" }); - client.stratis_manager = stratis.proxy("org.storage.stratis3.Manager." + stratis3_interface_revision, + client.stratis_manager = stratis.proxy("org.storage.stratis3.Manager.r" + stratis3_interface_revision, "/org/storage/stratis3"); // The rest of the code expects these to be initialized even if no @@ -960,6 +962,14 @@ function stratis3_start() { client.stratis_manager.StoppedPools = {}; return client.stratis_manager.wait() + .catch(err => { + if (stratis3_interface_revision == stratis3_interface_revision_newest && + !client.stratis_manager.valid) { + stratis3_interface_revision = stratis3_interface_revision_fallback; + return stratis3_start(); + } + return Promise.reject(err); + }) .then(() => { client.stratis_store_passphrase = (desc, passphrase) => { return python.spawn(stratis3_set_key_py, [desc], { superuser: true }) @@ -967,14 +977,23 @@ function stratis3_start() { }; client.stratis_start_pool = (uuid, unlock_method) => { - return client.stratis_manager.StartPool(uuid, [!!unlock_method, unlock_method || ""]); + if (stratis3_interface_revision >= 4) + return client.stratis_manager.StartPool(uuid, "uuid", [!!unlock_method, unlock_method || ""]); + else + return client.stratis_manager.StartPool(uuid, [!!unlock_method, unlock_method || ""]); }; client.stratis_create_pool = (name, devs, key_desc) => { - return client.stratis_manager.CreatePool(name, [false, 0], - devs, - key_desc ? [true, key_desc] : [false, ""], - [false, ["", ""]]); + if (stratis3_interface_revision >= 5) + return client.stratis_manager.CreatePool(name, + devs, + key_desc ? [true, key_desc] : [false, ""], + [false, ["", ""]]); + else + return client.stratis_manager.CreatePool(name, [false, 0], + devs, + key_desc ? [true, key_desc] : [false, ""], + [false, ["", ""]]); }; client.stratis_list_keys = () => { @@ -986,15 +1005,16 @@ function stratis3_start() { }; client.features.stratis = true; - client.stratis_pools = client.stratis_manager.client.proxies("org.storage.stratis3.pool." + + client.features.stratis_encrypted_caches = stratis3_interface_revision >= 5; + client.stratis_pools = client.stratis_manager.client.proxies("org.storage.stratis3.pool.r" + stratis3_interface_revision, "/org/storage/stratis3", { watch: false }); - client.stratis_blockdevs = client.stratis_manager.client.proxies("org.storage.stratis3.blockdev." + + client.stratis_blockdevs = client.stratis_manager.client.proxies("org.storage.stratis3.blockdev.r" + stratis3_interface_revision, "/org/storage/stratis3", { watch: false }); - client.stratis_filesystems = client.stratis_manager.client.proxies("org.storage.stratis3.filesystem." + + client.stratis_filesystems = client.stratis_manager.client.proxies("org.storage.stratis3.filesystem.r" + stratis3_interface_revision, "/org/storage/stratis3", { watch: false }); diff --git a/pkg/storaged/stratis-details.jsx b/pkg/storaged/stratis-details.jsx index 7ff56069137f..f976a64f8c79 100644 --- a/pkg/storaged/stratis-details.jsx +++ b/pkg/storaged/stratis-details.jsx @@ -83,7 +83,11 @@ const StratisPoolSidebar = ({ client, pool }) => { { choices: [ { value: "data", title: _("Data") }, - { value: "cache", title: _("Cache"), disabled: pool.Encrypted } + { + value: "cache", + title: _("Cache"), + disabled: !client.features.stratis_encrypted_caches + } ] }), PassInput("passphrase", _("Passphrase"), diff --git a/test/reference b/test/reference index e85a62d5fb36..53dee03e261b 160000 --- a/test/reference +++ b/test/reference @@ -1 +1 @@ -Subproject commit e85a62d5fb36dddbcedf1c288e1c834b731fdbd4 +Subproject commit 53dee03e261b4d6a88e85c58c8a43ee52b34aa50 diff --git a/test/verify/check-storage-stratis b/test/verify/check-storage-stratis index 2121eb6a4552..76b7ad3e14ce 100755 --- a/test/verify/check-storage-stratis +++ b/test/verify/check-storage-stratis @@ -20,7 +20,7 @@ from packagelib import PackageCase from storagelib import StorageCase from testlib import skipImage, test_main - +import re @skipImage("No Stratis", "debian-*", "ubuntu-*") class TestStorageStratis(StorageCase): @@ -32,6 +32,13 @@ class TestStorageStratis(StorageCase): self.machine.execute("systemctl enable --now stratisd") self.addCleanup(self.machine.execute, "systemctl disable --now stratisd") + ver = self.machine.execute("stratis daemon version") + m = re.match('s "(.*)"', ver) + if m: + self.stratisd_version = list(map(int, m.group(1).split("."))) + else: + self.stratisd_version = [0] + def testBasic(self): m = self.machine b = self.browser @@ -275,6 +282,10 @@ class TestStorageStratis(StorageCase): m.add_disk("4G", serial="DISK2") b.wait_in_text("#drives", dev_2) + dev_3 = "/dev/sdc" + m.add_disk("4G", serial="DISK3") + b.wait_in_text("#drives", dev_3) + # Create an encrypted pool with a filesystem, but don't mount # it. Cockpit will chose a key description for the pool and # we occupy its first choice in order to force Cockpit to use @@ -318,6 +329,18 @@ class TestStorageStratis(StorageCase): b.wait_in_text('#detail-sidebar', dev_2) b.wait_in_text(f'#detail-sidebar .sidepanel-row:contains({dev_2})', "data") + if self.stratisd_version >= [3, 5]: + # Add a cache blockdev + b.click('#detail-sidebar .pf-v5-c-card__actions button') + self.dialog_wait_open() + self.dialog_set_val('tier', "cache") + self.dialog_set_val('disks', {dev_3: True}) + self.dialog_set_val('passphrase', "foodeeboodeebar") + self.dialog_apply() + self.dialog_wait_close() + b.wait_in_text('#detail-sidebar', dev_3) + b.wait_in_text(f'#detail-sidebar .sidepanel-row:contains({dev_3})', "cache") + m.reboot() m.start_cockpit() b.relogin() @@ -325,8 +348,8 @@ class TestStorageStratis(StorageCase): b.wait_visible("#storage-detail") b.wait_in_text('#detail-header', "Stopped Stratis pool") - b.wait_in_text('#detail-sidebar', dev_1) - b.wait_in_text('#detail-sidebar', dev_2) + b.wait_in_text('#detail-sidebar', "DISK1") + b.wait_in_text('#detail-sidebar', "DISK2") # Unlock the pool b.click('#detail-header button:contains(Start)')