From e10e83eb9e054931b577b7e375f81c05ad68c7ab Mon Sep 17 00:00:00 2001 From: wangdi Date: Fri, 29 Sep 2006 14:30:25 +0000 Subject: [PATCH] Branch: b_new_cmd 1)add is_dir check for add/remove entries in split. 2)some fixes and cleanup --- lustre/cmm/cmm_split.c | 65 +++++++++++++++++++++++++++----------- lustre/include/lustre/lustre_idl.h | 2 ++ lustre/mdd/mdd_handler.c | 4 +-- lustre/mdt/mdt_handler.c | 8 ++--- lustre/obdclass/lu_object.c | 3 +- 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/lustre/cmm/cmm_split.c b/lustre/cmm/cmm_split.c index 847b428..e5a37b6 100644 --- a/lustre/cmm/cmm_split.c +++ b/lustre/cmm/cmm_split.c @@ -249,6 +249,48 @@ static int cmm_send_split_pages(const struct lu_env *env, RETURN(rc); } +static int cmm_remove_dir_ent(const struct lu_env *env, struct md_object *mo, + struct lu_dirent *ent) +{ + struct cmm_device *cmm = cmm_obj2dev(md2cmm_obj(mo)); + struct cmm_object *obj; + char *name; + int is_dir, rc; + ENTRY; + + if (!strncmp(ent->lde_name, ".", ent->lde_namelen) || + !strncmp(ent->lde_name, "..", ent->lde_namelen)) + RETURN(0); + + obj = cmm_object_find(env, cmm, &ent->lde_fid, NULL); + if (IS_ERR(obj)) + RETURN(PTR_ERR(obj)); + + is_dir = S_ISDIR(lu_object_attr(&obj->cmo_obj.mo_lu)); + OBD_ALLOC(name, ent->lde_namelen + 1); + if (!name) + GOTO(cleanup, rc = -ENOMEM); + + memcpy(name, ent->lde_name, ent->lde_namelen); + rc = mdo_name_remove(env, md_object_next(mo), + name, is_dir); + OBD_FREE(name, ent->lde_namelen + 1); + if (rc) + GOTO(cleanup, rc); + + /* Because this ent will be transferred to slave MDS and + * insert it there, so in the slave MDS, we should know whether + * this object is dir or not, so use the highest bit of the hash + * to indicate that (because we do not use highest bit of hash) + */ + if (is_dir) + ent->lde_hash |= MAX_HASH_HIGHEST_BIT; +cleanup: + cmm_object_put(env, obj); + + RETURN(rc); +} + static int cmm_remove_entries(const struct lu_env *env, struct md_object *mo, struct lu_rdpg *rdpg, __u32 hash_end, __u32 *len) @@ -263,24 +305,11 @@ static int cmm_remove_entries(const struct lu_env *env, for (ent = lu_dirent_start(dp); ent != NULL; ent = lu_dirent_next(ent)) { if (ent->lde_hash < hash_end) { - if (strncmp(ent->lde_name, ".", ent->lde_namelen) && - strncmp(ent->lde_name, "..", ent->lde_namelen)) { - char *name; - /* FIXME: Here we allocate name for each name, - * maybe stupid, but can not find better way. - * will find better way */ - OBD_ALLOC(name, ent->lde_namelen + 1); - memcpy(name, ent->lde_name, ent->lde_namelen); - rc = mdo_name_remove(env, md_object_next(mo), - name, 0); - OBD_FREE(name, ent->lde_namelen + 1); - } - if (rc) { - /* FIXME: Do not know why it return -ENOENT - * in some case - * */ - if (rc != -ENOENT) - GOTO(unmap, rc); + rc = cmm_remove_dir_ent(env, mo, ent); + if (rc) { + CERROR("Can not del %s rc %d\n", ent->lde_name, + rc); + GOTO(unmap, rc); } } else { if (ent != lu_dirent_start(dp)) diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 9e2e253..ce8b8cb 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -299,7 +299,9 @@ static inline struct lu_dirent *lu_dirent_next(struct lu_dirent *ent) #define MEA_MAGIC_LAST_CHAR 0xb2221ca1 #define MEA_MAGIC_ALL_CHARS 0xb222a11c #define MEA_MAGIC_HASH_SEGMENT 0xb222a11b + #define MAX_HASH_SIZE 0x7fffffff +#define MAX_HASH_HIGHEST_BIT 0x10000000 /* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */ struct lmv_stripe_md { diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 5e3a82b..9301401 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -438,7 +438,7 @@ static void mdd_object_delete(const struct lu_env *env, return; if (test_bit(LU_OBJECT_ORPHAN, &o->lo_header->loh_flags)) { - mdd_txn_param_build(env, MDD_TXN_MKDIR_OP); + mdd_txn_param_build(env, MDD_TXN_INDEX_DELETE_OP); handle = mdd_trans_start(env, lu2mdd_dev(o->lo_dev)); if (IS_ERR(handle)) CERROR("Cannot get thandle\n"); @@ -1761,7 +1761,7 @@ static int mdd_ref_del(const struct lu_env *env, struct md_object *obj, int rc; ENTRY; - mdd_txn_param_build(env, MDD_TXN_XATTR_SET_OP); + mdd_txn_param_build(env, MDD_TXN_UNLINK_OP); handle = mdd_trans_start(env, mdd); if (IS_ERR(handle)) RETURN(-ENOMEM); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 6a4d131..bf09b94 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -777,14 +777,14 @@ static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page) if (strncmp(ent->lde_name, ".", ent->lde_namelen) && strncmp(ent->lde_name, "..", ent->lde_namelen)) { char *name; - /* FIXME: Here we allocate name for each name, - * maybe stupid, but can not find better way. - * will find better way */ + int is_dir = le32_to_cpu(ent->lde_hash) & + MAX_HASH_HIGHEST_BIT; + OBD_ALLOC(name, ent->lde_namelen + 1); memcpy(name, ent->lde_name, ent->lde_namelen); rc = mdo_name_insert(info->mti_env, md_object_next(&object->mot_obj), - name, lf, 0); + name, lf, is_dir); OBD_FREE(name, ent->lde_namelen + 1); if (rc) GOTO(out, rc); diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index c9a3755..b0a4b77 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -132,8 +132,9 @@ static struct lu_object *lu_object_alloc(const struct lu_env *env, top->lo_header->loh_fid = *f; if (capa == BYPASS_CAPA) lu_object_bypass_capa(top); - else + else if (capa) top->lo_header->loh_capa = *capa; + layers = &top->lo_header->loh_layers; do { /* -- 1.8.3.1