]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/machine-pool.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / shared / machine-pool.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <sys/statfs.h>
5
6 #include "btrfs-util.h"
7 #include "label.h"
8 #include "machine-pool.h"
9 #include "missing.h"
10 #include "stat-util.h"
11
12 static int check_btrfs(void) {
13 struct statfs sfs;
14
15 if (statfs("/var/lib/machines", &sfs) < 0) {
16 if (errno != ENOENT)
17 return -errno;
18
19 if (statfs("/var/lib", &sfs) < 0)
20 return -errno;
21 }
22
23 return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
24 }
25
26 int setup_machine_directory(sd_bus_error *error) {
27 int r;
28
29 r = check_btrfs();
30 if (r < 0)
31 return sd_bus_error_set_errnof(error, r, "Failed to determine whether /var/lib/machines is located on btrfs: %m");
32 if (r == 0)
33 return 0;
34
35 (void) btrfs_subvol_make_label("/var/lib/machines");
36
37 r = btrfs_quota_enable("/var/lib/machines", true);
38 if (r < 0)
39 log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
40
41 r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
42 if (r < 0)
43 log_warning_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, ignoring: %m");
44
45 return 1;
46 }