Whamcloud - gitweb
6ad753e815cc97c047007d29655ebf1454d5cfbd
[fs/lustre-release.git] / lustre / target / out_handler.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2013, 2016, Intel Corporation.
24  *
25  * lustre/target/out_handler.c
26  *
27  * Object update handler between targets.
28  *
29  * Author: di.wang <di.wang@intel.com>
30  */
31
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <llog_swab.h>
35 #include <lustre_obdo.h>
36 #include <lustre_swab.h>
37 #include <lustre_update.h>
38 #include <md_object.h>
39 #include <obd_class.h>
40 #include "tgt_internal.h"
41
42 static inline void orr_cpu_to_le(struct out_read_reply *orr_dst,
43                                  const struct out_read_reply *orr_src)
44 {
45         orr_dst->orr_size = cpu_to_le32(orr_src->orr_size);
46         orr_dst->orr_padding = cpu_to_le32(orr_src->orr_padding);
47         orr_dst->orr_offset = cpu_to_le64(orr_dst->orr_offset);
48 }
49
50 static void out_reconstruct(const struct lu_env *env, struct dt_device *dt,
51                             struct dt_object *obj,
52                             struct object_update_reply *reply,
53                             int index)
54 {
55         CDEBUG(D_INFO, "%s: fork reply reply %p index %d: rc = %d\n",
56                dt_obd_name(dt), reply, index, 0);
57
58         object_update_result_insert(reply, NULL, 0, index, 0);
59         return;
60 }
61
62 typedef void (*out_reconstruct_t)(const struct lu_env *env,
63                                   struct dt_device *dt,
64                                   struct dt_object *obj,
65                                   struct object_update_reply *reply,
66                                   int index);
67
68 static inline int out_check_resent(const struct lu_env *env,
69                                    struct dt_device *dt,
70                                    struct dt_object *obj,
71                                    struct ptlrpc_request *req,
72                                    out_reconstruct_t reconstruct,
73                                    struct object_update_reply *reply,
74                                    int index)
75 {
76         if (likely(!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)))
77                 return 0;
78
79         if (req_xid_is_last(req)) {
80                 struct lsd_client_data *lcd;
81
82                 /* XXX this does not support mulitple transactions yet, i.e.
83                  * only 1 update RPC each time betwee MDTs */
84                 lcd = req->rq_export->exp_target_data.ted_lcd;
85
86                 req->rq_transno = lcd->lcd_last_transno;
87                 req->rq_status = lcd->lcd_last_result;
88                 if (req->rq_status != 0)
89                         req->rq_transno = 0;
90                 lustre_msg_set_transno(req->rq_repmsg, req->rq_transno);
91                 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
92
93                 DEBUG_REQ(D_RPCTRACE, req, "restoring resent RPC");
94
95                 reconstruct(env, dt, obj, reply, index);
96                 return 1;
97         }
98         DEBUG_REQ(D_HA, req, "no reply for RESENT req (have %lld)",
99                  req->rq_export->exp_target_data.ted_lcd->lcd_last_xid);
100         return 0;
101 }
102
103 static int out_create(struct tgt_session_info *tsi)
104 {
105         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
106         struct object_update    *update = tti->tti_u.update.tti_update;
107         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
108         struct dt_object_format *dof = &tti->tti_u.update.tti_update_dof;
109         struct obdo             *lobdo = &tti->tti_u.update.tti_obdo;
110         struct lu_attr          *attr = &tti->tti_attr;
111         struct lu_fid           *fid = NULL;
112         struct obdo             *wobdo;
113         size_t                  size;
114         int                     rc;
115
116         ENTRY;
117
118         wobdo = object_update_param_get(update, 0, &size);
119         if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
120                 CERROR("%s: obdo is NULL, invalid RPC: rc = %ld\n",
121                        tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
122                 RETURN(PTR_ERR(wobdo));
123         }
124
125         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
126                 lustre_swab_obdo(wobdo);
127         lustre_get_wire_obdo(NULL, lobdo, wobdo);
128         la_from_obdo(attr, lobdo, lobdo->o_valid);
129
130         dof->dof_type = dt_mode_to_dft(attr->la_mode);
131         if (update->ou_params_count > 1) {
132                 fid = object_update_param_get(update, 1, &size);
133                 if (IS_ERR(fid) || size != sizeof(*fid)) {
134                         CERROR("%s: invalid fid: rc = %ld\n",
135                                tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
136                         RETURN(PTR_ERR(fid));
137                 }
138                 if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
139                         lustre_swab_lu_fid(fid);
140                 if (!fid_is_sane(fid)) {
141                         CERROR("%s: invalid fid "DFID": rc = %d\n",
142                                tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
143                         RETURN(-EPROTO);
144                 }
145         }
146
147         if (lu_object_exists(&obj->do_lu))
148                 RETURN(-EEXIST);
149
150         rc = out_tx_create(tsi->tsi_env, obj, attr, fid, dof,
151                            &tti->tti_tea, tti->tti_tea.ta_handle,
152                            tti->tti_u.update.tti_update_reply,
153                            tti->tti_u.update.tti_update_reply_index);
154
155         RETURN(rc);
156 }
157
158 static int out_attr_set(struct tgt_session_info *tsi)
159 {
160         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
161         struct object_update    *update = tti->tti_u.update.tti_update;
162         struct lu_attr          *attr = &tti->tti_attr;
163         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
164         struct obdo             *lobdo = &tti->tti_u.update.tti_obdo;
165         struct obdo             *wobdo;
166         size_t                   size;
167         int                      rc;
168
169         ENTRY;
170
171         wobdo = object_update_param_get(update, 0, &size);
172         if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
173                 CERROR("%s: empty obdo in the update: rc = %ld\n",
174                        tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
175                 RETURN(PTR_ERR(wobdo));
176         }
177
178         attr->la_valid = 0;
179         attr->la_valid = 0;
180
181         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
182                 lustre_swab_obdo(wobdo);
183         lustre_get_wire_obdo(NULL, lobdo, wobdo);
184         la_from_obdo(attr, lobdo, lobdo->o_valid);
185
186         rc = out_tx_attr_set(tsi->tsi_env, obj, attr, &tti->tti_tea,
187                              tti->tti_tea.ta_handle,
188                              tti->tti_u.update.tti_update_reply,
189                              tti->tti_u.update.tti_update_reply_index);
190
191         RETURN(rc);
192 }
193
194 static int out_attr_get(struct tgt_session_info *tsi)
195 {
196         const struct lu_env     *env = tsi->tsi_env;
197         struct tgt_thread_info  *tti = tgt_th_info(env);
198         struct object_update    *update = tti->tti_u.update.tti_update;
199         struct obdo             *obdo = &tti->tti_u.update.tti_obdo;
200         struct lu_attr          *la = &tti->tti_attr;
201         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
202         int                     idx = tti->tti_u.update.tti_update_reply_index;
203         int                     rc;
204
205         ENTRY;
206
207         if (unlikely(update->ou_result_size < sizeof(*obdo)))
208                 return -EPROTO;
209
210         if (!lu_object_exists(&obj->do_lu)) {
211                 /* Usually, this will be called when the master MDT try
212                  * to init a remote object(see osp_object_init), so if
213                  * the object does not exist on slave, we need set BANSHEE flag,
214                  * so the object can be removed from the cache immediately */
215                 set_bit(LU_OBJECT_HEARD_BANSHEE,
216                         &obj->do_lu.lo_header->loh_flags);
217                 RETURN(-ENOENT);
218         }
219
220         dt_read_lock(env, obj, MOR_TGT_CHILD);
221         rc = dt_attr_get(env, obj, la);
222         if (rc)
223                 GOTO(out_unlock, rc);
224
225         obdo->o_valid = 0;
226         obdo_from_la(obdo, la, la->la_valid);
227
228 out_unlock:
229         dt_read_unlock(env, obj);
230
231         CDEBUG(D_INFO, "%s: insert attr get reply %p index %d: rc = %d\n",
232                tgt_name(tsi->tsi_tgt), tti->tti_u.update.tti_update_reply,
233                0, rc);
234
235         object_update_result_insert(tti->tti_u.update.tti_update_reply, obdo,
236                                     sizeof(*obdo), idx, rc);
237
238         RETURN(rc);
239 }
240
241 static int out_xattr_get(struct tgt_session_info *tsi)
242 {
243         const struct lu_env        *env = tsi->tsi_env;
244         struct tgt_thread_info     *tti = tgt_th_info(env);
245         struct object_update       *update = tti->tti_u.update.tti_update;
246         struct lu_buf              *lbuf = &tti->tti_buf;
247         struct object_update_reply *reply = tti->tti_u.update.tti_update_reply;
248         struct dt_object           *obj = tti->tti_u.update.tti_dt_object;
249         char                       *name;
250         struct object_update_result *update_result;
251         int                     idx = tti->tti_u.update.tti_update_reply_index;
252         int                        rc;
253
254         ENTRY;
255
256         if (!lu_object_exists(&obj->do_lu)) {
257                 set_bit(LU_OBJECT_HEARD_BANSHEE,
258                         &obj->do_lu.lo_header->loh_flags);
259                 RETURN(-ENOENT);
260         }
261
262         name = object_update_param_get(update, 0, NULL);
263         if (IS_ERR(name)) {
264                 CERROR("%s: empty name for xattr get: rc = %ld\n",
265                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
266                 RETURN(PTR_ERR(name));
267         }
268
269         update_result = object_update_result_get(reply, 0, NULL);
270         if (update_result == NULL) {
271                 CERROR("%s: empty name for xattr get: rc = %d\n",
272                        tgt_name(tsi->tsi_tgt), -EPROTO);
273                 RETURN(-EPROTO);
274         }
275
276         lbuf->lb_len = (int)tti->tti_u.update.tti_update->ou_result_size;
277         if (lbuf->lb_len == 0)
278                 lbuf->lb_buf = NULL;
279         else
280                 lbuf->lb_buf = update_result->our_data;
281
282         dt_read_lock(env, obj, MOR_TGT_CHILD);
283         rc = dt_xattr_get(env, obj, lbuf, name);
284         dt_read_unlock(env, obj);
285         if (rc <= 0) {
286                 lbuf->lb_len = 0;
287                 if (unlikely(!rc))
288                         rc = -ENODATA;
289         } else if (lbuf->lb_buf) {
290                 lbuf->lb_len = rc;
291         }
292
293         CDEBUG(D_INFO, "%s: "DFID" get xattr %s len %d: rc = %d\n",
294                tgt_name(tsi->tsi_tgt), PFID(lu_object_fid(&obj->do_lu)),
295                name, (int)lbuf->lb_len, rc);
296
297         object_update_result_insert(reply, lbuf->lb_buf, lbuf->lb_len, idx, rc);
298         RETURN(0);
299 }
300
301 static int out_index_lookup(struct tgt_session_info *tsi)
302 {
303         const struct lu_env     *env = tsi->tsi_env;
304         struct tgt_thread_info  *tti = tgt_th_info(env);
305         struct object_update    *update = tti->tti_u.update.tti_update;
306         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
307         char                    *name;
308         int                      rc;
309
310         ENTRY;
311
312         if (unlikely(update->ou_result_size < sizeof(tti->tti_fid1)))
313                 return -EPROTO;
314
315         if (!lu_object_exists(&obj->do_lu))
316                 RETURN(-ENOENT);
317
318         name = object_update_param_get(update, 0, NULL);
319         if (IS_ERR(name)) {
320                 CERROR("%s: empty name for lookup: rc = %ld\n",
321                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
322                 RETURN(PTR_ERR(name));
323         }
324
325         dt_read_lock(env, obj, MOR_TGT_CHILD);
326         if (!dt_try_as_dir(env, obj))
327                 GOTO(out_unlock, rc = -ENOTDIR);
328
329         rc = dt_lookup(env, obj, (struct dt_rec *)&tti->tti_fid1,
330                        (struct dt_key *)name);
331
332         if (rc < 0)
333                 GOTO(out_unlock, rc);
334
335         if (rc == 0)
336                 rc += 1;
337
338 out_unlock:
339         dt_read_unlock(env, obj);
340
341         CDEBUG(D_INFO, "lookup "DFID" %s get "DFID" rc %d\n",
342                PFID(lu_object_fid(&obj->do_lu)), name,
343                PFID(&tti->tti_fid1), rc);
344
345         CDEBUG(D_INFO, "%s: insert lookup reply %p index %d: rc = %d\n",
346                tgt_name(tsi->tsi_tgt), tti->tti_u.update.tti_update_reply,
347                0, rc);
348
349         object_update_result_insert(tti->tti_u.update.tti_update_reply,
350                             &tti->tti_fid1, sizeof(tti->tti_fid1),
351                             tti->tti_u.update.tti_update_reply_index, rc);
352         RETURN(rc);
353 }
354
355 static int out_xattr_set(struct tgt_session_info *tsi)
356 {
357         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
358         struct object_update    *update = tti->tti_u.update.tti_update;
359         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
360         struct lu_buf           *lbuf = &tti->tti_buf;
361         char                    *name;
362         char                    *buf;
363         __u32                   *tmp;
364         size_t                   buf_len = 0;
365         int                      flag;
366         size_t                   size = 0;
367         int                      rc;
368         ENTRY;
369
370         name = object_update_param_get(update, 0, NULL);
371         if (IS_ERR(name)) {
372                 CERROR("%s: empty name for xattr set: rc = %ld\n",
373                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
374                 RETURN(PTR_ERR(name));
375         }
376
377         /* If buffer == NULL (-ENODATA), then it might mean delete xattr */
378         buf = object_update_param_get(update, 1, &buf_len);
379         if (IS_ERR(buf) && PTR_ERR(buf) != -ENODATA)
380                 RETURN(PTR_ERR(buf));
381
382         lbuf->lb_buf = buf;
383         lbuf->lb_len = buf_len;
384
385         tmp = object_update_param_get(update, 2, &size);
386         if (IS_ERR(tmp) || size != sizeof(*tmp)) {
387                 CERROR("%s: emptry or wrong size %zu flag: rc = %ld\n",
388                        tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
389                 RETURN(PTR_ERR(tmp));
390         }
391
392         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
393                 __swab32s(tmp);
394         flag = *tmp;
395
396         rc = out_tx_xattr_set(tsi->tsi_env, obj, lbuf, name, flag,
397                               &tti->tti_tea, tti->tti_tea.ta_handle,
398                               tti->tti_u.update.tti_update_reply,
399                               tti->tti_u.update.tti_update_reply_index);
400         RETURN(rc);
401 }
402
403 static int out_xattr_del(struct tgt_session_info *tsi)
404 {
405         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
406         struct object_update    *update = tti->tti_u.update.tti_update;
407         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
408         char                    *name;
409         int                      rc;
410         ENTRY;
411
412         name = object_update_param_get(update, 0, NULL);
413         if (IS_ERR(name)) {
414                 CERROR("%s: empty name for xattr set: rc = %ld\n",
415                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
416                 RETURN(PTR_ERR(name));
417         }
418
419         rc = out_tx_xattr_del(tsi->tsi_env, obj, name, &tti->tti_tea,
420                               tti->tti_tea.ta_handle,
421                               tti->tti_u.update.tti_update_reply,
422                               tti->tti_u.update.tti_update_reply_index);
423         RETURN(rc);
424 }
425
426 /**
427  * increase ref of the object
428  **/
429 static int out_ref_add(struct tgt_session_info *tsi)
430 {
431         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
432         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
433         int                      rc;
434
435         ENTRY;
436
437         rc = out_tx_ref_add(tsi->tsi_env, obj, &tti->tti_tea,
438                             tti->tti_tea.ta_handle,
439                             tti->tti_u.update.tti_update_reply,
440                             tti->tti_u.update.tti_update_reply_index);
441         RETURN(rc);
442 }
443
444 static int out_ref_del(struct tgt_session_info *tsi)
445 {
446         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
447         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
448         int                      rc;
449
450         ENTRY;
451
452         if (!lu_object_exists(&obj->do_lu))
453                 RETURN(-ENOENT);
454
455         rc = out_tx_ref_del(tsi->tsi_env, obj, &tti->tti_tea,
456                             tti->tti_tea.ta_handle,
457                             tti->tti_u.update.tti_update_reply,
458                             tti->tti_u.update.tti_update_reply_index);
459         RETURN(rc);
460 }
461
462 static int out_index_insert(struct tgt_session_info *tsi)
463 {
464         struct tgt_thread_info  *tti    = tgt_th_info(tsi->tsi_env);
465         struct object_update    *update = tti->tti_u.update.tti_update;
466         struct dt_object        *obj    = tti->tti_u.update.tti_dt_object;
467         struct dt_insert_rec    *rec    = &tti->tti_rec;
468         struct lu_fid           *fid;
469         char                    *name;
470         __u32                   *ptype;
471         int                      rc     = 0;
472         size_t                   size;
473         ENTRY;
474
475         name = object_update_param_get(update, 0, NULL);
476         if (IS_ERR(name)) {
477                 CERROR("%s: empty name for index insert: rc = %ld\n",
478                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
479                 RETURN(PTR_ERR(name));
480         }
481
482         fid = object_update_param_get(update, 1, &size);
483         if (IS_ERR(fid) || size != sizeof(*fid)) {
484                 CERROR("%s: invalid fid: rc = %ld\n",
485                        tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
486                 RETURN(PTR_ERR(fid));
487         }
488
489         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
490                 lustre_swab_lu_fid(fid);
491
492         if (!fid_is_sane(fid)) {
493                 CERROR("%s: invalid FID "DFID": rc = %d\n",
494                        tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
495                 RETURN(-EPROTO);
496         }
497
498         ptype = object_update_param_get(update, 2, &size);
499         if (IS_ERR(ptype) || size != sizeof(*ptype)) {
500                 CERROR("%s: invalid type for index insert: rc = %ld\n",
501                        tgt_name(tsi->tsi_tgt), PTR_ERR(ptype));
502                 RETURN(PTR_ERR(ptype));
503         }
504
505         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
506                 __swab32s(ptype);
507
508         rec->rec_fid = fid;
509         rec->rec_type = *ptype;
510
511         rc = out_tx_index_insert(tsi->tsi_env, obj, (const struct dt_rec *)rec,
512                                  (const struct dt_key *)name, &tti->tti_tea,
513                                  tti->tti_tea.ta_handle,
514                                  tti->tti_u.update.tti_update_reply,
515                                  tti->tti_u.update.tti_update_reply_index);
516         RETURN(rc);
517 }
518
519 static int out_index_delete(struct tgt_session_info *tsi)
520 {
521         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
522         struct object_update    *update = tti->tti_u.update.tti_update;
523         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
524         char                    *name;
525         int                      rc = 0;
526
527         if (!lu_object_exists(&obj->do_lu))
528                 RETURN(-ENOENT);
529
530         name = object_update_param_get(update, 0, NULL);
531         if (IS_ERR(name)) {
532                 CERROR("%s: empty name for index delete: rc = %ld\n",
533                        tgt_name(tsi->tsi_tgt), PTR_ERR(name));
534                 RETURN(PTR_ERR(name));
535         }
536
537         rc = out_tx_index_delete(tsi->tsi_env, obj, (const struct dt_key *)name,
538                                  &tti->tti_tea, tti->tti_tea.ta_handle,
539                                  tti->tti_u.update.tti_update_reply,
540                                  tti->tti_u.update.tti_update_reply_index);
541         RETURN(rc);
542 }
543
544 static int out_destroy(struct tgt_session_info *tsi)
545 {
546         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
547         struct object_update    *update = tti->tti_u.update.tti_update;
548         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
549         struct lu_fid           *fid;
550         int                      rc;
551         ENTRY;
552
553         fid = &update->ou_fid;
554         if (!fid_is_sane(fid)) {
555                 CERROR("%s: invalid FID "DFID": rc = %d\n",
556                        tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
557                 RETURN(-EPROTO);
558         }
559
560         if (!lu_object_exists(&obj->do_lu))
561                 RETURN(-ENOENT);
562
563         rc = out_tx_destroy(tsi->tsi_env, obj, &tti->tti_tea,
564                             tti->tti_tea.ta_handle,
565                             tti->tti_u.update.tti_update_reply,
566                             tti->tti_u.update.tti_update_reply_index);
567
568         RETURN(rc);
569 }
570
571 static int out_write(struct tgt_session_info *tsi)
572 {
573         struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
574         struct object_update    *update = tti->tti_u.update.tti_update;
575         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
576         struct lu_buf           *lbuf = &tti->tti_buf;
577         char                    *buf;
578         __u64                   *tmp;
579         size_t                  size = 0;
580         size_t                  buf_len = 0;
581         loff_t                  pos;
582         int                      rc;
583         ENTRY;
584
585         buf = object_update_param_get(update, 0, &buf_len);
586         if (IS_ERR(buf) || buf_len == 0) {
587                 CERROR("%s: empty buf for xattr set: rc = %ld\n",
588                        tgt_name(tsi->tsi_tgt), PTR_ERR(buf));
589                 RETURN(PTR_ERR(buf));
590         }
591         lbuf->lb_buf = buf;
592         lbuf->lb_len = buf_len;
593
594         tmp = object_update_param_get(update, 1, &size);
595         if (IS_ERR(tmp) || size != sizeof(*tmp)) {
596                 CERROR("%s: empty or wrong size %zu pos: rc = %ld\n",
597                        tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
598                 RETURN(PTR_ERR(tmp));
599         }
600
601         if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
602                 __swab64s(tmp);
603         pos = *tmp;
604
605         rc = out_tx_write(tsi->tsi_env, obj, lbuf, pos,
606                           &tti->tti_tea, tti->tti_tea.ta_handle,
607                           tti->tti_u.update.tti_update_reply,
608                           tti->tti_u.update.tti_update_reply_index);
609         RETURN(rc);
610 }
611
612 static int out_read(struct tgt_session_info *tsi)
613 {
614         const struct lu_env     *env = tsi->tsi_env;
615         struct tgt_thread_info  *tti = tgt_th_info(env);
616         struct object_update    *update = tti->tti_u.update.tti_update;
617         struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
618         struct object_update_reply *reply = tti->tti_u.update.tti_update_reply;
619         int index = tti->tti_u.update.tti_update_reply_index;
620         struct lu_rdbuf *rdbuf;
621         struct object_update_result *update_result;
622         struct out_read_reply   *orr;
623         void *tmp;
624         size_t size;
625         size_t total_size = 0;
626         __u64 pos;
627         unsigned int i;
628         unsigned int nbufs;
629         int rc = 0;
630         ENTRY;
631
632         update_result = object_update_result_get(reply, index, NULL);
633         LASSERT(update_result != NULL);
634         update_result->our_datalen = sizeof(*orr);
635
636         if (!lu_object_exists(&obj->do_lu))
637                 GOTO(out, rc = -ENOENT);
638
639         tmp = object_update_param_get(update, 0, NULL);
640         if (IS_ERR(tmp)) {
641                 CERROR("%s: empty size for read: rc = %ld\n",
642                        tgt_name(tsi->tsi_tgt), PTR_ERR(tmp));
643                 GOTO(out, rc = PTR_ERR(tmp));
644         }
645         size = le64_to_cpu(*(size_t *)(tmp));
646
647         tmp = object_update_param_get(update, 1, NULL);
648         if (IS_ERR(tmp)) {
649                 CERROR("%s: empty pos for read: rc = %ld\n",
650                        tgt_name(tsi->tsi_tgt), PTR_ERR(tmp));
651                 GOTO(out, rc = PTR_ERR(tmp));
652         }
653         pos = le64_to_cpu(*(__u64 *)(tmp));
654
655         /* Put the offset into the begining of the buffer in reply */
656         orr = (struct out_read_reply *)update_result->our_data;
657
658         nbufs = (size + OUT_BULK_BUFFER_SIZE - 1) / OUT_BULK_BUFFER_SIZE;
659         OBD_ALLOC(rdbuf, sizeof(struct lu_rdbuf) +
660                          nbufs * sizeof(rdbuf->rb_bufs[0]));
661         if (rdbuf == NULL)
662                 GOTO(out, rc = -ENOMEM);
663
664         rdbuf->rb_nbufs = 0;
665         total_size = 0;
666         for (i = 0; i < nbufs; i++) {
667                 __u32 read_size;
668
669                 read_size = size > OUT_BULK_BUFFER_SIZE ?
670                             OUT_BULK_BUFFER_SIZE : size;
671                 OBD_ALLOC(rdbuf->rb_bufs[i].lb_buf, read_size);
672                 if (rdbuf->rb_bufs[i].lb_buf == NULL)
673                         GOTO(out_free, rc = -ENOMEM);
674
675                 rdbuf->rb_bufs[i].lb_len = read_size;
676                 dt_read_lock(env, obj, MOR_TGT_CHILD);
677                 rc = dt_read(env, obj, &rdbuf->rb_bufs[i], &pos);
678                 dt_read_unlock(env, obj);
679
680                 total_size += rc < 0 ? 0 : rc;
681                 if (rc <= 0)
682                         break;
683
684                 rdbuf->rb_nbufs++;
685                 size -= read_size;
686         }
687
688         /* send pages to client */
689         rc = tgt_send_buffer(tsi, rdbuf);
690         if (rc < 0)
691                 GOTO(out_free, rc);
692
693         orr->orr_size = total_size;
694         orr->orr_offset = pos;
695
696         orr_cpu_to_le(orr, orr);
697         update_result->our_datalen += orr->orr_size;
698 out_free:
699         for (i = 0; i < nbufs; i++) {
700                 if (rdbuf->rb_bufs[i].lb_buf != NULL) {
701                         OBD_FREE(rdbuf->rb_bufs[i].lb_buf,
702                                  rdbuf->rb_bufs[i].lb_len);
703                 }
704         }
705         OBD_FREE(rdbuf, sizeof(struct lu_rdbuf) +
706                         nbufs * sizeof(rdbuf->rb_bufs[0]));
707 out:
708         /* Insert read buffer */
709         update_result->our_rc = ptlrpc_status_hton(rc);
710         reply->ourp_lens[index] = cfs_size_round(update_result->our_datalen +
711                                                  sizeof(*update_result));
712         RETURN(rc);
713 }
714
715 static int out_noop(struct tgt_session_info *tsi)
716 {
717         return 0;
718 }
719
720 #define DEF_OUT_HNDL(opc, name, flags, fn)     \
721 [opc - OUT_CREATE] = {                                  \
722         .th_name    = name,                             \
723         .th_fail_id = 0,                                \
724         .th_opc     = opc,                              \
725         .th_flags   = flags,                            \
726         .th_act     = fn,                               \
727         .th_fmt     = NULL,                             \
728         .th_version = 0,                                \
729 }
730
731 static struct tgt_handler out_update_ops[] = {
732         DEF_OUT_HNDL(OUT_CREATE, "out_create", MUTABOR | HABEO_REFERO,
733                      out_create),
734         DEF_OUT_HNDL(OUT_DESTROY, "out_create", MUTABOR | HABEO_REFERO,
735                      out_destroy),
736         DEF_OUT_HNDL(OUT_REF_ADD, "out_ref_add", MUTABOR | HABEO_REFERO,
737                      out_ref_add),
738         DEF_OUT_HNDL(OUT_REF_DEL, "out_ref_del", MUTABOR | HABEO_REFERO,
739                      out_ref_del),
740         DEF_OUT_HNDL(OUT_ATTR_SET, "out_attr_set",  MUTABOR | HABEO_REFERO,
741                      out_attr_set),
742         DEF_OUT_HNDL(OUT_ATTR_GET, "out_attr_get",  HABEO_REFERO,
743                      out_attr_get),
744         DEF_OUT_HNDL(OUT_XATTR_SET, "out_xattr_set", MUTABOR | HABEO_REFERO,
745                      out_xattr_set),
746         DEF_OUT_HNDL(OUT_XATTR_DEL, "out_xattr_del", MUTABOR | HABEO_REFERO,
747                      out_xattr_del),
748         DEF_OUT_HNDL(OUT_XATTR_GET, "out_xattr_get", HABEO_REFERO,
749                      out_xattr_get),
750         DEF_OUT_HNDL(OUT_INDEX_LOOKUP, "out_index_lookup", HABEO_REFERO,
751                      out_index_lookup),
752         DEF_OUT_HNDL(OUT_INDEX_INSERT, "out_index_insert",
753                      MUTABOR | HABEO_REFERO, out_index_insert),
754         DEF_OUT_HNDL(OUT_INDEX_DELETE, "out_index_delete",
755                      MUTABOR | HABEO_REFERO, out_index_delete),
756         DEF_OUT_HNDL(OUT_WRITE, "out_write", MUTABOR | HABEO_REFERO, out_write),
757         DEF_OUT_HNDL(OUT_READ, "out_read", HABEO_REFERO, out_read),
758         DEF_OUT_HNDL(OUT_NOOP, "out_noop", HABEO_REFERO, out_noop),
759 };
760
761 static struct tgt_handler *out_handler_find(__u32 opc)
762 {
763         struct tgt_handler *h;
764
765         h = NULL;
766         if (OUT_CREATE <= opc && opc < OUT_LAST) {
767                 h = &out_update_ops[opc - OUT_CREATE];
768                 LASSERTF(h->th_opc == opc, "opcode mismatch %d != %d\n",
769                          h->th_opc, opc);
770         } else {
771                 h = NULL; /* unsupported opc */
772         }
773         return h;
774 }
775
776 static int out_tx_start(const struct lu_env *env, struct dt_device *dt,
777                         struct thandle_exec_args *ta, struct obd_export *exp)
778 {
779         ta->ta_argno = 0;
780         ta->ta_handle = dt_trans_create(env, dt);
781         if (IS_ERR(ta->ta_handle)) {
782                 int rc;
783
784                 rc = PTR_ERR(ta->ta_handle);
785                 ta->ta_handle = NULL;
786                 CERROR("%s: start handle error: rc = %d\n", dt_obd_name(dt),
787                        rc);
788                 return rc;
789         }
790         if (exp->exp_need_sync)
791                 ta->ta_handle->th_sync = 1;
792
793         return 0;
794 }
795
796 static int out_trans_start(const struct lu_env *env,
797                            struct thandle_exec_args *ta)
798 {
799         return dt_trans_start(env, ta->ta_handle->th_dev, ta->ta_handle);
800 }
801
802 static int out_trans_stop(const struct lu_env *env,
803                           struct thandle_exec_args *ta, int err)
804 {
805         int i;
806         int rc;
807
808         ta->ta_handle->th_result = err;
809         rc = dt_trans_stop(env, ta->ta_handle->th_dev, ta->ta_handle);
810         for (i = 0; i < ta->ta_argno; i++) {
811                 if (ta->ta_args[i]->object != NULL) {
812                         struct dt_object *obj = ta->ta_args[i]->object;
813
814                         /* If the object is being created during this
815                          * transaction, we need to remove them from the
816                          * cache immediately, because a few layers are
817                          * missing in OUT handler, i.e. the object might
818                          * not be initialized in all layers */
819                         if (ta->ta_args[i]->exec_fn == out_tx_create_exec)
820                                 set_bit(LU_OBJECT_HEARD_BANSHEE,
821                                         &obj->do_lu.lo_header->loh_flags);
822                         dt_object_put(env, ta->ta_args[i]->object);
823                         ta->ta_args[i]->object = NULL;
824                 }
825         }
826         ta->ta_handle = NULL;
827         ta->ta_argno = 0;
828
829         return rc;
830 }
831
832 static int out_tx_end(const struct lu_env *env, struct thandle_exec_args *ta,
833                       int declare_ret)
834 {
835         struct tgt_session_info *tsi = tgt_ses_info(env);
836         int                     i;
837         int                     rc;
838         int                     rc1;
839         ENTRY;
840
841         if (ta->ta_handle == NULL)
842                 RETURN(0);
843
844         if (declare_ret != 0 || ta->ta_argno == 0)
845                 GOTO(stop, rc = declare_ret);
846
847         LASSERT(ta->ta_handle->th_dev != NULL);
848         rc = out_trans_start(env, ta);
849         if (unlikely(rc != 0))
850                 GOTO(stop, rc);
851
852         for (i = 0; i < ta->ta_argno; i++) {
853                 rc = ta->ta_args[i]->exec_fn(env, ta->ta_handle,
854                                              ta->ta_args[i]);
855                 if (unlikely(rc != 0)) {
856                         CDEBUG(D_INFO, "error during execution of #%u from"
857                                " %s:%d: rc = %d\n", i, ta->ta_args[i]->file,
858                                ta->ta_args[i]->line, rc);
859                         while (--i >= 0) {
860                                 if (ta->ta_args[i]->undo_fn != NULL)
861                                         ta->ta_args[i]->undo_fn(env,
862                                                                ta->ta_handle,
863                                                                ta->ta_args[i]);
864                                 else
865                                         CERROR("%s: undo for %s:%d: rc = %d\n",
866                                              dt_obd_name(ta->ta_handle->th_dev),
867                                                ta->ta_args[i]->file,
868                                                ta->ta_args[i]->line, -ENOTSUPP);
869                         }
870                         break;
871                 }
872                 CDEBUG(D_INFO, "%s: executed %u/%u: rc = %d\n",
873                        dt_obd_name(ta->ta_handle->th_dev), i, ta->ta_argno, rc);
874         }
875
876         /* Only fail for real updates, XXX right now llog updates will be
877         * ignore, whose updates count is usually 1, so failover test
878         * case will spot this FAIL_UPDATE_NET_REP precisely, and it will
879         * be removed after async update patch is landed. */
880         if (ta->ta_argno > 1)
881                 tsi->tsi_reply_fail_id = OBD_FAIL_OUT_UPDATE_NET_REP;
882
883 stop:
884         rc1 = out_trans_stop(env, ta, rc);
885         if (rc == 0)
886                 rc = rc1;
887
888         ta->ta_handle = NULL;
889         ta->ta_argno = 0;
890
891         RETURN(rc);
892 }
893
894 /**
895  * Object updates between Targets. Because all the updates has been
896  * dis-assemblied into object updates at sender side, so OUT will
897  * call OSD API directly to execute these updates.
898  *
899  * In DNE phase I all of the updates in the request need to be executed
900  * in one transaction, and the transaction has to be synchronously.
901  *
902  * Please refer to lustre/include/lustre/lustre_idl.h for req/reply
903  * format.
904  */
905 int out_handle(struct tgt_session_info *tsi)
906 {
907         const struct lu_env             *env = tsi->tsi_env;
908         struct tgt_thread_info          *tti = tgt_th_info(env);
909         struct thandle_exec_args        *ta = &tti->tti_tea;
910         struct req_capsule              *pill = tsi->tsi_pill;
911         struct dt_device                *dt = tsi->tsi_tgt->lut_bottom;
912         struct out_update_header        *ouh;
913         struct out_update_buffer        *oub = NULL;
914         struct object_update            *update;
915         struct object_update_reply      *reply;
916         struct ptlrpc_bulk_desc         *desc = NULL;
917         struct l_wait_info              lwi;
918         void                            **update_bufs;
919         int                             current_batchid = -1;
920         __u32                           update_buf_count;
921         unsigned int                    i;
922         unsigned int                    reply_index = 0;
923         int                             rc = 0;
924         int                             rc1 = 0;
925         int                             ouh_size, reply_size;
926         int                             updates;
927         ENTRY;
928
929         req_capsule_set(pill, &RQF_OUT_UPDATE);
930         ouh_size = req_capsule_get_size(pill, &RMF_OUT_UPDATE_HEADER,
931                                         RCL_CLIENT);
932         if (ouh_size <= 0)
933                 RETURN(err_serious(-EPROTO));
934
935         ouh = req_capsule_client_get(pill, &RMF_OUT_UPDATE_HEADER);
936         if (ouh == NULL)
937                 RETURN(err_serious(-EPROTO));
938
939         if (ouh->ouh_magic != OUT_UPDATE_HEADER_MAGIC) {
940                 CERROR("%s: invalid update buffer magic %x expect %x: "
941                        "rc = %d\n", tgt_name(tsi->tsi_tgt), ouh->ouh_magic,
942                        UPDATE_REQUEST_MAGIC, -EPROTO);
943                 RETURN(err_serious(-EPROTO));
944         }
945
946         update_buf_count = ouh->ouh_count;
947         if (update_buf_count == 0)
948                 RETURN(err_serious(-EPROTO));
949
950         OBD_ALLOC(update_bufs, sizeof(*update_bufs) * update_buf_count);
951         if (update_bufs == NULL)
952                 RETURN(err_serious(-ENOMEM));
953
954         if (ouh->ouh_inline_length > 0) {
955                 update_bufs[0] = ouh->ouh_inline_data;
956         } else {
957                 struct out_update_buffer *tmp;
958
959                 oub = req_capsule_client_get(pill, &RMF_OUT_UPDATE_BUF);
960                 if (oub == NULL)
961                         GOTO(out_free, rc = err_serious(-EPROTO));
962
963                 desc = ptlrpc_prep_bulk_exp(pill->rc_req, update_buf_count,
964                                             PTLRPC_BULK_OPS_COUNT,
965                                             PTLRPC_BULK_GET_SINK |
966                                             PTLRPC_BULK_BUF_KVEC,
967                                             MDS_BULK_PORTAL,
968                                             &ptlrpc_bulk_kvec_ops);
969                 if (desc == NULL)
970                         GOTO(out_free, rc = err_serious(-ENOMEM));
971
972                 tmp = oub;
973                 for (i = 0; i < update_buf_count; i++, tmp++) {
974                         if (tmp->oub_size >= OUT_MAXREQSIZE)
975                                 GOTO(out_free, rc = err_serious(-EPROTO));
976
977                         OBD_ALLOC(update_bufs[i], tmp->oub_size);
978                         if (update_bufs[i] == NULL)
979                                 GOTO(out_free, rc = err_serious(-ENOMEM));
980
981                         desc->bd_frag_ops->add_iov_frag(desc, update_bufs[i],
982                                                         tmp->oub_size);
983                 }
984
985                 pill->rc_req->rq_bulk_write = 1;
986                 rc = sptlrpc_svc_prep_bulk(pill->rc_req, desc);
987                 if (rc != 0)
988                         GOTO(out_free, rc = err_serious(rc));
989
990                 rc = target_bulk_io(pill->rc_req->rq_export, desc, &lwi);
991                 if (rc < 0)
992                         GOTO(out_free, rc = err_serious(rc));
993         }
994         /* validate the request and calculate the total update count and
995          * set it to reply */
996         reply_size = 0;
997         updates = 0;
998         for (i = 0; i < update_buf_count; i++) {
999                 struct object_update_request    *our;
1000                 int                              j;
1001
1002                 our = update_bufs[i];
1003                 if (ptlrpc_req_need_swab(pill->rc_req))
1004                         lustre_swab_object_update_request(our);
1005
1006                 if (our->ourq_magic != UPDATE_REQUEST_MAGIC) {
1007                         CERROR("%s: invalid update buffer magic %x"
1008                                " expect %x: rc = %d\n",
1009                                tgt_name(tsi->tsi_tgt), our->ourq_magic,
1010                                UPDATE_REQUEST_MAGIC, -EPROTO);
1011                         GOTO(out_free, rc = err_serious(-EPROTO));
1012                 }
1013                 updates += our->ourq_count;
1014
1015                 /* need to calculate reply size */
1016                 for (j = 0; j < our->ourq_count; j++) {
1017                         update = object_update_request_get(our, j, NULL);
1018                         if (update == NULL)
1019                                 GOTO(out, rc = err_serious(-EPROTO));
1020                         if (ptlrpc_req_need_swab(pill->rc_req))
1021                                 lustre_swab_object_update(update);
1022
1023                         if (!fid_is_sane(&update->ou_fid)) {
1024                                 CERROR("%s: invalid FID "DFID": rc = %d\n",
1025                                        tgt_name(tsi->tsi_tgt),
1026                                        PFID(&update->ou_fid), -EPROTO);
1027                                 GOTO(out, rc = err_serious(-EPROTO));
1028                         }
1029
1030                         /* XXX: what ou_result_size can be considered safe? */
1031
1032                         reply_size += sizeof(reply->ourp_lens[0]);
1033                         reply_size += sizeof(struct object_update_result);
1034                         reply_size += update->ou_result_size;
1035                 }
1036         }
1037         reply_size += sizeof(*reply);
1038
1039         if (unlikely(reply_size > ouh->ouh_reply_size)) {
1040                 CERROR("%s: too small reply buf %u for %u, need %u at least\n",
1041                        tgt_name(tsi->tsi_tgt), ouh->ouh_reply_size,
1042                        updates, reply_size);
1043                 GOTO(out_free, rc = err_serious(-EPROTO));
1044         }
1045
1046         req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER,
1047                              ouh->ouh_reply_size);
1048         rc = req_capsule_server_pack(pill);
1049         if (rc != 0) {
1050                 CERROR("%s: Can't pack response: rc = %d\n",
1051                        tgt_name(tsi->tsi_tgt), rc);
1052                 GOTO(out_free, rc = err_serious(-EPROTO));
1053         }
1054
1055         /* Prepare the update reply buffer */
1056         reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY);
1057         if (reply == NULL)
1058                 GOTO(out_free, rc = -EPROTO);
1059         reply->ourp_magic = UPDATE_REPLY_MAGIC;
1060         reply->ourp_count = updates;
1061         tti->tti_u.update.tti_update_reply = reply;
1062         tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi));
1063
1064         /* Walk through updates in the request to execute them */
1065         for (i = 0; i < update_buf_count; i++) {
1066                 struct tgt_handler      *h;
1067                 struct dt_object        *dt_obj;
1068                 int                     update_count;
1069                 struct object_update_request *our;
1070                 int                     j;
1071
1072                 our = update_bufs[i];
1073                 update_count = our->ourq_count;
1074                 for (j = 0; j < update_count; j++) {
1075                         struct lu_object_conf conf;
1076
1077                         update = object_update_request_get(our, j, NULL);
1078                         if (update->ou_type == OUT_CREATE)
1079                                 conf.loc_flags = LOC_F_NEW;
1080                         else
1081                                 conf.loc_flags = 0;
1082
1083                         dt_obj = dt_locate_at(env, dt, &update->ou_fid,
1084                                 dt->dd_lu_dev.ld_site->ls_top_dev, &conf);
1085                         if (IS_ERR(dt_obj))
1086                                 GOTO(out, rc = PTR_ERR(dt_obj));
1087
1088                         if (dt->dd_record_fid_accessed) {
1089                                 struct lfsck_req_local *lrl = &tti->tti_lrl;
1090
1091                                 lfsck_pack_rfa(lrl,
1092                                                lu_object_fid(&dt_obj->do_lu),
1093                                                LEL_FID_ACCESSED,
1094                                                LFSCK_TYPE_LAYOUT);
1095                                 tgt_lfsck_in_notify_local(env, dt, lrl, NULL);
1096                         }
1097
1098                         tti->tti_u.update.tti_dt_object = dt_obj;
1099                         tti->tti_u.update.tti_update = update;
1100                         tti->tti_u.update.tti_update_reply_index = reply_index;
1101
1102                         h = out_handler_find(update->ou_type);
1103                         if (unlikely(h == NULL)) {
1104                                 CERROR("%s: unsupported opc: 0x%x\n",
1105                                        tgt_name(tsi->tsi_tgt), update->ou_type);
1106                                 GOTO(next, rc = -ENOTSUPP);
1107                         }
1108
1109                         /* Check resend case only for modifying RPC */
1110                         if (h->th_flags & MUTABOR) {
1111                                 struct ptlrpc_request *req = tgt_ses_req(tsi);
1112
1113                                 if (out_check_resent(env, dt, dt_obj, req,
1114                                                      out_reconstruct, reply,
1115                                                      reply_index))
1116                                         GOTO(next, rc = 0);
1117
1118                                 if (dt->dd_rdonly)
1119                                         GOTO(next, rc = -EROFS);
1120                         }
1121
1122                         /* start transaction for modification RPC only */
1123                         if (h->th_flags & MUTABOR && current_batchid == -1) {
1124                                 current_batchid = update->ou_batchid;
1125                                 rc = out_tx_start(env, dt, ta, tsi->tsi_exp);
1126                                 if (rc != 0)
1127                                         GOTO(next, rc);
1128
1129                                 if (update->ou_flags & UPDATE_FL_SYNC)
1130                                         ta->ta_handle->th_sync = 1;
1131                         }
1132
1133                         /* Stop the current update transaction, if the update
1134                          * has different batchid, or read-only update */
1135                         if (((current_batchid != update->ou_batchid) ||
1136                              !(h->th_flags & MUTABOR)) &&
1137                              ta->ta_handle != NULL) {
1138                                 rc = out_tx_end(env, ta, rc);
1139                                 current_batchid = -1;
1140                                 if (rc != 0)
1141                                         GOTO(next, rc);
1142
1143                                 /* start a new transaction if needed */
1144                                 if (h->th_flags & MUTABOR) {
1145                                         rc = out_tx_start(env, dt, ta,
1146                                                           tsi->tsi_exp);
1147                                         if (rc != 0)
1148                                                 GOTO(next, rc);
1149                                         if (update->ou_flags & UPDATE_FL_SYNC)
1150                                                 ta->ta_handle->th_sync = 1;
1151                                         current_batchid = update->ou_batchid;
1152                                 }
1153                         }
1154
1155                         rc = h->th_act(tsi);
1156 next:
1157                         reply_index++;
1158                         dt_object_put(env, dt_obj);
1159                         if (rc < 0)
1160                                 GOTO(out, rc);
1161                 }
1162         }
1163 out:
1164         if (current_batchid != -1) {
1165                 rc1 = out_tx_end(env, ta, rc);
1166                 if (rc == 0)
1167                         rc = rc1;
1168         }
1169
1170 out_free:
1171         if (update_bufs != NULL) {
1172                 if (oub != NULL) {
1173                         for (i = 0; i < update_buf_count; i++, oub++) {
1174                                 if (update_bufs[i] != NULL)
1175                                         OBD_FREE(update_bufs[i], oub->oub_size);
1176                         }
1177                 }
1178
1179                 OBD_FREE(update_bufs, sizeof(*update_bufs) * update_buf_count);
1180         }
1181
1182         if (desc != NULL)
1183                 ptlrpc_free_bulk(desc);
1184
1185         RETURN(rc);
1186 }
1187
1188 struct tgt_handler tgt_out_handlers[] = {
1189 TGT_UPDATE_HDL(MUTABOR, OUT_UPDATE,     out_handle),
1190 };
1191 EXPORT_SYMBOL(tgt_out_handlers);
1192