#include <time.h>
#include <unistd.h>
+#include <linux/lustre/lustre_user.h>
+#include <lustre/lustreapi.h>
+
static void usage(const char *prog)
{
printf("usage: %s {-o [-k]|-m|-d|-l<tgt>} [-u[<unlinkfmt>]] "
- "[-t seconds] filenamefmt [[start] count]\n", prog);
- printf("\t-l\tlink files to existing <tgt> file\n"
+ "[-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 <tgt> 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"
return filename;
}
-double now(void)
+static double now(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
{
bool do_open = false, do_keep = false, do_link = false;
bool do_unlink = false, do_mknod = false, do_mkdir = false;
+ bool do_rmdir = false;
+ int stripe_pattern = LMV_HASH_TYPE_FNV_1A_64;
+ int stripe_offset = -1, stripe_count = 1;
char *filename, *progname;
char *fmt = NULL, *fmt_unlink = NULL, *tgt = NULL;
char *endp = NULL;
else
progname = argv[0];
- while ((c = getopt(argc, argv, "dl:kmor::t:u::")) != -1) {
+ while ((c = getopt(argc, argv, "i:dl:kmor::t:u::")) != -1) {
switch (c) {
case 'd':
do_mkdir = true;
break;
+ case 'i':
+ stripe_offset = strtoul(optarg, &endp, 0);
+ if (*endp != '\0') {
+ fprintf(stderr, "invalid MDT index '%s'\n",
+ optarg);
+ return 1;
+ }
+ break;
case 'k':
do_keep = true;
break;
fprintf(stderr, "error: only one of -o, -m, -l, -d\n");
usage(progname);
}
+ if (do_mkdir && do_unlink)
+ do_rmdir = true;
if (!do_open && do_keep) {
fprintf(stderr, "error: can only use -k with -o\n");
for (i = 0, start = last_t = now(), end += start;
i < count && now() < end; i++, begin++) {
+ double tmp;
+
filename = get_file_name(fmt, begin, has_fmt_spec);
if (do_open) {
int fd = open(filename, O_CREAT|O_RDWR, 0644);
break;
}
} else if (do_mkdir) {
- rc = mkdir(filename, 0755);
- if (rc) {
- printf("mkdir(%s) error: %s\n",
- filename, strerror(errno));
- rc = errno;
- break;
+ if (stripe_offset != -1) {
+ rc = llapi_dir_create_pool(filename, 0755,
+ stripe_offset, stripe_count,
+ stripe_pattern, NULL);
+ if (rc) {
+ printf("llapi_dir_create_pool(%s) error: %s\n",
+ filename, strerror(-rc));
+ rc = errno;
+ break;
+ }
+ } else {
+ rc = mkdir(filename, 0755);
+ if (rc) {
+ printf("mkdir(%s) error: %s\n",
+ filename, strerror(errno));
+ rc = errno;
+ break;
+ }
}
} else if (do_mknod) {
rc = mknod(filename, S_IFREG | 0444, 0);
filename = get_file_name(fmt_unlink, begin,
unlink_has_fmt_spec);
- rc = do_mkdir ? rmdir(filename) : unlink(filename);
+ rc = do_rmdir ? rmdir(filename) : unlink(filename);
+ /* use rmdir if this is a directory */
+ if (!do_rmdir && rc && errno == EISDIR) {
+ do_rmdir = true;
+ rc = rmdir(filename);
+ }
if (rc) {
printf("unlink(%s) error: %s\n",
filename, strerror(errno));
}
}
- if ((i != 0 && (i % 10000) == 0) || now() - last_t >= 10.0) {
- double tmp = now();
-
+ tmp = now();
+ if (tmp - last_t >= 10.0 ||
+ (tmp - last_t > 2.0 && (i % 10000) == 0)) {
printf(" - %s%s %ld (time %.2f total %.2f last %.2f)"
"\n",
do_open ? do_keep ? "open/keep" : "open/close" :