summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-28 20:16:42 +0200
committerLennart Poettering <lennart@poettering.net>2021-11-16 17:18:07 +0100
commit71bf7ba1939cba29dfaf6734c243980a16c324c0 (patch)
tree0b55e29ac0325f4fab15b0b5ed969f995e4c69de
parent61fa16c1ca0d60dfcc2fc759171461de55e768ad (diff)
downloadsystemd-71bf7ba1939cba29dfaf6734c243980a16c324c0.tar.gz
user-record: relax rules on diskSize user record field
Let's not refuse low or high disk sizes unnecessarily early. They disk sizes are subject fs limits anyway, hence there's no point in adding another limit. Relaxing thhe rules here as the advantage that we can later allow "homectl resize lennart 0" as a generic way to minimize disk space.
-rw-r--r--src/home/home-util.h7
-rw-r--r--src/home/user-record-util.c3
-rw-r--r--src/shared/user-record.c24
-rw-r--r--src/shared/user-record.h7
4 files changed, 9 insertions, 32 deletions
diff --git a/src/home/home-util.h b/src/home/home-util.h
index 5e633ea4af..ca4c068f37 100644
--- a/src/home/home-util.h
+++ b/src/home/home-util.h
@@ -12,6 +12,13 @@
#define HOME_UID_MIN 60001
#define HOME_UID_MAX 60513
+/* Put some limits on disk sizes: not less than 5M, not more than 5T */
+#define USER_DISK_SIZE_MIN (UINT64_C(5)*1024*1024)
+#define USER_DISK_SIZE_MAX (UINT64_C(5)*1024*1024*1024*1024)
+
+/* The default disk size to use when nothing else is specified, relative to free disk space */
+#define USER_DISK_SIZE_DEFAULT_PERCENT 85
+
bool suitable_user_name(const char *name);
int suitable_realm(const char *realm);
int suitable_image_path(const char *path);
diff --git a/src/home/user-record-util.c b/src/home/user-record-util.c
index 464f1dbb7a..276caaa172 100644
--- a/src/home/user-record-util.c
+++ b/src/home/user-record-util.c
@@ -639,9 +639,6 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
if (!h->json)
return -EUNATCH;
- if (disk_size < USER_DISK_SIZE_MIN || disk_size > USER_DISK_SIZE_MAX)
- return -ERANGE;
-
r = sd_id128_get_machine(&mid);
if (r < 0)
return r;
diff --git a/src/shared/user-record.c b/src/shared/user-record.c
index b68b6a98d2..e16395f032 100644
--- a/src/shared/user-record.c
+++ b/src/shared/user-record.c
@@ -563,26 +563,6 @@ static int json_dispatch_storage(const char *name, JsonVariant *variant, JsonDis
return 0;
}
-static int json_dispatch_disk_size(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
- uint64_t *size = userdata;
- uintmax_t k;
-
- if (json_variant_is_null(variant)) {
- *size = UINT64_MAX;
- return 0;
- }
-
- if (!json_variant_is_unsigned(variant))
- return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
-
- k = json_variant_unsigned(variant);
- if (k < USER_DISK_SIZE_MIN || k > USER_DISK_SIZE_MAX)
- return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' is not in valid range %" PRIu64 "…%" PRIu64 ".", strna(name), USER_DISK_SIZE_MIN, USER_DISK_SIZE_MAX);
-
- *size = k;
- return 0;
-}
-
static int json_dispatch_tasks_or_memory_max(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
uint64_t *limit = userdata;
uintmax_t k;
@@ -1135,7 +1115,7 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp
{ "notBeforeUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_before_usec), 0 },
{ "notAfterUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_after_usec), 0 },
{ "storage", JSON_VARIANT_STRING, json_dispatch_storage, offsetof(UserRecord, storage), 0 },
- { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_disk_size, offsetof(UserRecord, disk_size), 0 },
+ { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size), 0 },
{ "diskSizeRelative", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size_relative), 0 },
{ "skeletonDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(UserRecord, skeleton_directory), 0 },
{ "accessMode", JSON_VARIANT_UNSIGNED, json_dispatch_access_mode, offsetof(UserRecord, access_mode), 0 },
@@ -1484,7 +1464,7 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla
{ "notBeforeUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_before_usec), 0 },
{ "notAfterUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, not_after_usec), 0 },
{ "storage", JSON_VARIANT_STRING, json_dispatch_storage, offsetof(UserRecord, storage), 0 },
- { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_disk_size, offsetof(UserRecord, disk_size), 0 },
+ { "diskSize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size), 0 },
{ "diskSizeRelative", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, disk_size_relative), 0 },
{ "skeletonDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(UserRecord, skeleton_directory), 0 },
{ "accessMode", JSON_VARIANT_UNSIGNED, json_dispatch_access_mode, offsetof(UserRecord, access_mode), 0 },
diff --git a/src/shared/user-record.h b/src/shared/user-record.h
index c72bef4a72..22a6bb28f4 100644
--- a/src/shared/user-record.h
+++ b/src/shared/user-record.h
@@ -10,13 +10,6 @@
#include "missing_resource.h"
#include "time-util.h"
-/* But some limits on disk sizes: not less than 5M, not more than 5T */
-#define USER_DISK_SIZE_MIN (UINT64_C(5)*1024*1024)
-#define USER_DISK_SIZE_MAX (UINT64_C(5)*1024*1024*1024*1024)
-
-/* The default disk size to use when nothing else is specified, relative to free disk space */
-#define USER_DISK_SIZE_DEFAULT_PERCENT 85
-
typedef enum UserDisposition {
USER_INTRINSIC, /* root and nobody */
USER_SYSTEM, /* statically allocated users for system services */