Whamcloud - gitweb
LU-2100 ofd: small batched precreation on a small system
[fs/lustre-release.git] / lustre / liblustre / tests / sanity.c
index bcf7056..dc41d06 100644 (file)
@@ -1,24 +1,39 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- * Lustre Light user test program
+ * 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 (c) 2003, 2010, Oracle and/or its affiliates. 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
@@ -41,7 +56,7 @@
 
 #include <liblustre.h>
 #include "test_common.h"
-#include <lustre/liblustreapi.h>
+#include <lustre/lustreapi.h>
 
 #define _npages (2048)
 
@@ -56,7 +71,9 @@ extern char *lustre_path;
         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);                  \
@@ -64,7 +81,6 @@ extern char *lustre_path;
                         buf[80] = 0;                                    \
                 }                                                       \
                 printf("%s", buf);                                      \
-                gettimeofday(&start, NULL);                             \
         } while (0)
 
 #define LEAVE()                                                         \
@@ -410,12 +426,13 @@ int t14(char *name)
                                 printf("found bad name %s\n", item);
                                 return(-1);
                         }
-                        printf("[%03d]: %s\n",
+                        printf("[%03d]: %s\t",
                                 index++, item + strlen(prefix));
 iter:
                         pos += ent->d_reclen;
                 }
         }
+        printf("\n");
         if (rc < 0) {
                 printf("getdents error %d\n", rc);
                 return(-1);
@@ -559,7 +576,8 @@ static int check_file_size(char *file, long long size)
                 return(1);
         }
         if (statbuf.st_size != size) {
-                printf("size of %s: %ld != %lld\n", file, statbuf.st_size, size);
+                printf("size of %s: %lld != %lld\n", file,
+                       (long long)statbuf.st_size, (long long )size);
                 return(-1);
         }
         return 0;
@@ -594,7 +612,7 @@ int t20(char *name)
         int fd;
         struct iovec iov[2];
         char buf[100];
-        ssize_t ret;
+        long ret;
         ENTER("trap app's general bad pointer for file i/o");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
 
@@ -606,12 +624,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;
@@ -620,7 +638,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;
@@ -629,19 +647,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;
@@ -650,7 +668,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;
@@ -659,7 +677,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);
         }
 
@@ -687,8 +705,9 @@ int t21(char *name)
         }
 
         t_fcntl(fd, F_SETFL, O_APPEND);
-        if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
-                printf("error get flag: ret %x\n", ret);
+        ret = t_fcntl(fd, F_GETFL);
+        if ((ret & O_APPEND) == 0) {
+                printf("error get flag: ret %o\n", ret);
                 return(-1);
         }
 
@@ -711,11 +730,11 @@ int t22(char *name)
         int fd;
         char *str = "1234567890";
         char buf[100];
-        ssize_t ret;
+        long ret;
         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);
+        fd = open(file, O_TRUNC|O_RDWR|O_CREAT|O_APPEND, (mode_t)0666);
         if (fd < 0) {
                 printf("error open file: %s\n", strerror(errno));
                 return(-1);
@@ -724,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);
         }
 
@@ -748,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);
         }
 
@@ -773,8 +792,8 @@ int t23(char *name)
 {
         char path[MAX_PATH_LENGTH];
         int fd;
-        off_t ret;
-        off_t off;
+        long long ret;
+        loff_t off;
 
         ENTER("handle seek > 2GB");
         snprintf(path, MAX_PATH_LENGTH, "%s/f%s", lustre_path, name);
@@ -823,7 +842,7 @@ int t23(char *name)
         ret = lseek(fd, -buf_size + 2, SEEK_CUR);
         if (ret != off) {
                 printf("relative seek error for %d %llu != %llu\n",
-                       -buf_size + 2, ret, off);
+                       -buf_size + 2, ret, (unsigned long long) off);
                 if (ret == -1)
                         perror("relative seek");
                 return -1;
@@ -849,7 +868,7 @@ int t23(char *name)
         off = 2048ULL * 1024 * 1024, SEEK_SET;
         ret = lseek(fd, off, SEEK_SET);
         if (ret != off) {
-                printf("seek 2GB error for %llu != %llu\n", ret, off);
+                printf("seek 2GB error for %llu != %llu\n", ret, (unsigned long long) off);
                 if (ret == -1)
                         perror("seek 2GB");
                 return -1;
@@ -1073,8 +1092,14 @@ int t52(char *name)
         printf("st_atime=%s", ctime(&statbuf.st_atime));
         atime = statbuf.st_atime;
         for (i = 0; i < 3; i++) {
+                ssize_t num_read;
                 sleep(2);
-                read(fd, buf, sizeof(buf));
+                /* should not ignore read(2)'s return value */
+                num_read = read(fd, buf, sizeof(buf));
+                if (num_read < 0 ) {
+                        printf("read from %s: %s\n", file, strerror(errno));
+                        return -1;
+                }
                 stat(file, &statbuf);
                 printf("st_atime=%s", ctime(&statbuf.st_atime));
                 diff = statbuf.st_atime - atime;
@@ -1083,8 +1108,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);
@@ -1098,26 +1123,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;
+
         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();
@@ -1125,7 +1150,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);
 }
@@ -1151,7 +1176,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);
@@ -1184,7 +1209,7 @@ int t55(char *name)
         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);
@@ -1213,7 +1238,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);
@@ -1232,15 +1257,15 @@ int t55(char *name)
         if (opt_verbose) {
                 printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);
                 printf("lmm_object_id:      "LPX64"\n", lum->lmm_object_id);
-                printf("lmm_object_gr:      "LPX64"\n", lum->lmm_object_gr);
+                printf("lmm_object_seq:     "LPX64"\n", lum->lmm_object_seq);
                 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_seq:   "LPX64"\n", lo->l_object_seq);
                         printf("\tobject_id:    "LPX64"\n", lo->l_object_id);
                         printf("\tost_gen:      %#x\n", lo->l_ost_gen);
                         printf("\tost_idx:      %u\n", lo->l_ost_idx);
@@ -1273,7 +1298,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);
@@ -1298,15 +1323,15 @@ int t55(char *name)
         if (opt_verbose) {
                 printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);
                 printf("lmm_object_id:      "LPX64"\n", lum->lmm_object_id);
-                printf("lmm_object_gr:      "LPX64"\n", lum->lmm_object_gr);
+                printf("lmm_object_seq:     "LPX64"\n", lum->lmm_object_seq);
                 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_seq:   "LPX64"\n", lo->l_object_seq);
                         printf("\tobject_id:    "LPX64"\n", lo->l_object_id);
                         printf("\tost_gen:      %#x\n", lo->l_ost_gen);
                         printf("\tost_idx:      %u\n", lo->l_ost_idx);
@@ -1341,7 +1366,7 @@ int t56(char *name)
         int fd;
         size_t nbytes;
         off_t basep = 0;
-        ssize_t rc = 0;
+        long rc = 0;
         cfs_dirent_t dir;
 
         ENTER("getdirentries should fail if nbytes is too small");
@@ -1355,13 +1380,14 @@ int t56(char *name)
         rc = getdirentries(fd, (char *)&dir, nbytes, &basep);
 
         if (rc != -1) {
-                printf("Test failed: getdirentries returned %ld\n", rc);
+                printf("Test failed: getdirentries returned %lld\n",
+                       (long long)rc);
                 t_close(fd);
                 return -1;
         }
         if (errno != EINVAL) {
-                printf("Test failed: getdirentries returned %ld but errno is set"
-                                " to %d (should be EINVAL)\n", rc, errno);
+                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;
         }