/*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like. Any license provided herein, whether implied or
- * otherwise, applies only to this software file. Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "global.h"
#ifdef HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#endif
+#ifdef HAVE_ATTR_ATTRIBUTES_H
+#include <attr/attributes.h>
+#endif
+
+#ifndef HAVE_ATTR_LIST
+#define attr_list(path, buf, size, flags, cursor) (errno = -ENOSYS, -1)
+#endif
#include <math.h>
#define XFS_ERRTAG_MAX 17
-#define XFS_IDMODULO_MAX 32
+#define XFS_IDMODULO_MAX 31 /* user/group IDs (1 << x) */
+#define XFS_PROJIDMODULO_MAX 16 /* project IDs (1 << x) */
+
+#define FILELEN_MAX (32*4096)
typedef enum {
OP_ALLOCSP,
OP_RENAME,
OP_RESVSP,
OP_RMDIR,
+ OP_SETXATTR,
OP_STAT,
OP_SYMLINK,
OP_SYNC,
void rename_f(int, long);
void resvsp_f(int, long);
void rmdir_f(int, long);
+void setxattr_f(int, long);
void stat_f(int, long);
void symlink_f(int, long);
void sync_f(int, long);
{ OP_RENAME, "rename", rename_f, 2, 1 },
{ OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
{ OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
+ { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
{ OP_STAT, "stat", stat_f, 1, 0 },
{ OP_SYMLINK, "symlink", symlink_f, 2, 1 },
{ OP_SYNC, "sync", sync_f, 1, 0 },
void add_to_flist(int, int, int);
void append_pathname(pathname_t *, char *);
-#ifdef HAVE_LIBATTR
-int attr_list_path(pathname_t *, char *, const int, int);
-#else
int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
-#endif
int attr_remove_path(pathname_t *, const char *, int);
int attr_set_path(pathname_t *, const char *, const char *, const int, int);
void check_cwd(void);
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 *);
exit(1);
}
}
-
+
if (!dirname) {
/* no directory specified */
if (!nousage) usage();
exit(1);
}
-
+
(void)mkdir(dirname, 0777);
if (chdir(dirname) < 0) {
perror(dirname);
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);
attr_list_path(pathname_t *name,
char *buffer,
const int buffersize,
- int flags
-#ifndef HAVE_LIBATTR
- , attrlist_cursor_t *cursor
-#endif
- )
+ int flags,
+ attrlist_cursor_t *cursor)
{
char buf[MAXNAMELEN];
pathname_t newname;
int rval;
-#ifdef ATTR_DONTFOLLOW
if (flags != ATTR_DONTFOLLOW) {
errno = EINVAL;
return -1;
}
-#endif
-#ifdef HAVE_LIBATTR
- rval = llistxattr(name->path, buffer, buffersize);
-#else
rval = attr_list(name->path, buffer, buffersize, flags, cursor);
-#endif
if (rval >= 0 || errno != ENAMETOOLONG)
return rval;
separate_pathname(name, buf, &newname);
if (chdir(buf) == 0) {
-#ifdef HAVE_LIBATTR
- rval = attr_list_path(&newname, buffer, buffersize, flags);
-#else
rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
-#endif
chdir("..");
}
free_pathname(&newname);
*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");
attrlist_t *alist;
char *aname;
char buf[4096];
-#ifndef HAVE_LIBATTR
attrlist_cursor_t cursor;
-#endif
int e;
int ent;
pathname_t f;
if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
append_pathname(&f, ".");
total = 0;
-#ifndef HAVE_LIBATTR
bzero(&cursor, sizeof(cursor));
-#endif
do {
bzero(buf, sizeof(buf));
-#ifdef HAVE_LIBATTR
- e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW);
-#else
e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
-#endif
check_cwd();
if (e)
break;
return;
}
which = (int)(random() % total);
-#ifndef HAVE_LIBATTR
bzero(&cursor, sizeof(cursor));
-#endif
ent = 0;
aname = NULL;
do {
bzero(buf, sizeof(buf));
-#ifdef HAVE_LIBATTR
- e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW);
-#else
e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
-#endif
check_cwd();
if (e)
break;
if (aname == NULL) {
if (v)
printf(
- "%d/%d: attr_remove - name %d not found at %s\n",
+ "%d/%d: attr_remove - name %d not found at %s\n",
procid, opno, which, f.path);
free_pathname(&f);
return;
t = malloc(nent * sizeof(*t));
fd = open(".", O_RDONLY);
total = 0;
-
+
bsr.lastip=&last;
bsr.icount=nent;
bsr.ubuffer=t;
free_pathname(&f);
}
+void
+setxattr_f(int opno, long r)
+{
+#ifdef XFS_XFLAG_EXTSIZE
+ struct fsxattr fsx;
+ int fd;
+ int e;
+ pathname_t f;
+ int nbits;
+ uint p;
+ int v;
+
+ init_pathname(&f);
+ if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+ append_pathname(&f, ".");
+ fd = open_path(&f, O_RDWR);
+ e = fd < 0 ? errno : 0;
+ check_cwd();
+
+ /* project ID */
+ p = (uint)random();
+ e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
+ nbits = (int)(random() % e);
+ p &= (1 << nbits) - 1;
+
+ if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
+ fsx.fsx_projid = p;
+ e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
+ }
+ if (v)
+ printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
+ free_pathname(&f);
+ close(fd);
+#endif
+}
+
void
creat_f(int opno, long r)
{
else
parid = fep->id;
init_pathname(&f);
- type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
- if (type == FT_RTF)
+ e1 = (random() % 100);
+ type = rtpct ? ((e1 > rtpct) ? FT_REG : FT_RTF) : FT_REG;
+#ifdef NOTYET
+ if (type == FT_RTF) /* rt always gets an extsize */
extsize = (random() % 10) + 1;
+ else if (e1 < 10) /* one-in-ten get an extsize */
+ extsize = random() % 1024;
else
+#endif
extsize = 0;
e = generate_fname(fep, type, &f, &id, &v);
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);
}
if (fd >= 0) {
if (extsize &&
xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
- a.fsx_xflags |= XFS_XFLAG_REALTIME;
- a.fsx_extsize =
- geom.rtextsize * geom.blocksize * extsize;
+ if (type == FT_RTF) {
+ a.fsx_xflags |= XFS_XFLAG_REALTIME;
+ a.fsx_extsize = extsize *
+ geom.rtextsize * geom.blocksize;
+#ifdef NOTYET
+ } else if (extsize) {
+ a.fsx_xflags |= XFS_XFLAG_EXTSIZE;
+ a.fsx_extsize = extsize * geom.blocksize;
+#endif
+ }
if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
e1 = errno;
}
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);
}
off = (off64_t)(lr % stb.st_size);
off -= (off % align);
lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 32)) + 1;
+ len = (random() % FILELEN_MAX) + 1;
len -= (len % align);
if (len <= 0)
len = align;
off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
off -= (off % align);
lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 32)) + 1;
+ len = (random() % FILELEN_MAX) + 1;
len -= (len % align);
if (len <= 0)
len = align;
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);
}
lr = ((__int64_t)random() << 32) + random();
off = (off64_t)(lr % stb.st_size);
lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 32)) + 1;
+ len = (random() % FILELEN_MAX) + 1;
buf = malloc(len);
e = read(fd, buf, len) < 0 ? errno : 0;
free(buf);
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);
}
off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
off %= maxfsize;
lseek64(fd, off, SEEK_SET);
- len = (random() % (getpagesize() * 32)) + 1;
+ len = (random() % FILELEN_MAX) + 1;
buf = malloc(len);
memset(buf, nameseq & 0xff, len);
e = write(fd, buf, len) < 0 ? errno : 0;