Whamcloud - gitweb
LU-4293 mdd: Allow layout swap for IGIF FIDs 37/8737/9
authorBruno Faccini <bruno.faccini@intel.com>
Mon, 6 Jan 2014 09:25:47 +0000 (10:25 +0100)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 19 Feb 2014 00:09:43 +0000 (00:09 +0000)
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.

Signed-off-by: Bruno Faccini <bruno.faccini@intel.com>
Change-Id: Ia7e7cb2e6e36ba67a57474b8a806a53257a3e014
Reviewed-on: http://review.whamcloud.com/8737
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
lustre/mdd/mdd_object.c
lustre/utils/lfs.c

index c030dfa..a959dea 100644 (file)
@@ -1254,6 +1254,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)
  */
@@ -1269,9 +1270,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);
+       }
 
        if ((attr1->la_uid != attr2->la_uid) ||
            (attr1->la_gid != attr2->la_gid))
index 60e3de1..f1021a3 100644 (file)
@@ -349,6 +349,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);
@@ -437,6 +438,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) {