From 648930da11a2e37d8bd715b24ece688096e13266 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Mon, 12 Dec 2011 20:03:59 +0300 Subject: [PATCH] LU-911 osd: couple helpers for osd api - dt_find_or_create() to "open" and create if needed an object - dt_object_sync() - a wrapper for corresponding osd api method Signed-off-by: Alex Zhuravlev Change-Id: If10e2f522f6e5383260a1d729f305ccdc0b02bbb Signed-off-by: Mikhail Pershin Reviewed-on: http://review.whamcloud.com/1838 Reviewed-by: Andreas Dilger Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/dt_object.h | 15 +++++++++++++ lustre/mdd/mdd_object.c | 4 +--- lustre/obdclass/dt_object.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index 197ff1e..b2e9021 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -731,10 +731,25 @@ struct dt_object *dt_store_open(const struct lu_env *env, const char *filename, struct lu_fid *fid); +struct dt_object *dt_find_or_create(const struct lu_env *env, + struct dt_device *dt, + const struct lu_fid *fid, + struct dt_object_format *dof, + struct lu_attr *attr); + struct dt_object *dt_locate(const struct lu_env *env, struct dt_device *dev, const struct lu_fid *fid); +static inline int dt_object_sync(const struct lu_env *env, + struct dt_object *o) +{ + LASSERT(o); + LASSERT(o->do_ops); + LASSERT(o->do_ops->do_object_sync); + return o->do_ops->do_object_sync(env, o); +} + int dt_declare_version_set(const struct lu_env *env, struct dt_object *o, struct thandle *th); void dt_version_set(const struct lu_env *env, struct dt_object *o, diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index dee2a93..2108ea3 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -2820,15 +2820,13 @@ out_unlock: static int mdd_object_sync(const struct lu_env *env, struct md_object *obj) { struct mdd_object *mdd_obj = md2mdd_obj(obj); - struct dt_object *next; if (mdd_object_exists(mdd_obj) == 0) { CERROR("%s: object "DFID" not found: rc = -2\n", mdd_obj_dev_name(mdd_obj),PFID(mdd_object_fid(mdd_obj))); return -ENOENT; } - next = mdd_object_child(mdd_obj); - return next->do_ops->do_object_sync(env, next); + return dt_object_sync(env, mdd_object_child(mdd_obj)); } const struct md_object_operations mdd_obj_ops = { diff --git a/lustre/obdclass/dt_object.c b/lustre/obdclass/dt_object.c index 1626b20..8765541 100644 --- a/lustre/obdclass/dt_object.c +++ b/lustre/obdclass/dt_object.c @@ -374,6 +374,61 @@ struct dt_object *dt_store_open(const struct lu_env *env, } EXPORT_SYMBOL(dt_store_open); +struct dt_object *dt_find_or_create(const struct lu_env *env, + struct dt_device *dt, + const struct lu_fid *fid, + struct dt_object_format *dof, + struct lu_attr *at) +{ + struct dt_object *dto; + struct thandle *th; + int rc; + + ENTRY; + + dto = dt_locate(env, dt, fid); + if (IS_ERR(dto)) + RETURN(dto); + + LASSERT(dto != NULL); + if (dt_object_exists(dto)) + RETURN(dto); + + th = dt_trans_create(env, dt); + if (IS_ERR(th)) + GOTO(out, rc = PTR_ERR(th)); + + rc = dt_declare_create(env, dto, at, NULL, dof, th); + if (rc) + GOTO(trans_stop, rc); + + rc = dt_trans_start_local(env, dt, th); + if (rc) + GOTO(trans_stop, rc); + + dt_write_lock(env, dto, 0); + if (dt_object_exists(dto)) + GOTO(unlock, rc = 0); + + CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid)); + + rc = dt_create(env, dto, at, NULL, dof, th); + if (rc) + GOTO(unlock, rc); + LASSERT(dt_object_exists(dto)); +unlock: + dt_write_unlock(env, dto); +trans_stop: + dt_trans_stop(env, dt, th); +out: + if (rc) { + lu_object_put(env, &dto->do_lu); + RETURN(ERR_PTR(rc)); + } + RETURN(dto); +} +EXPORT_SYMBOL(dt_find_or_create); + /* dt class init function. */ int dt_global_init(void) { -- 1.8.3.1