mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-22 22:03:43 +03:00
import: wire up SYSTEMD_IMPORT_BTRFS_{SUBVOL,QUOTA} to importd
Btrfs quotas are actually being enabled in systemd-importd via setup_machine_directory(), not in systemd-{import,pull} where those environment variables are checked. Therefore, also check them in systemd-importd and avoid enabling quotas if requested by the user. Fixes: #18421 Fixes: #15903 Fixes: #24387 (cherry picked from commit c7779a61ac20133646aaeaee2986d4e0901f4861) (cherry picked from commit fcc174cbdd9e0d9f9d2db87ee8020a8397136bda)
This commit is contained in:
parent
c31cceb0fd
commit
3bb53f281d
@ -95,6 +95,9 @@ struct Manager {
|
|||||||
int notify_fd;
|
int notify_fd;
|
||||||
|
|
||||||
sd_event_source *notify_event_source;
|
sd_event_source *notify_event_source;
|
||||||
|
|
||||||
|
bool use_btrfs_subvol;
|
||||||
|
bool use_btrfs_quota;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TRANSFERS_MAX 64
|
#define TRANSFERS_MAX 64
|
||||||
@ -631,10 +634,15 @@ static int manager_new(Manager **ret) {
|
|||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
m = new0(Manager, 1);
|
m = new(Manager, 1);
|
||||||
if (!m)
|
if (!m)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
*m = (Manager) {
|
||||||
|
.use_btrfs_subvol = true,
|
||||||
|
.use_btrfs_quota = true,
|
||||||
|
};
|
||||||
|
|
||||||
r = sd_event_default(&m->event);
|
r = sd_event_default(&m->event);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
@ -723,7 +731,7 @@ static int method_import_tar_or_raw(sd_bus_message *msg, void *userdata, sd_bus_
|
|||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||||
"Local name %s is invalid", local);
|
"Local name %s is invalid", local);
|
||||||
|
|
||||||
r = setup_machine_directory(error);
|
r = setup_machine_directory(error, m->use_btrfs_subvol, m->use_btrfs_quota);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -793,7 +801,7 @@ static int method_import_fs(sd_bus_message *msg, void *userdata, sd_bus_error *e
|
|||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||||
"Local name %s is invalid", local);
|
"Local name %s is invalid", local);
|
||||||
|
|
||||||
r = setup_machine_directory(error);
|
r = setup_machine_directory(error, m->use_btrfs_subvol, m->use_btrfs_quota);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -946,7 +954,7 @@ static int method_pull_tar_or_raw(sd_bus_message *msg, void *userdata, sd_bus_er
|
|||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||||
"Unknown verification mode %s", verify);
|
"Unknown verification mode %s", verify);
|
||||||
|
|
||||||
r = setup_machine_directory(error);
|
r = setup_machine_directory(error, m->use_btrfs_subvol, m->use_btrfs_quota);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -1363,6 +1371,28 @@ static int manager_run(Manager *m) {
|
|||||||
m);
|
m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void manager_parse_env(Manager *m) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
/* Same as src/import/{import,pull}.c:
|
||||||
|
* Let's make these relatively low-level settings also controllable via env vars. User can then set
|
||||||
|
* them for systemd-importd.service if they like to tweak behaviour */
|
||||||
|
|
||||||
|
r = getenv_bool("SYSTEMD_IMPORT_BTRFS_SUBVOL");
|
||||||
|
if (r >= 0)
|
||||||
|
m->use_btrfs_subvol = r;
|
||||||
|
else if (r != -ENXIO)
|
||||||
|
log_warning_errno(r, "Failed to parse $SYSTEMD_IMPORT_BTRFS_SUBVOL: %m");
|
||||||
|
|
||||||
|
r = getenv_bool("SYSTEMD_IMPORT_BTRFS_QUOTA");
|
||||||
|
if (r >= 0)
|
||||||
|
m->use_btrfs_quota = r;
|
||||||
|
else if (r != -ENXIO)
|
||||||
|
log_warning_errno(r, "Failed to parse $SYSTEMD_IMPORT_BTRFS_QUOTA: %m");
|
||||||
|
}
|
||||||
|
|
||||||
static int run(int argc, char *argv[]) {
|
static int run(int argc, char *argv[]) {
|
||||||
_cleanup_(manager_unrefp) Manager *m = NULL;
|
_cleanup_(manager_unrefp) Manager *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
@ -1385,6 +1415,8 @@ static int run(int argc, char *argv[]) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to allocate manager object: %m");
|
return log_error_errno(r, "Failed to allocate manager object: %m");
|
||||||
|
|
||||||
|
manager_parse_env(m);
|
||||||
|
|
||||||
r = manager_add_bus_objects(m);
|
r = manager_add_bus_objects(m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -870,7 +870,7 @@ static int method_set_pool_limit(sd_bus_message *message, void *userdata, sd_bus
|
|||||||
return 1; /* Will call us back */
|
return 1; /* Will call us back */
|
||||||
|
|
||||||
/* Set up the machine directory if necessary */
|
/* Set up the machine directory if necessary */
|
||||||
r = setup_machine_directory(error);
|
r = setup_machine_directory(error, /* use_btrfs_subvol= */ true, /* use_btrfs_quota= */ true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ static int check_btrfs(void) {
|
|||||||
return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
|
return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
int setup_machine_directory(sd_bus_error *error) {
|
int setup_machine_directory(sd_bus_error *error, bool use_btrfs_subvol, bool use_btrfs_quota) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = check_btrfs();
|
r = check_btrfs();
|
||||||
@ -31,8 +31,14 @@ int setup_machine_directory(sd_bus_error *error) {
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!use_btrfs_subvol)
|
||||||
|
return 0;
|
||||||
|
|
||||||
(void) btrfs_subvol_make_label("/var/lib/machines");
|
(void) btrfs_subvol_make_label("/var/lib/machines");
|
||||||
|
|
||||||
|
if (!use_btrfs_quota)
|
||||||
|
return 0;
|
||||||
|
|
||||||
r = btrfs_quota_enable("/var/lib/machines", true);
|
r = btrfs_quota_enable("/var/lib/machines", true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
|
log_warning_errno(r, "Failed to enable quota for /var/lib/machines, ignoring: %m");
|
||||||
|
@ -5,4 +5,4 @@
|
|||||||
|
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
|
|
||||||
int setup_machine_directory(sd_bus_error *error);
|
int setup_machine_directory(sd_bus_error *error, bool use_btrfs_subvol, bool use_btrfs_quota);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user