#include <poll.h>
#include <libcfs/util/string.h>
-#include <libcfs/libcfs.h>
#include <lnet/lnetctl.h>
#include <lustre/lustreapi.h>
#include <lustre_ioctl.h>
lum_size = PATH_MAX + 1;
param->fp_lum_size = lum_size;
- param->fp_lmd = malloc(sizeof(lstat_t) + param->fp_lum_size);
+ param->fp_lmd = calloc(1, sizeof(lstat_t) + param->fp_lum_size);
if (param->fp_lmd == NULL) {
llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
"error: allocation of %zu bytes for ioctl",
}
param->fp_lmv_stripe_count = 256;
- param->fp_lmv_md = malloc(lmv_user_md_size(param->fp_lmv_stripe_count,
+ param->fp_lmv_md = calloc(1,
+ lmv_user_md_size(param->fp_lmv_stripe_count,
LMV_MAGIC_V1));
if (param->fp_lmv_md == NULL) {
llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
static int cb_get_dirstripe(char *path, DIR *d, struct find_param *param)
{
+ int ret;
+
+again:
param->fp_lmv_md->lum_stripe_count = param->fp_lmv_stripe_count;
if (param->fp_get_default_lmv)
param->fp_lmv_md->lum_magic = LMV_USER_MAGIC;
else
param->fp_lmv_md->lum_magic = LMV_MAGIC_V1;
- return ioctl(dirfd(d), LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);
+ ret = ioctl(dirfd(d), LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);
+ if (errno == E2BIG && ret != 0) {
+ int stripe_count;
+ int lmv_size;
+
+ stripe_count = (__u32)param->fp_lmv_md->lum_stripe_count;
+ if (stripe_count <= param->fp_lmv_stripe_count)
+ return ret;
+
+ free(param->fp_lmv_md);
+ param->fp_lmv_stripe_count = stripe_count;
+ lmv_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
+ param->fp_lmv_md = malloc(lmv_size);
+ if (param->fp_lmv_md == NULL) {
+ llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
+ "error: allocation of %d bytes for ioctl",
+ lmv_user_md_size(param->fp_lmv_stripe_count,
+ LMV_MAGIC_V1));
+ return -ENOMEM;
+ }
+ goto again;
+ }
+ return ret;
}
static int get_lmd_info(char *path, DIR *parent, DIR *dir,
if (decision == 0) {
ret = get_lmd_info(path, parent, dir, param->fp_lmd,
param->fp_lum_size);
+ if (ret == 0 && param->fp_lmd->lmd_lmm.lmm_magic == 0 &&
+ (param->fp_check_pool || param->fp_check_stripe_count ||
+ param->fp_check_stripe_size || param->fp_check_layout)) {
+ struct lov_user_md *lmm = ¶m->fp_lmd->lmd_lmm;
+
+ /* We need to "fake" the "use the default" values
+ * since the lmm struct is zeroed out at this point. */
+ lmm->lmm_magic = LOV_USER_MAGIC_V1;
+ lmm->lmm_pattern = 0xFFFFFFFF;
+ if (!param->fp_raw)
+ ostid_set_seq(&lmm->lmm_oi,
+ FID_SEQ_LOV_DEFAULT);
+ lmm->lmm_stripe_size = 0;
+ lmm->lmm_stripe_count = 0;
+ lmm->lmm_stripe_offset = -1;
+ }
if (ret == 0 && param->fp_mdt_uuid != NULL) {
if (dir != NULL) {
ret = llapi_file_fget_mdtidx(dirfd(dir),
return 0;
}
-static int cb_mv_init(char *path, DIR *parent, DIR **dirp,
+static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
void *param_data, struct dirent64 *de)
{
struct find_param *param = (struct find_param *)param_data;
ret = ioctl(fd, LL_IOC_MIGRATE, rawbuf);
if (ret != 0) {
ret = -errno;
- fprintf(stderr, "%s migrate failed %d\n", path, ret);
+ fprintf(stderr, "%s migrate failed: %s (%d)\n",
+ path, strerror(-ret), ret);
goto out;
} else if (param->fp_verbose & VERBOSE_DETAIL) {
fprintf(stdout, "migrate %s to MDT%d\n",
return ret;
}
+int llapi_migrate_mdt(char *path, struct find_param *param)
+{
+ return param_callback(path, cb_migrate_mdt_init, cb_common_fini, param);
+}
+
int llapi_mv(char *path, struct find_param *param)
{
- return param_callback(path, cb_mv_init, cb_common_fini, param);
+#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 53, 0)
+ static bool printed;
+
+ if (!printed) {
+ llapi_error(LLAPI_MSG_ERROR, -ESTALE,
+ "llapi_mv() is deprecated, use llapi_migrate_mdt()\n");
+ printed = true;
+ }
+#endif
+ return llapi_migrate_mdt(path, param);
}
int llapi_find(char *path, struct find_param *param)
return rc;
}
-static int cb_quotachown(char *path, DIR *parent, DIR **dirp, void *data,
- struct dirent64 *de)
-{
- struct find_param *param = (struct find_param *)data;
- DIR *d = dirp == NULL ? NULL : *dirp;
- lstat_t *st;
- int rc;
-
- LASSERT(parent != NULL || d != NULL);
-
- rc = get_lmd_info(path, parent, d, param->fp_lmd, param->fp_lum_size);
- if (rc) {
- if (rc == -ENODATA) {
- if (!param->fp_obd_uuid && !param->fp_quiet)
- llapi_error(LLAPI_MSG_ERROR, -ENODATA,
- "%s has no stripe info", path);
- rc = 0;
- } else if (rc == -ENOENT) {
- rc = 0;
- }
- return rc;
- }
-
- st = ¶m->fp_lmd->lmd_st;
-
- /* libc chown() will do extra check, and if the real owner is
- * the same as the ones to set, it won't fall into kernel, so
- * invoke syscall directly. */
- rc = syscall(SYS_chown, path, -1, -1);
- if (rc)
- llapi_error(LLAPI_MSG_ERROR, errno,
- "error: chown %s", path);
-
- rc = chmod(path, st->st_mode);
- if (rc) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: chmod %s (%hu)",
- path, st->st_mode);
- }
-
- return rc;
-}
-
-int llapi_quotachown(char *path, int flag)
-{
- struct find_param param;
-
- memset(¶m, 0, sizeof(param));
- param.fp_recursive = 1;
- param.fp_verbose = 0;
- param.fp_quiet = 1;
-
- return param_callback(path, cb_quotachown, NULL, ¶m);
-}
-
#include <pwd.h>
#include <grp.h>
#include <mntent.h>