-static int out_obj_index_insert(const struct lu_env *env,
- struct dt_object *dt_obj,
- const struct dt_rec *rec,
- const struct dt_key *key,
- struct thandle *th)
-{
- int rc;
-
- CDEBUG(D_INFO, "%s: index insert "DFID" name: %s fid "DFID", type %u\n",
- dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
- (char *)key, PFID(((struct dt_insert_rec *)rec)->rec_fid),
- ((struct dt_insert_rec *)rec)->rec_type);
-
- if (dt_try_as_dir(env, dt_obj) == 0)
- return -ENOTDIR;
-
- dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
- rc = dt_insert(env, dt_obj, rec, key, th, NULL, 0);
- dt_write_unlock(env, dt_obj);
-
- return rc;
-}
-
-static int out_obj_index_delete(const struct lu_env *env,
- struct dt_object *dt_obj,
- const struct dt_key *key,
- struct thandle *th)
-{
- int rc;
-
- CDEBUG(D_INFO, "%s: index delete "DFID" name: %s\n",
- dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
- (char *)key);
-
- if (dt_try_as_dir(env, dt_obj) == 0)
- return -ENOTDIR;
-
- dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
- rc = dt_delete(env, dt_obj, key, th, NULL);
- dt_write_unlock(env, dt_obj);
-
- return rc;
-}
-
-static int out_tx_index_insert_exec(const struct lu_env *env,
- struct thandle *th, struct tx_arg *arg)
-{
- struct dt_object *dt_obj = arg->object;
- int rc;
-
- if (unlikely(!dt_object_exists(dt_obj)))
- RETURN(-ESTALE);
-
- rc = out_obj_index_insert(env, dt_obj,
- (const struct dt_rec *)&arg->u.insert.rec,
- arg->u.insert.key, th);
-
- CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
- dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
- object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
- return rc;
-}
-
-static int out_tx_index_insert_undo(const struct lu_env *env,
- struct thandle *th, struct tx_arg *arg)
-{
- return out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
-}
-
-static int __out_tx_index_insert(const struct lu_env *env,
- struct dt_object *dt_obj,
- const struct dt_rec *rec,
- const struct dt_key *key,
- struct thandle_exec_args *ta,
- struct object_update_reply *reply,
- int index, const char *file, int line)
-{
- struct tx_arg *arg;
- int rc;
-
- LASSERT(ta->ta_handle != NULL);
- if (dt_try_as_dir(env, dt_obj) == 0) {
- rc = -ENOTDIR;
- return rc;
- }
-
- rc = dt_declare_insert(env, dt_obj, rec, key, ta->ta_handle);
- if (rc != 0)
- return rc;
-
- arg = tx_add_exec(ta, out_tx_index_insert_exec,
- out_tx_index_insert_undo, file, line);
- if (IS_ERR(arg))
- return PTR_ERR(arg);
-
- lu_object_get(&dt_obj->do_lu);
- arg->object = dt_obj;
- arg->reply = reply;
- arg->index = index;
- arg->u.insert.rec = *(const struct dt_insert_rec *)rec;
- arg->u.insert.key = key;
-
- return 0;
-}
-