Whamcloud - gitweb
LU-1842 iam: store key & rec in LE order for quota IAM files
authorNiu Yawei <niu@whamcloud.com>
Fri, 14 Sep 2012 07:32:05 +0000 (03:32 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 20 Sep 2012 04:01:17 +0000 (00:01 -0400)
Store quota keys and records in little endian format in iam index
files.

Signed-off-by: Johann Lombardi <johann@whamcloud.com>
Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: I391fb9c0b8ff67c3cc5f51abd31a0dbf92d7276c
Reviewed-on: http://review.whamcloud.com/3989
Tested-by: Hudson
Reviewed-by: Fan Yong <yong.fan@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/include/lustre_fid.h
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_quota.c

index bb664b2..56e2186 100644 (file)
@@ -143,6 +143,12 @@ static inline int fid_is_acct(const struct lu_fid *fid)
                 fid_oid(fid) == ACCT_GROUP_OID);
 }
 
+static inline int fid_is_quota(const struct lu_fid *fid)
+{
+       return fid_seq(fid) == FID_SEQ_QUOTA ||
+              fid_seq(fid) == FID_SEQ_QUOTA_GLB;
+}
+
 enum lu_mgr_type {
         LUSTRE_SEQ_SERVER,
         LUSTRE_SEQ_CONTROLLER
index 78d8916..366454d 100644 (file)
@@ -2970,11 +2970,12 @@ static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
                                 struct thandle *handle,
                                 struct lustre_capa *capa)
 {
-        struct osd_object     *obj = osd_dt_obj(dt);
-        struct osd_thandle    *oh;
-        struct iam_path_descr *ipd;
-        struct iam_container  *bag = &obj->oo_dir->od_container;
-        int                    rc;
+        struct osd_thread_info *oti = osd_oti_get(env);
+        struct osd_object      *obj = osd_dt_obj(dt);
+        struct osd_thandle     *oh;
+        struct iam_path_descr  *ipd;
+        struct iam_container   *bag = &obj->oo_dir->od_container;
+        int                     rc;
 
         ENTRY;
 
@@ -2996,6 +2997,12 @@ static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
         LASSERT(oh->ot_handle != NULL);
         LASSERT(oh->ot_handle->h_transaction != NULL);
 
+       if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
+               /* swab quota uid/gid provided by caller */
+               oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
+               key = (const struct dt_key *)&oti->oti_quota_id;
+       }
+
         rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
         osd_ipd_put(env, bag, ipd);
         LINVRNT(osd_invariant(obj));
@@ -3148,6 +3155,12 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
         /* got ipd now we can start iterator. */
         iam_it_init(it, bag, 0, ipd);
 
+       if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
+               /* swab quota uid/gid provided by caller */
+               oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
+               key = (const struct dt_key *)&oti->oti_quota_id;
+       }
+
         rc = iam_it_get(it, (struct iam_key *)key);
         if (rc >= 0) {
                 if (S_ISDIR(obj->oo_inode->i_mode))
@@ -3156,10 +3169,14 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
                         iam_rec = (struct iam_rec *) rec;
 
                 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
+
                 if (S_ISDIR(obj->oo_inode->i_mode))
                         osd_fid_unpack((struct lu_fid *) rec,
                                        (struct osd_fid_pack *)iam_rec);
+               else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
+                       osd_quota_unpack(obj, rec);
         }
+
         iam_it_put(it);
         iam_it_fini(it);
         osd_ipd_put(env, bag, ipd);
@@ -3213,7 +3230,7 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
         cfs_cap_t              save = cfs_curproc_cap_pack();
 #endif
         struct osd_thread_info *oti = osd_oti_get(env);
-        struct iam_rec         *iam_rec = (struct iam_rec *)oti->oti_ldp;
+        struct iam_rec         *iam_rec;
         int                     rc;
 
         ENTRY;
@@ -3241,10 +3258,20 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
         else
                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
 #endif
-        if (S_ISDIR(obj->oo_inode->i_mode))
-                osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
-        else
-                iam_rec = (struct iam_rec *) rec;
+       if (S_ISDIR(obj->oo_inode->i_mode)) {
+               iam_rec = (struct iam_rec *)oti->oti_ldp;
+               osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
+       } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
+               /* pack quota uid/gid */
+               oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
+               key = (const struct dt_key *)&oti->oti_quota_id;
+               /* pack quota record */
+               rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
+               iam_rec = (struct iam_rec *)rec;
+       } else {
+               iam_rec = (struct iam_rec *)rec;
+       }
+
         rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
                         iam_rec, ipd);
 #ifdef HAVE_QUOTA_SUPPORT
@@ -3744,7 +3771,14 @@ static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
 static int osd_it_iam_get(const struct lu_env *env,
                           struct dt_it *di, const struct dt_key *key)
 {
-        struct osd_it_iam *it = (struct osd_it_iam *)di;
+       struct osd_thread_info  *oti = osd_oti_get(env);
+       struct osd_it_iam       *it = (struct osd_it_iam *)di;
+
+       if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
+               /* swab quota uid/gid */
+               oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
+               key = (struct dt_key *)&oti->oti_quota_id;
+       }
 
         return iam_it_get(&it->oi_it, (const struct iam_key *)key);
 }
@@ -3786,9 +3820,20 @@ static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
                                  const struct dt_it *di)
 {
-        struct osd_it_iam *it = (struct osd_it_iam *)di;
+       struct osd_thread_info *oti = osd_oti_get(env);
+       struct osd_it_iam      *it = (struct osd_it_iam *)di;
+       struct osd_object      *obj = it->oi_obj;
+       struct dt_key          *key;
 
-        return (struct dt_key *)iam_it_key_get(&it->oi_it);
+       key = (struct dt_key *)iam_it_key_get(&it->oi_it);
+
+       if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
+               /* swab quota uid/gid */
+               oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
+               key = (struct dt_key *)&oti->oti_quota_id;
+       }
+
+       return key;
 }
 
 /**
@@ -3881,6 +3926,10 @@ static int osd_it_iam_rec(const struct lu_env *env,
                /* IAM does not store object type in IAM index (dir) */
                osd_it_pack_dirent(lde, fid, hash, name, namelen,
                                   0, LUDA_FID);
+       } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
+               iam_reccpy(&it->oi_it.ii_path.ip_leaf,
+                          (struct iam_rec *)dtrec);
+               osd_quota_unpack(it->oi_obj, dtrec);
        } else {
                iam_reccpy(&it->oi_it.ii_path.ip_leaf,
                           (struct iam_rec *)dtrec);
index 898ee70..9efb06f 100644 (file)
@@ -614,8 +614,10 @@ struct osd_thread_info {
                struct if_dqblk         oti_dqblk;
                struct if_dqinfo        oti_dqinfo;
        };
-       struct lquota_id_info  oti_qi;
-       struct lquota_trans    oti_quota_trans;
+       struct lquota_id_info   oti_qi;
+       struct lquota_trans     oti_quota_trans;
+       union lquota_rec        oti_quota_rec;
+       __u64                   oti_quota_id;
 };
 
 extern int ldiskfs_pdo;
@@ -688,6 +690,10 @@ int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
 int osd_declare_inode_qid(const struct lu_env *env, qid_t uid, qid_t gid,
                          long long space, struct osd_thandle *oh,
                          bool is_blk, bool allocated, int *flags, bool force);
+const struct dt_rec *osd_quota_pack(struct osd_object *obj,
+                                   const struct dt_rec *rec,
+                                   union lquota_rec *quota_rec);
+void osd_quota_unpack(struct osd_object *obj, const struct dt_rec *rec);
 
 /*
  * Invariants, assertions.
index 5abfafa..26257ea 100644 (file)
@@ -415,6 +415,49 @@ const struct dt_index_operations osd_acct_index_ops = {
        }
 };
 
+static inline void osd_quota_swab(char *ptr, size_t size)
+{
+       int offset;
+
+       LASSERT((size & (sizeof(__u64) - 1)) == 0);
+
+       for (offset = 0; offset < size; offset += sizeof(__u64))
+            __swab64s((__u64 *)(ptr + offset));
+}
+
+const struct dt_rec *osd_quota_pack(struct osd_object *obj,
+                                   const struct dt_rec *rec,
+                                   union lquota_rec *quota_rec)
+{
+#ifdef __BIG_ENDIAN
+       struct iam_descr        *descr;
+
+       LASSERT(obj->oo_dir != NULL);
+       descr = obj->oo_dir->od_container.ic_descr;
+
+       memcpy(quota_rec, rec, descr->id_rec_size);
+
+       osd_quota_swab((char *)quota_rec, descr->id_rec_size);
+       return (const struct dt_rec *)quota_rec;
+#else
+       return rec;
+#endif
+}
+
+void osd_quota_unpack(struct osd_object *obj, const struct dt_rec *rec)
+{
+#ifdef __BIG_ENDIAN
+       struct iam_descr *descr;
+
+       LASSERT(obj->oo_dir != NULL);
+       descr = obj->oo_dir->od_container.ic_descr;
+
+       osd_quota_swab((char *)rec, descr->id_rec_size);
+#else
+       return;
+#endif
+}
+
 static inline int osd_qid_type(struct osd_thandle *oh, int i)
 {
        return (oh->ot_id_type & (1 << i)) ? GRPQUOTA : USRQUOTA;
@@ -541,4 +584,3 @@ int osd_declare_inode_qid(const struct lu_env *env, qid_t uid, qid_t gid,
 
        RETURN(rcu ? rcu : rcg);
 }
-