Whamcloud - gitweb
LU-13456 ldlm: fix reprocessing of locks with more bits
[fs/lustre-release.git] / lustre / tests / multiop.c
index d40c33a..100d014 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #ifndef _GNU_SOURCE
  */
 
 #ifndef _GNU_SOURCE
@@ -52,6 +51,7 @@
 #include <semaphore.h>
 #include <time.h>
 #include <err.h>
 #include <semaphore.h>
 #include <time.h>
 #include <err.h>
+#include <dirent.h>
 
 #include <lustre/lustreapi.h>
 
 
 #include <lustre/lustreapi.h>
 
@@ -59,7 +59,7 @@
 #define T2 "write data after unlink\n"
 char msg[] = "yabba dabba doo, I'm coming for you, I live in a shoe, I don't know what to do.\n'Bigger, bigger,and bigger yet!' cried the Creator.  'You are not yet substantial enough for my boundless intents!'  And ever greater and greater the object became, until all was lost 'neath its momentus bulk.\n";
 char *buf, *buf_align;
 #define T2 "write data after unlink\n"
 char msg[] = "yabba dabba doo, I'm coming for you, I live in a shoe, I don't know what to do.\n'Bigger, bigger,and bigger yet!' cried the Creator.  'You are not yet substantial enough for my boundless intents!'  And ever greater and greater the object became, until all was lost 'neath its momentus bulk.\n";
 char *buf, *buf_align;
-int bufsize = 0;
+int bufsize;
 sem_t sem;
 #define ALIGN_LEN 65535
 #define XATTR "user.multiop"
 sem_t sem;
 #define ALIGN_LEN 65535
 #define XATTR "user.multiop"
@@ -78,9 +78,9 @@ char usage[] =
 "       E[+|-] get lease. +/-: expect lease to (not) exist\n"
 "       f  statfs\n"
 "       F  print FID\n"
 "       E[+|-] get lease. +/-: expect lease to (not) exist\n"
 "       f  statfs\n"
 "       F  print FID\n"
-"       H[num] create HSM released file with num stripes\n"
 "       G gid get grouplock\n"
 "       g gid put grouplock\n"
 "       G gid get grouplock\n"
 "       g gid put grouplock\n"
+"       H[num] create HSM released file with num stripes\n"
 "       K  link path to filename\n"
 "       L  link\n"
 "       l  symlink filename to path\n"
 "       K  link path to filename\n"
 "       L  link\n"
 "       l  symlink filename to path\n"
@@ -91,6 +91,7 @@ char usage[] =
 "       o  open(O_RDONLY)\n"
 "       O  open(O_CREAT|O_RDWR)\n"
 "       p  print return value of last command\n"
 "       o  open(O_RDONLY)\n"
 "       O  open(O_CREAT|O_RDWR)\n"
 "       p  print return value of last command\n"
+"       Q  open filename (should be dir), stat first entry to init statahead"
 "       r[num] read [optional length]\n"
 "       R  reference entire mmap-ed region\n"
 "       s  stat\n"
 "       r[num] read [optional length]\n"
 "       R  reference entire mmap-ed region\n"
 "       s  stat\n"
@@ -112,28 +113,28 @@ char usage[] =
 
 void usr1_handler(int unused)
 {
 
 void usr1_handler(int unused)
 {
-        int saved_errno = errno;
+       int saved_errno = errno;
 
 
-        /*
-         * signal(7): POSIX.1-2004 ...requires an implementation to guarantee
-         * that the following functions can be safely called inside a signal
-         * handler:
-         *            sem_post()
-         */
-        sem_post(&sem);
+       /*
+        * signal(7): POSIX.1-2004 ...requires an implementation to guarantee
+        * that the following functions can be safely called inside a signal
+        * handler:
+        *            sem_post()
+        */
+       sem_post(&sem);
 
 
-        errno = saved_errno;
+       errno = saved_errno;
 }
 
 static const char *
 pop_arg(int argc, char *argv[])
 {
 }
 
 static const char *
 pop_arg(int argc, char *argv[])
 {
-        static int cur_arg = 3;
+       static int cur_arg = 3;
 
 
-        if (cur_arg >= argc)
-                return NULL;
+       if (cur_arg >= argc)
+               return NULL;
 
 
-        return argv[cur_arg++];
+       return argv[cur_arg++];
 }
 
 struct flag_mapping {
 }
 
 struct flag_mapping {
@@ -166,99 +167,131 @@ struct flag_mapping {
 
 int get_flags(char *data, int *rflags)
 {
 
 int get_flags(char *data, int *rflags)
 {
-        char *cloned_flags;
-        char *tmp;
-        int flag_set = 0;
-        int flags = 0;
-        int size = 0;
-
-        cloned_flags = strdup(data);
-        if (cloned_flags == NULL) {
-                fprintf(stderr, "Insufficient memory.\n");
-                exit(-1);
-        }
-
-        for (tmp = strtok(cloned_flags, ":"); tmp;
-             tmp = strtok(NULL, ":")) {
-                int i;
-
-                size = tmp - cloned_flags;
-                for (i = 0; flag_table[i].flag != -1; i++) {
-                        if (!strcmp(tmp, flag_table[i].string)){
-                                flags |= flag_table[i].flag;
-                                size += strlen(flag_table[i].string);
-                                flag_set = 1;
-                                break;
-                        }
-                }
-        }
-        free(cloned_flags);
-
-        if (!flag_set) {
-                *rflags = O_RDONLY;
-                return 0;
-        }
-
-        *rflags = flags;
-        return size;
+       char *cloned_flags;
+       char *tmp;
+       int flag_set = 0;
+       int flags = 0;
+       int size = 0;
+
+       cloned_flags = strdup(data);
+       if (!cloned_flags) {
+               fprintf(stderr, "Insufficient memory.\n");
+               exit(-1);
+       }
+
+       for (tmp = strtok(cloned_flags, ":"); tmp;
+            tmp = strtok(NULL, ":")) {
+               int i;
+
+               size = tmp - cloned_flags;
+               for (i = 0; flag_table[i].flag != -1; i++) {
+                       if (!strcmp(tmp, flag_table[i].string)) {
+                               flags |= flag_table[i].flag;
+                               size += strlen(flag_table[i].string);
+                               flag_set = 1;
+                               break;
+                       }
+               }
+       }
+       free(cloned_flags);
+
+       if (!flag_set) {
+               *rflags = O_RDONLY;
+               return 0;
+       }
+
+       *rflags = flags;
+       return size;
+}
+
+static int statahead(char *dname)
+{
+       DIR *d;
+       struct dirent *dent;
+       struct stat st;
+       char *buf;
+       int rc;
+
+       rc = 0;
+       d = opendir(dname);
+       if (!d)
+               return errno;
+       dent = readdir(d);
+       if (!dent) {
+               rc = errno;
+               goto out_closedir;
+       }
+       if (asprintf(&buf, "%s/%s", dname, dent->d_name) == -1) {
+               rc = errno;
+               goto out_closedir;
+       }
+       if (stat(buf, &st))
+               rc = errno;
+       free(buf);
+out_closedir:
+       closedir(d);
+       return rc;
 }
 
 #define POP_ARG() (pop_arg(argc, argv))
 
 int main(int argc, char **argv)
 {
 }
 
 #define POP_ARG() (pop_arg(argc, argv))
 
 int main(int argc, char **argv)
 {
-       char                    *fname, *commands;
-       const char              *newfile;
-       const char              *oldpath;
-       struct stat              st;
-       struct statfs            stfs;
-       size_t                   mmap_len = 0, i;
-       unsigned char           *mmap_ptr = NULL, junk = 1;
-       int                      len, fd = -1;
-       int                      flags;
-       int                      save_errno;
-       int                      verbose = 0;
-       int                      gid = 0;
-       struct lu_fid            fid;
-       struct timespec          ts;
-       struct lov_user_md_v3    lum;
+       char *fname, *commands;
+       const char *newfile;
+       const char *oldpath;
+       struct stat st;
+       struct statfs stfs;
+       size_t mmap_len = 0, i;
+       unsigned char *mmap_ptr = NULL, junk = 1;
+       int len, fd = -1;
+       int flags;
+       int save_errno;
+       int verbose = 0;
+       int gid = 0;
+       struct lu_fid fid;
+       struct timespec ts;
+       struct lov_user_md_v3 lum;
        char *xattr_buf = NULL;
        size_t xattr_buf_size = 0;
        long long rc = 0;
        long long last_rc;
 
        char *xattr_buf = NULL;
        size_t xattr_buf_size = 0;
        long long rc = 0;
        long long last_rc;
 
-        if (argc < 3) {
-                fprintf(stderr, usage, argv[0]);
-                exit(1);
-        }
+       if (argc < 3) {
+               fprintf(stderr, usage, argv[0]);
+               exit(1);
+       }
 
 
-        memset(&st, 0, sizeof(st));
-        sem_init(&sem, 0, 0);
-        /* use sigaction instead of signal to avoid SA_ONESHOT semantics */
-        sigaction(SIGUSR1, &(const struct sigaction){.sa_handler = &usr1_handler},
-                  NULL);
+       memset(&st, 0, sizeof(st));
+       sem_init(&sem, 0, 0);
+       /* use sigaction instead of signal to avoid SA_ONESHOT semantics */
+       sigaction(SIGUSR1,
+                 &(const struct sigaction){.sa_handler = &usr1_handler}, NULL);
 
 
-        fname = argv[1];
+       fname = argv[1];
 
 
-        for (commands = argv[2]; *commands; commands++) {
-               /* XXX Most commands return 0 or we exit so we only
-                * update rc where really needed. */
+       for (commands = argv[2]; *commands; commands++) {
+               /*
+                * XXX Most commands return 0 or we exit so we only
+                * update rc where really needed.
+                */
                last_rc = rc;
                rc = 0;
 
                last_rc = rc;
                rc = 0;
 
-                switch (*commands) {
-                case '_':
-                        if (verbose) {
-                                printf("PAUSING\n");
-                                fflush(stdout);
-                        }
-                       len = atoi(commands+1);
+               switch (*commands) {
+               case '_':
+                       if (verbose) {
+                               printf("PAUSING\n");
+                               fflush(stdout);
+                       }
+                       len = atoi(commands + 1);
                        if (len <= 0)
                                len = 3600; /* 1 hour */
                        ts.tv_sec = time(NULL) + len;
                        ts.tv_nsec = 0;
                        if (len <= 0)
                                len = 3600; /* 1 hour */
                        ts.tv_sec = time(NULL) + len;
                        ts.tv_nsec = 0;
-                        while (sem_timedwait(&sem, &ts) < 0 && errno == EINTR);
-                        break;
+                       while (sem_timedwait(&sem, &ts) < 0 && errno == EINTR)
+                               ;
+                       break;
                case 'A':
                        if (fsetxattr(fd, XATTR, "multiop", 8, 0)) {
                                save_errno = errno;
                case 'A':
                        if (fsetxattr(fd, XATTR, "multiop", 8, 0)) {
                                save_errno = errno;
@@ -270,7 +303,7 @@ int main(int argc, char **argv)
                        len = atoi(commands + 1);
                        if (xattr_buf_size < len) {
                                xattr_buf = realloc(xattr_buf, len);
                        len = atoi(commands + 1);
                        if (xattr_buf_size < len) {
                                xattr_buf = realloc(xattr_buf, len);
-                               if (xattr_buf == NULL) {
+                               if (!xattr_buf) {
                                        save_errno = errno;
                                        perror("allocating xattr buffer\n");
                                        exit(save_errno);
                                        save_errno = errno;
                                        perror("allocating xattr buffer\n");
                                        exit(save_errno);
@@ -286,14 +319,14 @@ int main(int argc, char **argv)
                                exit(save_errno);
                        }
                        break;
                                exit(save_errno);
                        }
                        break;
-                case 'c':
-                        if (close(fd) == -1) {
-                                save_errno = errno;
-                                perror("close");
-                                exit(save_errno);
-                        }
-                        fd = -1;
-                        break;
+               case 'c':
+                       if (close(fd) == -1) {
+                               save_errno = errno;
+                               perror("close");
+                               exit(save_errno);
+                       }
+                       fd = -1;
+                       break;
                case 'B':
                        lum = (struct lov_user_md_v3) {
                                .lmm_magic = LOV_USER_MAGIC_V3,
                case 'B':
                        lum = (struct lov_user_md_v3) {
                                .lmm_magic = LOV_USER_MAGIC_V3,
@@ -306,33 +339,33 @@ int main(int argc, char **argv)
                                exit(save_errno);
                        }
                        break;
                                exit(save_errno);
                        }
                        break;
-                case 'C':
-                        len = atoi(commands+1);
-                        fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644,
-                                             0, 0, len, 0);
-                        if (fd == -1) {
-                                save_errno = errno;
-                                perror("create stripe file");
-                                exit(save_errno);
-                        }
+               case 'C':
+                       len = atoi(commands + 1);
+                       fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644,
+                                            0, 0, len, 0);
+                       if (fd == -1) {
+                               save_errno = errno;
+                               perror("create stripe file");
+                               exit(save_errno);
+                       }
                        rc = fd;
                        rc = fd;
-                        break;
-                case 'd':
-                        if (mkdir(fname, 0755) == -1) {
-                                save_errno = errno;
-                                perror("mkdir(0755)");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'D':
-                        fd = open(fname, O_DIRECTORY);
-                        if (fd == -1) {
-                                save_errno = errno;
-                                perror("open(O_DIRECTORY)");
-                                exit(save_errno);
-                        }
+                       break;
+               case 'd':
+                       if (mkdir(fname, 0755) == -1) {
+                               save_errno = errno;
+                               perror("mkdir(0755)");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'D':
+                       fd = open(fname, O_DIRECTORY);
+                       if (fd == -1) {
+                               save_errno = errno;
+                               perror("open(O_DIRECTORY)");
+                               exit(save_errno);
+                       }
                        rc = fd;
                        rc = fd;
-                        break;
+                       break;
                case 'e':
                        commands++;
                        switch (*commands) {
                case 'e':
                        commands++;
                        switch (*commands) {
@@ -357,6 +390,7 @@ int main(int argc, char **argv)
                        /* F_UNLCK, interpret return code */
                        if (rc > 0) {
                                const char *str = "unknown";
                        /* F_UNLCK, interpret return code */
                        if (rc > 0) {
                                const char *str = "unknown";
+
                                if (rc == LL_LEASE_RDLCK)
                                        str = "read";
                                else if (rc == LL_LEASE_WRLCK)
                                if (rc == LL_LEASE_RDLCK)
                                        str = "read";
                                else if (rc == LL_LEASE_WRLCK)
@@ -409,27 +443,27 @@ int main(int argc, char **argv)
                                printf(DFID"\n", PFID(&fid));
                        fflush(stdout);
                        break;
                                printf(DFID"\n", PFID(&fid));
                        fflush(stdout);
                        break;
-                case 'G':
-                        gid = atoi(commands+1);
-                        if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
-                                save_errno = errno;
-                                perror("ioctl(GROUP_LOCK)");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'g':
-                        gid = atoi(commands+1);
-                        if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
-                                save_errno = errno;
-                                perror("ioctl(GROUP_UNLOCK)");
-                                exit(save_errno);
-                        }
-                        break;
+               case 'G':
+                       gid = atoi(commands + 1);
+                       if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
+                               save_errno = errno;
+                               perror("ioctl(GROUP_LOCK)");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'g':
+                       gid = atoi(commands + 1);
+                       if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
+                               save_errno = errno;
+                               perror("ioctl(GROUP_UNLOCK)");
+                               exit(save_errno);
+                       }
+                       break;
                case 'H':
                case 'H':
-                       len = atoi(commands+1);
-                       fd = llapi_file_open(fname, O_CREAT | O_WRONLY,
-                               0644, 0, 0, len,
-                               LOV_PATTERN_RAID0 | LOV_PATTERN_F_RELEASED);
+                       len = atoi(commands + 1);
+                       fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644,
+                                            0, 0, len, LOV_PATTERN_RAID0 |
+                                            LOV_PATTERN_F_RELEASED);
                        if (fd == -1) {
                                save_errno = errno;
                                perror("create stripe file");
                        if (fd == -1) {
                                save_errno = errno;
                                perror("create stripe file");
@@ -443,7 +477,7 @@ int main(int argc, char **argv)
                        break;
                case 'K':
                        oldpath = POP_ARG();
                        break;
                case 'K':
                        oldpath = POP_ARG();
-                       if (oldpath == NULL)
+                       if (!oldpath)
                                oldpath = fname;
 
                        if (link(oldpath, fname)) {
                                oldpath = fname;
 
                        if (link(oldpath, fname)) {
@@ -452,19 +486,19 @@ int main(int argc, char **argv)
                                exit(save_errno);
                        }
                        break;
                                exit(save_errno);
                        }
                        break;
-                case 'l':
-                        newfile = POP_ARG();
-                        if (!newfile)
-                                newfile = fname;
-                        if (symlink(fname, newfile)) {
-                                save_errno = errno;
-                                perror("symlink()");
-                                exit(save_errno);
-                        }
-                        break;
+               case 'l':
+                       newfile = POP_ARG();
+                       if (!newfile)
+                               newfile = fname;
+                       if (symlink(fname, newfile)) {
+                               save_errno = errno;
+                               perror("symlink()");
+                               exit(save_errno);
+                       }
+                       break;
                case 'L':
                        newfile = POP_ARG();
                case 'L':
                        newfile = POP_ARG();
-                       if (newfile == NULL)
+                       if (!newfile)
                                newfile = fname;
 
                        if (link(fname, newfile)) {
                                newfile = fname;
 
                        if (link(fname, newfile)) {
@@ -473,31 +507,31 @@ int main(int argc, char **argv)
                                exit(save_errno);
                        }
                        break;
                                exit(save_errno);
                        }
                        break;
-                case 'm':
-                        if (mknod(fname, S_IFREG | 0644, 0) == -1) {
-                                save_errno = errno;
-                                perror("mknod(S_IFREG|0644, 0)");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'M':
-                        if (st.st_size == 0) {
-                                fprintf(stderr, "mmap without preceeding stat, or on"
-                                        " zero length file.\n");
-                                exit(-1);
-                        }
-                        mmap_len = st.st_size;
-                        mmap_ptr = mmap(NULL, mmap_len, PROT_WRITE | PROT_READ,
-                                        MAP_SHARED, fd, 0);
-                        if (mmap_ptr == MAP_FAILED) {
-                                save_errno = errno;
-                                perror("mmap");
-                                exit(save_errno);
-                        }
-                        break;
+               case 'm':
+                       if (mknod(fname, S_IFREG | 0644, 0) == -1) {
+                               save_errno = errno;
+                               perror("mknod(S_IFREG|0644, 0)");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'M':
+                       if (st.st_size == 0) {
+                               fprintf(stderr,
+                                       "mmap without preceeding stat, or on zero length file.\n");
+                               exit(-1);
+                       }
+                       mmap_len = st.st_size;
+                       mmap_ptr = mmap(NULL, mmap_len, PROT_WRITE | PROT_READ,
+                                       MAP_SHARED, fd, 0);
+                       if (mmap_ptr == MAP_FAILED) {
+                               save_errno = errno;
+                               perror("mmap");
+                               exit(save_errno);
+                       }
+                       break;
                case 'n':
                        oldpath = POP_ARG();
                case 'n':
                        oldpath = POP_ARG();
-                       if (oldpath == NULL)
+                       if (!oldpath)
                                oldpath = fname;
 
                        if (rename(oldpath, fname) < 0) {
                                oldpath = fname;
 
                        if (rename(oldpath, fname) < 0) {
@@ -506,50 +540,58 @@ int main(int argc, char **argv)
                                exit(save_errno);
                        }
                        break;
                                exit(save_errno);
                        }
                        break;
-                case 'N':
-                        newfile = POP_ARG();
-                        if (!newfile)
-                                newfile = fname;
-                        if (rename (fname, newfile)) {
-                                save_errno = errno;
-                                perror("rename()");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'O':
-                        fd = open(fname, O_CREAT|O_RDWR, 0644);
-                        if (fd == -1) {
-                                save_errno = errno;
-                                perror("open(O_RDWR|O_CREAT)");
-                                exit(save_errno);
-                        }
+               case 'N':
+                       newfile = POP_ARG();
+                       if (!newfile)
+                               newfile = fname;
+                       if (rename(fname, newfile)) {
+                               save_errno = errno;
+                               perror("rename()");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'O':
+                       fd = open(fname, O_CREAT | O_RDWR, 0644);
+                       if (fd == -1) {
+                               save_errno = errno;
+                               perror("open(O_RDWR|O_CREAT)");
+                               exit(save_errno);
+                       }
                        rc = fd;
                        rc = fd;
-                        break;
-                case 'o':
-                        len = get_flags(commands+1, &flags);
-                        commands += len;
-                        if (flags & O_CREAT)
-                                fd = open(fname, flags, 0666);
-                        else
-                                fd = open(fname, flags);
-                        if (fd == -1) {
-                                save_errno = errno;
-                                perror("open");
-                                exit(save_errno);
-                        }
+                       break;
+               case 'o':
+                       len = get_flags(commands + 1, &flags);
+                       commands += len;
+                       if (flags & O_CREAT)
+                               fd = open(fname, flags, 0666);
+                       else
+                               fd = open(fname, flags);
+                       if (fd == -1) {
+                               save_errno = errno;
+                               perror("open");
+                               exit(save_errno);
+                       }
                        rc = fd;
                        rc = fd;
-                        break;
+                       break;
                case 'p':
                        printf("%lld\n", last_rc);
                        break;
                case 'p':
                        printf("%lld\n", last_rc);
                        break;
+               case 'Q':
+                       save_errno = statahead(fname);
+                       if (save_errno) {
+                               perror("statahead");
+                               exit(save_errno);
+                       }
+                       break;
                case 'r':
                case 'r':
-                       len = atoi(commands+1);
+                       len = atoi(commands + 1);
                        if (len <= 0)
                                len = 1;
                        if (bufsize < len) {
                                void *tmp;
                        if (len <= 0)
                                len = 1;
                        if (bufsize < len) {
                                void *tmp;
+
                                tmp = realloc(buf, len + ALIGN_LEN);
                                tmp = realloc(buf, len + ALIGN_LEN);
-                               if (tmp == NULL) {
+                               if (!tmp) {
                                        free(buf);
                                        save_errno = errno;
                                        perror("allocating buf for read\n");
                                        free(buf);
                                        save_errno = errno;
                                        perror("allocating buf for read\n");
@@ -578,63 +620,63 @@ int main(int argc, char **argv)
                                        printf("%.*s\n", (int)rc, buf_align);
                        }
                        break;
                                        printf("%.*s\n", (int)rc, buf_align);
                        }
                        break;
-                case 'R':
-                        for (i = 0; i < mmap_len && mmap_ptr; i += 4096)
-                                junk += mmap_ptr[i];
-                        break;
-                case 's':
-                        if (stat(fname, &st) == -1) {
-                                save_errno = errno;
-                                perror("stat");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'S':
-                        if (fstat(fd, &st) == -1) {
-                                save_errno = errno;
-                                perror("fstat");
-                                exit(save_errno);
-                        }
-                        break;
-                case 't':
-                        if (fchmod(fd, 0) == -1) {
-                                save_errno = errno;
-                                perror("fchmod");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'T':
-                        len = atoi(commands+1);
-                        if (ftruncate(fd, len) == -1) {
-                                save_errno = errno;
-                                printf("ftruncate (%d,%d)\n", fd, len);
-                                perror("ftruncate");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'u':
-                        if (unlink(fname) == -1) {
-                                save_errno = errno;
-                                perror("unlink");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'U':
-                        if (munmap(mmap_ptr, mmap_len)) {
-                                save_errno = errno;
-                                perror("munmap");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'v':
-                        verbose++;
-                        break;
+               case 'R':
+                       for (i = 0; i < mmap_len && mmap_ptr; i += 4096)
+                               junk += mmap_ptr[i];
+                       break;
+               case 's':
+                       if (stat(fname, &st) == -1) {
+                               save_errno = errno;
+                               perror("stat");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'S':
+                       if (fstat(fd, &st) == -1) {
+                               save_errno = errno;
+                               perror("fstat");
+                               exit(save_errno);
+                       }
+                       break;
+               case 't':
+                       if (fchmod(fd, 0) == -1) {
+                               save_errno = errno;
+                               perror("fchmod");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'T':
+                       len = atoi(commands + 1);
+                       if (ftruncate(fd, len) == -1) {
+                               save_errno = errno;
+                               printf("ftruncate (%d,%d)\n", fd, len);
+                               perror("ftruncate");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'u':
+                       if (unlink(fname) == -1) {
+                               save_errno = errno;
+                               perror("unlink");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'U':
+                       if (munmap(mmap_ptr, mmap_len)) {
+                               save_errno = errno;
+                               perror("munmap");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'v':
+                       verbose++;
+                       break;
                case 'V':
                        len = get_flags(commands + 1, &flags);
                        commands += len;
                        len = -1; /* mdt index */
                        if (commands[1] >= '0' && commands[1] <= '9')
                case 'V':
                        len = get_flags(commands + 1, &flags);
                        commands += len;
                        len = -1; /* mdt index */
                        if (commands[1] >= '0' && commands[1] <= '9')
-                               len = atoi(commands+1);
+                               len = atoi(commands + 1);
                        fd = llapi_create_volatile_idx(fname, len, flags);
                        if (fd < 0) {
                                perror("llapi_create_volatile");
                        fd = llapi_create_volatile_idx(fname, len, flags);
                        if (fd < 0) {
                                perror("llapi_create_volatile");
@@ -643,13 +685,14 @@ int main(int argc, char **argv)
                        rc = fd;
                        break;
                case 'w':
                        rc = fd;
                        break;
                case 'w':
-                       len = atoi(commands+1);
+                       len = atoi(commands + 1);
                        if (len <= 0)
                                len = 1;
                        if (bufsize < len) {
                                void *tmp;
                        if (len <= 0)
                                len = 1;
                        if (bufsize < len) {
                                void *tmp;
+
                                tmp = realloc(buf, len + ALIGN_LEN);
                                tmp = realloc(buf, len + ALIGN_LEN);
-                               if (tmp == NULL) {
+                               if (!tmp) {
                                        free(buf);
                                        save_errno = errno;
                                        perror("allocating buf for write\n");
                                        free(buf);
                                        save_errno = errno;
                                        perror("allocating buf for write\n");
@@ -669,7 +712,8 @@ int main(int argc, char **argv)
                                        exit(save_errno);
                                }
                                if (rc < len)
                                        exit(save_errno);
                                }
                                if (rc < len)
-                                       fprintf(stderr, "short write: %lld/%u\n",
+                                       fprintf(stderr,
+                                               "short write: %lld/%u\n",
                                                rc, len);
                                len -= rc;
                        }
                                                rc, len);
                                len -= rc;
                        }
@@ -683,8 +727,9 @@ int main(int argc, char **argv)
 
                        rc = llapi_get_data_version(fd, &dv, 0);
                        if (rc) {
 
                        rc = llapi_get_data_version(fd, &dv, 0);
                        if (rc) {
-                               fprintf(stderr, "cannot get file data version"
-                                       " %lld\n", rc);
+                               fprintf(stderr,
+                                       "cannot get file data version %lld\n",
+                                       rc);
                                exit(-rc);
                        }
                        printf("dataversion is %ju\n", (uintmax_t)dv);
                                exit(-rc);
                        }
                        printf("dataversion is %ju\n", (uintmax_t)dv);
@@ -695,21 +740,22 @@ int main(int argc, char **argv)
 
                        rc = llapi_get_ost_layout_version(fd, &layout_version);
                        if (rc) {
 
                        rc = llapi_get_ost_layout_version(fd, &layout_version);
                        if (rc) {
-                               fprintf(stderr, "cannot get ost layout version"
-                                       " %lld\n", rc);
+                               fprintf(stderr,
+                                       "cannot get ost layout version %lld\n",
+                                       rc);
                                exit(-rc);
                        }
                        printf("ostlayoutversion: %u\n", layout_version);
                        break;
                }
                                exit(-rc);
                        }
                        printf("ostlayoutversion: %u\n", layout_version);
                        break;
                }
-                case 'y':
-                        if (fsync(fd) == -1) {
-                                save_errno = errno;
-                                perror("fsync");
-                                exit(save_errno);
-                        }
-                        break;
-                case 'Y':
+               case 'y':
+                       if (fsync(fd) == -1) {
+                               save_errno = errno;
+                               perror("fsync");
+                               exit(save_errno);
+                       }
+                       break;
+               case 'Y':
                        if (fdatasync(fd) == -1) {
                                save_errno = errno;
                                perror("fdatasync");
                        if (fdatasync(fd) == -1) {
                                save_errno = errno;
                                perror("fdatasync");
@@ -745,26 +791,26 @@ int main(int argc, char **argv)
                        break;
                }
                case '-':
                        break;
                }
                case '-':
-                case '0':
-                case '1':
-                case '2':
-                case '3':
-                case '4':
-                case '5':
-                case '6':
-                case '7':
-                case '8':
-                case '9':
-                        break;
-                default:
-                        fprintf(stderr, "unknown command \"%c\"\n", *commands);
-                        fprintf(stderr, usage, argv[0]);
-                        exit(1);
-                }
-        }
-
-        if (buf)
-                free(buf);
-
-        return 0;
+               case '0':
+               case '1':
+               case '2':
+               case '3':
+               case '4':
+               case '5':
+               case '6':
+               case '7':
+               case '8':
+               case '9':
+                       break;
+               default:
+                       fprintf(stderr, "unknown command \"%c\"\n", *commands);
+                       fprintf(stderr, usage, argv[0]);
+                       exit(1);
+               }
+       }
+
+       if (buf)
+               free(buf);
+
+       return 0;
 }
 }