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);
157 * Implementation of dt_object_operations::do_create
159 * It adds an OUT_CREATE sub-request into the OUT RPC that will be flushed
160 * when the transaction stop, and sets necessary flags for created object.
162 * \param[in] env execution environment
163 * \param[in] dt object to be created
164 * \param[in] attr attribute of the created object
165 * \param[in] hint creation hint
166 * \param[in] dof creation format information
167 * \param[in] th the transaction handle
169 * \retval 0 if packing creation succeeds.
170 * \retval negative errno if packing creation fails.
172 int osp_md_object_create(const struct lu_env *env, struct dt_object *dt,
173 struct lu_attr *attr, struct dt_allocation_hint *hint,
174 struct dt_object_format *dof, struct thandle *th)
176 struct osp_update_request *update;
177 struct osp_object *obj = dt2osp_obj(dt);
180 update = thandle_to_osp_update_request(th);
181 LASSERT(update != NULL);
183 LASSERT(attr->la_valid & LA_TYPE);
184 rc = osp_update_rpc_pack(env, create, update, OUT_CREATE,
185 lu_object_fid(&dt->do_lu), attr, hint, dof);
189 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
190 osp_object_create_interpreter);
195 dt->do_lu.lo_header->loh_attr |= LOHA_EXISTS | (attr->la_mode & S_IFMT);
196 dt2osp_obj(dt)->opo_non_exist = 0;
198 LASSERT(obj->opo_ooa != NULL);
199 obj->opo_ooa->ooa_attr = *attr;
205 * Implementation of dt_object_operations::do_declare_ref_del
207 * Create the osp_update_request to track the update for this OSP
208 * in the transaction.
210 * \param[in] env execution environment
211 * \param[in] dt object to decrease the reference count.
212 * \param[in] th the transaction handle of refcount decrease.
214 * \retval 0 if preparation succeeds.
215 * \retval negative errno if preparation fails.
217 static int osp_md_declare_ref_del(const struct lu_env *env,
218 struct dt_object *dt, struct thandle *th)
220 return osp_trans_update_request_create(th);
224 * Implementation of dt_object_operations::do_ref_del
226 * Add an OUT_REF_DEL sub-request into the OUT RPC that will be
227 * flushed when the transaction stop.
229 * \param[in] env execution environment
230 * \param[in] dt object to decrease the reference count
231 * \param[in] th the transaction handle
233 * \retval 0 if packing ref_del succeeds.
234 * \retval negative errno if packing fails.
236 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
239 struct osp_update_request *update;
242 update = thandle_to_osp_update_request(th);
243 LASSERT(update != NULL);
245 rc = osp_update_rpc_pack(env, ref_del, update, OUT_REF_DEL,
246 lu_object_fid(&dt->do_lu));
251 * Implementation of dt_object_operations::do_declare_ref_del
253 * Create the osp_update_request to track the update for this OSP
254 * in the transaction.
256 * \param[in] env execution environment
257 * \param[in] dt object on which to increase the reference count.
258 * \param[in] th the transaction handle.
260 * \retval 0 if preparation succeeds.
261 * \retval negative errno if preparation fails.
263 static int osp_md_declare_ref_add(const struct lu_env *env,
264 struct dt_object *dt, struct thandle *th)
266 return osp_trans_update_request_create(th);
270 * Implementation of dt_object_operations::do_ref_add
272 * Add an OUT_REF_ADD sub-request into the OUT RPC that will be flushed
273 * when the transaction stop.
275 * \param[in] env execution environment
276 * \param[in] dt object on which to increase the reference count
277 * \param[in] th the transaction handle
279 * \retval 0 if packing ref_add succeeds.
280 * \retval negative errno if packing fails.
282 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
285 struct osp_update_request *update;
288 update = thandle_to_osp_update_request(th);
289 LASSERT(update != NULL);
291 rc = osp_update_rpc_pack(env, ref_add, update, OUT_REF_ADD,
292 lu_object_fid(&dt->do_lu));
297 * Implementation of dt_object_operations::do_ah_init
299 * Initialize the allocation hint for object creation, which is usually called
300 * before the creation, and these hints (parent and child mode) will be sent to
301 * the remote Object Update Target (OUT) and used in the object create process,
302 * same as OSD object creation.
304 * \param[in] env execution environment
305 * \param[in] ah the hint to be initialized
306 * \param[in] parent the parent of the object
307 * \param[in] child the object to be created
308 * \param[in] child_mode the mode of the created object
310 static void osp_md_ah_init(const struct lu_env *env,
311 struct dt_allocation_hint *ah,
312 struct dt_object *parent,
313 struct dt_object *child,
318 ah->dah_parent = parent;
319 ah->dah_mode = child_mode;
323 * Implementation of dt_object_operations::do_declare_attr_get
325 * Create the osp_update_request to track the update for this OSP
326 * in the transaction.
328 * \param[in] env execution environment
329 * \param[in] dt object on which to set attributes
330 * \param[in] attr attributes to be set
331 * \param[in] th the transaction handle
333 * \retval 0 if preparation succeeds.
334 * \retval negative errno if preparation fails.
336 int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
337 const struct lu_attr *attr, struct thandle *th)
339 return osp_trans_update_request_create(th);
343 * Implementation of dt_object_operations::do_attr_set
345 * Set attributes to the specified remote object.
347 * Add the OUT_ATTR_SET sub-request into the OUT RPC that will be flushed
348 * when the transaction stop.
350 * \param[in] env execution environment
351 * \param[in] dt object to set attributes
352 * \param[in] attr attributes to be set
353 * \param[in] th the transaction handle
355 * \retval 0 if packing attr_set succeeds.
356 * \retval negative errno if packing fails.
358 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
359 const struct lu_attr *attr, struct thandle *th)
361 struct osp_update_request *update;
364 update = thandle_to_osp_update_request(th);
365 LASSERT(update != NULL);
367 rc = osp_update_rpc_pack(env, attr_set, update, OUT_ATTR_SET,
368 lu_object_fid(&dt->do_lu), attr);
373 * Implementation of dt_object_operations::do_read_lock
375 * osp_md_object_{read,write}_lock() will only lock the remote object in the
376 * local cache, which uses the semaphore (opo_sem) inside the osp_object to
377 * lock the object. Note: it will not lock the object in the whole cluster,
378 * which relies on the LDLM lock.
380 * \param[in] env execution environment
381 * \param[in] dt object to be locked
382 * \param[in] role lock role from MDD layer, see mdd_object_role().
384 static void osp_md_object_read_lock(const struct lu_env *env,
385 struct dt_object *dt, unsigned role)
387 struct osp_object *obj = dt2osp_obj(dt);
389 LASSERT(obj->opo_owner != env);
390 down_read_nested(&obj->opo_sem, role);
392 LASSERT(obj->opo_owner == NULL);
396 * Implementation of dt_object_operations::do_write_lock
398 * Lock the remote object in write mode.
400 * \param[in] env execution environment
401 * \param[in] dt object to be locked
402 * \param[in] role lock role from MDD layer, see mdd_object_role().
404 static void osp_md_object_write_lock(const struct lu_env *env,
405 struct dt_object *dt, unsigned role)
407 struct osp_object *obj = dt2osp_obj(dt);
409 down_write_nested(&obj->opo_sem, role);
411 LASSERT(obj->opo_owner == NULL);
412 obj->opo_owner = env;
416 * Implementation of dt_object_operations::do_read_unlock
418 * Unlock the read lock of remote object.
420 * \param[in] env execution environment
421 * \param[in] dt object to be unlocked
423 static void osp_md_object_read_unlock(const struct lu_env *env,
424 struct dt_object *dt)
426 struct osp_object *obj = dt2osp_obj(dt);
428 up_read(&obj->opo_sem);
432 * Implementation of dt_object_operations::do_write_unlock
434 * Unlock the write lock of remote object.
436 * \param[in] env execution environment
437 * \param[in] dt object to be unlocked
439 static void osp_md_object_write_unlock(const struct lu_env *env,
440 struct dt_object *dt)
442 struct osp_object *obj = dt2osp_obj(dt);
444 LASSERT(obj->opo_owner == env);
445 obj->opo_owner = NULL;
446 up_write(&obj->opo_sem);
450 * Implementation of dt_object_operations::do_write_locked
452 * Test if the object is locked in write mode.
454 * \param[in] env execution environment
455 * \param[in] dt object to be tested
457 static int osp_md_object_write_locked(const struct lu_env *env,
458 struct dt_object *dt)
460 struct osp_object *obj = dt2osp_obj(dt);
462 return obj->opo_owner == env;
466 * Implementation of dt_index_operations::dio_lookup
468 * Look up record by key under a remote index object. It packs lookup update
469 * into RPC, sends to the remote OUT and waits for the lookup result.
471 * \param[in] env execution environment
472 * \param[in] dt index object to lookup
473 * \param[out] rec record in which to return lookup result
474 * \param[in] key key of index which will be looked up
476 * \retval 1 if the lookup succeeds.
477 * \retval negative errno if the lookup fails.
479 static int osp_md_index_lookup(const struct lu_env *env, struct dt_object *dt,
480 struct dt_rec *rec, const struct dt_key *key)
482 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
483 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
484 struct dt_device *dt_dev = &osp->opd_dt_dev;
485 struct osp_update_request *update;
486 struct object_update_reply *reply;
487 struct ptlrpc_request *req = NULL;
492 /* Because it needs send the update buffer right away,
493 * just create an update buffer, instead of attaching the
494 * update_remote list of the thandle.
496 update = osp_update_request_create(dt_dev);
498 RETURN(PTR_ERR(update));
500 rc = osp_update_rpc_pack(env, index_lookup, update, OUT_INDEX_LOOKUP,
501 lu_object_fid(&dt->do_lu), rec, key);
503 CERROR("%s: Insert update error: rc = %d\n",
504 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
508 rc = osp_remote_sync(env, osp, update, &req);
512 reply = req_capsule_server_sized_get(&req->rq_pill,
513 &RMF_OUT_UPDATE_REPLY,
514 OUT_UPDATE_REPLY_SIZE);
515 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
516 CERROR("%s: Wrong version %x expected %x: rc = %d\n",
517 dt_dev->dd_lu_dev.ld_obd->obd_name,
518 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
519 GOTO(out, rc = -EPROTO);
522 rc = object_update_result_data_get(reply, lbuf, 0);
526 if (lbuf->lb_len != sizeof(*fid)) {
527 CERROR("%s: lookup "DFID" %s wrong size %d\n",
528 dt_dev->dd_lu_dev.ld_obd->obd_name,
529 PFID(lu_object_fid(&dt->do_lu)), (char *)key,
531 GOTO(out, rc = -EINVAL);
535 if (ptlrpc_rep_need_swab(req))
536 lustre_swab_lu_fid(fid);
537 if (!fid_is_sane(fid)) {
538 CERROR("%s: lookup "DFID" %s invalid fid "DFID"\n",
539 dt_dev->dd_lu_dev.ld_obd->obd_name,
540 PFID(lu_object_fid(&dt->do_lu)), (char *)key, PFID(fid));
541 GOTO(out, rc = -EINVAL);
544 memcpy(rec, fid, sizeof(*fid));
550 ptlrpc_req_finished(req);
552 osp_update_request_destroy(update);
558 * Implementation of dt_index_operations::dio_declare_insert
560 * Create the osp_update_request to track the update for this OSP
561 * in the transaction.
563 * \param[in] env execution environment
564 * \param[in] dt object for which to insert index
565 * \param[in] rec record of the index which will be inserted
566 * \param[in] key key of the index which will be inserted
567 * \param[in] th the transaction handle
569 * \retval 0 if preparation succeeds.
570 * \retval negative errno if preparation fails.
572 static int osp_md_declare_index_insert(const struct lu_env *env,
573 struct dt_object *dt,
574 const struct dt_rec *rec,
575 const struct dt_key *key,
578 return osp_trans_update_request_create(th);
582 * Implementation of dt_index_operations::dio_insert
584 * Add an OUT_INDEX_INSERT sub-request into the OUT RPC that will
585 * be flushed when the transaction stop.
587 * \param[in] env execution environment
588 * \param[in] dt object for which to insert index
589 * \param[in] rec record of the index to be inserted
590 * \param[in] key key of the index to be inserted
591 * \param[in] th the transaction handle
592 * \param[in] ignore_quota quota enforcement for insert
594 * \retval 0 if packing index insert succeeds.
595 * \retval negative errno if packing fails.
597 static int osp_md_index_insert(const struct lu_env *env,
598 struct dt_object *dt,
599 const struct dt_rec *rec,
600 const struct dt_key *key,
604 struct osp_update_request *update;
607 update = thandle_to_osp_update_request(th);
608 LASSERT(update != NULL);
610 rc = osp_update_rpc_pack(env, index_insert, update, OUT_INDEX_INSERT,
611 lu_object_fid(&dt->do_lu), rec, key);
616 * Implementation of dt_index_operations::dio_declare_delete
618 * Create the osp_update_request to track the update for this OSP
619 * in the transaction.
621 * \param[in] env execution environment
622 * \param[in] dt object for which to delete index
623 * \param[in] key key of the index
624 * \param[in] th the transaction handle
626 * \retval 0 if preparation succeeds.
627 * \retval negative errno if preparation fails.
629 static int osp_md_declare_index_delete(const struct lu_env *env,
630 struct dt_object *dt,
631 const struct dt_key *key,
634 return osp_trans_update_request_create(th);
638 * Implementation of dt_index_operations::dio_delete
640 * Add an OUT_INDEX_DELETE sub-request into the OUT RPC that will
641 * be flushed when the transaction stop.
643 * \param[in] env execution environment
644 * \param[in] dt object for which to delete index
645 * \param[in] key key of the index which will be deleted
646 * \param[in] th the transaction handle
648 * \retval 0 if packing index delete succeeds.
649 * \retval negative errno if packing fails.
651 static int osp_md_index_delete(const struct lu_env *env,
652 struct dt_object *dt,
653 const struct dt_key *key,
656 struct osp_update_request *update;
659 update = thandle_to_osp_update_request(th);
660 LASSERT(update != NULL);
662 rc = osp_update_rpc_pack(env, index_delete, update, OUT_INDEX_DELETE,
663 lu_object_fid(&dt->do_lu), key);
669 * Implementation of dt_index_operations::dio_it.next
671 * Advance the pointer of the iterator to the next entry. It shares a similar
672 * internal implementation with osp_orphan_it_next(), which is being used for
673 * remote orphan index object. This method will be used for remote directory.
675 * \param[in] env execution environment
676 * \param[in] di iterator of this iteration
678 * \retval 0 if the pointer is advanced successfully.
679 * \retval 1 if it reaches to the end of the index object.
680 * \retval negative errno if the pointer cannot be advanced.
682 static int osp_md_index_it_next(const struct lu_env *env, struct dt_it *di)
684 struct osp_it *it = (struct osp_it *)di;
685 struct lu_idxpage *idxpage;
686 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
691 idxpage = it->ooi_cur_idxpage;
692 if (idxpage != NULL) {
693 if (idxpage->lip_nr == 0)
699 (struct lu_dirent *)idxpage->lip_entries;
701 } else if (le16_to_cpu(ent->lde_reclen) != 0 &&
702 it->ooi_pos_ent < idxpage->lip_nr) {
703 ent = (struct lu_dirent *)(((char *)ent) +
704 le16_to_cpu(ent->lde_reclen));
712 rc = osp_it_next_page(env, di);
720 * Implementation of dt_index_operations::dio_it.key
722 * Get the key at current iterator poisiton. These iteration methods
723 * (dio_it) will only be used for iterating the remote directory, so
724 * the key is the name of the directory entry.
726 * \param[in] env execution environment
727 * \param[in] di iterator of this iteration
729 * \retval name of the current entry
731 static struct dt_key *osp_it_key(const struct lu_env *env,
732 const struct dt_it *di)
734 struct osp_it *it = (struct osp_it *)di;
735 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
737 return (struct dt_key *)ent->lde_name;
741 * Implementation of dt_index_operations::dio_it.key_size
743 * Get the key size at current iterator poisiton. These iteration methods
744 * (dio_it) will only be used for iterating the remote directory, so the key
745 * size is the name size of the directory entry.
747 * \param[in] env execution environment
748 * \param[in] di iterator of this iteration
750 * \retval name size of the current entry
753 static int osp_it_key_size(const struct lu_env *env, const struct dt_it *di)
755 struct osp_it *it = (struct osp_it *)di;
756 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
758 return (int)le16_to_cpu(ent->lde_namelen);
762 * Implementation of dt_index_operations::dio_it.rec
764 * Get the record at current iterator position. These iteration methods
765 * (dio_it) will only be used for iterating the remote directory, so it
766 * uses lu_dirent_calc_size() to calculate the record size.
768 * \param[in] env execution environment
769 * \param[in] di iterator of this iteration
770 * \param[out] rec the record to be returned
771 * \param[in] attr attributes of the index object, so it knows
772 * how to pack the entry.
774 * \retval only return 0 for now
776 static int osp_md_index_it_rec(const struct lu_env *env, const struct dt_it *di,
777 struct dt_rec *rec, __u32 attr)
779 struct osp_it *it = (struct osp_it *)di;
780 struct lu_dirent *ent = (struct lu_dirent *)it->ooi_ent;
783 reclen = lu_dirent_calc_size(le16_to_cpu(ent->lde_namelen), attr);
784 memcpy(rec, ent, reclen);
789 * Implementation of dt_index_operations::dio_it.load
791 * Locate the iteration cursor to the specified position (cookie).
793 * \param[in] env pointer to the thread context
794 * \param[in] di pointer to the iteration structure
795 * \param[in] hash the specified position
797 * \retval positive number for locating to the exactly position
799 * \retval 0 for arriving at the end of the iteration
800 * \retval negative error number on failure
802 static int osp_it_load(const struct lu_env *env, const struct dt_it *di,
805 struct osp_it *it = (struct osp_it *)di;
809 rc = osp_md_index_it_next(env, (struct dt_it *)di);
819 const struct dt_index_operations osp_md_index_ops = {
820 .dio_lookup = osp_md_index_lookup,
821 .dio_declare_insert = osp_md_declare_index_insert,
822 .dio_insert = osp_md_index_insert,
823 .dio_declare_delete = osp_md_declare_index_delete,
824 .dio_delete = osp_md_index_delete,
830 .next = osp_md_index_it_next,
832 .key_size = osp_it_key_size,
833 .rec = osp_md_index_it_rec,
834 .store = osp_it_store,
836 .key_rec = osp_it_key_rec,
841 * Implementation of dt_object_operations::do_index_try
843 * Try to initialize the index API pointer for the given object. This
844 * is the entry point of the index API, i.e. we must call this method
845 * to initialize the index object before calling other index methods.
847 * \param[in] env execution environment
848 * \param[in] dt index object to be initialized
849 * \param[in] feat the index feature of the object
851 * \retval 0 if the initialization succeeds.
852 * \retval negative errno if the initialization fails.
854 static int osp_md_index_try(const struct lu_env *env,
855 struct dt_object *dt,
856 const struct dt_index_features *feat)
858 dt->do_index_ops = &osp_md_index_ops;
863 * Implementation of dt_object_operations::do_object_lock
865 * Enqueue a lock (by ldlm_cli_enqueue()) of remote object on the remote MDT,
866 * which will lock the object in the global namespace.
868 * \param[in] env execution environment
869 * \param[in] dt object to be locked
870 * \param[out] lh lock handle
871 * \param[in] einfo enqueue information
872 * \param[in] policy lock policy
874 * \retval ELDLM_OK if locking the object succeeds.
875 * \retval negative errno if locking fails.
877 static int osp_md_object_lock(const struct lu_env *env,
878 struct dt_object *dt,
879 struct lustre_handle *lh,
880 struct ldlm_enqueue_info *einfo,
881 ldlm_policy_data_t *policy)
883 struct ldlm_res_id *res_id;
884 struct dt_device *dt_dev = lu2dt_dev(dt->do_lu.lo_dev);
885 struct osp_device *osp = dt2osp_dev(dt_dev);
886 struct ptlrpc_request *req;
891 res_id = einfo->ei_res_id;
892 LASSERT(res_id != NULL);
894 mode = ldlm_lock_match(osp->opd_obd->obd_namespace,
895 LDLM_FL_BLOCK_GRANTED, res_id,
896 einfo->ei_type, policy,
897 einfo->ei_mode, lh, 0);
901 req = ldlm_enqueue_pack(osp->opd_exp, 0);
903 RETURN(PTR_ERR(req));
905 rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
906 (const ldlm_policy_data_t *)policy,
907 &flags, NULL, 0, LVB_T_NONE, lh, 0);
909 ptlrpc_req_finished(req);
911 return rc == ELDLM_OK ? 0 : -EIO;
915 * Implementation of dt_object_operations::do_object_unlock
917 * Cancel a lock of a remote object.
919 * \param[in] env execution environment
920 * \param[in] dt object to be unlocked
921 * \param[in] einfo lock enqueue information
922 * \param[in] policy lock policy
924 * \retval Only return 0 for now.
926 static int osp_md_object_unlock(const struct lu_env *env,
927 struct dt_object *dt,
928 struct ldlm_enqueue_info *einfo,
929 ldlm_policy_data_t *policy)
931 struct lustre_handle *lockh = einfo->ei_cbdata;
934 ldlm_lock_decref(lockh, einfo->ei_mode);
940 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
942 * Create the dt_update_request to track the update for this OSP
943 * in the transaction.
945 * \param[in] env pointer to the thread context
946 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
947 * \param[in] th pointer to the transaction handler
949 * \retval 0 for success
950 * \retval negative error number on failure
952 int osp_md_declare_object_destroy(const struct lu_env *env,
953 struct dt_object *dt, struct thandle *th)
955 return osp_trans_update_request_create(th);
959 * Implement OSP layer dt_object_operations::do_destroy() interface.
961 * Pack the destroy update into the RPC buffer, which will be sent
962 * to the remote MDT during transaction stop.
964 * It also marks the object as non-cached.
966 * \param[in] env pointer to the thread context
967 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
968 * \param[in] th pointer to the transaction handler
970 * \retval 0 for success
971 * \retval negative error number on failure
973 int osp_md_object_destroy(const struct lu_env *env, struct dt_object *dt,
976 struct osp_object *o = dt2osp_obj(dt);
977 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
978 struct osp_update_request *update;
982 o->opo_non_exist = 1;
984 LASSERT(osp->opd_connect_mdt);
985 update = thandle_to_osp_update_request(th);
986 LASSERT(update != NULL);
988 rc = osp_update_rpc_pack(env, object_destroy, update, OUT_DESTROY,
989 lu_object_fid(&dt->do_lu));
993 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
994 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1000 struct dt_object_operations osp_md_obj_ops = {
1001 .do_read_lock = osp_md_object_read_lock,
1002 .do_write_lock = osp_md_object_write_lock,
1003 .do_read_unlock = osp_md_object_read_unlock,
1004 .do_write_unlock = osp_md_object_write_unlock,
1005 .do_write_locked = osp_md_object_write_locked,
1006 .do_declare_create = osp_md_declare_object_create,
1007 .do_create = osp_md_object_create,
1008 .do_declare_ref_add = osp_md_declare_ref_add,
1009 .do_ref_add = osp_md_ref_add,
1010 .do_declare_ref_del = osp_md_declare_ref_del,
1011 .do_ref_del = osp_md_ref_del,
1012 .do_declare_destroy = osp_md_declare_object_destroy,
1013 .do_destroy = osp_md_object_destroy,
1014 .do_ah_init = osp_md_ah_init,
1015 .do_attr_get = osp_attr_get,
1016 .do_declare_attr_set = osp_md_declare_attr_set,
1017 .do_attr_set = osp_md_attr_set,
1018 .do_xattr_get = osp_xattr_get,
1019 .do_declare_xattr_set = osp_declare_xattr_set,
1020 .do_xattr_set = osp_xattr_set,
1021 .do_declare_xattr_del = osp_declare_xattr_del,
1022 .do_xattr_del = osp_xattr_del,
1023 .do_index_try = osp_md_index_try,
1024 .do_object_lock = osp_md_object_lock,
1025 .do_object_unlock = osp_md_object_unlock,
1029 * Implementation of dt_body_operations::dbo_declare_write
1031 * Create the osp_update_request to track the update for this OSP
1032 * in the transaction.
1034 * \param[in] env execution environment
1035 * \param[in] dt object to be written
1036 * \param[in] buf buffer to write which includes an embedded size field
1037 * \param[in] pos offet in the object to start writing at
1038 * \param[in] th transaction handle
1040 * \retval 0 if preparation succeeds.
1041 * \retval negative errno if preparation fails.
1043 static ssize_t osp_md_declare_write(const struct lu_env *env,
1044 struct dt_object *dt,
1045 const struct lu_buf *buf,
1046 loff_t pos, struct thandle *th)
1048 return osp_trans_update_request_create(th);
1052 * Implementation of dt_body_operations::dbo_write
1054 * Pack the write object update into the RPC buffer, which will be sent
1055 * to the remote MDT during transaction stop.
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
1062 * \param[in] ignore_quota quota enforcement for this write
1064 * \retval the buffer size in bytes if packing succeeds.
1065 * \retval negative errno if packing fails.
1067 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1068 const struct lu_buf *buf, loff_t *pos,
1069 struct thandle *th, int ignore_quota)
1071 struct osp_object *obj = dt2osp_obj(dt);
1072 struct osp_update_request *update;
1073 struct osp_thandle *oth = thandle_to_osp_thandle(th);
1077 update = thandle_to_osp_update_request(th);
1078 LASSERT(update != NULL);
1080 rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
1081 lu_object_fid(&dt->do_lu), buf, *pos);
1085 CDEBUG(D_INFO, "write "DFID" offset = "LPU64" length = %zu\n",
1086 PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
1088 /* XXX: how about the write error happened later? */
1089 *pos += buf->lb_len;
1091 if (obj->opo_ooa != NULL &&
1092 obj->opo_ooa->ooa_attr.la_valid & LA_SIZE &&
1093 obj->opo_ooa->ooa_attr.la_size < *pos)
1094 obj->opo_ooa->ooa_attr.la_size = *pos;
1096 rc = osp_check_and_set_rpc_version(oth);
1100 RETURN(buf->lb_len);
1103 static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
1104 struct lu_buf *rbuf, loff_t *pos)
1106 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1107 struct dt_device *dt_dev = &osp->opd_dt_dev;
1108 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
1109 struct osp_update_request *update = NULL;
1110 struct object_update_reply *reply;
1111 struct out_read_reply *orr;
1112 char *ptr = rbuf->lb_buf;
1113 struct ptlrpc_request *req = NULL;
1114 size_t total_length = rbuf->lb_len;
1115 size_t max_buf_size;
1116 loff_t offset = *pos;
1120 /* Calculate the maxium buffer length for each read request */
1121 max_buf_size = OUT_UPDATE_REPLY_SIZE - cfs_size_round(sizeof(*orr)) -
1122 cfs_size_round(sizeof(struct object_update_result)) -
1123 cfs_size_round(offsetof(struct object_update_reply,
1125 while (total_length > 0) {
1128 /* Because it needs send the update buffer right away,
1129 * just create an update buffer, instead of attaching the
1130 * update_remote list of the thandle. */
1131 update = osp_update_request_create(dt_dev);
1133 GOTO(out, rc = PTR_ERR(update));
1135 read_length = total_length > max_buf_size ?
1136 max_buf_size : total_length;
1138 rc = osp_update_rpc_pack(env, read, update, OUT_READ,
1139 lu_object_fid(&dt->do_lu),
1140 read_length, offset);
1142 CERROR("%s: cannot insert update: rc = %d\n",
1143 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
1147 rc = osp_remote_sync(env, osp, update, &req);
1151 reply = req_capsule_server_sized_get(&req->rq_pill,
1152 &RMF_OUT_UPDATE_REPLY,
1153 OUT_UPDATE_REPLY_SIZE);
1155 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1156 CERROR("%s: invalid update reply magic %x expected %x:"
1157 " rc = %d\n", dt_dev->dd_lu_dev.ld_obd->obd_name,
1158 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
1159 GOTO(out, rc = -EPROTO);
1162 rc = object_update_result_data_get(reply, lbuf, 0);
1166 if (lbuf->lb_len < sizeof(*orr))
1167 GOTO(out, rc = -EPROTO);
1170 orr_le_to_cpu(orr, orr);
1171 offset = orr->orr_offset;
1172 if (orr->orr_size > max_buf_size)
1173 GOTO(out, rc = -EPROTO);
1175 memcpy(ptr, orr->orr_data, orr->orr_size);
1176 ptr += orr->orr_size;
1177 total_length -= orr->orr_size;
1179 CDEBUG(D_INFO, "%s: read "DFID" pos "LPU64" len %u left %zu\n",
1180 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1181 offset, orr->orr_size, total_length);
1183 if (orr->orr_size < read_length)
1186 ptlrpc_req_finished(req);
1187 osp_update_request_destroy(update);
1192 total_length = rbuf->lb_len - total_length;
1194 CDEBUG(D_INFO, "%s: total read "DFID" pos "LPU64" len %zu\n",
1195 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1196 *pos, total_length);
1197 GOTO(out, rc = (int)total_length);
1200 ptlrpc_req_finished(req);
1203 osp_update_request_destroy(update);
1208 /* These body operation will be used to write symlinks during migration etc */
1209 struct dt_body_operations osp_md_body_ops = {
1210 .dbo_declare_write = osp_md_declare_write,
1211 .dbo_write = osp_md_write,
1212 .dbo_read = osp_md_read,