]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/machine-pool.c
import: wire up SYSTEMD_IMPORT_BTRFS_{SUBVOL,QUOTA} to importd
[thirdparty/systemd.git] / src / shared / machine-pool.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
432cea00 2
a8fbdf54 3#include <errno.h>
a8fbdf54 4
07630cea 5#include "btrfs-util.h"
de2e28d8 6#include "label.h"
3ffd4af2 7#include "machine-pool.h"
f5947a5e 8#include "missing_magic.h"
8fcde012 9#include "stat-util.h"
432cea00
LP
10
11static int check_btrfs(void) {
12 struct statfs sfs;
13
14 if (statfs("/var/lib/machines", &sfs) < 0) {
15 if (errno != ENOENT)
16 return -errno;
17
18 if (statfs("/var/lib", &sfs) < 0)
19 return -errno;
20 }
21
22 return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
23}
24
c7779a61 25int setup_machine_directory(sd_bus_error *error, bool use_btrfs_subvol, bool use_btrfs_quota) {
432cea00
LP
26 int r;
27
432cea00
LP
28 r = check_btrfs();
29 if (r < 0)
30 return sd_bus_error_set_errnof(error, r, "Failed to determine whether /var/lib/machines is located on btrfs: %m");
c3b0e5ac 31 if (r == 0)
26166c88
LP
32 return 0;
33
c7779a61
IS
34 if (!use_btrfs_subvol)
35 return 0;
36
5f7ecd61 37 (void) btrfs_subvol_make_label("/var/lib/machines");
26166c88 38
c7779a61
IS
39 if (!use_btrfs_quota)
40 return 0;
41
5f7ecd61 42 r = btrfs_quota_enable("/var/lib/machines", true);
7e691278 43 if (r < 0)
5f7ecd61 44 log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
7e691278 45
5f7ecd61 46 r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
7e691278 47 if (r < 0)
5f7ecd61 48 log_warning_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, ignoring: %m");
26166c88 49
e9231901 50 return 0;
26166c88 51}