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 dt_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 update_buffer *ubuf)
159 struct object_update_request *ureq;
160 size_t new_size = ubuf->ub_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(ureq, new_size);
170 memcpy(ureq, ubuf->ub_req, ubuf->ub_req_size);
172 OBD_FREE_LARGE(ubuf->ub_req, ubuf->ub_req_size);
175 ubuf->ub_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 dt_update_request *update;
201 struct osp_object *obj = dt2osp_obj(dt);
204 update = thandle_to_dt_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 dt_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 dt_update_request *update;
266 update = thandle_to_dt_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 dt_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 dt_update_request *update;
312 update = thandle_to_dt_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 dt_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 dt_update_request *update;
388 update = thandle_to_dt_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 dt_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 = dt_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 dt_update_request_destroy(update);
582 * Implementation of dt_index_operations::dio_declare_insert
584 * Create the dt_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_thandle *oth = thandle_to_osp_thandle(th);
629 struct dt_update_request *update = oth->ot_dur;
632 rc = osp_update_rpc_pack(env, index_insert, update, OUT_INDEX_INSERT,
633 lu_object_fid(&dt->do_lu), rec, key);
638 * Implementation of dt_index_operations::dio_declare_delete
640 * Create the dt_update_request to track the update for this OSP
641 * in the transaction.
643 * \param[in] env execution environment
644 * \param[in] dt object for which to delete index
645 * \param[in] key key of the index
646 * \param[in] th the transaction handle
648 * \retval 0 if preparation succeeds.
649 * \retval negative errno if preparation fails.
651 static int osp_md_declare_index_delete(const struct lu_env *env,
652 struct dt_object *dt,
653 const struct dt_key *key,
656 return osp_trans_update_request_create(th);
660 * Implementation of dt_index_operations::dio_delete
662 * Add an OUT_INDEX_DELETE sub-request into the OUT RPC that will
663 * be flushed when the transaction stop.
665 * \param[in] env execution environment
666 * \param[in] dt object for which to delete index
667 * \param[in] key key of the index which will be deleted
668 * \param[in] th the transaction handle
670 * \retval 0 if packing index delete succeeds.
671 * \retval negative errno if packing fails.
673 static int osp_md_index_delete(const struct lu_env *env,
674 struct dt_object *dt,
675 const struct dt_key *key,
678 struct dt_update_request *update;
681 update = thandle_to_dt_update_request(th);
682 LASSERT(update != NULL);
684 rc = osp_update_rpc_pack(env, index_delete, update, OUT_INDEX_DELETE,
685 lu_object_fid(&dt->do_lu), key);
691 * Implementation of dt_index_operations::dio_it.next
693 * Advance the pointer of the iterator to the next entry. It shares a similar
694 * internal implementation with osp_orphan_it_next(), which is being used for
695 * remote orphan index object. This method will be used for remote directory.
697 * \param[in] env execution environment
698 * \param[in] di iterator of this iteration
700 * \retval 0 if the pointer is advanced successfuly.
701 * \retval 1 if it reaches to the end of the index object.
702 * \retval negative errno if the pointer cannot be advanced.
704 static int osp_md_index_it_next(const struct lu_env *env, struct dt_it *di)
706 struct osp_it *it = (struct osp_it *)di;
707 struct lu_idxpage *idxpage;
708 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
713 idxpage = it->ooi_cur_idxpage;
714 if (idxpage != NULL) {
715 if (idxpage->lip_nr == 0)
721 (struct lu_dirent *)idxpage->lip_entries;
723 } else if (le16_to_cpu(ent->lde_reclen) != 0 &&
724 it->ooi_pos_ent < idxpage->lip_nr) {
725 ent = (struct lu_dirent *)(((char *)ent) +
726 le16_to_cpu(ent->lde_reclen));
734 rc = osp_it_next_page(env, di);
742 * Implementation of dt_index_operations::dio_it.key
744 * Get the key at current iterator poisiton. These iteration methods
745 * (dio_it) will only be used for iterating the remote directory, so
746 * the key is the name of the directory entry.
748 * \param[in] env execution environment
749 * \param[in] di iterator of this iteration
751 * \retval name of the current entry
753 static struct dt_key *osp_it_key(const struct lu_env *env,
754 const struct dt_it *di)
756 struct osp_it *it = (struct osp_it *)di;
757 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
759 return (struct dt_key *)ent->lde_name;
763 * Implementation of dt_index_operations::dio_it.key_size
765 * Get the key size at current iterator poisiton. These iteration methods
766 * (dio_it) will only be used for iterating the remote directory, so the key
767 * size is the name size of the directory entry.
769 * \param[in] env execution environment
770 * \param[in] di iterator of this iteration
772 * \retval name size of the current entry
775 static int osp_it_key_size(const struct lu_env *env, const struct dt_it *di)
777 struct osp_it *it = (struct osp_it *)di;
778 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
780 return (int)le16_to_cpu(ent->lde_namelen);
784 * Implementation of dt_index_operations::dio_it.rec
786 * Get the record at current iterator position. These iteration methods
787 * (dio_it) will only be used for iterating the remote directory, so it
788 * uses lu_dirent_calc_size() to calculate the record size.
790 * \param[in] env execution environment
791 * \param[in] di iterator of this iteration
792 * \param[out] rec the record to be returned
793 * \param[in] attr attributes of the index object, so it knows
794 * how to pack the entry.
796 * \retval only return 0 for now
798 static int osp_md_index_it_rec(const struct lu_env *env, const struct dt_it *di,
799 struct dt_rec *rec, __u32 attr)
801 struct osp_it *it = (struct osp_it *)di;
802 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
805 reclen = lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen), attr);
806 memcpy(rec, ent, reclen);
811 * Implementation of dt_index_operations::dio_it.load
813 * Locate the iteration cursor to the specified position (cookie).
815 * \param[in] env pointer to the thread context
816 * \param[in] di pointer to the iteration structure
817 * \param[in] hash the specified position
819 * \retval positive number for locating to the exactly position
821 * \retval 0 for arriving at the end of the iteration
822 * \retval negative error number on failure
824 static int osp_it_load(const struct lu_env *env, const struct dt_it *di,
827 struct osp_it *it = (struct osp_it *)di;
831 rc = osp_md_index_it_next(env, (struct dt_it *)di);
841 const struct dt_index_operations osp_md_index_ops = {
842 .dio_lookup = osp_md_index_lookup,
843 .dio_declare_insert = osp_md_declare_index_insert,
844 .dio_insert = osp_md_index_insert,
845 .dio_declare_delete = osp_md_declare_index_delete,
846 .dio_delete = osp_md_index_delete,
852 .next = osp_md_index_it_next,
854 .key_size = osp_it_key_size,
855 .rec = osp_md_index_it_rec,
856 .store = osp_it_store,
858 .key_rec = osp_it_key_rec,
863 * Implementation of dt_object_operations::do_index_try
865 * Try to initialize the index API pointer for the given object. This
866 * is the entry point of the index API, i.e. we must call this method
867 * to initialize the index object before calling other index methods.
869 * \param[in] env execution environment
870 * \param[in] dt index object to be initialized
871 * \param[in] feat the index feature of the object
873 * \retval 0 if the initialization succeeds.
874 * \retval negative errno if the initialization fails.
876 static int osp_md_index_try(const struct lu_env *env,
877 struct dt_object *dt,
878 const struct dt_index_features *feat)
880 dt->do_index_ops = &osp_md_index_ops;
885 * Implementation of dt_object_operations::do_object_lock
887 * Enqueue a lock (by ldlm_cli_enqueue()) of remote object on the remote MDT,
888 * which will lock the object in the global namespace.
890 * \param[in] env execution environment
891 * \param[in] dt object to be locked
892 * \param[out] lh lock handle
893 * \param[in] einfo enqueue information
894 * \param[in] policy lock policy
896 * \retval ELDLM_OK if locking the object succeeds.
897 * \retval negative errno if locking fails.
899 static int osp_md_object_lock(const struct lu_env *env,
900 struct dt_object *dt,
901 struct lustre_handle *lh,
902 struct ldlm_enqueue_info *einfo,
903 ldlm_policy_data_t *policy)
905 struct ldlm_res_id *res_id;
906 struct dt_device *dt_dev = lu2dt_dev(dt->do_lu.lo_dev);
907 struct osp_device *osp = dt2osp_dev(dt_dev);
908 struct ptlrpc_request *req;
913 res_id = einfo->ei_res_id;
914 LASSERT(res_id != NULL);
916 mode = ldlm_lock_match(osp->opd_obd->obd_namespace,
917 LDLM_FL_BLOCK_GRANTED, res_id,
918 einfo->ei_type, policy,
919 einfo->ei_mode, lh, 0);
923 req = ldlm_enqueue_pack(osp->opd_exp, 0);
925 RETURN(PTR_ERR(req));
927 rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
928 (const ldlm_policy_data_t *)policy,
929 &flags, NULL, 0, LVB_T_NONE, lh, 0);
931 ptlrpc_req_finished(req);
933 return rc == ELDLM_OK ? 0 : -EIO;
937 * Implementation of dt_object_operations::do_object_unlock
939 * Cancel a lock of a remote object.
941 * \param[in] env execution environment
942 * \param[in] dt object to be unlocked
943 * \param[in] einfo lock enqueue information
944 * \param[in] policy lock policy
946 * \retval Only return 0 for now.
948 static int osp_md_object_unlock(const struct lu_env *env,
949 struct dt_object *dt,
950 struct ldlm_enqueue_info *einfo,
951 ldlm_policy_data_t *policy)
953 struct lustre_handle *lockh = einfo->ei_cbdata;
956 ldlm_lock_decref(lockh, einfo->ei_mode);
962 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
964 * Create the dt_update_request to track the update for this OSP
965 * in the transaction.
967 * \param[in] env pointer to the thread context
968 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
969 * \param[in] th pointer to the transaction handler
971 * \retval 0 for success
972 * \retval negative error number on failure
974 int osp_md_declare_object_destroy(const struct lu_env *env,
975 struct dt_object *dt, struct thandle *th)
977 return osp_trans_update_request_create(th);
981 * Interpreter call for object destroy
983 * Object destroy interpreter, which will be called after destroying
984 * the remote object to set flags and status.
986 * \param[in] env execution environment
987 * \param[in] reply update reply
988 * \param[in] req ptlrpc update request for destroying object
989 * \param[in] obj object to be destroyed
990 * \param[in] data data used in this function.
991 * \param[in] index index(position) of destroy update in the whole
993 * \param[in] rc update result on the remote MDT.
995 * \retval only return 0 for now
997 static int osp_md_object_destroy_interpreter(const struct lu_env *env,
998 struct object_update_reply *reply,
999 struct ptlrpc_request *req,
1000 struct osp_object *obj,
1001 void *data, int index, int rc)
1003 /* not needed in cache any more */
1004 set_bit(LU_OBJECT_HEARD_BANSHEE,
1005 &obj->opo_obj.do_lu.lo_header->loh_flags);
1010 * Implement OSP layer dt_object_operations::do_destroy() interface.
1012 * Pack the destroy update into the RPC buffer, which will be sent
1013 * to the remote MDT during transaction stop.
1015 * It also marks the object as non-cached.
1017 * \param[in] env pointer to the thread context
1018 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
1019 * \param[in] th pointer to the transaction handler
1021 * \retval 0 for success
1022 * \retval negative error number on failure
1024 int osp_md_object_destroy(const struct lu_env *env, struct dt_object *dt,
1027 struct osp_object *o = dt2osp_obj(dt);
1028 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1029 struct dt_update_request *update;
1033 o->opo_non_exist = 1;
1035 LASSERT(osp->opd_connect_mdt);
1036 update = thandle_to_dt_update_request(th);
1037 LASSERT(update != NULL);
1039 rc = osp_update_rpc_pack(env, object_destroy, update, OUT_DESTROY,
1040 lu_object_fid(&dt->do_lu));
1044 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1045 osp_md_object_destroy_interpreter);
1049 struct dt_object_operations osp_md_obj_ops = {
1050 .do_read_lock = osp_md_object_read_lock,
1051 .do_write_lock = osp_md_object_write_lock,
1052 .do_read_unlock = osp_md_object_read_unlock,
1053 .do_write_unlock = osp_md_object_write_unlock,
1054 .do_write_locked = osp_md_object_write_locked,
1055 .do_declare_create = osp_md_declare_object_create,
1056 .do_create = osp_md_object_create,
1057 .do_declare_ref_add = osp_md_declare_ref_add,
1058 .do_ref_add = osp_md_ref_add,
1059 .do_declare_ref_del = osp_md_declare_ref_del,
1060 .do_ref_del = osp_md_ref_del,
1061 .do_declare_destroy = osp_md_declare_object_destroy,
1062 .do_destroy = osp_md_object_destroy,
1063 .do_ah_init = osp_md_ah_init,
1064 .do_attr_get = osp_attr_get,
1065 .do_declare_attr_set = osp_md_declare_attr_set,
1066 .do_attr_set = osp_md_attr_set,
1067 .do_xattr_get = osp_xattr_get,
1068 .do_declare_xattr_set = osp_declare_xattr_set,
1069 .do_xattr_set = osp_xattr_set,
1070 .do_declare_xattr_del = osp_declare_xattr_del,
1071 .do_xattr_del = osp_xattr_del,
1072 .do_index_try = osp_md_index_try,
1073 .do_object_lock = osp_md_object_lock,
1074 .do_object_unlock = osp_md_object_unlock,
1078 * Implementation of dt_body_operations::dbo_declare_write
1080 * Create the dt_update_request to track the update for this OSP
1081 * in the transaction.
1083 * \param[in] env execution environment
1084 * \param[in] dt object to be written
1085 * \param[in] buf buffer to write which includes an embedded size field
1086 * \param[in] pos offet in the object to start writing at
1087 * \param[in] th transaction handle
1089 * \retval 0 if preparation succeeds.
1090 * \retval negative errno if preparation fails.
1092 static ssize_t osp_md_declare_write(const struct lu_env *env,
1093 struct dt_object *dt,
1094 const struct lu_buf *buf,
1095 loff_t pos, struct thandle *th)
1097 return osp_trans_update_request_create(th);
1101 * Implementation of dt_body_operations::dbo_write
1103 * Pack the write object update into the RPC buffer, which will be sent
1104 * to the remote MDT during transaction stop.
1106 * \param[in] env execution environment
1107 * \param[in] dt object to be written
1108 * \param[in] buf buffer to write which includes an embedded size field
1109 * \param[in] pos offet in the object to start writing at
1110 * \param[in] th transaction handle
1111 * \param[in] ignore_quota quota enforcement for this write
1113 * \retval the buffer size in bytes if packing succeeds.
1114 * \retval negative errno if packing fails.
1116 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1117 const struct lu_buf *buf, loff_t *pos,
1118 struct thandle *th, int ignore_quota)
1120 struct osp_object *obj = dt2osp_obj(dt);
1121 struct dt_update_request *update;
1125 update = thandle_to_dt_update_request(th);
1126 LASSERT(update != NULL);
1128 rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
1129 lu_object_fid(&dt->do_lu), buf, *pos);
1133 CDEBUG(D_INFO, "write "DFID" offset = "LPU64" length = %zu\n",
1134 PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
1136 /* XXX: how about the write error happened later? */
1137 *pos += buf->lb_len;
1139 if (obj->opo_ooa != NULL &&
1140 obj->opo_ooa->ooa_attr.la_valid & LA_SIZE &&
1141 obj->opo_ooa->ooa_attr.la_size < *pos)
1142 obj->opo_ooa->ooa_attr.la_size = *pos;
1144 RETURN(buf->lb_len);
1147 static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
1148 struct lu_buf *rbuf, loff_t *pos)
1150 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1151 struct dt_device *dt_dev = &osp->opd_dt_dev;
1152 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
1153 struct dt_update_request *update;
1154 struct object_update_reply *reply;
1155 struct out_read_reply *orr;
1156 struct ptlrpc_request *req = NULL;
1160 /* Because it needs send the update buffer right away,
1161 * just create an update buffer, instead of attaching the
1162 * update_remote list of the thandle. */
1163 update = dt_update_request_create(dt_dev);
1165 RETURN(PTR_ERR(update));
1167 rc = osp_update_rpc_pack(env, read, update, OUT_READ,
1168 lu_object_fid(&dt->do_lu), rbuf->lb_len, *pos);
1170 CERROR("%s: cannot insert update: rc = %d\n",
1171 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
1175 rc = osp_remote_sync(env, osp, update, &req);
1179 reply = req_capsule_server_sized_get(&req->rq_pill,
1180 &RMF_OUT_UPDATE_REPLY,
1181 OUT_UPDATE_REPLY_SIZE);
1182 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1183 CERROR("%s: invalid update reply magic %x expected %x:"
1184 " rc = %d\n", dt_dev->dd_lu_dev.ld_obd->obd_name,
1185 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
1186 GOTO(out, rc = -EPROTO);
1189 rc = object_update_result_data_get(reply, lbuf, 0);
1193 if (lbuf->lb_len < sizeof(*orr))
1194 GOTO(out, rc = -EPROTO);
1197 orr_le_to_cpu(orr, orr);
1199 *pos = orr->orr_offset;
1201 if (orr->orr_size > rbuf->lb_len)
1202 GOTO(out, rc = -EPROTO);
1204 memcpy(rbuf->lb_buf, orr->orr_data, orr->orr_size);
1206 CDEBUG(D_INFO, "%s: read "DFID" pos "LPU64" len %u\n",
1207 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1208 *pos, orr->orr_size);
1209 GOTO(out, rc = (int)orr->orr_size);
1212 ptlrpc_req_finished(req);
1214 dt_update_request_destroy(update);
1219 /* These body operation will be used to write symlinks during migration etc */
1220 struct dt_body_operations osp_md_body_ops = {
1221 .dbo_declare_write = osp_md_declare_write,
1222 .dbo_write = osp_md_write,
1223 .dbo_read = osp_md_read,