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 if (einfo->ei_nonblock)
902 flags |= LDLM_FL_BLOCK_NOWAIT;
904 req = ldlm_enqueue_pack(osp->opd_exp, 0);
906 RETURN(PTR_ERR(req));
908 rc = ldlm_cli_enqueue(osp->opd_exp, &req, einfo, res_id,
909 (const ldlm_policy_data_t *)policy,
910 &flags, NULL, 0, LVB_T_NONE, lh, 0);
912 ptlrpc_req_finished(req);
914 return rc == ELDLM_OK ? 0 : -EIO;
918 * Implementation of dt_object_operations::do_object_unlock
920 * Cancel a lock of a remote object.
922 * \param[in] env execution environment
923 * \param[in] dt object to be unlocked
924 * \param[in] einfo lock enqueue information
925 * \param[in] policy lock policy
927 * \retval Only return 0 for now.
929 static int osp_md_object_unlock(const struct lu_env *env,
930 struct dt_object *dt,
931 struct ldlm_enqueue_info *einfo,
932 ldlm_policy_data_t *policy)
934 struct lustre_handle *lockh = einfo->ei_cbdata;
937 ldlm_lock_decref(lockh, einfo->ei_mode);
943 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
945 * Create the dt_update_request to track the update for this OSP
946 * in the transaction.
948 * \param[in] env pointer to the thread context
949 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
950 * \param[in] th pointer to the transaction handler
952 * \retval 0 for success
953 * \retval negative error number on failure
955 int osp_md_declare_object_destroy(const struct lu_env *env,
956 struct dt_object *dt, struct thandle *th)
958 return osp_trans_update_request_create(th);
962 * Implement OSP layer dt_object_operations::do_destroy() interface.
964 * Pack the destroy update into the RPC buffer, which will be sent
965 * to the remote MDT during transaction stop.
967 * It also marks the object as non-cached.
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_object_destroy(const struct lu_env *env, struct dt_object *dt,
979 struct osp_object *o = dt2osp_obj(dt);
980 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
981 struct osp_update_request *update;
985 o->opo_non_exist = 1;
987 LASSERT(osp->opd_connect_mdt);
988 update = thandle_to_osp_update_request(th);
989 LASSERT(update != NULL);
991 rc = osp_update_rpc_pack(env, object_destroy, update, OUT_DESTROY,
992 lu_object_fid(&dt->do_lu));
996 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
997 rc = osp_insert_update_callback(env, update, dt2osp_obj(dt), NULL,
1003 struct dt_object_operations osp_md_obj_ops = {
1004 .do_read_lock = osp_md_object_read_lock,
1005 .do_write_lock = osp_md_object_write_lock,
1006 .do_read_unlock = osp_md_object_read_unlock,
1007 .do_write_unlock = osp_md_object_write_unlock,
1008 .do_write_locked = osp_md_object_write_locked,
1009 .do_declare_create = osp_md_declare_object_create,
1010 .do_create = osp_md_object_create,
1011 .do_declare_ref_add = osp_md_declare_ref_add,
1012 .do_ref_add = osp_md_ref_add,
1013 .do_declare_ref_del = osp_md_declare_ref_del,
1014 .do_ref_del = osp_md_ref_del,
1015 .do_declare_destroy = osp_md_declare_object_destroy,
1016 .do_destroy = osp_md_object_destroy,
1017 .do_ah_init = osp_md_ah_init,
1018 .do_attr_get = osp_attr_get,
1019 .do_declare_attr_set = osp_md_declare_attr_set,
1020 .do_attr_set = osp_md_attr_set,
1021 .do_xattr_get = osp_xattr_get,
1022 .do_declare_xattr_set = osp_declare_xattr_set,
1023 .do_xattr_set = osp_xattr_set,
1024 .do_declare_xattr_del = osp_declare_xattr_del,
1025 .do_xattr_del = osp_xattr_del,
1026 .do_index_try = osp_md_index_try,
1027 .do_object_lock = osp_md_object_lock,
1028 .do_object_unlock = osp_md_object_unlock,
1032 * Implementation of dt_body_operations::dbo_declare_write
1034 * Create the osp_update_request to track the update for this OSP
1035 * in the transaction.
1037 * \param[in] env execution environment
1038 * \param[in] dt object to be written
1039 * \param[in] buf buffer to write which includes an embedded size field
1040 * \param[in] pos offet in the object to start writing at
1041 * \param[in] th transaction handle
1043 * \retval 0 if preparation succeeds.
1044 * \retval negative errno if preparation fails.
1046 static ssize_t osp_md_declare_write(const struct lu_env *env,
1047 struct dt_object *dt,
1048 const struct lu_buf *buf,
1049 loff_t pos, struct thandle *th)
1051 return osp_trans_update_request_create(th);
1055 * Implementation of dt_body_operations::dbo_write
1057 * Pack the write object update into the RPC buffer, which will be sent
1058 * to the remote MDT during transaction stop.
1060 * \param[in] env execution environment
1061 * \param[in] dt object to be written
1062 * \param[in] buf buffer to write which includes an embedded size field
1063 * \param[in] pos offet in the object to start writing at
1064 * \param[in] th transaction handle
1065 * \param[in] ignore_quota quota enforcement for this write
1067 * \retval the buffer size in bytes if packing succeeds.
1068 * \retval negative errno if packing fails.
1070 static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
1071 const struct lu_buf *buf, loff_t *pos,
1072 struct thandle *th, int ignore_quota)
1074 struct osp_object *obj = dt2osp_obj(dt);
1075 struct osp_update_request *update;
1076 struct osp_thandle *oth = thandle_to_osp_thandle(th);
1080 update = thandle_to_osp_update_request(th);
1081 LASSERT(update != NULL);
1083 rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
1084 lu_object_fid(&dt->do_lu), buf, *pos);
1088 CDEBUG(D_INFO, "write "DFID" offset = "LPU64" length = %zu\n",
1089 PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
1091 /* XXX: how about the write error happened later? */
1092 *pos += buf->lb_len;
1094 if (obj->opo_ooa != NULL &&
1095 obj->opo_ooa->ooa_attr.la_valid & LA_SIZE &&
1096 obj->opo_ooa->ooa_attr.la_size < *pos)
1097 obj->opo_ooa->ooa_attr.la_size = *pos;
1099 rc = osp_check_and_set_rpc_version(oth);
1103 RETURN(buf->lb_len);
1106 static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
1107 struct lu_buf *rbuf, loff_t *pos)
1109 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1110 struct dt_device *dt_dev = &osp->opd_dt_dev;
1111 struct lu_buf *lbuf = &osp_env_info(env)->osi_lb2;
1112 struct osp_update_request *update = NULL;
1113 struct object_update_reply *reply;
1114 struct out_read_reply *orr;
1115 char *ptr = rbuf->lb_buf;
1116 struct ptlrpc_request *req = NULL;
1117 size_t total_length = rbuf->lb_len;
1118 size_t max_buf_size;
1119 loff_t offset = *pos;
1123 /* Calculate the maxium buffer length for each read request */
1124 max_buf_size = OUT_UPDATE_REPLY_SIZE - cfs_size_round(sizeof(*orr)) -
1125 cfs_size_round(sizeof(struct object_update_result)) -
1126 cfs_size_round(offsetof(struct object_update_reply,
1128 while (total_length > 0) {
1131 /* Because it needs send the update buffer right away,
1132 * just create an update buffer, instead of attaching the
1133 * update_remote list of the thandle. */
1134 update = osp_update_request_create(dt_dev);
1136 GOTO(out, rc = PTR_ERR(update));
1138 read_length = total_length > max_buf_size ?
1139 max_buf_size : total_length;
1141 rc = osp_update_rpc_pack(env, read, update, OUT_READ,
1142 lu_object_fid(&dt->do_lu),
1143 read_length, offset);
1145 CERROR("%s: cannot insert update: rc = %d\n",
1146 dt_dev->dd_lu_dev.ld_obd->obd_name, rc);
1150 rc = osp_remote_sync(env, osp, update, &req);
1154 reply = req_capsule_server_sized_get(&req->rq_pill,
1155 &RMF_OUT_UPDATE_REPLY,
1156 OUT_UPDATE_REPLY_SIZE);
1158 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1159 CERROR("%s: invalid update reply magic %x expected %x:"
1160 " rc = %d\n", dt_dev->dd_lu_dev.ld_obd->obd_name,
1161 reply->ourp_magic, UPDATE_REPLY_MAGIC, -EPROTO);
1162 GOTO(out, rc = -EPROTO);
1165 rc = object_update_result_data_get(reply, lbuf, 0);
1169 if (lbuf->lb_len < sizeof(*orr))
1170 GOTO(out, rc = -EPROTO);
1173 orr_le_to_cpu(orr, orr);
1174 offset = orr->orr_offset;
1175 if (orr->orr_size > max_buf_size)
1176 GOTO(out, rc = -EPROTO);
1178 memcpy(ptr, orr->orr_data, orr->orr_size);
1179 ptr += orr->orr_size;
1180 total_length -= orr->orr_size;
1182 CDEBUG(D_INFO, "%s: read "DFID" pos "LPU64" len %u left %zu\n",
1183 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1184 offset, orr->orr_size, total_length);
1186 if (orr->orr_size < read_length)
1189 ptlrpc_req_finished(req);
1190 osp_update_request_destroy(update);
1195 total_length = rbuf->lb_len - total_length;
1197 CDEBUG(D_INFO, "%s: total read "DFID" pos "LPU64" len %zu\n",
1198 osp->opd_obd->obd_name, PFID(lu_object_fid(&dt->do_lu)),
1199 *pos, total_length);
1200 GOTO(out, rc = (int)total_length);
1203 ptlrpc_req_finished(req);
1206 osp_update_request_destroy(update);
1211 /* These body operation will be used to write symlinks during migration etc */
1212 struct dt_body_operations osp_md_body_ops = {
1213 .dbo_declare_write = osp_md_declare_write,
1214 .dbo_write = osp_md_write,
1215 .dbo_read = osp_md_read,