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;
90 /* Invalid the opo cache for the object after the object
91 * is being created, so attr_get will try to get attr
92 * from the remote object. XXX this can be improved when
93 * we have object lock/cache invalidate mechanism in OSP
95 if (obj->opo_ooa != NULL) {
96 spin_lock(&obj->opo_lock);
97 obj->opo_ooa->ooa_attr.la_valid = 0;
98 spin_unlock(&obj->opo_lock);
105 * Implementation of dt_object_operations::do_declare_create
107 * Create the osp_update_request to track the update for this OSP
108 * in the transaction.
110 * \param[in] env execution environment
111 * \param[in] dt remote object to be created
112 * \param[in] attr attribute of the created object
113 * \param[in] hint creation hint
114 * \param[in] dof creation format information
115 * \param[in] th the transaction handle
117 * \retval 0 if preparation succeeds.
118 * \retval negative errno if preparation fails.
120 int osp_md_declare_object_create(const struct lu_env *env,
121 struct dt_object *dt,
122 struct lu_attr *attr,
123 struct dt_allocation_hint *hint,
124 struct dt_object_format *dof,
127 struct osp_object *obj = dt2osp_obj(dt);
130 if (obj->opo_ooa == NULL) {
131 rc = osp_oac_init(obj);
136 return osp_trans_update_request_create(th);
139 struct object_update *
140 update_buffer_get_update(struct object_update_request *request,
146 if (index > request->ourq_count)
149 ptr = &request->ourq_updates[0];
150 for (i = 0; i < index; i++)
151 ptr += object_update_size(ptr);
156 int osp_extend_update_buffer(const struct lu_env *env,
157 struct osp_update_request *our)
159 struct object_update_request *obj_update_req;
160 size_t new_size = our->our_req_size + OUT_UPDATE_BUFFER_SIZE_ADD;
162 /* enlarge object update request size */
163 if (new_size > OUT_UPDATE_BUFFER_SIZE_MAX)
166 OBD_ALLOC_LARGE(obj_update_req, new_size);
167 if (obj_update_req == NULL)
170 memcpy(obj_update_req, our->our_req, our->our_req_size);
172 OBD_FREE_LARGE(our->our_req, our->our_req_size);
174 our->our_req = obj_update_req;
175 our->our_req_size = new_size;
181 * Implementation of dt_object_operations::do_create
183 * It adds an OUT_CREATE sub-request into the OUT RPC that will be flushed
184 * when the transaction stop, and sets necessary flags for created object.
186 * \param[in] env execution environment
187 * \param[in] dt object to be created
188 * \param[in] attr attribute of the created object
189 * \param[in] hint creation hint
190 * \param[in] dof creation format information
191 * \param[in] th the transaction handle
193 * \retval 0 if packing creation succeeds.
194 * \retval negative errno if packing creation fails.
196 int osp_md_object_create(const struct lu_env *env, struct dt_object *dt,
197 struct lu_attr *attr, struct dt_allocation_hint *hint,
198 struct dt_object_format *dof, struct thandle *th)
200 struct osp_update_request *update;
201 struct osp_object *obj = dt2osp_obj(dt);
204 update = thandle_to_osp_update_request(th);
205 LASSERT(update != NULL);
207 LASSERT(attr->la_valid & LA_TYPE);
208 rc = osp_update_rpc_pack(env, create, update, OUT_CREATE,
209 lu_object_fid(&dt->do_lu), attr, hint, dof);
213 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
214 osp_object_create_interpreter);
219 dt->do_lu.lo_header->loh_attr |= LOHA_EXISTS | (attr->la_mode & S_IFMT);
220 dt2osp_obj(dt)->opo_non_exist = 0;
222 LASSERT(obj->opo_ooa != NULL);
223 obj->opo_ooa->ooa_attr = *attr;
229 * Implementation of dt_object_operations::do_declare_ref_del
231 * Create the osp_update_request to track the update for this OSP
232 * in the transaction.
234 * \param[in] env execution environment
235 * \param[in] dt object to decrease the reference count.
236 * \param[in] th the transaction handle of refcount decrease.
238 * \retval 0 if preparation succeeds.
239 * \retval negative errno if preparation fails.
241 static int osp_md_declare_ref_del(const struct lu_env *env,
242 struct dt_object *dt, struct thandle *th)
244 return osp_trans_update_request_create(th);
248 * Implementation of dt_object_operations::do_ref_del
250 * Add an OUT_REF_DEL sub-request into the OUT RPC that will be
251 * flushed when the transaction stop.
253 * \param[in] env execution environment
254 * \param[in] dt object to decrease the reference count
255 * \param[in] th the transaction handle
257 * \retval 0 if packing ref_del succeeds.
258 * \retval negative errno if packing fails.
260 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
263 struct osp_update_request *update;
266 update = thandle_to_osp_update_request(th);
267 LASSERT(update != NULL);
269 rc = osp_update_rpc_pack(env, ref_del, update, OUT_REF_DEL,
270 lu_object_fid(&dt->do_lu));
275 * Implementation of dt_object_operations::do_declare_ref_del
277 * Create the osp_update_request to track the update for this OSP
278 * in the transaction.
280 * \param[in] env execution environment
281 * \param[in] dt object on which to increase the reference count.
282 * \param[in] th the transaction handle.
284 * \retval 0 if preparation succeeds.
285 * \retval negative errno if preparation fails.
287 static int osp_md_declare_ref_add(const struct lu_env *env,
288 struct dt_object *dt, struct thandle *th)
290 return osp_trans_update_request_create(th);
294 * Implementation of dt_object_operations::do_ref_add
296 * Add an OUT_REF_ADD sub-request into the OUT RPC that will be flushed
297 * when the transaction stop.
299 * \param[in] env execution environment
300 * \param[in] dt object on which to increase the reference count
301 * \param[in] th the transaction handle
303 * \retval 0 if packing ref_add succeeds.
304 * \retval negative errno if packing fails.
306 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
309 struct osp_update_request *update;
312 update = thandle_to_osp_update_request(th);
313 LASSERT(update != NULL);
315 rc = osp_update_rpc_pack(env, ref_add, update, OUT_REF_ADD,
316 lu_object_fid(&dt->do_lu));
321 * Implementation of dt_object_operations::do_ah_init
323 * Initialize the allocation hint for object creation, which is usually called
324 * before the creation, and these hints (parent and child mode) will be sent to
325 * the remote Object Update Target (OUT) and used in the object create process,
326 * same as OSD object creation.
328 * \param[in] env execution environment
329 * \param[in] ah the hint to be initialized
330 * \param[in] parent the parent of the object
331 * \param[in] child the object to be created
332 * \param[in] child_mode the mode of the created object
334 static void osp_md_ah_init(const struct lu_env *env,
335 struct dt_allocation_hint *ah,
336 struct dt_object *parent,
337 struct dt_object *child,
342 ah->dah_parent = parent;
343 ah->dah_mode = child_mode;
347 * Implementation of dt_object_operations::do_declare_attr_get
349 * Create the osp_update_request to track the update for this OSP
350 * in the transaction.
352 * \param[in] env execution environment
353 * \param[in] dt object on which to set attributes
354 * \param[in] attr attributes to be set
355 * \param[in] th the transaction handle
357 * \retval 0 if preparation succeeds.
358 * \retval negative errno if preparation fails.
360 int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
361 const struct lu_attr *attr, struct thandle *th)
363 return osp_trans_update_request_create(th);
367 * Implementation of dt_object_operations::do_attr_set
369 * Set attributes to the specified remote object.
371 * Add the OUT_ATTR_SET sub-request into the OUT RPC that will be flushed
372 * when the transaction stop.
374 * \param[in] env execution environment
375 * \param[in] dt object to set attributes
376 * \param[in] attr attributes to be set
377 * \param[in] th the transaction handle
379 * \retval 0 if packing attr_set succeeds.
380 * \retval negative errno if packing fails.
382 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
383 const struct lu_attr *attr, struct thandle *th)
385 struct osp_update_request *update;
388 update = thandle_to_osp_update_request(th);
389 LASSERT(update != NULL);
391 rc = osp_update_rpc_pack(env, attr_set, update, OUT_ATTR_SET,
392 lu_object_fid(&dt->do_lu), attr);
397 * Implementation of dt_object_operations::do_read_lock
399 * osp_md_object_{read,write}_lock() will only lock the remote object in the
400 * local cache, which uses the semaphore (opo_sem) inside the osp_object to
401 * lock the object. Note: it will not lock the object in the whole cluster,
402 * which relies on the LDLM lock.
404 * \param[in] env execution environment
405 * \param[in] dt object to be locked
406 * \param[in] role lock role from MDD layer, see mdd_object_role().
408 static void osp_md_object_read_lock(const struct lu_env *env,
409 struct dt_object *dt, unsigned role)
411 struct osp_object *obj = dt2osp_obj(dt);
413 LASSERT(obj->opo_owner != env);
414 down_read_nested(&obj->opo_sem, role);
416 LASSERT(obj->opo_owner == NULL);
420 * Implementation of dt_object_operations::do_write_lock
422 * Lock the remote object in write mode.
424 * \param[in] env execution environment
425 * \param[in] dt object to be locked
426 * \param[in] role lock role from MDD layer, see mdd_object_role().
428 static void osp_md_object_write_lock(const struct lu_env *env,
429 struct dt_object *dt, unsigned role)
431 struct osp_object *obj = dt2osp_obj(dt);
433 down_write_nested(&obj->opo_sem, role);
435 LASSERT(obj->opo_owner == NULL);
436 obj->opo_owner = env;
440 * Implementation of dt_object_operations::do_read_unlock
442 * Unlock the read lock of remote object.
444 * \param[in] env execution environment
445 * \param[in] dt object to be unlocked
447 static void osp_md_object_read_unlock(const struct lu_env *env,
448 struct dt_object *dt)
450 struct osp_object *obj = dt2osp_obj(dt);
452 up_read(&obj->opo_sem);
456 * Implementation of dt_object_operations::do_write_unlock
458 * Unlock the write lock of remote object.
460 * \param[in] env execution environment
461 * \param[in] dt object to be unlocked
463 static void osp_md_object_write_unlock(const struct lu_env *env,
464 struct dt_object *dt)
466 struct osp_object *obj = dt2osp_obj(dt);
468 LASSERT(obj->opo_owner == env);
469 obj->opo_owner = NULL;
470 up_write(&obj->opo_sem);
474 * Implementation of dt_object_operations::do_write_locked
476 * Test if the object is locked in write mode.
478 * \param[in] env execution environment
479 * \param[in] dt object to be tested
481 static int osp_md_object_write_locked(const struct lu_env *env,
482 struct dt_object *dt)
484 struct osp_object *obj = dt2osp_obj(dt);
486 return obj->opo_owner == env;
490 * Implementation of dt_index_operations::dio_lookup
492 * Look up record by key under a remote index object. It packs lookup update
493 * into RPC, sends to the remote OUT and waits for the lookup result.
495 * \param[in] env execution environment
496 * \param[in] dt index object to lookup
497 * \param[out] rec record in which to return lookup result
498 * \param[in] key key of index which will be looked up
500 * \retval 1 if the lookup succeeds.
501 * \retval negative errno if the lookup fails.
503 static int osp_md_index_lookup(const struct lu_env *env, struct dt_object *dt,
504 struct dt_rec *rec, const struct dt_key *key)
506 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
507 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
508 struct dt_device *dt_dev = &osp->opd_dt_dev;
509 struct osp_update_request *update;
510 struct object_update_reply *reply;
511 struct ptlrpc_request *req = NULL;
516 /* Because it needs send the update buffer right away,
517 * just create an update buffer, instead of attaching the
518 * update_remote list of the thandle.
520 update = osp_update_request_create(dt_dev);
522 RETURN(PTR_ERR(update));
524 rc = osp_update_rpc_pack(env, index_lookup, update, OUT_INDEX_LOOKUP,
525 lu_object_fid(&dt->do_lu), rec, key);
527 CERROR("%s: Insert update error: rc = %d\n",
528 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
532 rc = osp_remote_sync(env, osp, update, &req);
536 reply = req_capsule_server_sized_get(&req->rq_pill,
537 &RMF_OUT_UPDATE_REPLY,
538 OUT_UPDATE_REPLY_SIZE);
539 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
540 CERROR("%s: Wrong version %x expected %x: rc = %d\n",
541 dt_dev->dd_lu_dev.ld_obd->obd_name,
542 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
543 GOTO(out, rc = -EPROTO);
546 rc = object_update_result_data_get(reply, lbuf, 0);
550 if (lbuf->lb_len != sizeof(*fid)) {
551 CERROR("%s: lookup "DFID" %s wrong size %d\n",
552 dt_dev->dd_lu_dev.ld_obd->obd_name,
553 PFID(lu_object_fid(&dt->do_lu)), (char *)key,
555 GOTO(out, rc = -EINVAL);
559 if (ptlrpc_rep_need_swab(req))
560 lustre_swab_lu_fid(fid);
561 if (!fid_is_sane(fid)) {
562 CERROR("%s: lookup "DFID" %s invalid fid "DFID"\n",
563 dt_dev->dd_lu_dev.ld_obd->obd_name,
564 PFID(lu_object_fid(&dt->do_lu)), (char *)key, PFID(fid));
565 GOTO(out, rc = -EINVAL);
568 memcpy(rec, fid, sizeof(*fid));
574 ptlrpc_req_finished(req);
576 osp_update_request_destroy(update);
582 * Implementation of dt_index_operations::dio_declare_insert
584 * Create the osp_update_request to track the update for this OSP
585 * in the transaction.
587 * \param[in] env execution environment
588 * \param[in] dt object for which to insert index
589 * \param[in] rec record of the index which will be inserted
590 * \param[in] key key of the index which will be inserted
591 * \param[in] th the transaction handle
593 * \retval 0 if preparation succeeds.
594 * \retval negative errno if preparation fails.
596 static int osp_md_declare_index_insert(const struct lu_env *env,
597 struct dt_object *dt,
598 const struct dt_rec *rec,
599 const struct dt_key *key,
602 return osp_trans_update_request_create(th);
606 * Implementation of dt_index_operations::dio_insert
608 * Add an OUT_INDEX_INSERT sub-request into the OUT RPC that will
609 * be flushed when the transaction stop.
611 * \param[in] env execution environment
612 * \param[in] dt object for which to insert index
613 * \param[in] rec record of the index to be inserted
614 * \param[in] key key of the index to be inserted
615 * \param[in] th the transaction handle
616 * \param[in] ignore_quota quota enforcement for insert
618 * \retval 0 if packing index insert succeeds.
619 * \retval negative errno if packing fails.
621 static int osp_md_index_insert(const struct lu_env *env,
622 struct dt_object *dt,
623 const struct dt_rec *rec,
624 const struct dt_key *key,
628 struct osp_update_request *update;
631 update = thandle_to_osp_update_request(th);
632 LASSERT(update != NULL);
634 rc = osp_update_rpc_pack(env, index_insert, update, OUT_INDEX_INSERT,
635 lu_object_fid(&dt->do_lu), rec, key);
640 * Implementation of dt_index_operations::dio_declare_delete
642 * Create the osp_update_request to track the update for this OSP
643 * in the transaction.
645 * \param[in] env execution environment
646 * \param[in] dt object for which to delete index
647 * \param[in] key key of the index
648 * \param[in] th the transaction handle
650 * \retval 0 if preparation succeeds.
651 * \retval negative errno if preparation fails.
653 static int osp_md_declare_index_delete(const struct lu_env *env,
654 struct dt_object *dt,
655 const struct dt_key *key,
658 return osp_trans_update_request_create(th);
662 * Implementation of dt_index_operations::dio_delete
664 * Add an OUT_INDEX_DELETE sub-request into the OUT RPC that will
665 * be flushed when the transaction stop.
667 * \param[in] env execution environment
668 * \param[in] dt object for which to delete index
669 * \param[in] key key of the index which will be deleted
670 * \param[in] th the transaction handle
672 * \retval 0 if packing index delete succeeds.
673 * \retval negative errno if packing fails.
675 static int osp_md_index_delete(const struct lu_env *env,
676 struct dt_object *dt,
677 const struct dt_key *key,
680 struct osp_update_request *update;
683 update = thandle_to_osp_update_request(th);
684 LASSERT(update != NULL);
686 rc = osp_update_rpc_pack(env, index_delete, update, OUT_INDEX_DELETE,
687 lu_object_fid(&dt->do_lu), key);
693 * Implementation of dt_index_operations::dio_it.next
695 * Advance the pointer of the iterator to the next entry. It shares a similar
696 * internal implementation with osp_orphan_it_next(), which is being used for
697 * remote orphan index object. This method will be used for remote directory.
699 * \param[in] env execution environment
700 * \param[in] di iterator of this iteration
702 * \retval 0 if the pointer is advanced successfully.
703 * \retval 1 if it reaches to the end of the index object.
704 * \retval negative errno if the pointer cannot be advanced.
706 static int osp_md_index_it_next(const struct lu_env *env, struct dt_it *di)
708 struct osp_it *it = (struct osp_it *)di;
709 struct lu_idxpage *idxpage;
710 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
715 idxpage = it->ooi_cur_idxpage;
716 if (idxpage != NULL) {
717 if (idxpage->lip_nr == 0)
723 (struct lu_dirent *)idxpage->lip_entries;
725 } else if (le16_to_cpu(ent->lde_reclen) != 0 &&
726 it->ooi_pos_ent < idxpage->lip_nr) {
727 ent = (struct lu_dirent *)(((char *)ent) +
728 le16_to_cpu(ent->lde_reclen));
736 rc = osp_it_next_page(env, di);
744 * Implementation of dt_index_operations::dio_it.key
746 * Get the key at current iterator poisiton. These iteration methods
747 * (dio_it) will only be used for iterating the remote directory, so
748 * the key is the name of the directory entry.
750 * \param[in] env execution environment
751 * \param[in] di iterator of this iteration
753 * \retval name of the current entry
755 static struct dt_key *osp_it_key(const struct lu_env *env,
756 const struct dt_it *di)
758 struct osp_it *it = (struct osp_it *)di;
759 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
761 return (struct dt_key *)ent->lde_name;
765 * Implementation of dt_index_operations::dio_it.key_size
767 * Get the key size at current iterator poisiton. These iteration methods
768 * (dio_it) will only be used for iterating the remote directory, so the key
769 * size is the name size of the directory entry.
771 * \param[in] env execution environment
772 * \param[in] di iterator of this iteration
774 * \retval name size of the current entry
777 static int osp_it_key_size(const struct lu_env *env, const struct dt_it *di)
779 struct osp_it *it = (struct osp_it *)di;
780 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
782 return (int)le16_to_cpu(ent->lde_namelen);
786 * Implementation of dt_index_operations::dio_it.rec
788 * Get the record at current iterator position. These iteration methods
789 * (dio_it) will only be used for iterating the remote directory, so it
790 * uses lu_dirent_calc_size() to calculate the record size.
792 * \param[in] env execution environment
793 * \param[in] di iterator of this iteration
794 * \param[out] rec the record to be returned
795 * \param[in] attr attributes of the index object, so it knows
796 * how to pack the entry.
798 * \retval only return 0 for now
800 static int osp_md_index_it_rec(const struct lu_env *env, const struct dt_it *di,
801 struct dt_rec *rec, __u32 attr)
803 struct osp_it *it = (struct osp_it *)di;
804 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
807 reclen = lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen), attr);
808 memcpy(rec, ent, reclen);
813 * Implementation of dt_index_operations::dio_it.load
815 * Locate the iteration cursor to the specified position (cookie).
817 * \param[in] env pointer to the thread context
818 * \param[in] di pointer to the iteration structure
819 * \param[in] hash the specified position
821 * \retval positive number for locating to the exactly position
823 * \retval 0 for arriving at the end of the iteration
824 * \retval negative error number on failure
826 static int osp_it_load(const struct lu_env *env, const struct dt_it *di,
829 struct osp_it *it = (struct osp_it *)di;
833 rc = osp_md_index_it_next(env, (struct dt_it *)di);
843 const struct dt_index_operations osp_md_index_ops = {
844 .dio_lookup = osp_md_index_lookup,
845 .dio_declare_insert = osp_md_declare_index_insert,
846 .dio_insert = osp_md_index_insert,
847 .dio_declare_delete = osp_md_declare_index_delete,
848 .dio_delete = osp_md_index_delete,
854 .next = osp_md_index_it_next,
856 .key_size = osp_it_key_size,
857 .rec = osp_md_index_it_rec,
858 .store = osp_it_store,
860 .key_rec = osp_it_key_rec,
865 * Implementation of dt_object_operations::do_index_try
867 * Try to initialize the index API pointer for the given object. This
868 * is the entry point of the index API, i.e. we must call this method
869 * to initialize the index object before calling other index methods.
871 * \param[in] env execution environment
872 * \param[in] dt index object to be initialized
873 * \param[in] feat the index feature of the object
875 * \retval 0 if the initialization succeeds.
876 * \retval negative errno if the initialization fails.
878 static int osp_md_index_try(const struct lu_env *env,
879 struct dt_object *dt,
880 const struct dt_index_features *feat)
882 dt->do_index_ops = &osp_md_index_ops;
887 * Implementation of dt_object_operations::do_object_lock
889 * Enqueue a lock (by ldlm_cli_enqueue()) of remote object on the remote MDT,
890 * which will lock the object in the global namespace.
892 * \param[in] env execution environment
893 * \param[in] dt object to be locked
894 * \param[out] lh lock handle
895 * \param[in] einfo enqueue information
896 * \param[in] policy lock policy
898 * \retval ELDLM_OK if locking the object succeeds.
899 * \retval negative errno if locking fails.
901 static int osp_md_object_lock(const struct lu_env *env,
902 struct dt_object *dt,
903 struct lustre_handle *lh,
904 struct ldlm_enqueue_info *einfo,
905 ldlm_policy_data_t *policy)
907 struct ldlm_res_id *res_id;
908 struct dt_device *dt_dev = lu2dt_dev(dt->do_lu.lo_dev);
909 struct osp_device *osp = dt2osp_dev(dt_dev);
910 struct ptlrpc_request *req;
915 res_id = einfo->ei_res_id;
916 LASSERT(res_id != NULL);
918 mode = ldlm_lock_match(osp->opd_obd->obd_namespace,
919 LDLM_FL_BLOCK_GRANTED, res_id,
920 einfo->ei_type, policy,
921 einfo->ei_mode, lh, 0);
925 req = ldlm_enqueue_pack(osp->opd_exp, 0);
927 RETURN(PTR_ERR(req));
929 rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
930 (const ldlm_policy_data_t *)policy,
931 &flags, NULL, 0, LVB_T_NONE, lh, 0);
933 ptlrpc_req_finished(req);
935 return rc == ELDLM_OK ? 0 : -EIO;
939 * Implementation of dt_object_operations::do_object_unlock
941 * Cancel a lock of a remote object.
943 * \param[in] env execution environment
944 * \param[in] dt object to be unlocked
945 * \param[in] einfo lock enqueue information
946 * \param[in] policy lock policy
948 * \retval Only return 0 for now.
950 static int osp_md_object_unlock(const struct lu_env *env,
951 struct dt_object *dt,
952 struct ldlm_enqueue_info *einfo,
953 ldlm_policy_data_t *policy)
955 struct lustre_handle *lockh = einfo->ei_cbdata;
958 ldlm_lock_decref(lockh, einfo->ei_mode);
964 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
966 * Create the dt_update_request to track the update for this OSP
967 * in the transaction.
969 * \param[in] env pointer to the thread context
970 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
971 * \param[in] th pointer to the transaction handler
973 * \retval 0 for success
974 * \retval negative error number on failure
976 int osp_md_declare_object_destroy(const struct lu_env *env,
977 struct dt_object *dt, struct thandle *th)
979 return osp_trans_update_request_create(th);
983 * Interpreter call for object destroy
985 * Object destroy interpreter, which will be called after destroying
986 * the remote object to set flags and status.
988 * \param[in] env execution environment
989 * \param[in] reply update reply
990 * \param[in] req ptlrpc update request for destroying object
991 * \param[in] obj object to be destroyed
992 * \param[in] data data used in this function.
993 * \param[in] index index(position) of destroy update in the whole
995 * \param[in] rc update result on the remote MDT.
997 * \retval only return 0 for now
999 static int osp_md_object_destroy_interpreter(const struct lu_env *env,
1000 struct object_update_reply *reply,
1001 struct ptlrpc_request *req,
1002 struct osp_object *obj,
1003 void *data, int index, int rc)
1005 /* not needed in cache any more */
1006 set_bit(LU_OBJECT_HEARD_BANSHEE,
1007 &obj->opo_obj.do_lu.lo_header->loh_flags);
1012 * Implement OSP layer dt_object_operations::do_destroy() interface.
1014 * Pack the destroy update into the RPC buffer, which will be sent
1015 * to the remote MDT during transaction stop.
1017 * It also marks the object as non-cached.
1019 * \param[in] env pointer to the thread context
1020 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
1021 * \param[in] th pointer to the transaction handler
1023 * \retval 0 for success
1024 * \retval negative error number on failure
1026 int osp_md_object_destroy(const struct lu_env *env, struct dt_object *dt,
1029 struct osp_object *o = dt2osp_obj(dt);
1030 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1031 struct osp_update_request *update;
1035 o->opo_non_exist = 1;
1037 LASSERT(osp->opd_connect_mdt);
1038 update = thandle_to_osp_update_request(th);
1039 LASSERT(update != NULL);
1041 rc = osp_update_rpc_pack(env, object_destroy, update, OUT_DESTROY,
1042 lu_object_fid(&dt->do_lu));
1046 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1047 osp_md_object_destroy_interpreter);
1051 struct dt_object_operations osp_md_obj_ops = {
1052 .do_read_lock = osp_md_object_read_lock,
1053 .do_write_lock = osp_md_object_write_lock,
1054 .do_read_unlock = osp_md_object_read_unlock,
1055 .do_write_unlock = osp_md_object_write_unlock,
1056 .do_write_locked = osp_md_object_write_locked,
1057 .do_declare_create = osp_md_declare_object_create,
1058 .do_create = osp_md_object_create,
1059 .do_declare_ref_add = osp_md_declare_ref_add,
1060 .do_ref_add = osp_md_ref_add,
1061 .do_declare_ref_del = osp_md_declare_ref_del,
1062 .do_ref_del = osp_md_ref_del,
1063 .do_declare_destroy = osp_md_declare_object_destroy,
1064 .do_destroy = osp_md_object_destroy,
1065 .do_ah_init = osp_md_ah_init,
1066 .do_attr_get = osp_attr_get,
1067 .do_declare_attr_set = osp_md_declare_attr_set,
1068 .do_attr_set = osp_md_attr_set,
1069 .do_xattr_get = osp_xattr_get,
1070 .do_declare_xattr_set = osp_declare_xattr_set,
1071 .do_xattr_set = osp_xattr_set,
1072 .do_declare_xattr_del = osp_declare_xattr_del,
1073 .do_xattr_del = osp_xattr_del,
1074 .do_index_try = osp_md_index_try,
1075 .do_object_lock = osp_md_object_lock,
1076 .do_object_unlock = osp_md_object_unlock,
1080 * Implementation of dt_body_operations::dbo_declare_write
1082 * Create the osp_update_request to track the update for this OSP
1083 * in the transaction.
1085 * \param[in] env execution environment
1086 * \param[in] dt object to be written
1087 * \param[in] buf buffer to write which includes an embedded size field
1088 * \param[in] pos offet in the object to start writing at
1089 * \param[in] th transaction handle
1091 * \retval 0 if preparation succeeds.
1092 * \retval negative errno if preparation fails.
1094 static ssize_t osp_md_declare_write(const struct lu_env *env,
1095 struct dt_object *dt,
1096 const struct lu_buf *buf,
1097 loff_t pos, struct thandle *th)
1099 return osp_trans_update_request_create(th);
1103 * Implementation of dt_body_operations::dbo_write
1105 * Pack the write object update into the RPC buffer, which will be sent
1106 * to the remote MDT during transaction stop.
1108 * \param[in] env execution environment
1109 * \param[in] dt object to be written
1110 * \param[in] buf buffer to write which includes an embedded size field
1111 * \param[in] pos offet in the object to start writing at
1112 * \param[in] th transaction handle
1113 * \param[in] ignore_quota quota enforcement for this write
1115 * \retval the buffer size in bytes if packing succeeds.
1116 * \retval negative errno if packing fails.
1118 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1119 const struct lu_buf *buf, loff_t *pos,
1120 struct thandle *th, int ignore_quota)
1122 struct osp_object *obj = dt2osp_obj(dt);
1123 struct osp_update_request *update;
1124 struct osp_thandle *oth = thandle_to_osp_thandle(th);
1128 update = thandle_to_osp_update_request(th);
1129 LASSERT(update != NULL);
1131 rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
1132 lu_object_fid(&dt->do_lu), buf, *pos);
1136 CDEBUG(D_INFO, "write "DFID" offset = "LPU64" length = %zu\n",
1137 PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
1139 /* XXX: how about the write error happened later? */
1140 *pos += buf->lb_len;
1142 if (obj->opo_ooa != NULL &&
1143 obj->opo_ooa->ooa_attr.la_valid & LA_SIZE &&
1144 obj->opo_ooa->ooa_attr.la_size < *pos)
1145 obj->opo_ooa->ooa_attr.la_size = *pos;
1147 rc = osp_check_and_set_rpc_version(oth);
1151 RETURN(buf->lb_len);
1154 static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
1155 struct lu_buf *rbuf, loff_t *pos)
1157 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1158 struct dt_device *dt_dev = &osp->opd_dt_dev;
1159 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
1160 struct osp_update_request *update;
1161 struct object_update_reply *reply;
1162 struct out_read_reply *orr;
1163 struct ptlrpc_request *req = NULL;
1167 /* Because it needs send the update buffer right away,
1168 * just create an update buffer, instead of attaching the
1169 * update_remote list of the thandle. */
1170 update = osp_update_request_create(dt_dev);
1172 RETURN(PTR_ERR(update));
1174 rc = osp_update_rpc_pack(env, read, update, OUT_READ,
1175 lu_object_fid(&dt->do_lu), rbuf->lb_len, *pos);
1177 CERROR("%s: cannot insert update: rc = %d\n",
1178 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
1182 rc = osp_remote_sync(env, osp, update, &req);
1186 reply = req_capsule_server_sized_get(&req->rq_pill,
1187 &RMF_OUT_UPDATE_REPLY,
1188 OUT_UPDATE_REPLY_SIZE);
1189 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1190 CERROR("%s: invalid update reply magic %x expected %x:"
1191 " rc = %d\n", dt_dev->dd_lu_dev.ld_obd->obd_name,
1192 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
1193 GOTO(out, rc = -EPROTO);
1196 rc = object_update_result_data_get(reply, lbuf, 0);
1200 if (lbuf->lb_len < sizeof(*orr))
1201 GOTO(out, rc = -EPROTO);
1204 orr_le_to_cpu(orr, orr);
1206 *pos = orr->orr_offset;
1208 if (orr->orr_size > rbuf->lb_len)
1209 GOTO(out, rc = -EPROTO);
1211 memcpy(rbuf->lb_buf, orr->orr_data, orr->orr_size);
1213 CDEBUG(D_INFO, "%s: read "DFID" pos "LPU64" len %u\n",
1214 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1215 *pos, orr->orr_size);
1216 GOTO(out, rc = (int)orr->orr_size);
1219 ptlrpc_req_finished(req);
1221 osp_update_request_destroy(update);
1226 /* These body operation will be used to write symlinks during migration etc */
1227 struct dt_body_operations osp_md_body_ops = {
1228 .dbo_declare_write = osp_md_declare_write,
1229 .dbo_write = osp_md_write,
1230 .dbo_read = osp_md_read,