From: anserper Date: Mon, 24 Sep 2007 16:23:18 +0000 (+0000) Subject: patches related to bug 13377 (CMD small fixes), 2+4 patch and fid_unpack patch X-Git-Tag: v1_7_0_51~697 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f89a61cada93accbd02beee89f0610756ca595e9 patches related to bug 13377 (CMD small fixes), 2+4 patch and fid_unpack patch --- diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index 717271a..05413d7 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -383,24 +383,7 @@ static void cmm_device_free(const struct lu_env *env, struct lu_device *d) } /* context key constructor/destructor */ -static void *cmm_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct cmm_thread_info *info; - - CLASSERT(CFS_PAGE_SIZE >= sizeof *info); - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - return info; -} - -static void cmm_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct cmm_thread_info *info = data; - OBD_FREE_PTR(info); -} +LU_KEY_INIT_FINI(cmm, struct cmm_thread_info); static struct lu_context_key cmm_thread_key = { .lct_tags = LCT_MD_THREAD, diff --git a/lustre/cmm/mdc_device.c b/lustre/cmm/mdc_device.c index 480a73a..8c0239d 100644 --- a/lustre/cmm/mdc_device.c +++ b/lustre/cmm/mdc_device.c @@ -290,25 +290,7 @@ void mdc_device_free(const struct lu_env *env, struct lu_device *ld) } /* context key constructor/destructor */ - -static void *mdc_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct mdc_thread_info *info; - - CLASSERT(CFS_PAGE_SIZE >= sizeof *info); - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - return info; -} - -static void mdc_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct mdc_thread_info *info = data; - OBD_FREE_PTR(info); -} +LU_KEY_INIT_FINI(mdc, struct mdc_thread_info); struct lu_context_key mdc_thread_key = { .lct_tags = LCT_MD_THREAD|LCT_CL_THREAD, diff --git a/lustre/fid/fid_handler.c b/lustre/fid/fid_handler.c index 0aa64b2..45e1ebb 100644 --- a/lustre/fid/fid_handler.c +++ b/lustre/fid/fid_handler.c @@ -356,27 +356,7 @@ static int seq_req_handle(struct ptlrpc_request *req, RETURN(rc); } -static void *seq_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct seq_thread_info *info; - - /* - * check that no high order allocations are incurred. - */ - CLASSERT(CFS_PAGE_SIZE >= sizeof *info); - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - return info; -} - -static void seq_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct seq_thread_info *info = data; - OBD_FREE_PTR(info); -} +LU_KEY_INIT_FINI(seq, struct seq_thread_info); struct lu_context_key seq_thread_key = { .lct_tags = LCT_MD_THREAD, diff --git a/lustre/fld/fld_handler.c b/lustre/fld/fld_handler.c index d34ec0c..5f902d2 100644 --- a/lustre/fld/fld_handler.c +++ b/lustre/fld/fld_handler.c @@ -52,26 +52,8 @@ #include "fld_internal.h" #ifdef __KERNEL__ -static void *fld_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct fld_thread_info *info; - ENTRY; - - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - RETURN(info); -} -static void fld_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct fld_thread_info *info = data; - ENTRY; - OBD_FREE_PTR(info); - EXIT; -} +LU_KEY_INIT_FINI(fld, struct fld_thread_info); struct lu_context_key fld_thread_key = { .lct_tags = LCT_MD_THREAD|LCT_DT_THREAD, diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index e9761de..e07dfbb 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -966,6 +966,37 @@ struct lu_context_key { struct module *lct_owner; }; +#define LU_KEY_INIT(mod, type) \ + static void* mod##_key_init(const struct lu_context *ctx, \ + struct lu_context_key *key) \ + { \ + type *value; \ + \ + CLASSERT(CFS_PAGE_SIZE >= sizeof (*value)); \ + \ + OBD_ALLOC_PTR(value); \ + if (value == NULL) \ + value = ERR_PTR(-ENOMEM); \ + \ + return value; \ + } \ + struct __##mod##__dummy_init {;} /* semicolon catcher */ + +#define LU_KEY_FINI(mod, type) \ + static void mod##_key_fini(const struct lu_context *ctx, \ + struct lu_context_key *key, void* data) \ + { \ + type *info = data; \ + \ + OBD_FREE_PTR(info); \ + } \ + struct __##mod##__dummy_fini {;} /* semicolon catcher */ + +#define LU_KEY_INIT_FINI(mod, type) \ + LU_KEY_INIT(mod,type); \ + LU_KEY_FINI(mod,type); + + #define LU_CONTEXT_KEY_INIT(key) \ do { \ (key)->lct_owner = THIS_MODULE; \ diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 93cd4b8..bc2cfd2 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -289,7 +289,7 @@ struct lu_fid_pack { void fid_pack(struct lu_fid_pack *pack, const struct lu_fid *fid, struct lu_fid *befider); -void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid); +int fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid); /* __KERNEL__ */ #endif diff --git a/lustre/include/lustre_mds.h b/lustre/include/lustre_mds.h index b051786..e388fb8 100644 --- a/lustre/include/lustre_mds.h +++ b/lustre/include/lustre_mds.h @@ -115,4 +115,10 @@ void mds_objids_from_lmm(obd_id *, struct lov_mds_md *, struct lov_desc *); #define MDD_OBD_TYPE "mds" #define MDD_OBD_PROFILE "lustre-MDT0000" +static inline int md_should_create(__u32 flags) +{ + return !(flags & MDS_OPEN_DELAY_CREATE || + !(flags & FMODE_WRITE)); +} + #endif diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 0ad9650..7f776ce 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -329,24 +329,7 @@ static struct obd_ops mdd_obd_device_ops = { .o_owner = THIS_MODULE }; -static void *mdd_ucred_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct md_ucred *uc; - - OBD_ALLOC_PTR(uc); - if (uc == NULL) - uc = ERR_PTR(-ENOMEM); - return uc; -} - -static void mdd_ucred_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct md_ucred *uc = data; - if (!IS_ERR(uc)) - OBD_FREE_PTR(uc); -} +LU_KEY_INIT_FINI(mdd_ucred, struct md_ucred); static struct lu_context_key mdd_ucred_key = { .lct_tags = LCT_SESSION, @@ -361,24 +344,7 @@ struct md_ucred *md_ucred(const struct lu_env *env) } EXPORT_SYMBOL(md_ucred); -static void *mdd_capainfo_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct md_capainfo *ci; - - OBD_ALLOC_PTR(ci); - if (ci == NULL) - ci = ERR_PTR(-ENOMEM); - return ci; -} - -static void mdd_capainfo_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct md_capainfo *ci = data; - if (!IS_ERR(ci)) - OBD_FREE_PTR(ci); -} +LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo); struct lu_context_key mdd_capainfo_key = { .lct_tags = LCT_SESSION, @@ -445,16 +411,7 @@ static struct lu_device_type mdd_device_type = { .ldt_ctx_tags = LCT_MD_THREAD }; -static void *mdd_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct mdd_thread_info *info; - - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - return info; -} +LU_KEY_INIT(mdd, struct mdd_thread_info); static void mdd_key_fini(const struct lu_context *ctx, struct lu_context_key *key, void *data) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index b20bb9c..dc24003 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -979,8 +979,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj, if (rc) RETURN(rc); - if (spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE || - !(spec->sp_cr_flags & FMODE_WRITE)) + if (!md_should_create(spec->sp_cr_flags)) RETURN(0); rc = mdd_lov_create(env, mdd, mdd_pobj, son, &lmm, &lmm_size, @@ -1064,7 +1063,7 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj, (struct dt_rec *)pack, key, mdd_object_capa(env, mdd_obj)); if (rc == 0) - fid_unpack(pack, fid); + rc = fid_unpack(pack, fid); } else rc = -ENOTDIR; diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index 98e9018..687137a 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -409,8 +409,7 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd, int rc = 0; ENTRY; - if (create_flags & MDS_OPEN_DELAY_CREATE || - !(create_flags & FMODE_WRITE)) + if (!md_should_create(create_flags)) RETURN(0); oti_init(oti, NULL); diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index b45d37b..be12358 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1314,7 +1314,9 @@ static int mdd_dir_page_build(const struct lu_env *env, int first, len = iops->key_size(env, it); pack = (struct lu_fid_pack *)iops->rec(env, it); - fid_unpack(pack, fid); + result = fid_unpack(pack, fid); + if (result != 0) + break; recsize = (sizeof(*ent) + len + 3) & ~3; hash = iops->store(env, it); diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c index 73da5aa..5136883 100644 --- a/lustre/mds/mds_open.c +++ b/lustre/mds/mds_open.c @@ -320,8 +320,7 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset, if (!S_ISREG(inode->i_mode)) RETURN(0); - if (rec->ur_flags & MDS_OPEN_DELAY_CREATE || - !(rec->ur_flags & FMODE_WRITE)) + if (!md_should_create(rec->ur_flags)) RETURN(0); body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index f4c80ee..b6f9649 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -4542,27 +4542,7 @@ static struct lu_device *mdt_device_alloc(const struct lu_env *env, /* * context key constructor/destructor */ -static void *mdt_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct mdt_thread_info *info; - - /* - * check that no high order allocations are incurred. - */ - CLASSERT(CFS_PAGE_SIZE >= sizeof *info); - OBD_ALLOC_PTR(info); - if (info == NULL) - info = ERR_PTR(-ENOMEM); - return info; -} - -static void mdt_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct mdt_thread_info *info = data; - OBD_FREE_PTR(info); -} +LU_KEY_INIT_FINI(mdt, struct mdt_thread_info); struct lu_context_key mdt_thread_key = { .lct_tags = LCT_MD_THREAD, @@ -4570,28 +4550,7 @@ struct lu_context_key mdt_thread_key = { .lct_fini = mdt_key_fini }; -static void *mdt_txn_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct mdt_txn_info *txi; - - /* - * check that no high order allocations are incurred. - */ - CLASSERT(CFS_PAGE_SIZE >= sizeof *txi); - OBD_ALLOC_PTR(txi); - if (txi == NULL) - txi = ERR_PTR(-ENOMEM); - memset(txi, 0, sizeof(*txi)); - return txi; -} - -static void mdt_txn_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct mdt_txn_info *txi = data; - OBD_FREE_PTR(txi); -} +LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info); struct lu_context_key mdt_txn_key = { .lct_tags = LCT_TX_HANDLE, diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 0507d97..872bd1b 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -98,8 +98,7 @@ static int mdt_create_data(struct mdt_thread_info *info, int rc; ENTRY; - if ((spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE) || - !(spec->sp_cr_flags & FMODE_WRITE)) + if (!md_should_create(spec->sp_cr_flags)) RETURN(0); ma->ma_need = MA_INODE | MA_LOV; diff --git a/lustre/obdclass/dt_object.c b/lustre/obdclass/dt_object.c index 07ea54b..404b29e 100644 --- a/lustre/obdclass/dt_object.c +++ b/lustre/obdclass/dt_object.c @@ -157,7 +157,8 @@ static int dt_lookup(const struct lu_env *env, struct dt_object *dir, if (dt_try_as_dir(env, dir)) { result = dir->do_index_ops->dio_lookup(env, dir, rec, key, BYPASS_CAPA); - fid_unpack(pack, fid); + if (result == 0) + result = fid_unpack(pack, fid); } else result = -ENOTDIR; return result; diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index ba17f7d..387f0f2 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -290,23 +290,7 @@ struct lu_cdebug_data { struct lu_fid_pack lck_pack; }; -static void *lu_global_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct lu_cdebug_data *value; - - OBD_ALLOC_PTR(value); - if (value == NULL) - value = ERR_PTR(-ENOMEM); - return value; -} - -static void lu_global_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct lu_cdebug_data *value = data; - OBD_FREE_PTR(value); -} +LU_KEY_INIT_FINI(lu_global, struct lu_cdebug_data); /* * Key, holding temporary buffer. This key is registered very early by @@ -1183,8 +1167,11 @@ void fid_pack(struct lu_fid_pack *pack, const struct lu_fid *fid, } EXPORT_SYMBOL(fid_pack); -void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid) +int fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid) { + int result; + + result = 0; switch (pack->fp_len) { case sizeof *fid + 1: memcpy(fid, pack->fp_area, sizeof *fid); @@ -1201,8 +1188,9 @@ void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid) } default: CERROR("Unexpected packed fid size: %d\n", pack->fp_len); - LBUG(); + result = -EIO; } + return result; } EXPORT_SYMBOL(fid_unpack); diff --git a/lustre/obdclass/lu_time.c b/lustre/obdclass/lu_time.c index e51b7af..1eed2e2 100644 --- a/lustre/obdclass/lu_time.c +++ b/lustre/obdclass/lu_time.c @@ -48,23 +48,7 @@ struct lu_time_data { unsigned long long ltd_timestamp[LU_TIME_DEPTH_MAX]; }; -static void *lu_time_key_init(const struct lu_context *ctx, - struct lu_context_key *key) -{ - struct lu_time_data *value; - - OBD_ALLOC_PTR(value); - if (value == NULL) - value = ERR_PTR(-ENOMEM); - return value; -} - -static void lu_time_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct lu_time_data *value = data; - OBD_FREE_PTR(value); -} +LU_KEY_INIT_FINI(lu_time, struct lu_time_data); void lu_time_key_exit(const struct lu_context *ctx, struct lu_context_key *key, void *data) diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index ea283e2..39ac11b 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -2166,7 +2166,10 @@ static int osd_index_compat_insert(const struct lu_env *env, if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT)) return -EACCES; - fid_unpack(pack, fid); + result = fid_unpack(pack, fid); + if (result != 0) + return result; + luch = lu_object_find(env, ludev->ld_site, fid); if (!IS_ERR(luch)) { if (lu_object_exists(luch)) { @@ -2235,12 +2238,7 @@ static void *osd_key_init(const struct lu_context *ctx, return info; } -static void osd_key_fini(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct osd_thread_info *info = data; - OBD_FREE_PTR(info); -} +LU_KEY_FINI(osd, struct osd_thread_info); static void osd_key_exit(const struct lu_context *ctx, struct lu_context_key *key, void *data)