}
/* 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,
}
/* 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,
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,
#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,
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; \
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
#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
.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,
}
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,
.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)
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,
(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;
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);
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);
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));
/*
* 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,
.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,
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;
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;
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
}
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);
}
default:
CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
- LBUG();
+ result = -EIO;
}
+ return result;
}
EXPORT_SYMBOL(fid_unpack);
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)
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)) {
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)