1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
13 #ifdef HAVE_ATTR_ATTRIBUTES_H
14 #include <attr/attributes.h>
16 #ifdef HAVE_LINUX_FIEMAP_H
17 #include <linux/fiemap.h>
19 #ifndef HAVE_ATTR_LIST
20 #define attr_list(path, buf, size, flags, cursor) (errno = -ENOSYS, -1)
22 #ifdef HAVE_SYS_PRCTL_H
23 #include <sys/prctl.h>
29 #include <sys/syscall.h>
30 #include <sys/xattr.h>
32 #ifndef FS_IOC_GETFLAGS
33 #define FS_IOC_GETFLAGS _IOR('f', 1, long)
35 #ifndef FS_IOC_SETFLAGS
36 #define FS_IOC_SETFLAGS _IOW('f', 2, long)
40 #define XFS_ERRTAG_MAX 17
41 #define XFS_IDMODULO_MAX 31 /* user/group IDs (1 << x) */
42 #define XFS_PROJIDMODULO_MAX 16 /* project IDs (1 << x) */
47 #define FILELEN_MAX (32*4096)
103 typedef void (*opfnc_t)(int, long);
105 typedef struct opdesc {
113 typedef struct fent {
119 typedef struct flist {
126 typedef struct pathname {
136 struct print_string {
143 #define FT_DIRm (1 << FT_DIR)
145 #define FT_REGm (1 << FT_REG)
147 #define FT_SYMm (1 << FT_SYM)
149 #define FT_DEVm (1 << FT_DEV)
151 #define FT_RTFm (1 << FT_RTF)
153 #define FT_ANYm ((1 << FT_nft) - 1)
154 #define FT_REGFILE (FT_REGm | FT_RTFm)
155 #define FT_NOTDIR (FT_ANYm & ~FT_DIRm)
157 #define FLIST_SLOT_INCR 16
160 #define MAXFSIZE ((1ULL << 63) - 1ULL)
161 #define MAXFSIZE32 ((1ULL << 40) - 1ULL)
163 #define XATTR_NAME_BUF_SIZE 18
165 void afsync_f(int, long);
166 void allocsp_f(int, long);
167 void aread_f(int, long);
168 void attr_remove_f(int, long);
169 void attr_set_f(int, long);
170 void awrite_f(int, long);
171 void bulkstat_f(int, long);
172 void bulkstat1_f(int, long);
173 void chown_f(int, long);
174 void clonerange_f(int, long);
175 void copyrange_f(int, long);
176 void creat_f(int, long);
177 void deduperange_f(int, long);
178 void dread_f(int, long);
179 void dwrite_f(int, long);
180 void fallocate_f(int, long);
181 void fdatasync_f(int, long);
182 void fiemap_f(int, long);
183 void freesp_f(int, long);
184 void fsync_f(int, long);
185 char *gen_random_string(int);
186 void getattr_f(int, long);
187 void getdents_f(int, long);
188 void getfattr_f(int, long);
189 void link_f(int, long);
190 void mkdir_f(int, long);
191 void mknod_f(int, long);
192 void mread_f(int, long);
193 void mwrite_f(int, long);
194 void punch_f(int, long);
195 void zero_f(int, long);
196 void collapse_f(int, long);
197 void insert_f(int, long);
198 void read_f(int, long);
199 void readlink_f(int, long);
200 void readv_f(int, long);
201 void rename_f(int, long);
202 void resvsp_f(int, long);
203 void rmdir_f(int, long);
204 void setattr_f(int, long);
205 void setfattr_f(int, long);
206 void setxattr_f(int, long);
207 void splice_f(int, long);
208 void stat_f(int, long);
209 void symlink_f(int, long);
210 void sync_f(int, long);
211 void truncate_f(int, long);
212 void unlink_f(int, long);
213 void unresvsp_f(int, long);
214 void write_f(int, long);
215 void writev_f(int, long);
216 char *xattr_flag_to_string(int);
219 /* { OP_ENUM, "name", function, freq, iswrite }, */
220 { OP_AFSYNC, "afsync", afsync_f, 0, 1 },
221 { OP_ALLOCSP, "allocsp", allocsp_f, 1, 1 },
222 { OP_AREAD, "aread", aread_f, 1, 0 },
223 { OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1 },
224 { OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1 },
225 { OP_AWRITE, "awrite", awrite_f, 1, 1 },
226 { OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0 },
227 { OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0 },
228 { OP_CHOWN, "chown", chown_f, 3, 1 },
229 { OP_CLONERANGE, "clonerange", clonerange_f, 4, 1 },
230 { OP_COPYRANGE, "copyrange", copyrange_f, 4, 1 },
231 { OP_CREAT, "creat", creat_f, 4, 1 },
232 { OP_DEDUPERANGE, "deduperange", deduperange_f, 4, 1},
233 { OP_DREAD, "dread", dread_f, 4, 0 },
234 { OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
235 { OP_FALLOCATE, "fallocate", fallocate_f, 1, 1 },
236 { OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
237 { OP_FIEMAP, "fiemap", fiemap_f, 1, 1 },
238 { OP_FREESP, "freesp", freesp_f, 1, 1 },
239 { OP_FSYNC, "fsync", fsync_f, 1, 1 },
240 { OP_GETATTR, "getattr", getattr_f, 1, 0 },
241 { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
242 /* get extended attribute */
243 { OP_GETFATTR, "getfattr", getfattr_f, 1, 0 },
244 { OP_LINK, "link", link_f, 1, 1 },
245 { OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
246 { OP_MKNOD, "mknod", mknod_f, 2, 1 },
247 { OP_MREAD, "mread", mread_f, 2, 0 },
248 { OP_MWRITE, "mwrite", mwrite_f, 2, 1 },
249 { OP_PUNCH, "punch", punch_f, 1, 1 },
250 { OP_ZERO, "zero", zero_f, 1, 1 },
251 { OP_COLLAPSE, "collapse", collapse_f, 1, 1 },
252 { OP_INSERT, "insert", insert_f, 1, 1 },
253 { OP_READ, "read", read_f, 1, 0 },
254 { OP_READLINK, "readlink", readlink_f, 1, 0 },
255 { OP_READV, "readv", readv_f, 1, 0 },
256 { OP_RENAME, "rename", rename_f, 2, 1 },
257 { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
258 { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
259 /* set attribute flag (FS_IOC_SETFLAGS ioctl) */
260 { OP_SETATTR, "setattr", setattr_f, 0, 1 },
261 /* set extended attribute */
262 { OP_SETFATTR, "setfattr", setfattr_f, 2, 1 },
263 /* set project id (XFS_IOC_FSSETXATTR ioctl) */
264 { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
265 { OP_SPLICE, "splice", splice_f, 1, 1 },
266 { OP_STAT, "stat", stat_f, 1, 0 },
267 { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
268 { OP_SYNC, "sync", sync_f, 1, 1 },
269 { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
270 { OP_UNLINK, "unlink", unlink_f, 1, 1 },
271 { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
272 { OP_WRITE, "write", write_f, 4, 1 },
273 { OP_WRITEV, "writev", writev_f, 4, 1 },
276 flist_t flist[FT_nft] = {
289 xfs_fsop_geom_t geom;
300 unsigned int idmodulo = XFS_IDMODULO_MAX;
301 unsigned int attr_mask = ~0;
304 unsigned long seed = 0;
308 int verifiable_log = 0;
309 sig_atomic_t should_stop = 0;
310 sigjmp_buf *sigbus_jmp = NULL;
311 char *execute_cmd = NULL;
312 int execute_freq = 1;
313 struct print_string flag_str = {0};
315 void add_to_flist(int, int, int, int);
316 void append_pathname(pathname_t *, char *);
317 int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
318 int attr_remove_path(pathname_t *, const char *, int);
319 int attr_set_path(pathname_t *, const char *, const char *, const int, int);
320 void check_cwd(void);
321 void cleanup_flist(void);
322 int creat_path(pathname_t *, mode_t);
323 void dcache_enter(int, int);
324 void dcache_init(void);
325 fent_t *dcache_lookup(int);
326 void dcache_purge(int);
327 void del_from_flist(int, int);
328 int dirid_to_name(char *, int);
330 int fent_to_name(pathname_t *, flist_t *, fent_t *);
331 void fix_parent(int, int);
332 void free_pathname(pathname_t *);
333 int generate_fname(fent_t *, int, pathname_t *, int *, int *);
334 int generate_xattr_name(int, char *, int);
335 int get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
336 void init_pathname(pathname_t *);
337 int lchown_path(pathname_t *, uid_t, gid_t);
338 int link_path(pathname_t *, pathname_t *);
339 int lstat64_path(pathname_t *, struct stat64 *);
340 void make_freq_table(void);
341 int mkdir_path(pathname_t *, mode_t);
342 int mknod_path(pathname_t *, mode_t, dev_t);
343 void namerandpad(int, char *, int);
344 int open_file_or_dir(pathname_t *, int);
345 int open_path(pathname_t *, int);
346 DIR *opendir_path(pathname_t *);
347 void process_freq(char *);
348 int readlink_path(pathname_t *, char *, size_t);
349 int rename_path(pathname_t *, pathname_t *);
350 int rmdir_path(pathname_t *);
351 void separate_pathname(pathname_t *, char *, pathname_t *);
352 void show_ops(int, char *);
353 int stat64_path(pathname_t *, struct stat64 *);
354 int symlink_path(const char *, pathname_t *);
355 int truncate64_path(pathname_t *, off64_t);
356 int unlink_path(pathname_t *);
358 void write_freq(void);
359 void zero_freq(void);
361 void sg_handler(int signum)
369 * Only handle SIGBUS when mmap write to a hole and no
370 * block can be allocated due to ENOSPC, abort otherwise.
373 siglongjmp(*sigbus_jmp, -1);
375 printf("Unknown SIGBUS is caught, Abort!\n");
378 /* should not reach here */
385 int main(int argc, char **argv)
389 char *dirname = NULL;
390 char *logname = NULL;
391 char rpath[PATH_MAX];
400 xfs_error_injection_t err_inj;
401 struct sigaction action;
403 const char *allopts = "cd:e:f:i:l:m:M:n:o:p:rs:S:vVwx:X:zH";
405 errrange = errtag = 0;
407 nops = sizeof(ops) / sizeof(ops[0]);
408 ops_end = &ops[nops];
410 while ((c = getopt(argc, argv, allopts)) != -1) {
419 sscanf(optarg, "%d", &errtag);
423 } else if (errtag == 0)
425 if (errtag >= XFS_ERRTAG_MAX) {
427 "error tag %d too large (max %d)\n",
428 errtag, XFS_ERRTAG_MAX - 1);
433 process_freq(optarg);
436 ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
437 ilist[ilistlen - 1] = strtol(optarg, &p, 16);
440 idmodulo = strtoul(optarg, NULL, 0);
441 if (idmodulo > XFS_IDMODULO_MAX) {
443 "chown modulo %d too big (max %d)\n",
444 idmodulo, XFS_IDMODULO_MAX);
449 loops = atoi(optarg);
452 operations = atoi(optarg);
459 nproc = atoi(optarg);
465 seed = strtoul(optarg, NULL, 0);
474 execute_cmd = optarg;
480 attr_mask = strtoul(optarg, NULL, 0);
484 if (optarg[0] == 'c')
495 execute_freq = strtoul(optarg, NULL, 0);
498 fprintf(stderr, "%s - invalid parameters\n",
508 /* no directory specified */
509 if (!nousage) usage();
513 (void)mkdir(dirname, 0777);
514 if (logname && logname[0] != '/') {
515 if (!getcwd(rpath, sizeof(rpath))){
516 perror("getcwd failed");
522 if (chdir(dirname) < 0) {
527 char path[PATH_MAX + NAME_MAX + 1];
528 snprintf(path, sizeof(path), "%s/%s", rpath, logname);
529 if (freopen(path, "a", stdout) == NULL) {
530 perror("freopen logfile failed");
534 sprintf(buf, "fss%x", (unsigned int)getpid());
535 fd = creat(buf, 0666);
536 if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
537 maxfsize = (off64_t)MAXFSIZE32;
539 maxfsize = (off64_t)MAXFSIZE;
544 gettimeofday(&t, (void *)NULL);
545 seed = (int)t.tv_sec ^ (int)t.tv_usec;
546 printf("seed = %ld\n", seed);
548 i = xfsctl(buf, fd, XFS_IOC_FSGEOMETRY, &geom);
549 if (i >= 0 && geom.rtblocks)
550 rtpct = MIN(MAX(geom.rtblocks * 100 /
551 (geom.rtblocks + geom.datablocks), 1), 99);
560 for (i = 0; i < j; i++)
563 errtag = (random() % (XFS_ERRTAG_MAX-1)) + 1;
569 for (i = 0; i < j; i++)
572 errtag += (random() % (XFS_ERRTAG_MAX - errtag));
574 printf("Injecting failure on tag #%d\n", errtag);
575 err_inj.errtag = errtag;
577 srval = xfsctl(buf, fd, XFS_IOC_ERROR_INJECTION, &err_inj);
579 perror("fsstress - XFS_SYSSGI error injection call");
588 action.sa_handler = sg_handler;
589 sigemptyset(&action.sa_mask);
591 if (sigaction(SIGTERM, &action, 0)) {
592 perror("sigaction failed");
596 for (i = 0; i < nproc; i++) {
598 sigemptyset(&action.sa_mask);
599 action.sa_handler = SIG_DFL;
600 if (sigaction(SIGTERM, &action, 0))
602 action.sa_handler = sg_handler;
603 if (sigaction(SIGBUS, &action, 0))
605 #ifdef HAVE_SYS_PRCTL_H
606 prctl(PR_SET_PDEATHSIG, SIGKILL);
607 if (getppid() == 1) /* parent died already? */
611 char path[PATH_MAX + NAME_MAX + 2 + 11];
612 snprintf(path, sizeof(path), "%s/%s.%d",
614 if (freopen(path, "a", stdout) == NULL) {
615 perror("freopen logfile failed");
621 if (io_setup(128, &io_ctx) != 0) {
622 fprintf(stderr, "io_setup failed");
626 for (i = 0; !loops || (i < loops); i++)
629 if(io_destroy(io_ctx) != 0) {
630 fprintf(stderr, "io_destroy failed");
640 while (wait(&stat) > 0 && !should_stop) {
643 action.sa_flags = SA_RESTART;
644 sigaction(SIGTERM, &action, 0);
645 kill(-getpid(), SIGTERM);
646 while (wait(&stat) > 0)
652 srval = xfsctl(buf, fd, XFS_IOC_ERROR_CLEARALL, &err_inj);
654 fprintf(stderr, "Bad ej clear on %s fd=%d (%d).\n",
656 perror("xfsctl(XFS_IOC_ERROR_CLEARALL)");
669 add_string(struct print_string *str, const char *add)
671 int len = strlen(add);
676 if (len > (str->max - 1) - str->len) {
677 str->len = str->max - 1;
681 memcpy(str->buffer + str->len, add, len);
683 str->buffer[str->len] = '\0';
689 translate_flags(int flags, const char *delim,
690 const struct print_flags *flag_array)
692 int i, mask, first = 1;
695 if (!flag_str.buffer) {
696 flag_str.buffer = malloc(4096);
700 if (!flag_str.buffer)
703 flag_str.buffer[0] = '\0';
705 for (i = 0; flag_array[i].name && flags; i++) {
706 mask = flag_array[i].mask;
707 if ((flags & mask) != mask)
710 add = flag_array[i].name;
713 add_string(&flag_str, delim);
716 add_string(&flag_str, add);
719 /* Check whether there are any leftover flags. */
725 add_string(&flag_str, delim);
727 ret = snprintf(number, 11, "0x%x", flags) > 0;
728 if (ret > 0 && ret <= 11)
729 add_string(&flag_str, number);
732 return flag_str.buffer;
736 add_to_flist(int ft, int id, int parent, int xattr_counter)
742 if (ftp->nfiles == ftp->nslots) {
743 ftp->nslots += FLIST_SLOT_INCR;
744 ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
746 fep = &ftp->fents[ftp->nfiles++];
748 fep->parent = parent;
749 fep->xattr_counter = xattr_counter;
753 append_pathname(pathname_t *name, char *str)
759 /* attempting to append to a dir a zero length path */
760 if (len && *str == '/' && name->len == 0) {
761 fprintf(stderr, "fsstress: append_pathname failure\n");
762 assert(chdir(homedir) == 0);
767 name->path = realloc(name->path, name->len + 1 + len);
768 strcpy(&name->path[name->len], str);
773 attr_list_path(pathname_t *name,
775 const int buffersize,
777 attrlist_cursor_t *cursor)
779 char buf[NAME_MAX + 1];
783 if (flags != ATTR_DONTFOLLOW) {
788 rval = attr_list(name->path, buffer, buffersize, flags, cursor);
789 if (rval >= 0 || errno != ENAMETOOLONG)
791 separate_pathname(name, buf, &newname);
792 if (chdir(buf) == 0) {
793 rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
794 assert(chdir("..") == 0);
796 free_pathname(&newname);
801 attr_remove_path(pathname_t *name, const char *attrname, int flags)
803 char buf[NAME_MAX + 1];
807 rval = attr_remove(name->path, attrname, flags);
808 if (rval >= 0 || errno != ENAMETOOLONG)
810 separate_pathname(name, buf, &newname);
811 if (chdir(buf) == 0) {
812 rval = attr_remove_path(&newname, attrname, flags);
813 assert(chdir("..") == 0);
815 free_pathname(&newname);
820 attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
821 const int valuelength, int flags)
823 char buf[NAME_MAX + 1];
827 rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
828 if (rval >= 0 || errno != ENAMETOOLONG)
830 separate_pathname(name, buf, &newname);
831 if (chdir(buf) == 0) {
832 rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
834 assert(chdir("..") == 0);
836 free_pathname(&newname);
844 struct stat64 statbuf;
846 if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
848 assert(chdir(homedir) == 0);
849 fprintf(stderr, "fsstress: check_cwd failure\n");
856 * go thru flist and release all entries
858 * NOTE: this function shouldn't be called until the end of a process
866 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
875 creat_path(pathname_t *name, mode_t mode)
877 char buf[NAME_MAX + 1];
881 rval = creat(name->path, mode);
882 if (rval >= 0 || errno != ENAMETOOLONG)
884 separate_pathname(name, buf, &newname);
885 if (chdir(buf) == 0) {
886 rval = creat_path(&newname, mode);
887 assert(chdir("..") == 0);
889 free_pathname(&newname);
894 dcache_enter(int dirid, int slot)
896 dcache[dirid % NDCACHE] = slot;
904 for (i = 0; i < NDCACHE; i++)
909 dcache_lookup(int dirid)
914 i = dcache[dirid % NDCACHE];
915 if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
921 dcache_purge(int dirid)
925 dcp = &dcache[dirid % NDCACHE];
926 if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
931 * Delete the item from the list by
932 * moving last entry over the deleted one;
933 * unless deleted entry is the last one.
934 * Input: which file list array and which slot in array
937 del_from_flist(int ft, int slot)
943 dcache_purge(ftp->fents[slot].id);
944 if (slot != ftp->nfiles - 1) {
946 dcache_purge(ftp->fents[ftp->nfiles - 1].id);
947 ftp->fents[slot] = ftp->fents[--ftp->nfiles];
953 dirid_to_fent(int dirid)
959 if ((fep = dcache_lookup(dirid)))
961 flp = &flist[FT_DIR];
962 for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
963 if (fep->id == dirid) {
964 dcache_enter(dirid, fep - flp->fents);
974 struct stat64 statbuf;
982 dividend = (operations + execute_freq) / (execute_freq + 1);
983 sprintf(buf, "p%x", procid);
984 (void)mkdir(buf, 0777);
985 if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
989 top_ino = statbuf.st_ino;
990 homedir = getcwd(NULL, 0);
992 perror("getcwd failed");
999 for (opno = 0; opno < operations; opno++) {
1000 if (execute_cmd && opno && opno % dividend == 0) {
1002 printf("%d: execute command %s\n", opno,
1004 rval = system(execute_cmd);
1006 fprintf(stderr, "execute command failed with "
1009 p = &ops[freq_table[random() % freq_table_size]];
1010 p->func(opno, random());
1012 * test for forced shutdown by stat'ing the test
1013 * directory. If this stat returns EIO, assume
1014 * the forced shutdown happened.
1016 if (errtag != 0 && opno % 100 == 0) {
1017 rval = stat64(".", &statbuf);
1019 fprintf(stderr, "Detected EIO\n");
1025 assert(chdir("..") == 0);
1030 sprintf(cmd, "rm -rf %s", buf);
1033 perror("cleaning up");
1039 * build up a pathname going thru the file entry and all
1040 * its parent entries
1041 * Return 0 on error, 1 on success;
1044 fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
1046 char buf[NAME_MAX + 1];
1054 /* build up parent directory name */
1055 if (fep->parent != -1) {
1056 pfep = dirid_to_fent(fep->parent);
1059 fprintf(stderr, "%d: fent-id = %d: can't find parent id: %d\n",
1060 procid, fep->id, fep->parent);
1065 e = fent_to_name(name, &flist[FT_DIR], pfep);
1068 append_pathname(name, "/");
1071 i = sprintf(buf, "%c%x", flp->tag, fep->id);
1072 namerandpad(fep->id, buf, i);
1073 append_pathname(name, buf);
1078 fix_parent(int oldid, int newid)
1085 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1086 for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
1087 if (fep->parent == oldid)
1088 fep->parent = newid;
1094 free_pathname(pathname_t *name)
1104 * Generate a filename of type ft.
1105 * If we have a fep which should be a directory then use it
1106 * as the parent path for this new filename i.e. prepend with it.
1109 generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
1111 char buf[NAME_MAX + 1];
1120 len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
1121 namerandpad(id, buf, len);
1123 /* prepend fep parent dir-name to it */
1125 e = fent_to_name(name, &flist[FT_DIR], fep);
1128 append_pathname(name, "/");
1130 append_pathname(name, buf);
1134 for (j = 0; !*v && j < ilistlen; j++) {
1135 if (ilist[j] == id) {
1143 int generate_xattr_name(int xattr_num, char *buffer, int buflen)
1147 ret = snprintf(buffer, buflen, "user.x%d", xattr_num);
1157 * Input: "which" to choose the file-types eg. non-directory
1158 * Input: "r" to choose which file
1159 * Output: file-list, file-entry, name for the chosen file.
1160 * Output: verbose if chosen file is on the ilist.
1163 get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
1166 int totalsum = 0; /* total number of matching files */
1167 int partialsum = 0; /* partial sum of matching files */
1173 int e = 1; /* success */
1176 * go thru flist and add up number of files for each
1177 * category that matches with <which>.
1179 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1180 if (which & (1 << i))
1181 totalsum += flp->nfiles;
1183 if (totalsum == 0) {
1193 * Now we have possible matches between 0..totalsum-1.
1194 * And we use r to help us choose which one we want,
1195 * which when bounded by totalsum becomes x.
1197 x = (int)(r % totalsum);
1198 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1199 if (which & (1 << i)) {
1200 if (x < partialsum + flp->nfiles) {
1202 /* found the matching file entry */
1203 fep = &flp->fents[x - partialsum];
1205 /* fill-in what we were asked for */
1207 e = fent_to_name(name, flp, fep);
1210 fprintf(stderr, "%d: failed to get path for entry:"
1211 " id=%d,parent=%d\n",
1212 procid, fep->id, fep->parent);
1221 /* turn on verbose if its an ilisted file */
1223 for (j = 0; !*v && j < ilistlen; j++) {
1224 if (ilist[j] == fep->id) {
1231 partialsum += flp->nfiles;
1235 fprintf(stderr, "fsstress: get_fname failure\n");
1242 init_pathname(pathname_t *name)
1249 lchown_path(pathname_t *name, uid_t owner, gid_t group)
1251 char buf[NAME_MAX + 1];
1255 rval = lchown(name->path, owner, group);
1256 if (rval >= 0 || errno != ENAMETOOLONG)
1258 separate_pathname(name, buf, &newname);
1259 if (chdir(buf) == 0) {
1260 rval = lchown_path(&newname, owner, group);
1261 assert(chdir("..") == 0);
1263 free_pathname(&newname);
1268 link_path(pathname_t *name1, pathname_t *name2)
1270 char buf1[NAME_MAX + 1];
1271 char buf2[NAME_MAX + 1];
1273 pathname_t newname1;
1274 pathname_t newname2;
1277 rval = link(name1->path, name2->path);
1278 if (rval >= 0 || errno != ENAMETOOLONG)
1280 separate_pathname(name1, buf1, &newname1);
1281 separate_pathname(name2, buf2, &newname2);
1282 if (strcmp(buf1, buf2) == 0) {
1283 if (chdir(buf1) == 0) {
1284 rval = link_path(&newname1, &newname2);
1285 assert(chdir("..") == 0);
1288 if (strcmp(buf1, "..") == 0)
1290 else if (strcmp(buf2, "..") == 0)
1292 else if (strlen(buf1) == 0)
1294 else if (strlen(buf2) == 0)
1297 down1 = MAX(newname1.len, 3 + name2->len) <=
1298 MAX(3 + name1->len, newname2.len);
1300 free_pathname(&newname2);
1301 append_pathname(&newname2, "../");
1302 append_pathname(&newname2, name2->path);
1303 if (chdir(buf1) == 0) {
1304 rval = link_path(&newname1, &newname2);
1305 assert(chdir("..") == 0);
1308 free_pathname(&newname1);
1309 append_pathname(&newname1, "../");
1310 append_pathname(&newname1, name1->path);
1311 if (chdir(buf2) == 0) {
1312 rval = link_path(&newname1, &newname2);
1313 assert(chdir("..") == 0);
1317 free_pathname(&newname1);
1318 free_pathname(&newname2);
1323 lstat64_path(pathname_t *name, struct stat64 *sbuf)
1325 char buf[NAME_MAX + 1];
1329 rval = lstat64(name->path, sbuf);
1330 if (rval >= 0 || errno != ENAMETOOLONG)
1332 separate_pathname(name, buf, &newname);
1333 if (chdir(buf) == 0) {
1334 rval = lstat64_path(&newname, sbuf);
1335 assert(chdir("..") == 0);
1337 free_pathname(&newname);
1342 make_freq_table(void)
1348 for (p = ops, f = 0; p < ops_end; p++)
1350 freq_table = malloc(f * sizeof(*freq_table));
1351 freq_table_size = f;
1352 for (p = ops, i = 0; p < ops_end; p++) {
1353 for (f = 0; f < p->freq; f++, i++)
1354 freq_table[i] = p->op;
1359 mkdir_path(pathname_t *name, mode_t mode)
1361 char buf[NAME_MAX + 1];
1365 rval = mkdir(name->path, mode);
1366 if (rval >= 0 || errno != ENAMETOOLONG)
1368 separate_pathname(name, buf, &newname);
1369 if (chdir(buf) == 0) {
1370 rval = mkdir_path(&newname, mode);
1371 assert(chdir("..") == 0);
1373 free_pathname(&newname);
1378 mknod_path(pathname_t *name, mode_t mode, dev_t dev)
1380 char buf[NAME_MAX + 1];
1384 rval = mknod(name->path, mode, dev);
1385 if (rval >= 0 || errno != ENAMETOOLONG)
1387 separate_pathname(name, buf, &newname);
1388 if (chdir(buf) == 0) {
1389 rval = mknod_path(&newname, mode, dev);
1390 assert(chdir("..") == 0);
1392 free_pathname(&newname);
1397 namerandpad(int id, char *buf, int i)
1400 static int buckets[] =
1401 { 2, 4, 8, 16, 32, 64, 128, NAME_MAX };
1407 bucket = (id ^ namerand) % (sizeof(buckets) / sizeof(buckets[0]));
1408 padmod = buckets[bucket] + 1 - i;
1411 padlen = (id ^ namerand) % padmod;
1413 memset(&buf[i], 'X', padlen);
1414 buf[i + padlen] = '\0';
1419 open_file_or_dir(pathname_t *name, int flags)
1423 fd = open_path(name, flags);
1426 if (fd == -1 && errno != EISDIR)
1428 /* Directories can not be opened in write mode nor direct mode. */
1429 flags &= ~(O_WRONLY | O_DIRECT);
1430 flags |= O_RDONLY | O_DIRECTORY;
1431 return open_path(name, flags);
1435 open_path(pathname_t *name, int oflag)
1437 char buf[NAME_MAX + 1];
1441 rval = open(name->path, oflag);
1442 if (rval >= 0 || errno != ENAMETOOLONG)
1444 separate_pathname(name, buf, &newname);
1445 if (chdir(buf) == 0) {
1446 rval = open_path(&newname, oflag);
1447 assert(chdir("..") == 0);
1449 free_pathname(&newname);
1454 opendir_path(pathname_t *name)
1456 char buf[NAME_MAX + 1];
1460 rval = opendir(name->path);
1461 if (rval || errno != ENAMETOOLONG)
1463 separate_pathname(name, buf, &newname);
1464 if (chdir(buf) == 0) {
1465 rval = opendir_path(&newname);
1466 assert(chdir("..") == 0);
1468 free_pathname(&newname);
1473 process_freq(char *arg)
1478 s = strchr(arg, '=');
1480 fprintf(stderr, "bad argument '%s'\n", arg);
1484 for (p = ops; p < ops_end; p++) {
1485 if (strcmp(arg, p->name) == 0) {
1490 fprintf(stderr, "can't find op type %s for -f\n", arg);
1495 readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
1497 char buf[NAME_MAX + 1];
1501 rval = readlink(name->path, lbuf, lbufsiz);
1502 if (rval >= 0 || errno != ENAMETOOLONG)
1504 separate_pathname(name, buf, &newname);
1505 if (chdir(buf) == 0) {
1506 rval = readlink_path(&newname, lbuf, lbufsiz);
1507 assert(chdir("..") == 0);
1509 free_pathname(&newname);
1514 rename_path(pathname_t *name1, pathname_t *name2)
1516 char buf1[NAME_MAX + 1];
1517 char buf2[NAME_MAX + 1];
1519 pathname_t newname1;
1520 pathname_t newname2;
1523 rval = rename(name1->path, name2->path);
1524 if (rval >= 0 || errno != ENAMETOOLONG)
1526 separate_pathname(name1, buf1, &newname1);
1527 separate_pathname(name2, buf2, &newname2);
1528 if (strcmp(buf1, buf2) == 0) {
1529 if (chdir(buf1) == 0) {
1530 rval = rename_path(&newname1, &newname2);
1531 assert(chdir("..") == 0);
1534 if (strcmp(buf1, "..") == 0)
1536 else if (strcmp(buf2, "..") == 0)
1538 else if (strlen(buf1) == 0)
1540 else if (strlen(buf2) == 0)
1543 down1 = MAX(newname1.len, 3 + name2->len) <=
1544 MAX(3 + name1->len, newname2.len);
1546 free_pathname(&newname2);
1547 append_pathname(&newname2, "../");
1548 append_pathname(&newname2, name2->path);
1549 if (chdir(buf1) == 0) {
1550 rval = rename_path(&newname1, &newname2);
1551 assert(chdir("..") == 0);
1554 free_pathname(&newname1);
1555 append_pathname(&newname1, "../");
1556 append_pathname(&newname1, name1->path);
1557 if (chdir(buf2) == 0) {
1558 rval = rename_path(&newname1, &newname2);
1559 assert(chdir("..") == 0);
1563 free_pathname(&newname1);
1564 free_pathname(&newname2);
1569 rmdir_path(pathname_t *name)
1571 char buf[NAME_MAX + 1];
1575 rval = rmdir(name->path);
1576 if (rval >= 0 || errno != ENAMETOOLONG)
1578 separate_pathname(name, buf, &newname);
1579 if (chdir(buf) == 0) {
1580 rval = rmdir_path(&newname);
1581 assert(chdir("..") == 0);
1583 free_pathname(&newname);
1588 separate_pathname(pathname_t *name, char *buf, pathname_t *newname)
1592 init_pathname(newname);
1593 slash = strchr(name->path, '/');
1594 if (slash == NULL) {
1599 strcpy(buf, name->path);
1601 append_pathname(newname, slash + 1);
1607 show_ops(int flag, char *lead_str)
1612 /* print in list form */
1615 for (p = ops; p < ops_end; p++) {
1616 if (lead_str != NULL && x+strlen(p->name)>=WIDTH-5)
1617 x=printf("%s%s", (p==ops)?"":"\n", lead_str);
1618 x+=printf("%s ", p->name);
1621 } else if (flag == 0) {
1622 /* Table view style */
1624 for (f = 0, p = ops; p < ops_end; p++)
1630 for (p = ops; p < ops_end; p++) {
1631 if (flag != 0 || p->freq > 0) {
1632 if (lead_str != NULL)
1633 printf("%s", lead_str);
1634 printf("%20s %d/%d %s\n",
1635 p->name, p->freq, f,
1636 (p->iswrite == 0) ? " " : "write op");
1640 /* Command line style */
1641 if (lead_str != NULL)
1642 printf("%s", lead_str);
1643 printf ("-z -s %ld -m %d -n %d -p %d \\\n", seed, idmodulo,
1645 for (p = ops; p < ops_end; p++)
1647 printf("-f %s=%d \\\n",p->name, p->freq);
1652 stat64_path(pathname_t *name, struct stat64 *sbuf)
1654 char buf[NAME_MAX + 1];
1658 rval = stat64(name->path, sbuf);
1659 if (rval >= 0 || errno != ENAMETOOLONG)
1661 separate_pathname(name, buf, &newname);
1662 if (chdir(buf) == 0) {
1663 rval = stat64_path(&newname, sbuf);
1664 assert(chdir("..") == 0);
1666 free_pathname(&newname);
1671 symlink_path(const char *name1, pathname_t *name)
1673 char buf[NAME_MAX + 1];
1677 if (!strcmp(name1, name->path)) {
1678 printf("yikes! %s %s\n", name1, name->path);
1682 rval = symlink(name1, name->path);
1683 if (rval >= 0 || errno != ENAMETOOLONG)
1685 separate_pathname(name, buf, &newname);
1686 if (chdir(buf) == 0) {
1687 rval = symlink_path(name1, &newname);
1688 assert(chdir("..") == 0);
1690 free_pathname(&newname);
1695 truncate64_path(pathname_t *name, off64_t length)
1697 char buf[NAME_MAX + 1];
1701 rval = truncate64(name->path, length);
1702 if (rval >= 0 || errno != ENAMETOOLONG)
1704 separate_pathname(name, buf, &newname);
1705 if (chdir(buf) == 0) {
1706 rval = truncate64_path(&newname, length);
1707 assert(chdir("..") == 0);
1709 free_pathname(&newname);
1714 unlink_path(pathname_t *name)
1716 char buf[NAME_MAX + 1];
1720 rval = unlink(name->path);
1721 if (rval >= 0 || errno != ENAMETOOLONG)
1723 separate_pathname(name, buf, &newname);
1724 if (chdir(buf) == 0) {
1725 rval = unlink_path(&newname);
1726 assert(chdir("..") == 0);
1728 free_pathname(&newname);
1735 printf("Usage: %s -H or\n", myprog);
1736 printf(" %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
1738 printf(" [-p nproc][-r len][-s seed][-v][-w][-x cmd][-z][-S][-X ncmd]\n");
1740 printf(" -c clean up the test directory after each run\n");
1741 printf(" -d dir specifies the base directory for operations\n");
1742 printf(" -e errtg specifies error injection stuff\n");
1743 printf(" -f op_name=freq changes the frequency of option name to freq\n");
1744 printf(" the valid operation names are:\n");
1746 printf(" -i filenum get verbose output for this nth file object\n");
1747 printf(" -l loops specifies the no. of times the testrun should loop.\n");
1748 printf(" *use 0 for infinite (default 1)\n");
1749 printf(" -m modulo uid/gid modulo for chown/chgrp (default 32)\n");
1750 printf(" -n nops specifies the no. of operations per process (default 1)\n");
1751 printf(" -o logfile specifies logfile name\n");
1752 printf(" -p nproc specifies the no. of processes (default 1)\n");
1753 printf(" -r specifies random name padding\n");
1754 printf(" -s seed specifies the seed for the random generator (default random)\n");
1755 printf(" -v specifies verbose mode\n");
1756 printf(" -w zeros frequencies of non-write operations\n");
1757 printf(" -x cmd execute command in the middle of operations\n");
1758 printf(" -z zeros frequencies of all operations\n");
1759 printf(" -S [c,t] prints the list of operations (omitting zero frequency) in command line or table style\n");
1760 printf(" -V specifies verifiable logging mode (omitting inode numbers)\n");
1761 printf(" -X ncmd number of calls to the -x command (default 1)\n");
1762 printf(" -H prints usage and exits\n");
1770 for (p = ops; p < ops_end; p++) {
1781 for (p = ops; p < ops_end; p++)
1785 void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
1788 snprintf(str, sz, "[%ld %ld %d %d %lld %lld]",
1789 verifiable_log ? -1: (long)s->st_ino,
1790 (long)s->st_nlink, s->st_uid, s->st_gid,
1791 (long long) s->st_blocks, (long long) s->st_size);
1795 afsync_f(int opno, long r)
1803 struct iocb *iocbs[] = { &iocb };
1804 struct io_event event;
1807 if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, NULL, &v)) {
1809 printf("%d/%d: afsync - no filename\n", procid, opno);
1813 fd = open_file_or_dir(&f, O_WRONLY | O_DIRECT);
1814 e = fd < 0 ? errno : 0;
1818 printf("%d/%d: afsync - open %s failed %d\n",
1819 procid, opno, f.path, e);
1824 io_prep_fsync(&iocb, fd);
1825 if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
1827 printf("%d/%d: afsync - io_submit %s %d\n",
1828 procid, opno, f.path, e);
1833 if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
1835 printf("%d/%d: afsync - io_getevents failed %d\n",
1844 printf("%d/%d: afsync %s %d\n", procid, opno, f.path, e);
1851 allocsp_f(int opno, long r)
1856 struct xfs_flock64 fl;
1864 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1866 printf("%d/%d: allocsp - no filename\n", procid, opno);
1870 fd = open_path(&f, O_RDWR);
1871 e = fd < 0 ? errno : 0;
1875 printf("%d/%d: allocsp - open %s failed %d\n",
1876 procid, opno, f.path, e);
1880 if (fstat64(fd, &stb) < 0) {
1882 printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1883 procid, opno, f.path, errno);
1888 inode_info(st, sizeof(st), &stb, v);
1889 lr = ((int64_t)random() << 32) + random();
1890 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1892 fl.l_whence = SEEK_SET;
1895 e = xfsctl(f.path, fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1897 printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s%s %lld 0 %d\n",
1898 procid, opno, f.path, st, (long long)off, e);
1906 do_aio_rw(int opno, long r, int flags)
1910 struct dioattr diob;
1922 struct io_event event;
1923 struct iocb *iocbs[] = { &iocb };
1924 int iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
1927 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1929 printf("%d/%d: do_aio_rw - no filename\n", procid, opno);
1933 fd = open_path(&f, flags|O_DIRECT);
1934 e = fd < 0 ? errno : 0;
1938 printf("%d/%d: do_aio_rw - open %s failed %d\n",
1939 procid, opno, f.path, e);
1943 if (fstat64(fd, &stb) < 0) {
1945 printf("%d/%d: do_aio_rw - fstat64 %s failed %d\n",
1946 procid, opno, f.path, errno);
1951 inode_info(st, sizeof(st), &stb, v);
1952 if (!iswrite && stb.st_size == 0) {
1954 printf("%d/%d: do_aio_rw - %s%s zero size\n", procid, opno,
1960 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
1963 "%d/%d: do_aio_rw - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
1964 " fallback to stat()\n",
1965 procid, opno, f.path, st, errno);
1966 diob.d_mem = diob.d_miniosz = stb.st_blksize;
1967 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
1969 dio_env = getenv("XFS_DIO_MIN");
1971 diob.d_mem = diob.d_miniosz = atoi(dio_env);
1972 align = (int64_t)diob.d_miniosz;
1973 lr = ((int64_t)random() << 32) + random();
1974 len = (random() % FILELEN_MAX) + 1;
1975 len -= (len % align);
1978 else if (len > diob.d_maxiosz)
1979 len = diob.d_maxiosz;
1980 buf = memalign(diob.d_mem, len);
1983 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1984 off -= (off % align);
1986 memset(buf, nameseq & 0xff, len);
1987 io_prep_pwrite(&iocb, fd, buf, len, off);
1989 off = (off64_t)(lr % stb.st_size);
1990 off -= (off % align);
1991 io_prep_pread(&iocb, fd, buf, len, off);
1993 if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
1995 printf("%d/%d: %s - io_submit failed %d\n",
1996 procid, opno, iswrite ? "awrite" : "aread", e);
2001 if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
2003 printf("%d/%d: %s - io_getevents failed %d\n",
2004 procid, opno, iswrite ? "awrite" : "aread", e);
2010 e = event.res != len ? event.res2 : 0;
2013 printf("%d/%d: %s %s%s [%lld,%d] %d\n",
2014 procid, opno, iswrite ? "awrite" : "aread",
2015 f.path, st, (long long)off, (int)len, e);
2022 aread_f(int opno, long r)
2025 do_aio_rw(opno, r, O_RDONLY);
2030 attr_remove_f(int opno, long r)
2032 attrlist_ent_t *aep;
2036 attrlist_cursor_t cursor;
2045 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2046 append_pathname(&f, ".");
2048 bzero(&cursor, sizeof(cursor));
2050 bzero(buf, sizeof(buf));
2051 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
2055 alist = (attrlist_t *)buf;
2056 total += alist->al_count;
2057 } while (alist->al_more);
2060 printf("%d/%d: attr_remove - no attrs for %s\n",
2061 procid, opno, f.path);
2065 which = (int)(random() % total);
2066 bzero(&cursor, sizeof(cursor));
2070 bzero(buf, sizeof(buf));
2071 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
2075 alist = (attrlist_t *)buf;
2076 if (which < ent + alist->al_count) {
2077 aep = (attrlist_ent_t *)
2078 &buf[alist->al_offset[which - ent]];
2079 aname = aep->a_name;
2082 ent += alist->al_count;
2083 } while (alist->al_more);
2084 if (aname == NULL) {
2087 "%d/%d: attr_remove - name %d not found at %s\n",
2088 procid, opno, which, f.path);
2092 e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
2095 printf("%d/%d: attr_remove %s %s %d\n",
2096 procid, opno, f.path, aname, e);
2101 attr_set_f(int opno, long r)
2108 static int lengths[] = { 10, 100, 1000, 10000 };
2113 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2114 append_pathname(&f, ".");
2115 sprintf(aname, "a%x", nameseq++);
2116 li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
2117 len = (int)(random() % lengths[li]);
2121 memset(aval, nameseq & 0xff, len);
2122 e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
2127 printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
2133 awrite_f(int opno, long r)
2136 do_aio_rw(opno, r, O_WRONLY);
2141 bulkstat_f(int opno, long r)
2149 xfs_fsop_bulkreq_t bsr;
2152 nent = (r % 999) + 2;
2153 t = malloc(nent * sizeof(*t));
2154 fd = open(".", O_RDONLY);
2162 while (xfsctl(".", fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
2166 printf("%d/%d: bulkstat nent %d total %lld\n",
2167 procid, opno, nent, (long long)total);
2172 bulkstat1_f(int opno, long r)
2182 xfs_fsop_bulkreq_t bsr;
2185 good = random() & 1;
2187 /* use an inode we know exists */
2189 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2190 append_pathname(&f, ".");
2191 ino = stat64_path(&f, &s) < 0 ? (ino64_t)r : s.st_ino;
2196 * pick a random inode
2198 * note this can generate kernel warning messages
2199 * since bulkstat_one will read the disk block that
2200 * would contain a given inode even if that disk
2201 * block doesn't contain inodes.
2203 * this is detected later, but not until after the
2204 * warning is displayed.
2206 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
2212 fd = open(".", O_RDONLY);
2218 e = xfsctl(".", fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
2220 printf("%d/%d: bulkstat1 %s ino %lld %d\n",
2221 procid, opno, good?"real":"random",
2222 verifiable_log ? -1LL : (long long)ino, e);
2227 chown_f(int opno, long r)
2237 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2238 append_pathname(&f, ".");
2239 u = (uid_t)random();
2240 g = (gid_t)random();
2241 nbits = (int)(random() % idmodulo);
2242 u &= (1 << nbits) - 1;
2243 g &= (1 << nbits) - 1;
2244 e = lchown_path(&f, u, g) < 0 ? errno : 0;
2247 printf("%d/%d: chown %s %d/%d %d\n", procid, opno, f.path, (int)u, (int)g, e);
2251 /* reflink some arbitrary range of f1 to f2. */
2258 struct file_clone_range fcr;
2259 struct pathname fpath1;
2260 struct pathname fpath2;
2261 struct stat64 stat1;
2262 struct stat64 stat2;
2263 char inoinfo1[1024];
2264 char inoinfo2[1024];
2278 init_pathname(&fpath1);
2279 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2281 printf("%d/%d: clonerange read - no filename\n",
2286 init_pathname(&fpath2);
2287 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2289 printf("%d/%d: clonerange write - no filename\n",
2295 fd1 = open_path(&fpath1, O_RDONLY);
2296 e = fd1 < 0 ? errno : 0;
2300 printf("%d/%d: clonerange read - open %s failed %d\n",
2301 procid, opno, fpath1.path, e);
2305 fd2 = open_path(&fpath2, O_WRONLY);
2306 e = fd2 < 0 ? errno : 0;
2310 printf("%d/%d: clonerange write - open %s failed %d\n",
2311 procid, opno, fpath2.path, e);
2315 /* Get file stats */
2316 if (fstat64(fd1, &stat1) < 0) {
2318 printf("%d/%d: clonerange read - fstat64 %s failed %d\n",
2319 procid, opno, fpath1.path, errno);
2322 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2324 if (fstat64(fd2, &stat2) < 0) {
2326 printf("%d/%d: clonerange write - fstat64 %s failed %d\n",
2327 procid, opno, fpath2.path, errno);
2330 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2332 /* Calculate offsets */
2333 len = (random() % FILELEN_MAX) + 1;
2334 len &= ~(stat1.st_blksize - 1);
2336 len = stat1.st_blksize;
2337 if (len > stat1.st_size)
2338 len = stat1.st_size;
2340 lr = ((int64_t)random() << 32) + random();
2341 if (stat1.st_size == len)
2344 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2346 off1 &= ~(stat1.st_blksize - 1);
2349 * If srcfile == destfile, randomly generate destination ranges
2350 * until we find one that doesn't overlap the source range.
2352 max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
2354 lr = ((int64_t)random() << 32) + random();
2355 off2 = (off64_t)(lr % max_off2);
2357 off2 &= ~(stat2.st_blksize - 1);
2358 } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
2360 /* Clone data blocks */
2362 fcr.src_offset = off1;
2363 fcr.src_length = len;
2364 fcr.dest_offset = off2;
2366 ret = ioctl(fd2, FICLONERANGE, &fcr);
2367 e = ret < 0 ? errno : 0;
2369 printf("%d/%d: clonerange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
2371 fpath1.path, inoinfo1, (long long)off1, (long long)len,
2372 fpath2.path, inoinfo2, (long long)off2, (long long)len);
2375 printf(" error %d", e);
2384 free_pathname(&fpath2);
2386 free_pathname(&fpath1);
2390 /* copy some arbitrary range of f1 to f2. */
2396 #ifdef HAVE_COPY_FILE_RANGE
2397 struct pathname fpath1;
2398 struct pathname fpath2;
2399 struct stat64 stat1;
2400 struct stat64 stat2;
2401 char inoinfo1[1024];
2402 char inoinfo2[1024];
2420 init_pathname(&fpath1);
2421 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2423 printf("%d/%d: copyrange read - no filename\n",
2428 init_pathname(&fpath2);
2429 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2431 printf("%d/%d: copyrange write - no filename\n",
2437 fd1 = open_path(&fpath1, O_RDONLY);
2438 e = fd1 < 0 ? errno : 0;
2442 printf("%d/%d: copyrange read - open %s failed %d\n",
2443 procid, opno, fpath1.path, e);
2447 fd2 = open_path(&fpath2, O_WRONLY);
2448 e = fd2 < 0 ? errno : 0;
2452 printf("%d/%d: copyrange write - open %s failed %d\n",
2453 procid, opno, fpath2.path, e);
2457 /* Get file stats */
2458 if (fstat64(fd1, &stat1) < 0) {
2460 printf("%d/%d: copyrange read - fstat64 %s failed %d\n",
2461 procid, opno, fpath1.path, errno);
2464 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2466 if (fstat64(fd2, &stat2) < 0) {
2468 printf("%d/%d: copyrange write - fstat64 %s failed %d\n",
2469 procid, opno, fpath2.path, errno);
2472 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2474 /* Calculate offsets */
2475 len = (random() % FILELEN_MAX) + 1;
2477 len = stat1.st_blksize;
2478 if (len > stat1.st_size)
2479 len = stat1.st_size;
2481 lr = ((int64_t)random() << 32) + random();
2482 if (stat1.st_size == len)
2485 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2489 * If srcfile == destfile, randomly generate destination ranges
2490 * until we find one that doesn't overlap the source range.
2492 max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
2494 lr = ((int64_t)random() << 32) + random();
2495 off2 = (off64_t)(lr % max_off2);
2497 } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
2500 * Since len, off1 and off2 will be changed later, preserve their
2508 ret = syscall(__NR_copy_file_range, fd1, &off1, fd2, &off2,
2511 if (errno != EAGAIN || tries++ >= 300)
2513 } else if (ret > len || ret == 0)
2518 e = ret < 0 ? errno : 0;
2520 printf("%d/%d: copyrange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
2522 fpath1.path, inoinfo1,
2523 (long long)offset1, (long long)length,
2524 fpath2.path, inoinfo2,
2525 (long long)offset2, (long long)length);
2528 printf(" error %d", e);
2529 else if (len && ret > len)
2530 printf(" asked for %lld, copied %lld??\n",
2531 (long long)len, (long long)ret);
2540 free_pathname(&fpath2);
2542 free_pathname(&fpath1);
2546 /* dedupe some arbitrary range of f1 to f2...fn. */
2552 #ifdef FIDEDUPERANGE
2553 #define INFO_SZ 1024
2554 struct file_dedupe_range *fdr;
2555 struct pathname *fpath;
2556 struct stat64 *stat;
2568 if (flist[FT_REG].nfiles < 2)
2571 /* Pick somewhere between 2 and 128 files. */
2573 nr = random() % (flist[FT_REG].nfiles + 1);
2574 } while (nr < 2 || nr > 128);
2577 fdr = malloc(nr * sizeof(struct file_dedupe_range_info) +
2578 sizeof(struct file_dedupe_range));
2580 printf("%d/%d: line %d error %d\n",
2581 procid, opno, __LINE__, errno);
2584 memset(fdr, 0, (nr * sizeof(struct file_dedupe_range_info) +
2585 sizeof(struct file_dedupe_range)));
2587 fpath = calloc(nr, sizeof(struct pathname));
2589 printf("%d/%d: line %d error %d\n",
2590 procid, opno, __LINE__, errno);
2594 stat = calloc(nr, sizeof(struct stat64));
2596 printf("%d/%d: line %d error %d\n",
2597 procid, opno, __LINE__, errno);
2601 info = calloc(nr, INFO_SZ);
2603 printf("%d/%d: line %d error %d\n",
2604 procid, opno, __LINE__, errno);
2608 off = calloc(nr, sizeof(off64_t));
2610 printf("%d/%d: line %d error %d\n",
2611 procid, opno, __LINE__, errno);
2615 v = calloc(nr, sizeof(int));
2617 printf("%d/%d: line %d error %d\n",
2618 procid, opno, __LINE__, errno);
2621 fd = calloc(nr, sizeof(int));
2623 printf("%d/%d: line %d error %d\n",
2624 procid, opno, __LINE__, errno);
2627 memset(fd, 0xFF, nr * sizeof(int));
2629 /* Get paths for all files */
2630 for (i = 0; i < nr; i++)
2631 init_pathname(&fpath[i]);
2633 if (!get_fname(FT_REGm, r, &fpath[0], NULL, NULL, &v[0])) {
2635 printf("%d/%d: deduperange read - no filename\n",
2640 for (i = 1; i < nr; i++) {
2641 if (!get_fname(FT_REGm, random(), &fpath[i], NULL, NULL, &v[i])) {
2643 printf("%d/%d: deduperange write - no filename\n",
2650 fd[0] = open_path(&fpath[0], O_RDONLY);
2651 e = fd[0] < 0 ? errno : 0;
2655 printf("%d/%d: deduperange read - open %s failed %d\n",
2656 procid, opno, fpath[0].path, e);
2660 for (i = 1; i < nr; i++) {
2661 fd[i] = open_path(&fpath[i], O_WRONLY);
2662 e = fd[i] < 0 ? errno : 0;
2666 printf("%d/%d: deduperange write - open %s failed %d\n",
2667 procid, opno, fpath[i].path, e);
2672 /* Get file stats */
2673 if (fstat64(fd[0], &stat[0]) < 0) {
2675 printf("%d/%d: deduperange read - fstat64 %s failed %d\n",
2676 procid, opno, fpath[0].path, errno);
2680 inode_info(&info[0], INFO_SZ, &stat[0], v[0]);
2682 for (i = 1; i < nr; i++) {
2683 if (fstat64(fd[i], &stat[i]) < 0) {
2685 printf("%d/%d: deduperange write - fstat64 %s failed %d\n",
2686 procid, opno, fpath[i].path, errno);
2689 inode_info(&info[i * INFO_SZ], INFO_SZ, &stat[i], v[i]);
2692 /* Never try to dedupe more than half of the src file. */
2693 len = (random() % FILELEN_MAX) + 1;
2694 len &= ~(stat[0].st_blksize - 1);
2696 len = stat[0].st_blksize / 2;
2697 if (len > stat[0].st_size / 2)
2698 len = stat[0].st_size / 2;
2700 /* Calculate offsets */
2701 lr = ((int64_t)random() << 32) + random();
2702 if (stat[0].st_size == len)
2705 off[0] = (off64_t)(lr % MIN(stat[0].st_size - len, MAXFSIZE));
2707 off[0] &= ~(stat[0].st_blksize - 1);
2710 * If srcfile == destfile[i], randomly generate destination ranges
2711 * until we find one that doesn't overlap the source range.
2713 for (i = 1; i < nr; i++) {
2717 lr = ((int64_t)random() << 32) + random();
2718 if (stat[i].st_size <= len)
2721 off[i] = (off64_t)(lr % MIN(stat[i].st_size - len, MAXFSIZE));
2723 off[i] &= ~(stat[i].st_blksize - 1);
2724 } while (stat[0].st_ino == stat[i].st_ino &&
2725 llabs(off[i] - off[0]) < len &&
2729 /* Clone data blocks */
2730 fdr->src_offset = off[0];
2731 fdr->src_length = len;
2732 fdr->dest_count = nr - 1;
2733 for (i = 1; i < nr; i++) {
2734 fdr->info[i - 1].dest_fd = fd[i];
2735 fdr->info[i - 1].dest_offset = off[i];
2738 ret = ioctl(fd[0], FIDEDUPERANGE, fdr);
2739 e = ret < 0 ? errno : 0;
2741 printf("%d/%d: deduperange from %s%s [%lld,%lld]",
2743 fpath[0].path, &info[0], (long long)off[0],
2746 printf(" error %d", e);
2752 for (i = 1; i < nr; i++) {
2753 e = fdr->info[i - 1].status < 0 ? fdr->info[i - 1].status : 0;
2755 printf("%d/%d: ...to %s%s [%lld,%lld]",
2757 fpath[i].path, &info[i * INFO_SZ],
2758 (long long)off[i], (long long)len);
2759 if (fdr->info[i - 1].status < 0)
2760 printf(" error %d", e);
2761 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_SAME)
2762 printf(" %llu bytes deduplicated",
2763 fdr->info[i - 1].bytes_deduped);
2764 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_DIFFERS)
2765 printf(" differed");
2771 for (i = 0; i < nr; i++)
2775 for (i = 0; i < nr; i++)
2776 free_pathname(&fpath[i]);
2795 setxattr_f(int opno, long r)
2797 #ifdef XFS_XFLAG_EXTSIZE
2807 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2808 append_pathname(&f, ".");
2809 fd = open_path(&f, O_RDWR);
2810 e = fd < 0 ? errno : 0;
2815 e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
2816 nbits = (int)(random() % e);
2817 p &= (1 << nbits) - 1;
2819 if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
2821 e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
2824 printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
2831 splice_f(int opno, long r)
2833 struct pathname fpath1;
2834 struct pathname fpath2;
2835 struct stat64 stat1;
2836 struct stat64 stat2;
2837 char inoinfo1[1024];
2838 char inoinfo2[1024];
2842 loff_t offset1, offset2;
2849 ssize_t ret1 = 0, ret2 = 0;
2855 init_pathname(&fpath1);
2856 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2858 printf("%d/%d: splice read - no filename\n",
2863 init_pathname(&fpath2);
2864 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2866 printf("%d/%d: splice write - no filename\n",
2872 fd1 = open_path(&fpath1, O_RDONLY);
2873 e = fd1 < 0 ? errno : 0;
2877 printf("%d/%d: splice read - open %s failed %d\n",
2878 procid, opno, fpath1.path, e);
2882 fd2 = open_path(&fpath2, O_WRONLY);
2883 e = fd2 < 0 ? errno : 0;
2887 printf("%d/%d: splice write - open %s failed %d\n",
2888 procid, opno, fpath2.path, e);
2892 /* Get file stats */
2893 if (fstat64(fd1, &stat1) < 0) {
2895 printf("%d/%d: splice read - fstat64 %s failed %d\n",
2896 procid, opno, fpath1.path, errno);
2899 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2901 if (fstat64(fd2, &stat2) < 0) {
2903 printf("%d/%d: splice write - fstat64 %s failed %d\n",
2904 procid, opno, fpath2.path, errno);
2907 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2909 /* Calculate offsets */
2910 len = (random() % FILELEN_MAX) + 1;
2912 len = stat1.st_blksize;
2913 if (len > stat1.st_size)
2914 len = stat1.st_size;
2916 lr = ((int64_t)random() << 32) + random();
2917 if (stat1.st_size == len)
2920 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2924 * splice can overlap write, so the offset of the target file can be
2925 * any number. But to avoid too large offset, add a clamp of 1024 blocks
2926 * past the current dest file EOF
2928 lr = ((int64_t)random() << 32) + random();
2929 off2 = (off64_t)(lr % MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE));
2932 * Since len, off1 and off2 will be changed later, preserve their
2939 /* Pipe initialize */
2940 if (pipe(filedes) < 0) {
2942 printf("%d/%d: splice - pipe failed %d\n",
2943 procid, opno, errno);
2951 /* move to pipe buffer */
2952 ret1 = splice(fd1, &off1, filedes[1], NULL, len, 0);
2958 /* move from pipe buffer to dst file */
2960 ret2 = splice(filedes[0], NULL, fd2, &off2, bytes, 0);
2973 if (ret1 < 0 || ret2 < 0)
2978 printf("%d/%d: splice %s%s [%lld,%lld] -> %s%s [%lld,%lld] %d",
2980 fpath1.path, inoinfo1, (long long)offset1, (long long)length,
2981 fpath2.path, inoinfo2, (long long)offset2, (long long)length, e);
2983 if (length && length > total)
2984 printf(" asked for %lld, spliced %lld??\n",
2985 (long long)length, (long long)total);
2996 free_pathname(&fpath2);
2998 free_pathname(&fpath1);
3002 creat_f(int opno, long r)
3017 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
3022 e1 = (random() % 100);
3023 type = rtpct ? ((e1 > rtpct) ? FT_REG : FT_RTF) : FT_REG;
3025 if (type == FT_RTF) /* rt always gets an extsize */
3026 extsize = (random() % 10) + 1;
3027 else if (e1 < 10) /* one-in-ten get an extsize */
3028 extsize = random() % 1024;
3032 e = generate_fname(fep, type, &f, &id, &v);
3036 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3037 printf("%d/%d: creat - no filename from %s\n",
3038 procid, opno, f.path);
3043 fd = creat_path(&f, 0666);
3044 e = fd < 0 ? errno : 0;
3049 xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
3050 if (type == FT_RTF) {
3051 a.fsx_xflags |= XFS_XFLAG_REALTIME;
3052 a.fsx_extsize = extsize *
3053 geom.rtextsize * geom.blocksize;
3055 } else if (extsize) {
3056 a.fsx_xflags |= XFS_XFLAG_EXTSIZE;
3057 a.fsx_extsize = extsize * geom.blocksize;
3060 if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
3063 add_to_flist(type, id, parid, 0);
3067 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
3068 extsize ? a.fsx_extsize : 0, e, e1);
3069 printf("%d/%d: creat add id=%d,parent=%d\n", procid, opno, id, parid);
3075 dread_f(int opno, long r)
3079 struct dioattr diob;
3092 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3094 printf("%d/%d: dread - no filename\n", procid, opno);
3098 fd = open_path(&f, O_RDONLY|O_DIRECT);
3099 e = fd < 0 ? errno : 0;
3103 printf("%d/%d: dread - open %s failed %d\n",
3104 procid, opno, f.path, e);
3108 if (fstat64(fd, &stb) < 0) {
3110 printf("%d/%d: dread - fstat64 %s failed %d\n",
3111 procid, opno, f.path, errno);
3116 inode_info(st, sizeof(st), &stb, v);
3117 if (stb.st_size == 0) {
3119 printf("%d/%d: dread - %s%s zero size\n", procid, opno,
3125 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3128 "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
3129 " fallback to stat()\n",
3130 procid, opno, f.path, st, errno);
3131 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3132 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3135 dio_env = getenv("XFS_DIO_MIN");
3137 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3139 align = (int64_t)diob.d_miniosz;
3140 lr = ((int64_t)random() << 32) + random();
3141 off = (off64_t)(lr % stb.st_size);
3142 off -= (off % align);
3143 lseek64(fd, off, SEEK_SET);
3144 len = (random() % FILELEN_MAX) + 1;
3145 len -= (len % align);
3148 else if (len > diob.d_maxiosz)
3149 len = diob.d_maxiosz;
3150 buf = memalign(diob.d_mem, len);
3151 e = read(fd, buf, len) < 0 ? errno : 0;
3154 printf("%d/%d: dread %s%s [%lld,%d] %d\n",
3155 procid, opno, f.path, st, (long long)off, (int)len, e);
3161 dwrite_f(int opno, long r)
3165 struct dioattr diob;
3178 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3180 printf("%d/%d: dwrite - no filename\n", procid, opno);
3184 fd = open_path(&f, O_WRONLY|O_DIRECT);
3185 e = fd < 0 ? errno : 0;
3189 printf("%d/%d: dwrite - open %s failed %d\n",
3190 procid, opno, f.path, e);
3194 if (fstat64(fd, &stb) < 0) {
3196 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
3197 procid, opno, f.path, errno);
3202 inode_info(st, sizeof(st), &stb, v);
3203 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3205 printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
3206 " %s%s return %d, fallback to stat()\n",
3207 procid, opno, f.path, st, errno);
3208 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3209 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3212 dio_env = getenv("XFS_DIO_MIN");
3214 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3216 align = (int64_t)diob.d_miniosz;
3217 lr = ((int64_t)random() << 32) + random();
3218 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3219 off -= (off % align);
3220 lseek64(fd, off, SEEK_SET);
3221 len = (random() % FILELEN_MAX) + 1;
3222 len -= (len % align);
3225 else if (len > diob.d_maxiosz)
3226 len = diob.d_maxiosz;
3227 buf = memalign(diob.d_mem, len);
3229 lseek64(fd, off, SEEK_SET);
3230 memset(buf, nameseq & 0xff, len);
3231 e = write(fd, buf, len) < 0 ? errno : 0;
3234 printf("%d/%d: dwrite %s%s [%lld,%d] %d\n",
3235 procid, opno, f.path, st, (long long)off, (int)len, e);
3241 #ifdef HAVE_LINUX_FALLOC_H
3242 struct print_flags falloc_flags [] = {
3243 { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"},
3244 { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"},
3245 { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
3246 { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
3247 { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
3248 { FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
3252 #define translate_falloc_flags(mode) \
3253 ({translate_flags(mode, "|", falloc_flags);})
3257 do_fallocate(int opno, long r, int mode)
3259 #ifdef HAVE_LINUX_FALLOC_H
3271 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3273 printf("%d/%d: do_fallocate - no filename\n", procid, opno);
3277 fd = open_path(&f, O_RDWR);
3280 printf("%d/%d: do_fallocate - open %s failed %d\n",
3281 procid, opno, f.path, errno);
3286 if (fstat64(fd, &stb) < 0) {
3288 printf("%d/%d: do_fallocate - fstat64 %s failed %d\n",
3289 procid, opno, f.path, errno);
3294 inode_info(st, sizeof(st), &stb, v);
3295 lr = ((int64_t)random() << 32) + random();
3296 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3298 len = (off64_t)(random() % (1024 * 1024));
3300 * Collapse/insert range requires off and len to be block aligned,
3301 * make it more likely to be the case.
3303 if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) &&
3305 off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3306 len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3308 mode |= FALLOC_FL_KEEP_SIZE & random();
3309 e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
3311 printf("%d/%d: fallocate(%s) %s %st %lld %lld %d\n",
3312 procid, opno, translate_falloc_flags(mode),
3313 f.path, st, (long long)off, (long long)len, e);
3320 fallocate_f(int opno, long r)
3322 #ifdef HAVE_LINUX_FALLOC_H
3323 do_fallocate(opno, r, 0);
3328 fdatasync_f(int opno, long r)
3336 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3338 printf("%d/%d: fdatasync - no filename\n",
3343 fd = open_path(&f, O_WRONLY);
3344 e = fd < 0 ? errno : 0;
3348 printf("%d/%d: fdatasync - open %s failed %d\n",
3349 procid, opno, f.path, e);
3353 e = fdatasync(fd) < 0 ? errno : 0;
3355 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
3360 #ifdef HAVE_LINUX_FIEMAP_H
3361 struct print_flags fiemap_flags[] = {
3362 { FIEMAP_FLAG_SYNC, "SYNC"},
3363 { FIEMAP_FLAG_XATTR, "XATTR"},
3367 #define translate_fiemap_flags(mode) \
3368 ({translate_flags(mode, "|", fiemap_flags);})
3372 fiemap_f(int opno, long r)
3374 #ifdef HAVE_LINUX_FIEMAP_H
3384 struct fiemap *fiemap;
3387 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3389 printf("%d/%d: fiemap - no filename\n", procid, opno);
3393 fd = open_path(&f, O_RDWR);
3394 e = fd < 0 ? errno : 0;
3398 printf("%d/%d: fiemap - open %s failed %d\n",
3399 procid, opno, f.path, e);
3403 if (fstat64(fd, &stb) < 0) {
3405 printf("%d/%d: fiemap - fstat64 %s failed %d\n",
3406 procid, opno, f.path, errno);
3411 inode_info(st, sizeof(st), &stb, v);
3412 blocks_to_map = random() & 0xffff;
3413 fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) +
3414 (blocks_to_map * sizeof(struct fiemap_extent)));
3417 printf("%d/%d: malloc failed \n", procid, opno);
3422 lr = ((int64_t)random() << 32) + random();
3423 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3425 fiemap->fm_flags = random() & (FIEMAP_FLAGS_COMPAT | 0x10000);
3426 fiemap->fm_extent_count = blocks_to_map;
3427 fiemap->fm_mapped_extents = random() & 0xffff;
3428 fiemap->fm_start = off;
3429 fiemap->fm_length = ((int64_t)random() << 32) + random();
3431 e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
3433 printf("%d/%d: ioctl(FIEMAP) %s%s %lld %lld (%s) %d\n",
3434 procid, opno, f.path, st, (long long)fiemap->fm_start,
3435 (long long) fiemap->fm_length,
3436 translate_fiemap_flags(fiemap->fm_flags), e);
3444 freesp_f(int opno, long r)
3449 struct xfs_flock64 fl;
3457 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3459 printf("%d/%d: freesp - no filename\n", procid, opno);
3463 fd = open_path(&f, O_RDWR);
3464 e = fd < 0 ? errno : 0;
3468 printf("%d/%d: freesp - open %s failed %d\n",
3469 procid, opno, f.path, e);
3473 if (fstat64(fd, &stb) < 0) {
3475 printf("%d/%d: freesp - fstat64 %s failed %d\n",
3476 procid, opno, f.path, errno);
3481 inode_info(st, sizeof(st), &stb, v);
3482 lr = ((int64_t)random() << 32) + random();
3483 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3485 fl.l_whence = SEEK_SET;
3488 e = xfsctl(f.path, fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
3490 printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s%s %lld 0 %d\n",
3491 procid, opno, f.path, st, (long long)off, e);
3497 fsync_f(int opno, long r)
3505 if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, NULL, &v)) {
3507 printf("%d/%d: fsync - no filename\n", procid, opno);
3511 fd = open_file_or_dir(&f, O_WRONLY);
3512 e = fd < 0 ? errno : 0;
3516 printf("%d/%d: fsync - open %s failed %d\n",
3517 procid, opno, f.path, e);
3521 e = fsync(fd) < 0 ? errno : 0;
3523 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
3529 gen_random_string(int len)
3531 static const char charset[] = "0123456789"
3532 "abcdefghijklmnopqrstuvwxyz"
3533 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3544 for (i = 0; i < len; i++)
3545 s[i] = charset[random() % sizeof(charset)];
3551 getattr_f(int opno, long r)
3560 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
3561 append_pathname(&f, ".");
3562 fd = open_path(&f, O_RDWR);
3563 e = fd < 0 ? errno : 0;
3566 e = ioctl(fd, FS_IOC_GETFLAGS, &fl);
3568 printf("%d/%d: getattr %s %u %d\n", procid, opno, f.path, fl, e);
3574 getdents_f(int opno, long r)
3581 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
3582 append_pathname(&f, ".");
3583 dir = opendir_path(&f);
3587 printf("%d/%d: getdents - can't open %s\n",
3588 procid, opno, f.path);
3592 while (readdir64(dir) != NULL)
3595 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
3601 getfattr_f(int opno, long r)
3607 char name[XATTR_NAME_BUF_SIZE];
3613 if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
3615 printf("%d/%d: getfattr - no filename\n", procid, opno);
3621 * If the file/dir has xattrs, pick one randomly, otherwise attempt
3622 * to read a xattr that doesn't exist (fgetxattr should fail with
3623 * errno set to ENOATTR (61) in this case).
3625 if (fep->xattr_counter > 0)
3626 xattr_num = (random() % fep->xattr_counter) + 1;
3630 e = generate_xattr_name(xattr_num, name, sizeof(name));
3632 printf("%d/%d: getfattr - file %s failed to generate xattr name: %d\n",
3633 procid, opno, f.path, e);
3637 value_len = getxattr(f.path, name, NULL, 0);
3638 if (value_len < 0) {
3640 printf("%d/%d: getfattr file %s name %s failed %d\n",
3641 procid, opno, f.path, name, errno);
3645 /* A xattr without value.*/
3646 if (value_len == 0) {
3651 value = malloc(value_len);
3654 printf("%d/%d: getfattr file %s failed to allocate buffer with %d bytes\n",
3655 procid, opno, f.path, value_len);
3659 e = getxattr(f.path, name, value, value_len) < 0 ? errno : 0;
3662 printf("%d/%d: getfattr file %s name %s value length %d %d\n",
3663 procid, opno, f.path, name, value_len, e);
3670 link_f(int opno, long r)
3684 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep_src, &v1)) {
3686 printf("%d/%d: link - no file\n", procid, opno);
3690 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
3696 e = generate_fname(fep, flp - flist, &l, &id, &v1);
3700 (void)fent_to_name(&l, &flist[FT_DIR], fep);
3701 printf("%d/%d: link - no filename from %s\n",
3702 procid, opno, l.path);
3708 e = link_path(&f, &l) < 0 ? errno : 0;
3711 add_to_flist(flp - flist, id, parid, fep_src->xattr_counter);
3713 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
3715 printf("%d/%d: link add id=%d,parent=%d\n", procid, opno, id, parid);
3722 mkdir_f(int opno, long r)
3732 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3737 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
3741 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3742 printf("%d/%d: mkdir - no filename from %s\n",
3743 procid, opno, f.path);
3748 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
3751 add_to_flist(FT_DIR, id, parid, 0);
3753 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
3754 printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
3760 mknod_f(int opno, long r)
3770 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3775 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
3779 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3780 printf("%d/%d: mknod - no filename from %s\n",
3781 procid, opno, f.path);
3786 e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0;
3789 add_to_flist(FT_DEV, id, parid, 0);
3791 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
3792 printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
3797 #ifdef HAVE_SYS_MMAN_H
3798 struct print_flags mmap_flags[] = {
3799 { MAP_SHARED, "SHARED"},
3800 { MAP_PRIVATE, "PRIVATE"},
3804 #define translate_mmap_flags(flags) \
3805 ({translate_flags(flags, "|", mmap_flags);})
3809 do_mmap(int opno, long r, int prot)
3811 #ifdef HAVE_SYS_MMAN_H
3823 sigjmp_buf sigbus_jmpbuf;
3826 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3828 printf("%d/%d: do_mmap - no filename\n", procid, opno);
3832 fd = open_path(&f, O_RDWR);
3833 e = fd < 0 ? errno : 0;
3837 printf("%d/%d: do_mmap - open %s failed %d\n",
3838 procid, opno, f.path, e);
3842 if (fstat64(fd, &stb) < 0) {
3844 printf("%d/%d: do_mmap - fstat64 %s failed %d\n",
3845 procid, opno, f.path, errno);
3850 inode_info(st, sizeof(st), &stb, v);
3851 if (stb.st_size == 0) {
3853 printf("%d/%d: do_mmap - %s%s zero size\n", procid, opno,
3860 lr = ((int64_t)random() << 32) + random();
3861 off = (off64_t)(lr % stb.st_size);
3862 off &= (off64_t)(~(sysconf(_SC_PAGE_SIZE) - 1));
3863 len = (size_t)(random() % MIN(stb.st_size - off, FILELEN_MAX)) + 1;
3865 flags = (random() % 2) ? MAP_SHARED : MAP_PRIVATE;
3866 addr = mmap(NULL, len, prot, flags, fd, off);
3867 e = (addr == MAP_FAILED) ? errno : 0;
3870 printf("%d/%d: do_mmap - mmap failed %s%s [%lld,%d,%s] %d\n",
3871 procid, opno, f.path, st, (long long)off,
3872 (int)len, translate_mmap_flags(flags), e);
3878 if (prot & PROT_WRITE) {
3879 if ((e = sigsetjmp(sigbus_jmpbuf, 1)) == 0) {
3880 sigbus_jmp = &sigbus_jmpbuf;
3881 memset(addr, nameseq & 0xff, len);
3885 if ((buf = malloc(len)) != NULL) {
3886 memcpy(buf, addr, len);
3891 /* set NULL to stop other functions from doing siglongjmp */
3895 printf("%d/%d: %s %s%s [%lld,%d,%s] %s\n",
3896 procid, opno, (prot & PROT_WRITE) ? "mwrite" : "mread",
3897 f.path, st, (long long)off, (int)len,
3898 translate_mmap_flags(flags),
3899 (e == 0) ? "0" : "Bus error");
3907 mread_f(int opno, long r)
3909 #ifdef HAVE_SYS_MMAN_H
3910 do_mmap(opno, r, PROT_READ);
3915 mwrite_f(int opno, long r)
3917 #ifdef HAVE_SYS_MMAN_H
3918 do_mmap(opno, r, PROT_WRITE);
3923 punch_f(int opno, long r)
3925 #ifdef HAVE_LINUX_FALLOC_H
3926 do_fallocate(opno, r, FALLOC_FL_PUNCH_HOLE);
3931 zero_f(int opno, long r)
3933 #ifdef HAVE_LINUX_FALLOC_H
3934 do_fallocate(opno, r, FALLOC_FL_ZERO_RANGE);
3939 collapse_f(int opno, long r)
3941 #ifdef HAVE_LINUX_FALLOC_H
3942 do_fallocate(opno, r, FALLOC_FL_COLLAPSE_RANGE);
3947 insert_f(int opno, long r)
3949 #ifdef HAVE_LINUX_FALLOC_H
3950 do_fallocate(opno, r, FALLOC_FL_INSERT_RANGE);
3955 read_f(int opno, long r)
3969 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3971 printf("%d/%d: read - no filename\n", procid, opno);
3975 fd = open_path(&f, O_RDONLY);
3976 e = fd < 0 ? errno : 0;
3980 printf("%d/%d: read - open %s failed %d\n",
3981 procid, opno, f.path, e);
3985 if (fstat64(fd, &stb) < 0) {
3987 printf("%d/%d: read - fstat64 %s failed %d\n",
3988 procid, opno, f.path, errno);
3993 inode_info(st, sizeof(st), &stb, v);
3994 if (stb.st_size == 0) {
3996 printf("%d/%d: read - %s%s zero size\n", procid, opno,
4002 lr = ((int64_t)random() << 32) + random();
4003 off = (off64_t)(lr % stb.st_size);
4004 lseek64(fd, off, SEEK_SET);
4005 len = (random() % FILELEN_MAX) + 1;
4007 e = read(fd, buf, len) < 0 ? errno : 0;
4010 printf("%d/%d: read %s%s [%lld,%d] %d\n",
4011 procid, opno, f.path, st, (long long)off, (int)len, e);
4017 readlink_f(int opno, long r)
4025 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
4027 printf("%d/%d: readlink - no filename\n", procid, opno);
4031 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
4034 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
4039 readv_f(int opno, long r)
4051 struct iovec *iov = NULL;
4058 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4060 printf("%d/%d: readv - no filename\n", procid, opno);
4064 fd = open_path(&f, O_RDONLY);
4065 e = fd < 0 ? errno : 0;
4069 printf("%d/%d: readv - open %s failed %d\n",
4070 procid, opno, f.path, e);
4074 if (fstat64(fd, &stb) < 0) {
4076 printf("%d/%d: readv - fstat64 %s failed %d\n",
4077 procid, opno, f.path, errno);
4082 inode_info(st, sizeof(st), &stb, v);
4083 if (stb.st_size == 0) {
4085 printf("%d/%d: readv - %s%s zero size\n", procid, opno,
4091 lr = ((int64_t)random() << 32) + random();
4092 off = (off64_t)(lr % stb.st_size);
4093 lseek64(fd, off, SEEK_SET);
4094 len = (random() % FILELEN_MAX) + 1;
4097 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
4098 iov = calloc(iovcnt, sizeof(struct iovec));
4099 iovl = len / iovcnt;
4101 for (i=0; i<iovcnt; i++) {
4102 (iov + i)->iov_base = (buf + iovb);
4103 (iov + i)->iov_len = iovl;
4107 e = readv(fd, iov, iovcnt) < 0 ? errno : 0;
4110 printf("%d/%d: readv %s%s [%lld,%d,%d] %d\n",
4111 procid, opno, f.path, st, (long long)off, (int)iovl,
4118 rename_f(int opno, long r)
4132 /* get an existing path for the source of the rename */
4134 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
4136 printf("%d/%d: rename - no filename\n", procid, opno);
4141 /* get an existing directory for the destination parent directory name */
4142 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
4148 /* generate a new path using an existing parent directory in name */
4149 init_pathname(&newf);
4150 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
4154 (void)fent_to_name(&f, &flist[FT_DIR], dfep);
4155 printf("%d/%d: rename - no filename from %s\n",
4156 procid, opno, f.path);
4158 free_pathname(&newf);
4162 e = rename_path(&f, &newf) < 0 ? errno : 0;
4165 int xattr_counter = fep->xattr_counter;
4167 if (flp - flist == FT_DIR) {
4169 fix_parent(oldid, id);
4171 del_from_flist(flp - flist, fep - flp->fents);
4172 add_to_flist(flp - flist, id, parid, xattr_counter);
4175 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
4178 printf("%d/%d: rename del entry: id=%d,parent=%d\n",
4179 procid, opno, fep->id, fep->parent);
4180 printf("%d/%d: rename add entry: id=%d,parent=%d\n",
4181 procid, opno, id, parid);
4184 free_pathname(&newf);
4189 resvsp_f(int opno, long r)
4194 struct xfs_flock64 fl;
4202 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4204 printf("%d/%d: resvsp - no filename\n", procid, opno);
4208 fd = open_path(&f, O_RDWR);
4209 e = fd < 0 ? errno : 0;
4213 printf("%d/%d: resvsp - open %s failed %d\n",
4214 procid, opno, f.path, e);
4218 if (fstat64(fd, &stb) < 0) {
4220 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
4221 procid, opno, f.path, errno);
4226 inode_info(st, sizeof(st), &stb, v);
4227 lr = ((int64_t)random() << 32) + random();
4228 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4230 fl.l_whence = SEEK_SET;
4232 fl.l_len = (off64_t)(random() % (1024 * 1024));
4233 e = xfsctl(f.path, fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
4235 printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s%s %lld %lld %d\n",
4236 procid, opno, f.path, st,
4237 (long long)off, (long long)fl.l_len, e);
4243 rmdir_f(int opno, long r)
4251 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
4253 printf("%d/%d: rmdir - no directory\n", procid, opno);
4257 e = rmdir_path(&f) < 0 ? errno : 0;
4260 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
4262 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
4264 printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
4265 procid, opno, fep->id, fep->parent);
4271 setattr_f(int opno, long r)
4280 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
4281 append_pathname(&f, ".");
4282 fd = open_path(&f, O_RDWR);
4283 e = fd < 0 ? errno : 0;
4286 fl = attr_mask & (uint)random();
4287 e = ioctl(fd, FS_IOC_SETFLAGS, &fl);
4289 printf("%d/%d: setattr %s %x %d\n", procid, opno, f.path, fl, e);
4295 setfattr_f(int opno, long r)
4302 char name[XATTR_NAME_BUF_SIZE];
4308 if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
4310 printf("%d/%d: setfattr - no filename\n", procid, opno);
4315 if ((fep->xattr_counter > 0) && (random() % 2)) {
4317 * Use an existing xattr name for replacing its value or
4318 * create again a xattr that was previously deleted.
4320 xattr_num = (random() % fep->xattr_counter) + 1;
4322 flag = XATTR_REPLACE;
4324 /* Use a new xattr name. */
4325 xattr_num = fep->xattr_counter + 1;
4327 * Don't always use the create flag because even if our xattr
4328 * counter is 0, we may still have xattrs associated to this
4329 * file (this happens when xattrs are added to a file through
4330 * one of its other hard links), so we can end up updating an
4331 * existing xattr too.
4334 flag = XATTR_CREATE;
4338 * The maximum supported value size depends on the filesystem
4339 * implementation, but 100 bytes is a safe value for most filesystems
4342 value_len = random() % 101;
4343 value = gen_random_string(value_len);
4344 if (!value && value_len > 0) {
4346 printf("%d/%d: setfattr - file %s failed to allocate value with %d bytes\n",
4347 procid, opno, f.path, value_len);
4350 e = generate_xattr_name(xattr_num, name, sizeof(name));
4352 printf("%d/%d: setfattr - file %s failed to generate xattr name: %d\n",
4353 procid, opno, f.path, e);
4357 e = setxattr(f.path, name, value, value_len, flag) < 0 ? errno : 0;
4359 fep->xattr_counter++;
4361 printf("%d/%d: setfattr file %s name %s flag %s value length %d: %d\n",
4362 procid, opno, f.path, name, xattr_flag_to_string(flag),
4370 stat_f(int opno, long r)
4378 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
4380 printf("%d/%d: stat - no entries\n", procid, opno);
4384 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
4387 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
4392 symlink_f(int opno, long r)
4405 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
4410 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
4414 (void)fent_to_name(&f, &flist[FT_DIR], fep);
4415 printf("%d/%d: symlink - no filename from %s\n",
4416 procid, opno, f.path);
4421 len = (int)(random() % PATH_MAX);
4422 val = malloc(len + 1);
4424 memset(val, 'x', len);
4426 for (i = 10; i < len - 1; i += 10)
4428 e = symlink_path(val, &f) < 0 ? errno : 0;
4431 add_to_flist(FT_SYM, id, parid, 0);
4434 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
4435 printf("%d/%d: symlink add id=%d,parent=%d\n", procid, opno, id, parid);
4442 sync_f(int opno, long r)
4446 printf("%d/%d: sync\n", procid, opno);
4450 truncate_f(int opno, long r)
4461 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4463 printf("%d/%d: truncate - no filename\n", procid, opno);
4467 e = stat64_path(&f, &stb) < 0 ? errno : 0;
4471 printf("%d/%d: truncate - stat64 %s failed %d\n",
4472 procid, opno, f.path, e);
4476 inode_info(st, sizeof(st), &stb, v);
4477 lr = ((int64_t)random() << 32) + random();
4478 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4480 e = truncate64_path(&f, off) < 0 ? errno : 0;
4483 printf("%d/%d: truncate %s%s %lld %d\n", procid, opno, f.path,
4484 st, (long long)off, e);
4489 unlink_f(int opno, long r)
4498 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
4500 printf("%d/%d: unlink - no file\n", procid, opno);
4504 e = unlink_path(&f) < 0 ? errno : 0;
4507 del_from_flist(flp - flist, fep - flp->fents);
4509 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
4511 printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
4512 procid, opno, fep->id, fep->parent);
4518 unresvsp_f(int opno, long r)
4523 struct xfs_flock64 fl;
4531 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4533 printf("%d/%d: unresvsp - no filename\n", procid, opno);
4537 fd = open_path(&f, O_RDWR);
4538 e = fd < 0 ? errno : 0;
4542 printf("%d/%d: unresvsp - open %s failed %d\n",
4543 procid, opno, f.path, e);
4547 if (fstat64(fd, &stb) < 0) {
4549 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
4550 procid, opno, f.path, errno);
4555 inode_info(st, sizeof(st), &stb, v);
4556 lr = ((int64_t)random() << 32) + random();
4557 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4559 fl.l_whence = SEEK_SET;
4561 fl.l_len = (off64_t)(random() % (1 << 20));
4562 e = xfsctl(f.path, fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
4564 printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s%s %lld %lld %d\n",
4565 procid, opno, f.path, st,
4566 (long long)off, (long long)fl.l_len, e);
4572 write_f(int opno, long r)
4586 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4588 printf("%d/%d: write - no filename\n", procid, opno);
4592 fd = open_path(&f, O_WRONLY);
4593 e = fd < 0 ? errno : 0;
4597 printf("%d/%d: write - open %s failed %d\n",
4598 procid, opno, f.path, e);
4602 if (fstat64(fd, &stb) < 0) {
4604 printf("%d/%d: write - fstat64 %s failed %d\n",
4605 procid, opno, f.path, errno);
4610 inode_info(st, sizeof(st), &stb, v);
4611 lr = ((int64_t)random() << 32) + random();
4612 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4614 lseek64(fd, off, SEEK_SET);
4615 len = (random() % FILELEN_MAX) + 1;
4617 memset(buf, nameseq & 0xff, len);
4618 e = write(fd, buf, len) < 0 ? errno : 0;
4621 printf("%d/%d: write %s%s [%lld,%d] %d\n",
4622 procid, opno, f.path, st, (long long)off, (int)len, e);
4628 writev_f(int opno, long r)
4640 struct iovec *iov = NULL;
4647 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4649 printf("%d/%d: writev - no filename\n", procid, opno);
4653 fd = open_path(&f, O_WRONLY);
4654 e = fd < 0 ? errno : 0;
4658 printf("%d/%d: writev - open %s failed %d\n",
4659 procid, opno, f.path, e);
4663 if (fstat64(fd, &stb) < 0) {
4665 printf("%d/%d: writev - fstat64 %s failed %d\n",
4666 procid, opno, f.path, errno);
4671 inode_info(st, sizeof(st), &stb, v);
4672 lr = ((int64_t)random() << 32) + random();
4673 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4675 lseek64(fd, off, SEEK_SET);
4676 len = (random() % FILELEN_MAX) + 1;
4678 memset(buf, nameseq & 0xff, len);
4680 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
4681 iov = calloc(iovcnt, sizeof(struct iovec));
4682 iovl = len / iovcnt;
4684 for (i=0; i<iovcnt; i++) {
4685 (iov + i)->iov_base = (buf + iovb);
4686 (iov + i)->iov_len = iovl;
4690 e = writev(fd, iov, iovcnt) < 0 ? errno : 0;
4694 printf("%d/%d: writev %s%s [%lld,%d,%d] %d\n",
4695 procid, opno, f.path, st, (long long)off, (int)iovl,
4702 xattr_flag_to_string(int flag)
4704 if (flag == XATTR_CREATE)
4706 if (flag == XATTR_REPLACE)