#include <sys/types.h>
#include <libcfs/util/string.h>
-#include <lustre/lustre_fid.h>
+#include <linux/lustre/lustre_fid.h>
#include <lustre/lustreapi.h>
/* Progress reporting period */
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;
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;
}
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];
DIR *dir;
int rc;
__u16 sub_seq;
- struct dirent ent, *cookie = NULL;
+ struct dirent *ent;
*sub_seqmax = 0;
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;