+int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
+ const struct lu_buf *buf, loff_t pos,
+ struct thandle_exec_args *ta, struct thandle *th,
+ struct object_update_reply *reply, int index,
+ const char *file, int line)
+{
+ struct tx_arg *arg;
+ int rc;
+
+ rc = dt_declare_record_write(env, dt_obj, buf, pos, th);
+ if (rc != 0)
+ return rc;
+
+ arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line);
+ if (IS_ERR(arg))
+ return PTR_ERR(arg);
+
+ lu_object_get(&dt_obj->do_lu);
+ arg->object = dt_obj;
+ arg->u.write.buf = *buf;
+ arg->u.write.pos = pos;
+ arg->reply = reply;
+ arg->index = index;
+ return 0;
+}
+
+static int out_tx_xattr_set_exec(const struct lu_env *env,
+ struct thandle *th,
+ struct tx_arg *arg)
+{
+ struct dt_object *dt_obj = arg->object;
+ int rc;
+
+ CDEBUG(D_INFO, "%s: set xattr buf %p name %s flag %d\n",
+ dt_obd_name(th->th_dev), arg->u.xattr_set.buf.lb_buf,
+ arg->u.xattr_set.name, arg->u.xattr_set.flags);
+
+ if (!lu_object_exists(&dt_obj->do_lu))
+ GOTO(out, rc = -ENOENT);
+
+ dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
+ rc = dt_xattr_set(env, dt_obj, &arg->u.xattr_set.buf,
+ arg->u.xattr_set.name, arg->u.xattr_set.flags,
+ th);
+ /**
+ * Ignore errors if this is LINK EA
+ **/
+ if (unlikely(rc != 0 &&
+ strcmp(arg->u.xattr_set.name, XATTR_NAME_LINK) == 0)) {
+ /* XXX: If the linkEA is overflow, then we need to notify the
+ * namespace LFSCK to skip "nlink" attribute verification
+ * on this object to avoid the "nlink" to be shrinked by
+ * wrong. It may be not good an interaction with LFSCK
+ * like this. We will consider to replace it with other
+ * mechanism in future. LU-5802. */
+ if (rc == -ENOSPC && arg->reply != NULL) {
+ struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
+
+ lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
+ LE_SKIP_NLINK, LFSCK_TYPE_NAMESPACE);
+ tgt_lfsck_in_notify(env,
+ tgt_ses_info(env)->tsi_tgt->lut_bottom, lr, th);
+ }
+
+ rc = 0;
+ }
+ dt_write_unlock(env, dt_obj);
+
+out:
+ CDEBUG(D_INFO, "%s: insert xattr set reply %p index %d: rc = %d\n",
+ dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
+
+ if (arg->reply != NULL)
+ object_update_result_insert(arg->reply, NULL, 0, arg->index,
+ rc);
+
+ return rc;
+}
+
+int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
+ const struct lu_buf *buf, const char *name,
+ int flags, struct thandle_exec_args *ta,
+ struct thandle *th,
+ struct object_update_reply *reply,
+ int index, const char *file, int line)
+{
+ struct tx_arg *arg;
+ int rc;
+
+ rc = dt_declare_xattr_set(env, dt_obj, buf, name, flags, th);
+ if (rc != 0)
+ return rc;
+
+ if (strcmp(name, XATTR_NAME_LINK) == 0 && reply != NULL) {
+ struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
+
+ /* XXX: If the linkEA is overflow, then we need to notify the
+ * namespace LFSCK to skip "nlink" attribute verification
+ * on this object to avoid the "nlink" to be shrinked by
+ * wrong. It may be not good an interaction with LFSCK
+ * like this. We will consider to replace it with other
+ * mechanism in future. LU-5802. */
+ lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
+ LE_SKIP_NLINK_DECLARE, LFSCK_TYPE_NAMESPACE);
+ rc = tgt_lfsck_in_notify(env,
+ tgt_ses_info(env)->tsi_tgt->lut_bottom,
+ lr, ta->ta_handle);
+ if (rc != 0)
+ return rc;
+ }
+
+ arg = tx_add_exec(ta, out_tx_xattr_set_exec, NULL, file, line);
+ if (IS_ERR(arg))
+ return PTR_ERR(arg);
+
+ lu_object_get(&dt_obj->do_lu);
+ arg->object = dt_obj;
+ arg->u.xattr_set.name = name;
+ arg->u.xattr_set.flags = flags;
+ arg->u.xattr_set.buf = *buf;
+ arg->reply = reply;
+ arg->index = index;
+ arg->u.xattr_set.csum = 0;
+ return 0;
+}
+
+static int out_tx_xattr_del_exec(const struct lu_env *env, struct thandle *th,
+ struct tx_arg *arg)
+{
+ struct dt_object *dt_obj = arg->object;
+ int rc;
+
+ CDEBUG(D_INFO, "%s: del xattr name '%s' on "DFID"\n",
+ dt_obd_name(th->th_dev), arg->u.xattr_set.name,
+ PFID(lu_object_fid(&dt_obj->do_lu)));
+
+ if (!lu_object_exists(&dt_obj->do_lu))
+ GOTO(out, rc = -ENOENT);
+
+ dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
+ rc = dt_xattr_del(env, dt_obj, arg->u.xattr_set.name,
+ th);
+ dt_write_unlock(env, dt_obj);
+out:
+ CDEBUG(D_INFO, "%s: insert xattr del reply %p index %d: rc = %d\n",
+ dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
+
+ if (arg->reply != NULL)
+ object_update_result_insert(arg->reply, NULL, 0, arg->index,
+ rc);
+
+ return rc;
+}
+
+int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
+ const char *name, struct thandle_exec_args *ta,
+ struct thandle *th,
+ struct object_update_reply *reply, int index,
+ const char *file, int line)
+{
+ struct tx_arg *arg;
+ int rc;
+
+ rc = dt_declare_xattr_del(env, dt_obj, name, th);
+ if (rc != 0)
+ return rc;
+
+ arg = tx_add_exec(ta, out_tx_xattr_del_exec, NULL, file, line);
+ if (IS_ERR(arg))
+ return PTR_ERR(arg);
+
+ lu_object_get(&dt_obj->do_lu);
+ arg->object = dt_obj;
+ arg->u.xattr_set.name = name;
+ arg->reply = reply;
+ arg->index = index;
+ return 0;
+}
+
+static int out_obj_ref_add(const struct lu_env *env,
+ struct dt_object *dt_obj,
+ struct thandle *th)
+{
+ int rc;
+
+ dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
+ rc = dt_ref_add(env, dt_obj, th);
+ dt_write_unlock(env, dt_obj);
+
+ return rc;
+}
+
+static int out_obj_ref_del(const struct lu_env *env,
+ struct dt_object *dt_obj,
+ struct thandle *th)
+{
+ int rc;
+
+ dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
+ rc = dt_ref_del(env, dt_obj, th);
+ dt_write_unlock(env, dt_obj);
+
+ return rc;
+}
+
+static int out_tx_ref_add_exec(const struct lu_env *env, struct thandle *th,
+ struct tx_arg *arg)
+{
+ struct dt_object *dt_obj = arg->object;
+ int rc;
+
+ rc = out_obj_ref_add(env, dt_obj, th);
+
+ CDEBUG(D_INFO, "%s: insert ref_add reply %p index %d: rc = %d\n",
+ dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
+
+ if (arg->reply != NULL)
+ object_update_result_insert(arg->reply, NULL, 0, arg->index,
+ rc);
+ return rc;
+}
+
+static int out_tx_ref_add_undo(const struct lu_env *env, struct thandle *th,
+ struct tx_arg *arg)
+{
+ return out_obj_ref_del(env, arg->object, th);
+}
+
+int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
+ struct thandle_exec_args *ta,
+ struct thandle *th,
+ struct object_update_reply *reply, int index,
+ const char *file, int line)
+{
+ struct tx_arg *arg;
+ int rc;
+
+ rc = dt_declare_ref_add(env, dt_obj, th);
+ if (rc != 0)
+ return rc;
+
+ arg = tx_add_exec(ta, out_tx_ref_add_exec, out_tx_ref_add_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;
+ return 0;