From 2176bd23b50da7a373a74cee141d40cc5d05bfae Mon Sep 17 00:00:00 2001 From: Hadi Chokr Date: Tue, 28 Apr 2026 12:04:50 +0200 Subject: [PATCH] useradd: skip btrfs subvolume creation for system users Gate subvolume creation on user_id >= UID_MIN to exclude system users regardless of their home path. System users do not benefit from BTRFS subvolumes. They hold no snapshot-worthy data and do not interact with the filesystem in ways that would justify the overhead. Subvolumes multiply metadata operations and create unnecessary filesystem objects for accounts that simply do not need them. The BTRFS backend originally required an explicit flag to opt in to subvolume creation, making interactive useradd invocations the only practical target. Skipping subvolume creation for system users is the appropriate default. Fixes: c1d36a8acb1d (2019-05-04; "Add support for btrfs subvolumes for user homes") Signed-off-by: Hadi Chokr --- src/useradd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/useradd.c b/src/useradd.c index 9210379c8b..4b3ae3f8e3 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2220,12 +2220,21 @@ static void create_home(const struct option_flags *flags) char *bhome, *cp; mode_t mode; bool process_selinux; +#if WITH_BTRFS + uid_t uid_min; + uid_t uid_max; +#endif process_selinux = !flags->chroot && !flags->prefix; if (access (prefix_user_home, F_OK) == 0) return; +#if WITH_BTRFS + uid_min = getdef_ulong("UID_MIN", 1000UL); + uid_max = getdef_ulong("UID_MAX", 60000UL); +#endif + strcpy(path, ""); bhome = strdup(prefix_user_home); if (!bhome) { @@ -2264,7 +2273,8 @@ static void create_home(const struct option_flags *flags) dir_created = false; #if WITH_BTRFS - if (subvolflg && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) { + if (subvolflg && user_id >= uid_min && user_id <= uid_max + && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) { char *btrfs_check = strdup(path); struct statfs sfs;