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,
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 = {
}
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)
{