2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #define XFS_ERRTAG_MAX 17
69 typedef void (*opfnc_t)(int, long);
71 typedef struct opdesc {
84 typedef struct flist {
91 typedef struct pathname {
97 #define FT_DIRm (1 << FT_DIR)
99 #define FT_REGm (1 << FT_REG)
101 #define FT_SYMm (1 << FT_SYM)
103 #define FT_DEVm (1 << FT_DEV)
105 #define FT_RTFm (1 << FT_RTF)
107 #define FT_ANYm ((1 << FT_nft) - 1)
108 #define FT_REGFILE (FT_REGm | FT_RTFm)
109 #define FT_NOTDIR (FT_ANYm & ~FT_DIRm)
111 #define FLIST_SLOT_INCR 16
114 #define MAXFSIZE ((1ULL << 63) - 1ULL)
115 #define MAXFSIZE32 ((1ULL << 40) - 1ULL)
117 void allocsp_f(int, long);
118 void attr_remove_f(int, long);
119 void attr_set_f(int, long);
120 void bulkstat_f(int, long);
121 void bulkstat1_f(int, long);
122 void chown_f(int, long);
123 void creat_f(int, long);
124 void dread_f(int, long);
125 void dwrite_f(int, long);
126 void fdatasync_f(int, long);
127 void freesp_f(int, long);
128 void fsync_f(int, long);
129 void getdents_f(int, long);
130 void link_f(int, long);
131 void mkdir_f(int, long);
132 void mknod_f(int, long);
133 void read_f(int, long);
134 void readlink_f(int, long);
135 void rename_f(int, long);
136 void resvsp_f(int, long);
137 void rmdir_f(int, long);
138 void stat_f(int, long);
139 void symlink_f(int, long);
140 void sync_f(int, long);
141 void truncate_f(int, long);
142 void unlink_f(int, long);
143 void unresvsp_f(int, long);
144 void write_f(int, long);
147 { OP_ALLOCSP, "allocsp", allocsp_f, 1, 1 },
148 { OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1 },
149 { OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1 },
150 { OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0 },
151 { OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0 },
152 { OP_CHOWN, "chown", chown_f, 3, 1 },
153 { OP_CREAT, "creat", creat_f, 4, 1 },
154 { OP_DREAD, "dread", dread_f, 4, 0 },
155 { OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
156 { OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
157 { OP_FREESP, "freesp", freesp_f, 1, 1 },
158 { OP_FSYNC, "fsync", fsync_f, 1, 1 },
159 { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
160 { OP_LINK, "link", link_f, 1, 1 },
161 { OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
162 { OP_MKNOD, "mknod", mknod_f, 2, 1 },
163 { OP_READ, "read", read_f, 1, 0 },
164 { OP_READLINK, "readlink", readlink_f, 1, 0 },
165 { OP_RENAME, "rename", rename_f, 2, 1 },
166 { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
167 { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
168 { OP_STAT, "stat", stat_f, 1, 0 },
169 { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
170 { OP_SYNC, "sync", sync_f, 1, 0 },
171 { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
172 { OP_UNLINK, "unlink", unlink_f, 1, 1 },
173 { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
174 { OP_WRITE, "write", write_f, 4, 1 },
177 flist_t flist[FT_nft] = {
190 xfs_fsop_geom_t geom;
203 unsigned long seed = 0;
207 void add_to_flist(int, int, int);
208 void append_pathname(pathname_t *, char *);
209 int attr_list_path(pathname_t *, char *, const int, int,
210 attrlist_cursor_t *);
211 int attr_remove_path(pathname_t *, const char *, int);
212 int attr_set_path(pathname_t *, const char *, const char *, const int, int);
213 void check_cwd(void);
214 int creat_path(pathname_t *, mode_t);
215 void dcache_enter(int, int);
216 void dcache_init(void);
217 fent_t *dcache_lookup(int);
218 void dcache_purge(int);
219 void del_from_flist(int, int);
220 int dirid_to_name(char *, int);
222 void fent_to_name(pathname_t *, flist_t *, fent_t *);
223 void fix_parent(int, int);
224 void free_pathname(pathname_t *);
225 int generate_fname(fent_t *, int, pathname_t *, int *, int *);
226 int get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
227 void init_pathname(pathname_t *);
228 int lchown_path(pathname_t *, uid_t, gid_t);
229 int link_path(pathname_t *, pathname_t *);
230 int lstat64_path(pathname_t *, struct stat64 *);
231 void make_freq_table(void);
232 int mkdir_path(pathname_t *, mode_t);
233 int mknod_path(pathname_t *, mode_t, dev_t);
234 void namerandpad(int, char *, int);
235 int open_path(pathname_t *, int);
236 DIR *opendir_path(pathname_t *);
237 void process_freq(char *);
238 int readlink_path(pathname_t *, char *, size_t);
239 int rename_path(pathname_t *, pathname_t *);
240 int rmdir_path(pathname_t *);
241 void separate_pathname(pathname_t *, char *, pathname_t *);
242 void show_ops(int, char *);
243 int stat64_path(pathname_t *, struct stat64 *);
244 int symlink_path(const char *, pathname_t *);
245 int truncate64_path(pathname_t *, off64_t);
246 int unlink_path(pathname_t *);
248 void write_freq(void);
249 void zero_freq(void);
251 int main(int argc, char **argv)
255 char *dirname = NULL;
264 xfs_error_injection_t err_inj;
266 errrange = errtag = 0;
268 nops = sizeof(ops) / sizeof(ops[0]);
269 ops_end = &ops[nops];
271 while ((c = getopt(argc, argv, "d:e:f:i:n:p:rs:vwzHS")) != -1) {
277 sscanf(optarg, "%d", &errtag);
281 } else if (errtag == 0)
283 if (errtag >= XFS_ERRTAG_MAX) {
285 "error tag %d too large (max %d)\n",
286 errtag, XFS_ERRTAG_MAX - 1);
291 process_freq(optarg);
294 ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
295 ilist[ilistlen - 1] = strtol(optarg, &p, 16);
298 operations = atoi(optarg);
301 nproc = atoi(optarg);
307 seed = strtoul(optarg, NULL, 0);
324 fprintf(stderr, "%s - invalid parameters\n",
334 /* no directory specified */
335 if (!nousage) usage();
339 (void)mkdir(dirname, 0777);
340 if (chdir(dirname) < 0) {
344 sprintf(buf, "fss%x", getpid());
345 fd = creat(buf, 0666);
346 if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
347 maxfsize = (off64_t)MAXFSIZE32;
349 maxfsize = (off64_t)MAXFSIZE;
354 gettimeofday(&t, (void *)NULL);
355 seed = (int)t.tv_sec ^ (int)t.tv_usec;
356 printf("seed = %ld\n", seed);
358 i = ioctl(fd, XFS_IOC_FSGEOMETRY, &geom);
359 if (i >= 0 && geom.rtblocks)
360 rtpct = MIN(MAX(geom.rtblocks * 100 /
361 (geom.rtblocks + geom.datablocks), 1), 99);
370 for (i = 0; i < j; i++)
373 errtag = (random() % (XFS_ERRTAG_MAX-1)) + 1;
379 for (i = 0; i < j; i++)
382 errtag += (random() % (XFS_ERRTAG_MAX - errtag));
384 printf("Injecting failure on tag #%d\n", errtag);
385 err_inj.errtag = errtag;
387 srval = ioctl(fd, XFS_IOC_ERROR_INJECTION, &err_inj);
389 perror("fsstress - XFS_SYSSGI error injection call");
397 for (i = 0; i < nproc; i++) {
404 while (wait(&stat) > 0)
409 if((srval = ioctl(fd, XFS_IOC_ERROR_CLEARALL, &err_inj)) != 0) {
410 fprintf(stderr, "Bad ej clear on %d (%d).\n", fd, errno);
411 perror("fsstress - XFS_SYSSGI clear error injection call");
422 add_to_flist(int ft, int id, int parent)
428 if (ftp->nfiles == ftp->nslots) {
429 ftp->nslots += FLIST_SLOT_INCR;
430 ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
432 fep = &ftp->fents[ftp->nfiles++];
434 fep->parent = parent;
438 append_pathname(pathname_t *name, char *str)
444 if (len && *str == '/' && name->len == 0) {
445 fprintf(stderr, "fsstress: append_pathname failure\n");
451 name->path = realloc(name->path, name->len + 1 + len);
452 strcpy(&name->path[name->len], str);
457 attr_list_path(pathname_t *name, char *buffer, const int buffersize, int flags,
458 attrlist_cursor_t *cursor)
460 char buf[MAXNAMELEN];
464 rval = attr_list(name->path, buffer, buffersize, flags, cursor);
465 if (rval >= 0 || errno != ENAMETOOLONG)
467 separate_pathname(name, buf, &newname);
468 if (chdir(buf) == 0) {
469 rval = attr_list_path(&newname, buffer, buffersize, flags,
473 free_pathname(&newname);
478 attr_remove_path(pathname_t *name, const char *attrname, int flags)
480 char buf[MAXNAMELEN];
484 rval = attr_remove(name->path, attrname, flags);
485 if (rval >= 0 || errno != ENAMETOOLONG)
487 separate_pathname(name, buf, &newname);
488 if (chdir(buf) == 0) {
489 rval = attr_remove_path(&newname, attrname, flags);
492 free_pathname(&newname);
497 attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
498 const int valuelength, int flags)
500 char buf[MAXNAMELEN];
504 rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
505 if (rval >= 0 || errno != ENAMETOOLONG)
507 separate_pathname(name, buf, &newname);
508 if (chdir(buf) == 0) {
509 rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
513 free_pathname(&newname);
521 struct stat64 statbuf;
523 if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
526 fprintf(stderr, "fsstress: check_cwd failure\n");
533 creat_path(pathname_t *name, mode_t mode)
535 char buf[MAXNAMELEN];
539 rval = creat(name->path, mode);
540 if (rval >= 0 || errno != ENAMETOOLONG)
542 separate_pathname(name, buf, &newname);
543 if (chdir(buf) == 0) {
544 rval = creat_path(&newname, mode);
547 free_pathname(&newname);
552 dcache_enter(int dirid, int slot)
554 dcache[dirid % NDCACHE] = slot;
562 for (i = 0; i < NDCACHE; i++)
567 dcache_lookup(int dirid)
572 i = dcache[dirid % NDCACHE];
573 if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
579 dcache_purge(int dirid)
583 dcp = &dcache[dirid % NDCACHE];
584 if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
589 del_from_flist(int ft, int slot)
595 dcache_purge(ftp->fents[slot].id);
596 if (slot != ftp->nfiles - 1) {
598 dcache_purge(ftp->fents[ftp->nfiles - 1].id);
599 ftp->fents[slot] = ftp->fents[--ftp->nfiles];
605 dirid_to_fent(int dirid)
611 if ((fep = dcache_lookup(dirid)))
613 flp = &flist[FT_DIR];
614 for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
615 if (fep->id == dirid) {
616 dcache_enter(dirid, fep - flp->fents);
626 struct stat64 statbuf;
632 sprintf(buf, "p%x", procid);
633 (void)mkdir(buf, 0777);
634 if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
638 top_ino = statbuf.st_ino;
639 homedir = getcwd(NULL, -1);
644 for (opno = 0; opno < operations; opno++) {
645 p = &ops[freq_table[random() % freq_table_size]];
646 p->func(opno, random());
648 * test for forced shutdown by stat'ing the test
649 * directory. If this stat returns EIO, assume
650 * the forced shutdown happened.
652 if (errtag != 0 && opno % 100 == 0) {
653 rval = stat64(".", &statbuf);
655 fprintf(stderr, "Detected EIO\n");
663 fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
665 char buf[MAXNAMELEN];
671 if (fep->parent != -1) {
672 pfep = dirid_to_fent(fep->parent);
673 fent_to_name(name, &flist[FT_DIR], pfep);
674 append_pathname(name, "/");
676 i = sprintf(buf, "%c%x", flp->tag, fep->id);
677 namerandpad(fep->id, buf, i);
678 append_pathname(name, buf);
682 fix_parent(int oldid, int newid)
689 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
690 for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
691 if (fep->parent == oldid)
698 free_pathname(pathname_t *name)
708 generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
710 char buf[MAXNAMELEN];
717 len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
718 namerandpad(id, buf, len);
720 fent_to_name(name, &flist[FT_DIR], fep);
721 append_pathname(name, "/");
723 append_pathname(name, buf);
726 for (j = 0; !*v && j < ilistlen; j++) {
727 if (ilist[j] == id) {
736 get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
746 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
747 if (which & (1 << i))
759 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
760 if (which & (1 << i)) {
761 if (x < c + flp->nfiles) {
762 fep = &flp->fents[x - c];
764 fent_to_name(name, flp, fep);
770 for (j = 0; !*v && j < ilistlen; j++) {
771 if (ilist[j] == fep->id) {
782 fprintf(stderr, "fsstress: get_fname failure\n");
790 init_pathname(pathname_t *name)
797 lchown_path(pathname_t *name, uid_t owner, gid_t group)
799 char buf[MAXNAMELEN];
803 rval = lchown(name->path, owner, group);
804 if (rval >= 0 || errno != ENAMETOOLONG)
806 separate_pathname(name, buf, &newname);
807 if (chdir(buf) == 0) {
808 rval = lchown_path(&newname, owner, group);
811 free_pathname(&newname);
816 link_path(pathname_t *name1, pathname_t *name2)
818 char buf1[MAXNAMELEN];
819 char buf2[MAXNAMELEN];
825 rval = link(name1->path, name2->path);
826 if (rval >= 0 || errno != ENAMETOOLONG)
828 separate_pathname(name1, buf1, &newname1);
829 separate_pathname(name2, buf2, &newname2);
830 if (strcmp(buf1, buf2) == 0) {
831 if (chdir(buf1) == 0) {
832 rval = link_path(&newname1, &newname2);
836 if (strcmp(buf1, "..") == 0)
838 else if (strcmp(buf2, "..") == 0)
840 else if (strlen(buf1) == 0)
842 else if (strlen(buf2) == 0)
845 down1 = MAX(newname1.len, 3 + name2->len) <=
846 MAX(3 + name1->len, newname2.len);
848 free_pathname(&newname2);
849 append_pathname(&newname2, "../");
850 append_pathname(&newname2, name2->path);
851 if (chdir(buf1) == 0) {
852 rval = link_path(&newname1, &newname2);
856 free_pathname(&newname1);
857 append_pathname(&newname1, "../");
858 append_pathname(&newname1, name1->path);
859 if (chdir(buf2) == 0) {
860 rval = link_path(&newname1, &newname2);
865 free_pathname(&newname1);
866 free_pathname(&newname2);
871 lstat64_path(pathname_t *name, struct stat64 *sbuf)
873 char buf[MAXNAMELEN];
877 rval = lstat64(name->path, sbuf);
878 if (rval >= 0 || errno != ENAMETOOLONG)
880 separate_pathname(name, buf, &newname);
881 if (chdir(buf) == 0) {
882 rval = lstat64_path(&newname, sbuf);
885 free_pathname(&newname);
890 make_freq_table(void)
896 for (p = ops, f = 0; p < ops_end; p++)
898 freq_table = malloc(f * sizeof(*freq_table));
900 for (p = ops, i = 0; p < ops_end; p++) {
901 for (f = 0; f < p->freq; f++, i++)
902 freq_table[i] = p->op;
907 mkdir_path(pathname_t *name, mode_t mode)
909 char buf[MAXNAMELEN];
913 rval = mkdir(name->path, mode);
914 if (rval >= 0 || errno != ENAMETOOLONG)
916 separate_pathname(name, buf, &newname);
917 if (chdir(buf) == 0) {
918 rval = mkdir_path(&newname, mode);
921 free_pathname(&newname);
926 mknod_path(pathname_t *name, mode_t mode, dev_t dev)
928 char buf[MAXNAMELEN];
932 rval = mknod(name->path, mode, dev);
933 if (rval >= 0 || errno != ENAMETOOLONG)
935 separate_pathname(name, buf, &newname);
936 if (chdir(buf) == 0) {
937 rval = mknod_path(&newname, mode, dev);
940 free_pathname(&newname);
945 namerandpad(int id, char *buf, int i)
948 static int buckets[] =
949 { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 };
955 bucket = (id ^ namerand) % (sizeof(buckets) / sizeof(buckets[0]));
956 padmod = buckets[bucket] + 1 - i;
959 padlen = (id ^ namerand) % padmod;
961 memset(&buf[i], 'X', padlen);
962 buf[i + padlen] = '\0';
967 open_path(pathname_t *name, int oflag)
969 char buf[MAXNAMELEN];
973 rval = open(name->path, oflag);
974 if (rval >= 0 || errno != ENAMETOOLONG)
976 separate_pathname(name, buf, &newname);
977 if (chdir(buf) == 0) {
978 rval = open_path(&newname, oflag);
981 free_pathname(&newname);
986 opendir_path(pathname_t *name)
988 char buf[MAXNAMELEN];
992 rval = opendir(name->path);
993 if (rval || errno != ENAMETOOLONG)
995 separate_pathname(name, buf, &newname);
996 if (chdir(buf) == 0) {
997 rval = opendir_path(&newname);
1000 free_pathname(&newname);
1005 process_freq(char *arg)
1010 s = strchr(arg, '=');
1012 fprintf(stderr, "bad argument '%s'\n", arg);
1016 for (p = ops; p < ops_end; p++) {
1017 if (strcmp(arg, p->name) == 0) {
1022 fprintf(stderr, "can't find op type %s for -f\n", arg);
1027 readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
1029 char buf[MAXNAMELEN];
1033 rval = readlink(name->path, lbuf, lbufsiz);
1034 if (rval >= 0 || errno != ENAMETOOLONG)
1036 separate_pathname(name, buf, &newname);
1037 if (chdir(buf) == 0) {
1038 rval = readlink_path(&newname, lbuf, lbufsiz);
1041 free_pathname(&newname);
1046 rename_path(pathname_t *name1, pathname_t *name2)
1048 char buf1[MAXNAMELEN];
1049 char buf2[MAXNAMELEN];
1051 pathname_t newname1;
1052 pathname_t newname2;
1055 rval = rename(name1->path, name2->path);
1056 if (rval >= 0 || errno != ENAMETOOLONG)
1058 separate_pathname(name1, buf1, &newname1);
1059 separate_pathname(name2, buf2, &newname2);
1060 if (strcmp(buf1, buf2) == 0) {
1061 if (chdir(buf1) == 0) {
1062 rval = rename_path(&newname1, &newname2);
1066 if (strcmp(buf1, "..") == 0)
1068 else if (strcmp(buf2, "..") == 0)
1070 else if (strlen(buf1) == 0)
1072 else if (strlen(buf2) == 0)
1075 down1 = MAX(newname1.len, 3 + name2->len) <=
1076 MAX(3 + name1->len, newname2.len);
1078 free_pathname(&newname2);
1079 append_pathname(&newname2, "../");
1080 append_pathname(&newname2, name2->path);
1081 if (chdir(buf1) == 0) {
1082 rval = rename_path(&newname1, &newname2);
1086 free_pathname(&newname1);
1087 append_pathname(&newname1, "../");
1088 append_pathname(&newname1, name1->path);
1089 if (chdir(buf2) == 0) {
1090 rval = rename_path(&newname1, &newname2);
1095 free_pathname(&newname1);
1096 free_pathname(&newname2);
1101 rmdir_path(pathname_t *name)
1103 char buf[MAXNAMELEN];
1107 rval = rmdir(name->path);
1108 if (rval >= 0 || errno != ENAMETOOLONG)
1110 separate_pathname(name, buf, &newname);
1111 if (chdir(buf) == 0) {
1112 rval = rmdir_path(&newname);
1115 free_pathname(&newname);
1120 separate_pathname(pathname_t *name, char *buf, pathname_t *newname)
1124 init_pathname(newname);
1125 slash = strchr(name->path, '/');
1126 if (slash == NULL) {
1131 strcpy(buf, name->path);
1133 append_pathname(newname, slash + 1);
1139 show_ops(int flag, char *lead_str)
1144 /* print in list form */
1147 for (p = ops; p < ops_end; p++) {
1148 if (lead_str != NULL && x+strlen(p->name)>=WIDTH-5)
1149 x=printf("%s%s", (p==ops)?"":"\n", lead_str);
1150 x+=printf("%s ", p->name);
1155 for (f = 0, p = ops; p < ops_end; p++)
1161 for (p = ops; p < ops_end; p++) {
1162 if (flag != 0 || p->freq > 0) {
1163 if (lead_str != NULL)
1164 printf("%s", lead_str);
1165 printf("%20s %d/%d %s\n",
1166 p->name, p->freq, f,
1167 (p->iswrite == 0) ? " " : "write op");
1174 stat64_path(pathname_t *name, struct stat64 *sbuf)
1176 char buf[MAXNAMELEN];
1180 rval = stat64(name->path, sbuf);
1181 if (rval >= 0 || errno != ENAMETOOLONG)
1183 separate_pathname(name, buf, &newname);
1184 if (chdir(buf) == 0) {
1185 rval = stat64_path(&newname, sbuf);
1188 free_pathname(&newname);
1193 symlink_path(const char *name1, pathname_t *name)
1195 char buf[MAXNAMELEN];
1199 if (!strcmp(name1, name->path)) {
1200 printf("yikes! %s %s\n", name1, name->path);
1204 rval = symlink(name1, name->path);
1205 if (rval >= 0 || errno != ENAMETOOLONG)
1207 separate_pathname(name, buf, &newname);
1208 if (chdir(buf) == 0) {
1209 rval = symlink_path(name1, &newname);
1212 free_pathname(&newname);
1217 truncate64_path(pathname_t *name, off64_t length)
1219 char buf[MAXNAMELEN];
1223 rval = truncate64(name->path, length);
1224 if (rval >= 0 || errno != ENAMETOOLONG)
1226 separate_pathname(name, buf, &newname);
1227 if (chdir(buf) == 0) {
1228 rval = truncate64_path(&newname, length);
1231 free_pathname(&newname);
1236 unlink_path(pathname_t *name)
1238 char buf[MAXNAMELEN];
1242 rval = unlink(name->path);
1243 if (rval >= 0 || errno != ENAMETOOLONG)
1245 separate_pathname(name, buf, &newname);
1246 if (chdir(buf) == 0) {
1247 rval = unlink_path(&newname);
1250 free_pathname(&newname);
1257 printf("Usage: %s -H or\n", myprog);
1258 printf(" %s [-d dir][-e errtg][-f op_name=freq][-n nops]\n",
1260 printf(" [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
1262 printf(" -d dir specifies the base directory for operations\n");
1263 printf(" -e errtg specifies error injection stuff\n");
1264 printf(" -f op_name=freq changes the frequency of option name to freq\n");
1265 printf(" the valid operation names are:\n");
1267 printf(" -n nops specifies the no. of operations per process (default 1)\n");
1268 printf(" -p nproc specifies the no. of processes (default 1)\n");
1269 printf(" -r specifies random name padding\n");
1270 printf(" -s seed specifies the seed for the random generator (default random)\n");
1271 printf(" -v specifies verbose mode\n");
1272 printf(" -w zeros frequencies of non-write operations\n");
1273 printf(" -z zeros frequencies of all operations\n");
1274 printf(" -S prints the table of operations (omitting zero frequency)\n");
1275 printf(" -H prints usage and exits\n");
1283 for (p = ops; p < ops_end; p++) {
1294 for (p = ops; p < ops_end; p++)
1299 allocsp_f(int opno, long r)
1311 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1313 printf("%d/%d: allocsp - no filename\n", procid, opno);
1317 fd = open_path(&f, O_RDWR);
1318 e = fd < 0 ? errno : 0;
1322 printf("%d/%d: allocsp - open %s failed %d\n",
1323 procid, opno, f.path, e);
1327 if (fstat64(fd, &stb) < 0) {
1329 printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1330 procid, opno, f.path, errno);
1335 lr = ((__int64_t)random() << 32) + random();
1336 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1338 fl.l_whence = SEEK_SET;
1341 e = ioctl(fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1343 printf("%d/%d: ioctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
1344 procid, opno, f.path, off, e);
1350 attr_remove_f(int opno, long r)
1352 attrlist_ent_t *aep;
1356 attrlist_cursor_t cursor;
1365 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1366 append_pathname(&f, ".");
1368 bzero(&cursor, sizeof(cursor));
1370 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1375 alist = (attrlist_t *)buf;
1376 total += alist->al_count;
1377 } while (alist->al_more);
1380 printf("%d/%d: attr_remove - no attrs for %s\n",
1381 procid, opno, f.path);
1385 which = (int)(random() % total);
1386 bzero(&cursor, sizeof(cursor));
1390 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1395 alist = (attrlist_t *)buf;
1396 if (which < ent + alist->al_count) {
1397 aep = (attrlist_ent_t *)
1398 &buf[alist->al_offset[which - ent]];
1399 aname = aep->a_name;
1402 ent += alist->al_count;
1403 } while (alist->al_more);
1404 if (aname == NULL) {
1407 "%d/%d: attr_remove - name %d not found at %s\n",
1408 procid, opno, which, f.path);
1412 e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
1415 printf("%d/%d: attr_remove %s %s %d\n",
1416 procid, opno, f.path, aname, e);
1421 attr_set_f(int opno, long r)
1428 static int lengths[] = { 10, 100, 1000, 10000 };
1433 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1434 append_pathname(&f, ".");
1435 sprintf(aname, "a%x", nameseq++);
1436 li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
1437 len = (int)(random() % lengths[li]);
1441 memset(aval, nameseq & 0xff, len);
1442 e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
1447 printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
1453 bulkstat_f(int opno, long r)
1461 xfs_fsop_bulkreq_t bsr;
1464 nent = (r % 999) + 2;
1465 t = malloc(nent * sizeof(*t));
1466 fd = open(".", O_RDONLY);
1474 while (ioctl(fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
1478 printf("%d/%d: bulkstat nent %d total %lld\n",
1479 procid, opno, nent, total);
1484 bulkstat1_f(int opno, long r)
1494 xfs_fsop_bulkreq_t bsr;
1497 good = random() & 1;
1499 /* use an inode we know exists */
1501 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1502 append_pathname(&f, ".");
1503 ino = stat64_path(&f, &s) < 0 ? (ino64_t)r : s.st_ino;
1508 * pick a random inode
1510 * note this can generate kernel warning messages
1511 * since bulkstat_one will read the disk block that
1512 * would contain a given inode even if that disk
1513 * block doesn't contain inodes.
1515 * this is detected later, but not until after the
1516 * warning is displayed.
1518 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
1524 fd = open(".", O_RDONLY);
1531 e = ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
1533 printf("%d/%d: bulkstat1 %s ino %lld %d\n",
1534 procid, opno, good?"real":"random", (int64_t)ino, e);
1539 chown_f(int opno, long r)
1548 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1549 append_pathname(&f, ".");
1550 u = (uid_t)random();
1551 nbits = (int)(random() % 32);
1552 u &= (1 << nbits) - 1;
1553 e = lchown_path(&f, u, -1) < 0 ? errno : 0;
1556 printf("%d/%d: chown %s %d %d\n", procid, opno, f.path, u, e);
1561 creat_f(int opno, long r)
1576 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
1581 type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
1583 extsize = (random() % 10) + 1;
1586 e = generate_fname(fep, type, &f, &id, &v);
1590 fent_to_name(&f, &flist[FT_DIR], fep);
1591 printf("%d/%d: creat - no filename from %s\n",
1592 procid, opno, f.path);
1597 fd = creat_path(&f, 0666);
1598 e = fd < 0 ? errno : 0;
1602 if (extsize && ioctl(fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
1603 a.fsx_xflags |= XFS_XFLAG_REALTIME;
1605 geom.rtextsize * geom.blocksize * extsize;
1606 if (ioctl(fd, XFS_IOC_FSSETXATTR, &a) < 0)
1609 add_to_flist(type, id, parid);
1613 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
1614 extsize ? a.fsx_extsize : 0, e, e1);
1619 dread_f(int opno, long r)
1623 struct dioattr diob;
1634 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1636 printf("%d/%d: dread - no filename\n", procid, opno);
1640 fd = open_path(&f, O_RDONLY|O_DIRECT);
1641 e = fd < 0 ? errno : 0;
1645 printf("%d/%d: dread - open %s failed %d\n",
1646 procid, opno, f.path, e);
1650 if (fstat64(fd, &stb) < 0) {
1652 printf("%d/%d: dread - fstat64 %s failed %d\n",
1653 procid, opno, f.path, errno);
1658 if (stb.st_size == 0) {
1660 printf("%d/%d: dread - %s zero size\n", procid, opno,
1666 if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1669 "%d/%d: dread - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1670 procid, opno, f.path, errno);
1675 align = (__int64_t)diob.d_miniosz;
1676 lr = ((__int64_t)random() << 32) + random();
1677 off = (off64_t)(lr % stb.st_size);
1678 off -= (off % align);
1679 lseek64(fd, off, SEEK_SET);
1680 len = (random() % (getpagesize() * 32)) + 1;
1681 len -= (len % align);
1684 else if (len > diob.d_maxiosz)
1685 len = diob.d_maxiosz;
1686 buf = memalign(diob.d_mem, len);
1687 e = read(fd, buf, len) < 0 ? errno : 0;
1690 printf("%d/%d: dread %s [%lld,%d] %d\n",
1691 procid, opno, f.path, off, len, e);
1697 dwrite_f(int opno, long r)
1701 struct dioattr diob;
1712 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1714 printf("%d/%d: dwrite - no filename\n", procid, opno);
1718 fd = open_path(&f, O_WRONLY|O_DIRECT);
1719 e = fd < 0 ? errno : 0;
1723 printf("%d/%d: dwrite - open %s failed %d\n",
1724 procid, opno, f.path, e);
1728 if (fstat64(fd, &stb) < 0) {
1730 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
1731 procid, opno, f.path, errno);
1736 if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1739 "%d/%d: dwrite - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1740 procid, opno, f.path, errno);
1745 align = (__int64_t)diob.d_miniosz;
1746 lr = ((__int64_t)random() << 32) + random();
1747 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1748 off -= (off % align);
1749 lseek64(fd, off, SEEK_SET);
1750 len = (random() % (getpagesize() * 32)) + 1;
1751 len -= (len % align);
1754 else if (len > diob.d_maxiosz)
1755 len = diob.d_maxiosz;
1756 buf = memalign(diob.d_mem, len);
1758 lseek64(fd, off, SEEK_SET);
1759 memset(buf, nameseq & 0xff, len);
1760 e = write(fd, buf, len) < 0 ? errno : 0;
1763 printf("%d/%d: dwrite %s [%lld,%d] %d\n",
1764 procid, opno, f.path, off, len, e);
1770 fdatasync_f(int opno, long r)
1778 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1780 printf("%d/%d: fdatasync - no filename\n",
1785 fd = open_path(&f, O_WRONLY);
1786 e = fd < 0 ? errno : 0;
1790 printf("%d/%d: fdatasync - open %s failed %d\n",
1791 procid, opno, f.path, e);
1795 e = fdatasync(fd) < 0 ? errno : 0;
1797 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
1803 freesp_f(int opno, long r)
1815 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1817 printf("%d/%d: freesp - no filename\n", procid, opno);
1821 fd = open_path(&f, O_RDWR);
1822 e = fd < 0 ? errno : 0;
1826 printf("%d/%d: freesp - open %s failed %d\n",
1827 procid, opno, f.path, e);
1831 if (fstat64(fd, &stb) < 0) {
1833 printf("%d/%d: freesp - fstat64 %s failed %d\n",
1834 procid, opno, f.path, errno);
1839 lr = ((__int64_t)random() << 32) + random();
1840 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1842 fl.l_whence = SEEK_SET;
1845 e = ioctl(fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
1847 printf("%d/%d: ioctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
1848 procid, opno, f.path, off, e);
1854 fsync_f(int opno, long r)
1862 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1864 printf("%d/%d: fsync - no filename\n", procid, opno);
1868 fd = open_path(&f, O_WRONLY);
1869 e = fd < 0 ? errno : 0;
1873 printf("%d/%d: fsync - open %s failed %d\n",
1874 procid, opno, f.path, e);
1878 e = fsync(fd) < 0 ? errno : 0;
1880 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
1886 getdents_f(int opno, long r)
1893 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
1894 append_pathname(&f, ".");
1895 dir = opendir_path(&f);
1899 printf("%d/%d: getdents - can't open %s\n",
1900 procid, opno, f.path);
1904 while (readdir64(dir) != NULL)
1907 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
1913 link_f(int opno, long r)
1926 if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
1928 printf("%d/%d: link - no file\n", procid, opno);
1932 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
1938 e = generate_fname(fep, flp - flist, &l, &id, &v1);
1942 fent_to_name(&l, &flist[FT_DIR], fep);
1943 printf("%d/%d: link - no filename from %s\n",
1944 procid, opno, l.path);
1950 e = link_path(&f, &l) < 0 ? errno : 0;
1953 add_to_flist(flp - flist, id, parid);
1955 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
1962 mkdir_f(int opno, long r)
1972 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
1977 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
1981 fent_to_name(&f, &flist[FT_DIR], fep);
1982 printf("%d/%d: mkdir - no filename from %s\n",
1983 procid, opno, f.path);
1988 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
1991 add_to_flist(FT_DIR, id, parid);
1993 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
1998 mknod_f(int opno, long r)
2008 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2013 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
2017 fent_to_name(&f, &flist[FT_DIR], fep);
2018 printf("%d/%d: mknod - no filename from %s\n",
2019 procid, opno, f.path);
2024 e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0;
2027 add_to_flist(FT_DEV, id, parid);
2029 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
2034 read_f(int opno, long r)
2047 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2049 printf("%d/%d: read - no filename\n", procid, opno);
2053 fd = open_path(&f, O_RDONLY);
2054 e = fd < 0 ? errno : 0;
2058 printf("%d/%d: read - open %s failed %d\n",
2059 procid, opno, f.path, e);
2063 if (fstat64(fd, &stb) < 0) {
2065 printf("%d/%d: read - fstat64 %s failed %d\n",
2066 procid, opno, f.path, errno);
2071 if (stb.st_size == 0) {
2073 printf("%d/%d: read - %s zero size\n", procid, opno,
2079 lr = ((__int64_t)random() << 32) + random();
2080 off = (off64_t)(lr % stb.st_size);
2081 lseek64(fd, off, SEEK_SET);
2082 len = (random() % (getpagesize() * 32)) + 1;
2084 e = read(fd, buf, len) < 0 ? errno : 0;
2087 printf("%d/%d: read %s [%lld,%d] %d\n",
2088 procid, opno, f.path, off, len, e);
2094 readlink_f(int opno, long r)
2102 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
2104 printf("%d/%d: readlink - no filename\n", procid, opno);
2108 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
2111 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
2116 rename_f(int opno, long r)
2131 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
2133 printf("%d/%d: rename - no filename\n", procid, opno);
2137 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
2142 init_pathname(&newf);
2143 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
2147 fent_to_name(&f, &flist[FT_DIR], dfep);
2148 printf("%d/%d: rename - no filename from %s\n",
2149 procid, opno, f.path);
2151 free_pathname(&newf);
2155 e = rename_path(&f, &newf) < 0 ? errno : 0;
2158 if (flp - flist == FT_DIR) {
2160 fix_parent(oldid, id);
2162 del_from_flist(flp - flist, fep - flp->fents);
2163 add_to_flist(flp - flist, id, parid);
2166 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
2168 free_pathname(&newf);
2173 resvsp_f(int opno, long r)
2185 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2187 printf("%d/%d: resvsp - no filename\n", procid, opno);
2191 fd = open_path(&f, O_RDWR);
2192 e = fd < 0 ? errno : 0;
2196 printf("%d/%d: resvsp - open %s failed %d\n",
2197 procid, opno, f.path, e);
2201 if (fstat64(fd, &stb) < 0) {
2203 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
2204 procid, opno, f.path, errno);
2209 lr = ((__int64_t)random() << 32) + random();
2210 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2212 fl.l_whence = SEEK_SET;
2214 fl.l_len = (off64_t)(random() % (1024 * 1024));
2215 e = ioctl(fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
2217 printf("%d/%d: ioctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
2218 procid, opno, f.path, off, fl.l_len, e);
2224 rmdir_f(int opno, long r)
2232 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
2234 printf("%d/%d: rmdir - no directory\n", procid, opno);
2238 e = rmdir_path(&f) < 0 ? errno : 0;
2241 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
2243 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
2248 stat_f(int opno, long r)
2256 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
2258 printf("%d/%d: stat - no entries\n", procid, opno);
2262 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
2265 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
2270 symlink_f(int opno, long r)
2283 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2288 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
2292 fent_to_name(&f, &flist[FT_DIR], fep);
2293 printf("%d/%d: symlink - no filename from %s\n",
2294 procid, opno, f.path);
2299 len = (int)(random() % PATH_MAX);
2300 val = malloc(len + 1);
2302 memset(val, 'x', len);
2304 for (i = 10; i < len - 1; i += 10)
2306 e = symlink_path(val, &f) < 0 ? errno : 0;
2309 add_to_flist(FT_SYM, id, parid);
2312 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
2318 sync_f(int opno, long r)
2322 printf("%d/%d: sync\n", procid, opno);
2326 truncate_f(int opno, long r)
2336 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2338 printf("%d/%d: truncate - no filename\n", procid, opno);
2342 e = stat64_path(&f, &stb) < 0 ? errno : 0;
2346 printf("%d/%d: truncate - stat64 %s failed %d\n",
2347 procid, opno, f.path, e);
2351 lr = ((__int64_t)random() << 32) + random();
2352 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2354 e = truncate64_path(&f, off) < 0 ? errno : 0;
2357 printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
2363 unlink_f(int opno, long r)
2372 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
2374 printf("%d/%d: unlink - no file\n", procid, opno);
2378 e = unlink_path(&f) < 0 ? errno : 0;
2381 del_from_flist(flp - flist, fep - flp->fents);
2383 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
2388 unresvsp_f(int opno, long r)
2400 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2402 printf("%d/%d: unresvsp - no filename\n", procid, opno);
2406 fd = open_path(&f, O_RDWR);
2407 e = fd < 0 ? errno : 0;
2411 printf("%d/%d: unresvsp - open %s failed %d\n",
2412 procid, opno, f.path, e);
2416 if (fstat64(fd, &stb) < 0) {
2418 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
2419 procid, opno, f.path, errno);
2424 lr = ((__int64_t)random() << 32) + random();
2425 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2427 fl.l_whence = SEEK_SET;
2429 fl.l_len = (off64_t)(random() % (1 << 20));
2430 e = ioctl(fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
2432 printf("%d/%d: ioctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
2433 procid, opno, f.path, off, fl.l_len, e);
2439 write_f(int opno, long r)
2452 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
2454 printf("%d/%d: write - no filename\n", procid, opno);
2458 fd = open_path(&f, O_WRONLY);
2459 e = fd < 0 ? errno : 0;
2463 printf("%d/%d: write - open %s failed %d\n",
2464 procid, opno, f.path, e);
2468 if (fstat64(fd, &stb) < 0) {
2470 printf("%d/%d: write - fstat64 %s failed %d\n",
2471 procid, opno, f.path, errno);
2476 lr = ((__int64_t)random() << 32) + random();
2477 off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2479 lseek64(fd, off, SEEK_SET);
2480 len = (random() % (getpagesize() * 32)) + 1;
2482 memset(buf, nameseq & 0xff, len);
2483 e = write(fd, buf, len) < 0 ? errno : 0;
2486 printf("%d/%d: write %s [%lld,%d] %d\n",
2487 procid, opno, f.path, off, len, e);