Whamcloud - gitweb
LU-4017 quota: add project inherit attributes
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index 1bb8fa3..2876e6e 100644 (file)
@@ -674,10 +674,13 @@ int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
        if (rc == sizeof(*ff)) {
                rc = 0;
                ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
-               ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
-               /* XXX: use 0 as the index for compatibility, the caller will
-                *      handle index related issues when necessarry. */
-               ostid_to_fid(fid, ostid, 0);
+               rc = ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
+               /*
+                * XXX: use 0 as the index for compatibility, the caller will
+                *      handle index related issues when necessary.
+                */
+               if (!rc)
+                       ostid_to_fid(fid, ostid, 0);
        } else if (rc == sizeof(struct filter_fid)) {
                rc = 1;
        } else if (rc >= 0) {
@@ -750,7 +753,8 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
                rc = 0;
                lustre_lma_swab(lma);
                if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
-                            CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
+                            (CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT) &&
+                             S_ISREG(inode->i_mode)))) {
                        CWARN("%s: unsupported incompat LMA feature(s) %#x for "
                              "fid = "DFID", ino = %lu\n", osd_name(osd),
                              lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
@@ -1955,6 +1959,9 @@ static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
 
                        qi->lqi_id.qid_uid = gid;
                        qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
+
+                       qi->lqi_id.qid_uid = i_projid_read(inode);
+                       qsd_op_adjust(env, qsd, &qi->lqi_id, PRJQUOTA);
                }
         }
 }
@@ -2375,6 +2382,13 @@ static void osd_inode_getattr(const struct lu_env *env,
        attr->la_rdev    = inode->i_rdev;
        attr->la_blksize = 1 << inode->i_blkbits;
        attr->la_blkbits = inode->i_blkbits;
+       /*
+        * Ext4 did not transfer inherit flags from raw inode
+        * to inode flags, and ext4 internally test raw inode
+        * @i_flags directly. Instead of patching ext4, we do it here.
+        */
+       if (LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL)
+               attr->la_flags |= LUSTRE_PROJINHERIT_FL;
 }
 
 static int osd_attr_get(const struct lu_env *env,
@@ -2579,6 +2593,13 @@ static int osd_inode_setattr(const struct lu_env *env,
                /* always keep S_NOCMTIME */
                inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
                                 S_NOCMTIME;
+               /*
+                * Ext4 did not transfer inherit flags from
+                * @inode->i_flags to raw inode i_flags when writing
+                * flags, we do it explictly here.
+                */
+               if (attr->la_flags & LUSTRE_PROJINHERIT_FL)
+                       LDISKFS_I(inode)->i_flags |= LUSTRE_PROJINHERIT_FL;
        }
        return 0;
 }
@@ -2610,7 +2631,7 @@ static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
        }
 
 #ifdef HAVE_PROJECT_QUOTA
-       /* Handle project id Transfer here properly */
+       /* Handle project id transfer here properly */
        if (attr->la_valid & LA_PROJID && attr->la_projid !=
                                                i_projid_read(inode)) {
                rc = __ldiskfs_ioctl_setproject(inode, attr->la_projid);
@@ -3449,6 +3470,19 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
        ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
        unlock_new_inode(local);
 
+       /* Agent inode should not have project ID*/
+#ifdef HAVE_PROJECT_QUOTA
+       if (LDISKFS_I(pobj->oo_inode)->i_flags & LUSTRE_PROJINHERIT_FL) {
+               rc = __ldiskfs_ioctl_setproject(local, 0);
+               if (rc) {
+                       CERROR("%s: quota transfer failed: rc = %d. Is project "
+                              "quota enforcement enabled on the ldiskfs "
+                              "filesystem?\n", local->i_sb->s_id, rc);
+                       RETURN(ERR_PTR(rc));
+               }
+       }
+
+#endif
        /* Set special LMA flag for local agent inode */
        rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
        if (rc != 0) {
@@ -4352,10 +4386,6 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
         }
         LINVRNT(osd_invariant(obj));
 
-       if (result == 0 && feat == &dt_quota_glb_features &&
-           fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
-               result = osd_quota_migration(env, dt);
-
         return result;
 }