Whamcloud - gitweb
LU-6179 llite: Implement ladvise lockahead
[fs/lustre-release.git] / lustre / utils / lhsmtool_posix.c
index d99fce3..804dbe7 100644 (file)
@@ -23,7 +23,7 @@
  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
  *     alternatives
  *
- * Copyright (c) 2013, 2015, Intel Corporation.
+ * Copyright (c) 2013, 2016, Intel Corporation.
  */
 /* HSM copytool program for POSIX filesystem-based HSM's.
  *
@@ -57,7 +57,7 @@
 #include <sys/types.h>
 
 #include <libcfs/util/string.h>
-#include <lustre/lustre_idl.h>
+#include <linux/lustre/lustre_fid.h>
 #include <lustre/lustreapi.h>
 
 /* Progress reporting period */
@@ -210,35 +210,46 @@ static void usage(const char *name, int rc)
 static int ct_parseopts(int argc, char * const *argv)
 {
        struct option long_opts[] = {
-               {"abort-on-error", no_argument,       &opt.o_abort_on_error, 1},
-               {"abort_on_error", no_argument,       &opt.o_abort_on_error, 1},
-               {"archive",        required_argument, NULL,                'A'},
-               {"bandwidth",      required_argument, NULL,                'b'},
-               {"chunk-size",     required_argument, NULL,                'c'},
-               {"chunk_size",     required_argument, NULL,                'c'},
-               {"daemon",         no_argument,       &opt.o_daemonize,     1},
-               {"event-fifo",     required_argument, NULL,                'f'},
-               {"event_fifo",     required_argument, NULL,                'f'},
-               {"dry-run",        no_argument,       &opt.o_dry_run,       1},
-               {"help",           no_argument,       NULL,                'h'},
-               {"hsm-root",       required_argument, NULL,                'p'},
-               {"hsm_root",       required_argument, NULL,                'p'},
-               {"import",         no_argument,       NULL,                'i'},
-               {"max-sequence",   no_argument,       NULL,                'M'},
-               {"max_sequence",   no_argument,       NULL,                'M'},
-               {"no-attr",        no_argument,       &opt.o_copy_attrs,    0},
-               {"no_attr",        no_argument,       &opt.o_copy_attrs,    0},
-               {"no-shadow",      no_argument,       &opt.o_shadow_tree,   0},
-               {"no_shadow",      no_argument,       &opt.o_shadow_tree,   0},
-               {"no-xattr",       no_argument,       &opt.o_copy_xattrs,   0},
-               {"no_xattr",       no_argument,       &opt.o_copy_xattrs,   0},
-               {"quiet",          no_argument,       NULL,                'q'},
-               {"rebind",         no_argument,       NULL,                'r'},
-               {"update-interval", required_argument,  NULL,              'u'},
-               {"update_interval", required_argument,  NULL,              'u'},
-               {"verbose",        no_argument,       NULL,                'v'},
-               {0, 0, 0, 0}
-       };
+       { .val = 1,     .name = "abort-on-error",
+         .flag = &opt.o_abort_on_error,        .has_arg = no_argument },
+       { .val = 1,     .name = "abort_on_error",
+         .flag = &opt.o_abort_on_error,        .has_arg = no_argument },
+       { .val = 'A',   .name = "archive",      .has_arg = required_argument },
+       { .val = 'b',   .name = "bandwidth",    .has_arg = required_argument },
+       { .val = 'c',   .name = "chunk-size",   .has_arg = required_argument },
+       { .val = 'c',   .name = "chunk_size",   .has_arg = required_argument },
+       { .val = 1,     .name = "daemon",       .has_arg = no_argument,
+         .flag = &opt.o_daemonize },
+       { .val = 'f',   .name = "event-fifo",   .has_arg = required_argument },
+       { .val = 'f',   .name = "event_fifo",   .has_arg = required_argument },
+       { .val = 1,     .name = "dry-run",      .has_arg = no_argument,
+         .flag = &opt.o_dry_run },
+       { .val = 'h',   .name = "help",         .has_arg = no_argument },
+       { .val = 'i',   .name = "import",       .has_arg = no_argument },
+       { .val = 'M',   .name = "max-sequence", .has_arg = no_argument },
+       { .val = 'M',   .name = "max_sequence", .has_arg = no_argument },
+       { .val = 0,     .name = "no-attr",      .has_arg = no_argument,
+         .flag = &opt.o_copy_attrs },
+       { .val = 0,     .name = "no_attr",      .has_arg = no_argument,
+         .flag = &opt.o_copy_attrs },
+       { .val = 0,     .name = "no-shadow",    .has_arg = no_argument,
+         .flag = &opt.o_shadow_tree },
+       { .val = 0,     .name = "no_shadow",    .has_arg = no_argument,
+         .flag = &opt.o_shadow_tree },
+       { .val = 0,     .name = "no-xattr",     .has_arg = no_argument,
+         .flag = &opt.o_copy_xattrs },
+       { .val = 0,     .name = "no_xattr",     .has_arg = no_argument,
+         .flag = &opt.o_copy_xattrs },
+       { .val = 'p',   .name = "hsm-root",     .has_arg = required_argument },
+       { .val = 'p',   .name = "hsm_root",     .has_arg = required_argument },
+       { .val = 'q',   .name = "quiet",        .has_arg = no_argument },
+       { .val = 'r',   .name = "rebind",       .has_arg = no_argument },
+       { .val = 'u',   .name = "update-interval",
+                                               .has_arg = required_argument },
+       { .val = 'u',   .name = "update_interval",
+                                               .has_arg = required_argument },
+       { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .name = NULL } };
        int                      c, rc;
        unsigned long long       value;
        unsigned long long       unit;
@@ -1467,7 +1478,7 @@ static int ct_import_fid(const lustre_fid *import_fid)
 static int ct_import_recurse(const char *relpath)
 {
        DIR             *dir;
-       struct dirent    ent, *cookie = NULL;
+       struct dirent   *ent;
        char            *srcpath, *newpath;
        lustre_fid       import_fid;
        int              rc;
@@ -1504,31 +1515,20 @@ static int ct_import_recurse(const char *relpath)
        }
        free(srcpath);
 
-       while (1) {
-               rc = readdir_r(dir, &ent, &cookie);
-               if (rc != 0) {
-                       rc = -errno;
-                       CT_ERROR(rc, "cannot readdir_r '%s'", relpath);
-                       err_major++;
-                       goto out;
-               } else if ((rc == 0) && (cookie == NULL)) {
-                       /* end of directory */
-                       break;
-               }
-
-               if (!strcmp(ent.d_name, ".") ||
-                   !strcmp(ent.d_name, ".."))
+       while ((ent = readdir(dir)) != NULL) {
+               if (!strcmp(ent->d_name, ".") ||
+                   !strcmp(ent->d_name, ".."))
                        continue;
 
                /* New relative path */
-               newpath = path_concat(relpath, ent.d_name);
+               newpath = path_concat(relpath, ent->d_name);
                if (newpath == NULL) {
                        err_major++;
                        rc = -ENOMEM;
                        goto out;
                }
 
-               if (ent.d_type == DT_DIR) {
+               if (ent->d_type == DT_DIR) {
                        rc = ct_import_recurse(newpath);
                } else {
                        char src[PATH_MAX];
@@ -1705,7 +1705,7 @@ static int ct_dir_level_max(const char *dirpath, __u16 *sub_seqmax)
        DIR             *dir;
        int              rc;
        __u16            sub_seq;
-       struct dirent    ent, *cookie = NULL;
+       struct dirent *ent;
 
        *sub_seqmax = 0;
 
@@ -1716,26 +1716,29 @@ static int ct_dir_level_max(const char *dirpath, __u16 *sub_seqmax)
                return rc;
        }
 
-       while ((rc = readdir_r(dir, &ent, &cookie)) == 0) {
-               if (cookie == NULL)
+       do {
+               errno = 0;
+               ent = readdir(dir);
+               if (ent == NULL) {
                        /* end of directory.
                         * rc is 0 and seqmax contains the max value. */
+                       rc = -errno;
+                       if (rc)
+                               CT_ERROR(rc, "cannot readdir '%s'", dirpath);
                        goto out;
+               }
 
-               if (!strcmp(ent.d_name, ".") || !strcmp(ent.d_name, ".."))
+               if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
                        continue;
 
-               if (sscanf(ent.d_name, "%hx", &sub_seq) != 1) {
+               if (sscanf(ent->d_name, "%hx", &sub_seq) != 1) {
                        CT_TRACE("'%s' has an unexpected dirname format, "
-                                "skip entry", ent.d_name);
+                                "skip entry", ent->d_name);
                        continue;
                }
                if (sub_seq > *sub_seqmax)
                        *sub_seqmax = sub_seq;
-       }
-       rc = -errno;
-       CT_ERROR(rc, "cannot readdir_r '%s'", dirpath);
-
+       } while (1);
 out:
        closedir(dir);
        return rc;