2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2015-03-01 16:39:31 +01:00
|
|
|
|
2015-12-03 21:13:37 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "btrfs-util.h"
|
2017-12-19 14:33:11 +01:00
|
|
|
#include "label.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "machine-pool.h"
|
2015-12-03 21:13:37 +01:00
|
|
|
#include "missing.h"
|
2015-10-26 22:01:44 +01:00
|
|
|
#include "stat-util.h"
|
2015-03-01 16:39:31 +01:00
|
|
|
|
|
|
|
static int check_btrfs(void) {
|
|
|
|
struct statfs sfs;
|
|
|
|
|
|
|
|
if (statfs("/var/lib/machines", &sfs) < 0) {
|
|
|
|
if (errno != ENOENT)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
if (statfs("/var/lib", &sfs) < 0)
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
|
|
|
|
}
|
|
|
|
|
2018-10-11 10:27:59 +02:00
|
|
|
int setup_machine_directory(sd_bus_error *error) {
|
2015-03-01 16:39:31 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
r = check_btrfs();
|
|
|
|
if (r < 0)
|
|
|
|
return sd_bus_error_set_errnof(error, r, "Failed to determine whether /var/lib/machines is located on btrfs: %m");
|
2016-03-14 00:51:37 +01:00
|
|
|
if (r == 0)
|
2015-03-03 00:13:12 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-10-11 10:27:59 +02:00
|
|
|
(void) btrfs_subvol_make_label("/var/lib/machines");
|
2015-03-03 00:13:12 +01:00
|
|
|
|
2018-10-11 10:27:59 +02:00
|
|
|
r = btrfs_quota_enable("/var/lib/machines", true);
|
2018-09-24 19:47:42 +02:00
|
|
|
if (r < 0)
|
2018-10-11 10:27:59 +02:00
|
|
|
log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
|
2018-09-24 19:47:42 +02:00
|
|
|
|
2018-10-11 10:27:59 +02:00
|
|
|
r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
|
2018-09-24 19:47:42 +02:00
|
|
|
if (r < 0)
|
2018-10-11 10:27:59 +02:00
|
|
|
log_warning_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, ignoring: %m");
|
2015-03-03 00:13:12 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|