Whamcloud - gitweb
land clio.
[fs/lustre-release.git] / lustre / liblustre / tests / sanity.c
index 9edfc92..070e3c6 100644 (file)
@@ -1,24 +1,41 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Lustre Light user test program
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * This program is distributed in the hope that it will 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 version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   Lustre is distributed in the hope that it will 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.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/liblustre/tests/sanity.c
+ *
+ * Lustre Light user test program
  */
 
 #define _BSD_SOURCE
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/queue.h>
 #include <signal.h>
 #include <errno.h>
 #include <dirent.h>
 #include <sys/uio.h>
 #include <sys/time.h>
+#include <time.h>
 
+#include <liblustre.h>
 #include "test_common.h"
-#include <ioctl.h>
-#include <lustre/lustre_user.h>
+#include <lustre/liblustreapi.h>
 
-#ifndef PAGE_SIZE
-#define PAGE_SIZE getpagesize()
-#endif
 #define _npages (2048)
 
 void *buf_alloc;
@@ -55,11 +69,13 @@ struct timeval start;
 
 extern char *lustre_path;
 
-#define ENTRY(str)                                                      \
+#define ENTER(str)                                                      \
         do {                                                            \
                 char buf[100];                                          \
                 int len;                                                \
-                sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
+                gettimeofday(&start, NULL);                             \
+                sprintf(buf, "===== START %s: %s %ld", __FUNCTION__,    \
+                        (str), (long)start.tv_sec);                     \
                 len = strlen(buf);                                      \
                 if (len < 79) {                                         \
                         memset(buf+len, '=', 100-len);                  \
@@ -67,7 +83,6 @@ extern char *lustre_path;
                         buf[80] = 0;                                    \
                 }                                                       \
                 printf("%s", buf);                                      \
-                gettimeofday(&start, NULL);                             \
         } while (0)
 
 #define LEAVE()                                                         \
@@ -97,6 +112,7 @@ int t1(char *name)
 {
         char path[MAX_PATH_LENGTH] = "";
 
+        ENTER("touch+unlink");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path);
 
         if (opt_verbose)
@@ -111,7 +127,7 @@ int t2(char *name)
 {
         char path[MAX_PATH_LENGTH] = "";
 
-        ENTRY("mkdir/rmdir");
+        ENTER("mkdir/rmdir");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path);
 
         t_mkdir(path);
@@ -123,7 +139,7 @@ int t3(char *name)
 {
         char path[MAX_PATH_LENGTH] = "";
 
-        ENTRY("regular stat");
+        ENTER("regular stat");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path);
 
         t_touch(path);
@@ -136,7 +152,7 @@ int t4(char *name)
 {
         char path[MAX_PATH_LENGTH] = "";
 
-        ENTRY("dir stat");
+        ENTER("dir stat");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path);
 
         t_mkdir(path);
@@ -150,7 +166,7 @@ int t6(char *name)
         char path[MAX_PATH_LENGTH] = "";
         char path2[MAX_PATH_LENGTH] = "";
 
-        ENTRY("symlink");
+        ENTER("symlink");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path);
         snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path);
 
@@ -170,7 +186,7 @@ int t6b(char *name)
         char *tmp;
         int fd;
 
-        ENTRY("symlink + chdir and open");
+        ENTER("symlink + chdir and open");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path);
         snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path);
 
@@ -202,7 +218,7 @@ int t7(char *name)
         char path[MAX_PATH_LENGTH] = "";
         int rc;
 
-        ENTRY("mknod");
+        ENTER("mknod");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path);
 
         if (geteuid() != 0) {
@@ -223,7 +239,7 @@ int t8(char *name)
 {
         char path[MAX_PATH_LENGTH] = "";
 
-        ENTRY("chmod");
+        ENTER("chmod");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path);
 
         /* Check file. */
@@ -246,7 +262,7 @@ int t9(char *name)
         char path[MAX_PATH_LENGTH] = "";
         char path2[MAX_PATH_LENGTH] = "";
 
-        ENTRY("hard link");
+        ENTER("hard link");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path);
         snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path);
 
@@ -269,7 +285,7 @@ int t10(char *name)
         char rename2[MAX_PATH_LENGTH] = "";
         char rename3[MAX_PATH_LENGTH] = "";
 
-        ENTRY("rename");
+        ENTER("rename");
         snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path);
         snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path);
         snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path);
@@ -297,7 +313,7 @@ int t11(char *name)
         char *base=lustre_path;
         char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
         int i, j, level = 5, nreg = 5;
-        ENTRY("deep tree");
+        ENTER("deep tree");
 
         safe_strncpy(path, base, MAX_PATH_LENGTH);
 
@@ -333,7 +349,7 @@ int t12(char *name)
         char dir[MAX_PATH_LENGTH] = "";
         char buf[1024*128];
         int fd;
-        ENTRY("empty directory readdir");
+        ENTER("empty directory readdir");
         snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path);
 
         t_mkdir(dir);
@@ -352,7 +368,7 @@ int t13(char *name)
         const int nfiles = 20;
         char *prefix = "test13_filename_prefix_";
         int fd, i;
-        ENTRY("multiple entries directory readdir");
+        ENTER("multiple entries directory readdir");
         snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path);
 
         t_mkdir(dir);
@@ -380,10 +396,10 @@ int t14(char *name)
         char buf[1024];
         const int nfiles = 256;
         char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
-        struct dirent64 *ent;
+        cfs_dirent_t *ent;
         int fd, i, rc, pos, index;
         loff_t base = 0;
-        ENTRY(">1 block(4k) directory readdir");
+        ENTER(">1 block(4k) directory readdir");
         snprintf(dir, MAX_PATH_LENGTH, "%s/test_t14_dir/", lustre_path);
 
         rc = mkdir(dir, 0755);
@@ -404,7 +420,7 @@ int t14(char *name)
                 while (pos < rc) {
                         char *item;
 
-                        ent = (struct dirent64 *) ((char*) buf + pos);
+                        ent = (void *) buf + pos;
                         item = (char *) ent->d_name;
                         if (!strcmp(item, ".") || !strcmp(item, ".."))
                                 goto iter;
@@ -440,7 +456,7 @@ int t15(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
         int fd;
-        ENTRY("open-stat-close");
+        ENTER("open-stat-close");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t15_file", lustre_path);
 
         t_touch(file);
@@ -454,7 +470,7 @@ int t15(char *name)
 int t16(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
-        ENTRY("small-write-read");
+        ENTER("small-write-read");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t16_file", lustre_path);
 
         t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaa");
@@ -467,7 +483,7 @@ int t17(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
         int fd;
-        ENTRY("open-unlink without close");
+        ENTER("open-unlink without close");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t17_file", lustre_path);
 
         fd = open(file, O_WRONLY | O_CREAT, 0666);
@@ -485,7 +501,7 @@ int t18(char *name)
         char buf[128];
         int fd, i;
         struct stat statbuf[3];
-        ENTRY("write should change mtime/ctime");
+        ENTER("write should change mtime/ctime");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t18_file", lustre_path);
 
         for (i = 0; i < 3; i++) {
@@ -522,10 +538,9 @@ int t18(char *name)
 int t18b(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
-        char buf[128];
-        int fd, i;
+        int i;
         struct stat statbuf[3];
-        ENTRY("utime should change mtime/atime/ctime");
+        ENTER("utime should change mtime/atime/ctime");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t18b_file", lustre_path);
         t_touch(file);
 
@@ -553,7 +568,7 @@ int t18b(char *name)
         LEAVE();
 }
 
-static int check_file_size(char *file, off_t size)
+static int check_file_size(char *file, long long size)
 {
         struct stat statbuf;
 
@@ -562,7 +577,8 @@ static int check_file_size(char *file, off_t size)
                 return(1);
         }
         if (statbuf.st_size != size) {
-                printf("size of %s: %ld != %ld\n", file, statbuf.st_size, size);
+                printf("size of %s: %lld != %lld\n", file,
+                       (long long)statbuf.st_size, size);
                 return(-1);
         }
         return 0;
@@ -573,7 +589,7 @@ int t19(char *name)
         char file[MAX_PATH_LENGTH] = "";
         int fd;
         int result;
-        ENTRY("open(O_TRUNC) should truncate file to 0-length");
+        ENTER("open(O_TRUNC) should truncate file to 0-length");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t19_file", lustre_path);
 
         t_echo_create(file, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
@@ -598,7 +614,7 @@ int t20(char *name)
         struct iovec iov[2];
         char buf[100];
         ssize_t ret;
-        ENTRY("trap app's general bad pointer for file i/o");
+        ENTER("trap app's general bad pointer for file i/o");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
 
         fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
@@ -609,12 +625,12 @@ int t20(char *name)
 
         ret = write(fd, NULL, 20);
         if (ret != -1 || errno != EFAULT) {
-                printf("write 1: ret %ld, errno %d\n", ret, errno);
+                printf("write 1: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
         ret = write(fd, (void *)-1, 20);
         if (ret != -1 || errno != EFAULT) {
-                printf("write 2: ret %ld, errno %d\n", ret, errno);
+                printf("write 2: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
         iov[0].iov_base = NULL;
@@ -623,7 +639,7 @@ int t20(char *name)
         iov[1].iov_len = 10;
         ret = writev(fd, iov, 2);
         if (ret != -1 || errno != EFAULT) {
-                printf("writev 1: ret %ld, errno %d\n", ret, errno);
+                printf("writev 1: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
         iov[0].iov_base = NULL;
@@ -632,19 +648,19 @@ int t20(char *name)
         iov[1].iov_len = sizeof(buf);
         ret = writev(fd, iov, 2);
         if (ret != sizeof(buf)) {
-                printf("write 3 ret %ld, error %d\n", ret, errno);
+                printf("writev 2: ret %lld, error %d\n", (long long)ret, errno);
                 return(1);
         }
         lseek(fd, 0, SEEK_SET);
 
         ret = read(fd, NULL, 20);
         if (ret != -1 || errno != EFAULT) {
-                printf("read 1: ret %ld, errno %d\n", ret, errno);
+                printf("read 1: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
         ret = read(fd, (void *)-1, 20);
         if (ret != -1 || errno != EFAULT) {
-                printf("read 2: ret %ld, errno %d\n", ret, errno);
+                printf("read 2: ret %lld, error %d\n", (long long)ret, errno);
                 return(1);
         }
         iov[0].iov_base = NULL;
@@ -653,7 +669,7 @@ int t20(char *name)
         iov[1].iov_len = 10;
         ret = readv(fd, iov, 2);
         if (ret != -1 || errno != EFAULT) {
-                printf("readv 1: ret %ld, errno %d\n", ret, errno);
+                printf("readv 1: ret %lld, error %d\n", (long long)ret, errno);
                 return(1);
         }
         iov[0].iov_base = NULL;
@@ -662,7 +678,7 @@ int t20(char *name)
         iov[1].iov_len = sizeof(buf);
         ret = readv(fd, iov, 2);
         if (ret != sizeof(buf)) {
-                printf("read 3 ret %ld, error %d\n", ret, errno);
+                printf("readv 2: ret %lld, error %d\n", (long long)ret, errno);
                 return(1);
         }
 
@@ -680,12 +696,12 @@ int t21(char *name)
                 .l_whence = SEEK_SET,
         };
 
-        ENTRY("basic fcntl support");
+        ENTER("basic fcntl support");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
 
         fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
         if (fd < 0) {
-                printf("error open file: %m\n", file);
+                printf("error open file: %s\n", file);
                 return(-1);
         }
 
@@ -715,7 +731,7 @@ int t22(char *name)
         char *str = "1234567890";
         char buf[100];
         ssize_t ret;
-        ENTRY("make sure O_APPEND take effect");
+        ENTER("make sure O_APPEND take effect");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
 
         fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
@@ -727,14 +743,14 @@ int t22(char *name)
         lseek(fd, 100, SEEK_SET);
         ret = write(fd, str, strlen(str));
         if (ret != strlen(str)) {
-                printf("write 1: ret %ld, errno %d\n", ret, errno);
+                printf("write 1: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
 
         lseek(fd, 0, SEEK_SET);
         ret = read(fd, buf, sizeof(buf));
         if (ret != strlen(str)) {
-                printf("read 1 got %ld\n", ret);
+                printf("read 1: ret %lld\n", (long long)ret);
                 return(1);
         }
 
@@ -751,14 +767,14 @@ int t22(char *name)
         lseek(fd, 100, SEEK_SET);
         ret = write(fd, str, strlen(str));
         if (ret != strlen(str)) {
-                printf("write 2: ret %ld, errno %d\n", ret, errno);
+                printf("write 2: ret %lld, errno %d\n", (long long)ret, errno);
                 return(1);
         }
 
         lseek(fd, 100, SEEK_SET);
         ret = read(fd, buf, sizeof(buf));
         if (ret != strlen(str)) {
-                printf("read 2 got %ld\n", ret);
+                printf("read 2: ret %lld\n", (long long)ret);
                 return(1);
         }
 
@@ -776,10 +792,10 @@ int t23(char *name)
 {
         char path[MAX_PATH_LENGTH];
         int fd;
-        long long ret;
-        loff_t off;
+        off_t ret;
+        off_t off;
 
-        ENTRY("handle seek > 2GB");
+        ENTER("handle seek > 2GB");
         snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
 
         fd = open(path, O_WRONLY | O_CREAT | O_LARGEFILE, 0666);
@@ -882,14 +898,14 @@ static int pages_io(int xfer, loff_t pos)
 
         /* create sample data */
         for (i = 0, buf = buf_alloc; i < _npages; i++) {
-                for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
+                for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
                         *buf = rand();
                 }
         }
 
         /* compute checksum */
         for (i = 0, buf = buf_alloc; i < _npages; i++) {
-                for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
+                for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
                         check_sum[i] += *buf;
                 }
         }
@@ -907,9 +923,9 @@ static int pages_io(int xfer, loff_t pos)
         }
         gettimeofday(&tw1, NULL);
         for (i = 0, buf = buf_alloc; i < _npages;
-             i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
-                rc = write(fd, buf, PAGE_SIZE * xfer);
-                if (rc != PAGE_SIZE * xfer) {
+             i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
+                rc = write(fd, buf, CFS_PAGE_SIZE * xfer);
+                if (rc != CFS_PAGE_SIZE * xfer) {
                         printf("write error (i %d, rc %d): %s\n", i, rc,
                                strerror(errno));
                         return(1);
@@ -927,9 +943,9 @@ static int pages_io(int xfer, loff_t pos)
         }
         gettimeofday(&tr1, NULL);
         for (i = 0, buf = buf_alloc; i < _npages;
-             i += xfer, buf += xfer * PAGE_SIZE / sizeof(int)) {
-                rc = read(fd, buf, PAGE_SIZE * xfer);
-                if (rc != PAGE_SIZE * xfer) {
+             i += xfer, buf += xfer * CFS_PAGE_SIZE / sizeof(int)) {
+                rc = read(fd, buf, CFS_PAGE_SIZE * xfer);
+                if (rc != CFS_PAGE_SIZE * xfer) {
                         printf("read error (i %d, rc %d): %s\n", i, rc,
                                strerror(errno));
                         return(1);
@@ -940,7 +956,7 @@ static int pages_io(int xfer, loff_t pos)
         /* compute checksum */
         for (i = 0, buf = buf_alloc; i < _npages; i++) {
                 int sum = 0;
-                for (j = 0; j < PAGE_SIZE/sizeof(int); j++, buf++) {
+                for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
                         sum += *buf;
                 }
                 if (sum != check_sum[i]) {
@@ -955,8 +971,8 @@ static int pages_io(int xfer, loff_t pos)
         tw = (tw2.tv_sec - tw1.tv_sec) * 1000000 + (tw2.tv_usec - tw1.tv_usec);
         tr = (tr2.tv_sec - tr1.tv_sec) * 1000000 + (tr2.tv_usec - tr1.tv_usec);
         printf(" (R:%.3fM/s, W:%.3fM/s)\n",
-                (_npages * PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
-                (_npages * PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
+                (_npages * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
+                (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
 
         if (data_error)
                 return 1;
@@ -969,7 +985,7 @@ int t50(char *name)
         int np = 1;
         loff_t offset = 0;
 
-        ENTRY("4k aligned i/o sanity");
+        ENTER("4k aligned i/o sanity");
         while (np <= _npages) {
                 printf("%3d per xfer(total %d)...\t", np, _npages);
                 fflush(stdout);
@@ -985,9 +1001,9 @@ int t50b(char *name)
         loff_t off_array[] = {1, 17, 255, 258, 4095, 4097, 8191,
                               1024*1024*1024*1024ULL};
         int i;
-        loff_t offset;
+        long long offset;
 
-        ENTRY("4k un-aligned i/o sanity");
+        ENTER("4k un-aligned i/o sanity");
         for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
                 offset = off_array[i];
                 printf("16 per xfer(total %d), offset %10lld...\t",
@@ -1011,10 +1027,10 @@ int t51(char *name)
 {
         char file[MAX_PATH_LENGTH] = "";
         int fd;
-        off_t size;
+        long long size;
         int result;
 
-        ENTRY("truncate() should truncate file to proper length");
+        ENTER("truncate() should truncate file to proper length");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t51_file", lustre_path);
 
         for (size = 0; size < T51_NR * T51_STEP; size += T51_STEP) {
@@ -1063,7 +1079,7 @@ int t52(char *name)
         time_t diff;
         int fd, i;
 
-        ENTRY("atime should be updated during read");
+        ENTER("atime should be updated during read");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path);
 
         t_echo_create(file, "check atime update during read");
@@ -1086,8 +1102,8 @@ int t52(char *name)
                         close(fd);
                         t_unlink(file);
                         return -1;
-                }       
-                atime = statbuf.st_atime; 
+                }
+                atime = statbuf.st_atime;
         }
         close(fd);
         t_unlink(file);
@@ -1101,26 +1117,26 @@ int t53(char *name)
         struct utimbuf times;   /* struct. buffer for utime() */
         struct stat stat_buf;   /* struct buffer to hold file info. */
         time_t mtime, atime;
-        ENTRY("mtime/atime should be updated by utime() call");
+
+        ENTER("mtime/atime should be updated by utime() call");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t53_file", lustre_path);
 
         t_echo_create(file, "check mtime/atime update by utime() call");
+
         /* Initialize the modification and access time in the times arg */
         times.actime = NEW_TIME+10;
         times.modtime = NEW_TIME;
+
         /* file modification/access time */
         utime(file, &times);
+
         if (stat(file, &stat_buf) < 0) {
                 printf("stat(2) of %s failed, error:%d %s\n",
-                        file, errno, strerror(errno)); 
+                        file, errno, strerror(errno));
         }
         mtime = stat_buf.st_mtime;
         atime = stat_buf.st_atime;
+
         if ((mtime == NEW_TIME) && (atime == NEW_TIME + 10)) {
                 t_unlink(file);
                 LEAVE();
@@ -1128,7 +1144,7 @@ int t53(char *name)
 
         printf("mod time %ld, expected %ld\n", mtime, (long)NEW_TIME);
         printf("acc time %ld, expected %ld\n", atime, (long)NEW_TIME + 10);
+
         t_unlink(file);
         return (-1);
 }
@@ -1139,7 +1155,7 @@ int t54(char *name)
         struct flock lock;
         int fd, err;
 
-        ENTRY("fcntl should return 0 when succeed in getting flock");
+        ENTER("fcntl should return 0 when succeed in getting flock");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);
 
         t_echo_create(file, "fcntl should return 0 when succeed");
@@ -1154,7 +1170,7 @@ int t54(char *name)
         lock.l_whence = 0;
         lock.l_len    = 1;
         if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {
-                fprintf(stderr, "fcntl returned: %d (%s)\n", 
+                fprintf(stderr, "fcntl returned: %d (%s)\n",
                         err, strerror(err));
                 close(fd);
                 t_unlink(file);
@@ -1169,7 +1185,9 @@ int t54(char *name)
 }
 
 /* for O_DIRECTORY */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #define STRIPE_SIZE       (2048 * 2048)
 #define STRIPE_OFFSET           0
@@ -1182,10 +1200,10 @@ int t55(char *name)
         struct lov_user_ost_data *lo = NULL;
         int index, fd, buflen, rc;
 
-        ENTRY("setstripe/getstripe");
+        ENTER("setstripe/getstripe");
         snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);
-      
+
         buflen = sizeof(struct lov_user_md);
         buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);
         lum = (struct lov_user_md *)malloc(buflen);
@@ -1214,7 +1232,7 @@ int t55(char *name)
                 free(lum);
                 return -1;
         }
-        
+
         lum->lmm_magic = LOV_USER_MAGIC;
         lum->lmm_stripe_count = STRIPE_COUNT;
         rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);
@@ -1237,13 +1255,13 @@ int t55(char *name)
                 printf("lmm_stripe_count:   %u\n", (int)lum->lmm_stripe_count);
                 printf("lmm_stripe_size:    %u\n",      lum->lmm_stripe_size);
                 printf("lmm_stripe_pattern: %x\n",      lum->lmm_pattern);
-        
+
                 for (index = 0; index < lum->lmm_stripe_count; index++) {
                         lo = lum->lmm_objects + index;
                         printf("object %d:\n", index);
                         printf("\tobject_gr:    "LPX64"\n", lo->l_object_gr);
                         printf("\tobject_id:    "LPX64"\n", lo->l_object_id);
-                        printf("\tost_gen:      "LPX64"\n", lo->l_ost_gen);
+                        printf("\tost_gen:      %#x\n", lo->l_ost_gen);
                         printf("\tost_idx:      %u\n", lo->l_ost_idx);
                 }
         }
@@ -1274,7 +1292,7 @@ int t55(char *name)
         }
         fd = open(file, O_RDWR, 0644);
         if (fd < 0) {
-                printf("failed to open(%s): rc = %d (%s)\n", 
+                printf("failed to open(%s): rc = %d (%s)\n",
                        file, fd, strerror(errno));
                 t_unlink(file);
                 t_rmdir(path);
@@ -1303,13 +1321,13 @@ int t55(char *name)
                 printf("lmm_stripe_count:   %u\n", (int)lum->lmm_stripe_count);
                 printf("lmm_stripe_size:    %u\n",      lum->lmm_stripe_size);
                 printf("lmm_stripe_pattern: %x\n",      lum->lmm_pattern);
-        
+
                 for (index = 0; index < lum->lmm_stripe_count; index++) {
                         lo = lum->lmm_objects + index;
                         printf("object %d:\n", index);
                         printf("\tobject_gr:    "LPX64"\n", lo->l_object_gr);
                         printf("\tobject_id:    "LPX64"\n", lo->l_object_id);
-                        printf("\tost_gen:      "LPX64"\n", lo->l_ost_gen);
+                        printf("\tost_gen:      %#x\n", lo->l_ost_gen);
                         printf("\tost_idx:      %u\n", lo->l_ost_idx);
                 }
         }
@@ -1332,6 +1350,46 @@ int t55(char *name)
         LEAVE();
 }
 
+/*
+ * getdirentries should return -1 and set errno to EINVAL when the size
+ * specified as an argument is too small to contain at least one entry
+ * (see bugzilla ticket 12229)
+ */
+int t56(char *name)
+{
+        int fd;
+        size_t nbytes;
+        off_t basep = 0;
+        ssize_t rc = 0;
+        cfs_dirent_t dir;
+
+        ENTER("getdirentries should fail if nbytes is too small");
+
+        /* Set count to be very small.  The result should be EINVAL */
+        nbytes = 8;
+
+        /* open the directory and call getdirentries */
+        fd = t_opendir(lustre_path);
+
+        rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
+
+        if (rc != -1) {
+                printf("Test failed: getdirentries returned %lld\n",
+                       (long long)rc);
+                t_close(fd);
+                return -1;
+        }
+        if (errno != EINVAL) {
+                printf("Test failed: getdirentries returned %lld but errno is "
+                       "set to %d (should be EINVAL)\n", (long long)rc, errno);
+                t_close(fd);
+                return -1;
+        }
+        t_close(fd);
+
+        LEAVE();
+}
+
 extern void __liblustre_setup_(void);
 extern void __liblustre_cleanup_(void);
 
@@ -1339,8 +1397,8 @@ extern void __liblustre_cleanup_(void);
 void usage(char *cmd)
 {
         printf("\n"
-               "usage: %s [--only {test}] --target mgsnid:/fsname\n",
-               cmd);
+             "usage: %s [-o test][-e test][-v] --target mgsnid:/fsname\n",
+             cmd);
         printf("       %s --dumpfile dumpfile\n", cmd);
         exit(-1);
 }
@@ -1379,27 +1437,35 @@ struct testlist {
         { t53, "53" },
         { t54, "54" },
         { t55, "55" },
+        { t56, "56" },
         { NULL, NULL }
 };
 
 int main(int argc, char * const argv[])
 {
         struct testlist *test;
-        int opt_index, c, rc = 0, numonly = 0;
-        char *only[100];
+        int opt_index, c, rc = 0, numonly = 0, numexcept = 0;
+        char *only[100], *except[100];
         static struct option long_opts[] = {
                 {"dumpfile", 1, 0, 'd'},
                 {"only", 1, 0, 'o'},
+                {"except", 1, 0, 'e'},
                 {"target", 1, 0, 't'},
                 {"verbose", 1, 0, 'v'},
                 {0, 0, 0, 0}
         };
 
-        while ((c = getopt_long(argc, argv, "d:o:t:v", long_opts, &opt_index)) != -1) {
+        while ((c = getopt_long(argc, argv, "d:e:o:t:v", long_opts, &opt_index)) != -1) {
                 switch (c) {
                 case 'd':
                         setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
                         break;
+                case 'e':
+                        if (numexcept == 0)
+                                printf("Not running test(s): ");
+                        printf("%s ", optarg);
+                        except[numexcept++] = optarg;
+                        break;
                 case 'o':
                         if (numonly == 0)
                                 printf("Only running test(s): ");
@@ -1429,7 +1495,7 @@ int main(int argc, char * const argv[])
 
         __liblustre_setup_();
 
-        buf_size = _npages * PAGE_SIZE;
+        buf_size = _npages * CFS_PAGE_SIZE;
         if (opt_verbose)
                 printf("allocating %d bytes buffer\n", buf_size);
         buf_alloc = calloc(1, buf_size);
@@ -1440,14 +1506,35 @@ int main(int argc, char * const argv[])
 
         for (test = testlist; test->test != NULL; test++) {
                 int run = 1, i;
+                int len, olen;
 
-                if (numonly > 0) {
-                        int len;
+                if (numexcept > 0) {
+                        len = strlen(test->name);
+                        for (i = 0; i < numexcept; i++) {
+                                olen = strlen(except[i]);
 
+                                if (len < olen)
+                                        continue;
+
+                                if (strncmp(except[i], test->name, olen) == 0) {
+                                        switch(test->name[olen]) {
+                                        case '0': case '1': case '2': case '3':
+                                        case '4': case '5': case '6': case '7':
+                                        case '8': case '9':
+                                                break;
+                                        default:
+                                                run = 0;
+                                                break;
+                                        }
+                                }
+                        }
+                }
+
+                if (numonly > 0) {
                         run = 0;
                         len = strlen(test->name);
                         for (i = 0; i < numonly; i++) {
-                                int olen = strlen(only[i]);
+                                olen = strlen(only[i]);
 
                                 if (len < olen)
                                         continue;