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