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>
31 #ifndef FS_IOC_GETFLAGS
32 #define FS_IOC_GETFLAGS _IOR('f', 1, long)
34 #ifndef FS_IOC_SETFLAGS
35 #define FS_IOC_SETFLAGS _IOW('f', 2, long)
39 #define XFS_ERRTAG_MAX 17
40 #define XFS_IDMODULO_MAX 31 /* user/group IDs (1 << x) */
41 #define XFS_PROJIDMODULO_MAX 16 /* project IDs (1 << x) */
46 #define FILELEN_MAX (32*4096)
100 typedef void (*opfnc_t)(int, long);
102 typedef struct opdesc {
110 typedef struct fent {
115 typedef struct flist {
122 typedef struct pathname {
132 struct print_string {
139 #define FT_DIRm (1 << FT_DIR)
141 #define FT_REGm (1 << FT_REG)
143 #define FT_SYMm (1 << FT_SYM)
145 #define FT_DEVm (1 << FT_DEV)
147 #define FT_RTFm (1 << FT_RTF)
149 #define FT_ANYm ((1 << FT_nft) - 1)
150 #define FT_REGFILE (FT_REGm | FT_RTFm)
151 #define FT_NOTDIR (FT_ANYm & ~FT_DIRm)
153 #define FLIST_SLOT_INCR 16
156 #define MAXFSIZE ((1ULL << 63) - 1ULL)
157 #define MAXFSIZE32 ((1ULL << 40) - 1ULL)
159 void afsync_f(int, long);
160 void allocsp_f(int, long);
161 void aread_f(int, long);
162 void attr_remove_f(int, long);
163 void attr_set_f(int, long);
164 void awrite_f(int, long);
165 void bulkstat_f(int, long);
166 void bulkstat1_f(int, long);
167 void chown_f(int, long);
168 void clonerange_f(int, long);
169 void copyrange_f(int, long);
170 void creat_f(int, long);
171 void deduperange_f(int, long);
172 void dread_f(int, long);
173 void dwrite_f(int, long);
174 void fallocate_f(int, long);
175 void fdatasync_f(int, long);
176 void fiemap_f(int, long);
177 void freesp_f(int, long);
178 void fsync_f(int, long);
179 void getattr_f(int, long);
180 void getdents_f(int, long);
181 void link_f(int, long);
182 void mkdir_f(int, long);
183 void mknod_f(int, long);
184 void mread_f(int, long);
185 void mwrite_f(int, long);
186 void punch_f(int, long);
187 void zero_f(int, long);
188 void collapse_f(int, long);
189 void insert_f(int, long);
190 void read_f(int, long);
191 void readlink_f(int, long);
192 void readv_f(int, long);
193 void rename_f(int, long);
194 void resvsp_f(int, long);
195 void rmdir_f(int, long);
196 void setattr_f(int, long);
197 void setxattr_f(int, long);
198 void splice_f(int, long);
199 void stat_f(int, long);
200 void symlink_f(int, long);
201 void sync_f(int, long);
202 void truncate_f(int, long);
203 void unlink_f(int, long);
204 void unresvsp_f(int, long);
205 void write_f(int, long);
206 void writev_f(int, long);
209 /* { OP_ENUM, "name", function, freq, iswrite }, */
210 { OP_AFSYNC, "afsync", afsync_f, 0, 1 },
211 { OP_ALLOCSP, "allocsp", allocsp_f, 1, 1 },
212 { OP_AREAD, "aread", aread_f, 1, 0 },
213 { OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1 },
214 { OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1 },
215 { OP_AWRITE, "awrite", awrite_f, 1, 1 },
216 { OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0 },
217 { OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0 },
218 { OP_CHOWN, "chown", chown_f, 3, 1 },
219 { OP_CLONERANGE, "clonerange", clonerange_f, 4, 1 },
220 { OP_COPYRANGE, "copyrange", copyrange_f, 4, 1 },
221 { OP_CREAT, "creat", creat_f, 4, 1 },
222 { OP_DEDUPERANGE, "deduperange", deduperange_f, 4, 1},
223 { OP_DREAD, "dread", dread_f, 4, 0 },
224 { OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
225 { OP_FALLOCATE, "fallocate", fallocate_f, 1, 1 },
226 { OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
227 { OP_FIEMAP, "fiemap", fiemap_f, 1, 1 },
228 { OP_FREESP, "freesp", freesp_f, 1, 1 },
229 { OP_FSYNC, "fsync", fsync_f, 1, 1 },
230 { OP_GETATTR, "getattr", getattr_f, 1, 0 },
231 { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
232 { OP_LINK, "link", link_f, 1, 1 },
233 { OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
234 { OP_MKNOD, "mknod", mknod_f, 2, 1 },
235 { OP_MREAD, "mread", mread_f, 2, 0 },
236 { OP_MWRITE, "mwrite", mwrite_f, 2, 1 },
237 { OP_PUNCH, "punch", punch_f, 1, 1 },
238 { OP_ZERO, "zero", zero_f, 1, 1 },
239 { OP_COLLAPSE, "collapse", collapse_f, 1, 1 },
240 { OP_INSERT, "insert", insert_f, 1, 1 },
241 { OP_READ, "read", read_f, 1, 0 },
242 { OP_READLINK, "readlink", readlink_f, 1, 0 },
243 { OP_READV, "readv", readv_f, 1, 0 },
244 { OP_RENAME, "rename", rename_f, 2, 1 },
245 { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
246 { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
247 { OP_SETATTR, "setattr", setattr_f, 0, 1 },
248 { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
249 { OP_SPLICE, "splice", splice_f, 1, 1 },
250 { OP_STAT, "stat", stat_f, 1, 0 },
251 { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
252 { OP_SYNC, "sync", sync_f, 1, 1 },
253 { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
254 { OP_UNLINK, "unlink", unlink_f, 1, 1 },
255 { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
256 { OP_WRITE, "write", write_f, 4, 1 },
257 { OP_WRITEV, "writev", writev_f, 4, 1 },
260 flist_t flist[FT_nft] = {
273 xfs_fsop_geom_t geom;
284 unsigned int idmodulo = XFS_IDMODULO_MAX;
285 unsigned int attr_mask = ~0;
288 unsigned long seed = 0;
292 int verifiable_log = 0;
293 sig_atomic_t should_stop = 0;
294 sigjmp_buf *sigbus_jmp = NULL;
295 char *execute_cmd = NULL;
296 int execute_freq = 1;
297 struct print_string flag_str = {0};
299 void add_to_flist(int, int, int);
300 void append_pathname(pathname_t *, char *);
301 int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
302 int attr_remove_path(pathname_t *, const char *, int);
303 int attr_set_path(pathname_t *, const char *, const char *, const int, int);
304 void check_cwd(void);
305 void cleanup_flist(void);
306 int creat_path(pathname_t *, mode_t);
307 void dcache_enter(int, int);
308 void dcache_init(void);
309 fent_t *dcache_lookup(int);
310 void dcache_purge(int);
311 void del_from_flist(int, int);
312 int dirid_to_name(char *, int);
314 int fent_to_name(pathname_t *, flist_t *, fent_t *);
315 void fix_parent(int, int);
316 void free_pathname(pathname_t *);
317 int generate_fname(fent_t *, int, pathname_t *, int *, int *);
318 int get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
319 void init_pathname(pathname_t *);
320 int lchown_path(pathname_t *, uid_t, gid_t);
321 int link_path(pathname_t *, pathname_t *);
322 int lstat64_path(pathname_t *, struct stat64 *);
323 void make_freq_table(void);
324 int mkdir_path(pathname_t *, mode_t);
325 int mknod_path(pathname_t *, mode_t, dev_t);
326 void namerandpad(int, char *, int);
327 int open_path(pathname_t *, int);
328 DIR *opendir_path(pathname_t *);
329 void process_freq(char *);
330 int readlink_path(pathname_t *, char *, size_t);
331 int rename_path(pathname_t *, pathname_t *);
332 int rmdir_path(pathname_t *);
333 void separate_pathname(pathname_t *, char *, pathname_t *);
334 void show_ops(int, char *);
335 int stat64_path(pathname_t *, struct stat64 *);
336 int symlink_path(const char *, pathname_t *);
337 int truncate64_path(pathname_t *, off64_t);
338 int unlink_path(pathname_t *);
340 void write_freq(void);
341 void zero_freq(void);
343 void sg_handler(int signum)
351 * Only handle SIGBUS when mmap write to a hole and no
352 * block can be allocated due to ENOSPC, abort otherwise.
355 siglongjmp(*sigbus_jmp, -1);
357 printf("Unknown SIGBUS is caught, Abort!\n");
360 /* should not reach here */
367 int main(int argc, char **argv)
371 char *dirname = NULL;
372 char *logname = NULL;
373 char rpath[PATH_MAX];
382 xfs_error_injection_t err_inj;
383 struct sigaction action;
385 const char *allopts = "cd:e:f:i:l:m:M:n:o:p:rs:S:vVwx:X:zH";
387 errrange = errtag = 0;
389 nops = sizeof(ops) / sizeof(ops[0]);
390 ops_end = &ops[nops];
392 while ((c = getopt(argc, argv, allopts)) != -1) {
401 sscanf(optarg, "%d", &errtag);
405 } else if (errtag == 0)
407 if (errtag >= XFS_ERRTAG_MAX) {
409 "error tag %d too large (max %d)\n",
410 errtag, XFS_ERRTAG_MAX - 1);
415 process_freq(optarg);
418 ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
419 ilist[ilistlen - 1] = strtol(optarg, &p, 16);
422 idmodulo = strtoul(optarg, NULL, 0);
423 if (idmodulo > XFS_IDMODULO_MAX) {
425 "chown modulo %d too big (max %d)\n",
426 idmodulo, XFS_IDMODULO_MAX);
431 loops = atoi(optarg);
434 operations = atoi(optarg);
441 nproc = atoi(optarg);
447 seed = strtoul(optarg, NULL, 0);
456 execute_cmd = optarg;
462 attr_mask = strtoul(optarg, NULL, 0);
466 if (optarg[0] == 'c')
477 execute_freq = strtoul(optarg, NULL, 0);
480 fprintf(stderr, "%s - invalid parameters\n",
490 /* no directory specified */
491 if (!nousage) usage();
495 (void)mkdir(dirname, 0777);
496 if (logname && logname[0] != '/') {
497 if (!getcwd(rpath, sizeof(rpath))){
498 perror("getcwd failed");
504 if (chdir(dirname) < 0) {
509 char path[PATH_MAX + NAME_MAX + 1];
510 snprintf(path, sizeof(path), "%s/%s", rpath, logname);
511 if (freopen(path, "a", stdout) == NULL) {
512 perror("freopen logfile failed");
516 sprintf(buf, "fss%x", (unsigned int)getpid());
517 fd = creat(buf, 0666);
518 if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
519 maxfsize = (off64_t)MAXFSIZE32;
521 maxfsize = (off64_t)MAXFSIZE;
526 gettimeofday(&t, (void *)NULL);
527 seed = (int)t.tv_sec ^ (int)t.tv_usec;
528 printf("seed = %ld\n", seed);
530 i = xfsctl(buf, fd, XFS_IOC_FSGEOMETRY, &geom);
531 if (i >= 0 && geom.rtblocks)
532 rtpct = MIN(MAX(geom.rtblocks * 100 /
533 (geom.rtblocks + geom.datablocks), 1), 99);
542 for (i = 0; i < j; i++)
545 errtag = (random() % (XFS_ERRTAG_MAX-1)) + 1;
551 for (i = 0; i < j; i++)
554 errtag += (random() % (XFS_ERRTAG_MAX - errtag));
556 printf("Injecting failure on tag #%d\n", errtag);
557 err_inj.errtag = errtag;
559 srval = xfsctl(buf, fd, XFS_IOC_ERROR_INJECTION, &err_inj);
561 perror("fsstress - XFS_SYSSGI error injection call");
570 action.sa_handler = sg_handler;
571 sigemptyset(&action.sa_mask);
573 if (sigaction(SIGTERM, &action, 0)) {
574 perror("sigaction failed");
578 for (i = 0; i < nproc; i++) {
580 sigemptyset(&action.sa_mask);
581 action.sa_handler = SIG_DFL;
582 if (sigaction(SIGTERM, &action, 0))
584 action.sa_handler = sg_handler;
585 if (sigaction(SIGBUS, &action, 0))
587 #ifdef HAVE_SYS_PRCTL_H
588 prctl(PR_SET_PDEATHSIG, SIGKILL);
589 if (getppid() == 1) /* parent died already? */
593 char path[PATH_MAX + NAME_MAX + 2 + 11];
594 snprintf(path, sizeof(path), "%s/%s.%d",
596 if (freopen(path, "a", stdout) == NULL) {
597 perror("freopen logfile failed");
603 if (io_setup(128, &io_ctx) != 0) {
604 fprintf(stderr, "io_setup failed");
608 for (i = 0; !loops || (i < loops); i++)
611 if(io_destroy(io_ctx) != 0) {
612 fprintf(stderr, "io_destroy failed");
622 while (wait(&stat) > 0 && !should_stop) {
625 action.sa_flags = SA_RESTART;
626 sigaction(SIGTERM, &action, 0);
627 kill(-getpid(), SIGTERM);
628 while (wait(&stat) > 0)
634 srval = xfsctl(buf, fd, XFS_IOC_ERROR_CLEARALL, &err_inj);
636 fprintf(stderr, "Bad ej clear on %s fd=%d (%d).\n",
638 perror("xfsctl(XFS_IOC_ERROR_CLEARALL)");
651 add_string(struct print_string *str, const char *add)
653 int len = strlen(add);
658 if (len > (str->max - 1) - str->len) {
659 str->len = str->max - 1;
663 memcpy(str->buffer + str->len, add, len);
665 str->buffer[str->len] = '\0';
671 translate_flags(int flags, const char *delim,
672 const struct print_flags *flag_array)
674 int i, mask, first = 1;
677 if (!flag_str.buffer) {
678 flag_str.buffer = malloc(4096);
682 if (!flag_str.buffer)
685 flag_str.buffer[0] = '\0';
687 for (i = 0; flag_array[i].name && flags; i++) {
688 mask = flag_array[i].mask;
689 if ((flags & mask) != mask)
692 add = flag_array[i].name;
695 add_string(&flag_str, delim);
698 add_string(&flag_str, add);
701 /* Check whether there are any leftover flags. */
707 add_string(&flag_str, delim);
709 ret = snprintf(number, 11, "0x%x", flags) > 0;
710 if (ret > 0 && ret <= 11)
711 add_string(&flag_str, number);
714 return flag_str.buffer;
718 add_to_flist(int ft, int id, int parent)
724 if (ftp->nfiles == ftp->nslots) {
725 ftp->nslots += FLIST_SLOT_INCR;
726 ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
728 fep = &ftp->fents[ftp->nfiles++];
730 fep->parent = parent;
734 append_pathname(pathname_t *name, char *str)
740 /* attempting to append to a dir a zero length path */
741 if (len && *str == '/' && name->len == 0) {
742 fprintf(stderr, "fsstress: append_pathname failure\n");
743 assert(chdir(homedir) == 0);
748 name->path = realloc(name->path, name->len + 1 + len);
749 strcpy(&name->path[name->len], str);
754 attr_list_path(pathname_t *name,
756 const int buffersize,
758 attrlist_cursor_t *cursor)
760 char buf[NAME_MAX + 1];
764 if (flags != ATTR_DONTFOLLOW) {
769 rval = attr_list(name->path, buffer, buffersize, flags, cursor);
770 if (rval >= 0 || errno != ENAMETOOLONG)
772 separate_pathname(name, buf, &newname);
773 if (chdir(buf) == 0) {
774 rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
775 assert(chdir("..") == 0);
777 free_pathname(&newname);
782 attr_remove_path(pathname_t *name, const char *attrname, int flags)
784 char buf[NAME_MAX + 1];
788 rval = attr_remove(name->path, attrname, flags);
789 if (rval >= 0 || errno != ENAMETOOLONG)
791 separate_pathname(name, buf, &newname);
792 if (chdir(buf) == 0) {
793 rval = attr_remove_path(&newname, attrname, flags);
794 assert(chdir("..") == 0);
796 free_pathname(&newname);
801 attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
802 const int valuelength, int flags)
804 char buf[NAME_MAX + 1];
808 rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
809 if (rval >= 0 || errno != ENAMETOOLONG)
811 separate_pathname(name, buf, &newname);
812 if (chdir(buf) == 0) {
813 rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
815 assert(chdir("..") == 0);
817 free_pathname(&newname);
825 struct stat64 statbuf;
827 if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
829 assert(chdir(homedir) == 0);
830 fprintf(stderr, "fsstress: check_cwd failure\n");
837 * go thru flist and release all entries
839 * NOTE: this function shouldn't be called until the end of a process
847 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
856 creat_path(pathname_t *name, mode_t mode)
858 char buf[NAME_MAX + 1];
862 rval = creat(name->path, mode);
863 if (rval >= 0 || errno != ENAMETOOLONG)
865 separate_pathname(name, buf, &newname);
866 if (chdir(buf) == 0) {
867 rval = creat_path(&newname, mode);
868 assert(chdir("..") == 0);
870 free_pathname(&newname);
875 dcache_enter(int dirid, int slot)
877 dcache[dirid % NDCACHE] = slot;
885 for (i = 0; i < NDCACHE; i++)
890 dcache_lookup(int dirid)
895 i = dcache[dirid % NDCACHE];
896 if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
902 dcache_purge(int dirid)
906 dcp = &dcache[dirid % NDCACHE];
907 if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
912 * Delete the item from the list by
913 * moving last entry over the deleted one;
914 * unless deleted entry is the last one.
915 * Input: which file list array and which slot in array
918 del_from_flist(int ft, int slot)
924 dcache_purge(ftp->fents[slot].id);
925 if (slot != ftp->nfiles - 1) {
927 dcache_purge(ftp->fents[ftp->nfiles - 1].id);
928 ftp->fents[slot] = ftp->fents[--ftp->nfiles];
934 dirid_to_fent(int dirid)
940 if ((fep = dcache_lookup(dirid)))
942 flp = &flist[FT_DIR];
943 for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
944 if (fep->id == dirid) {
945 dcache_enter(dirid, fep - flp->fents);
955 struct stat64 statbuf;
963 dividend = (operations + execute_freq) / (execute_freq + 1);
964 sprintf(buf, "p%x", procid);
965 (void)mkdir(buf, 0777);
966 if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
970 top_ino = statbuf.st_ino;
971 homedir = getcwd(NULL, 0);
973 perror("getcwd failed");
980 for (opno = 0; opno < operations; opno++) {
981 if (execute_cmd && opno && opno % dividend == 0) {
983 printf("%d: execute command %s\n", opno,
985 rval = system(execute_cmd);
987 fprintf(stderr, "execute command failed with "
990 p = &ops[freq_table[random() % freq_table_size]];
991 p->func(opno, random());
993 * test for forced shutdown by stat'ing the test
994 * directory. If this stat returns EIO, assume
995 * the forced shutdown happened.
997 if (errtag != 0 && opno % 100 == 0) {
998 rval = stat64(".", &statbuf);
1000 fprintf(stderr, "Detected EIO\n");
1006 assert(chdir("..") == 0);
1011 sprintf(cmd, "rm -rf %s", buf);
1014 perror("cleaning up");
1020 * build up a pathname going thru the file entry and all
1021 * its parent entries
1022 * Return 0 on error, 1 on success;
1025 fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
1027 char buf[NAME_MAX + 1];
1035 /* build up parent directory name */
1036 if (fep->parent != -1) {
1037 pfep = dirid_to_fent(fep->parent);
1040 fprintf(stderr, "%d: fent-id = %d: can't find parent id: %d\n",
1041 procid, fep->id, fep->parent);
1046 e = fent_to_name(name, &flist[FT_DIR], pfep);
1049 append_pathname(name, "/");
1052 i = sprintf(buf, "%c%x", flp->tag, fep->id);
1053 namerandpad(fep->id, buf, i);
1054 append_pathname(name, buf);
1059 fix_parent(int oldid, int newid)
1066 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1067 for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
1068 if (fep->parent == oldid)
1069 fep->parent = newid;
1075 free_pathname(pathname_t *name)
1085 * Generate a filename of type ft.
1086 * If we have a fep which should be a directory then use it
1087 * as the parent path for this new filename i.e. prepend with it.
1090 generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
1092 char buf[NAME_MAX + 1];
1101 len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
1102 namerandpad(id, buf, len);
1104 /* prepend fep parent dir-name to it */
1106 e = fent_to_name(name, &flist[FT_DIR], fep);
1109 append_pathname(name, "/");
1111 append_pathname(name, buf);
1115 for (j = 0; !*v && j < ilistlen; j++) {
1116 if (ilist[j] == id) {
1126 * Input: "which" to choose the file-types eg. non-directory
1127 * Input: "r" to choose which file
1128 * Output: file-list, file-entry, name for the chosen file.
1129 * Output: verbose if chosen file is on the ilist.
1132 get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
1135 int totalsum = 0; /* total number of matching files */
1136 int partialsum = 0; /* partial sum of matching files */
1142 int e = 1; /* success */
1145 * go thru flist and add up number of files for each
1146 * category that matches with <which>.
1148 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1149 if (which & (1 << i))
1150 totalsum += flp->nfiles;
1152 if (totalsum == 0) {
1162 * Now we have possible matches between 0..totalsum-1.
1163 * And we use r to help us choose which one we want,
1164 * which when bounded by totalsum becomes x.
1166 x = (int)(r % totalsum);
1167 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
1168 if (which & (1 << i)) {
1169 if (x < partialsum + flp->nfiles) {
1171 /* found the matching file entry */
1172 fep = &flp->fents[x - partialsum];
1174 /* fill-in what we were asked for */
1176 e = fent_to_name(name, flp, fep);
1179 fprintf(stderr, "%d: failed to get path for entry:"
1180 " id=%d,parent=%d\n",
1181 procid, fep->id, fep->parent);
1190 /* turn on verbose if its an ilisted file */
1192 for (j = 0; !*v && j < ilistlen; j++) {
1193 if (ilist[j] == fep->id) {
1200 partialsum += flp->nfiles;
1204 fprintf(stderr, "fsstress: get_fname failure\n");
1211 init_pathname(pathname_t *name)
1218 lchown_path(pathname_t *name, uid_t owner, gid_t group)
1220 char buf[NAME_MAX + 1];
1224 rval = lchown(name->path, owner, group);
1225 if (rval >= 0 || errno != ENAMETOOLONG)
1227 separate_pathname(name, buf, &newname);
1228 if (chdir(buf) == 0) {
1229 rval = lchown_path(&newname, owner, group);
1230 assert(chdir("..") == 0);
1232 free_pathname(&newname);
1237 link_path(pathname_t *name1, pathname_t *name2)
1239 char buf1[NAME_MAX + 1];
1240 char buf2[NAME_MAX + 1];
1242 pathname_t newname1;
1243 pathname_t newname2;
1246 rval = link(name1->path, name2->path);
1247 if (rval >= 0 || errno != ENAMETOOLONG)
1249 separate_pathname(name1, buf1, &newname1);
1250 separate_pathname(name2, buf2, &newname2);
1251 if (strcmp(buf1, buf2) == 0) {
1252 if (chdir(buf1) == 0) {
1253 rval = link_path(&newname1, &newname2);
1254 assert(chdir("..") == 0);
1257 if (strcmp(buf1, "..") == 0)
1259 else if (strcmp(buf2, "..") == 0)
1261 else if (strlen(buf1) == 0)
1263 else if (strlen(buf2) == 0)
1266 down1 = MAX(newname1.len, 3 + name2->len) <=
1267 MAX(3 + name1->len, newname2.len);
1269 free_pathname(&newname2);
1270 append_pathname(&newname2, "../");
1271 append_pathname(&newname2, name2->path);
1272 if (chdir(buf1) == 0) {
1273 rval = link_path(&newname1, &newname2);
1274 assert(chdir("..") == 0);
1277 free_pathname(&newname1);
1278 append_pathname(&newname1, "../");
1279 append_pathname(&newname1, name1->path);
1280 if (chdir(buf2) == 0) {
1281 rval = link_path(&newname1, &newname2);
1282 assert(chdir("..") == 0);
1286 free_pathname(&newname1);
1287 free_pathname(&newname2);
1292 lstat64_path(pathname_t *name, struct stat64 *sbuf)
1294 char buf[NAME_MAX + 1];
1298 rval = lstat64(name->path, sbuf);
1299 if (rval >= 0 || errno != ENAMETOOLONG)
1301 separate_pathname(name, buf, &newname);
1302 if (chdir(buf) == 0) {
1303 rval = lstat64_path(&newname, sbuf);
1304 assert(chdir("..") == 0);
1306 free_pathname(&newname);
1311 make_freq_table(void)
1317 for (p = ops, f = 0; p < ops_end; p++)
1319 freq_table = malloc(f * sizeof(*freq_table));
1320 freq_table_size = f;
1321 for (p = ops, i = 0; p < ops_end; p++) {
1322 for (f = 0; f < p->freq; f++, i++)
1323 freq_table[i] = p->op;
1328 mkdir_path(pathname_t *name, mode_t mode)
1330 char buf[NAME_MAX + 1];
1334 rval = mkdir(name->path, mode);
1335 if (rval >= 0 || errno != ENAMETOOLONG)
1337 separate_pathname(name, buf, &newname);
1338 if (chdir(buf) == 0) {
1339 rval = mkdir_path(&newname, mode);
1340 assert(chdir("..") == 0);
1342 free_pathname(&newname);
1347 mknod_path(pathname_t *name, mode_t mode, dev_t dev)
1349 char buf[NAME_MAX + 1];
1353 rval = mknod(name->path, mode, dev);
1354 if (rval >= 0 || errno != ENAMETOOLONG)
1356 separate_pathname(name, buf, &newname);
1357 if (chdir(buf) == 0) {
1358 rval = mknod_path(&newname, mode, dev);
1359 assert(chdir("..") == 0);
1361 free_pathname(&newname);
1366 namerandpad(int id, char *buf, int i)
1369 static int buckets[] =
1370 { 2, 4, 8, 16, 32, 64, 128, NAME_MAX };
1376 bucket = (id ^ namerand) % (sizeof(buckets) / sizeof(buckets[0]));
1377 padmod = buckets[bucket] + 1 - i;
1380 padlen = (id ^ namerand) % padmod;
1382 memset(&buf[i], 'X', padlen);
1383 buf[i + padlen] = '\0';
1388 open_path(pathname_t *name, int oflag)
1390 char buf[NAME_MAX + 1];
1394 rval = open(name->path, oflag);
1395 if (rval >= 0 || errno != ENAMETOOLONG)
1397 separate_pathname(name, buf, &newname);
1398 if (chdir(buf) == 0) {
1399 rval = open_path(&newname, oflag);
1400 assert(chdir("..") == 0);
1402 free_pathname(&newname);
1407 opendir_path(pathname_t *name)
1409 char buf[NAME_MAX + 1];
1413 rval = opendir(name->path);
1414 if (rval || errno != ENAMETOOLONG)
1416 separate_pathname(name, buf, &newname);
1417 if (chdir(buf) == 0) {
1418 rval = opendir_path(&newname);
1419 assert(chdir("..") == 0);
1421 free_pathname(&newname);
1426 process_freq(char *arg)
1431 s = strchr(arg, '=');
1433 fprintf(stderr, "bad argument '%s'\n", arg);
1437 for (p = ops; p < ops_end; p++) {
1438 if (strcmp(arg, p->name) == 0) {
1443 fprintf(stderr, "can't find op type %s for -f\n", arg);
1448 readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
1450 char buf[NAME_MAX + 1];
1454 rval = readlink(name->path, lbuf, lbufsiz);
1455 if (rval >= 0 || errno != ENAMETOOLONG)
1457 separate_pathname(name, buf, &newname);
1458 if (chdir(buf) == 0) {
1459 rval = readlink_path(&newname, lbuf, lbufsiz);
1460 assert(chdir("..") == 0);
1462 free_pathname(&newname);
1467 rename_path(pathname_t *name1, pathname_t *name2)
1469 char buf1[NAME_MAX + 1];
1470 char buf2[NAME_MAX + 1];
1472 pathname_t newname1;
1473 pathname_t newname2;
1476 rval = rename(name1->path, name2->path);
1477 if (rval >= 0 || errno != ENAMETOOLONG)
1479 separate_pathname(name1, buf1, &newname1);
1480 separate_pathname(name2, buf2, &newname2);
1481 if (strcmp(buf1, buf2) == 0) {
1482 if (chdir(buf1) == 0) {
1483 rval = rename_path(&newname1, &newname2);
1484 assert(chdir("..") == 0);
1487 if (strcmp(buf1, "..") == 0)
1489 else if (strcmp(buf2, "..") == 0)
1491 else if (strlen(buf1) == 0)
1493 else if (strlen(buf2) == 0)
1496 down1 = MAX(newname1.len, 3 + name2->len) <=
1497 MAX(3 + name1->len, newname2.len);
1499 free_pathname(&newname2);
1500 append_pathname(&newname2, "../");
1501 append_pathname(&newname2, name2->path);
1502 if (chdir(buf1) == 0) {
1503 rval = rename_path(&newname1, &newname2);
1504 assert(chdir("..") == 0);
1507 free_pathname(&newname1);
1508 append_pathname(&newname1, "../");
1509 append_pathname(&newname1, name1->path);
1510 if (chdir(buf2) == 0) {
1511 rval = rename_path(&newname1, &newname2);
1512 assert(chdir("..") == 0);
1516 free_pathname(&newname1);
1517 free_pathname(&newname2);
1522 rmdir_path(pathname_t *name)
1524 char buf[NAME_MAX + 1];
1528 rval = rmdir(name->path);
1529 if (rval >= 0 || errno != ENAMETOOLONG)
1531 separate_pathname(name, buf, &newname);
1532 if (chdir(buf) == 0) {
1533 rval = rmdir_path(&newname);
1534 assert(chdir("..") == 0);
1536 free_pathname(&newname);
1541 separate_pathname(pathname_t *name, char *buf, pathname_t *newname)
1545 init_pathname(newname);
1546 slash = strchr(name->path, '/');
1547 if (slash == NULL) {
1552 strcpy(buf, name->path);
1554 append_pathname(newname, slash + 1);
1560 show_ops(int flag, char *lead_str)
1565 /* print in list form */
1568 for (p = ops; p < ops_end; p++) {
1569 if (lead_str != NULL && x+strlen(p->name)>=WIDTH-5)
1570 x=printf("%s%s", (p==ops)?"":"\n", lead_str);
1571 x+=printf("%s ", p->name);
1574 } else if (flag == 0) {
1575 /* Table view style */
1577 for (f = 0, p = ops; p < ops_end; p++)
1583 for (p = ops; p < ops_end; p++) {
1584 if (flag != 0 || p->freq > 0) {
1585 if (lead_str != NULL)
1586 printf("%s", lead_str);
1587 printf("%20s %d/%d %s\n",
1588 p->name, p->freq, f,
1589 (p->iswrite == 0) ? " " : "write op");
1593 /* Command line style */
1594 if (lead_str != NULL)
1595 printf("%s", lead_str);
1596 printf ("-z -s %ld -m %d -n %d -p %d \\\n", seed, idmodulo,
1598 for (p = ops; p < ops_end; p++)
1600 printf("-f %s=%d \\\n",p->name, p->freq);
1605 stat64_path(pathname_t *name, struct stat64 *sbuf)
1607 char buf[NAME_MAX + 1];
1611 rval = stat64(name->path, sbuf);
1612 if (rval >= 0 || errno != ENAMETOOLONG)
1614 separate_pathname(name, buf, &newname);
1615 if (chdir(buf) == 0) {
1616 rval = stat64_path(&newname, sbuf);
1617 assert(chdir("..") == 0);
1619 free_pathname(&newname);
1624 symlink_path(const char *name1, pathname_t *name)
1626 char buf[NAME_MAX + 1];
1630 if (!strcmp(name1, name->path)) {
1631 printf("yikes! %s %s\n", name1, name->path);
1635 rval = symlink(name1, name->path);
1636 if (rval >= 0 || errno != ENAMETOOLONG)
1638 separate_pathname(name, buf, &newname);
1639 if (chdir(buf) == 0) {
1640 rval = symlink_path(name1, &newname);
1641 assert(chdir("..") == 0);
1643 free_pathname(&newname);
1648 truncate64_path(pathname_t *name, off64_t length)
1650 char buf[NAME_MAX + 1];
1654 rval = truncate64(name->path, length);
1655 if (rval >= 0 || errno != ENAMETOOLONG)
1657 separate_pathname(name, buf, &newname);
1658 if (chdir(buf) == 0) {
1659 rval = truncate64_path(&newname, length);
1660 assert(chdir("..") == 0);
1662 free_pathname(&newname);
1667 unlink_path(pathname_t *name)
1669 char buf[NAME_MAX + 1];
1673 rval = unlink(name->path);
1674 if (rval >= 0 || errno != ENAMETOOLONG)
1676 separate_pathname(name, buf, &newname);
1677 if (chdir(buf) == 0) {
1678 rval = unlink_path(&newname);
1679 assert(chdir("..") == 0);
1681 free_pathname(&newname);
1688 printf("Usage: %s -H or\n", myprog);
1689 printf(" %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
1691 printf(" [-p nproc][-r len][-s seed][-v][-w][-x cmd][-z][-S][-X ncmd]\n");
1693 printf(" -c clean up the test directory after each run\n");
1694 printf(" -d dir specifies the base directory for operations\n");
1695 printf(" -e errtg specifies error injection stuff\n");
1696 printf(" -f op_name=freq changes the frequency of option name to freq\n");
1697 printf(" the valid operation names are:\n");
1699 printf(" -i filenum get verbose output for this nth file object\n");
1700 printf(" -l loops specifies the no. of times the testrun should loop.\n");
1701 printf(" *use 0 for infinite (default 1)\n");
1702 printf(" -m modulo uid/gid modulo for chown/chgrp (default 32)\n");
1703 printf(" -n nops specifies the no. of operations per process (default 1)\n");
1704 printf(" -o logfile specifies logfile name\n");
1705 printf(" -p nproc specifies the no. of processes (default 1)\n");
1706 printf(" -r specifies random name padding\n");
1707 printf(" -s seed specifies the seed for the random generator (default random)\n");
1708 printf(" -v specifies verbose mode\n");
1709 printf(" -w zeros frequencies of non-write operations\n");
1710 printf(" -x cmd execute command in the middle of operations\n");
1711 printf(" -z zeros frequencies of all operations\n");
1712 printf(" -S [c,t] prints the list of operations (omitting zero frequency) in command line or table style\n");
1713 printf(" -V specifies verifiable logging mode (omitting inode numbers)\n");
1714 printf(" -X ncmd number of calls to the -x command (default 1)\n");
1715 printf(" -H prints usage and exits\n");
1723 for (p = ops; p < ops_end; p++) {
1734 for (p = ops; p < ops_end; p++)
1738 void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
1741 snprintf(str, sz, "[%ld %ld %d %d %lld %lld]",
1742 verifiable_log ? -1: (long)s->st_ino,
1743 (long)s->st_nlink, s->st_uid, s->st_gid,
1744 (long long) s->st_blocks, (long long) s->st_size);
1748 afsync_f(int opno, long r)
1756 struct iocb *iocbs[] = { &iocb };
1757 struct io_event event;
1760 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1762 printf("%d/%d: afsync - no filename\n", procid, opno);
1766 fd = open_path(&f, O_WRONLY | O_DIRECT);
1767 e = fd < 0 ? errno : 0;
1771 printf("%d/%d: afsync - open %s failed %d\n",
1772 procid, opno, f.path, e);
1777 io_prep_fsync(&iocb, fd);
1778 if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
1780 printf("%d/%d: afsync - io_submit %s %d\n",
1781 procid, opno, f.path, e);
1786 if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
1788 printf("%d/%d: afsync - io_getevents failed %d\n",
1797 printf("%d/%d: afsync %s %d\n", procid, opno, f.path, e);
1804 allocsp_f(int opno, long r)
1809 struct xfs_flock64 fl;
1817 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1819 printf("%d/%d: allocsp - no filename\n", procid, opno);
1823 fd = open_path(&f, O_RDWR);
1824 e = fd < 0 ? errno : 0;
1828 printf("%d/%d: allocsp - open %s failed %d\n",
1829 procid, opno, f.path, e);
1833 if (fstat64(fd, &stb) < 0) {
1835 printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1836 procid, opno, f.path, errno);
1841 inode_info(st, sizeof(st), &stb, v);
1842 lr = ((int64_t)random() << 32) + random();
1843 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1845 fl.l_whence = SEEK_SET;
1848 e = xfsctl(f.path, fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1850 printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s%s %lld 0 %d\n",
1851 procid, opno, f.path, st, (long long)off, e);
1859 do_aio_rw(int opno, long r, int flags)
1863 struct dioattr diob;
1875 struct io_event event;
1876 struct iocb *iocbs[] = { &iocb };
1877 int iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
1880 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1882 printf("%d/%d: do_aio_rw - no filename\n", procid, opno);
1886 fd = open_path(&f, flags|O_DIRECT);
1887 e = fd < 0 ? errno : 0;
1891 printf("%d/%d: do_aio_rw - open %s failed %d\n",
1892 procid, opno, f.path, e);
1896 if (fstat64(fd, &stb) < 0) {
1898 printf("%d/%d: do_aio_rw - fstat64 %s failed %d\n",
1899 procid, opno, f.path, errno);
1904 inode_info(st, sizeof(st), &stb, v);
1905 if (!iswrite && stb.st_size == 0) {
1907 printf("%d/%d: do_aio_rw - %s%s zero size\n", procid, opno,
1913 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
1916 "%d/%d: do_aio_rw - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
1917 " fallback to stat()\n",
1918 procid, opno, f.path, st, errno);
1919 diob.d_mem = diob.d_miniosz = stb.st_blksize;
1920 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
1922 dio_env = getenv("XFS_DIO_MIN");
1924 diob.d_mem = diob.d_miniosz = atoi(dio_env);
1925 align = (int64_t)diob.d_miniosz;
1926 lr = ((int64_t)random() << 32) + random();
1927 len = (random() % FILELEN_MAX) + 1;
1928 len -= (len % align);
1931 else if (len > diob.d_maxiosz)
1932 len = diob.d_maxiosz;
1933 buf = memalign(diob.d_mem, len);
1936 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1937 off -= (off % align);
1939 memset(buf, nameseq & 0xff, len);
1940 io_prep_pwrite(&iocb, fd, buf, len, off);
1942 off = (off64_t)(lr % stb.st_size);
1943 off -= (off % align);
1944 io_prep_pread(&iocb, fd, buf, len, off);
1946 if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
1948 printf("%d/%d: %s - io_submit failed %d\n",
1949 procid, opno, iswrite ? "awrite" : "aread", e);
1954 if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
1956 printf("%d/%d: %s - io_getevents failed %d\n",
1957 procid, opno, iswrite ? "awrite" : "aread", e);
1963 e = event.res != len ? event.res2 : 0;
1966 printf("%d/%d: %s %s%s [%lld,%d] %d\n",
1967 procid, opno, iswrite ? "awrite" : "aread",
1968 f.path, st, (long long)off, (int)len, e);
1975 aread_f(int opno, long r)
1978 do_aio_rw(opno, r, O_RDONLY);
1983 attr_remove_f(int opno, long r)
1985 attrlist_ent_t *aep;
1989 attrlist_cursor_t cursor;
1998 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1999 append_pathname(&f, ".");
2001 bzero(&cursor, sizeof(cursor));
2003 bzero(buf, sizeof(buf));
2004 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
2008 alist = (attrlist_t *)buf;
2009 total += alist->al_count;
2010 } while (alist->al_more);
2013 printf("%d/%d: attr_remove - no attrs for %s\n",
2014 procid, opno, f.path);
2018 which = (int)(random() % total);
2019 bzero(&cursor, sizeof(cursor));
2023 bzero(buf, sizeof(buf));
2024 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
2028 alist = (attrlist_t *)buf;
2029 if (which < ent + alist->al_count) {
2030 aep = (attrlist_ent_t *)
2031 &buf[alist->al_offset[which - ent]];
2032 aname = aep->a_name;
2035 ent += alist->al_count;
2036 } while (alist->al_more);
2037 if (aname == NULL) {
2040 "%d/%d: attr_remove - name %d not found at %s\n",
2041 procid, opno, which, f.path);
2045 e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
2048 printf("%d/%d: attr_remove %s %s %d\n",
2049 procid, opno, f.path, aname, e);
2054 attr_set_f(int opno, long r)
2061 static int lengths[] = { 10, 100, 1000, 10000 };
2066 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2067 append_pathname(&f, ".");
2068 sprintf(aname, "a%x", nameseq++);
2069 li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
2070 len = (int)(random() % lengths[li]);
2074 memset(aval, nameseq & 0xff, len);
2075 e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
2080 printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
2086 awrite_f(int opno, long r)
2089 do_aio_rw(opno, r, O_WRONLY);
2094 bulkstat_f(int opno, long r)
2102 xfs_fsop_bulkreq_t bsr;
2105 nent = (r % 999) + 2;
2106 t = malloc(nent * sizeof(*t));
2107 fd = open(".", O_RDONLY);
2115 while (xfsctl(".", fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
2119 printf("%d/%d: bulkstat nent %d total %lld\n",
2120 procid, opno, nent, (long long)total);
2125 bulkstat1_f(int opno, long r)
2135 xfs_fsop_bulkreq_t bsr;
2138 good = random() & 1;
2140 /* use an inode we know exists */
2142 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2143 append_pathname(&f, ".");
2144 ino = stat64_path(&f, &s) < 0 ? (ino64_t)r : s.st_ino;
2149 * pick a random inode
2151 * note this can generate kernel warning messages
2152 * since bulkstat_one will read the disk block that
2153 * would contain a given inode even if that disk
2154 * block doesn't contain inodes.
2156 * this is detected later, but not until after the
2157 * warning is displayed.
2159 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
2165 fd = open(".", O_RDONLY);
2171 e = xfsctl(".", fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
2173 printf("%d/%d: bulkstat1 %s ino %lld %d\n",
2174 procid, opno, good?"real":"random",
2175 verifiable_log ? -1LL : (long long)ino, e);
2180 chown_f(int opno, long r)
2190 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2191 append_pathname(&f, ".");
2192 u = (uid_t)random();
2193 g = (gid_t)random();
2194 nbits = (int)(random() % idmodulo);
2195 u &= (1 << nbits) - 1;
2196 g &= (1 << nbits) - 1;
2197 e = lchown_path(&f, u, g) < 0 ? errno : 0;
2200 printf("%d/%d: chown %s %d/%d %d\n", procid, opno, f.path, (int)u, (int)g, e);
2204 /* reflink some arbitrary range of f1 to f2. */
2211 struct file_clone_range fcr;
2212 struct pathname fpath1;
2213 struct pathname fpath2;
2214 struct stat64 stat1;
2215 struct stat64 stat2;
2216 char inoinfo1[1024];
2217 char inoinfo2[1024];
2231 init_pathname(&fpath1);
2232 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2234 printf("%d/%d: clonerange read - no filename\n",
2239 init_pathname(&fpath2);
2240 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2242 printf("%d/%d: clonerange write - no filename\n",
2248 fd1 = open_path(&fpath1, O_RDONLY);
2249 e = fd1 < 0 ? errno : 0;
2253 printf("%d/%d: clonerange read - open %s failed %d\n",
2254 procid, opno, fpath1.path, e);
2258 fd2 = open_path(&fpath2, O_WRONLY);
2259 e = fd2 < 0 ? errno : 0;
2263 printf("%d/%d: clonerange write - open %s failed %d\n",
2264 procid, opno, fpath2.path, e);
2268 /* Get file stats */
2269 if (fstat64(fd1, &stat1) < 0) {
2271 printf("%d/%d: clonerange read - fstat64 %s failed %d\n",
2272 procid, opno, fpath1.path, errno);
2275 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2277 if (fstat64(fd2, &stat2) < 0) {
2279 printf("%d/%d: clonerange write - fstat64 %s failed %d\n",
2280 procid, opno, fpath2.path, errno);
2283 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2285 /* Calculate offsets */
2286 len = (random() % FILELEN_MAX) + 1;
2287 len &= ~(stat1.st_blksize - 1);
2289 len = stat1.st_blksize;
2290 if (len > stat1.st_size)
2291 len = stat1.st_size;
2293 lr = ((int64_t)random() << 32) + random();
2294 if (stat1.st_size == len)
2297 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2299 off1 &= ~(stat1.st_blksize - 1);
2302 * If srcfile == destfile, randomly generate destination ranges
2303 * until we find one that doesn't overlap the source range.
2305 max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
2307 lr = ((int64_t)random() << 32) + random();
2308 off2 = (off64_t)(lr % max_off2);
2310 off2 &= ~(stat2.st_blksize - 1);
2311 } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
2313 /* Clone data blocks */
2315 fcr.src_offset = off1;
2316 fcr.src_length = len;
2317 fcr.dest_offset = off2;
2319 ret = ioctl(fd2, FICLONERANGE, &fcr);
2320 e = ret < 0 ? errno : 0;
2322 printf("%d/%d: clonerange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
2324 fpath1.path, inoinfo1, (long long)off1, (long long)len,
2325 fpath2.path, inoinfo2, (long long)off2, (long long)len);
2328 printf(" error %d", e);
2337 free_pathname(&fpath2);
2339 free_pathname(&fpath1);
2343 /* copy some arbitrary range of f1 to f2. */
2349 #ifdef HAVE_COPY_FILE_RANGE
2350 struct pathname fpath1;
2351 struct pathname fpath2;
2352 struct stat64 stat1;
2353 struct stat64 stat2;
2354 char inoinfo1[1024];
2355 char inoinfo2[1024];
2370 init_pathname(&fpath1);
2371 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2373 printf("%d/%d: copyrange read - no filename\n",
2378 init_pathname(&fpath2);
2379 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2381 printf("%d/%d: copyrange write - no filename\n",
2387 fd1 = open_path(&fpath1, O_RDONLY);
2388 e = fd1 < 0 ? errno : 0;
2392 printf("%d/%d: copyrange read - open %s failed %d\n",
2393 procid, opno, fpath1.path, e);
2397 fd2 = open_path(&fpath2, O_WRONLY);
2398 e = fd2 < 0 ? errno : 0;
2402 printf("%d/%d: copyrange write - open %s failed %d\n",
2403 procid, opno, fpath2.path, e);
2407 /* Get file stats */
2408 if (fstat64(fd1, &stat1) < 0) {
2410 printf("%d/%d: copyrange read - fstat64 %s failed %d\n",
2411 procid, opno, fpath1.path, errno);
2414 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2416 if (fstat64(fd2, &stat2) < 0) {
2418 printf("%d/%d: copyrange write - fstat64 %s failed %d\n",
2419 procid, opno, fpath2.path, errno);
2422 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2424 /* Calculate offsets */
2425 len = (random() % FILELEN_MAX) + 1;
2427 len = stat1.st_blksize;
2428 if (len > stat1.st_size)
2429 len = stat1.st_size;
2431 lr = ((int64_t)random() << 32) + random();
2432 if (stat1.st_size == len)
2435 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2439 * If srcfile == destfile, randomly generate destination ranges
2440 * until we find one that doesn't overlap the source range.
2442 max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
2444 lr = ((int64_t)random() << 32) + random();
2445 off2 = (off64_t)(lr % max_off2);
2447 } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
2450 ret = syscall(__NR_copy_file_range, fd1, &off1, fd2, &off2,
2453 if (errno != EAGAIN || tries++ >= 300)
2455 } else if (ret > len)
2460 e = ret < 0 ? errno : 0;
2462 printf("%d/%d: copyrange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
2464 fpath1.path, inoinfo1, (long long)off1, (long long)len,
2465 fpath2.path, inoinfo2, (long long)off2, (long long)len);
2468 printf(" error %d", e);
2469 else if (len && ret > len)
2470 printf(" asked for %lld, copied %lld??\n",
2471 (long long)len, (long long)ret);
2480 free_pathname(&fpath2);
2482 free_pathname(&fpath1);
2486 /* dedupe some arbitrary range of f1 to f2...fn. */
2492 #ifdef FIDEDUPERANGE
2493 #define INFO_SZ 1024
2494 struct file_dedupe_range *fdr;
2495 struct pathname *fpath;
2496 struct stat64 *stat;
2508 if (flist[FT_REG].nfiles < 2)
2511 /* Pick somewhere between 2 and 128 files. */
2513 nr = random() % (flist[FT_REG].nfiles + 1);
2514 } while (nr < 2 || nr > 128);
2517 fdr = malloc(nr * sizeof(struct file_dedupe_range_info) +
2518 sizeof(struct file_dedupe_range));
2520 printf("%d/%d: line %d error %d\n",
2521 procid, opno, __LINE__, errno);
2524 memset(fdr, 0, (nr * sizeof(struct file_dedupe_range_info) +
2525 sizeof(struct file_dedupe_range)));
2527 fpath = calloc(nr, sizeof(struct pathname));
2529 printf("%d/%d: line %d error %d\n",
2530 procid, opno, __LINE__, errno);
2534 stat = calloc(nr, sizeof(struct stat64));
2536 printf("%d/%d: line %d error %d\n",
2537 procid, opno, __LINE__, errno);
2541 info = calloc(nr, INFO_SZ);
2543 printf("%d/%d: line %d error %d\n",
2544 procid, opno, __LINE__, errno);
2548 off = calloc(nr, sizeof(off64_t));
2550 printf("%d/%d: line %d error %d\n",
2551 procid, opno, __LINE__, errno);
2555 v = calloc(nr, sizeof(int));
2557 printf("%d/%d: line %d error %d\n",
2558 procid, opno, __LINE__, errno);
2561 fd = calloc(nr, sizeof(int));
2563 printf("%d/%d: line %d error %d\n",
2564 procid, opno, __LINE__, errno);
2567 memset(fd, 0xFF, nr * sizeof(int));
2569 /* Get paths for all files */
2570 for (i = 0; i < nr; i++)
2571 init_pathname(&fpath[i]);
2573 if (!get_fname(FT_REGm, r, &fpath[0], NULL, NULL, &v[0])) {
2575 printf("%d/%d: deduperange read - no filename\n",
2580 for (i = 1; i < nr; i++) {
2581 if (!get_fname(FT_REGm, random(), &fpath[i], NULL, NULL, &v[i])) {
2583 printf("%d/%d: deduperange write - no filename\n",
2590 fd[0] = open_path(&fpath[0], O_RDONLY);
2591 e = fd[0] < 0 ? errno : 0;
2595 printf("%d/%d: deduperange read - open %s failed %d\n",
2596 procid, opno, fpath[0].path, e);
2600 for (i = 1; i < nr; i++) {
2601 fd[i] = open_path(&fpath[i], O_WRONLY);
2602 e = fd[i] < 0 ? errno : 0;
2606 printf("%d/%d: deduperange write - open %s failed %d\n",
2607 procid, opno, fpath[i].path, e);
2612 /* Get file stats */
2613 if (fstat64(fd[0], &stat[0]) < 0) {
2615 printf("%d/%d: deduperange read - fstat64 %s failed %d\n",
2616 procid, opno, fpath[0].path, errno);
2620 inode_info(&info[0], INFO_SZ, &stat[0], v[0]);
2622 for (i = 1; i < nr; i++) {
2623 if (fstat64(fd[i], &stat[i]) < 0) {
2625 printf("%d/%d: deduperange write - fstat64 %s failed %d\n",
2626 procid, opno, fpath[i].path, errno);
2629 inode_info(&info[i * INFO_SZ], INFO_SZ, &stat[i], v[i]);
2632 /* Never try to dedupe more than half of the src file. */
2633 len = (random() % FILELEN_MAX) + 1;
2634 len &= ~(stat[0].st_blksize - 1);
2636 len = stat[0].st_blksize / 2;
2637 if (len > stat[0].st_size / 2)
2638 len = stat[0].st_size / 2;
2640 /* Calculate offsets */
2641 lr = ((int64_t)random() << 32) + random();
2642 if (stat[0].st_size == len)
2645 off[0] = (off64_t)(lr % MIN(stat[0].st_size - len, MAXFSIZE));
2647 off[0] &= ~(stat[0].st_blksize - 1);
2650 * If srcfile == destfile[i], randomly generate destination ranges
2651 * until we find one that doesn't overlap the source range.
2653 for (i = 1; i < nr; i++) {
2657 lr = ((int64_t)random() << 32) + random();
2658 if (stat[i].st_size <= len)
2661 off[i] = (off64_t)(lr % MIN(stat[i].st_size - len, MAXFSIZE));
2663 off[i] &= ~(stat[i].st_blksize - 1);
2664 } while (stat[0].st_ino == stat[i].st_ino &&
2665 llabs(off[i] - off[0]) < len &&
2669 /* Clone data blocks */
2670 fdr->src_offset = off[0];
2671 fdr->src_length = len;
2672 fdr->dest_count = nr - 1;
2673 for (i = 1; i < nr; i++) {
2674 fdr->info[i - 1].dest_fd = fd[i];
2675 fdr->info[i - 1].dest_offset = off[i];
2678 ret = ioctl(fd[0], FIDEDUPERANGE, fdr);
2679 e = ret < 0 ? errno : 0;
2681 printf("%d/%d: deduperange from %s%s [%lld,%lld]",
2683 fpath[0].path, &info[0], (long long)off[0],
2686 printf(" error %d", e);
2692 for (i = 1; i < nr; i++) {
2693 e = fdr->info[i - 1].status < 0 ? fdr->info[i - 1].status : 0;
2695 printf("%d/%d: ...to %s%s [%lld,%lld]",
2697 fpath[i].path, &info[i * INFO_SZ],
2698 (long long)off[i], (long long)len);
2699 if (fdr->info[i - 1].status < 0)
2700 printf(" error %d", e);
2701 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_SAME)
2702 printf(" %llu bytes deduplicated",
2703 fdr->info[i - 1].bytes_deduped);
2704 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_DIFFERS)
2705 printf(" differed");
2711 for (i = 0; i < nr; i++)
2715 for (i = 0; i < nr; i++)
2716 free_pathname(&fpath[i]);
2735 setxattr_f(int opno, long r)
2737 #ifdef XFS_XFLAG_EXTSIZE
2747 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2748 append_pathname(&f, ".");
2749 fd = open_path(&f, O_RDWR);
2750 e = fd < 0 ? errno : 0;
2755 e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
2756 nbits = (int)(random() % e);
2757 p &= (1 << nbits) - 1;
2759 if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
2761 e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
2764 printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
2771 splice_f(int opno, long r)
2773 struct pathname fpath1;
2774 struct pathname fpath2;
2775 struct stat64 stat1;
2776 struct stat64 stat2;
2777 char inoinfo1[1024];
2778 char inoinfo2[1024];
2782 loff_t offset1, offset2;
2789 ssize_t ret1 = 0, ret2 = 0;
2795 init_pathname(&fpath1);
2796 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2798 printf("%d/%d: splice read - no filename\n",
2803 init_pathname(&fpath2);
2804 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2806 printf("%d/%d: splice write - no filename\n",
2812 fd1 = open_path(&fpath1, O_RDONLY);
2813 e = fd1 < 0 ? errno : 0;
2817 printf("%d/%d: splice read - open %s failed %d\n",
2818 procid, opno, fpath1.path, e);
2822 fd2 = open_path(&fpath2, O_WRONLY);
2823 e = fd2 < 0 ? errno : 0;
2827 printf("%d/%d: splice write - open %s failed %d\n",
2828 procid, opno, fpath2.path, e);
2832 /* Get file stats */
2833 if (fstat64(fd1, &stat1) < 0) {
2835 printf("%d/%d: splice read - fstat64 %s failed %d\n",
2836 procid, opno, fpath1.path, errno);
2839 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2841 if (fstat64(fd2, &stat2) < 0) {
2843 printf("%d/%d: splice write - fstat64 %s failed %d\n",
2844 procid, opno, fpath2.path, errno);
2847 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2849 /* Calculate offsets */
2850 len = (random() % FILELEN_MAX) + 1;
2852 len = stat1.st_blksize;
2853 if (len > stat1.st_size)
2854 len = stat1.st_size;
2856 lr = ((int64_t)random() << 32) + random();
2857 if (stat1.st_size == len)
2860 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2864 * splice can overlap write, so the offset of the target file can be
2865 * any number. But to avoid too large offset, add a clamp of 1024 blocks
2866 * past the current dest file EOF
2868 lr = ((int64_t)random() << 32) + random();
2869 off2 = (off64_t)(lr % MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE));
2872 * Due to len, off1 and off2 will be changed later, so record the
2873 * original number at here
2879 /* Pipe initialize */
2880 if (pipe(filedes) < 0) {
2882 printf("%d/%d: splice - pipe failed %d\n",
2883 procid, opno, errno);
2891 /* move to pipe buffer */
2892 ret1 = splice(fd1, &off1, filedes[1], NULL, len, 0);
2898 /* move from pipe buffer to dst file */
2900 ret2 = splice(filedes[0], NULL, fd2, &off2, bytes, 0);
2913 if (ret1 < 0 || ret2 < 0)
2918 printf("%d/%d: splice %s%s [%lld,%lld] -> %s%s [%lld,%lld] %d",
2920 fpath1.path, inoinfo1, (long long)offset1, (long long)length,
2921 fpath2.path, inoinfo2, (long long)offset2, (long long)length, e);
2923 if (length && length > total)
2924 printf(" asked for %lld, spliced %lld??\n",
2925 (long long)length, (long long)total);
2936 free_pathname(&fpath2);
2938 free_pathname(&fpath1);
2942 creat_f(int opno, long r)
2957 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
2962 e1 = (random() % 100);
2963 type = rtpct ? ((e1 > rtpct) ? FT_REG : FT_RTF) : FT_REG;
2965 if (type == FT_RTF) /* rt always gets an extsize */
2966 extsize = (random() % 10) + 1;
2967 else if (e1 < 10) /* one-in-ten get an extsize */
2968 extsize = random() % 1024;
2972 e = generate_fname(fep, type, &f, &id, &v);
2976 (void)fent_to_name(&f, &flist[FT_DIR], fep);
2977 printf("%d/%d: creat - no filename from %s\n",
2978 procid, opno, f.path);
2983 fd = creat_path(&f, 0666);
2984 e = fd < 0 ? errno : 0;
2989 xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
2990 if (type == FT_RTF) {
2991 a.fsx_xflags |= XFS_XFLAG_REALTIME;
2992 a.fsx_extsize = extsize *
2993 geom.rtextsize * geom.blocksize;
2995 } else if (extsize) {
2996 a.fsx_xflags |= XFS_XFLAG_EXTSIZE;
2997 a.fsx_extsize = extsize * geom.blocksize;
3000 if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
3003 add_to_flist(type, id, parid);
3007 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
3008 extsize ? a.fsx_extsize : 0, e, e1);
3009 printf("%d/%d: creat add id=%d,parent=%d\n", procid, opno, id, parid);
3015 dread_f(int opno, long r)
3019 struct dioattr diob;
3032 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3034 printf("%d/%d: dread - no filename\n", procid, opno);
3038 fd = open_path(&f, O_RDONLY|O_DIRECT);
3039 e = fd < 0 ? errno : 0;
3043 printf("%d/%d: dread - open %s failed %d\n",
3044 procid, opno, f.path, e);
3048 if (fstat64(fd, &stb) < 0) {
3050 printf("%d/%d: dread - fstat64 %s failed %d\n",
3051 procid, opno, f.path, errno);
3056 inode_info(st, sizeof(st), &stb, v);
3057 if (stb.st_size == 0) {
3059 printf("%d/%d: dread - %s%s zero size\n", procid, opno,
3065 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3068 "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
3069 " fallback to stat()\n",
3070 procid, opno, f.path, st, errno);
3071 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3072 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3075 dio_env = getenv("XFS_DIO_MIN");
3077 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3079 align = (int64_t)diob.d_miniosz;
3080 lr = ((int64_t)random() << 32) + random();
3081 off = (off64_t)(lr % stb.st_size);
3082 off -= (off % align);
3083 lseek64(fd, off, SEEK_SET);
3084 len = (random() % FILELEN_MAX) + 1;
3085 len -= (len % align);
3088 else if (len > diob.d_maxiosz)
3089 len = diob.d_maxiosz;
3090 buf = memalign(diob.d_mem, len);
3091 e = read(fd, buf, len) < 0 ? errno : 0;
3094 printf("%d/%d: dread %s%s [%lld,%d] %d\n",
3095 procid, opno, f.path, st, (long long)off, (int)len, e);
3101 dwrite_f(int opno, long r)
3105 struct dioattr diob;
3118 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3120 printf("%d/%d: dwrite - no filename\n", procid, opno);
3124 fd = open_path(&f, O_WRONLY|O_DIRECT);
3125 e = fd < 0 ? errno : 0;
3129 printf("%d/%d: dwrite - open %s failed %d\n",
3130 procid, opno, f.path, e);
3134 if (fstat64(fd, &stb) < 0) {
3136 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
3137 procid, opno, f.path, errno);
3142 inode_info(st, sizeof(st), &stb, v);
3143 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3145 printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
3146 " %s%s return %d, fallback to stat()\n",
3147 procid, opno, f.path, st, errno);
3148 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3149 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3152 dio_env = getenv("XFS_DIO_MIN");
3154 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3156 align = (int64_t)diob.d_miniosz;
3157 lr = ((int64_t)random() << 32) + random();
3158 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3159 off -= (off % align);
3160 lseek64(fd, off, SEEK_SET);
3161 len = (random() % FILELEN_MAX) + 1;
3162 len -= (len % align);
3165 else if (len > diob.d_maxiosz)
3166 len = diob.d_maxiosz;
3167 buf = memalign(diob.d_mem, len);
3169 lseek64(fd, off, SEEK_SET);
3170 memset(buf, nameseq & 0xff, len);
3171 e = write(fd, buf, len) < 0 ? errno : 0;
3174 printf("%d/%d: dwrite %s%s [%lld,%d] %d\n",
3175 procid, opno, f.path, st, (long long)off, (int)len, e);
3181 #ifdef HAVE_LINUX_FALLOC_H
3182 struct print_flags falloc_flags [] = {
3183 { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"},
3184 { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"},
3185 { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
3186 { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
3187 { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
3188 { FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
3192 #define translate_falloc_flags(mode) \
3193 ({translate_flags(mode, "|", falloc_flags);})
3197 do_fallocate(int opno, long r, int mode)
3199 #ifdef HAVE_LINUX_FALLOC_H
3211 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3213 printf("%d/%d: do_fallocate - no filename\n", procid, opno);
3217 fd = open_path(&f, O_RDWR);
3220 printf("%d/%d: do_fallocate - open %s failed %d\n",
3221 procid, opno, f.path, errno);
3226 if (fstat64(fd, &stb) < 0) {
3228 printf("%d/%d: do_fallocate - fstat64 %s failed %d\n",
3229 procid, opno, f.path, errno);
3234 inode_info(st, sizeof(st), &stb, v);
3235 lr = ((int64_t)random() << 32) + random();
3236 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3238 len = (off64_t)(random() % (1024 * 1024));
3240 * Collapse/insert range requires off and len to be block aligned,
3241 * make it more likely to be the case.
3243 if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) &&
3245 off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3246 len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3248 mode |= FALLOC_FL_KEEP_SIZE & random();
3249 e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
3251 printf("%d/%d: fallocate(%s) %s %st %lld %lld %d\n",
3252 procid, opno, translate_falloc_flags(mode),
3253 f.path, st, (long long)off, (long long)len, e);
3260 fallocate_f(int opno, long r)
3262 #ifdef HAVE_LINUX_FALLOC_H
3263 do_fallocate(opno, r, 0);
3268 fdatasync_f(int opno, long r)
3276 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3278 printf("%d/%d: fdatasync - no filename\n",
3283 fd = open_path(&f, O_WRONLY);
3284 e = fd < 0 ? errno : 0;
3288 printf("%d/%d: fdatasync - open %s failed %d\n",
3289 procid, opno, f.path, e);
3293 e = fdatasync(fd) < 0 ? errno : 0;
3295 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
3300 #ifdef HAVE_LINUX_FIEMAP_H
3301 struct print_flags fiemap_flags[] = {
3302 { FIEMAP_FLAG_SYNC, "SYNC"},
3303 { FIEMAP_FLAG_XATTR, "XATTR"},
3307 #define translate_fiemap_flags(mode) \
3308 ({translate_flags(mode, "|", fiemap_flags);})
3312 fiemap_f(int opno, long r)
3314 #ifdef HAVE_LINUX_FIEMAP_H
3324 struct fiemap *fiemap;
3327 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3329 printf("%d/%d: fiemap - no filename\n", procid, opno);
3333 fd = open_path(&f, O_RDWR);
3334 e = fd < 0 ? errno : 0;
3338 printf("%d/%d: fiemap - open %s failed %d\n",
3339 procid, opno, f.path, e);
3343 if (fstat64(fd, &stb) < 0) {
3345 printf("%d/%d: fiemap - fstat64 %s failed %d\n",
3346 procid, opno, f.path, errno);
3351 inode_info(st, sizeof(st), &stb, v);
3352 blocks_to_map = random() & 0xffff;
3353 fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) +
3354 (blocks_to_map * sizeof(struct fiemap_extent)));
3357 printf("%d/%d: malloc failed \n", procid, opno);
3362 lr = ((int64_t)random() << 32) + random();
3363 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3365 fiemap->fm_flags = random() & (FIEMAP_FLAGS_COMPAT | 0x10000);
3366 fiemap->fm_extent_count = blocks_to_map;
3367 fiemap->fm_mapped_extents = random() & 0xffff;
3368 fiemap->fm_start = off;
3369 fiemap->fm_length = ((int64_t)random() << 32) + random();
3371 e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
3373 printf("%d/%d: ioctl(FIEMAP) %s%s %lld %lld (%s) %d\n",
3374 procid, opno, f.path, st, (long long)fiemap->fm_start,
3375 (long long) fiemap->fm_length,
3376 translate_fiemap_flags(fiemap->fm_flags), e);
3384 freesp_f(int opno, long r)
3389 struct xfs_flock64 fl;
3397 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3399 printf("%d/%d: freesp - no filename\n", procid, opno);
3403 fd = open_path(&f, O_RDWR);
3404 e = fd < 0 ? errno : 0;
3408 printf("%d/%d: freesp - open %s failed %d\n",
3409 procid, opno, f.path, e);
3413 if (fstat64(fd, &stb) < 0) {
3415 printf("%d/%d: freesp - fstat64 %s failed %d\n",
3416 procid, opno, f.path, errno);
3421 inode_info(st, sizeof(st), &stb, v);
3422 lr = ((int64_t)random() << 32) + random();
3423 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3425 fl.l_whence = SEEK_SET;
3428 e = xfsctl(f.path, fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
3430 printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s%s %lld 0 %d\n",
3431 procid, opno, f.path, st, (long long)off, e);
3437 fsync_f(int opno, long r)
3445 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3447 printf("%d/%d: fsync - no filename\n", procid, opno);
3451 fd = open_path(&f, O_WRONLY);
3452 e = fd < 0 ? errno : 0;
3456 printf("%d/%d: fsync - open %s failed %d\n",
3457 procid, opno, f.path, e);
3461 e = fsync(fd) < 0 ? errno : 0;
3463 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
3469 getattr_f(int opno, long r)
3478 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
3479 append_pathname(&f, ".");
3480 fd = open_path(&f, O_RDWR);
3481 e = fd < 0 ? errno : 0;
3484 e = ioctl(fd, FS_IOC_GETFLAGS, &fl);
3486 printf("%d/%d: getattr %s %u %d\n", procid, opno, f.path, fl, e);
3492 getdents_f(int opno, long r)
3499 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
3500 append_pathname(&f, ".");
3501 dir = opendir_path(&f);
3505 printf("%d/%d: getdents - can't open %s\n",
3506 procid, opno, f.path);
3510 while (readdir64(dir) != NULL)
3513 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
3519 link_f(int opno, long r)
3532 if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
3534 printf("%d/%d: link - no file\n", procid, opno);
3538 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
3544 e = generate_fname(fep, flp - flist, &l, &id, &v1);
3548 (void)fent_to_name(&l, &flist[FT_DIR], fep);
3549 printf("%d/%d: link - no filename from %s\n",
3550 procid, opno, l.path);
3556 e = link_path(&f, &l) < 0 ? errno : 0;
3559 add_to_flist(flp - flist, id, parid);
3561 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
3563 printf("%d/%d: link add id=%d,parent=%d\n", procid, opno, id, parid);
3570 mkdir_f(int opno, long r)
3580 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3585 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
3589 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3590 printf("%d/%d: mkdir - no filename from %s\n",
3591 procid, opno, f.path);
3596 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
3599 add_to_flist(FT_DIR, id, parid);
3601 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
3602 printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
3608 mknod_f(int opno, long r)
3618 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3623 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
3627 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3628 printf("%d/%d: mknod - no filename from %s\n",
3629 procid, opno, f.path);
3634 e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0;
3637 add_to_flist(FT_DEV, id, parid);
3639 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
3640 printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
3645 #ifdef HAVE_SYS_MMAN_H
3646 struct print_flags mmap_flags[] = {
3647 { MAP_SHARED, "SHARED"},
3648 { MAP_PRIVATE, "PRIVATE"},
3652 #define translate_mmap_flags(flags) \
3653 ({translate_flags(flags, "|", mmap_flags);})
3657 do_mmap(int opno, long r, int prot)
3659 #ifdef HAVE_SYS_MMAN_H
3671 sigjmp_buf sigbus_jmpbuf;
3674 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3676 printf("%d/%d: do_mmap - no filename\n", procid, opno);
3680 fd = open_path(&f, O_RDWR);
3681 e = fd < 0 ? errno : 0;
3685 printf("%d/%d: do_mmap - open %s failed %d\n",
3686 procid, opno, f.path, e);
3690 if (fstat64(fd, &stb) < 0) {
3692 printf("%d/%d: do_mmap - fstat64 %s failed %d\n",
3693 procid, opno, f.path, errno);
3698 inode_info(st, sizeof(st), &stb, v);
3699 if (stb.st_size == 0) {
3701 printf("%d/%d: do_mmap - %s%s zero size\n", procid, opno,
3708 lr = ((int64_t)random() << 32) + random();
3709 off = (off64_t)(lr % stb.st_size);
3710 off &= (off64_t)(~(sysconf(_SC_PAGE_SIZE) - 1));
3711 len = (size_t)(random() % MIN(stb.st_size - off, FILELEN_MAX)) + 1;
3713 flags = (random() % 2) ? MAP_SHARED : MAP_PRIVATE;
3714 addr = mmap(NULL, len, prot, flags, fd, off);
3715 e = (addr == MAP_FAILED) ? errno : 0;
3718 printf("%d/%d: do_mmap - mmap failed %s%s [%lld,%d,%s] %d\n",
3719 procid, opno, f.path, st, (long long)off,
3720 (int)len, translate_mmap_flags(flags), e);
3726 if (prot & PROT_WRITE) {
3727 if ((e = sigsetjmp(sigbus_jmpbuf, 1)) == 0) {
3728 sigbus_jmp = &sigbus_jmpbuf;
3729 memset(addr, nameseq & 0xff, len);
3733 if ((buf = malloc(len)) != NULL) {
3734 memcpy(buf, addr, len);
3739 /* set NULL to stop other functions from doing siglongjmp */
3743 printf("%d/%d: %s %s%s [%lld,%d,%s] %s\n",
3744 procid, opno, (prot & PROT_WRITE) ? "mwrite" : "mread",
3745 f.path, st, (long long)off, (int)len,
3746 translate_mmap_flags(flags),
3747 (e == 0) ? "0" : "Bus error");
3755 mread_f(int opno, long r)
3757 #ifdef HAVE_SYS_MMAN_H
3758 do_mmap(opno, r, PROT_READ);
3763 mwrite_f(int opno, long r)
3765 #ifdef HAVE_SYS_MMAN_H
3766 do_mmap(opno, r, PROT_WRITE);
3771 punch_f(int opno, long r)
3773 #ifdef HAVE_LINUX_FALLOC_H
3774 do_fallocate(opno, r, FALLOC_FL_PUNCH_HOLE);
3779 zero_f(int opno, long r)
3781 #ifdef HAVE_LINUX_FALLOC_H
3782 do_fallocate(opno, r, FALLOC_FL_ZERO_RANGE);
3787 collapse_f(int opno, long r)
3789 #ifdef HAVE_LINUX_FALLOC_H
3790 do_fallocate(opno, r, FALLOC_FL_COLLAPSE_RANGE);
3795 insert_f(int opno, long r)
3797 #ifdef HAVE_LINUX_FALLOC_H
3798 do_fallocate(opno, r, FALLOC_FL_INSERT_RANGE);
3803 read_f(int opno, long r)
3817 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3819 printf("%d/%d: read - no filename\n", procid, opno);
3823 fd = open_path(&f, O_RDONLY);
3824 e = fd < 0 ? errno : 0;
3828 printf("%d/%d: read - open %s failed %d\n",
3829 procid, opno, f.path, e);
3833 if (fstat64(fd, &stb) < 0) {
3835 printf("%d/%d: read - fstat64 %s failed %d\n",
3836 procid, opno, f.path, errno);
3841 inode_info(st, sizeof(st), &stb, v);
3842 if (stb.st_size == 0) {
3844 printf("%d/%d: read - %s%s zero size\n", procid, opno,
3850 lr = ((int64_t)random() << 32) + random();
3851 off = (off64_t)(lr % stb.st_size);
3852 lseek64(fd, off, SEEK_SET);
3853 len = (random() % FILELEN_MAX) + 1;
3855 e = read(fd, buf, len) < 0 ? errno : 0;
3858 printf("%d/%d: read %s%s [%lld,%d] %d\n",
3859 procid, opno, f.path, st, (long long)off, (int)len, e);
3865 readlink_f(int opno, long r)
3873 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
3875 printf("%d/%d: readlink - no filename\n", procid, opno);
3879 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
3882 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
3887 readv_f(int opno, long r)
3899 struct iovec *iov = NULL;
3906 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3908 printf("%d/%d: readv - no filename\n", procid, opno);
3912 fd = open_path(&f, O_RDONLY);
3913 e = fd < 0 ? errno : 0;
3917 printf("%d/%d: readv - open %s failed %d\n",
3918 procid, opno, f.path, e);
3922 if (fstat64(fd, &stb) < 0) {
3924 printf("%d/%d: readv - fstat64 %s failed %d\n",
3925 procid, opno, f.path, errno);
3930 inode_info(st, sizeof(st), &stb, v);
3931 if (stb.st_size == 0) {
3933 printf("%d/%d: readv - %s%s zero size\n", procid, opno,
3939 lr = ((int64_t)random() << 32) + random();
3940 off = (off64_t)(lr % stb.st_size);
3941 lseek64(fd, off, SEEK_SET);
3942 len = (random() % FILELEN_MAX) + 1;
3945 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
3946 iov = calloc(iovcnt, sizeof(struct iovec));
3947 iovl = len / iovcnt;
3949 for (i=0; i<iovcnt; i++) {
3950 (iov + i)->iov_base = (buf + iovb);
3951 (iov + i)->iov_len = iovl;
3955 e = readv(fd, iov, iovcnt) < 0 ? errno : 0;
3958 printf("%d/%d: readv %s%s [%lld,%d,%d] %d\n",
3959 procid, opno, f.path, st, (long long)off, (int)iovl,
3966 rename_f(int opno, long r)
3980 /* get an existing path for the source of the rename */
3982 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
3984 printf("%d/%d: rename - no filename\n", procid, opno);
3989 /* get an existing directory for the destination parent directory name */
3990 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
3996 /* generate a new path using an existing parent directory in name */
3997 init_pathname(&newf);
3998 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
4002 (void)fent_to_name(&f, &flist[FT_DIR], dfep);
4003 printf("%d/%d: rename - no filename from %s\n",
4004 procid, opno, f.path);
4006 free_pathname(&newf);
4010 e = rename_path(&f, &newf) < 0 ? errno : 0;
4013 if (flp - flist == FT_DIR) {
4015 fix_parent(oldid, id);
4017 del_from_flist(flp - flist, fep - flp->fents);
4018 add_to_flist(flp - flist, id, parid);
4021 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
4024 printf("%d/%d: rename del entry: id=%d,parent=%d\n",
4025 procid, opno, fep->id, fep->parent);
4026 printf("%d/%d: rename add entry: id=%d,parent=%d\n",
4027 procid, opno, id, parid);
4030 free_pathname(&newf);
4035 resvsp_f(int opno, long r)
4040 struct xfs_flock64 fl;
4048 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4050 printf("%d/%d: resvsp - no filename\n", procid, opno);
4054 fd = open_path(&f, O_RDWR);
4055 e = fd < 0 ? errno : 0;
4059 printf("%d/%d: resvsp - open %s failed %d\n",
4060 procid, opno, f.path, e);
4064 if (fstat64(fd, &stb) < 0) {
4066 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
4067 procid, opno, f.path, errno);
4072 inode_info(st, sizeof(st), &stb, v);
4073 lr = ((int64_t)random() << 32) + random();
4074 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4076 fl.l_whence = SEEK_SET;
4078 fl.l_len = (off64_t)(random() % (1024 * 1024));
4079 e = xfsctl(f.path, fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
4081 printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s%s %lld %lld %d\n",
4082 procid, opno, f.path, st,
4083 (long long)off, (long long)fl.l_len, e);
4089 rmdir_f(int opno, long r)
4097 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
4099 printf("%d/%d: rmdir - no directory\n", procid, opno);
4103 e = rmdir_path(&f) < 0 ? errno : 0;
4106 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
4108 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
4110 printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
4111 procid, opno, fep->id, fep->parent);
4117 setattr_f(int opno, long r)
4126 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
4127 append_pathname(&f, ".");
4128 fd = open_path(&f, O_RDWR);
4129 e = fd < 0 ? errno : 0;
4132 fl = attr_mask & (uint)random();
4133 e = ioctl(fd, FS_IOC_SETFLAGS, &fl);
4135 printf("%d/%d: setattr %s %x %d\n", procid, opno, f.path, fl, e);
4141 stat_f(int opno, long r)
4149 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
4151 printf("%d/%d: stat - no entries\n", procid, opno);
4155 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
4158 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
4163 symlink_f(int opno, long r)
4176 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
4181 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
4185 (void)fent_to_name(&f, &flist[FT_DIR], fep);
4186 printf("%d/%d: symlink - no filename from %s\n",
4187 procid, opno, f.path);
4192 len = (int)(random() % PATH_MAX);
4193 val = malloc(len + 1);
4195 memset(val, 'x', len);
4197 for (i = 10; i < len - 1; i += 10)
4199 e = symlink_path(val, &f) < 0 ? errno : 0;
4202 add_to_flist(FT_SYM, id, parid);
4205 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
4206 printf("%d/%d: symlink add id=%d,parent=%d\n", procid, opno, id, parid);
4213 sync_f(int opno, long r)
4217 printf("%d/%d: sync\n", procid, opno);
4221 truncate_f(int opno, long r)
4232 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4234 printf("%d/%d: truncate - no filename\n", procid, opno);
4238 e = stat64_path(&f, &stb) < 0 ? errno : 0;
4242 printf("%d/%d: truncate - stat64 %s failed %d\n",
4243 procid, opno, f.path, e);
4247 inode_info(st, sizeof(st), &stb, v);
4248 lr = ((int64_t)random() << 32) + random();
4249 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4251 e = truncate64_path(&f, off) < 0 ? errno : 0;
4254 printf("%d/%d: truncate %s%s %lld %d\n", procid, opno, f.path,
4255 st, (long long)off, e);
4260 unlink_f(int opno, long r)
4269 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
4271 printf("%d/%d: unlink - no file\n", procid, opno);
4275 e = unlink_path(&f) < 0 ? errno : 0;
4278 del_from_flist(flp - flist, fep - flp->fents);
4280 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
4282 printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
4283 procid, opno, fep->id, fep->parent);
4289 unresvsp_f(int opno, long r)
4294 struct xfs_flock64 fl;
4302 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4304 printf("%d/%d: unresvsp - no filename\n", procid, opno);
4308 fd = open_path(&f, O_RDWR);
4309 e = fd < 0 ? errno : 0;
4313 printf("%d/%d: unresvsp - open %s failed %d\n",
4314 procid, opno, f.path, e);
4318 if (fstat64(fd, &stb) < 0) {
4320 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
4321 procid, opno, f.path, errno);
4326 inode_info(st, sizeof(st), &stb, v);
4327 lr = ((int64_t)random() << 32) + random();
4328 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4330 fl.l_whence = SEEK_SET;
4332 fl.l_len = (off64_t)(random() % (1 << 20));
4333 e = xfsctl(f.path, fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
4335 printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s%s %lld %lld %d\n",
4336 procid, opno, f.path, st,
4337 (long long)off, (long long)fl.l_len, e);
4343 write_f(int opno, long r)
4357 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4359 printf("%d/%d: write - no filename\n", procid, opno);
4363 fd = open_path(&f, O_WRONLY);
4364 e = fd < 0 ? errno : 0;
4368 printf("%d/%d: write - open %s failed %d\n",
4369 procid, opno, f.path, e);
4373 if (fstat64(fd, &stb) < 0) {
4375 printf("%d/%d: write - fstat64 %s failed %d\n",
4376 procid, opno, f.path, errno);
4381 inode_info(st, sizeof(st), &stb, v);
4382 lr = ((int64_t)random() << 32) + random();
4383 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4385 lseek64(fd, off, SEEK_SET);
4386 len = (random() % FILELEN_MAX) + 1;
4388 memset(buf, nameseq & 0xff, len);
4389 e = write(fd, buf, len) < 0 ? errno : 0;
4392 printf("%d/%d: write %s%s [%lld,%d] %d\n",
4393 procid, opno, f.path, st, (long long)off, (int)len, e);
4399 writev_f(int opno, long r)
4411 struct iovec *iov = NULL;
4418 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4420 printf("%d/%d: writev - no filename\n", procid, opno);
4424 fd = open_path(&f, O_WRONLY);
4425 e = fd < 0 ? errno : 0;
4429 printf("%d/%d: writev - open %s failed %d\n",
4430 procid, opno, f.path, e);
4434 if (fstat64(fd, &stb) < 0) {
4436 printf("%d/%d: writev - fstat64 %s failed %d\n",
4437 procid, opno, f.path, errno);
4442 inode_info(st, sizeof(st), &stb, v);
4443 lr = ((int64_t)random() << 32) + random();
4444 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4446 lseek64(fd, off, SEEK_SET);
4447 len = (random() % FILELEN_MAX) + 1;
4449 memset(buf, nameseq & 0xff, len);
4451 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
4452 iov = calloc(iovcnt, sizeof(struct iovec));
4453 iovl = len / iovcnt;
4455 for (i=0; i<iovcnt; i++) {
4456 (iov + i)->iov_base = (buf + iovb);
4457 (iov + i)->iov_len = iovl;
4461 e = writev(fd, iov, iovcnt) < 0 ? errno : 0;
4465 printf("%d/%d: writev %s%s [%lld,%d,%d] %d\n",
4466 procid, opno, f.path, st, (long long)off, (int)iovl,