]>
Commit | Line | Data |
---|---|---|
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 | |
11 | static 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 | ||
5f7ecd61 | 25 | int setup_machine_directory(sd_bus_error *error) { |
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 | ||
5f7ecd61 | 34 | (void) btrfs_subvol_make_label("/var/lib/machines"); |
26166c88 | 35 | |
5f7ecd61 | 36 | r = btrfs_quota_enable("/var/lib/machines", true); |
7e691278 | 37 | if (r < 0) |
5f7ecd61 | 38 | log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m"); |
7e691278 | 39 | |
5f7ecd61 | 40 | r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true); |
7e691278 | 41 | if (r < 0) |
5f7ecd61 | 42 | log_warning_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, ignoring: %m"); |
26166c88 | 43 | |
26166c88 LP |
44 | return 1; |
45 | } |