From 7474855fc389247c7422d0cdaf39bb2dbce267f8 Mon Sep 17 00:00:00 2001 From: Bruno Faccini Date: Mon, 6 Jan 2014 10:25:47 +0100 Subject: [PATCH] LU-4293 mdd: Allow layout swap for IGIF FIDs Patch to also allow layout swap for pre-2.x migrated files (ie, IGIF FID with linkEA). Root user special case has also been added to lfs/migrate command to map owner/group of original file to volatile, in order to comply with other layout_swap rules. Lustre-commit: bd5ba50502bec5786c9a2f05c29f7b99a35147fb Lustre-change: http://review.whamcloud.com/8737 Signed-off-by: Bruno Faccini Signed-off-by: Bob Glossman Change-Id: Iad6194c6050fa2ba066d2051871a10a60ddae995 Reviewed-on: http://review.whamcloud.com/9278 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo --- lustre/mdd/mdd_object.c | 19 ++++++++++++++++--- lustre/utils/lfs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 229c128..a3bb4d8 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1273,6 +1273,7 @@ static int mdd_xattr_hsm_replace(const struct lu_env *env, /* * check if layout swapping between 2 objects is allowed * the rules are: + * - only normal FIDs or non-system IGIFs * - same type of objects * - same owner/group (so quotas are still valid) */ @@ -1289,9 +1290,21 @@ static int mdd_layout_swap_allowed(const struct lu_env *env, fid1 = mdo2fid(o1); fid2 = mdo2fid(o2); - if (!fid_is_norm(fid1) || !fid_is_norm(fid2) || - (mdd_object_type(o1) != mdd_object_type(o2))) - RETURN(-EPERM); + if (!fid_is_norm(fid1) && + (!fid_is_igif(fid1) || IS_ERR(mdd_links_get(env, o1)))) + RETURN(-EBADF); + + if (!fid_is_norm(fid2) && + (!fid_is_igif(fid2) || IS_ERR(mdd_links_get(env, o2)))) + RETURN(-EBADF); + + if (mdd_object_type(o1) != mdd_object_type(o2)) { + if (S_ISDIR(mdd_object_type(o1))) + RETURN(-ENOTDIR); + if (S_ISREG(mdd_object_type(o1))) + RETURN(-EISDIR); + RETURN(-EBADF); + } tmp_la->la_valid = 0; rc = mdd_la_get(env, o1, tmp_la, BYPASS_CAPA); diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 8370aa0..09d6c91 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -363,6 +363,7 @@ static int lfs_migrate(char *name, unsigned long long stripe_size, __u64 rpos, wpos, bufoff; int gid = 0, sz; int have_gl = 0; + struct stat st, stv; /* find the right size for the IO and allocate the buffer */ lumsz = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3); @@ -451,6 +452,34 @@ static int lfs_migrate(char *name, unsigned long long stripe_size, goto free; } + /* Not-owner (root?) special case. + * Need to set owner/group of volatile file like original. + * This will allow to pass related check during layout_swap. + */ + rc = fstat(fd, &st); + if (rc != 0) { + rc = -errno; + fprintf(stderr, "cannot stat %s (%s)\n", name, + strerror(errno)); + goto error; + } + rc = fstat(fdv, &stv); + if (rc != 0) { + rc = -errno; + fprintf(stderr, "cannot stat %s (%s)\n", volatile_file, + strerror(errno)); + goto error; + } + if (st.st_uid != stv.st_uid || st.st_gid != stv.st_gid) { + rc = fchown(fdv, st.st_uid, st.st_gid); + if (rc != 0) { + rc = -errno; + fprintf(stderr, "cannot chown %s (%s)\n", name, + strerror(errno)); + goto error; + } + } + /* get file data version */ rc = llapi_get_data_version(fd, &dv1, LL_DV_RD_FLUSH); if (rc != 0) { -- 1.8.3.1