Whamcloud - gitweb
LU-7174 build: add mmap_cat to .gitignore
[fs/lustre-release.git] / lustre / tests / ll_dirstripe_verify.c
index 0f85109..f3de1db 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <errno.h>
 #include <dirent.h>
 
-#include <liblustre.h>
-#include <obd.h>
-#include <lustre_lib.h>
-#include <lustre/liblustreapi.h>
-#include <obd_lov.h>
-
-#include <lnet/lnetctl.h>
-
+#include <lustre/lustreapi.h>
 
 #define MAX_LOV_UUID_COUNT      1000
 union {
@@ -74,32 +67,33 @@ union {
  */
 int read_proc_entry(char *proc_path, char *buf, int len)
 {
-        int rc, fd;
-
-        memset(buf, 0, len);
-
-        fd = open(proc_path, O_RDONLY);
-        if (fd == -1) {
-                llapi_error(LLAPI_MSG_ERROR, -errno, "open('%s') failed: %s\n",
-                            proc_path);
-                return -2;
-        }
-
-        rc = read(fd, buf, len - 1);
-        if (rc < 0) {
-                llapi_error(LLAPI_MSG_ERROR, -errno,
-                            "read('%s') failed: %s\n", proc_path);
-                rc = -3;
-        } else if (rc == 0) {
-                llapi_err_noerrno(LLAPI_MSG_ERROR,
-                                  "read('%s') zero bytes\n", proc_path);
-                rc = -4;
-        } else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
-                buf[rc - 1] = '\0'; /* Remove trailing newline */
-        }
-        close(fd);
-
-        return (rc);
+       int rc, fd;
+
+       memset(buf, 0, len);
+
+       fd = open(proc_path, O_RDONLY);
+       if (fd < 0) {
+               llapi_error(LLAPI_MSG_ERROR, -errno, "cannot open '%s'",
+                           proc_path);
+               return -2;
+       }
+
+       rc = read(fd, buf, len - 1);
+       if (rc < 0) {
+               llapi_error(LLAPI_MSG_ERROR, -errno,
+                           "error reading from '%s'", proc_path);
+               rc = -3;
+       } else if (rc == 0) {
+               llapi_err_noerrno(LLAPI_MSG_ERROR,
+                                 "read zero bytes from '%s'", proc_path);
+               rc = -4;
+       } else if (buf[rc - 1] == '\n') {
+               buf[rc - 1] = '\0'; /* Remove trailing newline */
+       }
+
+       close(fd);
+
+       return rc;
 }
 
 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
@@ -115,18 +109,20 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
         int i;
         FILE *fp;
 
-        fp = popen("\\ls -d  /proc/fs/lustre/lov/*clilov* | head -1", "r");
-        if (!fp) {
-                llapi_error(LLAPI_MSG_ERROR, -errno,
-                            "open(lustre/lov/*clilov*) failed: %s\n");
-                return 2;
-        }
-        if (fscanf(fp, "%s", lov_path) < 1) {
-                llapi_error(LLAPI_MSG_ERROR, -EINVAL,
-                            "read(lustre/lov/*clilov*) failed: %s\n");
-                pclose(fp);
-                return 3;
+       fp = popen("\\ls -d  /proc/fs/lustre/lov/*clilov* | head -1", "r");
+       if (fp == NULL) {
+               llapi_error(LLAPI_MSG_ERROR, -errno,
+                           "open(lustre/lov/*clilov*) failed");
+               return 2;
         }
+
+       if (fscanf(fp, "%s", lov_path) < 1) {
+               llapi_error(LLAPI_MSG_ERROR, -EINVAL,
+                           "read(lustre/lov/*clilov*) failed");
+               pclose(fp);
+               return 3;
+       }
+
         pclose(fp);
 
         snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
@@ -237,78 +233,80 @@ int main(int argc, char **argv)
                 return 1;
         }
 
-        dir = opendir(argv[1]);
-        if (dir == NULL) {
-                rc = -errno;
-                llapi_error(LLAPI_MSG_ERROR, rc,
-                            "error: %s opendir failed\n", argv[1]);
-                return rc;
-        }
-
-        lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC);
-        if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
-                rc = -ENOMEM;
-                llapi_error(LLAPI_MSG_ERROR, rc,
-                            "error: can't allocate %d bytes "
-                            "for dir EA", lum_size);
-                goto cleanup;
-        }
-
-        rc = llapi_file_get_stripe(argv[1], lum_dir);
-        if (rc) {
-                if (rc == -ENODATA) {
-                        free(lum_dir);
-                        lum_dir = NULL;
-                } else {
-                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                    "error: can't get EA for %s\n", argv[1]);
-                        goto cleanup;
-                }
-        }
-
-        /* XXX should be llapi_lov_getname() */
-        rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
-        if (rc) {
-                llapi_error(LLAPI_MSG_ERROR, rc,
-                            "error: can't get lov name for %s\n",
-                            argv[1]);
-                return rc;
-        }
-
-        if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
-                rc = -ENOMEM;
-                llapi_error(LLAPI_MSG_ERROR, rc,
-                            "error: can't allocate %d bytes for EA\n",
-                            lum_size);
-                goto cleanup;
-        }
-
-        rc = llapi_file_get_stripe(argv[2], lum_file1);
-        if (rc) {
-                llapi_error(LLAPI_MSG_ERROR, rc,
-                            "error: unable to get EA for %s\n", argv[2]);
-                goto cleanup;
-        }
-
-        if (argc == 4) {
-                lum_file2 = (struct lov_user_md *)malloc(lum_size);
-                if (lum_file2 == NULL) {
-                        rc = -ENOMEM;
-                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                    "error: can't allocate %d "
-                                    "bytes for file2 EA\n", lum_size);
-                        goto cleanup;
-                }
-
-                rc = llapi_file_get_stripe(argv[3], lum_file2);
-                if (rc) {
-                        llapi_error(LLAPI_MSG_ERROR, rc,
-                                    "error: can't get EA for %s\n", argv[3]);
-                        goto cleanup;
-                }
-        }
-
-        rc = compare(lum_dir, lum_file1, lum_file2);
+       dir = opendir(argv[1]);
+       if (dir == NULL) {
+               rc = -errno;
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "error: %s opendir failed", argv[1]);
+               return rc;
+       }
+
+       lum_size = lov_user_md_size(MAX_LOV_UUID_COUNT, LOV_USER_MAGIC);
+       lum_dir = (struct lov_user_md *)malloc(lum_size);
+       if (lum_dir == NULL) {
+               rc = -ENOMEM;
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "error: can't allocate %d bytes "
+                           "for dir EA", lum_size);
+               goto cleanup;
+       }
+
+       rc = llapi_file_get_stripe(argv[1], lum_dir);
+       if (rc) {
+               if (rc == -ENODATA) {
+                       free(lum_dir);
+                       lum_dir = NULL;
+               } else {
+                       llapi_error(LLAPI_MSG_ERROR, rc,
+                                   "error: can't get EA for %s", argv[1]);
+                       goto cleanup;
+               }
+       }
+
+       /* XXX should be llapi_lov_getname() */
+       rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
+       if (rc) {
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "error: can't get lov name for %s",
+                           argv[1]);
+               return rc;
+       }
+
+       lum_file1 = malloc(lum_size);
+       if (lum_file1 == NULL) {
+               rc = -ENOMEM;
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "error: can't allocate %d bytes for EA",
+                           lum_size);
+               goto cleanup;
+       }
+
+       rc = llapi_file_get_stripe(argv[2], lum_file1);
+       if (rc) {
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "error: unable to get EA for %s", argv[2]);
+               goto cleanup;
+       }
+
+       if (argc == 4) {
+               lum_file2 = (struct lov_user_md *)malloc(lum_size);
+               if (lum_file2 == NULL) {
+                       rc = -ENOMEM;
+                       llapi_error(LLAPI_MSG_ERROR, rc,
+                                   "error: can't allocate %d "
+                                   "bytes for file2 EA", lum_size);
+                       goto cleanup;
+               }
+
+               rc = llapi_file_get_stripe(argv[3], lum_file2);
+               if (rc) {
+                       llapi_error(LLAPI_MSG_ERROR, rc,
+                                   "error: can't get EA for %s", argv[3]);
+                       goto cleanup;
+               }
+       }
+
+       rc = compare(lum_dir, lum_file1, lum_file2);
 
 cleanup:
         closedir(dir);