Whamcloud - gitweb
LU-5456 hsm: hold inode mutex around ll_setattr_raw()
[fs/lustre-release.git] / lustre / liblustre / tests / sanity.c
index 070e3c6..21deed3 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -58,7 +58,7 @@
 
 #include <liblustre.h>
 #include "test_common.h"
-#include <lustre/liblustreapi.h>
+#include <lustre/lustreapi.h>
 
 #define _npages (2048)
 
@@ -396,7 +396,7 @@ int t14(char *name)
         char buf[1024];
         const int nfiles = 256;
         char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
-        cfs_dirent_t *ent;
+       struct dirent64 *ent;
         int fd, i, rc, pos, index;
         loff_t base = 0;
         ENTER(">1 block(4k) directory readdir");
@@ -428,12 +428,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);
@@ -578,7 +579,7 @@ static int check_file_size(char *file, long long size)
         }
         if (statbuf.st_size != size) {
                 printf("size of %s: %lld != %lld\n", file,
-                       (long long)statbuf.st_size, size);
+                       (long long)statbuf.st_size, (long long )size);
                 return(-1);
         }
         return 0;
@@ -613,7 +614,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);
 
@@ -706,8 +707,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);
         }
 
@@ -730,11 +732,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);
@@ -792,8 +794,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);
@@ -842,7 +844,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;
@@ -868,7 +870,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;
@@ -898,14 +900,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 < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
+               for (j = 0; j < PAGE_CACHE_SIZE/sizeof(int); j++, buf++) {
                         *buf = rand();
                 }
         }
 
         /* compute checksum */
         for (i = 0, buf = buf_alloc; i < _npages; i++) {
-                for (j = 0; j < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
+               for (j = 0; j < PAGE_CACHE_SIZE/sizeof(int); j++, buf++) {
                         check_sum[i] += *buf;
                 }
         }
@@ -923,9 +925,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 * CFS_PAGE_SIZE / sizeof(int)) {
-                rc = write(fd, buf, CFS_PAGE_SIZE * xfer);
-                if (rc != CFS_PAGE_SIZE * xfer) {
+            i += xfer, buf += xfer * PAGE_CACHE_SIZE / sizeof(int)) {
+               rc = write(fd, buf, PAGE_CACHE_SIZE * xfer);
+               if (rc != PAGE_CACHE_SIZE * xfer) {
                         printf("write error (i %d, rc %d): %s\n", i, rc,
                                strerror(errno));
                         return(1);
@@ -943,9 +945,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 * CFS_PAGE_SIZE / sizeof(int)) {
-                rc = read(fd, buf, CFS_PAGE_SIZE * xfer);
-                if (rc != CFS_PAGE_SIZE * xfer) {
+            i += xfer, buf += xfer * PAGE_CACHE_SIZE / sizeof(int)) {
+               rc = read(fd, buf, PAGE_CACHE_SIZE * xfer);
+               if (rc != PAGE_CACHE_SIZE * xfer) {
                         printf("read error (i %d, rc %d): %s\n", i, rc,
                                strerror(errno));
                         return(1);
@@ -956,7 +958,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 < CFS_PAGE_SIZE/sizeof(int); j++, buf++) {
+               for (j = 0; j < PAGE_CACHE_SIZE/sizeof(int); j++, buf++) {
                         sum += *buf;
                 }
                 if (sum != check_sum[i]) {
@@ -971,8 +973,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 * CFS_PAGE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
-                (_npages * CFS_PAGE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
+               (_npages * PAGE_CACHE_SIZE) / (tw / 1000000.0) / (1024 * 1024),
+               (_npages * PAGE_CACHE_SIZE) / (tr / 1000000.0) / (1024 * 1024));
 
         if (data_error)
                 return 1;
@@ -1092,8 +1094,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;
@@ -1249,21 +1257,23 @@ int t55(char *name)
         close(fd);
 
         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_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:      %#x\n", lo->l_ost_gen);
-                        printf("\tost_idx:      %u\n", lo->l_ost_idx);
-                }
+               printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);
+               printf("lmm_object_id:      "LPX64"\n",
+                                               lmm_oi_id(&lum->lmm_oi));
+               printf("lmm_object_seq:     "LPX64"\n",
+                                               lmm_oi_seq(&lum->lmm_oi));
+               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_oid:   "DOSTID"\n",
+                              POSTID(&lo->l_ost_oi));
+                       printf("\tost_gen:      %#x\n", lo->l_ost_gen);
+                       printf("\tost_idx:      %u\n", lo->l_ost_idx);
+               }
         }
 
         if (lum->lmm_magic != LOV_USER_MAGIC ||
@@ -1314,22 +1324,24 @@ int t55(char *name)
         }
         close(fd);
 
-        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_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:      %#x\n", lo->l_ost_gen);
-                        printf("\tost_idx:      %u\n", lo->l_ost_idx);
-                }
+       if (opt_verbose) {
+               printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);
+               printf("lmm_object_id:      "LPX64"\n",
+                                               lmm_oi_id(&lum->lmm_oi));
+               printf("lmm_object_seq:     "LPX64"\n",
+                                               lmm_oi_seq(&lum->lmm_oi));
+               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_oid:   "DOSTID"\n",
+                              POSTID(&lo->l_ost_oi));
+                       printf("\tost_gen:      %#x\n", lo->l_ost_gen);
+                       printf("\tost_idx:      %u\n", lo->l_ost_idx);
+               }
         }
 
         if (lum->lmm_magic != LOV_USER_MAGIC ||
@@ -1357,11 +1369,11 @@ int t55(char *name)
  */
 int t56(char *name)
 {
-        int fd;
-        size_t nbytes;
-        off_t basep = 0;
-        ssize_t rc = 0;
-        cfs_dirent_t dir;
+       int fd;
+       size_t nbytes;
+       off_t basep = 0;
+       long rc = 0;
+       struct dirent64 dir;
 
         ENTER("getdirentries should fail if nbytes is too small");
 
@@ -1495,7 +1507,7 @@ int main(int argc, char * const argv[])
 
         __liblustre_setup_();
 
-        buf_size = _npages * CFS_PAGE_SIZE;
+       buf_size = _npages * PAGE_CACHE_SIZE;
         if (opt_verbose)
                 printf("allocating %d bytes buffer\n", buf_size);
         buf_alloc = calloc(1, buf_size);