Skip to content

Commit

Permalink
storaged: Move /var/lib/cockpit/btrfs to /run
Browse files Browse the repository at this point in the history
This shouldn't be on persistent storage -- after a reboot all the mounts
are gone, so the database should not survive that either.

Use `os.path.join()` for a slightly more regular and cleaner path
building.

Move the database on package upgrades, to not break new cockpit sessions
in the current boot.
  • Loading branch information
martinpitt committed Jan 10, 2025
1 parent 7b48ee7 commit 85808c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pkg/storaged/btrfs/btrfs-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def debug(msg):
pass


TMP_MP_DIR = "/var/lib/cockpit/btrfs"
TMP_MP_DIR = "/run/cockpit/btrfs"


def read_all(fd):
Expand Down Expand Up @@ -106,7 +106,7 @@ def add_tmp_mountpoint(db, fs, dev, opt_repair):
else:
db[uuid] = 1
if not fs['has_tmp_mountpoint'] and (db[uuid] == 1 or opt_repair):
path = TMP_MP_DIR + "/" + uuid
path = os.path.join(TMP_MP_DIR, uuid)
debug(f"MOUNTING {path}")
os.makedirs(path, exist_ok=True)
subprocess.check_call(["mount", dev, path])
Expand All @@ -118,7 +118,7 @@ def remove_tmp_mountpoint(db, uuid):
debug(f"REMOVING {uuid}")
tmp_mountpoints.remove(uuid)
if db[uuid] == 1:
path = TMP_MP_DIR + "/" + uuid
path = os.path.join(TMP_MP_DIR, uuid)
try:
debug(f"UNMOUNTING {path}")
subprocess.check_call(["umount", path])
Expand All @@ -139,7 +139,7 @@ def remove_all_tmp_mountpoints():

def force_mount_point(db, fs, opt_repair):
add_tmp_mountpoint(db, fs, fs['devices'][0], opt_repair)
return TMP_MP_DIR + "/" + fs['uuid']
return os.path.join(TMP_MP_DIR, fs['uuid'])


def get_mount_point(db, fs, opt_mount, opt_repair):
Expand Down Expand Up @@ -251,7 +251,7 @@ def cmd_do(uuid, cmd):
filesystems = list_filesystems()
for fs in filesystems.values():
if fs['uuid'] == uuid:
path = "/run/cockpit/btrfs"
path = os.path.join(TMP_MP_DIR, uuid)
dev = fs['devices'][0]
os.makedirs(path, mode=0o700, exist_ok=True)
unshare_mounts()
Expand Down
2 changes: 1 addition & 1 deletion pkg/storaged/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as timeformat from "timeformat";
const _ = cockpit.gettext;
const C_ = cockpit.gettext;

export const BTRFS_TOOL_MOUNT_PATH = "/var/lib/cockpit/btrfs/";
export const BTRFS_TOOL_MOUNT_PATH = "/run/cockpit/btrfs/";

/* UTILITIES
*/
Expand Down
8 changes: 8 additions & 0 deletions tools/cockpit.spec
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,14 @@ The Cockpit component for managing storage. This package uses udisks.
%files -n cockpit-storaged -f storaged.list
%{_datadir}/metainfo/org.cockpit_project.cockpit_storaged.metainfo.xml

%post cockpit-storaged

# version 332 moved the btrfs temp mounts db to /run
if [ "$1" = 2 ] && [ -d /var/lib/cockpit/btrfs ] && [ ! -e /run/cockpit/btrfs ]; then
mkdir -p /run/cockpit
mv /var/lib/cockpit/btrfs /run/cockpit || true
fi

%package -n cockpit-packagekit
Summary: Cockpit user interface for packages
BuildArch: noarch
Expand Down
11 changes: 11 additions & 0 deletions tools/debian/cockpit-storage.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e

#DEBHELPER#

# version 332 moved the btrfs temp mounts db to /run
if [ "$1" = "configure" ] && dpkg --compare-versions "$2" lt-nl 322 &&
[ -d /var/lib/cockpit/btrfs ] && [ ! -e /run/cockpit/btrfs ]; then
mkdir -p /run/cockpit
mv /var/lib/cockpit/btrfs /run/cockpit || true
fi

0 comments on commit 85808c5

Please sign in to comment.