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)
606 if (len && *str == '/' && name->len == 0) {
607 fprintf(stderr, "fsstress: append_pathname failure\n");
613 path = realloc(name->path, name->len + 1 + len);
615 fprintf(stderr, "fsstress: append_pathname realloc failed\n");
620 strcpy(&name->path[name->len], str);
626 attr_list_path(pathname_t * name, char *buffer, const int buffersize, int flags,
627 attrlist_cursor_t * cursor)
629 char buf[MAXNAMELEN];
633 rval = attr_list(name->path, buffer, buffersize, flags, cursor);
634 if (rval >= 0 || errno != ENAMETOOLONG)
636 separate_pathname(name, buf, &newname);
637 if (chdir(buf) == 0) {
638 rval = attr_list_path(&newname, buffer, buffersize, flags,
642 free_pathname(&newname);
646 int attr_remove_path(pathname_t * name, const char *attrname, int flags)
648 char buf[MAXNAMELEN];
652 rval = attr_remove(name->path, attrname, flags);
653 if (rval >= 0 || errno != ENAMETOOLONG)
655 separate_pathname(name, buf, &newname);
656 if (chdir(buf) == 0) {
657 rval = attr_remove_path(&newname, attrname, flags);
660 free_pathname(&newname);
665 attr_set_path(pathname_t * name, const char *attrname, const char *attrvalue,
666 const int valuelength, int flags)
668 char buf[MAXNAMELEN];
672 rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
673 if (rval >= 0 || errno != ENAMETOOLONG)
675 separate_pathname(name, buf, &newname);
676 if (chdir(buf) == 0) {
677 rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
681 free_pathname(&newname);
689 struct stat64 statbuf;
691 if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
694 fprintf(stderr, "fsstress: check_cwd failure\n");
700 int creat_path(pathname_t * name, mode_t mode)
702 char buf[MAXNAMELEN];
706 rval = creat(name->path, mode);
707 if (rval >= 0 || errno != ENAMETOOLONG)
709 separate_pathname(name, buf, &newname);
710 if (chdir(buf) == 0) {
711 rval = creat_path(&newname, mode);
714 free_pathname(&newname);
718 void dcache_enter(int dirid, int slot)
720 dcache[dirid % NDCACHE] = slot;
723 void dcache_init(void)
727 for (i = 0; i < NDCACHE; i++)
731 fent_t *dcache_lookup(int dirid)
736 i = dcache[dirid % NDCACHE];
737 if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
742 void dcache_purge(int dirid)
746 dcp = &dcache[dirid % NDCACHE];
747 if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
751 void del_from_flist(int ft, int slot)
757 dcache_purge(ftp->fents[slot].id);
758 if (slot != ftp->nfiles - 1) {
760 dcache_purge(ftp->fents[ftp->nfiles - 1].id);
761 ftp->fents[slot] = ftp->fents[--ftp->nfiles];
766 fent_t *dirid_to_fent(int dirid)
772 if ((fep = dcache_lookup(dirid)))
774 flp = &flist[FT_DIR];
775 for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
776 if (fep->id == dirid) {
777 dcache_enter(dirid, fep - flp->fents);
786 struct stat64 statbuf;
792 sprintf(buf, "p%x", procid);
793 (void)mkdir(buf, 0777);
794 if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
798 top_ino = statbuf.st_ino;
799 homedir = getcwd(NULL, -1);
804 for (opno = 0; opno < operations; opno++) {
805 p = &ops[freq_table[random() % freq_table_size]];
806 if ((unsigned long)p->func < 4096)
809 p->func(opno, random());
811 * test for forced shutdown by stat'ing the test
812 * directory. If this stat returns EIO, assume
813 * the forced shutdown happened.
815 if (errtag != 0 && opno % 100 == 0) {
816 rval = stat64(".", &statbuf);
818 fprintf(stderr, "Detected EIO\n");
825 void fent_to_name(pathname_t * name, flist_t * flp, fent_t * fep)
827 char buf[MAXNAMELEN];
833 if (fep->parent != -1) {
834 pfep = dirid_to_fent(fep->parent);
835 fent_to_name(name, &flist[FT_DIR], pfep);
836 append_pathname(name, "/");
838 i = sprintf(buf, "%c%x", flp->tag, fep->id);
839 namerandpad(fep->id, buf, i);
840 append_pathname(name, buf);
843 void fix_parent(int oldid, int newid)
850 for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
851 for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
852 if (fep->parent == oldid)
858 void free_pathname(pathname_t * name)
867 int generate_fname(fent_t * fep, int ft, pathname_t * name, int *idp, int *v)
869 char buf[MAXNAMELEN];
876 len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
877 namerandpad(id, buf, len);
879 fent_to_name(name, &flist[FT_DIR], fep);
880 append_pathname(name, "/");
882 append_pathname(name, buf);
885 for (j = 0; !*v && j < ilistlen; j++) {
886 if (ilist[j] == id) {
895 get_fname(int which, long r, pathname_t * name, flist_t ** flpp, fent_t ** fepp,
905 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
906 if (which & (1 << i))
918 for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
919 if (which & (1 << i)) {
920 if (x < c + flp->nfiles) {
921 fep = &flp->fents[x - c];
923 fent_to_name(name, flp, fep);
929 for (j = 0; !*v && j < ilistlen; j++) {
930 if (ilist[j] == fep->id) {
941 fprintf(stderr, "fsstress: get_fname failure\n");
948 void init_pathname(pathname_t * name)
954 int lchown_path(pathname_t * name, uid_t owner, gid_t group)
956 char buf[MAXNAMELEN];
960 rval = lchown(name->path, owner, group);
961 if (rval >= 0 || errno != ENAMETOOLONG)
963 separate_pathname(name, buf, &newname);
964 if (chdir(buf) == 0) {
965 rval = lchown_path(&newname, owner, group);
968 free_pathname(&newname);
972 int link_path(pathname_t * name1, pathname_t * name2)
974 char buf1[MAXNAMELEN];
975 char buf2[MAXNAMELEN];
981 rval = link(name1->path, name2->path);
982 if (rval >= 0 || errno != ENAMETOOLONG)
984 separate_pathname(name1, buf1, &newname1);
985 separate_pathname(name2, buf2, &newname2);
986 if (strcmp(buf1, buf2) == 0) {
987 if (chdir(buf1) == 0) {
988 rval = link_path(&newname1, &newname2);
992 if (strcmp(buf1, "..") == 0)
994 else if (strcmp(buf2, "..") == 0)
996 else if (strlen(buf1) == 0)
998 else if (strlen(buf2) == 0)
1001 down1 = MAX(newname1.len, 3 + name2->len) <=
1002 MAX(3 + name1->len, newname2.len);
1004 free_pathname(&newname2);
1005 append_pathname(&newname2, "../");
1006 append_pathname(&newname2, name2->path);
1007 if (chdir(buf1) == 0) {
1008 rval = link_path(&newname1, &newname2);
1012 free_pathname(&newname1);
1013 append_pathname(&newname1, "../");
1014 append_pathname(&newname1, name1->path);
1015 if (chdir(buf2) == 0) {
1016 rval = link_path(&newname1, &newname2);
1021 free_pathname(&newname1);
1022 free_pathname(&newname2);
1026 int lstat64_path(pathname_t * name, struct stat64 *sbuf)
1028 char buf[MAXNAMELEN];
1032 rval = lstat64(name->path, sbuf);
1033 if (rval >= 0 || errno != ENAMETOOLONG)
1035 separate_pathname(name, buf, &newname);
1036 if (chdir(buf) == 0) {
1037 rval = lstat64_path(&newname, sbuf);
1040 free_pathname(&newname);
1044 void make_freq_table(void)
1050 for (p = ops, f = 0; p < ops_end; p++)
1052 freq_table = malloc(f * sizeof(*freq_table));
1053 freq_table_size = f;
1054 for (p = ops, i = 0; p < ops_end; p++) {
1055 for (f = 0; f < p->freq; f++, i++)
1056 freq_table[i] = p->op;
1060 int mkdir_path(pathname_t * name, mode_t mode)
1062 char buf[MAXNAMELEN];
1066 rval = mkdir(name->path, mode);
1067 if (rval >= 0 || errno != ENAMETOOLONG)
1069 separate_pathname(name, buf, &newname);
1070 if (chdir(buf) == 0) {
1071 rval = mkdir_path(&newname, mode);
1074 free_pathname(&newname);
1078 int mknod_path(pathname_t * name, mode_t mode, dev_t dev)
1080 char buf[MAXNAMELEN];
1084 rval = mknod(name->path, mode, dev);
1085 if (rval >= 0 || errno != ENAMETOOLONG)
1087 separate_pathname(name, buf, &newname);
1088 if (chdir(buf) == 0) {
1089 rval = mknod_path(&newname, mode, dev);
1092 free_pathname(&newname);
1096 void namerandpad(int id, char *buf, int i)
1099 static int buckets[] = { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 };
1105 bucket = (id ^ namerand) % (sizeof(buckets) / sizeof(buckets[0]));
1106 padmod = buckets[bucket] + 1 - i;
1109 padlen = (id ^ namerand) % padmod;
1111 memset(&buf[i], 'X', padlen);
1112 buf[i + padlen] = '\0';
1116 int open_path(pathname_t * name, int oflag)
1118 char buf[MAXNAMELEN];
1122 rval = open(name->path, oflag);
1123 if (rval >= 0 || errno != ENAMETOOLONG)
1125 separate_pathname(name, buf, &newname);
1126 if (chdir(buf) == 0) {
1127 rval = open_path(&newname, oflag);
1130 free_pathname(&newname);
1134 DIR *opendir_path(pathname_t * name)
1136 char buf[MAXNAMELEN];
1140 rval = opendir(name->path);
1141 if (rval || errno != ENAMETOOLONG)
1143 separate_pathname(name, buf, &newname);
1144 if (chdir(buf) == 0) {
1145 rval = opendir_path(&newname);
1148 free_pathname(&newname);
1152 void process_freq(char *arg)
1157 s = strchr(arg, '=');
1159 fprintf(stderr, "bad argument '%s'\n", arg);
1163 for (p = ops; p < ops_end; p++) {
1164 if (strcmp(arg, p->name) == 0) {
1169 fprintf(stderr, "can't find op type %s for -f\n", arg);
1173 int readlink_path(pathname_t * name, char *lbuf, size_t lbufsiz)
1175 char buf[MAXNAMELEN];
1179 rval = readlink(name->path, lbuf, lbufsiz);
1180 if (rval >= 0 || errno != ENAMETOOLONG)
1182 separate_pathname(name, buf, &newname);
1183 if (chdir(buf) == 0) {
1184 rval = readlink_path(&newname, lbuf, lbufsiz);
1187 free_pathname(&newname);
1191 int rename_path(pathname_t * name1, pathname_t * name2)
1193 char buf1[MAXNAMELEN];
1194 char buf2[MAXNAMELEN];
1196 pathname_t newname1;
1197 pathname_t newname2;
1200 rval = rename(name1->path, name2->path);
1201 if (rval >= 0 || errno != ENAMETOOLONG)
1203 separate_pathname(name1, buf1, &newname1);
1204 separate_pathname(name2, buf2, &newname2);
1205 if (strcmp(buf1, buf2) == 0) {
1206 if (chdir(buf1) == 0) {
1207 rval = rename_path(&newname1, &newname2);
1211 if (strcmp(buf1, "..") == 0)
1213 else if (strcmp(buf2, "..") == 0)
1215 else if (strlen(buf1) == 0)
1217 else if (strlen(buf2) == 0)
1220 down1 = MAX(newname1.len, 3 + name2->len) <=
1221 MAX(3 + name1->len, newname2.len);
1223 free_pathname(&newname2);
1224 append_pathname(&newname2, "../");
1225 append_pathname(&newname2, name2->path);
1226 if (chdir(buf1) == 0) {
1227 rval = rename_path(&newname1, &newname2);
1231 free_pathname(&newname1);
1232 append_pathname(&newname1, "../");
1233 append_pathname(&newname1, name1->path);
1234 if (chdir(buf2) == 0) {
1235 rval = rename_path(&newname1, &newname2);
1240 free_pathname(&newname1);
1241 free_pathname(&newname2);
1245 int rmdir_path(pathname_t * name)
1247 char buf[MAXNAMELEN];
1251 rval = rmdir(name->path);
1252 if (rval >= 0 || errno != ENAMETOOLONG)
1254 separate_pathname(name, buf, &newname);
1255 if (chdir(buf) == 0) {
1256 rval = rmdir_path(&newname);
1259 free_pathname(&newname);
1263 void separate_pathname(pathname_t * name, char *buf, pathname_t * newname)
1267 init_pathname(newname);
1268 slash = strchr(name->path, '/');
1269 if (slash == NULL) {
1274 strcpy(buf, name->path);
1276 append_pathname(newname, slash + 1);
1281 void show_ops(int flag, char *lead_str)
1286 /* print in list form */
1289 for (p = ops; p < ops_end; p++) {
1290 if (lead_str != NULL
1291 && x + strlen(p->name) >= WIDTH - 5)
1292 x = printf("%s%s", (p == ops) ? "" : "\n",
1294 x += printf("%s ", p->name);
1299 for (f = 0, p = ops; p < ops_end; p++)
1305 for (p = ops; p < ops_end; p++) {
1306 if (flag != 0 || p->freq > 0) {
1307 if (lead_str != NULL)
1308 printf("%s", lead_str);
1309 printf("%20s %d/%d %s\n",
1310 p->name, p->freq, f,
1311 (p->iswrite == 0) ? " " : "write op");
1317 int stat64_path(pathname_t * name, struct stat64 *sbuf)
1319 char buf[MAXNAMELEN];
1323 rval = stat64(name->path, sbuf);
1324 if (rval >= 0 || errno != ENAMETOOLONG)
1326 separate_pathname(name, buf, &newname);
1327 if (chdir(buf) == 0) {
1328 rval = stat64_path(&newname, sbuf);
1331 free_pathname(&newname);
1335 int symlink_path(const char *name1, pathname_t * name)
1337 char buf[MAXNAMELEN];
1341 if (!strcmp(name1, name->path)) {
1342 printf("yikes! %s %s\n", name1, name->path);
1346 rval = symlink(name1, name->path);
1347 if (rval >= 0 || errno != ENAMETOOLONG)
1349 separate_pathname(name, buf, &newname);
1350 if (chdir(buf) == 0) {
1351 rval = symlink_path(name1, &newname);
1354 free_pathname(&newname);
1358 int truncate64_path(pathname_t * name, off64_t length)
1360 char buf[MAXNAMELEN];
1364 rval = truncate64(name->path, length);
1365 if (rval >= 0 || errno != ENAMETOOLONG)
1367 separate_pathname(name, buf, &newname);
1368 if (chdir(buf) == 0) {
1369 rval = truncate64_path(&newname, length);
1372 free_pathname(&newname);
1376 int unlink_path(pathname_t * name)
1378 char buf[MAXNAMELEN];
1382 rval = unlink(name->path);
1383 if (rval >= 0 || errno != ENAMETOOLONG)
1385 separate_pathname(name, buf, &newname);
1386 if (chdir(buf) == 0) {
1387 rval = unlink_path(&newname);
1390 free_pathname(&newname);
1396 printf("Usage: %s -H or\n", myprog);
1398 (" %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
1400 printf(" [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
1403 (" -c specifies not to remove files(cleanup) after execution\n");
1405 (" -d dir specifies the base directory for operations\n");
1406 printf(" -e errtg specifies error injection stuff\n");
1408 (" -f op_name=freq changes the frequency of option name to freq\n");
1409 printf(" the valid operation names are:\n");
1412 (" -l loops specifies the no. of times the testrun should loop.\n");
1413 printf(" *use 0 for infinite (default 1)\n");
1415 (" -n nops specifies the no. of operations per process (default 1)\n");
1417 (" -p nproc specifies the no. of processes (default 1)\n");
1418 printf(" -r specifies random name padding\n");
1420 (" -s seed specifies the seed for the random generator (default random)\n");
1421 printf(" -v specifies verbose mode\n");
1423 (" -w zeros frequencies of non-write operations\n");
1424 printf(" -z zeros frequencies of all operations\n");
1426 (" -S prints the table of operations (omitting zero frequency)\n");
1427 printf(" -H prints usage and exits\n");
1429 (" -X don't do anything XFS specific (default with -DNO_XFS)\n");
1432 void write_freq(void)
1436 for (p = ops; p < ops_end; p++) {
1442 void zero_freq(void)
1446 for (p = ops; p < ops_end; p++)
1452 void allocsp_f(int opno, long r)
1457 struct xfs_flock64 fl;
1464 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1466 printf("%d/%d: allocsp - no filename\n", procid, opno);
1470 fd = open_path(&f, O_RDWR);
1471 e = fd < 0 ? errno : 0;
1475 printf("%d/%d: allocsp - open %s failed %d\n",
1476 procid, opno, f.path, e);
1480 if (fstat64(fd, &stb) < 0) {
1482 printf("%d/%d: allocsp - fstat64 %s failed %d\n",
1483 procid, opno, f.path, errno);
1488 lr = ((__s64) random() << 32) + random();
1489 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
1491 memset(&fl, 0, sizeof(fl));
1492 fl.l_whence = SEEK_SET;
1495 e = ioctl(fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
1497 printf("%d/%d: ioctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
1498 procid, opno, f.path, (long long)off, e);
1503 void attr_remove_f(int opno, long r)
1505 attrlist_ent_t *aep;
1509 attrlist_cursor_t cursor;
1518 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1519 append_pathname(&f, ".");
1521 memset(&cursor, 0x00, sizeof(cursor));
1523 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1528 alist = (attrlist_t *) buf;
1529 total += alist->al_count;
1530 } while (alist->al_more);
1533 printf("%d/%d: attr_remove - no attrs for %s\n",
1534 procid, opno, f.path);
1538 which = (int)(random() % total);
1539 memset(&cursor, 0x00, sizeof(cursor));
1543 e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW,
1548 alist = (attrlist_t *) buf;
1549 if (which < ent + alist->al_count) {
1550 aep = (attrlist_ent_t *)
1551 & buf[alist->al_offset[which - ent]];
1552 aname = aep->a_name;
1555 ent += alist->al_count;
1556 } while (alist->al_more);
1557 if (aname == NULL) {
1559 printf("%d/%d: attr_remove - name %d not found at %s\n",
1560 procid, opno, which, f.path);
1564 e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
1567 printf("%d/%d: attr_remove %s %s %d\n",
1568 procid, opno, f.path, aname, e);
1572 void attr_set_f(int opno, long r)
1579 static int lengths[] = { 10, 100, 1000, 10000 };
1584 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1585 append_pathname(&f, ".");
1586 sprintf(aname, "a%x", nameseq++);
1587 li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
1588 len = (int)(random() % lengths[li]);
1592 memset(aval, nameseq & 0xff, len);
1593 e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
1598 printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
1603 void bulkstat_f(int opno, long r)
1611 xfs_fsop_bulkreq_t bsr;
1614 nent = (r % 999) + 2;
1615 t = malloc(nent * sizeof(*t));
1616 fd = open(".", O_RDONLY);
1619 memset(&bsr, 0, sizeof(bsr));
1623 bsr.ocount = &count;
1625 while (ioctl(fd, XFS_IOC_FSBULKSTAT, &bsr) == 0 && count > 0)
1629 printf("%d/%d: bulkstat nent %d total %lld\n",
1630 procid, opno, (int)nent, (long long)total);
1634 void bulkstat1_f(int opno, long r)
1644 xfs_fsop_bulkreq_t bsr;
1646 good = random() & 1;
1648 /* use an inode we know exists */
1650 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1651 append_pathname(&f, ".");
1652 ino = stat64_path(&f, &s) < 0 ? (ino64_t) r : s.st_ino;
1657 * pick a random inode
1659 * note this can generate kernel warning messages
1660 * since bulkstat_one will read the disk block that
1661 * would contain a given inode even if that disk
1662 * block doesn't contain inodes.
1664 * this is detected later, but not until after the
1665 * warning is displayed.
1667 * "XFS: device 0x825- bad inode magic/vsn daddr 0x0 #0"
1673 fd = open(".", O_RDONLY);
1675 memset(&bsr, 0, sizeof(bsr));
1681 e = ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
1683 printf("%d/%d: bulkstat1 %s ino %lld %d\n",
1684 procid, opno, good ? "real" : "random",
1691 void chown_f(int opno, long r)
1700 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
1701 append_pathname(&f, ".");
1702 u = (uid_t) random();
1703 nbits = (int)(random() % 32);
1704 u &= (1 << nbits) - 1;
1705 e = lchown_path(&f, u, -1) < 0 ? errno : 0;
1708 printf("%d/%d: chown %s %d %d\n", procid, opno, f.path, u, e);
1712 void creat_f(int opno, long r)
1727 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
1732 type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
1734 extsize = (random() % 10) + 1;
1737 e = generate_fname(fep, type, &f, &id, &v);
1741 fent_to_name(&f, &flist[FT_DIR], fep);
1742 printf("%d/%d: creat - no filename from %s\n",
1743 procid, opno, f.path);
1748 fd = creat_path(&f, 0666);
1749 e = fd < 0 ? errno : 0;
1756 memset(&a, 0, sizeof(a));
1757 if (extsize && ioctl(fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
1758 a.fsx_xflags |= XFS_XFLAG_REALTIME;
1760 geom.rtextsize * geom.blocksize * extsize;
1761 if (ioctl(fd, XFS_IOC_FSSETXATTR, &a) < 0)
1763 esz = a.fsx_extsize;
1767 add_to_flist(type, id, parid);
1771 printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
1776 int setdirect(int fd)
1778 static int no_direct;
1784 flags = fcntl(fd, F_GETFL, 0);
1788 if (fcntl(fd, F_SETFL, flags | O_DIRECT) < 0) {
1793 printf("cannot set O_DIRECT: %s\n", strerror(errno));
1800 void dread_f(int opno, long r)
1804 struct dioattr diob;
1815 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1817 printf("%d/%d: dread - no filename\n", procid, opno);
1821 fd = open_path(&f, O_RDONLY);
1823 e = fd < 0 ? errno : 0;
1827 printf("%d/%d: dread - open %s failed %d\n",
1828 procid, opno, f.path, e);
1833 if (!setdirect(fd)) {
1839 if (fstat64(fd, &stb) < 0) {
1841 printf("%d/%d: dread - fstat64 %s failed %d\n",
1842 procid, opno, f.path, errno);
1847 if (stb.st_size == 0) {
1849 printf("%d/%d: dread - %s zero size\n", procid, opno,
1856 memset(&diob, 0, sizeof(diob));
1858 diob.d_miniosz = stb.st_blksize;
1859 diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */
1860 diob.d_mem = stb.st_blksize;
1863 else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1866 ("%d/%d: dread - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1867 procid, opno, f.path, errno);
1873 align = (__int64_t) diob.d_miniosz;
1874 lr = ((__int64_t) random() << 32) + random();
1875 off = (off64_t) (lr % stb.st_size);
1876 off -= (off % align);
1877 lseek64(fd, off, SEEK_SET);
1878 len = (random() % (getpagesize() * 32)) + 1;
1879 len -= (len % align);
1882 else if (len > diob.d_maxiosz)
1883 len = diob.d_maxiosz;
1884 if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1885 fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1889 fprintf(stderr, "posix_memalign: buf is NULL\n");
1892 e = read(fd, buf, len) < 0 ? errno : 0;
1895 printf("%d/%d: dread %s [%lld,%ld] %d\n",
1896 procid, opno, f.path, (long long int)off, (long)len, e);
1901 void dwrite_f(int opno, long r)
1905 struct dioattr diob;
1916 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
1918 printf("%d/%d: dwrite - no filename\n", procid, opno);
1922 fd = open_path(&f, O_WRONLY);
1923 e = fd < 0 ? errno : 0;
1927 printf("%d/%d: dwrite - open %s failed %d\n",
1928 procid, opno, f.path, e);
1933 if (!setdirect(fd)) {
1938 if (fstat64(fd, &stb) < 0) {
1940 printf("%d/%d: dwrite - fstat64 %s failed %d\n",
1941 procid, opno, f.path, errno);
1946 memset(&diob, 0, sizeof(diob));
1948 diob.d_miniosz = stb.st_blksize;
1949 diob.d_maxiosz = stb.st_blksize * 256; /* good number ? */
1950 diob.d_mem = stb.st_blksize;
1953 else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
1956 ("%d/%d: dwrite - ioctl(fd, XFS_IOC_DIOINFO) %s failed %d\n",
1957 procid, opno, f.path, errno);
1963 align = (__int64_t) diob.d_miniosz;
1964 lr = ((__int64_t) random() << 32) + random();
1965 off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
1966 off -= (off % align);
1967 lseek64(fd, off, SEEK_SET);
1968 len = (random() % (getpagesize() * 32)) + 1;
1969 len -= (len % align);
1972 else if (len > diob.d_maxiosz)
1973 len = diob.d_maxiosz;
1974 if ((e = posix_memalign((void **)&buf, diob.d_mem, len)) != 0) {
1975 fprintf(stderr, "posix_memalign: %s\n", strerror(e));
1979 fprintf(stderr, "posix_memalign: buf is NULL\n");
1983 lseek64(fd, off, SEEK_SET);
1984 memset(buf, nameseq & 0xff, len);
1985 e = write(fd, buf, len) < 0 ? errno : 0;
1988 printf("%d/%d: dwrite %s [%lld,%ld] %d\n",
1989 procid, opno, f.path, (long long)off, (long int)len, e);
1994 void fdatasync_f(int opno, long r)
2002 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2004 printf("%d/%d: fdatasync - no filename\n",
2009 fd = open_path(&f, O_WRONLY);
2010 e = fd < 0 ? errno : 0;
2014 printf("%d/%d: fdatasync - open %s failed %d\n",
2015 procid, opno, f.path, e);
2019 e = fdatasync(fd) < 0 ? errno : 0;
2021 printf("%d/%d: fdatasync %s %d\n", procid, opno, f.path, e);
2027 void freesp_f(int opno, long r)
2032 struct xfs_flock64 fl;
2039 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2041 printf("%d/%d: freesp - no filename\n", procid, opno);
2045 fd = open_path(&f, O_RDWR);
2046 e = fd < 0 ? errno : 0;
2050 printf("%d/%d: freesp - open %s failed %d\n",
2051 procid, opno, f.path, e);
2055 if (fstat64(fd, &stb) < 0) {
2057 printf("%d/%d: freesp - fstat64 %s failed %d\n",
2058 procid, opno, f.path, errno);
2063 lr = ((__s64) random() << 32) + random();
2064 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2066 memset(&fl, 0, sizeof(fl));
2067 fl.l_whence = SEEK_SET;
2070 e = ioctl(fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
2072 printf("%d/%d: ioctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
2073 procid, opno, f.path, (long long)off, e);
2080 void fsync_f(int opno, long r)
2088 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2090 printf("%d/%d: fsync - no filename\n", procid, opno);
2094 fd = open_path(&f, O_WRONLY);
2095 e = fd < 0 ? errno : 0;
2099 printf("%d/%d: fsync - open %s failed %d\n",
2100 procid, opno, f.path, e);
2104 e = fsync(fd) < 0 ? errno : 0;
2106 printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e);
2111 void getdents_f(int opno, long r)
2118 if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
2119 append_pathname(&f, ".");
2120 dir = opendir_path(&f);
2124 printf("%d/%d: getdents - can't open %s\n",
2125 procid, opno, f.path);
2129 while (readdir64(dir) != NULL)
2132 printf("%d/%d: getdents %s 0\n", procid, opno, f.path);
2137 void link_f(int opno, long r)
2150 if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
2152 printf("%d/%d: link - no file\n", procid, opno);
2156 if (!get_fname(FT_DIRm, random(), NULL, NULL, &fep, &v))
2162 e = generate_fname(fep, flp - flist, &l, &id, &v1);
2166 fent_to_name(&l, &flist[FT_DIR], fep);
2167 printf("%d/%d: link - no filename from %s\n",
2168 procid, opno, l.path);
2174 e = link_path(&f, &l) < 0 ? errno : 0;
2177 add_to_flist(flp - flist, id, parid);
2179 printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
2185 void mkdir_f(int opno, long r)
2195 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2200 e = generate_fname(fep, FT_DIR, &f, &id, &v1);
2204 fent_to_name(&f, &flist[FT_DIR], fep);
2205 printf("%d/%d: mkdir - no filename from %s\n",
2206 procid, opno, f.path);
2211 e = mkdir_path(&f, 0777) < 0 ? errno : 0;
2214 add_to_flist(FT_DIR, id, parid);
2216 printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
2220 void mknod_f(int opno, long r)
2230 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2235 e = generate_fname(fep, FT_DEV, &f, &id, &v1);
2239 fent_to_name(&f, &flist[FT_DIR], fep);
2240 printf("%d/%d: mknod - no filename from %s\n",
2241 procid, opno, f.path);
2246 e = mknod_path(&f, S_IFCHR | 0444, 0) < 0 ? errno : 0;
2249 add_to_flist(FT_DEV, id, parid);
2251 printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
2255 void read_f(int opno, long r)
2268 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2270 printf("%d/%d: read - no filename\n", procid, opno);
2274 fd = open_path(&f, O_RDONLY);
2275 e = fd < 0 ? errno : 0;
2279 printf("%d/%d: read - open %s failed %d\n",
2280 procid, opno, f.path, e);
2284 if (fstat64(fd, &stb) < 0) {
2286 printf("%d/%d: read - fstat64 %s failed %d\n",
2287 procid, opno, f.path, errno);
2292 if (stb.st_size == 0) {
2294 printf("%d/%d: read - %s zero size\n", procid, opno,
2300 lr = ((__int64_t) random() << 32) + random();
2301 off = (off64_t) (lr % stb.st_size);
2302 lseek64(fd, off, SEEK_SET);
2303 len = (random() % (getpagesize() * 32)) + 1;
2305 e = read(fd, buf, len) < 0 ? errno : 0;
2308 printf("%d/%d: read %s [%lld,%ld] %d\n",
2309 procid, opno, f.path, (long long)off, (long int)len, e);
2314 void readlink_f(int opno, long r)
2322 if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
2324 printf("%d/%d: readlink - no filename\n", procid, opno);
2328 e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
2331 printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
2335 void rename_f(int opno, long r)
2350 if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
2352 printf("%d/%d: rename - no filename\n", procid, opno);
2356 if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
2361 init_pathname(&newf);
2362 e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
2366 fent_to_name(&f, &flist[FT_DIR], dfep);
2367 printf("%d/%d: rename - no filename from %s\n",
2368 procid, opno, f.path);
2370 free_pathname(&newf);
2374 e = rename_path(&f, &newf) < 0 ? errno : 0;
2377 if (flp - flist == FT_DIR) {
2379 fix_parent(oldid, id);
2381 del_from_flist(flp - flist, fep - flp->fents);
2382 add_to_flist(flp - flist, id, parid);
2385 printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
2387 free_pathname(&newf);
2392 void resvsp_f(int opno, long r)
2397 struct xfs_flock64 fl;
2404 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2406 printf("%d/%d: resvsp - no filename\n", procid, opno);
2410 fd = open_path(&f, O_RDWR);
2411 e = fd < 0 ? errno : 0;
2415 printf("%d/%d: resvsp - open %s failed %d\n",
2416 procid, opno, f.path, e);
2420 if (fstat64(fd, &stb) < 0) {
2422 printf("%d/%d: resvsp - fstat64 %s failed %d\n",
2423 procid, opno, f.path, errno);
2428 lr = ((__s64) random() << 32) + random();
2429 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2431 memset(&fl, 0, sizeof(fl));
2432 fl.l_whence = SEEK_SET;
2434 fl.l_len = (__s64) (random() % (1024 * 1024));
2435 e = ioctl(fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
2437 printf("%d/%d: ioctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
2438 procid, opno, f.path, (long long)off,
2439 (long long)fl.l_len, e);
2445 void rmdir_f(int opno, long r)
2453 if (!get_fname(FT_DIRm, r, &f, NULL, &fep, &v)) {
2455 printf("%d/%d: rmdir - no directory\n", procid, opno);
2459 e = rmdir_path(&f) < 0 ? errno : 0;
2462 del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
2464 printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
2468 void stat_f(int opno, long r)
2476 if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v)) {
2478 printf("%d/%d: stat - no entries\n", procid, opno);
2482 e = lstat64_path(&f, &stb) < 0 ? errno : 0;
2485 printf("%d/%d: stat %s %d\n", procid, opno, f.path, e);
2489 void symlink_f(int opno, long r)
2502 if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
2507 e = generate_fname(fep, FT_SYM, &f, &id, &v1);
2511 fent_to_name(&f, &flist[FT_DIR], fep);
2512 printf("%d/%d: symlink - no filename from %s\n",
2513 procid, opno, f.path);
2518 len = (int)(random() % PATH_MAX);
2519 val = malloc(len + 1);
2521 memset(val, 'x', len);
2523 for (i = 10; i < len - 1; i += 10)
2525 e = symlink_path(val, &f) < 0 ? errno : 0;
2528 add_to_flist(FT_SYM, id, parid);
2531 printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
2536 void sync_f(int opno, long r)
2540 printf("%d/%d: sync\n", procid, opno);
2543 void truncate_f(int opno, long r)
2553 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2555 printf("%d/%d: truncate - no filename\n", procid, opno);
2559 e = stat64_path(&f, &stb) < 0 ? errno : 0;
2563 printf("%d/%d: truncate - stat64 %s failed %d\n",
2564 procid, opno, f.path, e);
2568 lr = ((__int64_t) random() << 32) + random();
2569 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2571 e = truncate64_path(&f, off) < 0 ? errno : 0;
2574 printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
2579 void unlink_f(int opno, long r)
2588 if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep, &v)) {
2590 printf("%d/%d: unlink - no file\n", procid, opno);
2594 e = unlink_path(&f) < 0 ? errno : 0;
2597 del_from_flist(flp - flist, fep - flp->fents);
2599 printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
2604 void unresvsp_f(int opno, long r)
2609 struct xfs_flock64 fl;
2616 if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
2618 printf("%d/%d: unresvsp - no filename\n", procid, opno);
2622 fd = open_path(&f, O_RDWR);
2623 e = fd < 0 ? errno : 0;
2627 printf("%d/%d: unresvsp - open %s failed %d\n",
2628 procid, opno, f.path, e);
2632 if (fstat64(fd, &stb) < 0) {
2634 printf("%d/%d: unresvsp - fstat64 %s failed %d\n",
2635 procid, opno, f.path, errno);
2640 lr = ((__s64) random() << 32) + random();
2641 off = lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE);
2643 memset(&fl, 0, sizeof(fl));
2644 fl.l_whence = SEEK_SET;
2646 fl.l_len = (__s64) (random() % (1 << 20));
2647 e = ioctl(fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
2649 printf("%d/%d: ioctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
2650 procid, opno, f.path, (long long)off,
2651 (long long)fl.l_len, e);
2657 void write_f(int opno, long r)
2670 if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
2672 printf("%d/%d: write - no filename\n", procid, opno);
2676 fd = open_path(&f, O_WRONLY);
2677 e = fd < 0 ? errno : 0;
2681 printf("%d/%d: write - open %s failed %d\n",
2682 procid, opno, f.path, e);
2686 if (fstat64(fd, &stb) < 0) {
2688 printf("%d/%d: write - fstat64 %s failed %d\n",
2689 procid, opno, f.path, errno);
2694 lr = ((__int64_t) random() << 32) + random();
2695 off = (off64_t) (lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
2697 lseek64(fd, off, SEEK_SET);
2698 len = (random() % (getpagesize() * 32)) + 1;
2700 memset(buf, nameseq & 0xff, len);
2701 e = write(fd, buf, len) < 0 ? errno : 0;
2704 printf("%d/%d: write %s [%lld,%ld] %d\n",
2705 procid, opno, f.path, (long long)off, (long int)len, e);