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