fsstress currently does not support fadvise operation, in order to enrich the operation of fsstress, add posix_fadvise operation. Signed-off-by: Chen Long <chenlongcl.chen@xxxxxxxxxx> --- ltp/fsstress.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 5f3126e6..7f81817f 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -85,6 +85,12 @@ static int renameat2(int dfd1, const char *path1, #define FILELEN_MAX (32*4096) typedef enum { + OP_FADV_NORMAL, + OP_FADV_SEQUENTIAL, + OP_FADV_RANDOM, + OP_FADV_NOREUSE, + OP_FADV_WILLNEED, + OP_FADV_DONTNEED, OP_AFSYNC, OP_ALLOCSP, OP_AREAD, @@ -230,6 +236,12 @@ void creat_f(opnum_t, long); void deduperange_f(opnum_t, long); void dread_f(opnum_t, long); void dwrite_f(opnum_t, long); +void fadv_normal_f(opnum_t, long); +void fadv_sequential_f(opnum_t, long); +void fadv_random_f(opnum_t, long); +void fadv_noreuse_f(opnum_t, long); +void fadv_willneed_f(opnum_t, long); +void fadv_dontneed_f(opnum_t, long); void fallocate_f(opnum_t, long); void fdatasync_f(opnum_t, long); void fiemap_f(opnum_t, long); @@ -295,6 +307,12 @@ struct opdesc ops[OP_LAST] = { [OP_DEDUPERANGE] = {"deduperange", deduperange_f, 4, 1 }, [OP_DREAD] = {"dread", dread_f, 4, 0 }, [OP_DWRITE] = {"dwrite", dwrite_f, 4, 1 }, + [OP_FADV_NORMAL] = {"fadv_normal", fadv_normal_f, 1, 0 }, + [OP_FADV_SEQUENTIAL] = {"fadv_sequential", fadv_sequential_f, 1, 0 }, + [OP_FADV_RANDOM] = {"fadv_random", fadv_random_f, 1, 0 }, + [OP_FADV_NOREUSE] = {"fadv_noreuse", fadv_noreuse_f, 1, 0 }, + [OP_FADV_WILLNEED] = {"fadv_willneed", fadv_willneed_f, 1, 0 }, + [OP_FADV_DONTNEED] = {"fadv_dontneed", fadv_dontneed_f, 1, 0 }, [OP_FALLOCATE] = {"fallocate", fallocate_f, 1, 1 }, [OP_FDATASYNC] = {"fdatasync", fdatasync_f, 1, 1 }, [OP_FIEMAP] = {"fiemap", fiemap_f, 1, 1 }, @@ -5337,3 +5355,91 @@ xattr_flag_to_string(int flag) return "replace"; return "none"; } + +void +do_posix_fadvise(opnum_t opno, long r, int advice) +{ + int fd; + size_t len; + off64_t off; + int e; + pathname_t f; + int64_t lr; + struct stat64 stb; + int v; + char st[1024]; + + + init_pathname(&f); + if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) { + if (v) + printf("%d/%lld: fadvise - no filename\n", procid, opno); + free_pathname(&f); + return; + } + fd = open_path(&f, O_RDWR); + e = fd < 0 ? errno : 0; + check_cwd(); + if (fd < 0) { + if (v) + printf("%d/%lld: fadvise - open %s failed %d\n", + procid, opno, f.path, e); + free_pathname(&f); + return; + } + if (fstat64(fd, &stb) < 0) { + if (v) + printf("%d/%lld: fadvise - fstat64 %s failed %d\n", + procid, opno, f.path, errno); + free_pathname(&f); + close(fd); + return; + } + inode_info(st, sizeof(st), &stb, v); + lr = ((int64_t)random() << 32) + random(); + off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE)); + off %= maxfsize; + len = (random() % FILELEN_MAX) + 1; + e = posix_fadvise(fd, off, len, advice); + if (v) + printf("%d/%lld: fadvise %s%s %lld %d %d\n", procid, opno, f.path, + st, (long long)off, advice, e); + free_pathname(&f); + close(fd); +} + +void +fadv_normal_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_NORMAL); +} + +void +fadv_sequential_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_SEQUENTIAL); +} + +void +fadv_random_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_RANDOM); +} + +void +fadv_noreuse_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_NOREUSE); +} + +void +fadv_willneed_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_WILLNEED); +} + +void +fadv_dontneed_f(opnum_t opno, long r) +{ + do_posix_fadvise(opno, r, POSIX_FADV_DONTNEED); +} -- 2.17.1