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, 2015, 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>
41 #include "tgt_internal.h"
43 const char *update_op_str(__u16 opc)
45 static const char *opc_str[] = {
46 [OUT_START] = "start",
47 [OUT_CREATE] = "create",
48 [OUT_DESTROY] = "destroy",
49 [OUT_REF_ADD] = "ref_add",
50 [OUT_REF_DEL] = "ref_del" ,
51 [OUT_ATTR_SET] = "attr_set",
52 [OUT_ATTR_GET] = "attr_get",
53 [OUT_XATTR_SET] = "xattr_set",
54 [OUT_XATTR_GET] = "xattr_get",
55 [OUT_INDEX_LOOKUP] = "lookup",
56 [OUT_INDEX_INSERT] = "insert",
57 [OUT_INDEX_DELETE] = "delete",
58 [OUT_WRITE] = "write",
59 [OUT_XATTR_DEL] = "xattr_del",
60 [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,out] max_update_size maximum object update size, if the
81 * current update length equals or
82 * exceeds the size, it will return -E2BIG.
83 * \params[in] update_op update type
84 * \params[in] fid object FID of the update
85 * \params[in] param_count the count of the update parameters
86 * \params[in] param_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,
93 size_t *max_update_size,
94 enum update_type update_op,
95 const struct lu_fid *fid,
96 unsigned int param_count,
100 struct object_update_param *param;
104 if (((reply_size + 7) >> 3) >= 1ULL << 16)
107 /* Check whether the packing exceeding the maxima update length */
108 update_size = sizeof(*update);
109 for (i = 0; i < param_count; i++)
110 update_size += cfs_size_round(sizeof(*param) + param_sizes[i]);
112 if (unlikely(update_size >= *max_update_size)) {
113 *max_update_size = update_size;
117 update->ou_fid = *fid;
118 update->ou_type = update_op;
119 update->ou_params_count = param_count;
120 update->ou_result_size = reply_size;
121 param = &update->ou_params[0];
122 for (i = 0; i < param_count; i++) {
123 param->oup_len = param_sizes[i];
124 param = (struct object_update_param *)((char *)param +
125 object_update_param_size(param));
132 * Packs one update into the update_buffer.
134 * \param[in] env execution environment
135 * \param[in] update update to be packed
136 * \param[in] max_update_size *maximum size of \a update
137 * \param[in] op update operation (enum update_type)
138 * \param[in] fid object FID for this update
139 * \param[in] param_count number of parameters for this update
140 * \param[in] param_sizes array of parameters length of this update
141 * \param[in] param_bufs parameter buffers
143 * \retval = 0 if updates packing succeeds
144 * \retval negative errno if updates packing fails
146 int out_update_pack(const struct lu_env *env, struct object_update *update,
147 size_t *max_update_size, enum update_type op,
148 const struct lu_fid *fid, unsigned int param_count,
149 __u16 *param_sizes, const void **param_bufs,
152 struct object_update_param *param;
157 rc = out_update_header_pack(env, update, max_update_size, op, fid,
158 param_count, param_sizes, reply_size);
162 param = &update->ou_params[0];
163 for (i = 0; i < param_count; i++) {
164 memcpy(¶m->oup_buf[0], param_bufs[i], param_sizes[i]);
165 param = (struct object_update_param *)((char *)param +
166 object_update_param_size(param));
171 EXPORT_SYMBOL(out_update_pack);
174 * Pack various updates into the update_buffer.
176 * The following functions pack different updates into the update_buffer
177 * So parameters of these API is basically same as its correspondent OSD/OSP
178 * API, for detail description of these parameters see osd_handler.c or
181 * \param[in] env execution environment
182 * \param[in] ubuf update buffer
183 * \param[in] fid fid of this object for the update
185 * \retval 0 if insertion succeeds.
186 * \retval negative errno if insertion fails.
188 int out_create_pack(const struct lu_env *env, struct object_update *update,
189 size_t *max_update_size, const struct lu_fid *fid,
190 const struct lu_attr *attr, struct dt_allocation_hint *hint,
191 struct dt_object_format *dof)
194 __u16 sizes[2] = {sizeof(*obdo), 0};
196 const struct lu_fid *parent_fid = NULL;
200 if (hint != NULL && hint->dah_parent) {
201 parent_fid = lu_object_fid(&hint->dah_parent->do_lu);
202 sizes[1] = sizeof(*parent_fid);
206 rc = out_update_header_pack(env, update, max_update_size, OUT_CREATE,
207 fid, buf_count, sizes, 0);
211 obdo = object_update_param_get(update, 0, NULL);
213 RETURN(PTR_ERR(obdo));
216 obdo_from_la(obdo, attr, attr->la_valid);
217 lustre_set_wire_obdo(NULL, obdo, obdo);
219 if (parent_fid != NULL) {
222 tmp = object_update_param_get(update, 1, NULL);
224 RETURN(PTR_ERR(tmp));
226 fid_cpu_to_le(tmp, parent_fid);
231 EXPORT_SYMBOL(out_create_pack);
233 int out_ref_del_pack(const struct lu_env *env, struct object_update *update,
234 size_t *max_update_size, const struct lu_fid *fid)
236 return out_update_pack(env, update, max_update_size, OUT_REF_DEL, fid,
239 EXPORT_SYMBOL(out_ref_del_pack);
241 int out_ref_add_pack(const struct lu_env *env, struct object_update *update,
242 size_t *max_update_size, const struct lu_fid *fid)
244 return out_update_pack(env, update, max_update_size, OUT_REF_ADD, fid,
247 EXPORT_SYMBOL(out_ref_add_pack);
249 int out_attr_set_pack(const struct lu_env *env, struct object_update *update,
250 size_t *max_update_size, const struct lu_fid *fid,
251 const struct lu_attr *attr)
254 __u16 size = sizeof(*obdo);
258 rc = out_update_header_pack(env, update, max_update_size,
259 OUT_ATTR_SET, fid, 1, &size, 0);
263 obdo = object_update_param_get(update, 0, NULL);
265 RETURN(PTR_ERR(obdo));
268 obdo_from_la(obdo, attr, attr->la_valid);
269 lustre_set_wire_obdo(NULL, obdo, obdo);
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_object_destroy_pack(const struct lu_env *env,
335 struct object_update *update,
336 size_t *max_update_size, const struct lu_fid *fid)
338 return out_update_pack(env, update, max_update_size, OUT_DESTROY, fid,
341 EXPORT_SYMBOL(out_object_destroy_pack);
343 int out_write_pack(const struct lu_env *env, struct object_update *update,
344 size_t *max_update_size, const struct lu_fid *fid,
345 const struct lu_buf *buf, __u64 pos)
347 __u16 sizes[2] = {buf->lb_len, sizeof(pos)};
348 const void *bufs[2] = {(char *)buf->lb_buf, (char *)&pos};
351 pos = cpu_to_le64(pos);
353 rc = out_update_pack(env, update, max_update_size, OUT_WRITE, fid,
354 ARRAY_SIZE(sizes), sizes, bufs, 0);
357 EXPORT_SYMBOL(out_write_pack);
360 * Pack various readonly updates into the update_buffer.
362 * The following update funcs are only used by read-only ops, lookup,
363 * getattr etc, so it does not need transaction here. Currently they
364 * are only used by OSP.
366 * \param[in] env execution environment
367 * \param[in] fid fid of this object for the update
368 * \param[in] ubuf update buffer
370 * \retval = 0 pack succeed.
373 int out_index_lookup_pack(const struct lu_env *env,
374 struct object_update *update,
375 size_t *max_update_size, const struct lu_fid *fid,
376 struct dt_rec *rec, const struct dt_key *key)
378 const void *name = key;
379 __u16 size = strlen((char *)name) + 1;
381 /* XXX: this shouldn't be hardcoded */
382 return out_update_pack(env, update, max_update_size, OUT_INDEX_LOOKUP,
383 fid, 1, &size, &name, 256);
385 EXPORT_SYMBOL(out_index_lookup_pack);
387 int out_attr_get_pack(const struct lu_env *env, struct object_update *update,
388 size_t *max_update_size, const struct lu_fid *fid)
390 return out_update_pack(env, update, max_update_size, OUT_ATTR_GET,
391 fid, 0, NULL, NULL, sizeof(struct obdo));
393 EXPORT_SYMBOL(out_attr_get_pack);
395 int out_xattr_get_pack(const struct lu_env *env, struct object_update *update,
396 size_t *max_update_size, const struct lu_fid *fid,
397 const char *name, const int bufsize)
401 LASSERT(name != NULL);
402 size = strlen(name) + 1;
404 return out_update_pack(env, update, max_update_size, OUT_XATTR_GET,
405 fid, 1, &size, (const void **)&name, bufsize);
407 EXPORT_SYMBOL(out_xattr_get_pack);
409 int out_read_pack(const struct lu_env *env, struct object_update *update,
410 size_t *max_update_size, const struct lu_fid *fid,
411 size_t size, loff_t pos)
413 __u16 sizes[2] = {sizeof(size), sizeof(pos)};
414 const void *bufs[2] = {&size, &pos};
417 size = cpu_to_le64(size);
418 pos = cpu_to_le64(pos);
420 return out_update_pack(env, update, max_update_size, OUT_READ, fid,
421 ARRAY_SIZE(sizes), sizes, bufs, size);
423 EXPORT_SYMBOL(out_read_pack);
425 static int tx_extend_args(struct thandle_exec_args *ta, int new_alloc_ta)
427 struct tx_arg **new_ta;
431 if (ta->ta_alloc_args >= new_alloc_ta)
434 OBD_ALLOC(new_ta, sizeof(*new_ta) * new_alloc_ta);
438 for (i = 0; i < new_alloc_ta; i++) {
439 if (i < ta->ta_alloc_args) {
440 /* copy the old args to new one */
441 new_ta[i] = ta->ta_args[i];
443 OBD_ALLOC_PTR(new_ta[i]);
444 if (new_ta[i] == NULL)
445 GOTO(out, rc = -ENOMEM);
449 /* free the old args */
450 if (ta->ta_args != NULL)
451 OBD_FREE(ta->ta_args, sizeof(ta->ta_args[0]) *
454 ta->ta_args = new_ta;
455 ta->ta_alloc_args = new_alloc_ta;
458 for (i = 0; i < new_alloc_ta; i++) {
459 if (new_ta[i] != NULL)
460 OBD_FREE_PTR(new_ta[i]);
462 OBD_FREE(new_ta, sizeof(*new_ta) * new_alloc_ta);
467 #define TX_ALLOC_STEP 8
468 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
469 tx_exec_func_t func, tx_exec_func_t undo,
470 const char *file, int line)
476 LASSERT(func != NULL);
478 if (ta->ta_argno + 1 >= ta->ta_alloc_args) {
479 rc = tx_extend_args(ta, ta->ta_alloc_args + TX_ALLOC_STEP);
488 ta->ta_args[i]->exec_fn = func;
489 ta->ta_args[i]->undo_fn = undo;
490 ta->ta_args[i]->file = file;
491 ta->ta_args[i]->line = line;
493 return ta->ta_args[i];
496 static int out_obj_destroy(const struct lu_env *env, struct dt_object *dt_obj,
501 CDEBUG(D_INFO, "%s: destroy "DFID"\n", dt_obd_name(th->th_dev),
502 PFID(lu_object_fid(&dt_obj->do_lu)));
504 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
505 rc = dt_destroy(env, dt_obj, th);
506 dt_write_unlock(env, dt_obj);
512 * All of the xxx_undo will be used once execution failed,
513 * But because all of the required resource has been reserved in
514 * declare phase, i.e. if declare succeed, it should make sure
515 * the following executing phase succeed in anyway, so these undo
516 * should be useless for most of the time in Phase I
518 static int out_tx_create_undo(const struct lu_env *env, struct thandle *th,
523 rc = out_obj_destroy(env, arg->object, th);
525 CERROR("%s: undo failure, we are doomed!: rc = %d\n",
526 dt_obd_name(th->th_dev), rc);
530 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
533 struct dt_object *dt_obj = arg->object;
536 CDEBUG(D_OTHER, "%s: create "DFID": dof %u, mode %o\n",
537 dt_obd_name(th->th_dev),
538 PFID(lu_object_fid(&arg->object->do_lu)),
539 arg->u.create.dof.dof_type,
540 arg->u.create.attr.la_mode & S_IFMT);
542 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
543 rc = dt_create(env, dt_obj, &arg->u.create.attr,
544 &arg->u.create.hint, &arg->u.create.dof, th);
546 dt_write_unlock(env, dt_obj);
548 CDEBUG(D_INFO, "%s: insert create reply %p index %d: rc = %d\n",
549 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
551 if (arg->reply != NULL)
552 object_update_result_insert(arg->reply, NULL, 0, arg->index,
559 * Add create update to thandle
561 * Declare create updates and add the update to the thandle updates
564 * \param [in] env execution environment
565 * \param [in] obj object to be created
566 * \param [in] attr attributes of the creation
567 * \param [in] parent_fid the fid of the parent
568 * \param [in] dof dt object format of the creation
569 * \param [in] ta thandle execuation args where all of updates
570 * of the transaction are stored
571 * \param [in] th thandle for this update
572 * \param [in] reply reply of the updates
573 * \param [in] index index of the reply
574 * \param [in] file the file name where the function is called,
575 * which is only for debugging purpose.
576 * \param [in] line the line number where the funtion is called,
577 * which is only for debugging purpose.
579 * \retval 0 if updates is added successfully.
580 * \retval negative errno if update adding fails.
582 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
583 struct lu_attr *attr, struct lu_fid *parent_fid,
584 struct dt_object_format *dof,
585 struct thandle_exec_args *ta,
587 struct object_update_reply *reply,
588 int index, const char *file, int line)
593 rc = dt_declare_create(env, obj, attr, NULL, dof, th);
597 arg = tx_add_exec(ta, out_tx_create_exec, out_tx_create_undo, file,
602 /* release the object in out_trans_stop */
603 lu_object_get(&obj->do_lu);
605 arg->u.create.attr = *attr;
606 if (parent_fid != NULL)
607 arg->u.create.fid = *parent_fid;
608 memset(&arg->u.create.hint, 0, sizeof(arg->u.create.hint));
609 arg->u.create.dof = *dof;
616 static int out_tx_attr_set_undo(const struct lu_env *env,
617 struct thandle *th, struct tx_arg *arg)
619 CERROR("%s: attr set undo "DFID" unimplemented yet!: rc = %d\n",
620 dt_obd_name(th->th_dev),
621 PFID(lu_object_fid(&arg->object->do_lu)), -ENOTSUPP);
626 static int out_tx_attr_set_exec(const struct lu_env *env, struct thandle *th,
629 struct dt_object *dt_obj = arg->object;
632 CDEBUG(D_OTHER, "%s: attr set "DFID"\n", dt_obd_name(th->th_dev),
633 PFID(lu_object_fid(&dt_obj->do_lu)));
635 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
636 rc = dt_attr_set(env, dt_obj, &arg->u.attr_set.attr, th);
637 dt_write_unlock(env, dt_obj);
639 CDEBUG(D_INFO, "%s: insert attr_set reply %p index %d: rc = %d\n",
640 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
642 if (arg->reply != NULL)
643 object_update_result_insert(arg->reply, NULL, 0,
649 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
650 const struct lu_attr *attr,
651 struct thandle_exec_args *ta,
652 struct thandle *th, struct object_update_reply *reply,
653 int index, const char *file, int line)
658 rc = dt_declare_attr_set(env, dt_obj, attr, th);
662 arg = tx_add_exec(ta, out_tx_attr_set_exec, out_tx_attr_set_undo,
667 lu_object_get(&dt_obj->do_lu);
668 arg->object = dt_obj;
669 arg->u.attr_set.attr = *attr;
675 static int out_tx_write_exec(const struct lu_env *env, struct thandle *th,
678 struct dt_object *dt_obj = arg->object;
681 CDEBUG(D_INFO, "write "DFID" pos "LPU64" buf %p, len %lu\n",
682 PFID(lu_object_fid(&dt_obj->do_lu)), arg->u.write.pos,
683 arg->u.write.buf.lb_buf, (unsigned long)arg->u.write.buf.lb_len);
685 if (OBD_FAIL_CHECK(OBD_FAIL_OUT_ENOSPC)) {
688 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
689 rc = dt_record_write(env, dt_obj, &arg->u.write.buf,
690 &arg->u.write.pos, th);
691 dt_write_unlock(env, dt_obj);
694 rc = arg->u.write.buf.lb_len;
697 if (arg->reply != NULL)
698 object_update_result_insert(arg->reply, NULL, 0, arg->index,
701 return rc > 0 ? 0 : rc;
704 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
705 const struct lu_buf *buf, loff_t pos,
706 struct thandle_exec_args *ta, struct thandle *th,
707 struct object_update_reply *reply, int index,
708 const char *file, int line)
713 rc = dt_declare_record_write(env, dt_obj, buf, pos, th);
717 arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line);
721 lu_object_get(&dt_obj->do_lu);
722 arg->object = dt_obj;
723 arg->u.write.buf = *buf;
724 arg->u.write.pos = pos;
730 static int out_tx_xattr_set_exec(const struct lu_env *env,
734 struct dt_object *dt_obj = arg->object;
737 CDEBUG(D_INFO, "%s: set xattr buf %p name %s flag %d\n",
738 dt_obd_name(th->th_dev), arg->u.xattr_set.buf.lb_buf,
739 arg->u.xattr_set.name, arg->u.xattr_set.flags);
741 if (!lu_object_exists(&dt_obj->do_lu))
742 GOTO(out, rc = -ENOENT);
744 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
745 rc = dt_xattr_set(env, dt_obj, &arg->u.xattr_set.buf,
746 arg->u.xattr_set.name, arg->u.xattr_set.flags,
749 * Ignore errors if this is LINK EA
751 if (unlikely(rc != 0 &&
752 strcmp(arg->u.xattr_set.name, XATTR_NAME_LINK) == 0)) {
753 /* XXX: If the linkEA is overflow, then we need to notify the
754 * namespace LFSCK to skip "nlink" attribute verification
755 * on this object to avoid the "nlink" to be shrinked by
756 * wrong. It may be not good an interaction with LFSCK
757 * like this. We will consider to replace it with other
758 * mechanism in future. LU-5802. */
759 if (rc == -ENOSPC && arg->reply != NULL) {
760 struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
762 lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
763 LE_SKIP_NLINK, LFSCK_TYPE_NAMESPACE);
764 tgt_lfsck_in_notify(env,
765 tgt_ses_info(env)->tsi_tgt->lut_bottom, lr, th);
770 dt_write_unlock(env, dt_obj);
773 CDEBUG(D_INFO, "%s: insert xattr set reply %p index %d: rc = %d\n",
774 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
776 if (arg->reply != NULL)
777 object_update_result_insert(arg->reply, NULL, 0, arg->index,
783 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
784 const struct lu_buf *buf, const char *name,
785 int flags, struct thandle_exec_args *ta,
787 struct object_update_reply *reply,
788 int index, const char *file, int line)
793 rc = dt_declare_xattr_set(env, dt_obj, buf, name, flags, th);
797 if (strcmp(name, XATTR_NAME_LINK) == 0 && reply != NULL) {
798 struct lfsck_request *lr = &tgt_th_info(env)->tti_lr;
800 /* XXX: If the linkEA is overflow, then we need to notify the
801 * namespace LFSCK to skip "nlink" attribute verification
802 * on this object to avoid the "nlink" to be shrinked by
803 * wrong. It may be not good an interaction with LFSCK
804 * like this. We will consider to replace it with other
805 * mechanism in future. LU-5802. */
806 lfsck_pack_rfa(lr, lu_object_fid(&dt_obj->do_lu),
807 LE_SKIP_NLINK_DECLARE, LFSCK_TYPE_NAMESPACE);
808 rc = tgt_lfsck_in_notify(env,
809 tgt_ses_info(env)->tsi_tgt->lut_bottom,
815 arg = tx_add_exec(ta, out_tx_xattr_set_exec, NULL, file, line);
819 lu_object_get(&dt_obj->do_lu);
820 arg->object = dt_obj;
821 arg->u.xattr_set.name = name;
822 arg->u.xattr_set.flags = flags;
823 arg->u.xattr_set.buf = *buf;
826 arg->u.xattr_set.csum = 0;
830 static int out_tx_xattr_del_exec(const struct lu_env *env, struct thandle *th,
833 struct dt_object *dt_obj = arg->object;
836 CDEBUG(D_INFO, "%s: del xattr name '%s' on "DFID"\n",
837 dt_obd_name(th->th_dev), arg->u.xattr_set.name,
838 PFID(lu_object_fid(&dt_obj->do_lu)));
840 if (!lu_object_exists(&dt_obj->do_lu))
841 GOTO(out, rc = -ENOENT);
843 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
844 rc = dt_xattr_del(env, dt_obj, arg->u.xattr_set.name,
846 dt_write_unlock(env, dt_obj);
848 CDEBUG(D_INFO, "%s: insert xattr del 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_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
859 const char *name, struct thandle_exec_args *ta,
861 struct object_update_reply *reply, int index,
862 const char *file, int line)
867 rc = dt_declare_xattr_del(env, dt_obj, name, th);
871 arg = tx_add_exec(ta, out_tx_xattr_del_exec, NULL, file, line);
875 lu_object_get(&dt_obj->do_lu);
876 arg->object = dt_obj;
877 arg->u.xattr_set.name = name;
883 static int out_obj_ref_add(const struct lu_env *env,
884 struct dt_object *dt_obj,
889 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
890 rc = dt_ref_add(env, dt_obj, th);
891 dt_write_unlock(env, dt_obj);
896 static int out_obj_ref_del(const struct lu_env *env,
897 struct dt_object *dt_obj,
902 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
903 rc = dt_ref_del(env, dt_obj, th);
904 dt_write_unlock(env, dt_obj);
909 static int out_tx_ref_add_exec(const struct lu_env *env, struct thandle *th,
912 struct dt_object *dt_obj = arg->object;
915 rc = out_obj_ref_add(env, dt_obj, th);
917 CDEBUG(D_INFO, "%s: insert ref_add reply %p index %d: rc = %d\n",
918 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
920 if (arg->reply != NULL)
921 object_update_result_insert(arg->reply, NULL, 0, arg->index,
926 static int out_tx_ref_add_undo(const struct lu_env *env, struct thandle *th,
929 return out_obj_ref_del(env, arg->object, th);
932 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
933 struct thandle_exec_args *ta,
935 struct object_update_reply *reply, int index,
936 const char *file, int line)
941 rc = dt_declare_ref_add(env, dt_obj, th);
945 arg = tx_add_exec(ta, out_tx_ref_add_exec, out_tx_ref_add_undo, file,
950 lu_object_get(&dt_obj->do_lu);
951 arg->object = dt_obj;
957 static int out_tx_ref_del_exec(const struct lu_env *env, struct thandle *th,
960 struct dt_object *dt_obj = arg->object;
963 rc = out_obj_ref_del(env, dt_obj, th);
965 CDEBUG(D_INFO, "%s: insert ref_del reply %p index %d: rc = %d\n",
966 dt_obd_name(th->th_dev), arg->reply, arg->index, 0);
968 if (arg->reply != NULL)
969 object_update_result_insert(arg->reply, NULL, 0, arg->index,
975 static int out_tx_ref_del_undo(const struct lu_env *env, struct thandle *th,
978 return out_obj_ref_add(env, arg->object, th);
981 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
982 struct thandle_exec_args *ta,
984 struct object_update_reply *reply, int index,
985 const char *file, int line)
990 rc = dt_declare_ref_del(env, dt_obj, th);
994 arg = tx_add_exec(ta, out_tx_ref_del_exec, out_tx_ref_del_undo, file,
999 lu_object_get(&dt_obj->do_lu);
1000 arg->object = dt_obj;
1006 static int out_obj_index_insert(const struct lu_env *env,
1007 struct dt_object *dt_obj,
1008 const struct dt_rec *rec,
1009 const struct dt_key *key,
1014 CDEBUG(D_INFO, "%s: index insert "DFID" name: %s fid "DFID", type %u\n",
1015 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
1016 (char *)key, PFID(((struct dt_insert_rec *)rec)->rec_fid),
1017 ((struct dt_insert_rec *)rec)->rec_type);
1019 if (dt_try_as_dir(env, dt_obj) == 0)
1022 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
1023 rc = dt_insert(env, dt_obj, rec, key, th, 0);
1024 dt_write_unlock(env, dt_obj);
1029 static int out_obj_index_delete(const struct lu_env *env,
1030 struct dt_object *dt_obj,
1031 const struct dt_key *key,
1036 CDEBUG(D_INFO, "%s: index delete "DFID" name: %s\n",
1037 dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
1040 if (dt_try_as_dir(env, dt_obj) == 0)
1043 dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
1044 rc = dt_delete(env, dt_obj, key, th);
1045 dt_write_unlock(env, dt_obj);
1050 static int out_tx_index_insert_exec(const struct lu_env *env,
1051 struct thandle *th, struct tx_arg *arg)
1053 struct dt_object *dt_obj = arg->object;
1056 if (unlikely(!dt_object_exists(dt_obj)))
1059 rc = out_obj_index_insert(env, dt_obj,
1060 (const struct dt_rec *)&arg->u.insert.rec,
1061 arg->u.insert.key, th);
1063 CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
1064 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1066 if (arg->reply != NULL)
1067 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1072 static int out_tx_index_insert_undo(const struct lu_env *env,
1073 struct thandle *th, struct tx_arg *arg)
1075 return out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1078 int out_index_insert_add_exec(const struct lu_env *env,
1079 struct dt_object *dt_obj,
1080 const struct dt_rec *rec,
1081 const struct dt_key *key,
1082 struct thandle_exec_args *ta,
1084 struct object_update_reply *reply,
1085 int index, const char *file, int line)
1090 if (dt_try_as_dir(env, dt_obj) == 0) {
1095 rc = dt_declare_insert(env, dt_obj, rec, key, th);
1099 arg = tx_add_exec(ta, out_tx_index_insert_exec,
1100 out_tx_index_insert_undo, file, line);
1102 return PTR_ERR(arg);
1104 lu_object_get(&dt_obj->do_lu);
1105 arg->object = dt_obj;
1108 arg->u.insert.rec = *(const struct dt_insert_rec *)rec;
1109 arg->u.insert.key = key;
1114 static int out_tx_index_delete_exec(const struct lu_env *env,
1120 rc = out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
1122 CDEBUG(D_INFO, "%s: delete idx insert reply %p index %d: rc = %d\n",
1123 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1125 if (arg->reply != NULL)
1126 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1132 static int out_tx_index_delete_undo(const struct lu_env *env,
1136 CERROR("%s: Oops, can not rollback index_delete yet: rc = %d\n",
1137 dt_obd_name(th->th_dev), -ENOTSUPP);
1141 int out_index_delete_add_exec(const struct lu_env *env,
1142 struct dt_object *dt_obj,
1143 const struct dt_key *key,
1144 struct thandle_exec_args *ta,
1146 struct object_update_reply *reply,
1147 int index, const char *file, int line)
1152 if (dt_try_as_dir(env, dt_obj) == 0) {
1157 LASSERT(ta->ta_handle != NULL);
1158 rc = dt_declare_delete(env, dt_obj, key, th);
1162 arg = tx_add_exec(ta, out_tx_index_delete_exec,
1163 out_tx_index_delete_undo, file, line);
1165 return PTR_ERR(arg);
1167 lu_object_get(&dt_obj->do_lu);
1168 arg->object = dt_obj;
1171 arg->u.insert.key = key;
1175 static int out_tx_destroy_exec(const struct lu_env *env, struct thandle *th,
1178 struct dt_object *dt_obj = arg->object;
1181 rc = out_obj_destroy(env, dt_obj, th);
1183 CDEBUG(D_INFO, "%s: insert destroy reply %p index %d: rc = %d\n",
1184 dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
1186 if (arg->reply != NULL)
1187 object_update_result_insert(arg->reply, NULL, 0, arg->index,
1193 static int out_tx_destroy_undo(const struct lu_env *env, struct thandle *th,
1196 CERROR("%s: not support destroy undo yet!: rc = %d\n",
1197 dt_obd_name(th->th_dev), -ENOTSUPP);
1201 int out_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
1202 struct thandle_exec_args *ta, struct thandle *th,
1203 struct object_update_reply *reply,
1204 int index, const char *file, int line)
1209 rc = dt_declare_destroy(env, dt_obj, th);
1213 arg = tx_add_exec(ta, out_tx_destroy_exec, out_tx_destroy_undo,
1216 return PTR_ERR(arg);
1218 lu_object_get(&dt_obj->do_lu);
1219 arg->object = dt_obj;