4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2013, 2014, Intel Corporation.
26 * lustre/osp/osp_md_object.c
28 * OST/MDT proxy device (OSP) Metadata methods
30 * This file implements methods for remote MD object, which include
31 * dt_object_operations, dt_index_operations and dt_body_operations.
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).
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
51 * Author: Di Wang <di.wang@intel.com>
54 #define DEBUG_SUBSYSTEM S_MDS
56 #include <lustre_log.h>
57 #include "osp_internal.h"
59 #define OUT_UPDATE_BUFFER_SIZE_ADD 4096
60 #define OUT_UPDATE_BUFFER_SIZE_MAX (256 * 4096) /* 1M update size now */
63 * Interpreter call for object creation
65 * Object creation interpreter, which will be called after creating
66 * the remote object to set flags and status.
68 * \param[in] env execution environment
69 * \param[in] reply update reply
70 * \param[in] req ptlrpc update request for creating object
71 * \param[in] obj object to be created
72 * \param[in] data data used in this function.
73 * \param[in] index index(position) of create update in the whole
75 * \param[in] rc update result on the remote MDT.
77 * \retval only return 0 for now
79 static int osp_object_create_interpreter(const struct lu_env *env,
80 struct object_update_reply *reply,
81 struct ptlrpc_request *req,
82 struct osp_object *obj,
83 void *data, int index, int rc)
86 obj->opo_obj.do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
87 obj->opo_non_exist = 1;
93 * Implementation of dt_object_operations::do_declare_create
95 * Create the dt_update_request to track the update for this OSP
98 * \param[in] env execution environment
99 * \param[in] dt remote object to be created
100 * \param[in] attr attribute of the created object
101 * \param[in] hint creation hint
102 * \param[in] dof creation format information
103 * \param[in] th the transaction handle
105 * \retval 0 if preparation succeeds.
106 * \retval negative errno if preparation fails.
108 int osp_md_declare_object_create(const struct lu_env *env,
109 struct dt_object *dt,
110 struct lu_attr *attr,
111 struct dt_allocation_hint *hint,
112 struct dt_object_format *dof,
115 return osp_trans_update_request_create(th);
118 struct object_update *
119 update_buffer_get_update(struct object_update_request *request,
125 if (index > request->ourq_count)
128 ptr = &request->ourq_updates[0];
129 for (i = 0; i < index; i++)
130 ptr += object_update_size(ptr);
135 int osp_extend_update_buffer(const struct lu_env *env,
136 struct update_buffer *ubuf)
138 struct object_update_request *ureq;
139 size_t new_size = ubuf->ub_req_size + OUT_UPDATE_BUFFER_SIZE_ADD;
141 /* enlarge object update request size */
142 if (new_size > OUT_UPDATE_BUFFER_SIZE_MAX)
145 OBD_ALLOC_LARGE(ureq, new_size);
149 memcpy(ureq, ubuf->ub_req, ubuf->ub_req_size);
151 OBD_FREE_LARGE(ubuf->ub_req, ubuf->ub_req_size);
154 ubuf->ub_req_size = new_size;
160 * Implementation of dt_object_operations::do_create
162 * It adds an OUT_CREATE sub-request into the OUT RPC that will be flushed
163 * when the transaction stop, and sets necessary flags for created object.
165 * \param[in] env execution environment
166 * \param[in] dt object to be created
167 * \param[in] attr attribute of the created object
168 * \param[in] hint creation hint
169 * \param[in] dof creation format information
170 * \param[in] th the transaction handle
172 * \retval 0 if packing creation succeeds.
173 * \retval negative errno if packing creation fails.
175 int osp_md_object_create(const struct lu_env *env, struct dt_object *dt,
176 struct lu_attr *attr, struct dt_allocation_hint *hint,
177 struct dt_object_format *dof, struct thandle *th)
179 struct dt_update_request *update;
182 update = thandle_to_dt_update_request(th);
183 LASSERT(update != NULL);
185 rc = osp_update_rpc_pack(env, create, update, OUT_CREATE,
186 lu_object_fid(&dt->do_lu), attr, hint, dof);
190 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
191 osp_object_create_interpreter);
196 dt->do_lu.lo_header->loh_attr |= LOHA_EXISTS | (attr->la_mode & S_IFMT);
197 dt2osp_obj(dt)->opo_non_exist = 0;
203 * Implementation of dt_object_operations::do_declare_ref_del
205 * Create the dt_update_request to track the update for this OSP
206 * in the transaction.
208 * \param[in] env execution environment
209 * \param[in] dt object to decrease the reference count.
210 * \param[in] th the transaction handle of refcount decrease.
212 * \retval 0 if preparation succeeds.
213 * \retval negative errno if preparation fails.
215 static int osp_md_declare_ref_del(const struct lu_env *env,
216 struct dt_object *dt, struct thandle *th)
218 return osp_trans_update_request_create(th);
222 * Implementation of dt_object_operations::do_ref_del
224 * Add an OUT_REF_DEL sub-request into the OUT RPC that will be
225 * flushed when the transaction stop.
227 * \param[in] env execution environment
228 * \param[in] dt object to decrease the reference count
229 * \param[in] th the transaction handle
231 * \retval 0 if packing ref_del succeeds.
232 * \retval negative errno if packing fails.
234 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
237 struct dt_update_request *update;
240 update = thandle_to_dt_update_request(th);
241 LASSERT(update != NULL);
243 rc = osp_update_rpc_pack(env, ref_del, update, OUT_REF_DEL,
244 lu_object_fid(&dt->do_lu));
249 * Implementation of dt_object_operations::do_declare_ref_del
251 * Create the dt_update_request to track the update for this OSP
252 * in the transaction.
254 * \param[in] env execution environment
255 * \param[in] dt object on which to increase the reference count.
256 * \param[in] th the transaction handle.
258 * \retval 0 if preparation succeeds.
259 * \retval negative errno if preparation fails.
261 static int osp_md_declare_ref_add(const struct lu_env *env,
262 struct dt_object *dt, struct thandle *th)
264 return osp_trans_update_request_create(th);
268 * Implementation of dt_object_operations::do_ref_add
270 * Add an OUT_REF_ADD sub-request into the OUT RPC that will be flushed
271 * when the transaction stop.
273 * \param[in] env execution environment
274 * \param[in] dt object on which to increase the reference count
275 * \param[in] th the transaction handle
277 * \retval 0 if packing ref_add succeeds.
278 * \retval negative errno if packing fails.
280 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
283 struct dt_update_request *update;
286 update = thandle_to_dt_update_request(th);
287 LASSERT(update != NULL);
289 rc = osp_update_rpc_pack(env, ref_add, update, OUT_REF_ADD,
290 lu_object_fid(&dt->do_lu));
295 * Implementation of dt_object_operations::do_ah_init
297 * Initialize the allocation hint for object creation, which is usually called
298 * before the creation, and these hints (parent and child mode) will be sent to
299 * the remote Object Update Target (OUT) and used in the object create process,
300 * same as OSD object creation.
302 * \param[in] env execution environment
303 * \param[in] ah the hint to be initialized
304 * \param[in] parent the parent of the object
305 * \param[in] child the object to be created
306 * \param[in] child_mode the mode of the created object
308 static void osp_md_ah_init(const struct lu_env *env,
309 struct dt_allocation_hint *ah,
310 struct dt_object *parent,
311 struct dt_object *child,
316 ah->dah_parent = parent;
317 ah->dah_mode = child_mode;
321 * Implementation of dt_object_operations::do_declare_attr_get
323 * Create the dt_update_request to track the update for this OSP
324 * in the transaction.
326 * \param[in] env execution environment
327 * \param[in] dt object on which to set attributes
328 * \param[in] attr attributes to be set
329 * \param[in] th the transaction handle
331 * \retval 0 if preparation succeeds.
332 * \retval negative errno if preparation fails.
334 int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
335 const struct lu_attr *attr, struct thandle *th)
337 return osp_trans_update_request_create(th);
341 * Implementation of dt_object_operations::do_attr_set
343 * Set attributes to the specified remote object.
345 * Add the OUT_ATTR_SET sub-request into the OUT RPC that will be flushed
346 * when the transaction stop.
348 * \param[in] env execution environment
349 * \param[in] dt object to set attributes
350 * \param[in] attr attributes to be set
351 * \param[in] th the transaction handle
353 * \retval 0 if packing attr_set succeeds.
354 * \retval negative errno if packing fails.
356 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
357 const struct lu_attr *attr, struct thandle *th)
359 struct dt_update_request *update;
362 update = thandle_to_dt_update_request(th);
363 LASSERT(update != NULL);
365 rc = osp_update_rpc_pack(env, attr_set, update, OUT_ATTR_SET,
366 lu_object_fid(&dt->do_lu), attr);
371 * Implementation of dt_object_operations::do_read_lock
373 * osp_md_object_{read,write}_lock() will only lock the remote object in the
374 * local cache, which uses the semaphore (opo_sem) inside the osp_object to
375 * lock the object. Note: it will not lock the object in the whole cluster,
376 * which relies on the LDLM lock.
378 * \param[in] env execution environment
379 * \param[in] dt object to be locked
380 * \param[in] role lock role from MDD layer, see mdd_object_role().
382 static void osp_md_object_read_lock(const struct lu_env *env,
383 struct dt_object *dt, unsigned role)
385 struct osp_object *obj = dt2osp_obj(dt);
387 LASSERT(obj->opo_owner != env);
388 down_read_nested(&obj->opo_sem, role);
390 LASSERT(obj->opo_owner == NULL);
394 * Implementation of dt_object_operations::do_write_lock
396 * Lock the remote object in write mode.
398 * \param[in] env execution environment
399 * \param[in] dt object to be locked
400 * \param[in] role lock role from MDD layer, see mdd_object_role().
402 static void osp_md_object_write_lock(const struct lu_env *env,
403 struct dt_object *dt, unsigned role)
405 struct osp_object *obj = dt2osp_obj(dt);
407 down_write_nested(&obj->opo_sem, role);
409 LASSERT(obj->opo_owner == NULL);
410 obj->opo_owner = env;
414 * Implementation of dt_object_operations::do_read_unlock
416 * Unlock the read lock of remote object.
418 * \param[in] env execution environment
419 * \param[in] dt object to be unlocked
421 static void osp_md_object_read_unlock(const struct lu_env *env,
422 struct dt_object *dt)
424 struct osp_object *obj = dt2osp_obj(dt);
426 up_read(&obj->opo_sem);
430 * Implementation of dt_object_operations::do_write_unlock
432 * Unlock the write lock of remote object.
434 * \param[in] env execution environment
435 * \param[in] dt object to be unlocked
437 static void osp_md_object_write_unlock(const struct lu_env *env,
438 struct dt_object *dt)
440 struct osp_object *obj = dt2osp_obj(dt);
442 LASSERT(obj->opo_owner == env);
443 obj->opo_owner = NULL;
444 up_write(&obj->opo_sem);
448 * Implementation of dt_object_operations::do_write_locked
450 * Test if the object is locked in write mode.
452 * \param[in] env execution environment
453 * \param[in] dt object to be tested
455 static int osp_md_object_write_locked(const struct lu_env *env,
456 struct dt_object *dt)
458 struct osp_object *obj = dt2osp_obj(dt);
460 return obj->opo_owner == env;
464 * Implementation of dt_index_operations::dio_lookup
466 * Look up record by key under a remote index object. It packs lookup update
467 * into RPC, sends to the remote OUT and waits for the lookup result.
469 * \param[in] env execution environment
470 * \param[in] dt index object to lookup
471 * \param[out] rec record in which to return lookup result
472 * \param[in] key key of index which will be looked up
474 * \retval 1 if the lookup succeeds.
475 * \retval negative errno if the lookup fails.
477 static int osp_md_index_lookup(const struct lu_env *env, struct dt_object *dt,
478 struct dt_rec *rec, const struct dt_key *key)
480 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
481 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
482 struct dt_device *dt_dev = &osp->opd_dt_dev;
483 struct dt_update_request *update;
484 struct object_update_reply *reply;
485 struct ptlrpc_request *req = NULL;
490 /* Because it needs send the update buffer right away,
491 * just create an update buffer, instead of attaching the
492 * update_remote list of the thandle.
494 update = dt_update_request_create(dt_dev);
496 RETURN(PTR_ERR(update));
498 rc = osp_update_rpc_pack(env, index_lookup, update, OUT_INDEX_LOOKUP,
499 lu_object_fid(&dt->do_lu), rec, key);
501 CERROR("%s: Insert update error: rc = %d\n",
502 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
506 rc = osp_remote_sync(env, osp, update, &req);
510 reply = req_capsule_server_sized_get(&req->rq_pill,
511 &RMF_OUT_UPDATE_REPLY,
512 OUT_UPDATE_REPLY_SIZE);
513 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
514 CERROR("%s: Wrong version %x expected %x: rc = %d\n",
515 dt_dev->dd_lu_dev.ld_obd->obd_name,
516 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
517 GOTO(out, rc = -EPROTO);
520 rc = object_update_result_data_get(reply, lbuf, 0);
524 if (lbuf->lb_len != sizeof(*fid)) {
525 CERROR("%s: lookup "DFID" %s wrong size %d\n",
526 dt_dev->dd_lu_dev.ld_obd->obd_name,
527 PFID(lu_object_fid(&dt->do_lu)), (char *)key,
529 GOTO(out, rc = -EINVAL);
533 if (ptlrpc_rep_need_swab(req))
534 lustre_swab_lu_fid(fid);
535 if (!fid_is_sane(fid)) {
536 CERROR("%s: lookup "DFID" %s invalid fid "DFID"\n",
537 dt_dev->dd_lu_dev.ld_obd->obd_name,
538 PFID(lu_object_fid(&dt->do_lu)), (char *)key, PFID(fid));
539 GOTO(out, rc = -EINVAL);
542 memcpy(rec, fid, sizeof(*fid));
548 ptlrpc_req_finished(req);
550 dt_update_request_destroy(update);
556 * Implementation of dt_index_operations::dio_declare_insert
558 * Create the dt_update_request to track the update for this OSP
559 * in the transaction.
561 * \param[in] env execution environment
562 * \param[in] dt object for which to insert index
563 * \param[in] rec record of the index which will be inserted
564 * \param[in] key key of the index which will be inserted
565 * \param[in] th the transaction handle
567 * \retval 0 if preparation succeeds.
568 * \retval negative errno if preparation fails.
570 static int osp_md_declare_index_insert(const struct lu_env *env,
571 struct dt_object *dt,
572 const struct dt_rec *rec,
573 const struct dt_key *key,
576 return osp_trans_update_request_create(th);
580 * Implementation of dt_index_operations::dio_insert
582 * Add an OUT_INDEX_INSERT sub-request into the OUT RPC that will
583 * be flushed when the transaction stop.
585 * \param[in] env execution environment
586 * \param[in] dt object for which to insert index
587 * \param[in] rec record of the index to be inserted
588 * \param[in] key key of the index to be inserted
589 * \param[in] th the transaction handle
590 * \param[in] ignore_quota quota enforcement for insert
592 * \retval 0 if packing index insert succeeds.
593 * \retval negative errno if packing fails.
595 static int osp_md_index_insert(const struct lu_env *env,
596 struct dt_object *dt,
597 const struct dt_rec *rec,
598 const struct dt_key *key,
602 struct osp_thandle *oth = thandle_to_osp_thandle(th);
603 struct dt_update_request *update = oth->ot_dur;
606 rc = osp_update_rpc_pack(env, index_insert, update, OUT_INDEX_INSERT,
607 lu_object_fid(&dt->do_lu), rec, key);
612 * Implementation of dt_index_operations::dio_declare_delete
614 * Create the dt_update_request to track the update for this OSP
615 * in the transaction.
617 * \param[in] env execution environment
618 * \param[in] dt object for which to delete index
619 * \param[in] key key of the index
620 * \param[in] th the transaction handle
622 * \retval 0 if preparation succeeds.
623 * \retval negative errno if preparation fails.
625 static int osp_md_declare_index_delete(const struct lu_env *env,
626 struct dt_object *dt,
627 const struct dt_key *key,
630 return osp_trans_update_request_create(th);
634 * Implementation of dt_index_operations::dio_delete
636 * Add an OUT_INDEX_DELETE sub-request into the OUT RPC that will
637 * be flushed when the transaction stop.
639 * \param[in] env execution environment
640 * \param[in] dt object for which to delete index
641 * \param[in] key key of the index which will be deleted
642 * \param[in] th the transaction handle
644 * \retval 0 if packing index delete succeeds.
645 * \retval negative errno if packing fails.
647 static int osp_md_index_delete(const struct lu_env *env,
648 struct dt_object *dt,
649 const struct dt_key *key,
652 struct dt_update_request *update;
655 update = thandle_to_dt_update_request(th);
656 LASSERT(update != NULL);
658 rc = osp_update_rpc_pack(env, index_delete, update, OUT_INDEX_DELETE,
659 lu_object_fid(&dt->do_lu), key);
665 * Implementation of dt_index_operations::dio_it.next
667 * Advance the pointer of the iterator to the next entry. It shares a similar
668 * internal implementation with osp_orphan_it_next(), which is being used for
669 * remote orphan index object. This method will be used for remote directory.
671 * \param[in] env execution environment
672 * \param[in] di iterator of this iteration
674 * \retval 0 if the pointer is advanced successfuly.
675 * \retval 1 if it reaches to the end of the index object.
676 * \retval negative errno if the pointer cannot be advanced.
678 static int osp_md_index_it_next(const struct lu_env *env, struct dt_it *di)
680 struct osp_it *it = (struct osp_it *)di;
681 struct lu_idxpage *idxpage;
682 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
687 idxpage = it->ooi_cur_idxpage;
688 if (idxpage != NULL) {
689 if (idxpage->lip_nr == 0)
695 (struct lu_dirent *)idxpage->lip_entries;
697 } else if (le16_to_cpu(ent->lde_reclen) != 0 &&
698 it->ooi_pos_ent < idxpage->lip_nr) {
699 ent = (struct lu_dirent *)(((char *)ent) +
700 le16_to_cpu(ent->lde_reclen));
708 rc = osp_it_next_page(env, di);
716 * Implementation of dt_index_operations::dio_it.key
718 * Get the key at current iterator poisiton. These iteration methods
719 * (dio_it) will only be used for iterating the remote directory, so
720 * the key is the name of the directory entry.
722 * \param[in] env execution environment
723 * \param[in] di iterator of this iteration
725 * \retval name of the current entry
727 static struct dt_key *osp_it_key(const struct lu_env *env,
728 const struct dt_it *di)
730 struct osp_it *it = (struct osp_it *)di;
731 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
733 return (struct dt_key *)ent->lde_name;
737 * Implementation of dt_index_operations::dio_it.key_size
739 * Get the key size at current iterator poisiton. These iteration methods
740 * (dio_it) will only be used for iterating the remote directory, so the key
741 * size is the name size of the directory entry.
743 * \param[in] env execution environment
744 * \param[in] di iterator of this iteration
746 * \retval name size of the current entry
749 static int osp_it_key_size(const struct lu_env *env, const struct dt_it *di)
751 struct osp_it *it = (struct osp_it *)di;
752 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
754 return (int)le16_to_cpu(ent->lde_namelen);
758 * Implementation of dt_index_operations::dio_it.rec
760 * Get the record at current iterator position. These iteration methods
761 * (dio_it) will only be used for iterating the remote directory, so it
762 * uses lu_dirent_calc_size() to calculate the record size.
764 * \param[in] env execution environment
765 * \param[in] di iterator of this iteration
766 * \param[out] rec the record to be returned
767 * \param[in] attr attributes of the index object, so it knows
768 * how to pack the entry.
770 * \retval only return 0 for now
772 static int osp_md_index_it_rec(const struct lu_env *env, const struct dt_it *di,
773 struct dt_rec *rec, __u32 attr)
775 struct osp_it *it = (struct osp_it *)di;
776 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
779 reclen = lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen), attr);
780 memcpy(rec, ent, reclen);
785 * Implementation of dt_index_operations::dio_it.load
787 * Locate the iteration cursor to the specified position (cookie).
789 * \param[in] env pointer to the thread context
790 * \param[in] di pointer to the iteration structure
791 * \param[in] hash the specified position
793 * \retval positive number for locating to the exactly position
795 * \retval 0 for arriving at the end of the iteration
796 * \retval negative error number on failure
798 static int osp_it_load(const struct lu_env *env, const struct dt_it *di,
801 struct osp_it *it = (struct osp_it *)di;
805 rc = osp_md_index_it_next(env, (struct dt_it *)di);
815 const struct dt_index_operations osp_md_index_ops = {
816 .dio_lookup = osp_md_index_lookup,
817 .dio_declare_insert = osp_md_declare_index_insert,
818 .dio_insert = osp_md_index_insert,
819 .dio_declare_delete = osp_md_declare_index_delete,
820 .dio_delete = osp_md_index_delete,
826 .next = osp_md_index_it_next,
828 .key_size = osp_it_key_size,
829 .rec = osp_md_index_it_rec,
830 .store = osp_it_store,
832 .key_rec = osp_it_key_rec,
837 * Implementation of dt_object_operations::do_index_try
839 * Try to initialize the index API pointer for the given object. This
840 * is the entry point of the index API, i.e. we must call this method
841 * to initialize the index object before calling other index methods.
843 * \param[in] env execution environment
844 * \param[in] dt index object to be initialized
845 * \param[in] feat the index feature of the object
847 * \retval 0 if the initialization succeeds.
848 * \retval negative errno if the initialization fails.
850 static int osp_md_index_try(const struct lu_env *env,
851 struct dt_object *dt,
852 const struct dt_index_features *feat)
854 dt->do_index_ops = &osp_md_index_ops;
859 * Implementation of dt_object_operations::do_object_lock
861 * Enqueue a lock (by ldlm_cli_enqueue()) of remote object on the remote MDT,
862 * which will lock the object in the global namespace.
864 * \param[in] env execution environment
865 * \param[in] dt object to be locked
866 * \param[out] lh lock handle
867 * \param[in] einfo enqueue information
868 * \param[in] policy lock policy
870 * \retval ELDLM_OK if locking the object succeeds.
871 * \retval negative errno if locking fails.
873 static int osp_md_object_lock(const struct lu_env *env,
874 struct dt_object *dt,
875 struct lustre_handle *lh,
876 struct ldlm_enqueue_info *einfo,
877 ldlm_policy_data_t *policy)
879 struct ldlm_res_id *res_id;
880 struct dt_device *dt_dev = lu2dt_dev(dt->do_lu.lo_dev);
881 struct osp_device *osp = dt2osp_dev(dt_dev);
882 struct ptlrpc_request *req;
887 res_id = einfo->ei_res_id;
888 LASSERT(res_id != NULL);
890 mode = ldlm_lock_match(osp->opd_obd->obd_namespace,
891 LDLM_FL_BLOCK_GRANTED, res_id,
892 einfo->ei_type, policy,
893 einfo->ei_mode, lh, 0);
897 req = ldlm_enqueue_pack(osp->opd_exp, 0);
899 RETURN(PTR_ERR(req));
901 rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
902 (const ldlm_policy_data_t *)policy,
903 &flags, NULL, 0, LVB_T_NONE, lh, 0);
905 ptlrpc_req_finished(req);
907 return rc == ELDLM_OK ? 0 : -EIO;
911 * Implementation of dt_object_operations::do_object_unlock
913 * Cancel a lock of a remote object.
915 * \param[in] env execution environment
916 * \param[in] dt object to be unlocked
917 * \param[in] einfo lock enqueue information
918 * \param[in] policy lock policy
920 * \retval Only return 0 for now.
922 static int osp_md_object_unlock(const struct lu_env *env,
923 struct dt_object *dt,
924 struct ldlm_enqueue_info *einfo,
925 ldlm_policy_data_t *policy)
927 struct lustre_handle *lockh = einfo->ei_cbdata;
930 ldlm_lock_decref(lockh, einfo->ei_mode);
936 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
938 * Create the dt_update_request to track the update for this OSP
939 * in the transaction.
941 * \param[in] env pointer to the thread context
942 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
943 * \param[in] th pointer to the transaction handler
945 * \retval 0 for success
946 * \retval negative error number on failure
948 int osp_md_declare_object_destroy(const struct lu_env *env,
949 struct dt_object *dt, struct thandle *th)
951 return osp_trans_update_request_create(th);
955 * Interpreter call for object destroy
957 * Object destroy interpreter, which will be called after destroying
958 * the remote object to set flags and status.
960 * \param[in] env execution environment
961 * \param[in] reply update reply
962 * \param[in] req ptlrpc update request for destroying object
963 * \param[in] obj object to be destroyed
964 * \param[in] data data used in this function.
965 * \param[in] index index(position) of destroy update in the whole
967 * \param[in] rc update result on the remote MDT.
969 * \retval only return 0 for now
971 static int osp_md_object_destroy_interpreter(const struct lu_env *env,
972 struct object_update_reply *reply,
973 struct ptlrpc_request *req,
974 struct osp_object *obj,
975 void *data, int index, int rc)
977 /* not needed in cache any more */
978 set_bit(LU_OBJECT_HEARD_BANSHEE,
979 &obj->opo_obj.do_lu.lo_header->loh_flags);
984 * Implement OSP layer dt_object_operations::do_destroy() interface.
986 * Pack the destroy update into the RPC buffer, which will be sent
987 * to the remote MDT during transaction stop.
989 * It also marks the object as non-cached.
991 * \param[in] env pointer to the thread context
992 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
993 * \param[in] th pointer to the transaction handler
995 * \retval 0 for success
996 * \retval negative error number on failure
998 int osp_md_object_destroy(const struct lu_env *env, struct dt_object *dt,
1001 struct osp_object *o = dt2osp_obj(dt);
1002 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1003 struct dt_update_request *update;
1007 o->opo_non_exist = 1;
1009 LASSERT(osp->opd_connect_mdt);
1010 update = thandle_to_dt_update_request(th);
1011 LASSERT(update != NULL);
1013 rc = osp_update_rpc_pack(env, object_destroy, update, OUT_DESTROY,
1014 lu_object_fid(&dt->do_lu));
1018 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1019 osp_md_object_destroy_interpreter);
1023 struct dt_object_operations osp_md_obj_ops = {
1024 .do_read_lock = osp_md_object_read_lock,
1025 .do_write_lock = osp_md_object_write_lock,
1026 .do_read_unlock = osp_md_object_read_unlock,
1027 .do_write_unlock = osp_md_object_write_unlock,
1028 .do_write_locked = osp_md_object_write_locked,
1029 .do_declare_create = osp_md_declare_object_create,
1030 .do_create = osp_md_object_create,
1031 .do_declare_ref_add = osp_md_declare_ref_add,
1032 .do_ref_add = osp_md_ref_add,
1033 .do_declare_ref_del = osp_md_declare_ref_del,
1034 .do_ref_del = osp_md_ref_del,
1035 .do_declare_destroy = osp_md_declare_object_destroy,
1036 .do_destroy = osp_md_object_destroy,
1037 .do_ah_init = osp_md_ah_init,
1038 .do_attr_get = osp_attr_get,
1039 .do_declare_attr_set = osp_md_declare_attr_set,
1040 .do_attr_set = osp_md_attr_set,
1041 .do_xattr_get = osp_xattr_get,
1042 .do_declare_xattr_set = osp_declare_xattr_set,
1043 .do_xattr_set = osp_xattr_set,
1044 .do_declare_xattr_del = osp_declare_xattr_del,
1045 .do_xattr_del = osp_xattr_del,
1046 .do_index_try = osp_md_index_try,
1047 .do_object_lock = osp_md_object_lock,
1048 .do_object_unlock = osp_md_object_unlock,
1052 * Implementation of dt_body_operations::dbo_declare_write
1054 * Create the dt_update_request to track the update for this OSP
1055 * in the transaction.
1057 * \param[in] env execution environment
1058 * \param[in] dt object to be written
1059 * \param[in] buf buffer to write which includes an embedded size field
1060 * \param[in] pos offet in the object to start writing at
1061 * \param[in] th transaction handle
1063 * \retval 0 if preparation succeeds.
1064 * \retval negative errno if preparation fails.
1066 static ssize_t osp_md_declare_write(const struct lu_env *env,
1067 struct dt_object *dt,
1068 const struct lu_buf *buf,
1069 loff_t pos, struct thandle *th)
1071 return osp_trans_update_request_create(th);
1075 * Implementation of dt_body_operations::dbo_write
1077 * Pack the write object update into the RPC buffer, which will be sent
1078 * to the remote MDT during transaction stop.
1080 * \param[in] env execution environment
1081 * \param[in] dt object to be written
1082 * \param[in] buf buffer to write which includes an embedded size field
1083 * \param[in] pos offet in the object to start writing at
1084 * \param[in] th transaction handle
1085 * \param[in] ignore_quota quota enforcement for this write
1087 * \retval the buffer size in bytes if packing succeeds.
1088 * \retval negative errno if packing fails.
1090 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1091 const struct lu_buf *buf, loff_t *pos,
1092 struct thandle *th, int ignore_quota)
1094 struct dt_update_request *update;
1097 update = thandle_to_dt_update_request(th);
1098 LASSERT(update != NULL);
1100 rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
1101 lu_object_fid(&dt->do_lu), buf, *pos);
1105 /* XXX: how about the write error happened later? */
1106 *pos += buf->lb_len;
1110 /* These body operation will be used to write symlinks during migration etc */
1111 struct dt_body_operations osp_md_body_ops = {
1112 .dbo_declare_write = osp_md_declare_write,
1113 .dbo_write = osp_md_write,