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, 2017, 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 <lustre_obdo.h>
36 #include <lustre_update.h>
37 #include <md_object.h>
39 #include <obd_class.h>
40 #include <lustre_linkea.h>
42 #include "tgt_internal.h"
44 const char *update_op_str(__u16 opc)
46 static const char *const 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_XATTR_LIST] = "xattr_list",
57 [OUT_INDEX_LOOKUP] = "lookup",
58 [OUT_INDEX_INSERT] = "insert",
59 [OUT_INDEX_DELETE] = "delete",
60 [OUT_WRITE] = "write",
61 [OUT_XATTR_DEL] = "xattr_del",
62 [OUT_PUNCH] = "punch",
67 if (opc < ARRAY_SIZE(opc_str) && opc_str[opc] != NULL)
72 EXPORT_SYMBOL(update_op_str);
75 * Fill object update header
77 * Only fill the object update header, and parameters will be filled later
80 * \params[in] env execution environment
81 * \params[in] update object update to be filled
82 * \params[in,out] max_update_size maximum object update size, if the
83 * current update length equals or
84 * exceeds the size, it will return -E2BIG.
85 * \params[in] update_op update type
86 * \params[in] fid object FID of the update
87 * \params[in] param_count the count of the update parameters
88 * \params[in] param_sizes the length of each parameters
90 * \retval 0 if packing succeeds.
91 * \retval -E2BIG if packing exceeds the maximum length.
93 int out_update_header_pack(const struct lu_env *env,
94 struct object_update *update,
95 size_t *max_update_size,
96 enum update_type update_op,
97 const struct lu_fid *fid,
98 unsigned int param_count,
102 struct object_update_param *param;
106 if (reply_size >= LNET_MTU)
109 /* Check whether the packing exceeding the maxima update length */
110 update_size = sizeof(*update);
111 for (i = 0; i < param_count; i++)
112 update_size += cfs_size_round(sizeof(*param) + param_sizes[i]);
114 if (unlikely(update_size >= *max_update_size)) {
115 *max_update_size = update_size;
119 update->ou_fid = *fid;
120 update->ou_type = update_op;
121 update->ou_params_count = param_count;
122 update->ou_result_size = reply_size;
123 param = &update->ou_params[0];
124 for (i = 0; i < param_count; i++) {
125 param->oup_len = param_sizes[i];
126 param = (struct object_update_param *)((char *)param +
127 object_update_param_size(param));
134 * Packs one update into the update_buffer.
136 * \param[in] env execution environment
137 * \param[in] update update to be packed
138 * \param[in] max_update_size *maximum size of \a update
139 * \param[in] op update operation (enum update_type)
140 * \param[in] fid object FID for this update
141 * \param[in] param_count number of parameters for this update
142 * \param[in] param_sizes array of parameters length of this update
143 * \param[in] param_bufs parameter buffers
145 * \retval = 0 if updates packing succeeds
146 * \retval negative errno if updates packing fails
148 int out_update_pack(const struct lu_env *env, struct object_update *update,
149 size_t *max_update_size, enum update_type op,
150 const struct lu_fid *fid, unsigned int param_count,
151 __u16 *param_sizes, const void **param_bufs,
154 struct object_update_param *param;
159 rc = out_update_header_pack(env, update, max_update_size, op, fid,
160 param_count, param_sizes, reply_size);
164 param = &update->ou_params[0];
165 for (i = 0; i < param_count; i++) {
166 memcpy(¶m->oup_buf[0], param_bufs[i], param_sizes[i]);
167 param = (struct object_update_param *)((char *)param +
168 object_update_param_size(param));
173 EXPORT_SYMBOL(out_update_pack);
176 * Pack various updates into the update_buffer.
178 * The following functions pack different updates into the update_buffer
179 * So parameters of these API is basically same as its correspondent OSD/OSP
180 * API, for detail description of these parameters see osd_handler.c or
183 * \param[in] env execution environment
184 * \param[in] ubuf update buffer
185 * \param[in] fid fid of this object for the update
187 * \retval 0 if insertion succeeds.
188 * \retval negative errno if insertion fails.
190 int out_create_pack(const struct lu_env *env, struct object_update *update,
191 size_t *max_update_size, const struct lu_fid *fid,
192 const struct lu_attr *attr, struct dt_allocation_hint *hint,
193 struct dt_object_format *dof)
196 __u16 sizes[2] = {sizeof(*obdo), 0};
198 const struct lu_fid *parent_fid = NULL;
202 if (hint != NULL && hint->dah_parent) {
203 parent_fid = lu_object_fid(&hint->dah_parent->do_lu);
204 sizes[1] = sizeof(*parent_fid);
208 rc = out_update_header_pack(env, update, max_update_size, OUT_CREATE,
209 fid, buf_count, sizes, 0);
213 obdo = object_update_param_get(update, 0, NULL);
215 RETURN(PTR_ERR(obdo));
218 obdo_from_la(obdo, attr, attr->la_valid);
220 if (parent_fid != NULL) {
223 tmp = object_update_param_get(update, 1, NULL);
225 RETURN(PTR_ERR(tmp));
227 fid_cpu_to_le(tmp, parent_fid);
232 EXPORT_SYMBOL(out_create_pack);
234 int out_ref_del_pack(const struct lu_env *env, struct object_update *update,
235 size_t *max_update_size, const struct lu_fid *fid)
237 return out_update_pack(env, update, max_update_size, OUT_REF_DEL, fid,
240 EXPORT_SYMBOL(out_ref_del_pack);
242 int out_ref_add_pack(const struct lu_env *env, struct object_update *update,
243 size_t *max_update_size, const struct lu_fid *fid)
245 return out_update_pack(env, update, max_update_size, OUT_REF_ADD, fid,
248 EXPORT_SYMBOL(out_ref_add_pack);
250 int out_attr_set_pack(const struct lu_env *env, struct object_update *update,
251 size_t *max_update_size, const struct lu_fid *fid,
252 const struct lu_attr *attr)
255 __u16 size = sizeof(*obdo);
259 rc = out_update_header_pack(env, update, max_update_size,
260 OUT_ATTR_SET, fid, 1, &size, 0);
264 obdo = object_update_param_get(update, 0, NULL);
266 RETURN(PTR_ERR(obdo));
269 obdo_from_la(obdo, attr, attr->la_valid);
273 EXPORT_SYMBOL(out_attr_set_pack);
275 int out_xattr_set_pack(const struct lu_env *env, struct object_update *update,
276 size_t *max_update_size, const struct lu_fid *fid,
277 const struct lu_buf *buf, const char *name, __u32 flag)
279 __u16 sizes[3] = {strlen(name) + 1, buf->lb_len, sizeof(flag)};
280 const void *bufs[3] = {(char *)name, (char *)buf->lb_buf,
283 return out_update_pack(env, update, max_update_size, OUT_XATTR_SET,
284 fid, ARRAY_SIZE(sizes), sizes, bufs, 0);
286 EXPORT_SYMBOL(out_xattr_set_pack);
288 int out_xattr_del_pack(const struct lu_env *env, struct object_update *update,
289 size_t *max_update_size, const struct lu_fid *fid,
292 __u16 size = strlen(name) + 1;
294 return out_update_pack(env, update, max_update_size, OUT_XATTR_DEL,
295 fid, 1, &size, (const void **)&name, 0);
297 EXPORT_SYMBOL(out_xattr_del_pack);
299 int out_index_insert_pack(const struct lu_env *env,
300 struct object_update *update,
301 size_t *max_update_size, const struct lu_fid *fid,
302 const struct dt_rec *rec, const struct dt_key *key)
304 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
305 struct lu_fid rec_fid;
306 __u32 type = cpu_to_le32(rec1->rec_type);
307 __u16 sizes[3] = { strlen((char *)key) + 1,
310 const void *bufs[3] = { (char *)key,
314 fid_cpu_to_le(&rec_fid, rec1->rec_fid);
316 return out_update_pack(env, update, max_update_size, OUT_INDEX_INSERT,
317 fid, ARRAY_SIZE(sizes), sizes, bufs, 0);
319 EXPORT_SYMBOL(out_index_insert_pack);
321 int out_index_delete_pack(const struct lu_env *env,
322 struct object_update *update,
323 size_t *max_update_size, const struct lu_fid *fid,
324 const struct dt_key *key)
326 __u16 size = strlen((char *)key) + 1;
327 const void *buf = key;
329 return out_update_pack(env, update, max_update_size, OUT_INDEX_DELETE,
330 fid, 1, &size, &buf, 0);
332 EXPORT_SYMBOL(out_index_delete_pack);
334 int out_destroy_pack(const struct lu_env *env, struct object_update *update,
335 size_t *max_update_size, const struct lu_fid *fid)
337 return out_update_pack(env, update, max_update_size, OUT_DESTROY, fid,
340 EXPORT_SYMBOL(out_destroy_pack);
342 int out_write_pack(const struct lu_env *env, struct object_update *update,
343 size_t *max_update_size, const struct lu_fid *fid,
344 const struct lu_buf *buf, __u64 pos)
346 __u16 sizes[2] = {buf->lb_len, sizeof(pos)};
347 const void *bufs[2] = {(char *)buf->lb_buf, (char *)&pos};
350 pos = cpu_to_le64(pos);
352 rc = out_update_pack(env, update, max_update_size, OUT_WRITE, fid,
353 ARRAY_SIZE(sizes), sizes, bufs, 0);
356 EXPORT_SYMBOL(out_write_pack);
359 * Pack various readonly updates into the update_buffer.
361 * The following update funcs are only used by read-only ops, lookup,
362 * getattr etc, so it does not need transaction here. Currently they
363 * are only used by OSP.
365 * \param[in] env execution environment
366 * \param[in] fid fid of this object for the update
367 * \param[in] ubuf update buffer
369 * \retval = 0 pack succeed.
372 int out_index_lookup_pack(const struct lu_env *env,
373 struct object_update *update,
374 size_t *max_update_size, const struct lu_fid *fid,
375 struct dt_rec *rec, const struct dt_key *key)
377 const void *name = key;
378 __u16 size = strlen((char *)name) + 1;
380 /* XXX: this shouldn't be hardcoded */
381 return out_update_pack(env, update, max_update_size, OUT_INDEX_LOOKUP,
382 fid, 1, &size, &name, 256);
384 EXPORT_SYMBOL(out_index_lookup_pack);
386 int out_attr_get_pack(const struct lu_env *env, struct object_update *update,
387 size_t *max_update_size, const struct lu_fid *fid)
389 return out_update_pack(env, update, max_update_size, OUT_ATTR_GET,
390 fid, 0, NULL, NULL, sizeof(struct obdo));
392 EXPORT_SYMBOL(out_attr_get_pack);
394 int out_xattr_get_pack(const struct lu_env *env, struct object_update *update,
395 size_t *max_update_size, const struct lu_fid *fid,
396 const char *name, const int bufsize)
400 LASSERT(name != NULL);
401 size = strlen(name) + 1;
403 return out_update_pack(env, update, max_update_size, OUT_XATTR_GET,
404 fid, 1, &size, (const void **)&name, bufsize);
406 EXPORT_SYMBOL(out_xattr_get_pack);
408 int out_xattr_list_pack(const struct lu_env *env, struct object_update *update,
409 size_t *max_update_size, const struct lu_fid *fid,
412 return out_update_pack(env, update, max_update_size, OUT_XATTR_LIST,
413 fid, 0, NULL, NULL, bufsize);
415 EXPORT_SYMBOL(out_xattr_list_pack);
417 int out_read_pack(const struct lu_env *env, struct object_update *update,
418 size_t *max_update_size, const struct lu_fid *fid,
419 size_t size, loff_t pos)
421 __u16 sizes[2] = {sizeof(size), sizeof(pos)};
422 const void *bufs[2] = {&size, &pos};
425 size = cpu_to_le64(size);
426 pos = cpu_to_le64(pos);
428 return out_update_pack(env, update, max_update_size, OUT_READ, fid,
429 ARRAY_SIZE(sizes), sizes, bufs, size);
431 EXPORT_SYMBOL(out_read_pack);
433 static int tx_extend_args(struct thandle_exec_args *ta, int new_alloc_ta)
435 struct tx_arg **new_ta;
439 if (ta->ta_alloc_args >= new_alloc_ta)
442 OBD_ALLOC_PTR_ARRAY(new_ta, new_alloc_ta);
446 for (i = 0; i < new_alloc_ta; i++) {
447 if (i < ta->ta_alloc_args) {
448 /* copy the old args to new one */
449 new_ta[i] = ta->ta_args[i];
451 OBD_ALLOC_PTR(new_ta[i]);
452 if (new_ta[i] == NULL)
453 GOTO(out, rc = -ENOMEM);
457 /* free the old args */
458 if (ta->ta_args != NULL)
459 OBD_FREE_PTR_ARRAY(ta->ta_args, ta->ta_alloc_args);
461 ta->ta_args = new_ta;
462 ta->ta_alloc_args = new_alloc_ta;
465 for (i = 0; i < new_alloc_ta; i++) {
466 if (new_ta[i] != NULL)
467 OBD_FREE_PTR(new_ta[i]);
469 OBD_FREE_PTR_ARRAY(new_ta, new_alloc_ta);
474 #define TX_ALLOC_STEP 8
475 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
476 tx_exec_func_t func, tx_exec_func_t undo,
477 const char *file, int line)
483 LASSERT(func != NULL);
485 if (ta->ta_argno + 1 >= ta->ta_alloc_args) {
486 rc = tx_extend_args(ta, ta->ta_alloc_args + TX_ALLOC_STEP);
495 ta->ta_args[i]->exec_fn = func;
496 ta->ta_args[i]->undo_fn = undo;
497 ta->ta_args[i]->file = file;
498 ta->ta_args[i]->line = line;
500 return ta->ta_args[i];
503 static int out_obj_destroy(const struct lu_env *env, struct dt_object *dt_obj,
508 CDEBUG(D_INFO, "%s: destroy "DFID"\n", dt_obd_name(th->th_dev),
509 PFID(lu_object_fid(&dt_obj->do_lu)));
511 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
512 rc = dt_destroy(env, dt_obj, th);
513 dt_write_unlock(env, dt_obj);
519 * All of the xxx_undo will be used once execution failed,
520 * But because all of the required resource has been reserved in
521 * declare phase, i.e. if declare succeed, it should make sure
522 * the following executing phase succeed in anyway, so these undo
523 * should be useless for most of the time in Phase I
525 static int out_tx_create_undo(const struct lu_env *env, struct thandle *th,
530 rc = out_obj_destroy(env, arg->object, th);
532 CERROR("%s: undo failure, we are doomed!: rc = %d\n",
533 dt_obd_name(th->th_dev), rc);
537 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
540 struct dt_object *dt_obj = arg->object;
543 CDEBUG(D_OTHER, "%s: create "DFID": dof %u, mode %o\n",
544 dt_obd_name(th->th_dev),
545 PFID(lu_object_fid(&arg->object->do_lu)),
546 arg->u.create.dof.dof_type,
547 arg->u.create.attr.la_mode & S_IFMT);
549 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
550 rc = dt_create(env, dt_obj, &arg->u.create.attr,
551 &arg->u.create.hint, &arg->u.create.dof, th);
553 dt_write_unlock(env, dt_obj);
555 CDEBUG(D_INFO, "%s: insert create reply %p index %d: rc = %d\n",
556 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
558 if (arg->reply != NULL)
559 object_update_result_insert(arg->reply, NULL, 0, arg->index,
566 * Add create update to thandle
568 * Declare create updates and add the update to the thandle updates
571 * \param [in] env execution environment
572 * \param [in] obj object to be created
573 * \param [in] attr attributes of the creation
574 * \param [in] parent_fid the fid of the parent
575 * \param [in] dof dt object format of the creation
576 * \param [in] ta thandle execuation args where all of updates
577 * of the transaction are stored
578 * \param [in] th thandle for this update
579 * \param [in] reply reply of the updates
580 * \param [in] index index of the reply
581 * \param [in] file the file name where the function is called,
582 * which is only for debugging purpose.
583 * \param [in] line the line number where the funtion is called,
584 * which is only for debugging purpose.
586 * \retval 0 if updates is added successfully.
587 * \retval negative errno if update adding fails.
589 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
590 struct lu_attr *attr, struct lu_fid *parent_fid,
591 struct dt_object_format *dof,
592 struct thandle_exec_args *ta,
594 struct object_update_reply *reply,
595 int index, const char *file, int line)
600 /* LU-13653: ignore quota for DNE directory creation */
601 if (dof->dof_type == DFT_DIR)
602 th->th_ignore_quota = 1;
604 rc = dt_declare_create(env, obj, attr, NULL, dof, th);
608 arg = tx_add_exec(ta, out_tx_create_exec, out_tx_create_undo, file,
613 /* release the object in out_trans_stop */
614 lu_object_get(&obj->do_lu);
616 arg->u.create.attr = *attr;
617 if (parent_fid != NULL)
618 arg->u.create.fid = *parent_fid;
619 memset(&arg->u.create.hint, 0, sizeof(arg->u.create.hint));
620 arg->u.create.dof = *dof;
627 static int out_tx_attr_set_undo(const struct lu_env *env,
628 struct thandle *th, struct tx_arg *arg)
630 CERROR("%s: attr set undo "DFID" unimplemented yet!: rc = %d\n",
631 dt_obd_name(th->th_dev),
632 PFID(lu_object_fid(&arg->object->do_lu)), -ENOTSUPP);
637 static int out_tx_attr_set_exec(const struct lu_env *env, struct thandle *th,
640 struct dt_object *dt_obj = arg->object;
643 CDEBUG(D_OTHER, "%s: attr set "DFID"\n", dt_obd_name(th->th_dev),
644 PFID(lu_object_fid(&dt_obj->do_lu)));
646 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
647 rc = dt_attr_set(env, dt_obj, &arg->u.attr_set.attr, th);
648 dt_write_unlock(env, dt_obj);
650 CDEBUG(D_INFO, "%s: insert attr_set reply %p index %d: rc = %d\n",
651 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
653 if (arg->reply != NULL)
654 object_update_result_insert(arg->reply, NULL, 0,
660 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
661 const struct lu_attr *attr,
662 struct thandle_exec_args *ta,
663 struct thandle *th, struct object_update_reply *reply,
664 int index, const char *file, int line)
669 rc = dt_declare_attr_set(env, dt_obj, attr, th);
673 if (attr->la_valid & LA_FLAGS &&
674 attr->la_flags & LUSTRE_SET_SYNC_FL)
677 arg = tx_add_exec(ta, out_tx_attr_set_exec, out_tx_attr_set_undo,
682 lu_object_get(&dt_obj->do_lu);
683 arg->object = dt_obj;
684 arg->u.attr_set.attr = *attr;
690 static int out_tx_write_exec(const struct lu_env *env, struct thandle *th,
693 struct dt_object *dt_obj = arg->object;
696 CDEBUG(D_INFO, "write "DFID" pos %llu buf %p, len %lu\n",
697 PFID(lu_object_fid(&dt_obj->do_lu)), arg->u.write.pos,
698 arg->u.write.buf.lb_buf, (unsigned long)arg->u.write.buf.lb_len);
700 if (OBD_FAIL_CHECK(OBD_FAIL_OUT_ENOSPC)) {
703 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
704 rc = dt_record_write(env, dt_obj, &arg->u.write.buf,
705 &arg->u.write.pos, th);
706 dt_write_unlock(env, dt_obj);
709 rc = arg->u.write.buf.lb_len;
712 if (arg->reply != NULL)
713 object_update_result_insert(arg->reply, NULL, 0, arg->index,
716 return rc > 0 ? 0 : rc;
719 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
720 const struct lu_buf *buf, loff_t pos,
721 struct thandle_exec_args *ta, struct thandle *th,
722 struct object_update_reply *reply, int index,
723 const char *file, int line)
728 rc = dt_declare_record_write(env, dt_obj, buf, pos, th);
732 arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line);
736 lu_object_get(&dt_obj->do_lu);
737 arg->object = dt_obj;
738 arg->u.write.buf = *buf;
739 arg->u.write.pos = pos;
745 static int out_tx_xattr_set_exec(const struct lu_env *env,
749 struct dt_object *dt_obj = arg->object;
753 CDEBUG(D_INFO, "%s: set xattr buf %p name %s flag %d\n",
754 dt_obd_name(th->th_dev), arg->u.xattr_set.buf.lb_buf,
755 arg->u.xattr_set.name, arg->u.xattr_set.flags);
757 if (!lu_object_exists(&dt_obj->do_lu) ||
758 OBD_FAIL_PRECHECK(OBD_FAIL_OUT_OBJECT_MISS)) {
761 struct linkea_data ldata = { 0 };
764 ldata.ld_buf = &arg->u.xattr_set.buf;
765 if (strcmp(arg->u.xattr_set.name, XATTR_NAME_LINK) == 0) {
766 struct link_ea_header *leh;
769 rc = linkea_init(&ldata);
771 GOTO(out, rc == -ENODATA ? -EINVAL : rc);
774 LASSERT(leh != NULL);
776 /* If the new linkEA contains overflow timestamp,
779 * 1. The old linkEA for the object has already
780 * overflowed before current setting, the new
781 * linkEA does not contains new link entry. So
782 * the linkEA overflow timestamp is unchanged.
784 * 2. There are new link entry in the new linkEA,
785 * so its overflow timestamp is differnt from
786 * the old one. Usually, the overstamp in the
787 * given linkEA is newer. But because of clock
788 * drift among MDTs, the timestamp may become
789 * older. So here, we convert the timestamp to
790 * the server local time. Then namespace LFSCK
791 * that uses local time can handle it easily. */
792 if (unlikely(leh->leh_overflow_time)) {
793 struct lu_buf tbuf = { 0 };
796 lu_buf_alloc(&tbuf, MAX_LINKEA_SIZE);
797 if (tbuf.lb_buf == NULL)
798 GOTO(unlock, rc = -ENOMEM);
800 rc = dt_xattr_get(env, dt_obj, &tbuf,
803 struct linkea_data tdata = { 0 };
805 tdata.ld_buf = &tbuf;
806 rc = linkea_init(&tdata);
807 if (rc || leh->leh_overflow_time !=
808 tdata.ld_leh->leh_overflow_time)
811 /* Update the timestamp by force if
812 * fail to load the old linkEA. */
818 leh->leh_overflow_time = ktime_get_real_seconds();
819 if (unlikely(!leh->leh_overflow_time))
820 leh->leh_overflow_time++;
827 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
830 rc = dt_xattr_set(env, dt_obj, ldata.ld_buf,
831 arg->u.xattr_set.name, arg->u.xattr_set.flags,
833 if (unlikely(rc == -ENOSPC && linkea)) {
834 rc = linkea_overflow_shrink(&ldata);
835 if (likely(rc > 0)) {
836 arg->u.xattr_set.buf.lb_len = rc;
842 dt_write_unlock(env, dt_obj);
848 CDEBUG(D_INFO, "%s: insert xattr set reply %p index %d: rc = %d\n",
849 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
851 if (arg->reply != NULL)
852 object_update_result_insert(arg->reply, NULL, 0, arg->index,
858 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
859 const struct lu_buf *buf, const char *name,
860 int flags, struct thandle_exec_args *ta,
862 struct object_update_reply *reply,
863 int index, const char *file, int line)
868 rc = dt_declare_xattr_set(env, dt_obj, buf, name, flags, th);
872 arg = tx_add_exec(ta, out_tx_xattr_set_exec, NULL, file, line);
876 lu_object_get(&dt_obj->do_lu);
877 arg->object = dt_obj;
878 arg->u.xattr_set.name = name;
879 arg->u.xattr_set.flags = flags;
880 arg->u.xattr_set.buf = *buf;
883 arg->u.xattr_set.csum = 0;
887 static int out_tx_xattr_del_exec(const struct lu_env *env, struct thandle *th,
890 struct dt_object *dt_obj = arg->object;
893 CDEBUG(D_INFO, "%s: del xattr name '%s' on "DFID"\n",
894 dt_obd_name(th->th_dev), arg->u.xattr_set.name,
895 PFID(lu_object_fid(&dt_obj->do_lu)));
897 if (!lu_object_exists(&dt_obj->do_lu))
898 GOTO(out, rc = -ENOENT);
900 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
901 rc = dt_xattr_del(env, dt_obj, arg->u.xattr_set.name,
903 dt_write_unlock(env, dt_obj);
905 CDEBUG(D_INFO, "%s: insert xattr del reply %p index %d: rc = %d\n",
906 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
908 if (arg->reply != NULL)
909 object_update_result_insert(arg->reply, NULL, 0, arg->index,
915 int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
916 const char *name, struct thandle_exec_args *ta,
918 struct object_update_reply *reply, int index,
919 const char *file, int line)
924 rc = dt_declare_xattr_del(env, dt_obj, name, th);
928 arg = tx_add_exec(ta, out_tx_xattr_del_exec, NULL, file, line);
932 lu_object_get(&dt_obj->do_lu);
933 arg->object = dt_obj;
934 arg->u.xattr_set.name = name;
940 static int out_obj_ref_add(const struct lu_env *env,
941 struct dt_object *dt_obj,
946 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
947 rc = dt_ref_add(env, dt_obj, th);
948 dt_write_unlock(env, dt_obj);
953 static int out_obj_ref_del(const struct lu_env *env,
954 struct dt_object *dt_obj,
959 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
960 rc = dt_ref_del(env, dt_obj, th);
961 dt_write_unlock(env, dt_obj);
966 static int out_tx_ref_add_exec(const struct lu_env *env, struct thandle *th,
969 struct dt_object *dt_obj = arg->object;
972 rc = out_obj_ref_add(env, dt_obj, th);
974 CDEBUG(D_INFO, "%s: insert ref_add reply %p index %d: rc = %d\n",
975 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
977 if (arg->reply != NULL)
978 object_update_result_insert(arg->reply, NULL, 0, arg->index,
983 static int out_tx_ref_add_undo(const struct lu_env *env, struct thandle *th,
986 return out_obj_ref_del(env, arg->object, th);
989 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
990 struct thandle_exec_args *ta,
992 struct object_update_reply *reply, int index,
993 const char *file, int line)
998 rc = dt_declare_ref_add(env, dt_obj, th);
1002 arg = tx_add_exec(ta, out_tx_ref_add_exec, out_tx_ref_add_undo, file,
1005 return PTR_ERR(arg);
1007 lu_object_get(&dt_obj->do_lu);
1008 arg->object = dt_obj;
1014 static int out_tx_ref_del_exec(const struct lu_env *env, struct thandle *th,
1017 struct dt_object *dt_obj = arg->object;
1020 rc = out_obj_ref_del(env, dt_obj, th);
1022 CDEBUG(D_INFO, "%s: insert ref_del reply %p index %d: rc = %d\n",
1023 dt_obd_name(th->th_dev), arg->reply, arg->index, 0);
1025 if (arg->reply != NULL)
1026 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1032 static int out_tx_ref_del_undo(const struct lu_env *env, struct thandle *th,
1035 return out_obj_ref_add(env, arg->object, th);
1038 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
1039 struct thandle_exec_args *ta,
1041 struct object_update_reply *reply, int index,
1042 const char *file, int line)
1047 rc = dt_declare_ref_del(env, dt_obj, th);
1051 arg = tx_add_exec(ta, out_tx_ref_del_exec, out_tx_ref_del_undo, file,
1054 return PTR_ERR(arg);
1056 lu_object_get(&dt_obj->do_lu);
1057 arg->object = dt_obj;
1063 static int out_obj_index_insert(const struct lu_env *env,
1064 struct dt_object *dt_obj,
1065 const struct dt_rec *rec,
1066 const struct dt_key *key,
1071 CDEBUG(D_INFO, "%s: index insert "DFID" name: %s fid "DFID", type %u\n",
1072 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
1073 (char *)key, PFID(((struct dt_insert_rec *)rec)->rec_fid),
1074 ((struct dt_insert_rec *)rec)->rec_type);
1076 if (dt_try_as_dir(env, dt_obj) == 0)
1079 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
1080 rc = dt_insert(env, dt_obj, rec, key, th);
1081 dt_write_unlock(env, dt_obj);
1086 static int out_obj_index_delete(const struct lu_env *env,
1087 struct dt_object *dt_obj,
1088 const struct dt_key *key,
1093 CDEBUG(D_INFO, "%s: index delete "DFID" name: %s\n",
1094 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
1097 if (dt_try_as_dir(env, dt_obj) == 0)
1100 dt_write_lock(env, dt_obj, DT_TGT_CHILD);
1101 rc = dt_delete(env, dt_obj, key, th);
1102 dt_write_unlock(env, dt_obj);
1107 static int out_tx_index_insert_exec(const struct lu_env *env,
1108 struct thandle *th, struct tx_arg *arg)
1110 struct dt_object *dt_obj = arg->object;
1113 if (unlikely(!dt_object_exists(dt_obj)))
1116 rc = out_obj_index_insert(env, dt_obj,
1117 (const struct dt_rec *)&arg->u.insert.rec,
1118 arg->u.insert.key, th);
1120 CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
1121 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1123 if (arg->reply != NULL)
1124 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1129 static int out_tx_index_insert_undo(const struct lu_env *env,
1130 struct thandle *th, struct tx_arg *arg)
1132 return out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1135 int out_index_insert_add_exec(const struct lu_env *env,
1136 struct dt_object *dt_obj,
1137 const struct dt_rec *rec,
1138 const struct dt_key *key,
1139 struct thandle_exec_args *ta,
1141 struct object_update_reply *reply,
1142 int index, const char *file, int line)
1147 if (dt_try_as_dir(env, dt_obj) == 0) {
1152 rc = dt_declare_insert(env, dt_obj, rec, key, th);
1156 arg = tx_add_exec(ta, out_tx_index_insert_exec,
1157 out_tx_index_insert_undo, file, line);
1159 return PTR_ERR(arg);
1161 lu_object_get(&dt_obj->do_lu);
1162 arg->object = dt_obj;
1165 arg->u.insert.rec = *(const struct dt_insert_rec *)rec;
1166 arg->u.insert.key = key;
1171 static int out_tx_index_delete_exec(const struct lu_env *env,
1177 rc = out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1179 CDEBUG(D_INFO, "%s: delete idx insert reply %p index %d: rc = %d\n",
1180 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1182 if (arg->reply != NULL)
1183 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1189 static int out_tx_index_delete_undo(const struct lu_env *env,
1193 CERROR("%s: Oops, can not rollback index_delete yet: rc = %d\n",
1194 dt_obd_name(th->th_dev), -ENOTSUPP);
1198 int out_index_delete_add_exec(const struct lu_env *env,
1199 struct dt_object *dt_obj,
1200 const struct dt_key *key,
1201 struct thandle_exec_args *ta,
1203 struct object_update_reply *reply,
1204 int index, const char *file, int line)
1209 if (dt_try_as_dir(env, dt_obj) == 0) {
1214 LASSERT(ta->ta_handle != NULL);
1215 rc = dt_declare_delete(env, dt_obj, key, th);
1219 arg = tx_add_exec(ta, out_tx_index_delete_exec,
1220 out_tx_index_delete_undo, file, line);
1222 return PTR_ERR(arg);
1224 lu_object_get(&dt_obj->do_lu);
1225 arg->object = dt_obj;
1228 arg->u.insert.key = key;
1232 static int out_tx_destroy_exec(const struct lu_env *env, struct thandle *th,
1235 struct dt_object *dt_obj = arg->object;
1238 rc = out_obj_destroy(env, dt_obj, th);
1240 CDEBUG(D_INFO, "%s: insert destroy reply %p index %d: rc = %d\n",
1241 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1243 if (arg->reply != NULL)
1244 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1250 static int out_tx_destroy_undo(const struct lu_env *env, struct thandle *th,
1253 CERROR("%s: not support destroy undo yet!: rc = %d\n",
1254 dt_obd_name(th->th_dev), -ENOTSUPP);
1258 int out_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
1259 struct thandle_exec_args *ta, struct thandle *th,
1260 struct object_update_reply *reply,
1261 int index, const char *file, int line)
1266 rc = dt_declare_destroy(env, dt_obj, th);
1270 arg = tx_add_exec(ta, out_tx_destroy_exec, out_tx_destroy_undo,
1273 return PTR_ERR(arg);
1275 lu_object_get(&dt_obj->do_lu);
1276 arg->object = dt_obj;