4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2014, Intel Corporation.
26 * lustre/target/out_lib.c
28 * Author: Di Wang <di.wang@intel.com>
29 * Author: Fan, Yong <fan.yong@intel.com>
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <lu_target.h>
35 #include <md_object.h>
36 #include <lustre_update.h>
38 #include <obd_class.h>
39 #include "tgt_internal.h"
41 #define OUT_UPDATE_BUFFER_SIZE_ADD 4096
42 #define OUT_UPDATE_BUFFER_SIZE_MAX (256 * 4096) /* 1MB update size now */
44 const char *update_op_str(__u16 opc)
46 static const char *opc_str[] = {
47 [OUT_START] = "start",
48 [OUT_CREATE] = "create",
49 [OUT_DESTROY] = "destroy",
50 [OUT_REF_ADD] = "ref_add",
51 [OUT_REF_DEL] = "ref_del" ,
52 [OUT_ATTR_SET] = "attr_set",
53 [OUT_ATTR_GET] = "attr_get",
54 [OUT_XATTR_SET] = "xattr_set",
55 [OUT_XATTR_GET] = "xattr_get",
56 [OUT_INDEX_LOOKUP] = "lookup",
57 [OUT_INDEX_INSERT] = "insert",
58 [OUT_INDEX_DELETE] = "delete",
59 [OUT_WRITE] = "write",
60 [OUT_XATTR_DEL] = "xattr_del",
61 [OUT_PUNCH] = "punch",
65 if (opc < ARRAY_SIZE(opc_str) && opc_str[opc] != NULL)
70 EXPORT_SYMBOL(update_op_str);
73 * Fill object update header
75 * Only fill the object update header, and parameters will be filled later
78 * \params[in] env execution environment
79 * \params[in] update object update to be filled
80 * \params[in] max_update_size maximum object update size, if the current
81 * update length equals or exceeds the size, it
83 * \params[in] update_op update type
84 * \params[in] fid object FID of the update
85 * \params[in] params_count the count of the update parameters
86 * \params[in] params_sizes the length of each parameters
88 * \retval 0 if packing succeeds.
89 * \retval -E2BIG if packing exceeds the maximum length.
91 int out_update_header_pack(const struct lu_env *env,
92 struct object_update *update, size_t max_update_size,
93 enum update_type update_op, const struct lu_fid *fid,
94 unsigned int param_count, __u16 *params_sizes)
96 struct object_update_param *param;
100 /* Check whether the packing exceeding the maxima update length */
101 update_size = sizeof(*update);
102 for (i = 0; i < param_count; i++)
103 update_size += cfs_size_round(sizeof(*param) + params_sizes[i]);
105 if (unlikely(update_size >= max_update_size))
108 update->ou_fid = *fid;
109 update->ou_type = update_op;
110 update->ou_params_count = param_count;
111 param = &update->ou_params[0];
112 for (i = 0; i < param_count; i++) {
113 param->oup_len = params_sizes[i];
114 param = (struct object_update_param *)((char *)param +
115 object_update_param_size(param));
122 * Packs one update into the update_buffer.
124 * \param[in] env execution environment
125 * \param[in] update update to be packed
126 * \param[in] max_update_size *maximum size of \a update
127 * \param[in] op update operation (enum update_type)
128 * \param[in] fid object FID for this update
129 * \param[in] param_count number of parameters for this update
130 * \param[in] param_sizes array of parameters length of this update
131 * \param[in] param_bufs parameter buffers
133 * \retval = 0 if updates packing succeeds
134 * \retval negative errno if updates packing fails
136 int out_update_pack(const struct lu_env *env, struct object_update *update,
137 size_t max_update_size, enum update_type op,
138 const struct lu_fid *fid, unsigned int param_count,
139 __u16 *param_sizes, const void **param_bufs)
141 struct object_update_param *param;
146 rc = out_update_header_pack(env, update, max_update_size, op, fid,
147 param_count, param_sizes);
151 param = &update->ou_params[0];
152 for (i = 0; i < param_count; i++) {
153 memcpy(¶m->oup_buf[0], param_bufs[i], param_sizes[i]);
154 param = (struct object_update_param *)((char *)param +
155 object_update_param_size(param));
160 EXPORT_SYMBOL(out_update_pack);
163 * Pack various updates into the update_buffer.
165 * The following functions pack different updates into the update_buffer
166 * So parameters of these API is basically same as its correspondent OSD/OSP
167 * API, for detail description of these parameters see osd_handler.c or
170 * \param[in] env execution environment
171 * \param[in] ubuf update buffer
172 * \param[in] fid fid of this object for the update
174 * \retval 0 if insertion succeeds.
175 * \retval negative errno if insertion fails.
177 int out_create_pack(const struct lu_env *env, struct object_update *update,
178 size_t max_update_size, const struct lu_fid *fid,
179 const struct lu_attr *attr, struct dt_allocation_hint *hint,
180 struct dt_object_format *dof)
183 __u16 sizes[2] = {sizeof(*obdo), 0};
185 const struct lu_fid *parent_fid = NULL;
189 if (hint != NULL && hint->dah_parent) {
190 parent_fid = lu_object_fid(&hint->dah_parent->do_lu);
191 sizes[1] = sizeof(*parent_fid);
195 rc = out_update_header_pack(env, update, max_update_size, OUT_CREATE,
196 fid, buf_count, sizes);
200 obdo = object_update_param_get(update, 0, NULL);
201 LASSERT(obdo != NULL);
203 obdo_from_la(obdo, attr, attr->la_valid);
204 lustre_set_wire_obdo(NULL, obdo, obdo);
206 if (parent_fid != NULL) {
209 tmp = object_update_param_get(update, 1, NULL);
210 LASSERT(tmp != NULL);
211 fid_cpu_to_le(tmp, parent_fid);
216 EXPORT_SYMBOL(out_create_pack);
218 int out_ref_del_pack(const struct lu_env *env, struct object_update *update,
219 size_t max_update_size, const struct lu_fid *fid)
221 return out_update_pack(env, update, max_update_size, OUT_REF_DEL, fid,
224 EXPORT_SYMBOL(out_ref_del_pack);
226 int out_ref_add_pack(const struct lu_env *env, struct object_update *update,
227 size_t max_update_size, const struct lu_fid *fid)
229 return out_update_pack(env, update, max_update_size, OUT_REF_ADD, fid,
232 EXPORT_SYMBOL(out_ref_add_pack);
234 int out_attr_set_pack(const struct lu_env *env, struct object_update *update,
235 size_t max_update_size, const struct lu_fid *fid,
236 const struct lu_attr *attr)
239 __u16 size = sizeof(*obdo);
243 rc = out_update_header_pack(env, update, max_update_size,
244 OUT_ATTR_SET, fid, 1, &size);
248 obdo = object_update_param_get(update, 0, NULL);
249 LASSERT(obdo != NULL);
251 obdo_from_la(obdo, attr, attr->la_valid);
252 lustre_set_wire_obdo(NULL, obdo, obdo);
256 EXPORT_SYMBOL(out_attr_set_pack);
258 int out_xattr_set_pack(const struct lu_env *env, struct object_update *update,
259 size_t max_update_size, const struct lu_fid *fid,
260 const struct lu_buf *buf, const char *name, __u32 flag)
262 __u16 sizes[3] = {strlen(name) + 1, buf->lb_len, sizeof(flag)};
263 const void *bufs[3] = {(char *)name, (char *)buf->lb_buf,
266 return out_update_pack(env, update, max_update_size, OUT_XATTR_SET,
267 fid, ARRAY_SIZE(sizes), sizes, bufs);
269 EXPORT_SYMBOL(out_xattr_set_pack);
271 int out_xattr_del_pack(const struct lu_env *env, struct object_update *update,
272 size_t max_update_size, const struct lu_fid *fid,
275 __u16 size = strlen(name) + 1;
277 return out_update_pack(env, update, max_update_size, OUT_XATTR_DEL,
278 fid, 1, &size, (const void **)&name);
280 EXPORT_SYMBOL(out_xattr_del_pack);
283 int out_index_insert_pack(const struct lu_env *env,
284 struct object_update *update,
285 size_t max_update_size, const struct lu_fid *fid,
286 const struct dt_rec *rec, const struct dt_key *key)
288 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
289 struct lu_fid rec_fid;
290 __u32 type = cpu_to_le32(rec1->rec_type);
291 __u16 sizes[3] = { strlen((char *)key) + 1,
294 const void *bufs[3] = { (char *)key,
298 fid_cpu_to_le(&rec_fid, rec1->rec_fid);
300 return out_update_pack(env, update, max_update_size, OUT_INDEX_INSERT,
301 fid, ARRAY_SIZE(sizes), sizes, bufs);
303 EXPORT_SYMBOL(out_index_insert_pack);
305 int out_index_delete_pack(const struct lu_env *env,
306 struct object_update *update,
307 size_t max_update_size, const struct lu_fid *fid,
308 const struct dt_key *key)
310 __u16 size = strlen((char *)key) + 1;
311 const void *buf = key;
313 return out_update_pack(env, update, max_update_size, OUT_INDEX_DELETE,
314 fid, 1, &size, &buf);
316 EXPORT_SYMBOL(out_index_delete_pack);
318 int out_object_destroy_pack(const struct lu_env *env,
319 struct object_update *update,
320 size_t max_update_size, const struct lu_fid *fid)
322 return out_update_pack(env, update, max_update_size, OUT_DESTROY, fid,
325 EXPORT_SYMBOL(out_object_destroy_pack);
327 int out_write_pack(const struct lu_env *env, struct object_update *update,
328 size_t max_update_size, const struct lu_fid *fid,
329 const struct lu_buf *buf, __u64 pos)
331 __u16 sizes[2] = {buf->lb_len, sizeof(pos)};
332 const void *bufs[2] = {(char *)buf->lb_buf, (char *)&pos};
335 pos = cpu_to_le64(pos);
337 rc = out_update_pack(env, update, max_update_size, OUT_WRITE, fid,
338 ARRAY_SIZE(sizes), sizes, bufs);
341 EXPORT_SYMBOL(out_write_pack);
344 * Pack various readonly updates into the update_buffer.
346 * The following update funcs are only used by read-only ops, lookup,
347 * getattr etc, so it does not need transaction here. Currently they
348 * are only used by OSP.
350 * \param[in] env execution environment
351 * \param[in] fid fid of this object for the update
352 * \param[in] ubuf update buffer
354 * \retval = 0 pack succeed.
357 int out_index_lookup_pack(const struct lu_env *env,
358 struct object_update *update,
359 size_t max_update_size, const struct lu_fid *fid,
360 struct dt_rec *rec, const struct dt_key *key)
362 const void *name = key;
363 __u16 size = strlen((char *)name) + 1;
365 return out_update_pack(env, update, max_update_size, OUT_INDEX_LOOKUP,
366 fid, 1, &size, &name);
368 EXPORT_SYMBOL(out_index_lookup_pack);
370 int out_attr_get_pack(const struct lu_env *env, struct object_update *update,
371 size_t max_update_size, const struct lu_fid *fid)
373 return out_update_pack(env, update, max_update_size, OUT_ATTR_GET,
376 EXPORT_SYMBOL(out_attr_get_pack);
378 int out_xattr_get_pack(const struct lu_env *env, struct object_update *update,
379 size_t max_update_size, const struct lu_fid *fid,
384 LASSERT(name != NULL);
385 size = strlen(name) + 1;
387 return out_update_pack(env, update, max_update_size, OUT_XATTR_GET,
388 fid, 1, &size, (const void **)&name);
390 EXPORT_SYMBOL(out_xattr_get_pack);
392 int out_read_pack(const struct lu_env *env, struct object_update *update,
393 size_t max_update_length, const struct lu_fid *fid,
394 size_t size, loff_t pos)
396 __u16 sizes[2] = {sizeof(size), sizeof(pos)};
397 const void *bufs[2] = {&size, &pos};
399 size = cpu_to_le64(size);
400 pos = cpu_to_le64(pos);
402 return out_update_pack(env, update, max_update_length, OUT_READ, fid,
403 ARRAY_SIZE(sizes), sizes, bufs);
405 EXPORT_SYMBOL(out_read_pack);
407 static int tx_extend_args(struct thandle_exec_args *ta, int new_alloc_ta)
409 struct tx_arg **new_ta;
413 if (ta->ta_alloc_args >= new_alloc_ta)
416 OBD_ALLOC(new_ta, sizeof(*new_ta) * new_alloc_ta);
420 for (i = 0; i < new_alloc_ta; i++) {
421 if (i < ta->ta_alloc_args) {
422 /* copy the old args to new one */
423 new_ta[i] = ta->ta_args[i];
425 OBD_ALLOC_PTR(new_ta[i]);
426 if (new_ta[i] == NULL)
427 GOTO(out, rc = -ENOMEM);
431 /* free the old args */
432 if (ta->ta_args != NULL)
433 OBD_FREE(ta->ta_args, sizeof(ta->ta_args[0]) *
436 ta->ta_args = new_ta;
437 ta->ta_alloc_args = new_alloc_ta;
440 for (i = 0; i < new_alloc_ta; i++) {
441 if (new_ta[i] != NULL)
442 OBD_FREE_PTR(new_ta[i]);
444 OBD_FREE(new_ta, sizeof(*new_ta) * new_alloc_ta);
449 #define TX_ALLOC_STEP 8
450 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
451 tx_exec_func_t func, tx_exec_func_t undo,
452 const char *file, int line)
458 LASSERT(func != NULL);
460 if (ta->ta_argno + 1 >= ta->ta_alloc_args) {
461 rc = tx_extend_args(ta, ta->ta_alloc_args + TX_ALLOC_STEP);
470 ta->ta_args[i]->exec_fn = func;
471 ta->ta_args[i]->undo_fn = undo;
472 ta->ta_args[i]->file = file;
473 ta->ta_args[i]->line = line;
475 return ta->ta_args[i];
478 static int out_obj_destroy(const struct lu_env *env, struct dt_object *dt_obj,
483 CDEBUG(D_INFO, "%s: destroy "DFID"\n", dt_obd_name(th->th_dev),
484 PFID(lu_object_fid(&dt_obj->do_lu)));
486 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
487 rc = dt_destroy(env, dt_obj, th);
488 dt_write_unlock(env, dt_obj);
494 * All of the xxx_undo will be used once execution failed,
495 * But because all of the required resource has been reserved in
496 * declare phase, i.e. if declare succeed, it should make sure
497 * the following executing phase succeed in anyway, so these undo
498 * should be useless for most of the time in Phase I
500 static int out_tx_create_undo(const struct lu_env *env, struct thandle *th,
505 rc = out_obj_destroy(env, arg->object, th);
507 CERROR("%s: undo failure, we are doomed!: rc = %d\n",
508 dt_obd_name(th->th_dev), rc);
512 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
515 struct dt_object *dt_obj = arg->object;
518 CDEBUG(D_OTHER, "%s: create "DFID": dof %u, mode %o\n",
519 dt_obd_name(th->th_dev),
520 PFID(lu_object_fid(&arg->object->do_lu)),
521 arg->u.create.dof.dof_type,
522 arg->u.create.attr.la_mode & S_IFMT);
524 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
525 rc = dt_create(env, dt_obj, &arg->u.create.attr,
526 &arg->u.create.hint, &arg->u.create.dof, th);
528 dt_write_unlock(env, dt_obj);
530 CDEBUG(D_INFO, "%s: insert create reply %p index %d: rc = %d\n",
531 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
533 if (arg->reply != NULL)
534 object_update_result_insert(arg->reply, NULL, 0, arg->index,
541 * Add create update to thandle
543 * Declare create updates and add the update to the thandle updates
546 * \param [in] env execution environment
547 * \param [in] obj object to be created
548 * \param [in] attr attributes of the creation
549 * \param [in] parent_fid the fid of the parent
550 * \param [in] dof dt object format of the creation
551 * \param [in] ta thandle execuation args where all of updates
552 * of the transaction are stored
553 * \param [in] th thandle for this update
554 * \param [in] reply reply of the updates
555 * \param [in] index index of the reply
556 * \param [in] file the file name where the function is called,
557 * which is only for debugging purpose.
558 * \param [in] line the line number where the funtion is called,
559 * which is only for debugging purpose.
561 * \retval 0 if updates is added successfully.
562 * \retval negative errno if update adding fails.
564 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
565 struct lu_attr *attr, struct lu_fid *parent_fid,
566 struct dt_object_format *dof,
567 struct thandle_exec_args *ta,
569 struct object_update_reply *reply,
570 int index, const char *file, int line)
575 rc = dt_declare_create(env, obj, attr, NULL, dof, th);
579 arg = tx_add_exec(ta, out_tx_create_exec, out_tx_create_undo, file,
584 /* release the object in out_trans_stop */
585 lu_object_get(&obj->do_lu);
587 arg->u.create.attr = *attr;
588 if (parent_fid != NULL)
589 arg->u.create.fid = *parent_fid;
590 memset(&arg->u.create.hint, 0, sizeof(arg->u.create.hint));
591 arg->u.create.dof = *dof;
598 static int out_tx_attr_set_undo(const struct lu_env *env,
599 struct thandle *th, struct tx_arg *arg)
601 CERROR("%s: attr set undo "DFID" unimplemented yet!: rc = %d\n",
602 dt_obd_name(th->th_dev),
603 PFID(lu_object_fid(&arg->object->do_lu)), -ENOTSUPP);
608 static int out_tx_attr_set_exec(const struct lu_env *env, struct thandle *th,
611 struct dt_object *dt_obj = arg->object;
614 CDEBUG(D_OTHER, "%s: attr set "DFID"\n", dt_obd_name(th->th_dev),
615 PFID(lu_object_fid(&dt_obj->do_lu)));
617 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
618 rc = dt_attr_set(env, dt_obj, &arg->u.attr_set.attr, th);
619 dt_write_unlock(env, dt_obj);
621 CDEBUG(D_INFO, "%s: insert attr_set reply %p index %d: rc = %d\n",
622 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
624 if (arg->reply != NULL)
625 object_update_result_insert(arg->reply, NULL, 0,
631 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
632 const struct lu_attr *attr,
633 struct thandle_exec_args *ta,
634 struct thandle *th, struct object_update_reply *reply,
635 int index, const char *file, int line)
640 rc = dt_declare_attr_set(env, dt_obj, attr, th);
644 arg = tx_add_exec(ta, out_tx_attr_set_exec, out_tx_attr_set_undo,
649 lu_object_get(&dt_obj->do_lu);
650 arg->object = dt_obj;
651 arg->u.attr_set.attr = *attr;
657 static int out_tx_write_exec(const struct lu_env *env, struct thandle *th,
660 struct dt_object *dt_obj = arg->object;
663 CDEBUG(D_INFO, "write "DFID" pos "LPU64" buf %p, len %lu\n",
664 PFID(lu_object_fid(&dt_obj->do_lu)), arg->u.write.pos,
665 arg->u.write.buf.lb_buf, (unsigned long)arg->u.write.buf.lb_len);
667 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
668 rc = dt_record_write(env, dt_obj, &arg->u.write.buf,
669 &arg->u.write.pos, th);
670 dt_write_unlock(env, dt_obj);
673 rc = arg->u.write.buf.lb_len;
675 if (arg->reply != NULL)
676 object_update_result_insert(arg->reply, NULL, 0, arg->index,
679 return rc > 0 ? 0 : rc;
682 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
683 const struct lu_buf *buf, loff_t pos,
684 struct thandle_exec_args *ta, struct thandle *th,
685 struct object_update_reply *reply, int index,
686 const char *file, int line)
691 rc = dt_declare_record_write(env, dt_obj, buf, pos, th);
695 arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line);
699 lu_object_get(&dt_obj->do_lu);
700 arg->object = dt_obj;
701 arg->u.write.buf = *buf;
702 arg->u.write.pos = pos;
708 static int out_tx_xattr_set_exec(const struct lu_env *env,
712 struct dt_object *dt_obj = arg->object;
715 CDEBUG(D_INFO, "%s: set xattr buf %p name %s flag %d\n",
716 dt_obd_name(th->th_dev), arg->u.xattr_set.buf.lb_buf,
717 arg->u.xattr_set.name, arg->u.xattr_set.flags);
719 if (!lu_object_exists(&dt_obj->do_lu))
720 GOTO(out, rc = -ENOENT);
722 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
723 rc = dt_xattr_set(env, dt_obj, &arg->u.xattr_set.buf,
724 arg->u.xattr_set.name, arg->u.xattr_set.flags,
727 * Ignore errors if this is LINK EA
729 if (unlikely(rc != 0 &&
730 strcmp(arg->u.xattr_set.name, XATTR_NAME_LINK) == 0)) {
731 /* XXX: If the linkEA is overflow, then we need to notify the
732 * namespace LFSCK to skip "nlink" attribute verification
733 * on this object to avoid the "nlink" to be shrinked by
734 * wrong. It may be not good an interaction with LFSCK
735 * like this. We will consider to replace it with other
736 * mechanism in future. LU-5802. */
737 if (rc == -ENOSPC && arg->reply != NULL) {
738 struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
740 lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
741 LE_SKIP_NLINK, LFSCK_TYPE_NAMESPACE);
742 tgt_lfsck_in_notify(env,
743 tgt_ses_info(env)->tsi_tgt->lut_bottom, lr, th);
748 dt_write_unlock(env, dt_obj);
751 CDEBUG(D_INFO, "%s: insert xattr set reply %p index %d: rc = %d\n",
752 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
754 if (arg->reply != NULL)
755 object_update_result_insert(arg->reply, NULL, 0, arg->index,
761 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
762 const struct lu_buf *buf, const char *name,
763 int flags, struct thandle_exec_args *ta,
765 struct object_update_reply *reply,
766 int index, const char *file, int line)
771 rc = dt_declare_xattr_set(env, dt_obj, buf, name, flags, th);
775 if (strcmp(name, XATTR_NAME_LINK) == 0 && reply != NULL) {
776 struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
778 /* XXX: If the linkEA is overflow, then we need to notify the
779 * namespace LFSCK to skip "nlink" attribute verification
780 * on this object to avoid the "nlink" to be shrinked by
781 * wrong. It may be not good an interaction with LFSCK
782 * like this. We will consider to replace it with other
783 * mechanism in future. LU-5802. */
784 lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
785 LE_SKIP_NLINK_DECLARE, LFSCK_TYPE_NAMESPACE);
786 rc = tgt_lfsck_in_notify(env,
787 tgt_ses_info(env)->tsi_tgt->lut_bottom,
793 arg = tx_add_exec(ta, out_tx_xattr_set_exec, NULL, file, line);
797 lu_object_get(&dt_obj->do_lu);
798 arg->object = dt_obj;
799 arg->u.xattr_set.name = name;
800 arg->u.xattr_set.flags = flags;
801 arg->u.xattr_set.buf = *buf;
804 arg->u.xattr_set.csum = 0;
808 static int out_tx_xattr_del_exec(const struct lu_env *env, struct thandle *th,
811 struct dt_object *dt_obj = arg->object;
814 CDEBUG(D_INFO, "%s: del xattr name '%s' on "DFID"\n",
815 dt_obd_name(th->th_dev), arg->u.xattr_set.name,
816 PFID(lu_object_fid(&dt_obj->do_lu)));
818 if (!lu_object_exists(&dt_obj->do_lu))
819 GOTO(out, rc = -ENOENT);
821 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
822 rc = dt_xattr_del(env, dt_obj, arg->u.xattr_set.name,
824 dt_write_unlock(env, dt_obj);
826 CDEBUG(D_INFO, "%s: insert xattr del reply %p index %d: rc = %d\n",
827 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
829 if (arg->reply != NULL)
830 object_update_result_insert(arg->reply, NULL, 0, arg->index,
836 int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
837 const char *name, struct thandle_exec_args *ta,
839 struct object_update_reply *reply, int index,
840 const char *file, int line)
845 rc = dt_declare_xattr_del(env, dt_obj, name, th);
849 arg = tx_add_exec(ta, out_tx_xattr_del_exec, NULL, file, line);
853 lu_object_get(&dt_obj->do_lu);
854 arg->object = dt_obj;
855 arg->u.xattr_set.name = name;
861 static int out_obj_ref_add(const struct lu_env *env,
862 struct dt_object *dt_obj,
867 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
868 rc = dt_ref_add(env, dt_obj, th);
869 dt_write_unlock(env, dt_obj);
874 static int out_obj_ref_del(const struct lu_env *env,
875 struct dt_object *dt_obj,
880 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
881 rc = dt_ref_del(env, dt_obj, th);
882 dt_write_unlock(env, dt_obj);
887 static int out_tx_ref_add_exec(const struct lu_env *env, struct thandle *th,
890 struct dt_object *dt_obj = arg->object;
893 rc = out_obj_ref_add(env, dt_obj, th);
895 CDEBUG(D_INFO, "%s: insert ref_add reply %p index %d: rc = %d\n",
896 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
898 if (arg->reply != NULL)
899 object_update_result_insert(arg->reply, NULL, 0, arg->index,
904 static int out_tx_ref_add_undo(const struct lu_env *env, struct thandle *th,
907 return out_obj_ref_del(env, arg->object, th);
910 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
911 struct thandle_exec_args *ta,
913 struct object_update_reply *reply, int index,
914 const char *file, int line)
919 rc = dt_declare_ref_add(env, dt_obj, th);
923 arg = tx_add_exec(ta, out_tx_ref_add_exec, out_tx_ref_add_undo, file,
928 lu_object_get(&dt_obj->do_lu);
929 arg->object = dt_obj;
935 static int out_tx_ref_del_exec(const struct lu_env *env, struct thandle *th,
938 struct dt_object *dt_obj = arg->object;
941 rc = out_obj_ref_del(env, dt_obj, th);
943 CDEBUG(D_INFO, "%s: insert ref_del reply %p index %d: rc = %d\n",
944 dt_obd_name(th->th_dev), arg->reply, arg->index, 0);
946 if (arg->reply != NULL)
947 object_update_result_insert(arg->reply, NULL, 0, arg->index,
953 static int out_tx_ref_del_undo(const struct lu_env *env, struct thandle *th,
956 return out_obj_ref_add(env, arg->object, th);
959 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
960 struct thandle_exec_args *ta,
962 struct object_update_reply *reply, int index,
963 const char *file, int line)
968 rc = dt_declare_ref_del(env, dt_obj, th);
972 arg = tx_add_exec(ta, out_tx_ref_del_exec, out_tx_ref_del_undo, file,
977 lu_object_get(&dt_obj->do_lu);
978 arg->object = dt_obj;
984 static int out_obj_index_insert(const struct lu_env *env,
985 struct dt_object *dt_obj,
986 const struct dt_rec *rec,
987 const struct dt_key *key,
992 CDEBUG(D_INFO, "%s: index insert "DFID" name: %s fid "DFID", type %u\n",
993 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
994 (char *)key, PFID(((struct dt_insert_rec *)rec)->rec_fid),
995 ((struct dt_insert_rec *)rec)->rec_type);
997 if (dt_try_as_dir(env, dt_obj) == 0)
1000 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
1001 rc = dt_insert(env, dt_obj, rec, key, th, 0);
1002 dt_write_unlock(env, dt_obj);
1007 static int out_obj_index_delete(const struct lu_env *env,
1008 struct dt_object *dt_obj,
1009 const struct dt_key *key,
1014 CDEBUG(D_INFO, "%s: index delete "DFID" name: %s\n",
1015 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
1018 if (dt_try_as_dir(env, dt_obj) == 0)
1021 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
1022 rc = dt_delete(env, dt_obj, key, th);
1023 dt_write_unlock(env, dt_obj);
1028 static int out_tx_index_insert_exec(const struct lu_env *env,
1029 struct thandle *th, struct tx_arg *arg)
1031 struct dt_object *dt_obj = arg->object;
1034 if (unlikely(!dt_object_exists(dt_obj)))
1037 rc = out_obj_index_insert(env, dt_obj,
1038 (const struct dt_rec *)&arg->u.insert.rec,
1039 arg->u.insert.key, th);
1041 CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
1042 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1044 if (arg->reply != NULL)
1045 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1050 static int out_tx_index_insert_undo(const struct lu_env *env,
1051 struct thandle *th, struct tx_arg *arg)
1053 return out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1056 int out_index_insert_add_exec(const struct lu_env *env,
1057 struct dt_object *dt_obj,
1058 const struct dt_rec *rec,
1059 const struct dt_key *key,
1060 struct thandle_exec_args *ta,
1062 struct object_update_reply *reply,
1063 int index, const char *file, int line)
1068 if (dt_try_as_dir(env, dt_obj) == 0) {
1073 rc = dt_declare_insert(env, dt_obj, rec, key, th);
1077 arg = tx_add_exec(ta, out_tx_index_insert_exec,
1078 out_tx_index_insert_undo, file, line);
1080 return PTR_ERR(arg);
1082 lu_object_get(&dt_obj->do_lu);
1083 arg->object = dt_obj;
1086 arg->u.insert.rec = *(const struct dt_insert_rec *)rec;
1087 arg->u.insert.key = key;
1092 static int out_tx_index_delete_exec(const struct lu_env *env,
1098 rc = out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1100 CDEBUG(D_INFO, "%s: delete idx insert reply %p index %d: rc = %d\n",
1101 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1103 if (arg->reply != NULL)
1104 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1110 static int out_tx_index_delete_undo(const struct lu_env *env,
1114 CERROR("%s: Oops, can not rollback index_delete yet: rc = %d\n",
1115 dt_obd_name(th->th_dev), -ENOTSUPP);
1119 int out_index_delete_add_exec(const struct lu_env *env,
1120 struct dt_object *dt_obj,
1121 const struct dt_key *key,
1122 struct thandle_exec_args *ta,
1124 struct object_update_reply *reply,
1125 int index, const char *file, int line)
1130 if (dt_try_as_dir(env, dt_obj) == 0) {
1135 LASSERT(ta->ta_handle != NULL);
1136 rc = dt_declare_delete(env, dt_obj, key, th);
1140 arg = tx_add_exec(ta, out_tx_index_delete_exec,
1141 out_tx_index_delete_undo, file, line);
1143 return PTR_ERR(arg);
1145 lu_object_get(&dt_obj->do_lu);
1146 arg->object = dt_obj;
1149 arg->u.insert.key = key;
1153 static int out_tx_destroy_exec(const struct lu_env *env, struct thandle *th,
1156 struct dt_object *dt_obj = arg->object;
1159 rc = out_obj_destroy(env, dt_obj, th);
1161 CDEBUG(D_INFO, "%s: insert destroy reply %p index %d: rc = %d\n",
1162 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1164 if (arg->reply != NULL)
1165 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1171 static int out_tx_destroy_undo(const struct lu_env *env, struct thandle *th,
1174 CERROR("%s: not support destroy undo yet!: rc = %d\n",
1175 dt_obd_name(th->th_dev), -ENOTSUPP);
1179 int out_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
1180 struct thandle_exec_args *ta, struct thandle *th,
1181 struct object_update_reply *reply,
1182 int index, const char *file, int line)
1187 rc = dt_declare_destroy(env, dt_obj, th);
1191 arg = tx_add_exec(ta, out_tx_destroy_exec, out_tx_destroy_undo,
1194 return PTR_ERR(arg);
1196 lu_object_get(&dt_obj->do_lu);
1197 arg->object = dt_obj;