]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/machine-pool.c
Merge pull request #11714 from poettering/final-news-241
[thirdparty/systemd.git] / src / shared / machine-pool.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
432cea00 2
a8fbdf54 3#include <errno.h>
a8fbdf54 4#include <sys/statfs.h>
a8fbdf54 5
07630cea 6#include "btrfs-util.h"
de2e28d8 7#include "label.h"
3ffd4af2 8#include "machine-pool.h"
a8fbdf54 9#include "missing.h"
8fcde012 10#include "stat-util.h"
432cea00
LP
11
12static 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
5f7ecd61 26int setup_machine_directory(sd_bus_error *error) {
432cea00
LP
27 int r;
28
432cea00
LP
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");
c3b0e5ac 32 if (r == 0)
26166c88
LP
33 return 0;
34
5f7ecd61 35 (void) btrfs_subvol_make_label("/var/lib/machines");
26166c88 36
5f7ecd61 37 r = btrfs_quota_enable("/var/lib/machines", true);
7e691278 38 if (r < 0)
5f7ecd61 39 log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
7e691278 40
5f7ecd61 41 r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
7e691278 42 if (r < 0)
5f7ecd61 43 log_warning_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, ignoring: %m");
26166c88 44
26166c88
LP
45 return 1;
46}