From: pravins Date: Tue, 23 Jun 2009 20:59:16 +0000 (+0000) Subject: b=17670 X-Git-Tag: v1_9_220~107 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f2bedfe6e389eccf931f339cd8efe93f72ed530c;ds=sidebyside b=17670 i=tom.wang i=yong.fan build and return lu_dirent from osd iterator. use type info available in ext3 dirent --- diff --git a/libcfs/include/libcfs/linux/linux-fs.h b/libcfs/include/libcfs/linux/linux-fs.h index 903001e..dc9ab89 100644 --- a/libcfs/include/libcfs/linux/linux-fs.h +++ b/libcfs/include/libcfs/linux/linux-fs.h @@ -85,6 +85,9 @@ typedef struct file_lock cfs_flock_t; ssize_t cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset); -#define CFS_IFTODT(type) (((type) & 0170000) >> 12) +#define CFS_IFSHIFT 12 + +#define CFS_IFTODT(type) (((type) & S_IFMT) >> CFS_IFSHIFT) +#define CFS_DTTOIF(dirtype) ((dirtype) << CFS_IFSHIFT) #endif diff --git a/libcfs/include/libcfs/posix/libcfs.h b/libcfs/include/libcfs/posix/libcfs.h index 9d5970a..37072e0 100644 --- a/libcfs/include/libcfs/posix/libcfs.h +++ b/libcfs/include/libcfs/posix/libcfs.h @@ -411,5 +411,9 @@ static inline void radix_tree_preload_end(void) typedef ssize_t (*read_actor_t)(); -#define CFS_IFTODT(type) (((type) & 0170000) >> 12) +#define CFS_IFSHIFT 12 + +#define CFS_IFTODT(type) (((type) & S_IFMT) >> CFS_IFSHIFT) +#define CFS_DTTOIF(dirtype) ((dirtype) << CFS_IFSHIFT) + #endif diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index 242473e..8e4cb77 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -471,8 +471,10 @@ struct dt_index_operations { const struct dt_it *di); int (*key_size)(const struct lu_env *env, const struct dt_it *di); - struct dt_rec *(*rec)(const struct lu_env *env, - const struct dt_it *di); + int (*rec)(const struct lu_env *env, + const struct dt_it *di, + struct lu_dirent *lde, + __u32 attr); __u64 (*store)(const struct lu_env *env, const struct dt_it *di); int (*load)(const struct lu_env *env, diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 943786e..099a552 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -1420,7 +1420,7 @@ struct quota_adjust_qunit { }; extern void lustre_swab_quota_adjust_qunit(struct quota_adjust_qunit *q); -/* flags is shared among quota structures */ +/* flags in qunit_data and quota_adjust_qunit will use macroes below */ #define LQUOTA_FLAGS_GRP 1UL /* 0 is user, 1 is group */ #define LQUOTA_FLAGS_BLK 2UL /* 0 is inode, 1 is block */ #define LQUOTA_FLAGS_ADJBLK 4UL /* adjust the block qunit size */ @@ -1428,21 +1428,16 @@ extern void lustre_swab_quota_adjust_qunit(struct quota_adjust_qunit *q); #define LQUOTA_FLAGS_CHG_QS 16UL /* indicate whether it has capability of * OBD_CONNECT_CHANGE_QS */ -/* flags is specific for quota_adjust_qunit */ -#define LQUOTA_QAQ_CEATE_LQS (1 << 31) /* when it is set, need create lqs */ - -/* the status of lqs_flags in struct lustre_qunit_size */ +/* the status of lqsk_flags in struct lustre_qunit_size_key */ #define LQUOTA_QUNIT_FLAGS (LQUOTA_FLAGS_GRP | LQUOTA_FLAGS_BLK) -#define QAQ_IS_GRP(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_GRP) -#define QAQ_IS_ADJBLK(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJBLK) -#define QAQ_IS_ADJINO(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJINO) -#define QAQ_IS_CREATE_LQS(qaq) ((qaq)->qaq_flags & LQUOTA_QAQ_CEATE_LQS) +#define QAQ_IS_GRP(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_GRP) +#define QAQ_IS_ADJBLK(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJBLK) +#define QAQ_IS_ADJINO(qaq) ((qaq)->qaq_flags & LQUOTA_FLAGS_ADJINO) -#define QAQ_SET_GRP(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_GRP) -#define QAQ_SET_ADJBLK(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJBLK) -#define QAQ_SET_ADJINO(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJINO) -#define QAQ_SET_CREATE_LQS(qaq) ((qaq)->qaq_flags |= LQUOTA_QAQ_CEATE_LQS) +#define QAQ_SET_GRP(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_GRP) +#define QAQ_SET_ADJBLK(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJBLK) +#define QAQ_SET_ADJINO(qaq) ((qaq)->qaq_flags |= LQUOTA_FLAGS_ADJINO) /* inode access permission for remote user, the inode info are omitted, * for client knows them. */ diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 9567c38..224aff7 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1951,71 +1951,6 @@ static int mdd_readpage_sanity_check(const struct lu_env *env, RETURN(rc); } -static int mdd_append_attrs(const struct lu_env *env, - struct mdd_device *mdd, - __u32 attr, - const struct dt_it_ops *iops, - struct dt_it *it, - struct lu_dirent*ent) -{ - struct mdd_thread_info *info = mdd_env_info(env); - struct lu_fid *fid = &info->mti_fid2; - int len = cpu_to_le16(ent->lde_namelen); - const unsigned align = sizeof(struct luda_type) - 1; - struct lu_fid_pack *pack; - struct mdd_object *obj; - struct luda_type *lt; - int rc = 0; - - if (attr & LUDA_FID) { - pack = (struct lu_fid_pack *)iops->rec(env, it); - if (IS_ERR(pack)) { - rc = PTR_ERR(pack); - ent->lde_attrs = 0; - goto out; - } - rc = fid_unpack(pack, fid); - if (rc != 0) { - ent->lde_attrs = 0; - goto out; - } - - fid_cpu_to_le(&ent->lde_fid, fid); - ent->lde_attrs = LUDA_FID; - } - - /* check if file type is required */ - if (attr & LUDA_TYPE) { - if (!(attr & LUDA_FID)) { - CERROR("wrong attr : [%x]\n",attr); - rc = -EINVAL; - goto out; - } - - obj = mdd_object_find(env, mdd, fid); - if (obj == NULL) /* remote object */ - goto out; - - if (IS_ERR(obj)) { - rc = PTR_ERR(obj); - goto out; - } - - if (mdd_object_exists(obj) == +1) { - len = (len + align) & ~align; - - lt = (void *) ent->lde_name + len; - lt->lt_type = cpu_to_le16(mdd_object_type(obj)); - - ent->lde_attrs |= LUDA_TYPE; - } - mdd_object_put(env, obj); - } -out: - ent->lde_attrs = cpu_to_le32(ent->lde_attrs); - return rc; -} - static int mdd_dir_page_build(const struct lu_env *env, struct mdd_device *mdd, int first, void *area, int nob, const struct dt_it_ops *iops, struct dt_it *it, @@ -2023,8 +1958,8 @@ static int mdd_dir_page_build(const struct lu_env *env, struct mdd_device *mdd, struct lu_dirent **last, __u32 attr) { int result; + __u64 hash = 0; struct lu_dirent *ent; - __u64 hash = 0; if (first) { memset(area, 0, sizeof (struct lu_dirpage)); @@ -2034,7 +1969,6 @@ static int mdd_dir_page_build(const struct lu_env *env, struct mdd_device *mdd, ent = area; do { - char *name; int len; int recsize; @@ -2044,30 +1978,25 @@ static int mdd_dir_page_build(const struct lu_env *env, struct mdd_device *mdd, if (len == 0) goto next; - name = (char *)iops->key(env, it); hash = iops->store(env, it); - if (unlikely(first)) { first = 0; *start = hash; } + /* calculate max space required for lu_dirent */ recsize = lu_dirent_calc_size(len, attr); - CDEBUG(D_INFO, "%p %p %d "LPU64" (%d) \"%*.*s\"\n", - name, ent, nob, hash, len, len, len, name); - if (nob >= recsize) { - ent->lde_hash = cpu_to_le64(hash); - ent->lde_namelen = cpu_to_le16(len); - ent->lde_reclen = cpu_to_le16(recsize); - memcpy(ent->lde_name, name, len); - - result = mdd_append_attrs(env, mdd, attr, iops, it, ent); + result = iops->rec(env, it, ent, attr); if (result == -ESTALE) goto next; if (result != 0) goto out; + + /* osd might not able to pack all attributes, + * so recheck rec length */ + recsize = le16_to_cpu(ent->lde_reclen); } else { /* * record doesn't fit into page, enlarge previous one. @@ -2128,7 +2057,7 @@ static int __mdd_readpage(const struct lu_env *env, struct mdd_object *obj, rc = iops->load(env, it, rdpg->rp_hash); - if (rc == 0) + if (rc == 0){ /* * Iterator didn't find record with exactly the key requested. * @@ -2141,7 +2070,7 @@ static int __mdd_readpage(const struct lu_env *env, struct mdd_object *obj, * state)---position it on the next item. */ rc = iops->next(env, it); - else if (rc > 0) + } else if (rc > 0) rc = 0; /* diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index a580390..8076cbd 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -247,15 +247,19 @@ static struct dt_it *osd_it_iam_init (const struct lu_env *env, struct lustre_capa *capa); static struct dt_key *osd_it_iam_key (const struct lu_env *env, const struct dt_it *di); -static struct dt_rec *osd_it_iam_rec (const struct lu_env *env, - const struct dt_it *di); +static int osd_it_iam_rec (const struct lu_env *env, + const struct dt_it *di, + struct lu_dirent *lde, + __u32 attr); static struct dt_it *osd_it_ea_init (const struct lu_env *env, struct dt_object *dt, struct lustre_capa *capa); static struct dt_key *osd_it_ea_key (const struct lu_env *env, const struct dt_it *di); -static struct dt_rec *osd_it_ea_rec (const struct lu_env *env, - const struct dt_it *di); +static inline int osd_it_ea_rec (const struct lu_env *env, + const struct dt_it *di, + struct lu_dirent *lde, + __u32 attr); static struct timespec *osd_inode_time (const struct lu_env *env, struct inode *inode, @@ -1755,26 +1759,25 @@ static inline void osd_igif_get(const struct lu_env *env, struct dentry *dentry, * Helper function to pack the fid */ static inline void osd_fid_pack(const struct lu_env *env, const struct lu_fid *fid, - struct lu_fid_pack *pack) + struct dt_rec *pack) { - fid_pack(pack, fid, &osd_oti_get(env)->oti_fid); + fid_pack((struct lu_fid_pack *)pack, fid, &osd_oti_get(env)->oti_fid); } /** * Try to read the fid from inode ea into dt_rec, if return value * i.e. rc is +ve, then we got fid, otherwise we will have to form igif * - * \param rec, the data-structure into which fid/igif is read + * \param fid, object fid. * * \retval 0, on success */ static int osd_ea_fid_get(const struct lu_env *env, struct dentry *dentry, - struct dt_rec *rec) + struct lu_fid *fid) { struct inode *inode = dentry->d_inode; struct osd_thread_info *info = osd_oti_get(env); struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs; - struct lu_fid *fid = &info->oti_fid; int rc; LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL); @@ -1799,9 +1802,6 @@ static int osd_ea_fid_get(const struct lu_env *env, struct dentry *dentry, rc = 0; } - if (rc == 0) - osd_fid_pack(env, fid, (struct lu_fid_pack*)rec); - return rc; } @@ -2736,6 +2736,7 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, struct osd_inode_id *id = &info->oti_id; struct ldiskfs_dir_entry_2 *de; struct buffer_head *bh; + struct lu_fid * fid = &info->oti_fid; struct inode *inode; int ino; int rc; @@ -2757,7 +2758,10 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, if (!IS_ERR(inode)) { dentry->d_inode = inode; - rc = osd_ea_fid_get(env, dentry, rec); + rc = osd_ea_fid_get(env, dentry, fid); + if (rc == 0) + osd_fid_pack(env, fid, rec); + iput(inode); } else rc = PTR_ERR(inode); @@ -3018,15 +3022,89 @@ static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di) return iam_it_key_size(&it->oi_it); } +static inline void osd_it_append_attrs(struct lu_dirent*ent, + __u32 attr, + int len, + __u16 type) +{ + struct luda_type *lt; + const unsigned align = sizeof(struct luda_type) - 1; + + /* check if file type is required */ + if (attr & LUDA_TYPE) { + len = (len + align) & ~align; + + lt = (void *) ent->lde_name + len; + lt->lt_type = cpu_to_le16(CFS_DTTOIF(type)); + ent->lde_attrs |= LUDA_TYPE; + } + + ent->lde_attrs = cpu_to_le32(ent->lde_attrs); +} + +/** + * build lu direct from backend fs dirent. + */ + +static inline void osd_it_pack_dirent(struct lu_dirent *ent, + struct lu_fid *fid, + __u64 offset, + char *name, + __u16 namelen, + __u16 type, + __u32 attr) +{ + fid_cpu_to_le(&ent->lde_fid, fid); + ent->lde_attrs = LUDA_FID; + + ent->lde_hash = cpu_to_le64(offset); + ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr)); + + strncpy(ent->lde_name, name, namelen); + ent->lde_namelen = cpu_to_le16(namelen); + + /* append lustre attributes */ + osd_it_append_attrs(ent, attr, namelen, type); +} + /** * Return pointer to the record under iterator. */ -static struct dt_rec *osd_it_iam_rec(const struct lu_env *env, - const struct dt_it *di) +static int osd_it_iam_rec(const struct lu_env *env, + const struct dt_it *di, + struct lu_dirent *lde, + __u32 attr) { - struct osd_it_iam *it = (struct osd_it_iam *)di; + struct osd_it_iam *it = (struct osd_it_iam *)di; + struct osd_thread_info *info = osd_oti_get(env); + struct lu_fid *fid = &info->oti_fid; + const struct lu_fid_pack *rec; + char *name; + int namelen; + __u64 hash; + int rc; + + name = (char *)iam_it_key_get(&it->oi_it); + if (IS_ERR(name)) + RETURN(PTR_ERR(name)); + + namelen = iam_it_key_size(&it->oi_it); + + rec = (const struct lu_fid_pack *) iam_it_rec_get(&it->oi_it); + if (IS_ERR(rec)) + RETURN(PTR_ERR(rec)); + + rc = fid_unpack(rec, fid); + if (rc) + RETURN(rc); + + hash = iam_it_store(&it->oi_it); - return (struct dt_rec *)iam_it_rec_get(&it->oi_it); + /* IAM does not store object type in IAM index (dir) */ + osd_it_pack_dirent(lde, fid, hash, name, namelen, + 0, LUDA_FID); + + return 0; } /** @@ -3195,6 +3273,8 @@ static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen, ent->oied_ino = ino; ent->oied_off = offset; ent->oied_namelen = namelen; + ent->oied_type = d_type; + memcpy(ent->oied_name, name, namelen); it->oie_rd_dirent++; @@ -3305,25 +3385,31 @@ static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di) RETURN(it->oie_dirent->oied_namelen); } + /** * Returns the value (i.e. fid/igif) at current position from iterator's * in memory structure. * * \param di, struct osd_it_ea, iterator's in memory structure + * \param attr, attr requested for dirent. + * \param lde, lustre dirent * - * \retval value i.e. struct dt_rec on success + * \retval 0, no error and \param lde has correct lustre dirent. + * \retval -ve, on error */ -static struct dt_rec *osd_it_ea_rec(const struct lu_env *env, - const struct dt_it *di) +static inline int osd_it_ea_rec(const struct lu_env *env, + const struct dt_it *di, + struct lu_dirent *lde, + __u32 attr) { struct osd_it_ea *it = (struct osd_it_ea *)di; struct osd_object *obj = it->oie_obj; struct osd_thread_info *info = osd_oti_get(env); struct osd_inode_id *id = &info->oti_id; - struct lu_fid_pack *rec = &info->oti_pack; struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev; struct dentry *dentry = &info->oti_child_dentry; struct osd_device *dev; + struct lu_fid *fid = &info->oti_fid; struct inode *inode; int rc; @@ -3336,16 +3422,19 @@ static struct dt_rec *osd_it_ea_rec(const struct lu_env *env, dentry->d_inode = inode; LASSERT(dentry->d_inode->i_sb == osd_sb(dev)); } else { - RETURN((struct dt_rec *) PTR_ERR(inode)); + RETURN(PTR_ERR(inode)); } - rc = osd_ea_fid_get(env, dentry, (struct dt_rec*) rec); - if (rc != 0) - rec = ERR_PTR(rc); + rc = osd_ea_fid_get(env, dentry, fid); + if (rc == 0) + osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off, + it->oie_dirent->oied_name, + it->oie_dirent->oied_namelen, + it->oie_dirent->oied_type, + attr); iput(inode); - RETURN((struct dt_rec *)rec); - + RETURN(rc); } /** diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index 6514dc7..624b82a 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -132,6 +132,7 @@ struct osd_it_ea_dirent { __u64 oied_ino; __u64 oied_off; unsigned short oied_namelen; + unsigned int oied_type; char oied_name[0]; } __attribute__((packed));