void del_from_flist(int, int);
int dirid_to_name(char *, int);
void doproc(void);
-void fent_to_name(pathname_t *, flist_t *, fent_t *);
+int fent_to_name(pathname_t *, flist_t *, fent_t *);
void fix_parent(int, int);
void free_pathname(pathname_t *);
int generate_fname(fent_t *, int, pathname_t *, int *, int *);
len = strlen(str);
#ifdef DEBUG
+ /* attempting to append to a dir a zero length path */
if (len && *str == '/' && name->len == 0) {
fprintf(stderr, "fsstress: append_pathname failure\n");
chdir(homedir);
*dcp = -1;
}
+/*
+ * Delete the item from the list by
+ * moving last entry over the deleted one;
+ * unless deleted entry is the last one.
+ * Input: which file list array and which slot in array
+ */
void
del_from_flist(int ft, int slot)
{
}
}
-void
+/*
+ * build up a pathname going thru the file entry and all
+ * its parent entries
+ * Return 0 on error, 1 on success;
+ */
+int
fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
{
char buf[MAXNAMELEN];
int i;
fent_t *pfep;
+ int e;
if (fep == NULL)
- return;
+ return 0;
+
+ /* build up parent directory name */
if (fep->parent != -1) {
pfep = dirid_to_fent(fep->parent);
- fent_to_name(name, &flist[FT_DIR], pfep);
+#ifdef DEBUG
+ if (pfep == NULL) {
+ fprintf(stderr, "%d: fent-id = %d: can't find parent id: %d\n",
+ procid, fep->id, fep->parent);
+ }
+#endif
+ if (pfep == NULL)
+ return 0;
+ e = fent_to_name(name, &flist[FT_DIR], pfep);
+ if (!e)
+ return 0;
append_pathname(name, "/");
}
+
i = sprintf(buf, "%c%x", flp->tag, fep->id);
namerandpad(fep->id, buf, i);
append_pathname(name, buf);
+ return 1;
}
void
}
}
+/*
+ * Generate a filename of type ft.
+ * If we have a fep which should be a directory then use it
+ * as the parent path for this new filename i.e. prepend with it.
+ */
int
generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
{
int id;
int j;
int len;
+ int e;
+ /* create name */
flp = &flist[ft];
len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
namerandpad(id, buf, len);
+
+ /* prepend fep parent dir-name to it */
if (fep) {
- fent_to_name(name, &flist[FT_DIR], fep);
+ e = fent_to_name(name, &flist[FT_DIR], fep);
+ if (!e)
+ return 0;
append_pathname(name, "/");
}
append_pathname(name, buf);
+
*idp = id;
*v = verbose;
for (j = 0; !*v && j < ilistlen; j++) {
return 1;
}
+/*
+ * Get file
+ * Input: "which" to choose the file-types eg. non-directory
+ * Input: "r" to choose which file
+ * Output: file-list, file-entry, name for the chosen file.
+ * Output: verbose if chosen file is on the ilist.
+ */
int
get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
int *v)
{
- int c;
+ int totalsum = 0; /* total number of matching files */
+ int partialsum = 0; /* partial sum of matching files */
fent_t *fep;
flist_t *flp;
int i;
int j;
int x;
+ int e = 1; /* success */
- for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
+ /*
+ * go thru flist and add up number of files for each
+ * category that matches with <which>.
+ */
+ for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
if (which & (1 << i))
- c += flp->nfiles;
+ totalsum += flp->nfiles;
}
- if (c == 0) {
+ if (totalsum == 0) {
if (flpp)
*flpp = NULL;
if (fepp)
*v = verbose;
return 0;
}
- x = (int)(r % c);
- for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
+
+ /*
+ * Now we have possible matches between 0..totalsum-1.
+ * And we use r to help us choose which one we want,
+ * which when bounded by totalsum becomes x.
+ */
+ x = (int)(r % totalsum);
+ for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
if (which & (1 << i)) {
- if (x < c + flp->nfiles) {
- fep = &flp->fents[x - c];
- if (name)
- fent_to_name(name, flp, fep);
+ if (x < partialsum + flp->nfiles) {
+
+ /* found the matching file entry */
+ fep = &flp->fents[x - partialsum];
+
+ /* fill-in what we were asked for */
+ if (name) {
+ e = fent_to_name(name, flp, fep);
+#ifdef DEBUG
+ if (!e) {
+ fprintf(stderr, "%d: failed to get path for entry:"
+ " id=%d,parent=%d\n",
+ procid, fep->id, fep->parent);
+ }
+#endif
+ }
if (flpp)
*flpp = flp;
if (fepp)
*fepp = fep;
+
+ /* turn on verbose if its an ilisted file */
*v = verbose;
for (j = 0; !*v && j < ilistlen; j++) {
if (ilist[j] == fep->id) {
break;
}
}
- return 1;
+ return e;
}
- c += flp->nfiles;
+ partialsum += flp->nfiles;
}
}
#ifdef DEBUG
fprintf(stderr, "fsstress: get_fname failure\n");
abort();
#endif
- return -1;
- /* NOTREACHED */
+ return 0;
}
void
printf(" -e errtg specifies error injection stuff\n");
printf(" -f op_name=freq changes the frequency of option name to freq\n");
printf(" the valid operation names are:\n");
+ printf(" -i filenum get verbose output for this nth file object\n");
show_ops(-1, " ");
printf(" -m modulo uid/gid modulo for chown/chgrp (default 32)\n");
printf(" -n nops specifies the no. of operations per process (default 1)\n");
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
+ (void)fent_to_name(&f, &flist[FT_DIR], fep);
printf("%d/%d: creat - no filename from %s\n",
procid, opno, f.path);
}
add_to_flist(type, id, parid);
close(fd);
}
- if (v)
+ if (v) {
printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
extsize ? a.fsx_extsize : 0, e, e1);
+ printf("%d/%d: creat add id=%d,parent=%d\n", procid, opno, id, parid);
+ }
free_pathname(&f);
}
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&l, &flist[FT_DIR], fep);
+ (void)fent_to_name(&l, &flist[FT_DIR], fep);
printf("%d/%d: link - no filename from %s\n",
procid, opno, l.path);
}
check_cwd();
if (e == 0)
add_to_flist(flp - flist, id, parid);
- if (v)
+ if (v) {
printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
e);
+ printf("%d/%d: link add id=%d,parent=%d\n", procid, opno, id, parid);
+ }
free_pathname(&l);
free_pathname(&f);
}
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
+ (void)fent_to_name(&f, &flist[FT_DIR], fep);
printf("%d/%d: mkdir - no filename from %s\n",
procid, opno, f.path);
}
check_cwd();
if (e == 0)
add_to_flist(FT_DIR, id, parid);
- if (v)
+ if (v) {
printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
+ printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
+ }
free_pathname(&f);
}
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
+ (void)fent_to_name(&f, &flist[FT_DIR], fep);
printf("%d/%d: mknod - no filename from %s\n",
procid, opno, f.path);
}
check_cwd();
if (e == 0)
add_to_flist(FT_DEV, id, parid);
- if (v)
+ if (v) {
printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
+ printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
+ }
free_pathname(&f);
}
int v;
int v1;
+ /* get an existing path for the source of the rename */
init_pathname(&f);
if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
if (v1)
free_pathname(&f);
return;
}
+
+ /* get an existing directory for the destination parent directory name */
if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
parid = -1;
else
parid = dfep->id;
v |= v1;
+
+ /* generate a new path using an existing parent directory in name */
init_pathname(&newf);
e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&f, &flist[FT_DIR], dfep);
+ (void)fent_to_name(&f, &flist[FT_DIR], dfep);
printf("%d/%d: rename - no filename from %s\n",
procid, opno, f.path);
}
del_from_flist(flp - flist, fep - flp->fents);
add_to_flist(flp - flist, id, parid);
}
- if (v)
+ if (v) {
printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
newf.path, e);
+ if (e == 0) {
+ printf("%d/%d: rename del entry: id=%d,parent=%d\n",
+ procid, opno, fep->id, fep->parent);
+ printf("%d/%d: rename add entry: id=%d,parent=%d\n",
+ procid, opno, id, parid);
+ }
+ }
free_pathname(&newf);
free_pathname(&f);
}
check_cwd();
if (e == 0)
del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
- if (v)
+ if (v) {
printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
+ if (e == 0)
+ printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
+ procid, opno, fep->id, fep->parent);
+ }
free_pathname(&f);
}
v |= v1;
if (!e) {
if (v) {
- fent_to_name(&f, &flist[FT_DIR], fep);
+ (void)fent_to_name(&f, &flist[FT_DIR], fep);
printf("%d/%d: symlink - no filename from %s\n",
procid, opno, f.path);
}
if (e == 0)
add_to_flist(FT_SYM, id, parid);
free(val);
- if (v)
+ if (v) {
printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
+ printf("%d/%d: symlink add id=%d,parent=%d\n", procid, opno, id, parid);
+ }
free_pathname(&f);
}
check_cwd();
if (e == 0)
del_from_flist(flp - flist, fep - flp->fents);
- if (v)
+ if (v) {
printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
+ if (e == 0)
+ printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
+ procid, opno, fep->id, fep->parent);
+ }
free_pathname(&f);
}