]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Handle EINVAL as not supported for chattr_xxx()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 26 May 2025 14:11:06 +0000 (16:11 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 26 May 2025 19:59:08 +0000 (21:59 +0200)
F2FS returns EINVAL from FS_IOC_SETFLAGS when trying to set
FS_NOCOW_FL. Let's handle this by treating EINVAL as not supported.
While we're at it, make sure we use ERRNO_IS_IOCTL_NOT_SUPPORTED()
across the tree instead of ERRNO_IS_NOT_SUPPORTED() when calling any
of the chattr_xxx() functions.

Fixes #37593

src/basic/chattr-util.c
src/basic/fs-util.c
src/home/homework-luks.c
src/journal/journalctl-authenticate.c
src/repart/repart.c
src/shared/copy.c
src/shared/import-util.c
src/tmpfiles/tmpfiles.c

index 5786c12a3f8db1a94c67a488aa19bc0a25876aaf..70a0210f72b8d5601b4dceb3a7a5285a0365a2b1 100644 (file)
@@ -80,16 +80,15 @@ int chattr_full(
                 errno = EINVAL;
         }
 
-        if ((errno != EINVAL && !ERRNO_IS_NOT_SUPPORTED(errno)) ||
-            !FLAGS_SET(flags, CHATTR_FALLBACK_BITWISE))
+        if (!ERRNO_IS_IOCTL_NOT_SUPPORTED(errno) || !FLAGS_SET(flags, CHATTR_FALLBACK_BITWISE))
                 return -errno;
 
-        /* When -EINVAL is returned, we assume that incompatible attributes are simultaneously
-         * specified. E.g., compress(c) and nocow(C) attributes cannot be set to files on btrfs.
-         * As a fallback, let's try to set attributes one by one.
+        /* When -EINVAL is returned, incompatible attributes might be simultaneously specified. E.g.,
+         * compress(c) and nocow(C) attributes cannot be set to files on btrfs. As a fallback, let's try to
+         * set attributes one by one.
          *
-         * Also, when we get EOPNOTSUPP (or a similar error code) we assume a flag might just not be
-         * supported, and we can ignore it too */
+         * Alternatively, when we get EINVAL or EOPNOTSUPP (or a similar error code) we assume a flag might
+         * just not be supported, and we can ignore it too */
 
         unsigned current_attr = old_attr;
 
@@ -110,7 +109,7 @@ int chattr_full(
 
                         /* Ensures that we record whether only EOPNOTSUPP&friends are encountered, or if a more serious
                          * error (thus worth logging at a different level, etc) was seen too. */
-                        if (set_flags_errno == 0 || !ERRNO_IS_NOT_SUPPORTED(errno))
+                        if (set_flags_errno == 0 || !ERRNO_IS_IOCTL_NOT_SUPPORTED(errno))
                                 set_flags_errno = -errno;
 
                         continue;
@@ -125,10 +124,10 @@ int chattr_full(
         if (ret_final)
                 *ret_final = current_attr;
 
-        /* -ENOANO indicates that some attributes cannot be set. ERRNO_IS_NOT_SUPPORTED indicates that all
-         * encountered failures were due to flags not supported by the FS, so return a specific error in
+        /* -ENOANO indicates that some attributes cannot be set. ERRNO_IS_IOCTL_NOT_SUPPORTED indicates that
+         * all encountered failures were due to flags not supported by the FS, so return a specific error in
          * that case, so callers can handle it properly (e.g.: tmpfiles.d can use debug level logging). */
-        return current_attr == new_attr ? 1 : ERRNO_IS_NOT_SUPPORTED(set_flags_errno) ? set_flags_errno : -ENOANO;
+        return current_attr == new_attr ? 1 : ERRNO_IS_IOCTL_NOT_SUPPORTED(set_flags_errno) ? set_flags_errno : -ENOANO;
 }
 
 int read_attr_fd(int fd, unsigned *ret) {
index 6c6b00596779e8202547dc7e3898042a26a86ac2..5db9572ba558fe0aca28f49812685f9d9a19ab6f 100644 (file)
@@ -1280,7 +1280,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
 
         if (FLAGS_SET(xopen_flags, XO_NOCOW)) {
                 r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
-                if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r))
+                if (r < 0 && !ERRNO_IS_IOCTL_NOT_SUPPORTED(r))
                         goto error;
         }
 
index dc510eb1f5f046b7aa8026e875e09966e60113b7..e92e5e2eb9a4e9dced0007fe0fc49ffe3fff2ce3 100644 (file)
@@ -2304,7 +2304,7 @@ int home_create_luks(
 
                 r = chattr_full(setup->image_fd, NULL, FS_NOCOW_FL|FS_NOCOMP_FL, FS_NOCOW_FL|FS_NOCOMP_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
                 if (r < 0 && r != -ENOANO) /* ENOANO → some bits didn't work; which we skip logging about because chattr_full() already debug logs about those flags */
-                        log_full_errno(ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
+                        log_full_errno(ERRNO_IS_IOCTL_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
                                        "Failed to set file attributes on %s, ignoring: %m", setup->temporary_image_path);
 
                 r = calculate_initial_image_size(h, setup->image_fd, fstype, &host_size);
index 7b2d8714ad8a15e96b5572d3bced21f17b317779..0728493e0142b972f56aa7722ce21e8c53f5eaf1 100644 (file)
@@ -137,7 +137,7 @@ int action_setup_keys(void) {
 
         r = chattr_secret(fd, CHATTR_WARN_UNSUPPORTED_FLAGS);
         if (r < 0)
-                log_full_errno(ERRNO_IS_NOT_SUPPORTED(r) || arg_quiet ? LOG_DEBUG : LOG_WARNING,
+                log_full_errno(ERRNO_IS_IOCTL_NOT_SUPPORTED(r) || arg_quiet ? LOG_DEBUG : LOG_WARNING,
                                r, "Failed to set file attributes on a temporary file for '%s', ignoring: %m", path);
 
         struct FSSHeader h = {
index ccc820ec515430963cb28a8f2ed5ef7eb4f6fdf5..89d4297d626cb9d4c1a3426661b8f166c2569bf3 100644 (file)
@@ -4368,7 +4368,7 @@ static int prepare_temporary_file(Context *context, PartitionTarget *t, uint64_t
 
         if (FLAGS_SET(attrs, FS_NOCOW_FL)) {
                 r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
-                if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r))
+                if (r < 0 && !ERRNO_IS_IOCTL_NOT_SUPPORTED(r))
                         return log_error_errno(r, "Failed to disable copy-on-write on %s: %m", temp);
         }
 
index 08828856c0b3548cb7475ce45a779828922c9174..ca2325459d9d1863de4cf31822985a104f784f1a 100644 (file)
@@ -774,7 +774,7 @@ static int prepare_nocow(int fdf, const char *from, int fdt, unsigned *chattr_ma
                 return 0;
 
         r = read_attr_at(fdf, from, &attrs);
-        if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP) /* If the source is a symlink we get ELOOP */
+        if (r < 0 && !ERRNO_IS_IOCTL_NOT_SUPPORTED(r) && r != -ELOOP) /* If the source is a symlink we get ELOOP */
                 return r;
 
         if (FLAGS_SET(attrs, FS_NOCOW_FL)) {
index 50794a86ba96df0cacd71e005ad558c160898b04..9c9a9d7e301efd2e9b687ea0ea17010e0b08f462 100644 (file)
@@ -232,7 +232,7 @@ int import_set_nocow_and_log(int fd, const char *path) {
         r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
         if (r < 0)
                 return log_full_errno(
-                                ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING,
+                                ERRNO_IS_IOCTL_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING,
                                 r, "Failed to set file attributes on %s: %m", path);
 
         return 0;
index 3a3f8b1bfd2a2b68d0246f38674cc5df8a202a03..5d51d9ae4fdfa2516ef4f25321f74bd9ba2c3569 100644 (file)
@@ -1653,7 +1653,7 @@ static int fd_set_attribute(
                                     "previous=0x%08x, current=0x%08x, expected=0x%08x, ignoring.",
                                     path, previous, current, (previous & ~item->attribute_mask) | (f & item->attribute_mask));
                 else if (r < 0)
-                        log_full_errno(ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
+                        log_full_errno(ERRNO_IS_IOCTL_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r,
                                        "Cannot set file attributes for '%s', value=0x%08x, mask=0x%08x, ignoring: %m",
                                        path, item->attribute_value, item->attribute_mask);
         }