Whamcloud - gitweb
LU-15727 lod: honor append_pool with default composite layouts
[fs/lustre-release.git] / lustre / osp / osp_md_object.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, 2017, Intel Corporation.
24  */
25 /*
26  * lustre/osp/osp_md_object.c
27  *
28  * OST/MDT proxy device (OSP) Metadata methods
29  *
30  * This file implements methods for remote MD object, which include
31  * dt_object_operations, dt_index_operations and dt_body_operations.
32  *
33  * If there are multiple MDTs in one filesystem, one operation might
34  * include modifications in several MDTs. In such cases, clients
35  * send the RPC to the master MDT, then the operation is decomposed into
36  * object updates which will be dispatched to OSD or OSP. The local updates
37  * go to local OSD and the remote updates go to OSP. In OSP, these remote
38  * object updates will be packed into an update RPC, sent to the remote MDT
39  * and handled by Object Update Target (OUT).
40  *
41  * In DNE phase I, because of missing complete recovery solution, updates
42  * will be executed in order and synchronously.
43  *     1. The transaction is created.
44  *     2. In transaction declare, it collects and packs remote
45  *        updates (in osp_md_declare_xxx()).
46  *     3. In transaction start, it sends these remote updates
47  *        to remote MDTs, which will execute these updates synchronously.
48  *     4. In transaction execute phase, the local updates will be executed
49  *        synchronously.
50  *
51  * Author: Di Wang <di.wang@intel.com>
52  */
53
54 #define DEBUG_SUBSYSTEM S_MDS
55
56 #include <llog_swab.h>
57 #include <lustre_log.h>
58 #include "osp_internal.h"
59
60 #define OUT_UPDATE_BUFFER_SIZE_ADD      4096
61 #define OUT_UPDATE_BUFFER_SIZE_MAX      (256 * 4096)  /*  1M update size now */
62
63 /**
64  * Interpreter call for object creation
65  *
66  * Object creation interpreter, which will be called after creating
67  * the remote object to set flags and status.
68  *
69  * \param[in] env       execution environment
70  * \param[in] reply     update reply
71  * \param[in] req       ptlrpc update request for creating object
72  * \param[in] obj       object to be created
73  * \param[in] data      data used in this function.
74  * \param[in] index     index(position) of create update in the whole
75  *                      updates
76  * \param[in] rc        update result on the remote MDT.
77  *
78  * \retval              only return 0 for now
79  */
80 static int osp_create_interpreter(const struct lu_env *env,
81                                   struct object_update_reply *reply,
82                                   struct ptlrpc_request *req,
83                                   struct osp_object *obj,
84                                   void *data, int index, int rc)
85 {
86         if (rc != 0 && rc != -EEXIST) {
87                 obj->opo_obj.do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
88                 obj->opo_non_exist = 1;
89         }
90
91         /*
92          * invalidate opo cache for the object after the object is created, so
93          * attr_get will try to get attr from remote object.
94          */
95         osp_obj_invalidate_cache(obj);
96
97         return 0;
98 }
99
100 /**
101  * Implementation of dt_object_operations::do_declare_create
102  *
103  * Create the osp_update_request to track the update for this OSP
104  * in the transaction.
105  *
106  * \param[in] env       execution environment
107  * \param[in] dt        remote object to be created
108  * \param[in] attr      attribute of the created object
109  * \param[in] hint      creation hint
110  * \param[in] dof       creation format information
111  * \param[in] th        the transaction handle
112  *
113  * \retval              0 if preparation succeeds.
114  * \retval              negative errno if preparation fails.
115  */
116 int osp_md_declare_create(const struct lu_env *env, struct dt_object *dt,
117                           struct lu_attr *attr, struct dt_allocation_hint *hint,
118                           struct dt_object_format *dof, struct thandle *th)
119 {
120         return osp_trans_update_request_create(th);
121 }
122
123 struct object_update *
124 update_buffer_get_update(struct object_update_request *request,
125                          unsigned int index)
126 {
127         void    *ptr;
128         int     i;
129
130         if (index > request->ourq_count)
131                 return NULL;
132
133         ptr = &request->ourq_updates[0];
134         for (i = 0; i < index; i++)
135                 ptr += object_update_size(ptr);
136
137         return ptr;
138 }
139
140 /**
141  * Implementation of dt_object_operations::do_create
142  *
143  * It adds an OUT_CREATE sub-request into the OUT RPC that will be flushed
144  * when the transaction stop, and sets necessary flags for created object.
145  *
146  * \param[in] env       execution environment
147  * \param[in] dt        object to be created
148  * \param[in] attr      attribute of the created object
149  * \param[in] hint      creation hint
150  * \param[in] dof       creation format information
151  * \param[in] th        the transaction handle
152  *
153  * \retval              0 if packing creation succeeds.
154  * \retval              negative errno if packing creation fails.
155  */
156 int osp_md_create(const struct lu_env *env, struct dt_object *dt,
157                   struct lu_attr *attr, struct dt_allocation_hint *hint,
158                   struct dt_object_format *dof, struct thandle *th)
159 {
160         struct osp_update_request *update;
161         struct osp_object *obj = dt2osp_obj(dt);
162         int rc;
163
164         update = thandle_to_osp_update_request(th);
165         LASSERT(update != NULL);
166
167         if (!(attr->la_valid & LA_TYPE)) {
168                 CERROR("%s: create type not specified: valid %llx\n",
169                        dt->do_lu.lo_dev->ld_obd->obd_name, attr->la_valid);
170                 GOTO(out, rc = -EINVAL);
171         }
172
173         rc = OSP_UPDATE_RPC_PACK(env, out_create_pack, update,
174                                  lu_object_fid(&dt->do_lu), attr, hint, dof);
175         if (rc != 0)
176                 GOTO(out, rc);
177
178         rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
179                                         osp_create_interpreter);
180
181         if (rc < 0)
182                 GOTO(out, rc);
183
184         dt->do_lu.lo_header->loh_attr |= LOHA_EXISTS | (attr->la_mode & S_IFMT);
185         dt2osp_obj(dt)->opo_non_exist = 0;
186         obj->opo_stale = 0;
187
188         obj->opo_attr = *attr;
189 out:
190         return rc;
191 }
192
193 /**
194  * Implementation of dt_object_operations::do_declare_ref_del
195  *
196  * Create the osp_update_request to track the update for this OSP
197  * in the transaction.
198  *
199  * \param[in] env       execution environment
200  * \param[in] dt        object to decrease the reference count.
201  * \param[in] th        the transaction handle of refcount decrease.
202  *
203  * \retval              0 if preparation succeeds.
204  * \retval              negative errno if preparation fails.
205  */
206 static int osp_md_declare_ref_del(const struct lu_env *env,
207                                   struct dt_object *dt, struct thandle *th)
208 {
209         return osp_trans_update_request_create(th);
210 }
211
212 /**
213  * Implementation of dt_object_operations::do_ref_del
214  *
215  * Add an OUT_REF_DEL sub-request into the OUT RPC that will be
216  * flushed when the transaction stop.
217  *
218  * \param[in] env       execution environment
219  * \param[in] dt        object to decrease the reference count
220  * \param[in] th        the transaction handle
221  *
222  * \retval              0 if packing ref_del succeeds.
223  * \retval              negative errno if packing fails.
224  */
225 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
226                           struct thandle *th)
227 {
228         struct osp_update_request *update;
229         int rc;
230
231         update = thandle_to_osp_update_request(th);
232         LASSERT(update != NULL);
233
234         rc = OSP_UPDATE_RPC_PACK(env, out_ref_del_pack, update,
235                                  lu_object_fid(&dt->do_lu));
236         return rc;
237 }
238
239 /**
240  * Implementation of dt_object_operations::do_declare_ref_del
241  *
242  * Create the osp_update_request to track the update for this OSP
243  * in the transaction.
244  *
245  * \param[in] env       execution environment
246  * \param[in] dt        object on which to increase the reference count.
247  * \param[in] th        the transaction handle.
248  *
249  * \retval              0 if preparation succeeds.
250  * \retval              negative errno if preparation fails.
251  */
252 static int osp_md_declare_ref_add(const struct lu_env *env,
253                                   struct dt_object *dt, struct thandle *th)
254 {
255         return osp_trans_update_request_create(th);
256 }
257
258 /**
259  * Implementation of dt_object_operations::do_ref_add
260  *
261  * Add an OUT_REF_ADD sub-request into the OUT RPC that will be flushed
262  * when the transaction stop.
263  *
264  * \param[in] env       execution environment
265  * \param[in] dt        object on which to increase the reference count
266  * \param[in] th        the transaction handle
267  *
268  * \retval              0 if packing ref_add succeeds.
269  * \retval              negative errno if packing fails.
270  */
271 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
272                           struct thandle *th)
273 {
274         struct osp_update_request *update;
275         int rc;
276
277         update = thandle_to_osp_update_request(th);
278         LASSERT(update != NULL);
279
280         rc = OSP_UPDATE_RPC_PACK(env, out_ref_add_pack, update,
281                                  lu_object_fid(&dt->do_lu));
282         return rc;
283 }
284
285 /**
286  * Implementation of dt_object_operations::do_ah_init
287  *
288  * Initialize the allocation hint for object creation, which is usually called
289  * before the creation, and these hints (parent and child mode) will be sent to
290  * the remote Object Update Target (OUT) and used in the object create process,
291  * same as OSD object creation.
292  *
293  * \param[in] env       execution environment
294  * \param[in] ah        the hint to be initialized
295  * \param[in] parent    the parent of the object
296  * \param[in] child     the object to be created
297  * \param[in] child_mode the mode of the created object
298  */
299 static void osp_md_ah_init(const struct lu_env *env,
300                            struct dt_allocation_hint *ah,
301                            struct dt_object *parent,
302                            struct dt_object *child,
303                            umode_t child_mode)
304 {
305         LASSERT(ah);
306
307         ah->dah_parent = parent;
308 }
309
310 /**
311  * Implementation of dt_object_operations::do_declare_attr_get
312  *
313  * Create the osp_update_request to track the update for this OSP
314  * in the transaction.
315  *
316  * \param[in] env       execution environment
317  * \param[in] dt        object on which to set attributes
318  * \param[in] attr      attributes to be set
319  * \param[in] th        the transaction handle
320  *
321  * \retval              0 if preparation succeeds.
322  * \retval              negative errno if preparation fails.
323  */
324 int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
325                             const struct lu_attr *attr, struct thandle *th)
326 {
327         return osp_trans_update_request_create(th);
328 }
329
330 /**
331  * Implementation of dt_object_operations::do_attr_set
332  *
333  * Set attributes to the specified remote object.
334  *
335  * Add the OUT_ATTR_SET sub-request into the OUT RPC that will be flushed
336  * when the transaction stop.
337  *
338  * \param[in] env       execution environment
339  * \param[in] dt        object to set attributes
340  * \param[in] attr      attributes to be set
341  * \param[in] th        the transaction handle
342  *
343  * \retval              0 if packing attr_set succeeds.
344  * \retval              negative errno if packing fails.
345  */
346 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
347                     const struct lu_attr *attr, struct thandle *th)
348 {
349         struct osp_update_request *update;
350         int rc;
351
352         update = thandle_to_osp_update_request(th);
353         LASSERT(update != NULL);
354
355         rc = OSP_UPDATE_RPC_PACK(env, out_attr_set_pack, update,
356                                  lu_object_fid(&dt->do_lu), attr);
357         return rc;
358 }
359
360 /**
361  * Implementation of dt_object_operations::do_read_lock
362  *
363  * osp_md_{read,write}_lock() will only lock the remote object in the
364  * local cache, which uses the semaphore (opo_sem) inside the osp_object to
365  * lock the object. Note: it will not lock the object in the whole cluster,
366  * which relies on the LDLM lock.
367  *
368  * \param[in] env       execution environment
369  * \param[in] dt        object to be locked
370  * \param[in] role      lock role from MDD layer, see dt_object_role().
371  */
372 static void osp_md_read_lock(const struct lu_env *env, struct dt_object *dt,
373                              unsigned role)
374 {
375         struct osp_object  *obj = dt2osp_obj(dt);
376
377         LASSERT(obj->opo_owner != env);
378         down_read_nested(&obj->opo_sem, role);
379
380         LASSERT(obj->opo_owner == NULL);
381 }
382
383 /**
384  * Implementation of dt_object_operations::do_write_lock
385  *
386  * Lock the remote object in write mode.
387  *
388  * \param[in] env       execution environment
389  * \param[in] dt        object to be locked
390  * \param[in] role      lock role from MDD layer, see dt_object_role().
391  */
392 static void osp_md_write_lock(const struct lu_env *env, struct dt_object *dt,
393                               unsigned role)
394 {
395         struct osp_object *obj = dt2osp_obj(dt);
396
397         down_write_nested(&obj->opo_sem, role);
398
399         LASSERT(obj->opo_owner == NULL);
400         obj->opo_owner = env;
401 }
402
403 /**
404  * Implementation of dt_object_operations::do_read_unlock
405  *
406  * Unlock the read lock of remote object.
407  *
408  * \param[in] env       execution environment
409  * \param[in] dt        object to be unlocked
410  */
411 static void osp_md_read_unlock(const struct lu_env *env, struct dt_object *dt)
412 {
413         struct osp_object *obj = dt2osp_obj(dt);
414
415         up_read(&obj->opo_sem);
416 }
417
418 /**
419  * Implementation of dt_object_operations::do_write_unlock
420  *
421  * Unlock the write lock of remote object.
422  *
423  * \param[in] env       execution environment
424  * \param[in] dt        object to be unlocked
425  */
426 static void osp_md_write_unlock(const struct lu_env *env, struct dt_object *dt)
427 {
428         struct osp_object *obj = dt2osp_obj(dt);
429
430         LASSERT(obj->opo_owner == env);
431         obj->opo_owner = NULL;
432         up_write(&obj->opo_sem);
433 }
434
435 /**
436  * Implementation of dt_object_operations::do_write_locked
437  *
438  * Test if the object is locked in write mode.
439  *
440  * \param[in] env       execution environment
441  * \param[in] dt        object to be tested
442  */
443 static int osp_md_write_locked(const struct lu_env *env, struct dt_object *dt)
444 {
445         struct osp_object *obj = dt2osp_obj(dt);
446
447         return obj->opo_owner == env;
448 }
449
450 /**
451  * Implementation of dt_index_operations::dio_lookup
452  *
453  * Look up record by key under a remote index object. It packs lookup update
454  * into RPC, sends to the remote OUT and waits for the lookup result.
455  *
456  * \param[in] env       execution environment
457  * \param[in] dt        index object to lookup
458  * \param[out] rec      record in which to return lookup result
459  * \param[in] key       key of index which will be looked up
460  *
461  * \retval              1 if the lookup succeeds.
462  * \retval              negative errno if the lookup fails.
463  */
464 static int osp_md_index_lookup(const struct lu_env *env, struct dt_object *dt,
465                                struct dt_rec *rec, const struct dt_key *key)
466 {
467         struct lu_buf           *lbuf   = &osp_env_info(env)->osi_lb2;
468         struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
469         struct dt_device        *dt_dev = &osp->opd_dt_dev;
470         struct osp_update_request   *update;
471         struct object_update_reply *reply;
472         struct ptlrpc_request      *req = NULL;
473         struct lu_fid              *fid;
474         int                        rc;
475         ENTRY;
476
477         /* Because it needs send the update buffer right away,
478          * just create an update buffer, instead of attaching the
479          * update_remote list of the thandle.
480          */
481         update = osp_update_request_create(dt_dev);
482         if (IS_ERR(update))
483                 RETURN(PTR_ERR(update));
484
485         rc = OSP_UPDATE_RPC_PACK(env, out_index_lookup_pack, update,
486                                  lu_object_fid(&dt->do_lu), rec, key);
487         if (rc != 0) {
488                 CERROR("%s: Insert update error: rc = %d\n",
489                        dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
490                 GOTO(out, rc);
491         }
492
493         rc = osp_remote_sync(env, osp, update, &req);
494         if (rc < 0)
495                 GOTO(out, rc);
496
497         reply = req_capsule_server_sized_get(&req->rq_pill,
498                                              &RMF_OUT_UPDATE_REPLY,
499                                              OUT_UPDATE_REPLY_SIZE);
500         if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
501                 CERROR("%s: Wrong version %x expected %x: rc = %d\n",
502                        dt_dev->dd_lu_dev.ld_obd->obd_name,
503                        reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
504                 GOTO(out, rc = -EPROTO);
505         }
506
507         rc = object_update_result_data_get(reply, lbuf, 0);
508         if (rc < 0)
509                 GOTO(out, rc);
510
511         if (lbuf->lb_len != sizeof(*fid)) {
512                 CERROR("%s: lookup "DFID" %s wrong size %d\n",
513                        dt_dev->dd_lu_dev.ld_obd->obd_name,
514                        PFID(lu_object_fid(&dt->do_lu)), (char *)key,
515                        (int)lbuf->lb_len);
516                 GOTO(out, rc = -EINVAL);
517         }
518
519         fid = lbuf->lb_buf;
520         if (req_capsule_rep_need_swab(&req->rq_pill))
521                 lustre_swab_lu_fid(fid);
522         if (!fid_is_sane(fid)) {
523                 CERROR("%s: lookup "DFID" %s invalid fid "DFID"\n",
524                        dt_dev->dd_lu_dev.ld_obd->obd_name,
525                        PFID(lu_object_fid(&dt->do_lu)), (char *)key, PFID(fid));
526                 GOTO(out, rc = -EINVAL);
527         }
528
529         memcpy(rec, fid, sizeof(*fid));
530
531         GOTO(out, rc = 1);
532
533 out:
534         if (req != NULL)
535                 ptlrpc_req_finished(req);
536
537         osp_update_request_destroy(env, update);
538
539         return rc;
540 }
541
542 /**
543  * Implementation of dt_index_operations::dio_declare_insert
544  *
545  * Create the osp_update_request to track the update for this OSP
546  * in the transaction.
547  *
548  * \param[in] env       execution environment
549  * \param[in] dt        object for which to insert index
550  * \param[in] rec       record of the index which will be inserted
551  * \param[in] key       key of the index which will be inserted
552  * \param[in] th        the transaction handle
553  *
554  * \retval              0 if preparation succeeds.
555  * \retval              negative errno if preparation fails.
556  */
557 static int osp_md_declare_index_insert(const struct lu_env *env,
558                                        struct dt_object *dt,
559                                        const struct dt_rec *rec,
560                                        const struct dt_key *key,
561                                        struct thandle *th)
562 {
563         return osp_trans_update_request_create(th);
564 }
565
566 /**
567  * Implementation of dt_index_operations::dio_insert
568  *
569  * Add an OUT_INDEX_INSERT sub-request into the OUT RPC that will
570  * be flushed when the transaction stop.
571  *
572  * \param[in] env       execution environment
573  * \param[in] dt        object for which to insert index
574  * \param[in] rec       record of the index to be inserted
575  * \param[in] key       key of the index to be inserted
576  * \param[in] th        the transaction handle
577  *
578  * \retval              0 if packing index insert succeeds.
579  * \retval              negative errno if packing fails.
580  */
581 static int osp_md_index_insert(const struct lu_env *env, struct dt_object *dt,
582                                const struct dt_rec *rec,
583                                const struct dt_key *key, struct thandle *th)
584 {
585         struct osp_update_request *update;
586         int rc;
587
588         update = thandle_to_osp_update_request(th);
589         LASSERT(update != NULL);
590
591         rc = OSP_UPDATE_RPC_PACK(env, out_index_insert_pack, update,
592                                  lu_object_fid(&dt->do_lu), rec, key);
593         return rc;
594 }
595
596 /**
597  * Implementation of dt_index_operations::dio_declare_delete
598  *
599  * Create the osp_update_request to track the update for this OSP
600  * in the transaction.
601  *
602  * \param[in] env       execution environment
603  * \param[in] dt        object for which to delete index
604  * \param[in] key       key of the index
605  * \param[in] th        the transaction handle
606  *
607  * \retval              0 if preparation succeeds.
608  * \retval              negative errno if preparation fails.
609  */
610 static int osp_md_declare_index_delete(const struct lu_env *env,
611                                        struct dt_object *dt,
612                                        const struct dt_key *key,
613                                        struct thandle *th)
614 {
615         return osp_trans_update_request_create(th);
616 }
617
618 /**
619  * Implementation of dt_index_operations::dio_delete
620  *
621  * Add an OUT_INDEX_DELETE sub-request into the OUT RPC that will
622  * be flushed when the transaction stop.
623  *
624  * \param[in] env       execution environment
625  * \param[in] dt        object for which to delete index
626  * \param[in] key       key of the index which will be deleted
627  * \param[in] th        the transaction handle
628  *
629  * \retval              0 if packing index delete succeeds.
630  * \retval              negative errno if packing fails.
631  */
632 static int osp_md_index_delete(const struct lu_env *env,
633                                struct dt_object *dt,
634                                const struct dt_key *key,
635                                struct thandle *th)
636 {
637         struct osp_update_request *update;
638         int                      rc;
639
640         update = thandle_to_osp_update_request(th);
641         LASSERT(update != NULL);
642
643         rc = OSP_UPDATE_RPC_PACK(env, out_index_delete_pack, update,
644                                  lu_object_fid(&dt->do_lu), key);
645
646         return rc;
647 }
648
649 /**
650  * Implementation of dt_index_operations::dio_it.next
651  *
652  * Advance the pointer of the iterator to the next entry. It shares a similar
653  * internal implementation with osp_orphan_it_next(), which is being used for
654  * remote orphan index object. This method will be used for remote directory.
655  *
656  * \param[in] env       execution environment
657  * \param[in] di        iterator of this iteration
658  *
659  * \retval              0 if the pointer is advanced successfully.
660  * \retval              1 if it reaches to the end of the index object.
661  * \retval              negative errno if the pointer cannot be advanced.
662  */
663 static int osp_md_index_it_next(const struct lu_env *env, struct dt_it *di)
664 {
665         struct osp_it           *it = (struct osp_it *)di;
666         struct lu_idxpage       *idxpage;
667         struct lu_dirent        *ent = (struct lu_dirent *)it->ooi_ent;
668         int                     rc;
669         ENTRY;
670
671 again:
672         idxpage = it->ooi_cur_idxpage;
673         if (idxpage != NULL) {
674                 if (idxpage->lip_nr == 0)
675                         RETURN(1);
676
677                 it->ooi_pos_ent++;
678                 if (ent == NULL) {
679                         it->ooi_ent =
680                               (struct lu_dirent *)idxpage->lip_entries;
681                         RETURN(0);
682                 } else if (le16_to_cpu(ent->lde_reclen) != 0 &&
683                            it->ooi_pos_ent < idxpage->lip_nr) {
684                         ent = (struct lu_dirent *)(((char *)ent) +
685                                         le16_to_cpu(ent->lde_reclen));
686                         it->ooi_ent = ent;
687                         RETURN(0);
688                 } else {
689                         it->ooi_ent = NULL;
690                 }
691         }
692
693         rc = osp_it_next_page(env, di);
694         if (rc == 0)
695                 goto again;
696
697         RETURN(rc);
698 }
699
700 /**
701  * Implementation of dt_index_operations::dio_it.key
702  *
703  * Get the key at current iterator poisiton. These iteration methods
704  * (dio_it) will only be used for iterating the remote directory, so
705  * the key is the name of the directory entry.
706  *
707  * \param[in] env       execution environment
708  * \param[in] di        iterator of this iteration
709  *
710  * \retval              name of the current entry
711  */
712 static struct dt_key *osp_it_key(const struct lu_env *env,
713                                  const struct dt_it *di)
714 {
715         struct osp_it           *it = (struct osp_it *)di;
716         struct lu_dirent        *ent = (struct lu_dirent *)it->ooi_ent;
717
718         return (struct dt_key *)ent->lde_name;
719 }
720
721 /**
722  * Implementation of dt_index_operations::dio_it.key_size
723  *
724  * Get the key size at current iterator poisiton. These iteration methods
725  * (dio_it) will only be used for iterating the remote directory, so the key
726  * size is the name size of the directory entry.
727  *
728  * \param[in] env       execution environment
729  * \param[in] di        iterator of this iteration
730  *
731  * \retval              name size of the current entry
732  */
733
734 static int osp_it_key_size(const struct lu_env *env, const struct dt_it *di)
735 {
736         struct osp_it           *it = (struct osp_it *)di;
737         struct lu_dirent        *ent = (struct lu_dirent *)it->ooi_ent;
738
739         return (int)le16_to_cpu(ent->lde_namelen);
740 }
741
742 /**
743  * Implementation of dt_index_operations::dio_it.rec
744  *
745  * Get the record at current iterator position. These iteration methods
746  * (dio_it) will only be used for iterating the remote directory, so it
747  * uses lu_dirent_calc_size() to calculate the record size.
748  *
749  * \param[in] env       execution environment
750  * \param[in] di        iterator of this iteration
751  * \param[out] rec      the record to be returned
752  * \param[in] attr      attributes of the index object, so it knows
753  *                      how to pack the entry.
754  *
755  * \retval              only return 0 for now
756  */
757 static int osp_md_index_it_rec(const struct lu_env *env, const struct dt_it *di,
758                                struct dt_rec *rec, __u32 attr)
759 {
760         struct osp_it           *it = (struct osp_it *)di;
761         struct lu_dirent        *ent = (struct lu_dirent *)it->ooi_ent;
762         size_t                  reclen;
763
764         reclen = lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen), attr);
765         memcpy(rec, ent, reclen);
766         return 0;
767 }
768
769 /**
770  * Implementation of dt_index_operations::dio_it.load
771  *
772  * Locate the iteration cursor to the specified position (cookie).
773  *
774  * \param[in] env       pointer to the thread context
775  * \param[in] di        pointer to the iteration structure
776  * \param[in] hash      the specified position
777  *
778  * \retval              positive number for locating to the exactly position
779  *                      or the next
780  * \retval              0 for arriving at the end of the iteration
781  * \retval              negative error number on failure
782  */
783 static int osp_it_load(const struct lu_env *env, const struct dt_it *di,
784                        __u64 hash)
785 {
786         struct osp_it   *it     = (struct osp_it *)di;
787         int              rc;
788
789         it->ooi_next = hash;
790         rc = osp_md_index_it_next(env, (struct dt_it *)di);
791         if (rc == 1)
792                 return 0;
793
794         if (rc == 0)
795                 return 1;
796
797         return rc;
798 }
799
800 const struct dt_index_operations osp_md_index_ops = {
801         .dio_lookup         = osp_md_index_lookup,
802         .dio_declare_insert = osp_md_declare_index_insert,
803         .dio_insert         = osp_md_index_insert,
804         .dio_declare_delete = osp_md_declare_index_delete,
805         .dio_delete         = osp_md_index_delete,
806         .dio_it     = {
807                 .init     = osp_it_init,
808                 .fini     = osp_it_fini,
809                 .get      = osp_it_get,
810                 .put      = osp_it_put,
811                 .next     = osp_md_index_it_next,
812                 .key      = osp_it_key,
813                 .key_size = osp_it_key_size,
814                 .rec      = osp_md_index_it_rec,
815                 .store    = osp_it_store,
816                 .load     = osp_it_load,
817                 .key_rec  = osp_it_key_rec,
818         }
819 };
820
821 /**
822  * Implement OSP layer dt_object_operations::do_xattr_list() interface.
823  *
824  * List extended attribute from the specified MDT/OST object, result is not
825  * cached because this is called by directory migration only.
826  *
827  * \param[in] env       pointer to the thread context
828  * \param[in] dt        pointer to the OSP layer dt_object
829  * \param[out] buf      pointer to the lu_buf to hold the extended attribute
830  *
831  * \retval              positive bytes used/required in the buffer
832  * \retval              negative error number on failure
833  */
834 static int osp_md_xattr_list(const struct lu_env *env, struct dt_object *dt,
835                              const struct lu_buf *buf)
836 {
837         struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
838         struct osp_object *obj = dt2osp_obj(dt);
839         struct dt_device *dev = &osp->opd_dt_dev;
840         struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
841         struct osp_update_request *update = NULL;
842         struct ptlrpc_request *req = NULL;
843         struct object_update_reply *reply;
844         const char *dname  = dt->do_lu.lo_dev->ld_obd->obd_name;
845         int rc = 0;
846
847         ENTRY;
848
849         LASSERT(buf);
850
851         if (unlikely(obj->opo_non_exist))
852                 RETURN(-ENOENT);
853
854         update = osp_update_request_create(dev);
855         if (IS_ERR(update))
856                 RETURN(PTR_ERR(update));
857
858         rc = OSP_UPDATE_RPC_PACK(env, out_xattr_list_pack, update,
859                                  lu_object_fid(&dt->do_lu), buf->lb_len);
860         if (rc) {
861                 CERROR("%s: Insert update error "DFID": rc = %d\n",
862                        dname, PFID(lu_object_fid(&dt->do_lu)), rc);
863                 GOTO(out, rc);
864         }
865
866         rc = osp_remote_sync(env, osp, update, &req);
867         if (rc < 0) {
868                 if (rc == -ENOENT) {
869                         dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
870                         obj->opo_non_exist = 1;
871                 }
872                 GOTO(out, rc);
873         }
874
875         reply = req_capsule_server_sized_get(&req->rq_pill,
876                                              &RMF_OUT_UPDATE_REPLY,
877                                              OUT_UPDATE_REPLY_SIZE);
878         if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
879                 DEBUG_REQ(D_ERROR, req,
880                           "%s: Wrong version %x expected %x "DFID": rc = %d",
881                           dname, reply->ourp_magic, UPDATE_REPLY_MAGIC,
882                           PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
883
884                 GOTO(out, rc = -EPROTO);
885         }
886
887         rc = object_update_result_data_get(reply, rbuf, 0);
888         if (rc < 0)
889                 GOTO(out, rc);
890
891         if (!buf->lb_buf)
892                 GOTO(out, rc);
893
894         if (unlikely(buf->lb_len < rbuf->lb_len))
895                 GOTO(out, rc = -ERANGE);
896
897         memcpy(buf->lb_buf, rbuf->lb_buf, rbuf->lb_len);
898         EXIT;
899
900 out:
901         if (req)
902                 ptlrpc_req_finished(req);
903
904         if (update && !IS_ERR(update))
905                 osp_update_request_destroy(env, update);
906
907         return rc;
908 }
909
910 /**
911  * Implementation of dt_object_operations::do_index_try
912  *
913  * Try to initialize the index API pointer for the given object. This
914  * is the entry point of the index API, i.e. we must call this method
915  * to initialize the index object before calling other index methods.
916  *
917  * \param[in] env       execution environment
918  * \param[in] dt        index object to be initialized
919  * \param[in] feat      the index feature of the object
920  *
921  * \retval              0 if the initialization succeeds.
922  * \retval              negative errno if the initialization fails.
923  */
924 static int osp_md_index_try(const struct lu_env *env,
925                             struct dt_object *dt,
926                             const struct dt_index_features *feat)
927 {
928         dt->do_index_ops = &osp_md_index_ops;
929         return 0;
930 }
931
932 /**
933  * Implementation of dt_object_operations::do_object_lock
934  *
935  * Enqueue a lock (by ldlm_cli_enqueue()) of remote object on the remote MDT,
936  * which will lock the object in the global namespace. And because the
937  * cross-MDT locks are relatively rare compared with normal local MDT operation,
938  * let's release it right away, instead of putting it into the LRU list.
939  *
940  * \param[in] env       execution environment
941  * \param[in] dt        object to be locked
942  * \param[out] lh       lock handle
943  * \param[in] einfo     enqueue information
944  * \param[in] policy    lock policy
945  *
946  * \retval              ELDLM_OK if locking the object succeeds.
947  * \retval              negative errno if locking fails.
948  */
949 static int osp_md_object_lock(const struct lu_env *env,
950                               struct dt_object *dt,
951                               struct lustre_handle *lh,
952                               struct ldlm_enqueue_info *einfo,
953                               union ldlm_policy_data *policy)
954 {
955         struct ldlm_res_id      *res_id;
956         struct osp_device       *osp = dt2osp_dev(lu2dt_dev(dt->do_lu.lo_dev));
957         struct ptlrpc_request   *req;
958         int                     rc = 0;
959         __u64                   flags = LDLM_FL_NO_LRU;
960         ENTRY;
961
962         res_id = einfo->ei_res_id;
963         LASSERT(res_id != NULL);
964
965         if (einfo->ei_mode & (LCK_EX | LCK_PW))
966                 flags |= LDLM_FL_COS_INCOMPAT;
967
968         req = ldlm_enqueue_pack(osp->opd_exp, 0);
969         if (IS_ERR(req))
970                 RETURN(PTR_ERR(req));
971
972         osp_set_req_replay(osp, req);
973         rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
974                               (const union ldlm_policy_data *)policy,
975                               &flags, NULL, 0, LVB_T_NONE, lh, 0);
976
977         ptlrpc_req_finished(req);
978
979         RETURN(rc == ELDLM_OK ? 0 : -EIO);
980 }
981
982 /**
983  * Implementation of dt_object_operations::do_object_unlock
984  *
985  * Cancel a lock of a remote object.
986  *
987  * \param[in] env       execution environment
988  * \param[in] dt        object to be unlocked
989  * \param[in] einfo     lock enqueue information
990  * \param[in] policy    lock policy
991  *
992  * \retval              Only return 0 for now.
993  */
994 static int osp_md_object_unlock(const struct lu_env *env,
995                                 struct dt_object *dt,
996                                 struct ldlm_enqueue_info *einfo,
997                                 union ldlm_policy_data *policy)
998 {
999         struct lustre_handle    *lockh = einfo->ei_cbdata;
1000
1001         /* unlock finally */
1002         ldlm_lock_decref(lockh, einfo->ei_mode);
1003
1004         return 0;
1005 }
1006
1007 /**
1008  * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
1009  *
1010  * Create the dt_update_request to track the update for this OSP
1011  * in the transaction.
1012  *
1013  * \param[in] env       pointer to the thread context
1014  * \param[in] dt        pointer to the OSP layer dt_object to be destroyed
1015  * \param[in] th        pointer to the transaction handler
1016  *
1017  * \retval              0 for success
1018  * \retval              negative error number on failure
1019  */
1020 int osp_md_declare_destroy(const struct lu_env *env, struct dt_object *dt,
1021                            struct thandle *th)
1022 {
1023         return osp_trans_update_request_create(th);
1024 }
1025
1026 static int osp_destroy_interpreter(const struct lu_env *env,
1027                                    struct object_update_reply *reply,
1028                                    struct ptlrpc_request *req,
1029                                    struct osp_object *obj,
1030                                    void *data, int index, int rc)
1031 {
1032         return 0;
1033 }
1034
1035 /**
1036  * Implement OSP layer dt_object_operations::do_destroy() interface.
1037  *
1038  * Pack the destroy update into the RPC buffer, which will be sent
1039  * to the remote MDT during transaction stop.
1040  *
1041  * It also marks the object as non-cached.
1042  *
1043  * \param[in] env       pointer to the thread context
1044  * \param[in] dt        pointer to the OSP layer dt_object to be destroyed
1045  * \param[in] th        pointer to the transaction handler
1046  *
1047  * \retval              0 for success
1048  * \retval              negative error number on failure
1049  */
1050 int osp_md_destroy(const struct lu_env *env, struct dt_object *dt,
1051                    struct thandle *th)
1052 {
1053         struct osp_object *o = dt2osp_obj(dt);
1054         struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1055         struct osp_update_request *update;
1056         int rc = 0;
1057         ENTRY;
1058
1059         o->opo_non_exist = 1;
1060         o->opo_destroyed = 1;
1061
1062         LASSERT(osp->opd_connect_mdt);
1063         update = thandle_to_osp_update_request(th);
1064         LASSERT(update != NULL);
1065
1066         rc = OSP_UPDATE_RPC_PACK(env, out_destroy_pack, update,
1067                                  lu_object_fid(&dt->do_lu));
1068         if (rc != 0)
1069                 RETURN(rc);
1070
1071         /* retain the object and it's status until it's destroyed on remote */
1072         rc = osp_insert_update_callback(env, update, o, NULL,
1073                                         osp_destroy_interpreter);
1074         if (rc != 0)
1075                 RETURN(rc);
1076
1077         set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
1078         rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1079                                         NULL);
1080
1081         RETURN(rc);
1082 }
1083
1084 const struct dt_object_operations osp_md_obj_ops = {
1085         .do_read_lock         = osp_md_read_lock,
1086         .do_write_lock        = osp_md_write_lock,
1087         .do_read_unlock       = osp_md_read_unlock,
1088         .do_write_unlock      = osp_md_write_unlock,
1089         .do_write_locked      = osp_md_write_locked,
1090         .do_declare_create    = osp_md_declare_create,
1091         .do_create            = osp_md_create,
1092         .do_declare_ref_add   = osp_md_declare_ref_add,
1093         .do_ref_add           = osp_md_ref_add,
1094         .do_declare_ref_del   = osp_md_declare_ref_del,
1095         .do_ref_del           = osp_md_ref_del,
1096         .do_declare_destroy   = osp_md_declare_destroy,
1097         .do_destroy           = osp_md_destroy,
1098         .do_ah_init           = osp_md_ah_init,
1099         .do_attr_get          = osp_attr_get,
1100         .do_declare_attr_set  = osp_md_declare_attr_set,
1101         .do_attr_set          = osp_md_attr_set,
1102         .do_xattr_get         = osp_xattr_get,
1103         .do_xattr_list        = osp_md_xattr_list,
1104         .do_declare_xattr_set = osp_declare_xattr_set,
1105         .do_xattr_set         = osp_xattr_set,
1106         .do_declare_xattr_del = osp_declare_xattr_del,
1107         .do_xattr_del         = osp_xattr_del,
1108         .do_index_try         = osp_md_index_try,
1109         .do_object_lock       = osp_md_object_lock,
1110         .do_object_unlock     = osp_md_object_unlock,
1111         .do_invalidate        = osp_invalidate,
1112         .do_check_stale       = osp_check_stale,
1113 };
1114
1115 /**
1116  * Implementation of dt_body_operations::dbo_declare_write
1117  *
1118  * Create the osp_update_request to track the update for this OSP
1119  * in the transaction.
1120   *
1121  * \param[in] env       execution environment
1122  * \param[in] dt        object to be written
1123  * \param[in] buf       buffer to write which includes an embedded size field
1124  * \param[in] pos       offet in the object to start writing at
1125  * \param[in] th        transaction handle
1126  *
1127  * \retval              0 if preparation succeeds.
1128  * \retval              negative errno if preparation fails.
1129  */
1130 static ssize_t osp_md_declare_write(const struct lu_env *env,
1131                                     struct dt_object *dt,
1132                                     const struct lu_buf *buf,
1133                                     loff_t pos, struct thandle *th)
1134 {
1135         struct osp_device *osp = dt2osp_dev(th->th_dev);
1136         int rc;
1137
1138         if (dt2osp_obj(dt)->opo_destroyed)
1139                 return -ENOENT;
1140
1141         rc = osp_trans_update_request_create(th);
1142         if (rc != 0)
1143                 return rc;
1144
1145         if (osp->opd_update == NULL)
1146                 return 0;
1147
1148         if (dt2osp_obj(dt)->opo_stale)
1149                 return -ESTALE;
1150
1151         return 0;
1152 }
1153
1154 static int osp_write_interpreter(const struct lu_env *env,
1155                                   struct object_update_reply *reply,
1156                                   struct ptlrpc_request *req,
1157                                   struct osp_object *obj,
1158                                   void *data, int index, int rc)
1159 {
1160         if (rc) {
1161                 CDEBUG(D_HA, "error "DFID": rc = %d\n",
1162                        PFID(lu_object_fid(&obj->opo_obj.do_lu)), rc);
1163                 OBD_RACE(OBD_FAIL_OUT_OBJECT_MISS);
1164                 spin_lock(&obj->opo_lock);
1165                 obj->opo_attr.la_valid = 0;
1166                 obj->opo_stale = 1;
1167                 spin_unlock(&obj->opo_lock);
1168         }
1169         return 0;
1170 }
1171
1172 /**
1173  * Implementation of dt_body_operations::dbo_write
1174  *
1175  * Pack the write object update into the RPC buffer, which will be sent
1176  * to the remote MDT during transaction stop.
1177  *
1178  * \param[in] env       execution environment
1179  * \param[in] dt        object to be written
1180  * \param[in] buf       buffer to write which includes an embedded size field
1181  * \param[in] pos       offet in the object to start writing at
1182  * \param[in] th        transaction handle
1183  *
1184  * \retval              the buffer size in bytes if packing succeeds.
1185  * \retval              negative errno if packing fails.
1186  */
1187 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1188                             const struct lu_buf *buf, loff_t *pos,
1189                             struct thandle *th)
1190 {
1191         struct osp_object         *obj = dt2osp_obj(dt);
1192         struct osp_update_request  *update;
1193         struct osp_thandle        *oth = thandle_to_osp_thandle(th);
1194         ssize_t                   rc;
1195         ENTRY;
1196
1197         if (obj->opo_destroyed)
1198                 RETURN(-ENOENT);
1199
1200         update = thandle_to_osp_update_request(th);
1201         LASSERT(update != NULL);
1202
1203         CDEBUG(D_INFO, "write "DFID" offset = %llu length = %zu\n",
1204                PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
1205
1206         rc = OSP_UPDATE_RPC_PACK(env, out_write_pack, update,
1207                                  lu_object_fid(&dt->do_lu), buf, *pos);
1208         if (rc < 0)
1209                 RETURN(rc);
1210
1211         rc = osp_check_and_set_rpc_version(oth, obj);
1212         if (rc < 0)
1213                 RETURN(rc);
1214
1215         /* to be able to invalidate object's state in case of an error */
1216         rc = osp_insert_update_callback(env, update, obj, NULL,
1217                         osp_write_interpreter);
1218         if (rc < 0)
1219                 RETURN(rc);
1220
1221         /* XXX: how about the write error happened later? */
1222         *pos += buf->lb_len;
1223
1224         if (obj->opo_attr.la_valid & LA_SIZE && obj->opo_attr.la_size < *pos)
1225                 obj->opo_attr.la_size = *pos;
1226
1227         spin_lock(&obj->opo_lock);
1228         if (list_empty(&obj->opo_invalidate_cb_list)) {
1229                 lu_object_get(&obj->opo_obj.do_lu);
1230
1231                 list_add_tail(&obj->opo_invalidate_cb_list,
1232                               &update->our_invalidate_cb_list);
1233         }
1234         spin_unlock(&obj->opo_lock);
1235
1236         RETURN(buf->lb_len);
1237 }
1238
1239 static inline void orr_le_to_cpu(struct out_read_reply *orr_dst,
1240                                  const struct out_read_reply *orr_src)
1241 {
1242         orr_dst->orr_size = le32_to_cpu(orr_src->orr_size);
1243         orr_dst->orr_padding = le32_to_cpu(orr_src->orr_padding);
1244         orr_dst->orr_offset = le64_to_cpu(orr_dst->orr_offset);
1245 }
1246
1247
1248
1249 static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
1250                            struct lu_buf *rbuf, loff_t *pos)
1251 {
1252         struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1253         struct dt_device *dt_dev        = &osp->opd_dt_dev;
1254         struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
1255         char *ptr = rbuf->lb_buf;
1256         struct osp_update_request *update;
1257         struct ptlrpc_request *req = NULL;
1258         struct out_read_reply *orr;
1259         struct ptlrpc_bulk_desc *desc;
1260         struct object_update_reply *reply;
1261         int pages;
1262         int rc;
1263         ENTRY;
1264
1265         if (dt2osp_obj(dt)->opo_destroyed)
1266                 RETURN(-ENOENT);
1267
1268         /* Because it needs send the update buffer right away,
1269          * just create an update buffer, instead of attaching the
1270          * update_remote list of the thandle.  */
1271         update = osp_update_request_create(dt_dev);
1272         if (IS_ERR(update))
1273                 RETURN(PTR_ERR(update));
1274
1275         rc = OSP_UPDATE_RPC_PACK(env, out_read_pack, update,
1276                                  lu_object_fid(&dt->do_lu),
1277                                  rbuf->lb_len, *pos);
1278         if (rc != 0) {
1279                 CERROR("%s: cannot insert update: rc = %d\n",
1280                        dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
1281                 GOTO(out_update, rc);
1282         }
1283
1284         CDEBUG(D_INFO, "%s "DFID" read offset %llu size %zu\n",
1285                dt_dev->dd_lu_dev.ld_obd->obd_name,
1286                PFID(lu_object_fid(&dt->do_lu)), *pos, rbuf->lb_len);
1287         rc = osp_prep_update_req(env, osp->opd_obd->u.cli.cl_import, update,
1288                                  &req);
1289         if (rc != 0)
1290                 GOTO(out_update, rc);
1291
1292         /* First *and* last might be partial pages, hence +1 */
1293         pages = DIV_ROUND_UP(rbuf->lb_len, PAGE_SIZE) + 1;
1294
1295         /* allocate bulk descriptor */
1296         desc = ptlrpc_prep_bulk_imp(req, pages, 1,
1297                                     PTLRPC_BULK_PUT_SINK,
1298                                     MDS_BULK_PORTAL,
1299                                     &ptlrpc_bulk_kiov_nopin_ops);
1300         if (desc == NULL)
1301                 GOTO(out, rc = -ENOMEM);
1302
1303         desc->bd_frag_ops->add_iov_frag(desc, ptr, rbuf->lb_len);
1304
1305         osp_set_req_replay(osp, req);
1306         req->rq_bulk_read = 1;
1307         /* send request to master and wait for RPC to complete */
1308         rc = ptlrpc_queue_wait(req);
1309         if (rc != 0)
1310                 GOTO(out, rc);
1311
1312         rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1313                                           req->rq_bulk->bd_nob_transferred);
1314         if (rc < 0)
1315                 GOTO(out, rc);
1316
1317         reply = req_capsule_server_sized_get(&req->rq_pill,
1318                                              &RMF_OUT_UPDATE_REPLY,
1319                                              OUT_UPDATE_REPLY_SIZE);
1320
1321         if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1322                 CERROR("%s: invalid update reply magic %x expected %x:"
1323                        " rc = %d\n", dt_dev->dd_lu_dev.ld_obd->obd_name,
1324                        reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
1325                 GOTO(out, rc = -EPROTO);
1326         }
1327
1328         rc = object_update_result_data_get(reply, lbuf, 0);
1329         if (rc < 0)
1330                 GOTO(out, rc);
1331
1332         if (lbuf->lb_len < sizeof(*orr))
1333                 GOTO(out, rc = -EPROTO);
1334
1335         orr = lbuf->lb_buf;
1336         orr_le_to_cpu(orr, orr);
1337         rc = orr->orr_size;
1338         *pos = orr->orr_offset;
1339 out:
1340         ptlrpc_req_finished(req);
1341
1342 out_update:
1343         osp_update_request_destroy(env, update);
1344
1345         RETURN(rc);
1346 }
1347
1348 /* These body operation will be used to write symlinks during migration etc */
1349 const struct dt_body_operations osp_md_body_ops = {
1350         .dbo_declare_write      = osp_md_declare_write,
1351         .dbo_write              = osp_md_write,
1352         .dbo_read               = osp_md_read,
1353 };