aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2023-12-11 17:37:35 +0100
committerCarlos Maiolino <cem@kernel.org>2023-12-18 14:57:49 +0100
commita3106f3292ad49301437cff111a6a945e5305fe4 (patch)
treed398d4f72cb85b1ea37dfa25c43b51398e47b130
parent8798d4a6a73caea5fb8d95ae87303d3d39c68abe (diff)
downloadxfsprogs-dev-a3106f3292ad49301437cff111a6a945e5305fe4.tar.gz
libfrog: make platform_set_blocksize exit on fatal failure
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>
-rw-r--r--libfrog/linux.c27
-rw-r--r--libfrog/platform.h4
-rw-r--r--libxfs/init.c15
3 files changed, 23 insertions, 23 deletions
diff --git a/libfrog/linux.c b/libfrog/linux.c
index 2e4fd316e7..46a5ff39e2 100644
--- a/libfrog/linux.c
+++ b/libfrog/linux.c
@@ -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;
}
/*
diff --git a/libfrog/platform.h b/libfrog/platform.h
index e3e6b7c71b..20f9bdf5ce 100644
--- a/libfrog/platform.h
+++ b/libfrog/platform.h
@@ -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);
diff --git a/libxfs/init.c b/libxfs/init.c
index 6570c595ae..5be6f8cf1d 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -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);
}
/*