From 0c1a65c0422f8322f52a3ada6c1296653c20cbcc Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Tue, 1 Aug 2023 14:16:36 +1000 Subject: [PATCH] LU-16972 tests: createmany sets xattr Add -x option to make createmany set an xattr named user.createmany when open+create the files. The xattr content is unique to avoid sharing on the backend filesystem. This could be useful for testing EA blocks and ea_inode feature. Test-Parameters: trivial Signed-off-by: Li Dongyang Change-Id: Ic2effe1f8cc60065dfda649d4ce003d7f10a135c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51827 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/tests/createmany.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/lustre/tests/createmany.c b/lustre/tests/createmany.c index d728701..dc9e38f 100644 --- a/lustre/tests/createmany.c +++ b/lustre/tests/createmany.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -49,14 +50,15 @@ static void usage(const char *prog) { - printf("usage: %s {-o [-k]|-m|-d|-l} [-u[]] " - "[-i mdt_index] [-t seconds] filenamefmt [[start] count]\n", + printf( + "usage: %s {-o [-k] [-x ]|-m|-d|-l} [-u[]] [-i mdt_index] [-t seconds] filenamefmt [[start] count]\n", prog); printf("\t-i\tMDT to create the directories on\n" "\t-l\tlink files to existing file\n" "\t-m\tmknod regular files (don't create OST objects)\n" "\t-o\topen+create files with path and printf format\n" "\t-k\t keep files open until all files are opened\n" + "\t-x\t set an xattr with length on the files\n" "\t-u\tunlink file/dir (with optional )\n"); printf("\t-d\tuse directories instead of regular files\n" "\t-t\tstop creating files after have elapsed\n"); @@ -97,8 +99,11 @@ int main(int argc, char **argv) bool do_setsize = false, do_chuid = false, do_chgid = false; bool do_chprj = false; bool do_rmdir = false; + bool do_xattr = false; int stripe_pattern = LMV_HASH_TYPE_FNV_1A_64; int stripe_offset = -1, stripe_count = 1; + size_t xattr_size = 0; + char *xattr_buf = NULL; char *filename, *progname; char *fmt = NULL, *fmt_unlink = NULL, *tgt = NULL; char *endp = NULL; @@ -127,7 +132,7 @@ int main(int argc, char **argv) else progname = argv[0]; - while ((c = getopt(argc, argv, "i:dG:l:kmor::S:t:u::U:")) != -1) { + while ((c = getopt(argc, argv, "i:dG:l:kmor::S:t:u::U:x:")) != -1) { switch (c) { case 'd': do_mkdir = true; @@ -179,6 +184,15 @@ int main(int argc, char **argv) do_chuid = true; uid = strtoul(optarg, NULL, 0); break; + case 'x': + do_xattr = true; + xattr_size = strtoul(optarg, &endp, 0); + if (*endp != '\0') { + fprintf(stderr, "invalid xattr size '%s'\n", + optarg); + return 1; + } + break; case '?': fprintf(stderr, "Unknown option '%c'\n", optopt); usage(progname); @@ -198,8 +212,8 @@ int main(int argc, char **argv) if (do_mkdir && do_unlink) do_rmdir = true; - if (!do_open && do_keep) { - fprintf(stderr, "error: can only use -k with -o\n"); + if (!do_open && (do_keep || do_xattr)) { + fprintf(stderr, "error: can only use -k|-x with -o\n"); usage(progname); } @@ -219,6 +233,14 @@ int main(int argc, char **argv) if (fmt_unlink != NULL) unlink_has_fmt_spec = strchr(fmt_unlink, '%') != NULL; + if (do_xattr) { + xattr_buf = malloc(xattr_size); + if (!xattr_buf) { + printf("malloc xattr buf error: %s\n", strerror(errno)); + return errno; + } + } + for (i = 0, start = last_t = now(), end += start; i < count && now() < end; i++, begin++) { double tmp; @@ -283,6 +305,18 @@ int main(int argc, char **argv) } } + if (do_xattr) { + strncpy(xattr_buf, filename, xattr_size); + rc = fsetxattr(fd, "user.createmany", xattr_buf, + xattr_size, 0); + if (rc < 0) { + printf("fsetxattr(%s) error: %s\n", + filename, strerror(errno)); + rc = errno; + break; + } + } + if (!do_keep) close(fd); else if (fd > last_fd) @@ -368,6 +402,9 @@ int main(int argc, char **argv) do_unlink ? do_mkdir ? "/rmdir" : "/unlink" : "", last_t - start, ((double)total / (last_t - start))); + if (xattr_buf) + free(xattr_buf); + if (!do_keep) return rc; -- 1.8.3.1