Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storaged: btrfs helper cleanups #21504

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 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 @@ -225,6 +225,7 @@ def cmd_monitor(opt_mount):


def cmd_poll(opt_mount):
unshare_mounts()
infos = poll(opt_mount, opt_repair=True)
sys.stdout.write(json.dumps(infos) + "\n")
sys.stdout.flush()
Expand All @@ -245,17 +246,18 @@ def unshare_mounts():
errno = get_errno_loc()[0]
raise OSError(errno, os.strerror(errno))

subprocess.check_call(["mount", "--make-rprivate", "/"])


def cmd_do(uuid, cmd):
debug(f"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()
subprocess.check_call(["mount", "--make-rprivate", "/"])
subprocess.check_call(["mount", dev, path])
subprocess.check_call(cmd, cwd=path)

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 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
Loading