Move FIFREEZE/FITHAW ioctl invocations into linuxfsutil.c
authorColin Walters <walters@verbum.org>
Wed, 3 Aug 2022 14:43:43 +0000 (10:43 -0400)
committerColin Walters <walters@verbum.org>
Wed, 3 Aug 2022 14:44:51 +0000 (10:44 -0400)
Should help avoid conflicts between glibc and linux headers.

Closes: https://github.com/ostreedev/ostree/issues/2685
src/libostree/ostree-linuxfsutil.c
src/libostree/ostree-linuxfsutil.h
src/libostree/ostree-sysroot-deploy.c

index 97f936048a42c33542deb30575e27f32f4bbb6ee..aa389aaa80ba654db3b061d6ea3c93550b23b52f 100644 (file)
 
 #include <fcntl.h>
 #include <sys/ioctl.h>
+// This should be the only file including linux/fs.h; see
+// https://sourceware.org/glibc/wiki/Release/2.36#Usage_of_.3Clinux.2Fmount.h.3E_and_.3Csys.2Fmount.h.3E
+// https://github.com/ostreedev/ostree/issues/2685
+#include <linux/fs.h>
 #include <ext2fs/ext2_fs.h>
 
-#include "otutil.h"
-
 /**
  * _ostree_linuxfs_fd_alter_immutable_flag:
  * @fd: A file descriptor
@@ -88,3 +90,21 @@ _ostree_linuxfs_fd_alter_immutable_flag (int            fd,
 
   return TRUE;
 }
+
+/* Wrapper for FIFREEZE ioctl.
+ * This is split into a separate wrapped API for
+ * reasons around conflicts between glibc and linux/fs.h
+ * includes; see above.
+ */
+int
+_ostree_linuxfs_filesystem_freeze (int fd)
+{
+  return TEMP_FAILURE_RETRY (ioctl (fd, FIFREEZE, 0));
+}
+
+/* Wrapper for FITHAW ioctl.  See above. */
+int
+_ostree_linuxfs_filesystem_thaw (int fd)
+{
+  return TEMP_FAILURE_RETRY (ioctl (fd, FITHAW, 0));
+}
index 0654b6fc7ccf8fcf7cd5cb9dea02c146fa9d90d8..9011c9d86981da9c7f6b7d43bcdae6e0c8321f88 100644 (file)
@@ -29,4 +29,7 @@ _ostree_linuxfs_fd_alter_immutable_flag (int            fd,
                                          GCancellable  *cancellable,
                                          GError       **error);
 
+int _ostree_linuxfs_filesystem_freeze (int fd);
+int _ostree_linuxfs_filesystem_thaw (int fd);
+
 G_END_DECLS
index 2dc9f58b16777a2c94b0df0df468ff659e6ee717..d86de7dc7b7a91557de69b6dbf8a7e93005f6210 100644 (file)
@@ -29,7 +29,6 @@
 #include <sys/ioctl.h>
 #include <stdbool.h>
 #include <sys/poll.h>
-#include <linux/fs.h>
 #include <err.h>
 
 #ifdef HAVE_LIBMOUNT
@@ -1476,7 +1475,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
            * EOPNOTSUPP: If the filesystem doesn't support it
            */
           int saved_errno = errno;
-          (void) TEMP_FAILURE_RETRY (ioctl (rootfs_dfd, FITHAW, 0));
+          _ostree_linuxfs_filesystem_thaw (rootfs_dfd);
           errno = saved_errno;
           /* But if we got an error from poll, let's log it */
           if (r < 0)
@@ -1517,7 +1516,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
           return glnx_throw (error, "aborting due to test-fifreeze");
         }
       /* Do a freeze/thaw cycle; TODO add a FIFREEZETHAW ioctl */
-      if (ioctl (rootfs_dfd, FIFREEZE, 0) != 0)
+      if (_ostree_linuxfs_filesystem_freeze (rootfs_dfd) != 0)
         {
           /* Not supported, we're running in the unit tests (as non-root), or
            * the filesystem is already frozen (EBUSY).
@@ -1539,7 +1538,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
             return glnx_throw_errno_prefix (error, "ioctl(FIFREEZE)");
         }
       /* And finally thaw, then signal our completion to the watchdog */
-      if (TEMP_FAILURE_RETRY (ioctl (rootfs_dfd, FITHAW, 0)) != 0)
+      if (_ostree_linuxfs_filesystem_thaw (rootfs_dfd) != 0)
         {
           /* Warn but don't error if the filesystem was already thawed */
           if (errno == EINVAL)