[PATCH] fs: fsstress: make test more POSIX compliant in commit bacc849720ec4efda5a0a8a9ea6a0e93a1415541, malloc.h was removed and stdlib.h got used instead. However, it's not enough. The function memalign() is also obsolete (via man memalign) and we should use posix_memalign instead. Also if we keep memalign() function here, the program would probably hit segfault once it enters dwrite_t and dread_t. Besides the POSIX compliant fix, I also did a small fix to remove compling warnings. I tried to update this program output to tst_resm/tst_brkm style but failed, I got confused by some printf output. Signed-off-by: Caspar Zhang --- testcases/kernel/fs/fsstress/fsstress.c | 38 ++++++++++++++++++------------ 1 files changed, 23 insertions(+), 15 deletions(-) diff --git a/testcases/kernel/fs/fsstress/fsstress.c b/testcases/kernel/fs/fsstress/fsstress.c index e3b48ea..0e5fba2 100644 --- a/testcases/kernel/fs/fsstress/fsstress.c +++ b/testcases/kernel/fs/fsstress/fsstress.c @@ -1746,7 +1746,7 @@ void dread_f(int opno, long r) { __int64_t align; - char *buf; + char *buf=NULL; struct dioattr diob; int e; pathname_t f; @@ -1799,11 +1799,9 @@ dread_f(int opno, long r) return; } - if (no_xfs) { - diob.d_miniosz = stb.st_blksize; - diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */ - diob.d_mem = stb.st_blksize; - } + diob.d_miniosz = stb.st_blksize; + diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */ + diob.d_mem = stb.st_blksize; #ifndef NO_XFS else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) { if (v) @@ -1826,7 +1824,13 @@ dread_f(int opno, long r) len = align; else if (len > diob.d_maxiosz) len = diob.d_maxiosz; - buf = memalign(diob.d_mem, len); + if (posix_memalign((void **)buf, diob.d_mem, len) != 0) { + perror("posix_memalign"); + exit (1); + } else if (buf == NULL) { + fprintf(stderr, "buf remains NULL unexpectly\n"); + exit (1); + } e = read(fd, buf, len) < 0 ? errno : 0; free(buf); if (v) @@ -1840,7 +1844,7 @@ void dwrite_f(int opno, long r) { __int64_t align; - char *buf; + char *buf=NULL; struct dioattr diob; int e; pathname_t f; @@ -1882,11 +1886,9 @@ dwrite_f(int opno, long r) close(fd); return; } - if (no_xfs) { - diob.d_miniosz = stb.st_blksize; - diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */ - diob.d_mem = stb.st_blksize; - } + diob.d_miniosz = stb.st_blksize; + diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */ + diob.d_mem = stb.st_blksize; #ifndef NO_XFS else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) { if (v) @@ -1909,7 +1911,13 @@ dwrite_f(int opno, long r) len = align; else if (len > diob.d_maxiosz) len = diob.d_maxiosz; - buf = memalign(diob.d_mem, len); + if (posix_memalign((void **)buf, diob.d_mem, len) != 0) { + perror("posix_memalign"); + exit (1); + } else if (buf == NULL) { + fprintf(stderr, "buf remains NULL unexpectly\n"); + exit (1); + } off %= maxfsize; lseek64(fd, off, SEEK_SET); memset(buf, nameseq & 0xff, len); @@ -2650,4 +2658,4 @@ write_f(int opno, long r) procid, opno, f.path, (long long)off, (long int)len, e); free_pathname(&f); close(fd); -} \ No newline at end of file +} -- 1.7.4.1 -- Quality Engineer (Kernel) in Red Hat Software (Beijing) Co., R&D Branch http://www.cn.redhat.com/ TEL: +86-10-62608150