]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: make platform_set_blocksize exit on fatal failure
authorChristoph Hellwig <hch@lst.de>
Mon, 11 Dec 2023 16:37:35 +0000 (17:37 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 18 Dec 2023 13:57:49 +0000 (14:57 +0100)
platform_set_blocksize has a fatal argument that is currently only
used to change the printed message.  Make it actually fatal similar to
other libfrog platform helpers to simplify the caller.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libfrog/linux.c
libfrog/platform.h
libxfs/init.c

index 2e4fd316e75cb59e0b928dd57f61d6c02fe64e70..46a5ff39e2eb72981fca6533822d77a351e8bc38 100644 (file)
@@ -127,20 +127,23 @@ platform_check_iswritable(char *name, char *block, struct stat *s)
        return platform_check_mount(name, block, s, flags);
 }
 
-int
-platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
+void
+platform_set_blocksize(int fd, char *path, dev_t device, int blocksize,
+               bool fatal)
 {
-       int error = 0;
-
-       if (major(device) != RAMDISK_MAJOR) {
-               if ((error = ioctl(fd, BLKBSZSET, &blocksize)) < 0) {
-                       fprintf(stderr, _("%s: %s - cannot set blocksize "
-                                       "%d on block device %s: %s\n"),
-                               progname, fatal ? "error": "warning",
-                               blocksize, path, strerror(errno));
-               }
+       int error;
+
+       if (major(device) == RAMDISK_MAJOR)
+               return;
+       error = ioctl(fd, BLKBSZSET, &blocksize);
+       if (error < 0) {
+               fprintf(stderr, _("%s: %s - cannot set blocksize "
+                               "%d on block device %s: %s\n"),
+                       progname, fatal ? "error": "warning",
+                       blocksize, path, strerror(errno));
+               if (fatal)
+                       exit(1);
        }
-       return error;
 }
 
 /*
index e3e6b7c71b780a7dbe777467277c01a83ca4a6b9..20f9bdf5ce5b0279903727853719a7470d6682c8 100644 (file)
@@ -10,8 +10,8 @@
 int platform_check_ismounted(char *path, char *block, struct stat *sptr,
                int verbose);
 int platform_check_iswritable(char *path, char *block, struct stat *sptr);
-int platform_set_blocksize(int fd, char *path, dev_t device, int bsz,
-               int fatal);
+void platform_set_blocksize(int fd, char *path, dev_t device, int bsz,
+               bool fatal);
 int platform_flush_device(int fd, dev_t device);
 int platform_direct_blockdev(void);
 int platform_align_blockdev(void);
index 6570c595aedcd02e2128aff54f27ebcf75118b9a..5be6f8cf1d8624fc3e0ac7c72b8f13acdc0d3a51 100644 (file)
@@ -125,15 +125,12 @@ retry:
        }
 
        if (!readonly && setblksize && (statb.st_mode & S_IFMT) == S_IFBLK) {
-               if (dio) {
-                       /* try to use the given explicit blocksize */
-                       (void)platform_set_blocksize(fd, path, statb.st_rdev,
-                                       setblksize, 0);
-               } else {
-                       /* given an explicit blocksize to use */
-                       if (platform_set_blocksize(fd, path, statb.st_rdev, setblksize, 1))
-                           exit(1);
-               }
+               /*
+                * Try to use the given explicit blocksize.  Failure to set the
+                * block size is only fatal for direct I/O.
+                */
+               platform_set_blocksize(fd, path, statb.st_rdev, setblksize,
+                               dio);
        }
 
        /*