Skip to content

Commit

Permalink
storage: Allow adding cache to encrypted pools
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvollmer committed Jun 6, 2023
1 parent fe26c62 commit 05bdefb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
40 changes: 30 additions & 10 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -960,21 +962,38 @@ 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 })
.input(passphrase);
};

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 = () => {
Expand All @@ -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 });
Expand Down
6 changes: 5 additions & 1 deletion pkg/storaged/stratis-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
29 changes: 27 additions & 2 deletions test/verify/check-storage-stratis
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import re

from packagelib import PackageCase
from storagelib import StorageCase
from testlib import skipImage, test_main
Expand All @@ -32,6 +34,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
Expand Down Expand Up @@ -275,6 +284,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
Expand Down Expand Up @@ -318,15 +331,27 @@ 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()
b.enter_page("/storage")
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)')
Expand Down

0 comments on commit 05bdefb

Please sign in to comment.