[LTP] [PATCH 2/3] stat04+lstat03: fix bad blocksize mkfs option for xfs

Zorro Lang via ltp
2024-12-02T13:33:01Z

Not all filesystems use "-b 1024" to set its blocksize. XFS uses
"-b size=1024", so this test fails as "unknown option -b 1024" on
xfs.

Signed-off-by: Zorro Lang <zlang@kernel.org>
---
testcases/kernel/syscalls/lstat/lstat03.c | 8 ++++++--
testcases/kernel/syscalls/stat/stat04.c | 8 ++++++--
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/lstat/lstat03.c b/testcases/kernel/syscalls/lstat/lstat03.c
index d48af180b..675fb56f4 100644
--- a/testcases/kernel/syscalls/lstat/lstat03.c
+++ b/testcases/kernel/syscalls/lstat/lstat03.c
@@ -44,8 +44,9 @@ static void run(void)

static void setup(void)
{
+ char *opt_name="-b";
char opt_bsize[32];
- const char *const fs_opts[] = {opt_bsize, NULL};
+ const char *const fs_opts[] = {opt_name, opt_bsize, NULL};
struct stat sb;
int pagesize;
int fd;
@@ -54,7 +55,10 @@ static void setup(void)
SAFE_STAT(".", &sb);
pagesize = sb.st_blksize == 4096 ? 1024 : 4096;

- snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", pagesize);
+ if (strcmp(tst_device->fs_type, "xfs") == 0)
+ snprintf(opt_bsize, sizeof(opt_bsize), "size=%i", pagesize);
+ else
+ snprintf(opt_bsize, sizeof(opt_bsize), "%i", pagesize);
SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);

diff --git a/testcases/kernel/syscalls/stat/stat04.c b/testcases/kernel/syscalls/stat/stat04.c
index 05ace606a..2a17cc7d7 100644
--- a/testcases/kernel/syscalls/stat/stat04.c
+++ b/testcases/kernel/syscalls/stat/stat04.c
@@ -43,8 +43,9 @@ static void run(void)

static void setup(void)
{
+ char *opt_name="-b";
char opt_bsize[32];
- const char *const fs_opts[] = {opt_bsize, NULL};
+ const char *const fs_opts[] = {opt_name, opt_bsize, NULL};
struct stat sb;
int pagesize;
int fd;
@@ -56,7 +57,10 @@ static void setup(void)
SAFE_STAT(".", &sb);
pagesize = sb.st_blksize == 4096 ? 1024 : 4096;

- snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", pagesize);
+ if (strcmp(tst_device->fs_type, "xfs") == 0)
+ snprintf(opt_bsize, sizeof(opt_bsize), "size=%i", pagesize);
+ else
+ snprintf(opt_bsize, sizeof(opt_bsize), "%i", pagesize);
SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);

--
2.45.2