#include <linux/lustre/lustre_ver.h>
#include <linux/lustre/lustre_param.h>
#include <linux/lnet/nidstr.h>
-#include <cyaml.h>
+#include <lnetconfig/cyaml.h>
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
"\tstripe_count: stripe count of the striped directory\n" \
"\tmdt_index: MDT index of first stripe\n" \
"\tmdt_hash: hash type of the striped directory. mdt types:\n" \
- " fnv_1a_64 FNV-1a hash algorithm (default)\n" \
+ " crush CRUSH hash algorithm (default)\n" \
+ " fnv_1a_64 FNV-1a hash algorithm\n" \
" all_char sum of characters % MDT_COUNT (not recommended)\n" \
- " space create subdirectories with balanced space usage\n" \
"\tdefault_stripe: set default dirstripe of the directory\n" \
"\tmode: the file access permission of the directory (octal)\n" \
"To create dir with a foreign (free format) layout :\n" \
"setdirstripe|mkdir --foreign[=<foreign_type>] -x|-xattr <string> " \
- "[--mode|-m mode] [--flags <hex>] <dir>\n" \
+ "[--mode|-o mode] [--flags <hex>] <dir>\n" \
"\tmode: the mode of the directory\n" \
"\tforeign_type: none or daos\n"
" it's the MDT index of first stripe\n"
"\tmdt_count: number of MDTs to stripe a directory over\n"
"\tmdt_hash: hash type of the striped directory. mdt types:\n"
- " fnv_1a_64 FNV-1a hash algorithm (default)\n"
+ " crush CRUSH hash algorithm (default)\n"
+ " fnv_1a_64 FNV-1a hash algorithm\n"
" all_char sum of characters % MDT_COUNT\n"
"\n"
"migrate file objects from one OST "
}
/* create, open a volatile file, use caching (ie no directio) */
- if (param != NULL)
- fdv = llapi_file_open_param(volatile_file, open_flags,
- open_mode, param);
- else
+ if (layout)
fdv = lfs_component_create(volatile_file, open_flags,
open_mode, layout);
+ else
+ fdv = llapi_file_open_param(volatile_file, open_flags,
+ open_mode, param);
} while (fdv < 0 && (rc = fdv) == -EEXIST);
if (rc < 0) {
goto usage_error;
}
+ /* lfs migrate $filename should keep the file's layout by default */
+ if (migrate_mode && !setstripe_args_specified(&lsa) && !layout &&
+ !from_yaml)
+ from_copy = true;
+
if (xattr && !foreign_mode) {
/* only print a warning as this is harmless and will be ignored
*/
if ((from_yaml || from_copy) &&
(setstripe_args_specified(&lsa) || layout != NULL)) {
- fprintf(stderr, "error: %s: can't specify --yaml with "
- "-c, -S, -i, -o, -p or -E options.\n",
+ fprintf(stderr, "error: %s: can't specify --yaml or --copy with"
+ " -c, -S, -i, -o, -p or -E options.\n",
argv[0]);
goto error;
}
if (lsa.lsa_pattern != LLAPI_LAYOUT_RAID0)
lmu->lum_hash_type = lsa.lsa_pattern;
else
- lmu->lum_hash_type = LMV_HASH_TYPE_DEFAULT;
+ lmu->lum_hash_type = LMV_HASH_TYPE_UNKNOWN;
if (lsa.lsa_pool_name) {
strncpy(lmu->lum_pool_name, lsa.lsa_pool_name,
sizeof(lmu->lum_pool_name) - 1);
argv[0], template);
goto error;
}
- } else if (from_copy) {
- layout = llapi_layout_get_by_path(template, 0);
- if (layout == NULL) {
- fprintf(stderr,
- "%s: can't create composite layout from file %s.\n",
- progname, template);
- goto error;
- }
}
for (fname = argv[optind]; fname != NULL; fname = argv[++optind]) {
+ if (from_copy) {
+ layout = llapi_layout_get_by_path(template ?: fname, 0);
+ if (layout == NULL) {
+ fprintf(stderr, "%s: can't create composite "
+ "layout from file %s.\n",
+ progname, template ?: fname);
+ goto error;
+ }
+ }
+
if (migrate_mdt_mode) {
result = llapi_migrate_mdt(fname, &migrate_mdt_param);
} else if (migrate_mode) {
if (lsa.lsa_pattern != LLAPI_LAYOUT_RAID0)
param->lsp_stripe_pattern = lsa.lsa_pattern;
else
- param->lsp_stripe_pattern = LMV_HASH_TYPE_DEFAULT;
+ param->lsp_stripe_pattern = LMV_HASH_TYPE_UNKNOWN;
param->lsp_pool = lsa.lsa_pool_name;
param->lsp_is_specific = false;
if (lsa.lsa_nr_tgts > 1) {
return CMD_HELP;
}
+ lmu.lum_hash_type = LMV_HASH_TYPE_UNKNOWN;
/* initialize migrate mdt parameters */
param.fp_lmv_md = &lmu;
rc = llapi_migrate_mdt(argv[optind], ¶m);
if (rc != 0)
fprintf(stderr, "%s mv: cannot migrate '%s' to MDT%04x: %s\n",
- progname, argv[optind], param.fp_mdt_index,
+ progname, argv[optind], lmu.lum_stripe_offset,
strerror(-rc));
return rc;
}
* \retval 1 not the same file
* \retval <0 error code
*/
-static inline int check_same_file(const char *f1, const char *f2)
+static inline int check_same_file(int fd, const char *f2)
{
struct stat stbuf1;
struct stat stbuf2;
- if (stat(f1, &stbuf1) < 0) {
- fprintf(stderr, "%s: cannot stat file '%s': %s\n",
- progname, f1, strerror(errno));
+ if (fstat(fd, &stbuf1) < 0)
return -errno;
- }
- if (stat(f2, &stbuf2) < 0) {
- fprintf(stderr, "%s: cannot stat file '%s': %s\n",
- progname, f2, strerror(errno));
- return -errno;
- }
+ if (stat(f2, &stbuf2) < 0)
+ return 1;
if (stbuf1.st_rdev == stbuf2.st_rdev &&
stbuf1.st_ino == stbuf2.st_ino)
/* open mirror file */
fname = argv[optind];
-
- if (outfile) {
- rc = check_same_file(fname, outfile);
- if (rc == 0) {
- fprintf(stderr,
- "%s %s: output file cannot be the mirrored file\n",
- progname, argv[0]);
- return -EINVAL;
- }
- if (rc < 0)
- return rc;
- }
-
fd = open(fname, O_DIRECT | O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s %s: cannot open '%s': %s\n",
goto close_fd;
}
- /* open output file */
+ /* open output file - O_EXCL ensures output is not the same as input */
if (outfile) {
outfd = open(outfile, O_EXCL | O_WRONLY | O_CREAT, 0644);
if (outfd < 0) {
/* open mirror file */
fname = argv[optind];
-
- if (inputfile) {
- rc = check_same_file(fname, inputfile);
- if (rc == 0) {
- fprintf(stderr,
- "%s %s: input file cannot be the mirrored file\n",
- progname, argv[0]);
- return -EINVAL;
- }
- if (rc < 0)
- return rc;
- }
-
fd = open(fname, O_DIRECT | O_WRONLY);
if (fd < 0) {
fprintf(stderr, "%s %s: cannot open '%s': %s\n",
/* open input file */
if (inputfile) {
+ rc = check_same_file(fd, inputfile);
+ if (rc == 0) {
+ fprintf(stderr,
+ "%s %s: input file cannot be the mirrored file\n",
+ progname, argv[0]);
+ goto close_fd;
+ }
+ if (rc < 0)
+ goto close_fd;
+
inputfd = open(inputfile, O_RDONLY, 0644);
if (inputfd < 0) {
fprintf(stderr, "%s %s: cannot open file '%s': %s\n",