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.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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/
34 #define HAVE_SYS_PRCTL_H
35 #define _LARGEFILE64_SOURCE
37 #define MAXNAMELEN 1024
39 int d_miniosz, d_maxiosz, d_mem;
42 #define MIN(a,b) ((a)<(b) ? (a):(b))
43 #define MAX(a,b) ((a)>(b) ? (a):(b))
46 #include <sys/statvfs.h>
48 #include <sys/ioctl.h>
50 #include <sys/types.h>
61 #define O_DIRECT 040000
64 #ifdef HAVE_SYS_PRCTL_H
65 # include <sys/prctl.h>
68 #define XFS_ERRTAG_MAX 17
110 typedef void (*opfnc_t) (int, long);
112 typedef struct opdesc {
121 typedef struct fent {
126 typedef struct flist {
133 typedef struct pathname {
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 allocsp_f(int, long);
160 void attr_remove_f(int, long);
161 void attr_set_f(int, long);
162 void bulkstat_f(int, long);
163 void bulkstat1_f(int, long);
164 void chown_f(int, long);
165 void creat_f(int, long);
166 void dread_f(int, long);
167 void dwrite_f(int, long);
168 void fdatasync_f(int, long);
169 void freesp_f(int, long);
170 void fsync_f(int, long);
171 void getdents_f(int, long);
172 void link_f(int, long);
173 void mkdir_f(int, long);
174 void mknod_f(int, long);
175 void read_f(int, long);
176 void readlink_f(int, long);
177 void rename_f(int, long);
178 void resvsp_f(int, long);
179 void rmdir_f(int, long);
180 void stat_f(int, long);
181 void symlink_f(int, long);
182 void sync_f(int, long);
183 void truncate_f(int, long);
184 void unlink_f(int, long);
185 void unresvsp_f(int, long);
186 void write_f(int, long);
190 {OP_ALLOCSP, "allocsp", allocsp_f, 1, 1, 1},
191 {OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1, 1},
192 {OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1, 1},
193 {OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0, 1},
194 {OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0, 1},
196 {OP_CHOWN, "chown", chown_f, 3, 1, 0},
197 {OP_CREAT, "creat", creat_f, 4, 1, 0},
198 {OP_DREAD, "dread", dread_f, 4, 0, 0},
199 {OP_DWRITE, "dwrite", dwrite_f, 4, 1, 0},
200 {OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1, 0},
202 {OP_FREESP, "freesp", freesp_f, 1, 1, 1},
204 {OP_FSYNC, "fsync", fsync_f, 1, 1, 0},
205 {OP_GETDENTS, "getdents", getdents_f, 1, 0, 0},
206 {OP_LINK, "link", link_f, 1, 1, 0},
207 {OP_MKDIR, "mkdir", mkdir_f, 2, 1, 0},
208 {OP_MKNOD, "mknod", mknod_f, 2, 1, 0},
209 {OP_READ, "read", read_f, 1, 0, 0},
210 {OP_READLINK, "readlink", readlink_f, 1, 0, 0},
211 {OP_RENAME, "rename", rename_f, 2, 1, 0},
213 {OP_RESVSP, "resvsp", resvsp_f, 1, 1, 1},
215 {OP_RMDIR, "rmdir", rmdir_f, 1, 1, 0},
216 {OP_STAT, "stat", stat_f, 1, 0, 0},
217 {OP_SYMLINK, "symlink", symlink_f, 2, 1, 0},
218 {OP_SYNC, "sync", sync_f, 1, 0, 0},
219 {OP_TRUNCATE, "truncate", truncate_f, 2, 1, 0},
220 {OP_UNLINK, "unlink", unlink_f, 1, 1, 0},
222 {OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1, 1},
224 {OP_WRITE, "write", write_f, 4, 1, 0},
227 flist_t flist[FT_nft] = {
241 xfs_fsop_geom_t geom;
255 unsigned long seed = 0;
263 sig_atomic_t should_stop = 0;
265 void add_to_flist(int, int, int);
266 void append_pathname(pathname_t *, char *);
268 int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
269 int attr_remove_path(pathname_t *, const char *, int);
270 int attr_set_path(pathname_t *, const char *, const char *, const int, int);
272 void check_cwd(void);
273 int creat_path(pathname_t *, mode_t);
274 void dcache_enter(int, int);
275 void dcache_init(void);
276 fent_t *dcache_lookup(int);
277 void dcache_purge(int);
278 void del_from_flist(int, int);
279 int dirid_to_name(char *, int);
281 void fent_to_name(pathname_t *, flist_t *, fent_t *);
282 void fix_parent(int, int);
283 void free_pathname(pathname_t *);
284 int generate_fname(fent_t *, int, pathname_t *, int *, int *);
285 int get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
286 void init_pathname(pathname_t *);
287 int lchown_path(pathname_t *, uid_t, gid_t);
288 int link_path(pathname_t *, pathname_t *);
289 int lstat64_path(pathname_t *, struct stat64 *);
290 void make_freq_table(void);
291 int mkdir_path(pathname_t *, mode_t);
292 int mknod_path(pathname_t *, mode_t, dev_t);
293 void namerandpad(int, char *, int);
294 int open_path(pathname_t *, int);
295 DIR *opendir_path(pathname_t *);
296 void process_freq(char *);
297 int readlink_path(pathname_t *, char *, size_t);
298 int rename_path(pathname_t *, pathname_t *);
299 int rmdir_path(pathname_t *);
300 void separate_pathname(pathname_t *, char *, pathname_t *);
301 void show_ops(int, char *);
302 int stat64_path(pathname_t *, struct stat64 *);
303 int symlink_path(const char *, pathname_t *);
304 int truncate64_path(pathname_t *, off64_t);
305 int unlink_path(pathname_t *);
307 void write_freq(void);
308 void zero_freq(void);
310 void sg_handler(int signum)
315 int main(int argc, char **argv)
319 char *dirname = NULL;
337 xfs_error_injection_t err_inj;
339 struct sigaction action;
341 errrange = errtag = 0;
343 nops = sizeof(ops) / sizeof(ops[0]);
344 ops_end = &ops[nops];
346 while ((c = getopt(argc, argv, "cd:e:f:i:l:n:p:rs:vwzHSX")) != -1) {
356 sscanf(optarg, "%d", &errtag);
360 } else if (errtag == 0)
362 if (errtag >= XFS_ERRTAG_MAX) {
364 "error tag %d too large (max %d)\n",
365 errtag, XFS_ERRTAG_MAX - 1);
370 process_freq(optarg);
373 ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
374 ilist[ilistlen - 1] = strtol(optarg, &p, 16);
377 loops = atoi(optarg);
380 operations = atoi(optarg);
383 nproc = atoi(optarg);
389 seed = strtoul(optarg, NULL, 0);
406 fprintf(stderr, "%s - invalid parameters\n", myprog);
417 if (no_xfs && errtag) {
418 fprintf(stderr, "error injection only works on XFS\n");
424 for (i = 0; ops + i < ops_end; ++i) {
432 while (((loopcntr <= loops) || (loops == 0)) && !should_stop) {
434 /* no directory specified */
440 (void)mkdir(dirname, 0777);
441 if (chdir(dirname) < 0) {
445 sprintf(buf, "fss%x", getpid());
446 fd = creat(buf, 0666);
447 if (lseek64(fd, (off64_t) (MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
448 maxfsize = (off64_t) MAXFSIZE32;
450 maxfsize = (off64_t) MAXFSIZE;
454 gettimeofday(&t, NULL);
455 seed = (int)t.tv_sec ^ (int)t.tv_usec;
456 printf("seed = %ld\n", seed);
460 memset(&geom, 0, sizeof(geom));
461 i = ioctl(fd, XFS_IOC_FSGEOMETRY, &geom);
462 if (i >= 0 && geom.rtblocks)
463 rtpct = MIN(MAX(geom.rtblocks * 100 /
465 geom.datablocks), 1), 99);
475 for (i = 0; i < j; i++)
479 (random() % (XFS_ERRTAG_MAX - 1)) +
486 for (i = 0; i < j; i++)
490 (random() % (XFS_ERRTAG_MAX - errtag));
492 printf("Injecting failure on tag #%d\n", errtag);
493 memset(&err_inj, 0, sizeof(err_inj));
494 err_inj.errtag = errtag;
496 srval = ioctl(fd, XFS_IOC_ERROR_INJECTION, &err_inj);
499 ("fsstress - XFS_SYSSGI error injection call");
515 action.sa_handler = sg_handler;
516 sigemptyset(&action.sa_mask);
518 if (sigaction(SIGTERM, &action, 0)) {
519 perror("sigaction failed");
523 for (i = 0; i < nproc; i++) {
526 action.sa_handler = SIG_DFL;
527 sigemptyset(&action.sa_mask);
528 if (sigaction(SIGTERM, &action, 0))
530 #ifdef HAVE_SYS_PRCTL_H
531 prctl(PR_SET_PDEATHSIG, SIGKILL);
532 if (getppid() == 1) /* parent died already? */
540 while (wait(&stat) > 0 && !should_stop) {
544 action.sa_flags = SA_RESTART;
545 sigaction(SIGTERM, &action, 0);
546 kill(-getpid(), SIGTERM);
547 while (wait(&stat) > 0)
553 memset(&err_inj, 0, sizeof(err_inj));
557 ioctl(fd, XFS_IOC_ERROR_CLEARALL,
559 fprintf(stderr, "Bad ej clear on %d (%d).\n",
562 ("fsstress - XFS_SYSSGI clear error injection call");
570 sprintf(cmd, "rm -rf %s/*", dirname);
572 for (i = 0; i < FT_nft; i++) {
575 free(flist[i].fents);
576 flist[i].fents = NULL;
584 void add_to_flist(int ft, int id, int parent)
590 if (ftp->nfiles == ftp->nslots) {
591 ftp->nslots += FLIST_SLOT_INCR;
592 ftp->fents = realloc(ftp->fents, ftp->nslots * sizeof(fent_t));
594 fep = &ftp->fents[ftp->nfiles++];
596 fep->parent = parent;
599 void append_pathname(pathname_t * name, char *str)
605 if (len && *str == '/' && name->len == 0) {
606 fprintf(stderr, "fsstress: append_pathname failure\n");
612 name->path = realloc(name->path, name->len + 1 + len);
613 strcpy(&name->path[name->len], str);
619 attr_list_path(pathname_t * name, char *buffer, const int buffersize, int flags,
620 attrlist_cursor_t * cursor)
622 char buf[MAXNAMELEN];
626 rval = attr_list(name->path, buffer, buffersize, flags, cursor);
627 if (rval >= 0 || errno != ENAMETOOLONG)
629 separate_pathname(name, buf, &newname);
630 if (chdir(buf) == 0) {
631 rval = attr_list_path(&newname, buffer, buffersize, flags,
635 free_pathname(&newname);
639 int attr_remove_path(pathname_t * name, const char *attrname, int flags)
641 char buf[MAXNAMELEN];
645 rval = attr_remove(name->path, attrname, flags);
646 if (rval >= 0 || errno != ENAMETOOLONG)
648 separate_pathname(name, buf, &newname);
649 if (chdir(buf) == 0) {
650 rval = attr_remove_path(&newname, attrname, flags);
653 free_pathname(&newname);
658 attr_set_path(pathname_t * name, const char *attrname, const char *attrvalue,
659 const int valuelength, int flags)
661 char buf[MAXNAMELEN];
665 rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
666 if (rval >= 0 || errno != ENAMETOOLONG)
668 separate_pathname(name, buf, &newname);
669 if (chdir(buf) == 0) {
670 rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
674 free_pathname(&newname);
682 struct stat64 statbuf;
684 if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
687 fprintf(stderr, "fsstress: check_cwd failure\n");
693 int creat_path(pathname_t * name, mode_t mode)
695 char buf[MAXNAMELEN];
699 rval = creat(name->path, mode);
700 if (rval >= 0 || errno != ENAMETOOLONG)
702 separate_pathname(name, buf, &newname);
703 if (chdir(buf) == 0) {
704 rval = creat_path(&newname, mode);
707 free_pathname(&newname);
711 void dcache_enter(int dirid, int slot)
713 dcache[dirid % NDCACHE] = slot;
716 void dcache_init(void)
720 for (i = 0; i < NDCACHE; i++)
724 fent_t *dcache_lookup(int dirid)
729 i = dcache[dirid % NDCACHE];
730 if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
735 void dcache_purge(int dirid)
739 dcp = &dcache[dirid % NDCACHE];
740 if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
744 void del_from_flist(int ft, int slot)
750 dcache_purge(ftp->fents[slot].id);
751 if (slot != ftp->nfiles - 1) {
753 dcache_purge(ftp->fents[ftp->nfiles - 1].id);
754 ftp->fents[slot] = ftp->fents[--ftp->nfiles];
759 fent_t *dirid_to_fent(int dirid)
765 if ((fep = dcache_lookup(dirid)))
767 flp = &flist[FT_DIR];
768 for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
769 if (fep->id == dirid) {
770 dcache_enter(dirid, fep - flp->fents);
779 struct stat64 statbuf;
785 sprintf(buf, "p%x", procid);
786 (void)mkdir(buf, 0777);
787 if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
791 top_ino = statbuf.st_ino;
792 homedir = getcwd(NULL, -1);
797 for (opno = 0; opno < operations; opno++) {
798 p = &ops[freq_table[random() % freq_table_size]];
799 if ((unsigned long)p->func < 4096)
802 p->func(opno, random());
804 * test for forced shutdown by stat'ing the test
805 * directory. If this stat returns EIO, assume
806 * the forced shutdown happened.
808 if (errtag != 0 && opno % 100 == 0) {
809 rval = stat64(".", &statbuf);
811 fprintf(stderr, "Detected EIO\n");
818 void fent_to_name(pathname_t * name, flist_t * flp, fent_t * fep)
820 char buf[MAXNAMELEN];
826 if (fep->parent != -1) {
827 pfep = dirid_to_fent(fep->parent);
828 fent_to_name(name, &flist[FT_DIR], pfep);
829 append_pathname(name, "/");
831 i = sprintf(buf, "%c%x", flp->tag, fep->id);
832 namerandpad(fep->id, buf, i);
833 append_pathname(name, buf);
836 void fix_parent(int oldid, int newid)
843 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
844 for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
845 if (fep->parent == oldid)
851 void free_pathname(pathname_t * name)
860 int generate_fname(fent_t * fep, int ft, pathname_t * name, int *idp, int *v)
862 char buf[MAXNAMELEN];
869 len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
870 namerandpad(id, buf, len);
872 fent_to_name(name, &flist[FT_DIR], fep);
873 append_pathname(name, "/");
875 append_pathname(name, buf);
878 for (j = 0; !*v && j < ilistlen; j++) {
879 if (ilist[j] == id) {
888 get_fname(int which, long r, pathname_t * name, flist_t ** flpp, fent_t ** fepp,
898 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
899 if (which & (1 << i))
911 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
912 if (which & (1 << i)) {
913 if (x < c + flp->nfiles) {
914 fep = &flp->fents[x - c];
916 fent_to_name(name, flp, fep);
922 for (j = 0; !*v && j < ilistlen; j++) {
923 if (ilist[j] == fep->id) {
934 fprintf(stderr, "fsstress: get_fname failure\n");
941 void init_pathname(pathname_t * name)
947 int lchown_path(pathname_t * name, uid_t owner, gid_t group)
949 char buf[MAXNAMELEN];
953 rval = lchown(name->path, owner, group);
954 if (rval >= 0 || errno != ENAMETOOLONG)
956 separate_pathname(name, buf, &newname);
957 if (chdir(buf) == 0) {
958 rval = lchown_path(&newname, owner, group);
961 free_pathname(&newname);
965 int link_path(pathname_t * name1, pathname_t * name2)
967 char buf1[MAXNAMELEN];
968 char buf2[MAXNAMELEN];
974 rval = link(name1->path, name2->path);
975 if (rval >= 0 || errno != ENAMETOOLONG)
977 separate_pathname(name1, buf1, &newname1);
978 separate_pathname(name2, buf2, &newname2);
979 if (strcmp(buf1, buf2) == 0) {
980 if (chdir(buf1) == 0) {
981 rval = link_path(&newname1, &newname2);
985 if (strcmp(buf1, "..") == 0)
987 else if (strcmp(buf2, "..") == 0)
989 else if (strlen(buf1) == 0)
991 else if (strlen(buf2) == 0)
994 down1 = MAX(newname1.len, 3 + name2->len) <=
995 MAX(3 + name1->len, newname2.len);
997 free_pathname(&newname2);
998 append_pathname(&newname2, "../");
999 append_pathname(&newname2, name2->path);
1000 if (chdir(buf1) == 0) {
1001 rval = link_path(&newname1, &newname2);
1005 free_pathname(&newname1);
1006 append_pathname(&newname1, "../");
1007 append_pathname(&newname1, name1->path);
1008 if (chdir(buf2) == 0) {
1009 rval = link_path(&newname1, &newname2);
1014 free_pathname(&newname1);
1015 free_pathname(&newname2);
1019 int lstat64_path(pathname_t * name, struct stat64 *sbuf)
1021 char buf[MAXNAMELEN];
1025 rval = lstat64(name->path, sbuf);
1026 if (rval >= 0 || errno != ENAMETOOLONG)
1028 separate_pathname(name, buf, &newname);
1029 if (chdir(buf) == 0) {
1030 rval = lstat64_path(&newname, sbuf);
1033 free_pathname(&newname);
1037 void make_freq_table(void)
1043 for (p = ops, f = 0; p < ops_end; p++)
1045 freq_table = malloc(f * sizeof(*freq_table));
1046 freq_table_size = f;
1047 for (p = ops, i = 0; p < ops_end; p++) {
1048 for (f = 0; f < p->freq; f++, i++)
1049 freq_table[i] = p->op;
1053 int mkdir_path(pathname_t * name, mode_t mode)
1055 char buf[MAXNAMELEN];
1059 rval = mkdir(name->path, mode);
1060 if (rval >= 0 || errno != ENAMETOOLONG)
1062 separate_pathname(name, buf, &newname);
1063 if (chdir(buf) == 0) {
1064 rval = mkdir_path(&newname, mode);
1067 free_pathname(&newname);
1071 int mknod_path(pathname_t * name, mode_t mode, dev_t dev)
1073 char buf[MAXNAMELEN];
1077 rval = mknod(name->path, mode, dev);
1078 if (rval >= 0 || errno != ENAMETOOLONG)
1080 separate_pathname(name, buf, &newname);
1081 if (chdir(buf) == 0) {
1082 rval = mknod_path(&newname, mode, dev);
1085 free_pathname(&newname);
1089 void namerandpad(int id, char *buf, int i)
1092 static int buckets[] = { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 };
1098 bucket = (id ^ namerand) % (sizeof(buckets) / sizeof(buckets[0]));
1099 padmod = buckets[bucket] + 1 - i;
1102 padlen = (id ^ namerand) % padmod;
1104 memset(&buf[i], 'X', padlen);
1105 buf[i + padlen] = '\0';
1109 int open_path(pathname_t * name, int oflag)
1111 char buf[MAXNAMELEN];
1115 rval = open(name->path, oflag);
1116 if (rval >= 0 || errno != ENAMETOOLONG)
1118 separate_pathname(name, buf, &newname);
1119 if (chdir(buf) == 0) {
1120 rval = open_path(&newname, oflag);
1123 free_pathname(&newname);
1127 DIR *opendir_path(pathname_t * name)
1129 char buf[MAXNAMELEN];
1133 rval = opendir(name->path);
1134 if (rval || errno != ENAMETOOLONG)
1136 separate_pathname(name, buf, &newname);
1137 if (chdir(buf) == 0) {
1138 rval = opendir_path(&newname);
1141 free_pathname(&newname);
1145 void process_freq(char *arg)
1150 s = strchr(arg, '=');
1152 fprintf(stderr, "bad argument '%s'\n", arg);
1156 for (p = ops; p < ops_end; p++) {
1157 if (strcmp(arg, p->name) == 0) {
1162 fprintf(stderr, "can't find op type %s for -f\n", arg);
1166 int readlink_path(pathname_t * name, char *lbuf, size_t lbufsiz)
1168 char buf[MAXNAMELEN];
1172 rval = readlink(name->path, lbuf, lbufsiz);
1173 if (rval >= 0 || errno != ENAMETOOLONG)
1175 separate_pathname(name, buf, &newname);
1176 if (chdir(buf) == 0) {
1177 rval = readlink_path(&newname, lbuf, lbufsiz);
1180 free_pathname(&newname);
1184 int rename_path(pathname_t * name1, pathname_t * name2)
1186 char buf1[MAXNAMELEN];
1187 char buf2[MAXNAMELEN];
1189 pathname_t newname1;
1190 pathname_t newname2;
1193 rval = rename(name1->path, name2->path);
1194 if (rval >= 0 || errno != ENAMETOOLONG)
1196 separate_pathname(name1, buf1, &newname1);
1197 separate_pathname(name2, buf2, &newname2);
1198 if (strcmp(buf1, buf2) == 0) {
1199 if (chdir(buf1) == 0) {
1200 rval = rename_path(&newname1, &newname2);
1204 if (strcmp(buf1, "..") == 0)
1206 else if (strcmp(buf2, "..") == 0)
1208 else if (strlen(buf1) == 0)
1210 else if (strlen(buf2) == 0)
1213 down1 = MAX(newname1.len, 3 + name2->len) <=
1214 MAX(3 + name1->len, newname2.len);
1216 free_pathname(&newname2);
1217 append_pathname(&newname2, "../");
1218 append_pathname(&newname2, name2->path);
1219 if (chdir(buf1) == 0) {
1220 rval = rename_path(&newname1, &newname2);
1224 free_pathname(&newname1);
1225 append_pathname(&newname1, "../");
1226 append_pathname(&newname1, name1->path);
1227 if (chdir(buf2) == 0) {
1228 rval = rename_path(&newname1, &newname2);
1233 free_pathname(&newname1);
1234 free_pathname(&newname2);
1238 int rmdir_path(pathname_t * name)
1240 char buf[MAXNAMELEN];
1244 rval = rmdir(name->path);
1245 if (rval >= 0 || errno != ENAMETOOLONG)
1247 separate_pathname(name, buf, &newname);
1248 if (chdir(buf) == 0) {
1249 rval = rmdir_path(&newname);
1252 free_pathname(&newname);
1256 void separate_pathname(pathname_t * name, char *buf, pathname_t * newname)
1260 init_pathname(newname);
1261 slash = strchr(name->path, '/');
1262 if (slash == NULL) {
1267 strcpy(buf, name->path);
1269 append_pathname(newname, slash + 1);
1274 void show_ops(int flag, char *lead_str)
1279 /* print in list form */
1282 for (p = ops; p < ops_end; p++) {
1283 if (lead_str != NULL
1284 && x + strlen(p->name) >= WIDTH - 5)
1285 x = printf("%s%s", (p == ops) ? "" : "\n",
1287 x += printf("%s ", p->name);
1292 for (f = 0, p = ops; p < ops_end; p++)
1298 for (p = ops; p < ops_end; p++) {
1299 if (flag != 0 || p->freq > 0) {
1300 if (lead_str != NULL)
1301 printf("%s", lead_str);
1302 printf("%20s %d/%d %s\n",
1303 p->name, p->freq, f,
1304 (p->iswrite == 0) ? " " : "write op");
1310 int stat64_path(pathname_t * name, struct stat64 *sbuf)
1312 char buf[MAXNAMELEN];
1316 rval = stat64(name->path, sbuf);
1317 if (rval >= 0 || errno != ENAMETOOLONG)
1319 separate_pathname(name, buf, &newname);
1320 if (chdir(buf) == 0) {
1321 rval = stat64_path(&newname, sbuf);
1324 free_pathname(&newname);
1328 int symlink_path(const char *name1, pathname_t * name)
1330 char buf[MAXNAMELEN];
1334 if (!strcmp(name1, name->path)) {
1335 printf("yikes! %s %s\n", name1, name->path);
1339 rval = symlink(name1, name->path);
1340 if (rval >= 0 || errno != ENAMETOOLONG)
1342 separate_pathname(name, buf, &newname);
1343 if (chdir(buf) == 0) {
1344 rval = symlink_path(name1, &newname);
1347 free_pathname(&newname);
1351 int truncate64_path(pathname_t * name, off64_t length)
1353 char buf[MAXNAMELEN];
1357 rval = truncate64(name->path, length);
1358 if (rval >= 0 || errno != ENAMETOOLONG)
1360 separate_pathname(name, buf, &newname);
1361 if (chdir(buf) == 0) {
1362 rval = truncate64_path(&newname, length);
1365 free_pathname(&newname);
1369 int unlink_path(pathname_t * name)
1371 char buf[MAXNAMELEN];
1375 rval = unlink(name->path);
1376 if (rval >= 0 || errno != ENAMETOOLONG)
1378 separate_pathname(name, buf, &newname);
1379 if (chdir(buf) == 0) {
1380 rval = unlink_path(&newname);
1383 free_pathname(&newname);
1389 printf("Usage: %s -H or\n", myprog);
1391 (" %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
1393 printf(" [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
1396 (" -c specifies not to remove files(cleanup) after execution\n");
1398 (" -d dir specifies the base directory for operations\n");
1399 printf(" -e errtg specifies error injection stuff\n");
1401 (" -f op_name=freq changes the frequency of option name to freq\n");
1402 printf(" the valid operation names are:\n");
1405 (" -l loops specifies the no. of times the testrun should loop.\n");
1406 printf(" *use 0 for infinite (default 1)\n");
1408 (" -n nops specifies the no. of operations per process (default 1)\n");
1410 (" -p nproc specifies the no. of processes (default 1)\n");
1411 printf(" -r specifies random name padding\n");
1413 (" -s seed specifies the seed for the random generator (default random)\n");
1414 printf(" -v specifies verbose mode\n");
1416 (" -w zeros frequencies of non-write operations\n");
1417 printf(" -z zeros frequencies of all operations\n");
1419 (" -S prints the table of operations (omitting zero frequency)\n");
1420 printf(" -H prints usage and exits\n");
1422 (" -X don't do anything XFS specific (default with -DNO_XFS)\n");
1425 void write_freq(void)
1429 for (p = ops; p < ops_end; p++) {
1435 void zero_freq(void)
1439 for (p = ops; p < ops_end; p++)
1445 void allocsp_f(int opno, long r)
1450 struct xfs_flock64 fl;
1457 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1459 printf("%d/%d: allocsp - no filename\n", procid, opno);
1463 fd = open_path(&f, O_RDWR);
1464 e = fd < 0 ? errno : 0;
1468 printf("%d/%d: allocsp - open %s failed %d\n",
1469 procid, opno, f.path, e);
1473 if (fstat64(fd, &stb) < 0) {
1475 printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1476 procid, opno, f.path, errno);
1481 lr = ((__s64) random() << 32) + random();
1482 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
1484 memset(&fl, 0, sizeof(fl));
1485 fl.l_whence = SEEK_SET;
1488 e = ioctl(fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1490 printf("%d/%d: ioctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
1491 procid, opno, f.path, (long long)off, e);
1496 void attr_remove_f(int opno, long r)
1498 attrlist_ent_t *aep;
1502 attrlist_cursor_t cursor;
1511 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1512 append_pathname(&f, ".");
1514 memset(&cursor, 0x00, sizeof(cursor));
1516 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1521 alist = (attrlist_t *) buf;
1522 total += alist->al_count;
1523 } while (alist->al_more);
1526 printf("%d/%d: attr_remove - no attrs for %s\n",
1527 procid, opno, f.path);
1531 which = (int)(random() % total);
1532 memset(&cursor, 0x00, sizeof(cursor));
1536 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1541 alist = (attrlist_t *) buf;
1542 if (which < ent + alist->al_count) {
1543 aep = (attrlist_ent_t *)
1544 & buf[alist->al_offset[which - ent]];
1545 aname = aep->a_name;
1548 ent += alist->al_count;
1549 } while (alist->al_more);
1550 if (aname == NULL) {
1552 printf("%d/%d: attr_remove - name %d not found at %s\n",
1553 procid, opno, which, f.path);
1557 e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
1560 printf("%d/%d: attr_remove %s %s %d\n",
1561 procid, opno, f.path, aname, e);
1565 void attr_set_f(int opno, long r)
1572 static int lengths[] = { 10, 100, 1000, 10000 };
1577 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1578 append_pathname(&f, ".");
1579 sprintf(aname, "a%x", nameseq++);
1580 li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
1581 len = (int)(random() % lengths[li]);
1585 memset(aval, nameseq & 0xff, len);
1586 e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
1591 printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
1596 void bulkstat_f(int opno, long r)
1604 xfs_fsop_bulkreq_t bsr;
1607 nent = (r % 999) + 2;
1608 t = malloc(nent * sizeof(*t));
1609 fd = open(".", O_RDONLY);
1612 memset(&bsr, 0, sizeof(bsr));
1616 bsr.ocount = &count;
1618 while (ioctl(fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
1622 printf("%d/%d: bulkstat nent %d total %lld\n",
1623 procid, opno, (int)nent, (long long)total);
1627 void bulkstat1_f(int opno, long r)
1637 xfs_fsop_bulkreq_t bsr;
1639 good = random() & 1;
1641 /* use an inode we know exists */
1643 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1644 append_pathname(&f, ".");
1645 ino = stat64_path(&f, &s) < 0 ? (ino64_t) r : s.st_ino;
1650 * pick a random inode
1652 * note this can generate kernel warning messages
1653 * since bulkstat_one will read the disk block that
1654 * would contain a given inode even if that disk
1655 * block doesn't contain inodes.
1657 * this is detected later, but not until after the
1658 * warning is displayed.
1660 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
1666 fd = open(".", O_RDONLY);
1668 memset(&bsr, 0, sizeof(bsr));
1674 e = ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
1676 printf("%d/%d: bulkstat1 %s ino %lld %d\n",
1677 procid, opno, good ? "real" : "random",
1684 void chown_f(int opno, long r)
1693 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1694 append_pathname(&f, ".");
1695 u = (uid_t) random();
1696 nbits = (int)(random() % 32);
1697 u &= (1 << nbits) - 1;
1698 e = lchown_path(&f, u, -1) < 0 ? errno : 0;
1701 printf("%d/%d: chown %s %d %d\n", procid, opno, f.path, u, e);
1705 void creat_f(int opno, long r)
1720 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
1725 type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
1727 extsize = (random() % 10) + 1;
1730 e = generate_fname(fep, type, &f, &id, &v);
1734 fent_to_name(&f, &flist[FT_DIR], fep);
1735 printf("%d/%d: creat - no filename from %s\n",
1736 procid, opno, f.path);
1741 fd = creat_path(&f, 0666);
1742 e = fd < 0 ? errno : 0;
1749 memset(&a, 0, sizeof(a));
1750 if (extsize && ioctl(fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
1751 a.fsx_xflags |= XFS_XFLAG_REALTIME;
1753 geom.rtextsize * geom.blocksize * extsize;
1754 if (ioctl(fd, XFS_IOC_FSSETXATTR, &a) < 0)
1756 esz = a.fsx_extsize;
1760 add_to_flist(type, id, parid);
1764 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
1769 int setdirect(int fd)
1771 static int no_direct;
1777 flags = fcntl(fd, F_GETFL, 0);
1781 if (fcntl(fd, F_SETFL, flags | O_DIRECT) < 0) {
1786 printf("cannot set O_DIRECT: %s\n", strerror(errno));
1793 void dread_f(int opno, long r)
1797 struct dioattr diob;
1808 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1810 printf("%d/%d: dread - no filename\n", procid, opno);
1814 fd = open_path(&f, O_RDONLY);
1816 e = fd < 0 ? errno : 0;
1820 printf("%d/%d: dread - open %s failed %d\n",
1821 procid, opno, f.path, e);
1826 if (!setdirect(fd)) {
1832 if (fstat64(fd, &stb) < 0) {
1834 printf("%d/%d: dread - fstat64 %s failed %d\n",
1835 procid, opno, f.path, errno);
1840 if (stb.st_size == 0) {
1842 printf("%d/%d: dread - %s zero size\n", procid, opno,
1849 memset(&diob, 0, sizeof(diob));
1851 diob.d_miniosz = stb.st_blksize;
1852 diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */
1853 diob.d_mem = stb.st_blksize;
1856 else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1859 ("%d/%d: dread - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1860 procid, opno, f.path, errno);
1866 align = (__int64_t) diob.d_miniosz;
1867 lr = ((__int64_t) random() << 32) + random();
1868 off = (off64_t) (lr % stb.st_size);
1869 off -= (off % align);
1870 lseek64(fd, off, SEEK_SET);
1871 len = (random() % (getpagesize() * 32)) + 1;
1872 len -= (len % align);
1875 else if (len > diob.d_maxiosz)
1876 len = diob.d_maxiosz;
1877 if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1878 fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1882 fprintf(stderr, "posix_memalign: buf is NULL\n");
1885 e = read(fd, buf, len) < 0 ? errno : 0;
1888 printf("%d/%d: dread %s [%lld,%ld] %d\n",
1889 procid, opno, f.path, (long long int)off, (long)len, e);
1894 void dwrite_f(int opno, long r)
1898 struct dioattr diob;
1909 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1911 printf("%d/%d: dwrite - no filename\n", procid, opno);
1915 fd = open_path(&f, O_WRONLY);
1916 e = fd < 0 ? errno : 0;
1920 printf("%d/%d: dwrite - open %s failed %d\n",
1921 procid, opno, f.path, e);
1926 if (!setdirect(fd)) {
1931 if (fstat64(fd, &stb) < 0) {
1933 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
1934 procid, opno, f.path, errno);
1939 memset(&diob, 0, sizeof(diob));
1941 diob.d_miniosz = stb.st_blksize;
1942 diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */
1943 diob.d_mem = stb.st_blksize;
1946 else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1949 ("%d/%d: dwrite - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1950 procid, opno, f.path, errno);
1956 align = (__int64_t) diob.d_miniosz;
1957 lr = ((__int64_t) random() << 32) + random();
1958 off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1959 off -= (off % align);
1960 lseek64(fd, off, SEEK_SET);
1961 len = (random() % (getpagesize() * 32)) + 1;
1962 len -= (len % align);
1965 else if (len > diob.d_maxiosz)
1966 len = diob.d_maxiosz;
1967 if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1968 fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1972 fprintf(stderr, "posix_memalign: buf is NULL\n");
1976 lseek64(fd, off, SEEK_SET);
1977 memset(buf, nameseq & 0xff, len);
1978 e = write(fd, buf, len) < 0 ? errno : 0;
1981 printf("%d/%d: dwrite %s [%lld,%ld] %d\n",
1982 procid, opno, f.path, (long long)off, (long int)len, e);
1987 void fdatasync_f(int opno, long r)
1995 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1997 printf("%d/%d: fdatasync - no filename\n",
2002 fd = open_path(&f, O_WRONLY);
2003 e = fd < 0 ? errno : 0;
2007 printf("%d/%d: fdatasync - open %s failed %d\n",
2008 procid, opno, f.path, e);
2012 e = fdatasync(fd) < 0 ? errno : 0;
2014 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
2020 void freesp_f(int opno, long r)
2025 struct xfs_flock64 fl;
2032 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2034 printf("%d/%d: freesp - no filename\n", procid, opno);
2038 fd = open_path(&f, O_RDWR);
2039 e = fd < 0 ? errno : 0;
2043 printf("%d/%d: freesp - open %s failed %d\n",
2044 procid, opno, f.path, e);
2048 if (fstat64(fd, &stb) < 0) {
2050 printf("%d/%d: freesp - fstat64 %s failed %d\n",
2051 procid, opno, f.path, errno);
2056 lr = ((__s64) random() << 32) + random();
2057 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2059 memset(&fl, 0, sizeof(fl));
2060 fl.l_whence = SEEK_SET;
2063 e = ioctl(fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
2065 printf("%d/%d: ioctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
2066 procid, opno, f.path, (long long)off, e);
2073 void fsync_f(int opno, long r)
2081 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2083 printf("%d/%d: fsync - no filename\n", procid, opno);
2087 fd = open_path(&f, O_WRONLY);
2088 e = fd < 0 ? errno : 0;
2092 printf("%d/%d: fsync - open %s failed %d\n",
2093 procid, opno, f.path, e);
2097 e = fsync(fd) < 0 ? errno : 0;
2099 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
2104 void getdents_f(int opno, long r)
2111 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
2112 append_pathname(&f, ".");
2113 dir = opendir_path(&f);
2117 printf("%d/%d: getdents - can't open %s\n",
2118 procid, opno, f.path);
2122 while (readdir64(dir) != NULL)
2125 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
2130 void link_f(int opno, long r)
2143 if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
2145 printf("%d/%d: link - no file\n", procid, opno);
2149 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
2155 e = generate_fname(fep, flp - flist, &l, &id, &v1);
2159 fent_to_name(&l, &flist[FT_DIR], fep);
2160 printf("%d/%d: link - no filename from %s\n",
2161 procid, opno, l.path);
2167 e = link_path(&f, &l) < 0 ? errno : 0;
2170 add_to_flist(flp - flist, id, parid);
2172 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
2178 void mkdir_f(int opno, long r)
2188 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2193 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
2197 fent_to_name(&f, &flist[FT_DIR], fep);
2198 printf("%d/%d: mkdir - no filename from %s\n",
2199 procid, opno, f.path);
2204 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
2207 add_to_flist(FT_DIR, id, parid);
2209 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
2213 void mknod_f(int opno, long r)
2223 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2228 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
2232 fent_to_name(&f, &flist[FT_DIR], fep);
2233 printf("%d/%d: mknod - no filename from %s\n",
2234 procid, opno, f.path);
2239 e = mknod_path(&f, S_IFCHR | 0444, 0) < 0 ? errno : 0;
2242 add_to_flist(FT_DEV, id, parid);
2244 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
2248 void read_f(int opno, long r)
2261 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2263 printf("%d/%d: read - no filename\n", procid, opno);
2267 fd = open_path(&f, O_RDONLY);
2268 e = fd < 0 ? errno : 0;
2272 printf("%d/%d: read - open %s failed %d\n",
2273 procid, opno, f.path, e);
2277 if (fstat64(fd, &stb) < 0) {
2279 printf("%d/%d: read - fstat64 %s failed %d\n",
2280 procid, opno, f.path, errno);
2285 if (stb.st_size == 0) {
2287 printf("%d/%d: read - %s zero size\n", procid, opno,
2293 lr = ((__int64_t) random() << 32) + random();
2294 off = (off64_t) (lr % stb.st_size);
2295 lseek64(fd, off, SEEK_SET);
2296 len = (random() % (getpagesize() * 32)) + 1;
2298 e = read(fd, buf, len) < 0 ? errno : 0;
2301 printf("%d/%d: read %s [%lld,%ld] %d\n",
2302 procid, opno, f.path, (long long)off, (long int)len, e);
2307 void readlink_f(int opno, long r)
2315 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
2317 printf("%d/%d: readlink - no filename\n", procid, opno);
2321 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
2324 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
2328 void rename_f(int opno, long r)
2343 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
2345 printf("%d/%d: rename - no filename\n", procid, opno);
2349 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
2354 init_pathname(&newf);
2355 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
2359 fent_to_name(&f, &flist[FT_DIR], dfep);
2360 printf("%d/%d: rename - no filename from %s\n",
2361 procid, opno, f.path);
2363 free_pathname(&newf);
2367 e = rename_path(&f, &newf) < 0 ? errno : 0;
2370 if (flp - flist == FT_DIR) {
2372 fix_parent(oldid, id);
2374 del_from_flist(flp - flist, fep - flp->fents);
2375 add_to_flist(flp - flist, id, parid);
2378 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
2380 free_pathname(&newf);
2385 void resvsp_f(int opno, long r)
2390 struct xfs_flock64 fl;
2397 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2399 printf("%d/%d: resvsp - no filename\n", procid, opno);
2403 fd = open_path(&f, O_RDWR);
2404 e = fd < 0 ? errno : 0;
2408 printf("%d/%d: resvsp - open %s failed %d\n",
2409 procid, opno, f.path, e);
2413 if (fstat64(fd, &stb) < 0) {
2415 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
2416 procid, opno, f.path, errno);
2421 lr = ((__s64) random() << 32) + random();
2422 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2424 memset(&fl, 0, sizeof(fl));
2425 fl.l_whence = SEEK_SET;
2427 fl.l_len = (__s64) (random() % (1024 * 1024));
2428 e = ioctl(fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
2430 printf("%d/%d: ioctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
2431 procid, opno, f.path, (long long)off,
2432 (long long)fl.l_len, e);
2438 void rmdir_f(int opno, long r)
2446 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
2448 printf("%d/%d: rmdir - no directory\n", procid, opno);
2452 e = rmdir_path(&f) < 0 ? errno : 0;
2455 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
2457 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
2461 void stat_f(int opno, long r)
2469 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
2471 printf("%d/%d: stat - no entries\n", procid, opno);
2475 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
2478 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
2482 void symlink_f(int opno, long r)
2495 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2500 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
2504 fent_to_name(&f, &flist[FT_DIR], fep);
2505 printf("%d/%d: symlink - no filename from %s\n",
2506 procid, opno, f.path);
2511 len = (int)(random() % PATH_MAX);
2512 val = malloc(len + 1);
2514 memset(val, 'x', len);
2516 for (i = 10; i < len - 1; i += 10)
2518 e = symlink_path(val, &f) < 0 ? errno : 0;
2521 add_to_flist(FT_SYM, id, parid);
2524 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
2529 void sync_f(int opno, long r)
2533 printf("%d/%d: sync\n", procid, opno);
2536 void truncate_f(int opno, long r)
2546 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2548 printf("%d/%d: truncate - no filename\n", procid, opno);
2552 e = stat64_path(&f, &stb) < 0 ? errno : 0;
2556 printf("%d/%d: truncate - stat64 %s failed %d\n",
2557 procid, opno, f.path, e);
2561 lr = ((__int64_t) random() << 32) + random();
2562 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2564 e = truncate64_path(&f, off) < 0 ? errno : 0;
2567 printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
2572 void unlink_f(int opno, long r)
2581 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
2583 printf("%d/%d: unlink - no file\n", procid, opno);
2587 e = unlink_path(&f) < 0 ? errno : 0;
2590 del_from_flist(flp - flist, fep - flp->fents);
2592 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
2597 void unresvsp_f(int opno, long r)
2602 struct xfs_flock64 fl;
2609 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2611 printf("%d/%d: unresvsp - no filename\n", procid, opno);
2615 fd = open_path(&f, O_RDWR);
2616 e = fd < 0 ? errno : 0;
2620 printf("%d/%d: unresvsp - open %s failed %d\n",
2621 procid, opno, f.path, e);
2625 if (fstat64(fd, &stb) < 0) {
2627 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
2628 procid, opno, f.path, errno);
2633 lr = ((__s64) random() << 32) + random();
2634 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2636 memset(&fl, 0, sizeof(fl));
2637 fl.l_whence = SEEK_SET;
2639 fl.l_len = (__s64) (random() % (1 << 20));
2640 e = ioctl(fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
2642 printf("%d/%d: ioctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
2643 procid, opno, f.path, (long long)off,
2644 (long long)fl.l_len, e);
2650 void write_f(int opno, long r)
2663 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
2665 printf("%d/%d: write - no filename\n", procid, opno);
2669 fd = open_path(&f, O_WRONLY);
2670 e = fd < 0 ? errno : 0;
2674 printf("%d/%d: write - open %s failed %d\n",
2675 procid, opno, f.path, e);
2679 if (fstat64(fd, &stb) < 0) {
2681 printf("%d/%d: write - fstat64 %s failed %d\n",
2682 procid, opno, f.path, errno);
2687 lr = ((__int64_t) random() << 32) + random();
2688 off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2690 lseek64(fd, off, SEEK_SET);
2691 len = (random() % (getpagesize() * 32)) + 1;
2693 memset(buf, nameseq & 0xff, len);
2694 e = write(fd, buf, len) < 0 ? errno : 0;
2697 printf("%d/%d: write %s [%lld,%ld] %d\n",
2698 procid, opno, f.path, (long long)off, (long int)len, e);