]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: avoid unnecessary mount_setattr() call in make_fsmount()
authorLennart Poettering <lennart@poettering.net>
Sat, 31 May 2025 05:58:30 +0000 (07:58 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 25 Jun 2025 17:17:42 +0000 (18:17 +0100)
If .attr_set is zero (and .att_clr, .propagation too), then there's no
point in calling mount_setattr().

Fixes: #37062
Note that this optimization is not precisely load-bearing anymore, since
3cc23a2c2345eb188551565349c89ec1fa8f650f got merged which removes the
only caller of make_fsmount() that might trigger it. But it's worth
fixing generic code anyway, in case it gets used like this later again.

(cherry picked from commit 249752d1ecd0f8e160d6e8633f71771b51db5a84)
(cherry picked from commit 77babb252d94e1e9e46f0cdb13d198bd1e4e5958)

src/shared/mount-util.c

index f932a5eac012f025892291b47840024f9a074dcc..26902e5ac0d2d1cf351474bc0ee6841e1b47a421 100644 (file)
@@ -1801,11 +1801,11 @@ int make_fsmount(
         if (mnt_fd < 0)
                 return log_full_errno(error_log_level, errno, "Failed to create mount fd for \"%s\" (\"%s\"): %m", what, type);
 
-        if (mount_setattr(mnt_fd, "", AT_EMPTY_PATH|AT_RECURSIVE,
-                          &(struct mount_attr) {
-                                  .attr_set = ms_flags_to_mount_attr(f) | (userns_fd >= 0 ? MOUNT_ATTR_IDMAP : 0),
-                                  .userns_fd = userns_fd,
-                          }, MOUNT_ATTR_SIZE_VER0) < 0)
+        struct mount_attr ma = {
+                .attr_set = ms_flags_to_mount_attr(f) | (userns_fd >= 0 ? MOUNT_ATTR_IDMAP : 0),
+                .userns_fd = userns_fd,
+        };
+        if (ma.attr_set != 0 && mount_setattr(mnt_fd, "", AT_EMPTY_PATH|AT_RECURSIVE, &ma, MOUNT_ATTR_SIZE_VER0) < 0)
                 return log_full_errno(error_log_level,
                                       errno,
                                       "Failed to set mount flags for \"%s\" (\"%s\"): %m",