From fd04d29e80cf5f2bea989de29a574d04478cf1f3 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Fri, 14 Sep 2012 03:32:05 -0400 Subject: [PATCH] LU-1842 iam: store key & rec in LE order for quota IAM files Store quota keys and records in little endian format in iam index files. Signed-off-by: Johann Lombardi Signed-off-by: Niu Yawei Change-Id: I391fb9c0b8ff67c3cc5f51abd31a0dbf92d7276c Reviewed-on: http://review.whamcloud.com/3989 Tested-by: Hudson Reviewed-by: Fan Yong Tested-by: Maloo --- lustre/include/lustre_fid.h | 6 ++++ lustre/osd-ldiskfs/osd_handler.c | 75 ++++++++++++++++++++++++++++++++------- lustre/osd-ldiskfs/osd_internal.h | 10 ++++-- lustre/osd-ldiskfs/osd_quota.c | 44 ++++++++++++++++++++++- 4 files changed, 119 insertions(+), 16 deletions(-) diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index bb664b2..56e2186 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -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 diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 78d8916..366454d 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -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); diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 898ee70..9efb06f 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -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. diff --git a/lustre/osd-ldiskfs/osd_quota.c b/lustre/osd-ldiskfs/osd_quota.c index 5abfafa..26257ea 100644 --- a/lustre/osd-ldiskfs/osd_quota.c +++ b/lustre/osd-ldiskfs/osd_quota.c @@ -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); } - -- 1.8.3.1