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];
2373 init_pathname(&fpath1);
2374 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2376 printf("%d/%d: copyrange read - no filename\n",
2381 init_pathname(&fpath2);
2382 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2384 printf("%d/%d: copyrange write - no filename\n",
2390 fd1 = open_path(&fpath1, O_RDONLY);
2391 e = fd1 < 0 ? errno : 0;
2395 printf("%d/%d: copyrange read - open %s failed %d\n",
2396 procid, opno, fpath1.path, e);
2400 fd2 = open_path(&fpath2, O_WRONLY);
2401 e = fd2 < 0 ? errno : 0;
2405 printf("%d/%d: copyrange write - open %s failed %d\n",
2406 procid, opno, fpath2.path, e);
2410 /* Get file stats */
2411 if (fstat64(fd1, &stat1) < 0) {
2413 printf("%d/%d: copyrange read - fstat64 %s failed %d\n",
2414 procid, opno, fpath1.path, errno);
2417 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2419 if (fstat64(fd2, &stat2) < 0) {
2421 printf("%d/%d: copyrange write - fstat64 %s failed %d\n",
2422 procid, opno, fpath2.path, errno);
2425 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2427 /* Calculate offsets */
2428 len = (random() % FILELEN_MAX) + 1;
2430 len = stat1.st_blksize;
2431 if (len > stat1.st_size)
2432 len = stat1.st_size;
2434 lr = ((int64_t)random() << 32) + random();
2435 if (stat1.st_size == len)
2438 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2442 * If srcfile == destfile, randomly generate destination ranges
2443 * until we find one that doesn't overlap the source range.
2445 max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
2447 lr = ((int64_t)random() << 32) + random();
2448 off2 = (off64_t)(lr % max_off2);
2450 } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
2453 * Since len, off1 and off2 will be changed later, preserve their
2461 ret = syscall(__NR_copy_file_range, fd1, &off1, fd2, &off2,
2464 if (errno != EAGAIN || tries++ >= 300)
2466 } else if (ret > len || ret == 0)
2471 e = ret < 0 ? errno : 0;
2473 printf("%d/%d: copyrange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
2475 fpath1.path, inoinfo1,
2476 (long long)offset1, (long long)length,
2477 fpath2.path, inoinfo2,
2478 (long long)offset2, (long long)length);
2481 printf(" error %d", e);
2482 else if (len && ret > len)
2483 printf(" asked for %lld, copied %lld??\n",
2484 (long long)len, (long long)ret);
2493 free_pathname(&fpath2);
2495 free_pathname(&fpath1);
2499 /* dedupe some arbitrary range of f1 to f2...fn. */
2505 #ifdef FIDEDUPERANGE
2506 #define INFO_SZ 1024
2507 struct file_dedupe_range *fdr;
2508 struct pathname *fpath;
2509 struct stat64 *stat;
2521 if (flist[FT_REG].nfiles < 2)
2524 /* Pick somewhere between 2 and 128 files. */
2526 nr = random() % (flist[FT_REG].nfiles + 1);
2527 } while (nr < 2 || nr > 128);
2530 fdr = malloc(nr * sizeof(struct file_dedupe_range_info) +
2531 sizeof(struct file_dedupe_range));
2533 printf("%d/%d: line %d error %d\n",
2534 procid, opno, __LINE__, errno);
2537 memset(fdr, 0, (nr * sizeof(struct file_dedupe_range_info) +
2538 sizeof(struct file_dedupe_range)));
2540 fpath = calloc(nr, sizeof(struct pathname));
2542 printf("%d/%d: line %d error %d\n",
2543 procid, opno, __LINE__, errno);
2547 stat = calloc(nr, sizeof(struct stat64));
2549 printf("%d/%d: line %d error %d\n",
2550 procid, opno, __LINE__, errno);
2554 info = calloc(nr, INFO_SZ);
2556 printf("%d/%d: line %d error %d\n",
2557 procid, opno, __LINE__, errno);
2561 off = calloc(nr, sizeof(off64_t));
2563 printf("%d/%d: line %d error %d\n",
2564 procid, opno, __LINE__, errno);
2568 v = calloc(nr, sizeof(int));
2570 printf("%d/%d: line %d error %d\n",
2571 procid, opno, __LINE__, errno);
2574 fd = calloc(nr, sizeof(int));
2576 printf("%d/%d: line %d error %d\n",
2577 procid, opno, __LINE__, errno);
2580 memset(fd, 0xFF, nr * sizeof(int));
2582 /* Get paths for all files */
2583 for (i = 0; i < nr; i++)
2584 init_pathname(&fpath[i]);
2586 if (!get_fname(FT_REGm, r, &fpath[0], NULL, NULL, &v[0])) {
2588 printf("%d/%d: deduperange read - no filename\n",
2593 for (i = 1; i < nr; i++) {
2594 if (!get_fname(FT_REGm, random(), &fpath[i], NULL, NULL, &v[i])) {
2596 printf("%d/%d: deduperange write - no filename\n",
2603 fd[0] = open_path(&fpath[0], O_RDONLY);
2604 e = fd[0] < 0 ? errno : 0;
2608 printf("%d/%d: deduperange read - open %s failed %d\n",
2609 procid, opno, fpath[0].path, e);
2613 for (i = 1; i < nr; i++) {
2614 fd[i] = open_path(&fpath[i], O_WRONLY);
2615 e = fd[i] < 0 ? errno : 0;
2619 printf("%d/%d: deduperange write - open %s failed %d\n",
2620 procid, opno, fpath[i].path, e);
2625 /* Get file stats */
2626 if (fstat64(fd[0], &stat[0]) < 0) {
2628 printf("%d/%d: deduperange read - fstat64 %s failed %d\n",
2629 procid, opno, fpath[0].path, errno);
2633 inode_info(&info[0], INFO_SZ, &stat[0], v[0]);
2635 for (i = 1; i < nr; i++) {
2636 if (fstat64(fd[i], &stat[i]) < 0) {
2638 printf("%d/%d: deduperange write - fstat64 %s failed %d\n",
2639 procid, opno, fpath[i].path, errno);
2642 inode_info(&info[i * INFO_SZ], INFO_SZ, &stat[i], v[i]);
2645 /* Never try to dedupe more than half of the src file. */
2646 len = (random() % FILELEN_MAX) + 1;
2647 len &= ~(stat[0].st_blksize - 1);
2649 len = stat[0].st_blksize / 2;
2650 if (len > stat[0].st_size / 2)
2651 len = stat[0].st_size / 2;
2653 /* Calculate offsets */
2654 lr = ((int64_t)random() << 32) + random();
2655 if (stat[0].st_size == len)
2658 off[0] = (off64_t)(lr % MIN(stat[0].st_size - len, MAXFSIZE));
2660 off[0] &= ~(stat[0].st_blksize - 1);
2663 * If srcfile == destfile[i], randomly generate destination ranges
2664 * until we find one that doesn't overlap the source range.
2666 for (i = 1; i < nr; i++) {
2670 lr = ((int64_t)random() << 32) + random();
2671 if (stat[i].st_size <= len)
2674 off[i] = (off64_t)(lr % MIN(stat[i].st_size - len, MAXFSIZE));
2676 off[i] &= ~(stat[i].st_blksize - 1);
2677 } while (stat[0].st_ino == stat[i].st_ino &&
2678 llabs(off[i] - off[0]) < len &&
2682 /* Clone data blocks */
2683 fdr->src_offset = off[0];
2684 fdr->src_length = len;
2685 fdr->dest_count = nr - 1;
2686 for (i = 1; i < nr; i++) {
2687 fdr->info[i - 1].dest_fd = fd[i];
2688 fdr->info[i - 1].dest_offset = off[i];
2691 ret = ioctl(fd[0], FIDEDUPERANGE, fdr);
2692 e = ret < 0 ? errno : 0;
2694 printf("%d/%d: deduperange from %s%s [%lld,%lld]",
2696 fpath[0].path, &info[0], (long long)off[0],
2699 printf(" error %d", e);
2705 for (i = 1; i < nr; i++) {
2706 e = fdr->info[i - 1].status < 0 ? fdr->info[i - 1].status : 0;
2708 printf("%d/%d: ...to %s%s [%lld,%lld]",
2710 fpath[i].path, &info[i * INFO_SZ],
2711 (long long)off[i], (long long)len);
2712 if (fdr->info[i - 1].status < 0)
2713 printf(" error %d", e);
2714 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_SAME)
2715 printf(" %llu bytes deduplicated",
2716 fdr->info[i - 1].bytes_deduped);
2717 if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_DIFFERS)
2718 printf(" differed");
2724 for (i = 0; i < nr; i++)
2728 for (i = 0; i < nr; i++)
2729 free_pathname(&fpath[i]);
2748 setxattr_f(int opno, long r)
2750 #ifdef XFS_XFLAG_EXTSIZE
2760 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
2761 append_pathname(&f, ".");
2762 fd = open_path(&f, O_RDWR);
2763 e = fd < 0 ? errno : 0;
2768 e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
2769 nbits = (int)(random() % e);
2770 p &= (1 << nbits) - 1;
2772 if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
2774 e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
2777 printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
2784 splice_f(int opno, long r)
2786 struct pathname fpath1;
2787 struct pathname fpath2;
2788 struct stat64 stat1;
2789 struct stat64 stat2;
2790 char inoinfo1[1024];
2791 char inoinfo2[1024];
2795 loff_t offset1, offset2;
2802 ssize_t ret1 = 0, ret2 = 0;
2808 init_pathname(&fpath1);
2809 if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
2811 printf("%d/%d: splice read - no filename\n",
2816 init_pathname(&fpath2);
2817 if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
2819 printf("%d/%d: splice write - no filename\n",
2825 fd1 = open_path(&fpath1, O_RDONLY);
2826 e = fd1 < 0 ? errno : 0;
2830 printf("%d/%d: splice read - open %s failed %d\n",
2831 procid, opno, fpath1.path, e);
2835 fd2 = open_path(&fpath2, O_WRONLY);
2836 e = fd2 < 0 ? errno : 0;
2840 printf("%d/%d: splice write - open %s failed %d\n",
2841 procid, opno, fpath2.path, e);
2845 /* Get file stats */
2846 if (fstat64(fd1, &stat1) < 0) {
2848 printf("%d/%d: splice read - fstat64 %s failed %d\n",
2849 procid, opno, fpath1.path, errno);
2852 inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
2854 if (fstat64(fd2, &stat2) < 0) {
2856 printf("%d/%d: splice write - fstat64 %s failed %d\n",
2857 procid, opno, fpath2.path, errno);
2860 inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
2862 /* Calculate offsets */
2863 len = (random() % FILELEN_MAX) + 1;
2865 len = stat1.st_blksize;
2866 if (len > stat1.st_size)
2867 len = stat1.st_size;
2869 lr = ((int64_t)random() << 32) + random();
2870 if (stat1.st_size == len)
2873 off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
2877 * splice can overlap write, so the offset of the target file can be
2878 * any number. But to avoid too large offset, add a clamp of 1024 blocks
2879 * past the current dest file EOF
2881 lr = ((int64_t)random() << 32) + random();
2882 off2 = (off64_t)(lr % MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE));
2885 * Since len, off1 and off2 will be changed later, preserve their
2892 /* Pipe initialize */
2893 if (pipe(filedes) < 0) {
2895 printf("%d/%d: splice - pipe failed %d\n",
2896 procid, opno, errno);
2904 /* move to pipe buffer */
2905 ret1 = splice(fd1, &off1, filedes[1], NULL, len, 0);
2911 /* move from pipe buffer to dst file */
2913 ret2 = splice(filedes[0], NULL, fd2, &off2, bytes, 0);
2926 if (ret1 < 0 || ret2 < 0)
2931 printf("%d/%d: splice %s%s [%lld,%lld] -> %s%s [%lld,%lld] %d",
2933 fpath1.path, inoinfo1, (long long)offset1, (long long)length,
2934 fpath2.path, inoinfo2, (long long)offset2, (long long)length, e);
2936 if (length && length > total)
2937 printf(" asked for %lld, spliced %lld??\n",
2938 (long long)length, (long long)total);
2949 free_pathname(&fpath2);
2951 free_pathname(&fpath1);
2955 creat_f(int opno, long r)
2970 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
2975 e1 = (random() % 100);
2976 type = rtpct ? ((e1 > rtpct) ? FT_REG : FT_RTF) : FT_REG;
2978 if (type == FT_RTF) /* rt always gets an extsize */
2979 extsize = (random() % 10) + 1;
2980 else if (e1 < 10) /* one-in-ten get an extsize */
2981 extsize = random() % 1024;
2985 e = generate_fname(fep, type, &f, &id, &v);
2989 (void)fent_to_name(&f, &flist[FT_DIR], fep);
2990 printf("%d/%d: creat - no filename from %s\n",
2991 procid, opno, f.path);
2996 fd = creat_path(&f, 0666);
2997 e = fd < 0 ? errno : 0;
3002 xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
3003 if (type == FT_RTF) {
3004 a.fsx_xflags |= XFS_XFLAG_REALTIME;
3005 a.fsx_extsize = extsize *
3006 geom.rtextsize * geom.blocksize;
3008 } else if (extsize) {
3009 a.fsx_xflags |= XFS_XFLAG_EXTSIZE;
3010 a.fsx_extsize = extsize * geom.blocksize;
3013 if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
3016 add_to_flist(type, id, parid);
3020 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
3021 extsize ? a.fsx_extsize : 0, e, e1);
3022 printf("%d/%d: creat add id=%d,parent=%d\n", procid, opno, id, parid);
3028 dread_f(int opno, long r)
3032 struct dioattr diob;
3045 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3047 printf("%d/%d: dread - no filename\n", procid, opno);
3051 fd = open_path(&f, O_RDONLY|O_DIRECT);
3052 e = fd < 0 ? errno : 0;
3056 printf("%d/%d: dread - open %s failed %d\n",
3057 procid, opno, f.path, e);
3061 if (fstat64(fd, &stb) < 0) {
3063 printf("%d/%d: dread - fstat64 %s failed %d\n",
3064 procid, opno, f.path, errno);
3069 inode_info(st, sizeof(st), &stb, v);
3070 if (stb.st_size == 0) {
3072 printf("%d/%d: dread - %s%s zero size\n", procid, opno,
3078 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3081 "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
3082 " fallback to stat()\n",
3083 procid, opno, f.path, st, errno);
3084 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3085 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3088 dio_env = getenv("XFS_DIO_MIN");
3090 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3092 align = (int64_t)diob.d_miniosz;
3093 lr = ((int64_t)random() << 32) + random();
3094 off = (off64_t)(lr % stb.st_size);
3095 off -= (off % align);
3096 lseek64(fd, off, SEEK_SET);
3097 len = (random() % FILELEN_MAX) + 1;
3098 len -= (len % align);
3101 else if (len > diob.d_maxiosz)
3102 len = diob.d_maxiosz;
3103 buf = memalign(diob.d_mem, len);
3104 e = read(fd, buf, len) < 0 ? errno : 0;
3107 printf("%d/%d: dread %s%s [%lld,%d] %d\n",
3108 procid, opno, f.path, st, (long long)off, (int)len, e);
3114 dwrite_f(int opno, long r)
3118 struct dioattr diob;
3131 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3133 printf("%d/%d: dwrite - no filename\n", procid, opno);
3137 fd = open_path(&f, O_WRONLY|O_DIRECT);
3138 e = fd < 0 ? errno : 0;
3142 printf("%d/%d: dwrite - open %s failed %d\n",
3143 procid, opno, f.path, e);
3147 if (fstat64(fd, &stb) < 0) {
3149 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
3150 procid, opno, f.path, errno);
3155 inode_info(st, sizeof(st), &stb, v);
3156 if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
3158 printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
3159 " %s%s return %d, fallback to stat()\n",
3160 procid, opno, f.path, st, errno);
3161 diob.d_mem = diob.d_miniosz = stb.st_blksize;
3162 diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
3165 dio_env = getenv("XFS_DIO_MIN");
3167 diob.d_mem = diob.d_miniosz = atoi(dio_env);
3169 align = (int64_t)diob.d_miniosz;
3170 lr = ((int64_t)random() << 32) + random();
3171 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3172 off -= (off % align);
3173 lseek64(fd, off, SEEK_SET);
3174 len = (random() % FILELEN_MAX) + 1;
3175 len -= (len % align);
3178 else if (len > diob.d_maxiosz)
3179 len = diob.d_maxiosz;
3180 buf = memalign(diob.d_mem, len);
3182 lseek64(fd, off, SEEK_SET);
3183 memset(buf, nameseq & 0xff, len);
3184 e = write(fd, buf, len) < 0 ? errno : 0;
3187 printf("%d/%d: dwrite %s%s [%lld,%d] %d\n",
3188 procid, opno, f.path, st, (long long)off, (int)len, e);
3194 #ifdef HAVE_LINUX_FALLOC_H
3195 struct print_flags falloc_flags [] = {
3196 { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"},
3197 { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"},
3198 { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
3199 { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
3200 { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
3201 { FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
3205 #define translate_falloc_flags(mode) \
3206 ({translate_flags(mode, "|", falloc_flags);})
3210 do_fallocate(int opno, long r, int mode)
3212 #ifdef HAVE_LINUX_FALLOC_H
3224 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3226 printf("%d/%d: do_fallocate - no filename\n", procid, opno);
3230 fd = open_path(&f, O_RDWR);
3233 printf("%d/%d: do_fallocate - open %s failed %d\n",
3234 procid, opno, f.path, errno);
3239 if (fstat64(fd, &stb) < 0) {
3241 printf("%d/%d: do_fallocate - fstat64 %s failed %d\n",
3242 procid, opno, f.path, errno);
3247 inode_info(st, sizeof(st), &stb, v);
3248 lr = ((int64_t)random() << 32) + random();
3249 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3251 len = (off64_t)(random() % (1024 * 1024));
3253 * Collapse/insert range requires off and len to be block aligned,
3254 * make it more likely to be the case.
3256 if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) &&
3258 off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3259 len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
3261 mode |= FALLOC_FL_KEEP_SIZE & random();
3262 e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
3264 printf("%d/%d: fallocate(%s) %s %st %lld %lld %d\n",
3265 procid, opno, translate_falloc_flags(mode),
3266 f.path, st, (long long)off, (long long)len, e);
3273 fallocate_f(int opno, long r)
3275 #ifdef HAVE_LINUX_FALLOC_H
3276 do_fallocate(opno, r, 0);
3281 fdatasync_f(int opno, long r)
3289 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3291 printf("%d/%d: fdatasync - no filename\n",
3296 fd = open_path(&f, O_WRONLY);
3297 e = fd < 0 ? errno : 0;
3301 printf("%d/%d: fdatasync - open %s failed %d\n",
3302 procid, opno, f.path, e);
3306 e = fdatasync(fd) < 0 ? errno : 0;
3308 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
3313 #ifdef HAVE_LINUX_FIEMAP_H
3314 struct print_flags fiemap_flags[] = {
3315 { FIEMAP_FLAG_SYNC, "SYNC"},
3316 { FIEMAP_FLAG_XATTR, "XATTR"},
3320 #define translate_fiemap_flags(mode) \
3321 ({translate_flags(mode, "|", fiemap_flags);})
3325 fiemap_f(int opno, long r)
3327 #ifdef HAVE_LINUX_FIEMAP_H
3337 struct fiemap *fiemap;
3340 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3342 printf("%d/%d: fiemap - no filename\n", procid, opno);
3346 fd = open_path(&f, O_RDWR);
3347 e = fd < 0 ? errno : 0;
3351 printf("%d/%d: fiemap - open %s failed %d\n",
3352 procid, opno, f.path, e);
3356 if (fstat64(fd, &stb) < 0) {
3358 printf("%d/%d: fiemap - fstat64 %s failed %d\n",
3359 procid, opno, f.path, errno);
3364 inode_info(st, sizeof(st), &stb, v);
3365 blocks_to_map = random() & 0xffff;
3366 fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) +
3367 (blocks_to_map * sizeof(struct fiemap_extent)));
3370 printf("%d/%d: malloc failed \n", procid, opno);
3375 lr = ((int64_t)random() << 32) + random();
3376 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3378 fiemap->fm_flags = random() & (FIEMAP_FLAGS_COMPAT | 0x10000);
3379 fiemap->fm_extent_count = blocks_to_map;
3380 fiemap->fm_mapped_extents = random() & 0xffff;
3381 fiemap->fm_start = off;
3382 fiemap->fm_length = ((int64_t)random() << 32) + random();
3384 e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
3386 printf("%d/%d: ioctl(FIEMAP) %s%s %lld %lld (%s) %d\n",
3387 procid, opno, f.path, st, (long long)fiemap->fm_start,
3388 (long long) fiemap->fm_length,
3389 translate_fiemap_flags(fiemap->fm_flags), e);
3397 freesp_f(int opno, long r)
3402 struct xfs_flock64 fl;
3410 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3412 printf("%d/%d: freesp - no filename\n", procid, opno);
3416 fd = open_path(&f, O_RDWR);
3417 e = fd < 0 ? errno : 0;
3421 printf("%d/%d: freesp - open %s failed %d\n",
3422 procid, opno, f.path, e);
3426 if (fstat64(fd, &stb) < 0) {
3428 printf("%d/%d: freesp - fstat64 %s failed %d\n",
3429 procid, opno, f.path, errno);
3434 inode_info(st, sizeof(st), &stb, v);
3435 lr = ((int64_t)random() << 32) + random();
3436 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
3438 fl.l_whence = SEEK_SET;
3441 e = xfsctl(f.path, fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
3443 printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s%s %lld 0 %d\n",
3444 procid, opno, f.path, st, (long long)off, e);
3450 fsync_f(int opno, long r)
3458 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3460 printf("%d/%d: fsync - no filename\n", procid, opno);
3464 fd = open_path(&f, O_WRONLY);
3465 e = fd < 0 ? errno : 0;
3469 printf("%d/%d: fsync - open %s failed %d\n",
3470 procid, opno, f.path, e);
3474 e = fsync(fd) < 0 ? errno : 0;
3476 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
3482 getattr_f(int opno, long r)
3491 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
3492 append_pathname(&f, ".");
3493 fd = open_path(&f, O_RDWR);
3494 e = fd < 0 ? errno : 0;
3497 e = ioctl(fd, FS_IOC_GETFLAGS, &fl);
3499 printf("%d/%d: getattr %s %u %d\n", procid, opno, f.path, fl, e);
3505 getdents_f(int opno, long r)
3512 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
3513 append_pathname(&f, ".");
3514 dir = opendir_path(&f);
3518 printf("%d/%d: getdents - can't open %s\n",
3519 procid, opno, f.path);
3523 while (readdir64(dir) != NULL)
3526 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
3532 link_f(int opno, long r)
3545 if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
3547 printf("%d/%d: link - no file\n", procid, opno);
3551 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
3557 e = generate_fname(fep, flp - flist, &l, &id, &v1);
3561 (void)fent_to_name(&l, &flist[FT_DIR], fep);
3562 printf("%d/%d: link - no filename from %s\n",
3563 procid, opno, l.path);
3569 e = link_path(&f, &l) < 0 ? errno : 0;
3572 add_to_flist(flp - flist, id, parid);
3574 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
3576 printf("%d/%d: link add id=%d,parent=%d\n", procid, opno, id, parid);
3583 mkdir_f(int opno, long r)
3593 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3598 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
3602 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3603 printf("%d/%d: mkdir - no filename from %s\n",
3604 procid, opno, f.path);
3609 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
3612 add_to_flist(FT_DIR, id, parid);
3614 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
3615 printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
3621 mknod_f(int opno, long r)
3631 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
3636 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
3640 (void)fent_to_name(&f, &flist[FT_DIR], fep);
3641 printf("%d/%d: mknod - no filename from %s\n",
3642 procid, opno, f.path);
3647 e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0;
3650 add_to_flist(FT_DEV, id, parid);
3652 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
3653 printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
3658 #ifdef HAVE_SYS_MMAN_H
3659 struct print_flags mmap_flags[] = {
3660 { MAP_SHARED, "SHARED"},
3661 { MAP_PRIVATE, "PRIVATE"},
3665 #define translate_mmap_flags(flags) \
3666 ({translate_flags(flags, "|", mmap_flags);})
3670 do_mmap(int opno, long r, int prot)
3672 #ifdef HAVE_SYS_MMAN_H
3684 sigjmp_buf sigbus_jmpbuf;
3687 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3689 printf("%d/%d: do_mmap - no filename\n", procid, opno);
3693 fd = open_path(&f, O_RDWR);
3694 e = fd < 0 ? errno : 0;
3698 printf("%d/%d: do_mmap - open %s failed %d\n",
3699 procid, opno, f.path, e);
3703 if (fstat64(fd, &stb) < 0) {
3705 printf("%d/%d: do_mmap - fstat64 %s failed %d\n",
3706 procid, opno, f.path, errno);
3711 inode_info(st, sizeof(st), &stb, v);
3712 if (stb.st_size == 0) {
3714 printf("%d/%d: do_mmap - %s%s zero size\n", procid, opno,
3721 lr = ((int64_t)random() << 32) + random();
3722 off = (off64_t)(lr % stb.st_size);
3723 off &= (off64_t)(~(sysconf(_SC_PAGE_SIZE) - 1));
3724 len = (size_t)(random() % MIN(stb.st_size - off, FILELEN_MAX)) + 1;
3726 flags = (random() % 2) ? MAP_SHARED : MAP_PRIVATE;
3727 addr = mmap(NULL, len, prot, flags, fd, off);
3728 e = (addr == MAP_FAILED) ? errno : 0;
3731 printf("%d/%d: do_mmap - mmap failed %s%s [%lld,%d,%s] %d\n",
3732 procid, opno, f.path, st, (long long)off,
3733 (int)len, translate_mmap_flags(flags), e);
3739 if (prot & PROT_WRITE) {
3740 if ((e = sigsetjmp(sigbus_jmpbuf, 1)) == 0) {
3741 sigbus_jmp = &sigbus_jmpbuf;
3742 memset(addr, nameseq & 0xff, len);
3746 if ((buf = malloc(len)) != NULL) {
3747 memcpy(buf, addr, len);
3752 /* set NULL to stop other functions from doing siglongjmp */
3756 printf("%d/%d: %s %s%s [%lld,%d,%s] %s\n",
3757 procid, opno, (prot & PROT_WRITE) ? "mwrite" : "mread",
3758 f.path, st, (long long)off, (int)len,
3759 translate_mmap_flags(flags),
3760 (e == 0) ? "0" : "Bus error");
3768 mread_f(int opno, long r)
3770 #ifdef HAVE_SYS_MMAN_H
3771 do_mmap(opno, r, PROT_READ);
3776 mwrite_f(int opno, long r)
3778 #ifdef HAVE_SYS_MMAN_H
3779 do_mmap(opno, r, PROT_WRITE);
3784 punch_f(int opno, long r)
3786 #ifdef HAVE_LINUX_FALLOC_H
3787 do_fallocate(opno, r, FALLOC_FL_PUNCH_HOLE);
3792 zero_f(int opno, long r)
3794 #ifdef HAVE_LINUX_FALLOC_H
3795 do_fallocate(opno, r, FALLOC_FL_ZERO_RANGE);
3800 collapse_f(int opno, long r)
3802 #ifdef HAVE_LINUX_FALLOC_H
3803 do_fallocate(opno, r, FALLOC_FL_COLLAPSE_RANGE);
3808 insert_f(int opno, long r)
3810 #ifdef HAVE_LINUX_FALLOC_H
3811 do_fallocate(opno, r, FALLOC_FL_INSERT_RANGE);
3816 read_f(int opno, long r)
3830 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3832 printf("%d/%d: read - no filename\n", procid, opno);
3836 fd = open_path(&f, O_RDONLY);
3837 e = fd < 0 ? errno : 0;
3841 printf("%d/%d: read - open %s failed %d\n",
3842 procid, opno, f.path, e);
3846 if (fstat64(fd, &stb) < 0) {
3848 printf("%d/%d: read - fstat64 %s failed %d\n",
3849 procid, opno, f.path, errno);
3854 inode_info(st, sizeof(st), &stb, v);
3855 if (stb.st_size == 0) {
3857 printf("%d/%d: read - %s%s zero size\n", procid, opno,
3863 lr = ((int64_t)random() << 32) + random();
3864 off = (off64_t)(lr % stb.st_size);
3865 lseek64(fd, off, SEEK_SET);
3866 len = (random() % FILELEN_MAX) + 1;
3868 e = read(fd, buf, len) < 0 ? errno : 0;
3871 printf("%d/%d: read %s%s [%lld,%d] %d\n",
3872 procid, opno, f.path, st, (long long)off, (int)len, e);
3878 readlink_f(int opno, long r)
3886 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
3888 printf("%d/%d: readlink - no filename\n", procid, opno);
3892 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
3895 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
3900 readv_f(int opno, long r)
3912 struct iovec *iov = NULL;
3919 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
3921 printf("%d/%d: readv - no filename\n", procid, opno);
3925 fd = open_path(&f, O_RDONLY);
3926 e = fd < 0 ? errno : 0;
3930 printf("%d/%d: readv - open %s failed %d\n",
3931 procid, opno, f.path, e);
3935 if (fstat64(fd, &stb) < 0) {
3937 printf("%d/%d: readv - fstat64 %s failed %d\n",
3938 procid, opno, f.path, errno);
3943 inode_info(st, sizeof(st), &stb, v);
3944 if (stb.st_size == 0) {
3946 printf("%d/%d: readv - %s%s zero size\n", procid, opno,
3952 lr = ((int64_t)random() << 32) + random();
3953 off = (off64_t)(lr % stb.st_size);
3954 lseek64(fd, off, SEEK_SET);
3955 len = (random() % FILELEN_MAX) + 1;
3958 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
3959 iov = calloc(iovcnt, sizeof(struct iovec));
3960 iovl = len / iovcnt;
3962 for (i=0; i<iovcnt; i++) {
3963 (iov + i)->iov_base = (buf + iovb);
3964 (iov + i)->iov_len = iovl;
3968 e = readv(fd, iov, iovcnt) < 0 ? errno : 0;
3971 printf("%d/%d: readv %s%s [%lld,%d,%d] %d\n",
3972 procid, opno, f.path, st, (long long)off, (int)iovl,
3979 rename_f(int opno, long r)
3993 /* get an existing path for the source of the rename */
3995 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
3997 printf("%d/%d: rename - no filename\n", procid, opno);
4002 /* get an existing directory for the destination parent directory name */
4003 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
4009 /* generate a new path using an existing parent directory in name */
4010 init_pathname(&newf);
4011 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
4015 (void)fent_to_name(&f, &flist[FT_DIR], dfep);
4016 printf("%d/%d: rename - no filename from %s\n",
4017 procid, opno, f.path);
4019 free_pathname(&newf);
4023 e = rename_path(&f, &newf) < 0 ? errno : 0;
4026 if (flp - flist == FT_DIR) {
4028 fix_parent(oldid, id);
4030 del_from_flist(flp - flist, fep - flp->fents);
4031 add_to_flist(flp - flist, id, parid);
4034 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
4037 printf("%d/%d: rename del entry: id=%d,parent=%d\n",
4038 procid, opno, fep->id, fep->parent);
4039 printf("%d/%d: rename add entry: id=%d,parent=%d\n",
4040 procid, opno, id, parid);
4043 free_pathname(&newf);
4048 resvsp_f(int opno, long r)
4053 struct xfs_flock64 fl;
4061 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4063 printf("%d/%d: resvsp - no filename\n", procid, opno);
4067 fd = open_path(&f, O_RDWR);
4068 e = fd < 0 ? errno : 0;
4072 printf("%d/%d: resvsp - open %s failed %d\n",
4073 procid, opno, f.path, e);
4077 if (fstat64(fd, &stb) < 0) {
4079 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
4080 procid, opno, f.path, errno);
4085 inode_info(st, sizeof(st), &stb, v);
4086 lr = ((int64_t)random() << 32) + random();
4087 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4089 fl.l_whence = SEEK_SET;
4091 fl.l_len = (off64_t)(random() % (1024 * 1024));
4092 e = xfsctl(f.path, fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
4094 printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s%s %lld %lld %d\n",
4095 procid, opno, f.path, st,
4096 (long long)off, (long long)fl.l_len, e);
4102 rmdir_f(int opno, long r)
4110 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
4112 printf("%d/%d: rmdir - no directory\n", procid, opno);
4116 e = rmdir_path(&f) < 0 ? errno : 0;
4119 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
4121 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
4123 printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
4124 procid, opno, fep->id, fep->parent);
4130 setattr_f(int opno, long r)
4139 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
4140 append_pathname(&f, ".");
4141 fd = open_path(&f, O_RDWR);
4142 e = fd < 0 ? errno : 0;
4145 fl = attr_mask & (uint)random();
4146 e = ioctl(fd, FS_IOC_SETFLAGS, &fl);
4148 printf("%d/%d: setattr %s %x %d\n", procid, opno, f.path, fl, e);
4154 stat_f(int opno, long r)
4162 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
4164 printf("%d/%d: stat - no entries\n", procid, opno);
4168 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
4171 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
4176 symlink_f(int opno, long r)
4189 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
4194 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
4198 (void)fent_to_name(&f, &flist[FT_DIR], fep);
4199 printf("%d/%d: symlink - no filename from %s\n",
4200 procid, opno, f.path);
4205 len = (int)(random() % PATH_MAX);
4206 val = malloc(len + 1);
4208 memset(val, 'x', len);
4210 for (i = 10; i < len - 1; i += 10)
4212 e = symlink_path(val, &f) < 0 ? errno : 0;
4215 add_to_flist(FT_SYM, id, parid);
4218 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
4219 printf("%d/%d: symlink add id=%d,parent=%d\n", procid, opno, id, parid);
4226 sync_f(int opno, long r)
4230 printf("%d/%d: sync\n", procid, opno);
4234 truncate_f(int opno, long r)
4245 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4247 printf("%d/%d: truncate - no filename\n", procid, opno);
4251 e = stat64_path(&f, &stb) < 0 ? errno : 0;
4255 printf("%d/%d: truncate - stat64 %s failed %d\n",
4256 procid, opno, f.path, e);
4260 inode_info(st, sizeof(st), &stb, v);
4261 lr = ((int64_t)random() << 32) + random();
4262 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4264 e = truncate64_path(&f, off) < 0 ? errno : 0;
4267 printf("%d/%d: truncate %s%s %lld %d\n", procid, opno, f.path,
4268 st, (long long)off, e);
4273 unlink_f(int opno, long r)
4282 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
4284 printf("%d/%d: unlink - no file\n", procid, opno);
4288 e = unlink_path(&f) < 0 ? errno : 0;
4291 del_from_flist(flp - flist, fep - flp->fents);
4293 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
4295 printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
4296 procid, opno, fep->id, fep->parent);
4302 unresvsp_f(int opno, long r)
4307 struct xfs_flock64 fl;
4315 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
4317 printf("%d/%d: unresvsp - no filename\n", procid, opno);
4321 fd = open_path(&f, O_RDWR);
4322 e = fd < 0 ? errno : 0;
4326 printf("%d/%d: unresvsp - open %s failed %d\n",
4327 procid, opno, f.path, e);
4331 if (fstat64(fd, &stb) < 0) {
4333 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
4334 procid, opno, f.path, errno);
4339 inode_info(st, sizeof(st), &stb, v);
4340 lr = ((int64_t)random() << 32) + random();
4341 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4343 fl.l_whence = SEEK_SET;
4345 fl.l_len = (off64_t)(random() % (1 << 20));
4346 e = xfsctl(f.path, fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
4348 printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s%s %lld %lld %d\n",
4349 procid, opno, f.path, st,
4350 (long long)off, (long long)fl.l_len, e);
4356 write_f(int opno, long r)
4370 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4372 printf("%d/%d: write - no filename\n", procid, opno);
4376 fd = open_path(&f, O_WRONLY);
4377 e = fd < 0 ? errno : 0;
4381 printf("%d/%d: write - open %s failed %d\n",
4382 procid, opno, f.path, e);
4386 if (fstat64(fd, &stb) < 0) {
4388 printf("%d/%d: write - fstat64 %s failed %d\n",
4389 procid, opno, f.path, errno);
4394 inode_info(st, sizeof(st), &stb, v);
4395 lr = ((int64_t)random() << 32) + random();
4396 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4398 lseek64(fd, off, SEEK_SET);
4399 len = (random() % FILELEN_MAX) + 1;
4401 memset(buf, nameseq & 0xff, len);
4402 e = write(fd, buf, len) < 0 ? errno : 0;
4405 printf("%d/%d: write %s%s [%lld,%d] %d\n",
4406 procid, opno, f.path, st, (long long)off, (int)len, e);
4412 writev_f(int opno, long r)
4424 struct iovec *iov = NULL;
4431 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
4433 printf("%d/%d: writev - no filename\n", procid, opno);
4437 fd = open_path(&f, O_WRONLY);
4438 e = fd < 0 ? errno : 0;
4442 printf("%d/%d: writev - open %s failed %d\n",
4443 procid, opno, f.path, e);
4447 if (fstat64(fd, &stb) < 0) {
4449 printf("%d/%d: writev - fstat64 %s failed %d\n",
4450 procid, opno, f.path, errno);
4455 inode_info(st, sizeof(st), &stb, v);
4456 lr = ((int64_t)random() << 32) + random();
4457 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
4459 lseek64(fd, off, SEEK_SET);
4460 len = (random() % FILELEN_MAX) + 1;
4462 memset(buf, nameseq & 0xff, len);
4464 iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
4465 iov = calloc(iovcnt, sizeof(struct iovec));
4466 iovl = len / iovcnt;
4468 for (i=0; i<iovcnt; i++) {
4469 (iov + i)->iov_base = (buf + iovb);
4470 (iov + i)->iov_len = iovl;
4474 e = writev(fd, iov, iovcnt) < 0 ? errno : 0;
4478 printf("%d/%d: writev %s%s [%lld,%d,%d] %d\n",
4479 procid, opno, f.path, st, (long long)off, (int)iovl,