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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * lustre/osp/osp_object.c
31 * Lustre OST Proxy Device (OSP) is the agent on the local MDT for the OST
34 * OSP object attributes cache
35 * ---------------------------
36 * OSP object is the stub of the remote OST-object or MDT-object. Both the
37 * attribute and the extended attributes are stored on the peer side remotely.
38 * It is inefficient to send RPC to peer to fetch those attributes when every
39 * get_attr()/get_xattr() called. For a large system, the LFSCK synchronous
40 * mode scanning is prohibitively inefficient.
42 * The OSP maintains the OSP object attributes cache to cache some
43 * attributes on the local MDT.
45 * The basic attributes, such as owner/mode/flags, are stored in the
46 * osp_object::opo_attr. The extended attributes will be stored
47 * as osp_xattr_entry. Every extended attribute has an independent
48 * osp_xattr_entry, and all the osp_xattr_entry are linked into the
49 * osp_object::opo_xattr_list. The OSP object attributes cache
50 * is protected by the osp_object::opo_lock.
52 * Not all OSP objects have an attributes cache because maintaining
53 * the cache requires some resources. Currently, the OSP object
54 * attributes cache will be initialized when the attributes or the
55 * extended attributes are pre-fetched via osp_declare_attr_get()
56 * or osp_declare_xattr_get(). That is usually for LFSCK purpose,
57 * but it also can be shared by others.
60 * XXX: NOT prepare out RPC for remote transaction. ((please refer to the
61 * comment of osp_trans_create() for remote transaction)
63 * According to our current transaction/dt_object_lock framework (to make
64 * the cross-MDTs modification for DNE1 to be workable), the transaction
65 * sponsor will start the transaction firstly, then try to acquire related
66 * dt_object_lock if needed. Under such rules, if we want to prepare the
67 * OUT RPC in the transaction declare phase, then related attr/xattr
68 * should be known without dt_object_lock. But such condition maybe not
69 * true for some remote transaction case. For example:
71 * For linkEA repairing (by LFSCK) case, before the LFSCK thread obtained
72 * the dt_object_lock on the target MDT-object, it cannot know whether
73 * the MDT-object has linkEA or not, neither invalid or not.
75 * Since the LFSCK thread cannot hold dt_object_lock before the remote
76 * transaction start (otherwise there will be some potential deadlock),
77 * it cannot prepare related OUT RPC for repairing during the declare
78 * phase as other normal transactions do.
80 * To resolve the trouble, we will make OSP to prepare related OUT RPC
81 * after remote transaction started, and trigger the remote updating
82 * (send RPC) when trans_stop. Then the up layer users, such as LFSCK,
83 * can follow the general rule to handle trans_start/dt_object_lock
84 * for repairing linkEA inconsistency without distinguishing remote
87 * In fact, above solution for remote transaction should be the normal
88 * model without considering DNE1. The trouble brought by DNE1 will be
89 * resolved in DNE2. At that time, this patch can be removed.
92 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
93 * Author: Mikhail Pershin <mike.tappro@intel.com>
96 #define DEBUG_SUBSYSTEM S_MDS
98 #include <lustre_obdo.h>
99 #include <lustre_swab.h>
101 #include "osp_internal.h"
103 static inline __u32 osp_dev2node(struct osp_device *osp)
105 return osp->opd_storage->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
108 static inline const char *osp_dto2name(struct osp_object *obj)
110 return obj->opo_obj.do_lu.lo_dev->ld_obd->obd_name;
113 static inline bool is_ost_obj(struct lu_object *lo)
115 return !lu2osp_dev(lo->lo_dev)->opd_connect_mdt;
118 static inline void __osp_oac_xattr_assignment(struct osp_object *obj,
119 struct osp_xattr_entry *oxe,
120 const struct lu_buf *buf)
123 memcpy(oxe->oxe_value, buf->lb_buf, buf->lb_len);
125 oxe->oxe_vallen = buf->lb_len;
131 * Assign FID to the OST object.
133 * This function will assign the FID to the OST object of a striped file.
135 * \param[in] env pointer to the thread context
136 * \param[in] d pointer to the OSP device
137 * \param[in] o pointer to the OSP object that the FID will be
140 static void osp_object_assign_fid(const struct lu_env *env,
141 struct osp_device *d, struct osp_object *o)
143 struct osp_thread_info *osi = osp_env_info(env);
145 LASSERT(fid_is_zero(lu_object_fid(&o->opo_obj.do_lu)));
146 LASSERT(o->opo_reserved);
149 osp_precreate_get_fid(env, d, &osi->osi_fid);
151 lu_object_assign_fid(env, &o->opo_obj.do_lu, &osi->osi_fid);
154 #define OXE_DEFAULT_LEN 16
157 * Allocate osp_xattr_entry.
159 * If total size exceeds PAGE_SIZE, name and value will allocated in a
160 * separate buf, otherwise it's allocated inline.
162 * \param[in] name pointer to XATTR name
163 * \param[in] namelen XATTR name len
164 * \param[in] vallen XATTR value len
165 * \retval oxe pointer on success
166 * \retval NULL on failure
168 static struct osp_xattr_entry *osp_oac_xattr_alloc(const char *name,
172 struct osp_xattr_entry *oxe;
176 vallen = OXE_DEFAULT_LEN;
177 size = sizeof(*oxe) + namelen + 1 + vallen;
178 if (likely(size <= PAGE_SIZE)) {
179 OBD_ALLOC(oxe, size);
182 oxe->oxe_buflen = size;
183 oxe->oxe_value = oxe->oxe_name + namelen + 1;
187 OBD_ALLOC_LARGE(buf, vallen);
192 OBD_ALLOC(oxe, size);
193 if (unlikely(!oxe)) {
197 oxe->oxe_buflen = vallen;
198 oxe->oxe_value = buf;
199 oxe->oxe_largebuf = 1;
202 INIT_LIST_HEAD(&oxe->oxe_list);
204 oxe->oxe_namelen = namelen;
205 memcpy(oxe->oxe_name, name, namelen);
206 /* One ref is for the caller, the other is for the entry on the list. */
207 atomic_set(&oxe->oxe_ref, 2);
212 static void osp_oac_xattr_free(struct osp_xattr_entry *oxe)
214 LASSERT(list_empty(&oxe->oxe_list));
215 if (unlikely(oxe->oxe_largebuf)) {
216 OBD_FREE_LARGE(oxe->oxe_value, oxe->oxe_buflen);
217 OBD_FREE(oxe, sizeof(*oxe) + oxe->oxe_namelen + 1);
219 OBD_FREE(oxe, oxe->oxe_buflen);
224 * Release reference from the OSP object extended attribute entry.
226 * If it is the last reference, then free the entry.
228 * \param[in] oxe pointer to the OSP object extended attribute entry.
230 static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
232 if (atomic_dec_and_test(&oxe->oxe_ref))
233 osp_oac_xattr_free(oxe);
237 * Find the named extended attribute in the OSP object attributes cache.
239 * The caller should take the osp_object::opo_lock before calling
242 * \param[in] obj pointer to the OSP object
243 * \param[in] name the name of the extended attribute
244 * \param[in] namelen the name length of the extended attribute
246 * \retval pointer to the found extended attribute entry
247 * \retval NULL if the specified extended attribute is not
250 static struct osp_xattr_entry *
251 osp_oac_xattr_find_locked(struct osp_object *obj, const char *name,
254 struct osp_xattr_entry *oxe;
256 list_for_each_entry(oxe, &obj->opo_xattr_list, oxe_list) {
257 if (namelen == oxe->oxe_namelen &&
258 strncmp(name, oxe->oxe_name, namelen) == 0)
266 * Find the named extended attribute in the OSP object attributes cache.
268 * Call osp_oac_xattr_find_locked() with the osp_object::opo_lock held.
270 * \param[in] obj pointer to the OSP object
271 * \param[in] name the name of the extended attribute
272 * \param[in] unlink true if the extended attribute entry is to be removed
275 * \retval pointer to the found extended attribute entry
276 * \retval NULL if the specified extended attribute is not
279 static struct osp_xattr_entry *osp_oac_xattr_find(struct osp_object *obj,
280 const char *name, bool unlink)
282 struct osp_xattr_entry *oxe = NULL;
284 spin_lock(&obj->opo_lock);
285 oxe = osp_oac_xattr_find_locked(obj, name, strlen(name));
288 list_del_init(&oxe->oxe_list);
290 atomic_inc(&oxe->oxe_ref);
292 spin_unlock(&obj->opo_lock);
298 * Find the named extended attribute in the OSP object attributes cache.
300 * If it is not in the cache, then add an empty entry (that will be
301 * filled later) to cache with the given name.
303 * \param[in] obj pointer to the OSP object
304 * \param[in] name the name of the extended attribute
305 * \param[in] len the length of the extended attribute value
307 * \retval pointer to the found or new-created extended
309 * \retval NULL if the specified extended attribute is not in the
310 * cache or fail to add new empty entry to the cache.
312 static struct osp_xattr_entry *
313 osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
315 struct osp_xattr_entry *oxe;
316 struct osp_xattr_entry *tmp = NULL;
317 size_t namelen = strlen(name);
319 oxe = osp_oac_xattr_find(obj, name, false);
323 oxe = osp_oac_xattr_alloc(name, namelen, len);
327 spin_lock(&obj->opo_lock);
328 tmp = osp_oac_xattr_find_locked(obj, name, namelen);
330 list_add_tail(&oxe->oxe_list, &obj->opo_xattr_list);
332 atomic_inc(&tmp->oxe_ref);
333 spin_unlock(&obj->opo_lock);
336 osp_oac_xattr_free(oxe);
343 /* whether \a oxe is large enough to hold XATTR value */
344 static inline bool oxe_can_hold(struct osp_xattr_entry *oxe, size_t len)
346 if (unlikely(oxe->oxe_largebuf))
347 return oxe->oxe_buflen > len;
349 return oxe->oxe_buflen - oxe->oxe_namelen - 1 - sizeof(*oxe) > len;
353 * Assign the cached OST-object's EA with the given value.
355 * If the current EA entry in cache has not enough space to hold the new
356 * value, remove it, create a new one, then assign with the given value.
358 * \param[in] obj pointer to the OSP object
359 * \param[in] oxe pointer to the cached EA entry to be assigned
360 * \param[in] buf pointer to the buffer with new EA value
362 * \retval pointer to the new created EA entry in cache if
363 * current entry is not big enough; otherwise, the
364 * input 'oxe' will be returned.
366 static struct osp_xattr_entry *
367 osp_oac_xattr_assignment(struct osp_object *obj, struct osp_xattr_entry *oxe,
368 const struct lu_buf *buf)
370 struct osp_xattr_entry *new = NULL;
371 struct osp_xattr_entry *old = NULL;
372 int namelen = oxe->oxe_namelen;
373 bool unlink_only = false;
375 if (!oxe_can_hold(oxe, buf->lb_len)) {
376 new = osp_oac_xattr_alloc(oxe->oxe_name, namelen, buf->lb_len);
378 __osp_oac_xattr_assignment(obj, new, buf);
381 CWARN("%s: cannot update cached xattr %.*s of "DFID"\n",
382 osp_dto2name(obj), namelen, oxe->oxe_name,
383 PFID(lu_object_fid(&obj->opo_obj.do_lu)));
387 spin_lock(&obj->opo_lock);
388 old = osp_oac_xattr_find_locked(obj, oxe->oxe_name, namelen);
391 /* Unlink the 'old'. */
392 list_del_init(&old->oxe_list);
394 /* Drop the ref for 'old' on list. */
395 osp_oac_xattr_put(old);
397 /* Drop the ref for current using. */
398 osp_oac_xattr_put(oxe);
401 /* Insert 'new' into list. */
402 list_add_tail(&new->oxe_list, &obj->opo_xattr_list);
403 } else if (unlink_only) {
404 /* Unlink the 'old'. */
405 list_del_init(&old->oxe_list);
407 /* Drop the ref for 'old' on list. */
408 osp_oac_xattr_put(old);
410 __osp_oac_xattr_assignment(obj, oxe, buf);
413 /* Drop the ref for current using. */
414 osp_oac_xattr_put(oxe);
417 /* Someone unlinked the 'old' by race,
418 * insert the 'new' one into list. */
419 list_add_tail(&new->oxe_list, &obj->opo_xattr_list);
421 spin_unlock(&obj->opo_lock);
427 * Parse the OSP object attribute from the RPC reply.
429 * If the attribute is valid, then it will be added to the OSP object
432 * \param[in] env pointer to the thread context
433 * \param[in] reply pointer to the RPC reply
434 * \param[in] req pointer to the RPC request
435 * \param[out] attr pointer to buffer to hold the output attribute
436 * \param[in] obj pointer to the OSP object
437 * \param[in] index the index of the attribute buffer in the reply
439 * \retval 0 for success
440 * \retval negative error number on failure
442 static int osp_get_attr_from_reply(const struct lu_env *env,
443 struct object_update_reply *reply,
444 struct ptlrpc_request *req,
445 struct lu_attr *attr,
446 struct osp_object *obj, int index)
448 struct osp_thread_info *osi = osp_env_info(env);
449 struct lu_buf *rbuf = &osi->osi_lb2;
450 struct obdo *lobdo = &osi->osi_obdo;
454 rc = object_update_result_data_get(reply, rbuf, index);
458 wobdo = rbuf->lb_buf;
459 if (rbuf->lb_len != sizeof(*wobdo))
462 LASSERT(req != NULL);
463 if (req_capsule_req_need_swab(&req->rq_pill))
464 lustre_swab_obdo(wobdo);
466 lustre_get_wire_obdo(NULL, lobdo, wobdo);
468 spin_lock(&obj->opo_lock);
469 la_from_obdo(&obj->opo_attr, lobdo, lobdo->o_valid);
470 spin_unlock(&obj->opo_lock);
473 la_from_obdo(attr, lobdo, lobdo->o_valid);
479 * Interpreter function for getting OSP object attribute asynchronously.
481 * Called to interpret the result of an async mode RPC for getting the
482 * OSP object attribute.
484 * \param[in] env pointer to the thread context
485 * \param[in] reply pointer to the RPC reply
486 * \param[in] req pointer to the RPC request
487 * \param[in] obj pointer to the OSP object
488 * \param[out] data pointer to buffer to hold the output attribute
489 * \param[in] index the index of the attribute buffer in the reply
490 * \param[in] rc the result for handling the RPC
492 * \retval 0 for success
493 * \retval negative error number on failure
495 static int osp_attr_get_interpterer(const struct lu_env *env,
496 struct object_update_reply *reply,
497 struct ptlrpc_request *req,
498 struct osp_object *obj,
499 void *data, int index, int rc)
501 struct lu_attr *attr = data;
504 osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
505 obj->opo_non_exist = 0;
507 return osp_get_attr_from_reply(env, reply, req, NULL, obj,
511 osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
512 obj->opo_non_exist = 1;
515 spin_lock(&obj->opo_lock);
517 spin_unlock(&obj->opo_lock);
524 * Implement OSP layer dt_object_operations::do_declare_attr_get() interface.
526 * Declare that the caller will get attribute from the specified OST object.
528 * This function adds an Object Unified Target (OUT) sub-request to the per-OSP
529 * based shared asynchronous request queue. The osp_attr_get_interpterer()
530 * is registered as the interpreter function to handle the result of this
533 * \param[in] env pointer to the thread context
534 * \param[in] dt pointer to the OSP layer dt_object
536 * \retval 0 for success
537 * \retval negative error number on failure
539 static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt)
541 struct osp_object *obj = dt2osp_obj(dt);
542 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
545 mutex_lock(&osp->opd_async_requests_mutex);
546 rc = osp_insert_async_request(env, OUT_ATTR_GET, obj, 0, NULL, NULL,
547 &obj->opo_attr, sizeof(struct obdo),
548 osp_attr_get_interpterer);
549 mutex_unlock(&osp->opd_async_requests_mutex);
555 * Implement OSP layer dt_object_operations::do_attr_get() interface.
557 * Get attribute from the specified MDT/OST object.
559 * If the attribute is in the OSP object attributes cache, then return
560 * the cached attribute directly. Otherwise it will trigger an OUT RPC
561 * to the peer to get the attribute synchronously, if successful, add it
562 * to the OSP attributes cache. (\see lustre/osp/osp_trans.c for OUT RPC.)
564 * \param[in] env pointer to the thread context
565 * \param[in] dt pointer to the OSP layer dt_object
566 * \param[out] attr pointer to the buffer to hold the output attribute
568 * \retval 0 for success
569 * \retval negative error number on failure
571 int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
572 struct lu_attr *attr)
574 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
575 struct osp_object *obj = dt2osp_obj(dt);
576 struct dt_device *dev = &osp->opd_dt_dev;
577 struct osp_update_request *update;
578 struct object_update_reply *reply;
579 struct ptlrpc_request *req = NULL;
580 int invalidated, cache = 0, rc = 0;
583 if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
585 if (obj->opo_destroyed)
588 spin_lock(&obj->opo_lock);
589 if (obj->opo_attr.la_valid != 0 && !obj->opo_stale) {
590 *attr = obj->opo_attr;
591 spin_unlock(&obj->opo_lock);
595 spin_unlock(&obj->opo_lock);
597 update = osp_update_request_create(dev);
599 RETURN(PTR_ERR(update));
601 rc = OSP_UPDATE_RPC_PACK(env, out_attr_get_pack, update,
602 lu_object_fid(&dt->do_lu));
604 CERROR("%s: Insert update error "DFID": rc = %d\n",
605 dev->dd_lu_dev.ld_obd->obd_name,
606 PFID(lu_object_fid(&dt->do_lu)), rc);
611 invalidated = atomic_read(&obj->opo_invalidate_seq);
613 rc = osp_remote_sync(env, osp, update, &req);
615 down_read(&obj->opo_invalidate_sem);
616 if (invalidated == atomic_read(&obj->opo_invalidate_seq)) {
617 /* no invalited has came so far, we can cache the attrs */
623 osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
625 obj->opo_non_exist = 1;
627 CERROR("%s: osp_attr_get update error "DFID": rc = %d\n",
628 dev->dd_lu_dev.ld_obd->obd_name,
629 PFID(lu_object_fid(&dt->do_lu)), rc);
635 osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
636 obj->opo_non_exist = 0;
637 reply = req_capsule_server_sized_get(&req->rq_pill,
638 &RMF_OUT_UPDATE_REPLY,
639 OUT_UPDATE_REPLY_SIZE);
640 if (reply == NULL || reply->ourp_magic != UPDATE_REPLY_MAGIC)
641 GOTO(out, rc = -EPROTO);
643 rc = osp_get_attr_from_reply(env, reply, req, attr,
644 cache ? obj : NULL, 0);
648 spin_lock(&obj->opo_lock);
651 spin_unlock(&obj->opo_lock);
656 up_read(&obj->opo_invalidate_sem);
660 ptlrpc_req_finished(req);
662 osp_update_request_destroy(env, update);
668 * Implement OSP layer dt_object_operations::do_declare_attr_set() interface.
670 * If the transaction is not remote one, then declare the credits that will
671 * be used for the subsequent llog record for the object's attributes.
673 * \param[in] env pointer to the thread context
674 * \param[in] dt pointer to the OSP layer dt_object
675 * \param[in] attr pointer to the attribute to be set
676 * \param[in] th pointer to the transaction handler
678 * \retval 0 for success
679 * \retval negative error number on failure
681 static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
682 const struct lu_attr *attr, struct thandle *th)
684 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
685 struct osp_object *o = dt2osp_obj(dt);
688 if (is_only_remote_trans(th))
689 return osp_md_declare_attr_set(env, dt, attr, th);
691 * Usually we don't allow server stack to manipulate size
692 * but there is a special case when striping is created
693 * late, after stripeless file got truncated to non-zero.
695 * In this case we do the following:
697 * 1) grab id in declare - this can lead to leaked OST objects
698 * but we don't currently have proper mechanism and the only
699 * options we have are to do truncate RPC holding transaction
700 * open (very bad) or to grab id in declare at cost of leaked
701 * OST object in same very rare unfortunate case (just bad)
702 * notice 1.6-2.0 do assignment outside of running transaction
703 * all the time, meaning many more chances for leaked objects.
705 * 2) send synchronous truncate RPC with just assigned id
708 /* there are few places in MDD code still passing NULL
709 * XXX: to be fixed soon */
713 if (attr->la_valid & LA_SIZE && attr->la_size > 0 &&
714 fid_is_zero(lu_object_fid(&o->opo_obj.do_lu))) {
715 LASSERT(!dt_object_exists(dt));
716 osp_object_assign_fid(env, d, o);
717 rc = osp_object_truncate(env, dt, attr->la_size);
722 if (!(attr->la_valid & LA_REMOTE_ATTR_SET))
725 /* track all UID/GID, projid, and layout version changes via llog */
726 rc = osp_sync_declare_add(env, o, MDS_SETATTR64_REC, th);
732 * Implement OSP layer dt_object_operations::do_attr_set() interface.
734 * Set attribute to the specified OST object.
736 * If the transaction is a remote one, then add OUT_ATTR_SET sub-request
737 * in the OUT RPC that will be flushed when the remote transaction stop.
738 * Otherwise, it will generate a MDS_SETATTR64_REC record in the llog that
739 * will be handled by a dedicated thread asynchronously.
741 * If the attribute entry exists in the OSP object attributes cache,
742 * then update the cached attribute according to given attribute.
744 * \param[in] env pointer to the thread context
745 * \param[in] dt pointer to the OSP layer dt_object
746 * \param[in] attr pointer to the attribute to be set
747 * \param[in] th pointer to the transaction handler
749 * \retval 0 for success
750 * \retval negative error number on failure
752 static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
753 const struct lu_attr *attr, struct thandle *th)
755 struct osp_object *o = dt2osp_obj(dt);
759 /* we're interested in uid/gid/projid/layout version changes,
760 * and also specific setting of enc flag
762 if (!(attr->la_valid & LA_REMOTE_ATTR_SET) &&
763 !(attr->la_valid == LA_FLAGS &&
764 attr->la_flags == LUSTRE_ENCRYPT_FL))
767 if (!is_only_remote_trans(th)) {
768 if (attr->la_flags & LUSTRE_SET_SYNC_FL) {
769 struct ptlrpc_request *req = NULL;
770 struct osp_update_request *update = NULL;
771 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
773 update = osp_update_request_create(&osp->opd_dt_dev);
775 RETURN(PTR_ERR(update));
777 rc = OSP_UPDATE_RPC_PACK(env, out_attr_set_pack, update,
778 lu_object_fid(&dt->do_lu),
781 CERROR("%s: update error "DFID": rc = %d\n",
782 osp->opd_obd->obd_name,
783 PFID(lu_object_fid(&dt->do_lu)), rc);
785 osp_update_request_destroy(env, update);
789 rc = osp_remote_sync(env, osp, update, &req);
791 ptlrpc_req_finished(req);
793 osp_update_request_destroy(env, update);
795 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
797 rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
798 /* send layout version to OST ASAP */
799 if (attr->la_valid & LA_LAYOUT_VERSION)
800 wake_up(&osp->opd_sync_waitq);
801 /* XXX: send new uid/gid to OST ASAP? */
806 /* It is for OST-object attr_set directly without updating
807 * local MDT-object attribute. It is usually used by LFSCK. */
808 rc = osp_md_attr_set(env, dt, attr, th);
809 CDEBUG(D_INFO, "(1) set attr "DFID": rc = %d\n",
810 PFID(&dt->do_lu.lo_header->loh_fid), rc);
815 /* Update the OSP object attributes cache. */
817 spin_lock(&o->opo_lock);
818 if (attr->la_valid & LA_UID) {
819 la->la_uid = attr->la_uid;
820 la->la_valid |= LA_UID;
823 if (attr->la_valid & LA_GID) {
824 la->la_gid = attr->la_gid;
825 la->la_valid |= LA_GID;
827 if (attr->la_valid & LA_PROJID) {
828 la->la_projid = attr->la_projid;
829 la->la_valid |= LA_PROJID;
831 spin_unlock(&o->opo_lock);
838 * Interpreter function for getting OSP object extended attribute asynchronously
840 * Called to interpret the result of an async mode RPC for getting the
841 * OSP object extended attribute.
843 * \param[in] env pointer to the thread context
844 * \param[in] reply pointer to the RPC reply
845 * \param[in] req pointer to the RPC request
846 * \param[in] obj pointer to the OSP object
847 * \param[out] data pointer to OSP object attributes cache
848 * \param[in] index the index of the attribute buffer in the reply
849 * \param[in] rc the result for handling the RPC
851 * \retval 0 for success
852 * \retval negative error number on failure
854 static int osp_xattr_get_interpterer(const struct lu_env *env,
855 struct object_update_reply *reply,
856 struct ptlrpc_request *req,
857 struct osp_object *obj,
858 void *data, int index, int rc)
860 struct osp_xattr_entry *oxe = data;
862 spin_lock(&obj->opo_lock);
864 struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
866 rc = object_update_result_data_get(reply, rbuf, index);
867 if (rc == -ENOENT || rc == -ENODATA || rc == 0) {
873 if (unlikely(rc < 0) || !oxe_can_hold(oxe, rbuf->lb_len)) {
878 __osp_oac_xattr_assignment(obj, oxe, rbuf);
879 } else if (rc == -ENOENT || rc == -ENODATA) {
887 spin_unlock(&obj->opo_lock);
889 /* Put the reference obtained in the osp_declare_xattr_get(). */
890 osp_oac_xattr_put(oxe);
896 * Implement OSP dt_object_operations::do_declare_xattr_get() interface.
898 * Declare that the caller will get extended attribute from the specified
901 * This function will add an OUT_XATTR_GET sub-request to the per OSP
902 * based shared asynchronous request queue with the interpreter function:
903 * osp_xattr_get_interpterer().
905 * \param[in] env pointer to the thread context
906 * \param[in] dt pointer to the OSP layer dt_object
907 * \param[out] buf pointer to the lu_buf to hold the extended attribute
908 * \param[in] name the name for the expected extended attribute
910 * \retval 0 for success
911 * \retval negative error number on failure
913 static int osp_declare_xattr_get(const struct lu_env *env, struct dt_object *dt,
914 struct lu_buf *buf, const char *name)
916 struct osp_object *obj = dt2osp_obj(dt);
917 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
918 struct osp_xattr_entry *oxe;
922 LASSERT(buf != NULL);
923 LASSERT(name != NULL);
925 if (unlikely(buf->lb_len == 0))
928 oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
932 len = strlen(name) + 1;
933 mutex_lock(&osp->opd_async_requests_mutex);
934 rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
935 &len, (const void **)&name,
937 osp_xattr_get_interpterer);
939 mutex_unlock(&osp->opd_async_requests_mutex);
940 osp_oac_xattr_put(oxe);
942 struct osp_update_request *our;
943 struct osp_update_request_sub *ours;
945 /* XXX: Currently, we trigger the batched async OUT
946 * RPC via dt_declare_xattr_get(). It is not
947 * perfect solution, but works well now.
949 * We will improve it in the future. */
950 our = osp->opd_async_requests;
951 ours = osp_current_object_update_request(our);
952 if (ours != NULL && ours->ours_req != NULL &&
953 ours->ours_req->ourq_count > 0) {
954 osp->opd_async_requests = NULL;
955 mutex_unlock(&osp->opd_async_requests_mutex);
956 rc = osp_unplug_async_request(env, osp, our);
958 mutex_unlock(&osp->opd_async_requests_mutex);
966 * Implement OSP layer dt_object_operations::do_xattr_get() interface.
968 * Get extended attribute from the specified MDT/OST object.
970 * If the extended attribute is in the OSP object attributes cache, then
971 * return the cached extended attribute directly. Otherwise it will get
972 * the extended attribute synchronously, if successful, add it to the OSP
973 * attributes cache. (\see lustre/osp/osp_trans.c for OUT RPC.)
975 * There is a race condition: some other thread has added the named extended
976 * attributed entry to the OSP object attributes cache during the current
977 * OUT_XATTR_GET handling. If such case happens, the OSP will replace the
978 * (just) existing extended attribute entry with the new replied one.
980 * \param[in] env pointer to the thread context
981 * \param[in] dt pointer to the OSP layer dt_object
982 * \param[out] buf pointer to the lu_buf to hold the extended attribute
983 * \param[in] name the name for the expected extended attribute
985 * \retval 0 for success
986 * \retval negative error number on failure
988 int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
989 struct lu_buf *buf, const char *name)
991 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
992 struct osp_object *obj = dt2osp_obj(dt);
993 struct dt_device *dev = &osp->opd_dt_dev;
994 struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
995 struct osp_update_request *update = NULL;
996 struct ptlrpc_request *req = NULL;
997 struct object_update_reply *reply;
998 struct osp_xattr_entry *oxe = NULL;
999 const char *dname = osp_dto2name(obj);
1000 int invalidated, rc = 0;
1003 LASSERT(buf != NULL);
1004 LASSERT(name != NULL);
1006 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NETWORK) &&
1007 osp->opd_index == cfs_fail_val) {
1008 if (is_ost_obj(&dt->do_lu)) {
1009 if (osp_dev2node(osp) == cfs_fail_val)
1012 if (strcmp(name, XATTR_NAME_LINK) == 0)
1017 if (unlikely(obj->opo_non_exist))
1020 invalidated = atomic_read(&obj->opo_invalidate_seq);
1022 oxe = osp_oac_xattr_find(obj, name, false);
1024 spin_lock(&obj->opo_lock);
1025 if (oxe->oxe_ready) {
1026 if (!oxe->oxe_exist)
1027 GOTO(unlock, rc = -ENODATA);
1029 if (buf->lb_buf == NULL)
1030 GOTO(unlock, rc = oxe->oxe_vallen);
1032 if (buf->lb_len < oxe->oxe_vallen)
1033 GOTO(unlock, rc = -ERANGE);
1035 memcpy(buf->lb_buf, oxe->oxe_value,
1038 GOTO(unlock, rc = oxe->oxe_vallen);
1041 spin_unlock(&obj->opo_lock);
1042 osp_oac_xattr_put(oxe);
1046 spin_unlock(&obj->opo_lock);
1048 update = osp_update_request_create(dev);
1050 GOTO(out_req, rc = PTR_ERR(update));
1052 rc = OSP_UPDATE_RPC_PACK(env, out_xattr_get_pack, update,
1053 lu_object_fid(&dt->do_lu), name, buf->lb_len);
1055 CERROR("%s: Insert update error "DFID": rc = %d\n",
1056 dname, PFID(lu_object_fid(&dt->do_lu)), rc);
1060 rc = osp_remote_sync(env, osp, update, &req);
1062 down_read(&obj->opo_invalidate_sem);
1063 if (invalidated != atomic_read(&obj->opo_invalidate_seq)) {
1064 /* invalidated has been requested, we can't cache the result */
1067 dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
1070 reply = req_capsule_server_sized_get(&req->rq_pill,
1071 &RMF_OUT_UPDATE_REPLY,
1072 OUT_UPDATE_REPLY_SIZE);
1073 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1074 CERROR("%s: Wrong version %x expected %x "DFID
1075 ": rc = %d\n", dname, reply->ourp_magic,
1077 PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
1078 GOTO(out, rc = -EPROTO);
1080 rc = object_update_result_data_get(reply, rbuf, 0);
1085 if (rc == -ENOENT) {
1086 dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
1087 obj->opo_non_exist = 1;
1091 oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
1094 CWARN("%s: Fail to add xattr (%s) to cache for "
1095 DFID" (1): rc = %d\n", dname, name,
1096 PFID(lu_object_fid(&dt->do_lu)), rc);
1101 spin_lock(&obj->opo_lock);
1102 if (rc == -ENOENT || rc == -ENODATA) {
1108 spin_unlock(&obj->opo_lock);
1113 reply = req_capsule_server_sized_get(&req->rq_pill,
1114 &RMF_OUT_UPDATE_REPLY,
1115 OUT_UPDATE_REPLY_SIZE);
1116 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
1117 CERROR("%s: Wrong version %x expected %x "DFID": rc = %d\n",
1118 dname, reply->ourp_magic, UPDATE_REPLY_MAGIC,
1119 PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
1121 GOTO(out, rc = -EPROTO);
1124 rc = object_update_result_data_get(reply, rbuf, 0);
1125 if (rc < 0 || rbuf->lb_len == 0) {
1126 if (oxe == NULL && rc == -ENODATA) {
1127 oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
1130 CWARN("%s: Fail to add xattr (%s) to cache for "
1131 DFID" (1): rc = %d\n", dname, name,
1132 PFID(lu_object_fid(&dt->do_lu)), rc);
1138 spin_lock(&obj->opo_lock);
1139 if (unlikely(rc == -ENODATA)) {
1145 spin_unlock(&obj->opo_lock);
1151 /* For detecting EA size. */
1156 oxe = osp_oac_xattr_find_or_add(obj, name, rbuf->lb_len);
1158 CWARN("%s: Fail to add xattr (%s) to "
1159 "cache for "DFID" (2): rc = %d\n",
1160 dname, name, PFID(lu_object_fid(&dt->do_lu)), rc);
1166 oxe = osp_oac_xattr_assignment(obj, oxe, rbuf);
1171 up_read(&obj->opo_invalidate_sem);
1174 if (rc > 0 && buf->lb_buf) {
1175 if (unlikely(buf->lb_len < rbuf->lb_len))
1178 memcpy(buf->lb_buf, rbuf->lb_buf, rbuf->lb_len);
1182 ptlrpc_req_finished(req);
1184 if (update && !IS_ERR(update))
1185 osp_update_request_destroy(env, update);
1188 osp_oac_xattr_put(oxe);
1194 * Implement OSP layer dt_object_operations::do_declare_xattr_set() interface.
1196 * Declare that the caller will set extended attribute to the specified
1199 * If it is non-remote transaction, it will add an OUT_XATTR_SET sub-request
1200 * to the OUT RPC that will be flushed when the transaction start. And if the
1201 * OSP attributes cache is initialized, then check whether the name extended
1202 * attribute entry exists in the cache or not. If yes, replace it; otherwise,
1203 * add the extended attribute to the cache.
1205 * \param[in] env pointer to the thread context
1206 * \param[in] dt pointer to the OSP layer dt_object
1207 * \param[in] buf pointer to the lu_buf to hold the extended attribute
1208 * \param[in] name the name of the extended attribute to be set
1209 * \param[in] flag to indicate the detailed set operation: LU_XATTR_CREATE
1210 * or LU_XATTR_REPLACE or others
1211 * \param[in] th pointer to the transaction handler
1213 * \retval 0 for success
1214 * \retval negative error number on failure
1216 int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
1217 const struct lu_buf *buf, const char *name,
1218 int flag, struct thandle *th)
1220 return osp_trans_update_request_create(th);
1224 * Implement OSP layer dt_object_operations::do_xattr_set() interface.
1226 * Set extended attribute to the specified MDT/OST object.
1228 * Add an OUT_XATTR_SET sub-request into the OUT RPC that will be flushed in
1229 * the transaction stop. And if the OSP attributes cache is initialized, then
1230 * check whether the name extended attribute entry exists in the cache or not.
1231 * If yes, replace it; otherwise, add the extended attribute to the cache.
1233 * \param[in] env pointer to the thread context
1234 * \param[in] dt pointer to the OSP layer dt_object
1235 * \param[in] buf pointer to the lu_buf to hold the extended attribute
1236 * \param[in] name the name of the extended attribute to be set
1237 * \param[in] fl to indicate the detailed set operation: LU_XATTR_CREATE
1238 * or LU_XATTR_REPLACE or others
1239 * \param[in] th pointer to the transaction handler
1241 * \retval 0 for success
1242 * \retval negative error number on failure
1244 int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
1245 const struct lu_buf *buf, const char *name, int fl,
1248 struct osp_object *o = dt2osp_obj(dt);
1249 struct osp_update_request *update;
1250 struct osp_xattr_entry *oxe;
1254 update = thandle_to_osp_update_request(th);
1255 LASSERT(update != NULL);
1257 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
1258 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
1260 rc = OSP_UPDATE_RPC_PACK(env, out_xattr_set_pack, update,
1261 lu_object_fid(&dt->do_lu), buf, name, fl);
1265 /* Do not cache linkEA that may be self-adjusted by peers
1266 * under EA overflow case. */
1267 if (strcmp(name, XATTR_NAME_LINK) == 0) {
1268 oxe = osp_oac_xattr_find(o, name, true);
1270 osp_oac_xattr_put(oxe);
1275 oxe = osp_oac_xattr_find_or_add(o, name, buf->lb_len);
1277 CWARN("%s: cannot cache xattr '%s' of "DFID"\n",
1278 osp_dto2name(o), name, PFID(lu_object_fid(&dt->do_lu)));
1283 oxe = osp_oac_xattr_assignment(o, oxe, buf);
1285 osp_oac_xattr_put(oxe);
1291 * Implement OSP layer dt_object_operations::do_declare_xattr_del() interface.
1293 * Declare that the caller will delete extended attribute on the specified
1296 * If it is non-remote transaction, it will add an OUT_XATTR_DEL sub-request
1297 * to the OUT RPC that will be flushed when the transaction start. And if the
1298 * name extended attribute entry exists in the OSP attributes cache, then remove
1299 * it from the cache.
1301 * \param[in] env pointer to the thread context
1302 * \param[in] dt pointer to the OSP layer dt_object
1303 * \param[in] name the name of the extended attribute to be set
1304 * \param[in] th pointer to the transaction handler
1306 * \retval 0 for success
1307 * \retval negative error number on failure
1309 int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
1310 const char *name, struct thandle *th)
1312 return osp_trans_update_request_create(th);
1316 * Implement OSP layer dt_object_operations::do_xattr_del() interface.
1318 * Delete extended attribute on the specified MDT/OST object.
1320 * If it is remote transaction, it will add an OUT_XATTR_DEL sub-request into
1321 * the OUT RPC that will be flushed when the transaction stop. And if the name
1322 * extended attribute entry exists in the OSP attributes cache, then remove it
1325 * \param[in] env pointer to the thread context
1326 * \param[in] dt pointer to the OSP layer dt_object
1327 * \param[in] name the name of the extended attribute to be set
1328 * \param[in] th pointer to the transaction handler
1330 * \retval 0 for success
1331 * \retval negative error number on failure
1333 int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
1334 const char *name, struct thandle *th)
1336 struct osp_update_request *update;
1337 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1338 struct osp_object *o = dt2osp_obj(dt);
1339 struct osp_xattr_entry *oxe;
1342 update = thandle_to_osp_update_request(th);
1343 LASSERT(update != NULL);
1345 rc = OSP_UPDATE_RPC_PACK(env, out_xattr_del_pack, update, fid, name);
1349 oxe = osp_oac_xattr_find(o, name, true);
1351 /* Drop the ref for entry on list. */
1352 osp_oac_xattr_put(oxe);
1357 void osp_obj_invalidate_cache(struct osp_object *obj)
1359 struct osp_xattr_entry *oxe;
1360 struct osp_xattr_entry *tmp;
1362 spin_lock(&obj->opo_lock);
1363 list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
1365 list_del_init(&oxe->oxe_list);
1366 osp_oac_xattr_put(oxe);
1368 obj->opo_attr.la_valid = 0;
1369 spin_unlock(&obj->opo_lock);
1373 * Implement OSP layer dt_object_operations::do_invalidate() interface.
1375 * Invalidate attributes cached on the specified MDT/OST object.
1377 * \param[in] env pointer to the thread context
1378 * \param[in] dt pointer to the OSP layer dt_object
1380 * \retval 0 for success
1381 * \retval negative error number on failure
1383 int osp_invalidate(const struct lu_env *env, struct dt_object *dt)
1385 struct osp_object *obj = dt2osp_obj(dt);
1388 CDEBUG(D_HA, "Invalidate osp_object "DFID"\n",
1389 PFID(lu_object_fid(&dt->do_lu)));
1391 /* serialize attr/EA set vs. invalidation */
1392 down_write(&obj->opo_invalidate_sem);
1394 /* this should invalidate all in-flights */
1395 atomic_inc(&obj->opo_invalidate_seq);
1397 spin_lock(&obj->opo_lock);
1398 /* do not mark new objects stale */
1399 if (obj->opo_attr.la_valid)
1401 obj->opo_non_exist = 0;
1402 spin_unlock(&obj->opo_lock);
1404 osp_obj_invalidate_cache(obj);
1406 up_write(&obj->opo_invalidate_sem);
1411 bool osp_check_stale(struct dt_object *dt)
1413 struct osp_object *obj = dt2osp_obj(dt);
1415 if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
1418 return obj->opo_stale;
1423 * Implement OSP layer dt_object_operations::do_declare_create() interface.
1425 * Declare that the caller will create the OST object.
1427 * If the transaction is a remote transaction and the FID for the OST-object
1428 * has been assigned already, then handle it as creating (remote) MDT object
1429 * via osp_md_declare_create(). This function is usually used for LFSCK
1430 * to re-create the lost OST object. Otherwise, if it is not replay case, the
1431 * OSP will reserve pre-created object for the subsequent create operation;
1432 * if the MDT side cached pre-created objects are less than some threshold,
1433 * then it will wakeup the pre-create thread.
1435 * \param[in] env pointer to the thread context
1436 * \param[in] dt pointer to the OSP layer dt_object
1437 * \param[in] attr the attribute for the object to be created
1438 * \param[in] hint pointer to the hint for creating the object, such as
1440 * \param[in] dof pointer to the dt_object_format for help the creation
1441 * \param[in] th pointer to the transaction handler
1443 * \retval 0 for success
1444 * \retval negative error number on failure
1446 static int osp_declare_create(const struct lu_env *env, struct dt_object *dt,
1447 struct lu_attr *attr,
1448 struct dt_allocation_hint *hint,
1449 struct dt_object_format *dof, struct thandle *th)
1451 struct osp_thread_info *osi = osp_env_info(env);
1452 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
1453 struct osp_object *o = dt2osp_obj(dt);
1454 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1455 struct thandle *local_th;
1460 if (is_only_remote_trans(th) && !fid_is_zero(fid)) {
1461 LASSERT(fid_is_sane(fid));
1463 rc = osp_md_declare_create(env, dt, attr, hint, dof, th);
1468 /* should happen to non-0 OSP only so that at least one object
1469 * has been already declared in the scenario and LOD should
1471 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL) && d->opd_index == 1)
1474 LASSERT(d->opd_last_used_oid_file);
1477 * There can be gaps in precreated ids and record to unlink llog
1478 * XXX: we do not handle gaps yet, implemented before solution
1479 * was found to be racy, so we disabled that. there is no
1480 * point in making useless but expensive llog declaration.
1482 /* rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th); */
1484 local_th = osp_get_storage_thandle(env, th, d);
1485 if (IS_ERR(local_th))
1486 RETURN(PTR_ERR(local_th));
1488 if (unlikely(!fid_is_zero(fid))) {
1489 /* replay case: caller knows fid */
1490 osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, NULL,
1492 rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
1493 &osi->osi_lb, osi->osi_off,
1499 * in declaration we need to reserve object so that we don't block
1500 * awaiting precreation RPC to complete
1502 rc = osp_precreate_reserve(env, d, !hint || hint->dah_can_block);
1504 * we also need to declare update to local "last used id" file for
1505 * recovery if object isn't used for a reason, we need to release
1506 * reservation, this can be made in osd_object_release()
1509 /* mark id is reserved: in create we don't want to talk
1511 LASSERT(o->opo_reserved == 0);
1512 o->opo_reserved = 1;
1514 /* common for all OSPs file hystorically */
1515 osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, NULL,
1517 rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
1518 &osi->osi_lb, osi->osi_off,
1521 /* not needed in the cache anymore */
1522 set_bit(LU_OBJECT_HEARD_BANSHEE,
1523 &dt->do_lu.lo_header->loh_flags);
1529 * Implement OSP layer dt_object_operations::do_create() interface.
1531 * Create the OST object.
1533 * If the transaction is a remote transaction and the FID for the OST-object
1534 * has been assigned already, then handle it as handling MDT object via the
1535 * osp_md_create(). For other cases, the OSP will assign FID to the
1536 * object to be created, and update last_used Object ID (OID) file.
1538 * \param[in] env pointer to the thread context
1539 * \param[in] dt pointer to the OSP layer dt_object
1540 * \param[in] attr the attribute for the object to be created
1541 * \param[in] hint pointer to the hint for creating the object, such as
1543 * \param[in] dof pointer to the dt_object_format for help the creation
1544 * \param[in] th pointer to the transaction handler
1546 * \retval 0 for success
1547 * \retval negative error number on failure
1549 static int osp_create(const struct lu_env *env, struct dt_object *dt,
1550 struct lu_attr *attr, struct dt_allocation_hint *hint,
1551 struct dt_object_format *dof, struct thandle *th)
1553 struct osp_thread_info *osi = osp_env_info(env);
1554 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
1555 struct osp_object *o = dt2osp_obj(dt);
1557 struct lu_fid *fid = &osi->osi_fid;
1558 struct thandle *local_th;
1561 if (is_only_remote_trans(th) &&
1562 !fid_is_zero(lu_object_fid(&dt->do_lu))) {
1563 LASSERT(fid_is_sane(lu_object_fid(&dt->do_lu)));
1565 rc = osp_md_create(env, dt, attr, hint, dof, th);
1567 o->opo_non_exist = 0;
1572 o->opo_non_exist = 0;
1573 if (o->opo_reserved) {
1574 /* regular case, fid is assigned holding transaction open */
1575 osp_object_assign_fid(env, d, o);
1578 memcpy(fid, lu_object_fid(&dt->do_lu), sizeof(*fid));
1580 LASSERTF(fid_is_sane(fid), "fid for osp_object %p is insane"DFID"!\n",
1583 if (!o->opo_reserved) {
1584 /* special case, id was assigned outside of transaction
1585 * see comments in osp_declare_attr_set */
1586 LASSERT(d->opd_pre != NULL);
1587 spin_lock(&d->opd_pre_lock);
1588 osp_update_last_fid(d, fid);
1589 spin_unlock(&d->opd_pre_lock);
1592 CDEBUG(D_INODE, "fid for osp_object %p is "DFID"\n", o, PFID(fid));
1594 /* If the precreate ends, it means it will be ready to rollover to
1595 * the new sequence soon, all the creation should be synchronized,
1596 * otherwise during replay, the replay fid will be inconsistent with
1597 * last_used/create fid */
1598 if (osp_precreate_end_seq(env, d) && osp_is_fid_client(d))
1601 local_th = osp_get_storage_thandle(env, th, d);
1602 if (IS_ERR(local_th))
1603 RETURN(PTR_ERR(local_th));
1605 * it's OK if the import is inactive by this moment - id was created
1606 * by OST earlier, we just need to maintain it consistently on the disk
1607 * once import is reconnected, OSP will claim this and other objects
1608 * used and OST either keep them, if they exist or recreate
1611 /* we might have lost precreated objects */
1612 if (unlikely(d->opd_gap_count) > 0) {
1613 LASSERT(d->opd_pre != NULL);
1614 spin_lock(&d->opd_pre_lock);
1615 if (d->opd_gap_count > 0) {
1616 int count = d->opd_gap_count;
1618 rc = ostid_set_id(&osi->osi_oi,
1619 fid_oid(&d->opd_gap_start_fid));
1621 spin_unlock(&d->opd_pre_lock);
1624 d->opd_gap_count = 0;
1625 spin_unlock(&d->opd_pre_lock);
1627 CDEBUG(D_HA, "Writing gap "DFID"+%d in llog\n",
1628 PFID(&d->opd_gap_start_fid), count);
1629 /* real gap handling is disabled intil ORI-692 will be
1630 * fixed, now we only report gaps */
1632 spin_unlock(&d->opd_pre_lock);
1636 /* Only need update last_used oid file, seq file will only be update
1637 * during seq rollover */
1638 osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off,
1639 &d->opd_last_id, d->opd_index);
1641 rc = dt_record_write(env, d->opd_last_used_oid_file, &osi->osi_lb,
1642 &osi->osi_off, local_th);
1644 CDEBUG(D_HA, "%s: Wrote last used FID: "DFID", index %d: %d\n",
1645 d->opd_obd->obd_name, PFID(fid), d->opd_index, rc);
1651 * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
1653 * Declare that the caller will destroy the specified OST object.
1655 * The OST object destroy will be handled via llog asynchronously. This
1656 * function will declare the credits for generating MDS_UNLINK64_REC llog.
1658 * \param[in] env pointer to the thread context
1659 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
1660 * \param[in] th pointer to the transaction handler
1662 * \retval 0 for success
1663 * \retval negative error number on failure
1665 int osp_declare_destroy(const struct lu_env *env, struct dt_object *dt,
1668 struct osp_object *o = dt2osp_obj(dt);
1669 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1674 LASSERT(!osp->opd_connect_mdt);
1676 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ))
1677 rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th);
1683 * Implement OSP layer dt_object_operations::do_destroy() interface.
1685 * Destroy the specified OST object.
1687 * The OSP generates a MDS_UNLINK64_REC record in the llog. There
1688 * will be some dedicated thread to handle the llog asynchronously.
1690 * It also marks the object as non-cached.
1692 * \param[in] env pointer to the thread context
1693 * \param[in] dt pointer to the OSP layer dt_object to be destroyed
1694 * \param[in] th pointer to the transaction handler
1696 * \retval 0 for success
1697 * \retval negative error number on failure
1699 static int osp_destroy(const struct lu_env *env, struct dt_object *dt,
1702 struct osp_object *o = dt2osp_obj(dt);
1703 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
1708 o->opo_non_exist = 1;
1710 LASSERT(!osp->opd_connect_mdt);
1712 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ)) {
1713 /* once transaction is committed put proper command on
1714 * the queue going to our OST. */
1715 rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
1720 /* not needed in cache any more */
1721 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
1726 static int osp_orphan_index_lookup(const struct lu_env *env,
1727 struct dt_object *dt,
1729 const struct dt_key *key)
1734 static int osp_orphan_index_declare_insert(const struct lu_env *env,
1735 struct dt_object *dt,
1736 const struct dt_rec *rec,
1737 const struct dt_key *key,
1738 struct thandle *handle)
1743 static int osp_orphan_index_insert(const struct lu_env *env,
1744 struct dt_object *dt,
1745 const struct dt_rec *rec,
1746 const struct dt_key *key,
1747 struct thandle *handle)
1752 static int osp_orphan_index_declare_delete(const struct lu_env *env,
1753 struct dt_object *dt,
1754 const struct dt_key *key,
1755 struct thandle *handle)
1760 static int osp_orphan_index_delete(const struct lu_env *env,
1761 struct dt_object *dt,
1762 const struct dt_key *key,
1763 struct thandle *handle)
1769 * Initialize the OSP layer index iteration.
1771 * \param[in] env pointer to the thread context
1772 * \param[in] dt pointer to the index object to be iterated
1773 * \param[in] attr unused
1775 * \retval pointer to the iteration structure
1776 * \retval negative error number on failure
1778 struct dt_it *osp_it_init(const struct lu_env *env, struct dt_object *dt,
1785 return ERR_PTR(-ENOMEM);
1787 it->ooi_pos_ent = -1;
1789 it->ooi_attr = attr;
1791 return (struct dt_it *)it;
1795 * Finalize the OSP layer index iteration.
1797 * \param[in] env pointer to the thread context
1798 * \param[in] di pointer to the iteration structure
1800 void osp_it_fini(const struct lu_env *env, struct dt_it *di)
1802 struct osp_it *it = (struct osp_it *)di;
1803 struct page **pages = it->ooi_pages;
1804 int npages = it->ooi_total_npages;
1807 if (pages != NULL) {
1808 for (i = 0; i < npages; i++) {
1809 if (pages[i] != NULL) {
1810 if (pages[i] == it->ooi_cur_page) {
1812 it->ooi_cur_page = NULL;
1814 __free_page(pages[i]);
1817 OBD_FREE_PTR_ARRAY(pages, npages);
1823 * Get more records for the iteration from peer.
1825 * The new records will be filled in an array of pages. The OSP side
1826 * allows 1MB bulk data to be transferred.
1828 * \param[in] env pointer to the thread context
1829 * \param[in] it pointer to the iteration structure
1831 * \retval 0 for success
1832 * \retval negative error number on failure
1834 static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
1836 struct lu_device *dev = it->ooi_obj->do_lu.lo_dev;
1837 struct osp_device *osp = lu2osp_dev(dev);
1838 struct page **pages;
1839 struct ptlrpc_request *req = NULL;
1840 struct ptlrpc_bulk_desc *desc;
1841 struct idx_info *ii;
1848 npages = min_t(unsigned int, OFD_MAX_BRW_SIZE, 1 << 20);
1849 npages /= PAGE_SIZE;
1851 OBD_ALLOC_PTR_ARRAY(pages, npages);
1855 it->ooi_pages = pages;
1856 it->ooi_total_npages = npages;
1857 for (i = 0; i < npages; i++) {
1858 pages[i] = alloc_page(GFP_NOFS);
1859 if (pages[i] == NULL)
1863 req = ptlrpc_request_alloc(osp->opd_obd->u.cli.cl_import,
1868 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, OBD_IDX_READ);
1870 ptlrpc_request_free(req);
1874 osp_set_req_replay(osp, req);
1875 req->rq_request_portal = OUT_PORTAL;
1876 ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
1877 memset(ii, 0, sizeof(*ii));
1878 if (fid_is_last_id(lu_object_fid(&it->ooi_obj->do_lu))) {
1879 /* LFSCK will iterate orphan object[FID_SEQ_LAYOUT_BTREE,
1880 * ost_index, 0] with LAST_ID FID, so it needs to replace
1881 * the FID with orphan FID here */
1882 ii->ii_fid.f_seq = FID_SEQ_LAYOUT_RBTREE;
1883 ii->ii_fid.f_oid = osp->opd_index;
1884 ii->ii_fid.f_ver = 0;
1885 ii->ii_flags = II_FL_NOHASH;
1886 ii->ii_attrs = osp_dev2node(osp);
1888 ii->ii_fid = *lu_object_fid(&it->ooi_obj->do_lu);
1889 ii->ii_flags = II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
1891 ii->ii_attrs = it->ooi_attr;
1893 ii->ii_magic = IDX_INFO_MAGIC;
1894 ii->ii_count = npages * LU_PAGE_COUNT;
1895 ii->ii_hash_start = it->ooi_next;
1897 ptlrpc_at_set_req_timeout(req);
1899 desc = ptlrpc_prep_bulk_imp(req, npages, 1,
1900 PTLRPC_BULK_PUT_SINK,
1902 &ptlrpc_bulk_kiov_pin_ops);
1904 GOTO(out, rc = -ENOMEM);
1906 for (i = 0; i < npages; i++)
1907 desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
1910 ptlrpc_request_set_replen(req);
1911 rc = ptlrpc_queue_wait(req);
1915 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1916 req->rq_bulk->bd_nob_transferred);
1921 ii = req_capsule_server_get(&req->rq_pill, &RMF_IDX_INFO);
1922 if (ii->ii_magic != IDX_INFO_MAGIC)
1923 GOTO(out, rc = -EPROTO);
1925 npages = (ii->ii_count + LU_PAGE_COUNT - 1) >>
1926 (PAGE_SHIFT - LU_PAGE_SHIFT);
1927 if (npages > it->ooi_total_npages) {
1928 CERROR("%s: returned more pages than expected, %u > %u\n",
1929 osp->opd_obd->obd_name, npages, it->ooi_total_npages);
1930 GOTO(out, rc = -EINVAL);
1933 it->ooi_rec_size = ii->ii_recsize;
1934 it->ooi_valid_npages = npages;
1935 if (req_capsule_rep_need_swab(&req->rq_pill))
1938 it->ooi_next = ii->ii_hash_end;
1941 ptlrpc_req_finished(req);
1947 * Move the iteration cursor to the next lu_page.
1949 * One system page (PAGE_SIZE) may contain multiple lu_page (4KB),
1950 * that depends on the LU_PAGE_COUNT. If it is not the last lu_page
1951 * in current system page, then move the iteration cursor to the next
1952 * lu_page in current system page. Otherwise, if there are more system
1953 * pages in the cache, then move the iteration cursor to the next system
1954 * page. If all the cached records (pages) have been iterated, then fetch
1955 * more records via osp_it_fetch().
1957 * \param[in] env pointer to the thread context
1958 * \param[in] di pointer to the iteration structure
1960 * \retval positive for end of the directory
1961 * \retval 0 for success
1962 * \retval negative error number on failure
1964 int osp_it_next_page(const struct lu_env *env, struct dt_it *di)
1966 struct osp_it *it = (struct osp_it *)di;
1967 struct lu_idxpage *idxpage;
1968 struct page **pages;
1974 idxpage = it->ooi_cur_idxpage;
1975 if (idxpage != NULL) {
1976 if (idxpage->lip_nr == 0)
1979 if (it->ooi_pos_ent < idxpage->lip_nr) {
1980 CDEBUG(D_INFO, "ooi_pos %d nr %d\n",
1981 (int)it->ooi_pos_ent, (int)idxpage->lip_nr);
1984 it->ooi_cur_idxpage = NULL;
1985 it->ooi_pos_lu_page++;
1988 if (it->ooi_pos_lu_page < LU_PAGE_COUNT) {
1989 it->ooi_cur_idxpage = (void *)it->ooi_cur_page +
1990 LU_PAGE_SIZE * it->ooi_pos_lu_page;
1992 lustre_swab_lip_header(it->ooi_cur_idxpage);
1993 if (it->ooi_cur_idxpage->lip_magic != LIP_MAGIC) {
1994 struct osp_device *osp =
1995 lu2osp_dev(it->ooi_obj->do_lu.lo_dev);
1997 CERROR("%s: invalid magic (%x != %x) for page "
1998 "%d/%d while read layout orphan index\n",
1999 osp->opd_obd->obd_name,
2000 it->ooi_cur_idxpage->lip_magic,
2001 LIP_MAGIC, it->ooi_pos_page,
2002 it->ooi_pos_lu_page);
2003 /* Skip this lu_page next time. */
2004 it->ooi_pos_ent = idxpage->lip_nr - 1;
2007 it->ooi_pos_ent = -1;
2011 kunmap(it->ooi_cur_page);
2012 it->ooi_cur_page = NULL;
2016 pages = it->ooi_pages;
2017 if (it->ooi_pos_page < it->ooi_valid_npages) {
2018 it->ooi_cur_page = kmap(pages[it->ooi_pos_page]);
2019 it->ooi_pos_lu_page = 0;
2023 for (i = 0; i < it->ooi_total_npages; i++) {
2024 if (pages[i] != NULL)
2025 __free_page(pages[i]);
2027 OBD_FREE_PTR_ARRAY(pages, it->ooi_total_npages);
2029 it->ooi_pos_page = 0;
2030 it->ooi_total_npages = 0;
2031 it->ooi_valid_npages = 0;
2034 it->ooi_cur_page = NULL;
2035 it->ooi_cur_idxpage = NULL;
2036 it->ooi_pages = NULL;
2039 if (it->ooi_next == II_END_OFF)
2042 rc = osp_it_fetch(env, it);
2050 * Move the iteration cursor to the next record.
2052 * If there are more records in the lu_page, then move the iteration
2053 * cursor to the next record directly. Otherwise, move the iteration
2054 * cursor to the record in the next lu_page via osp_it_next_page()
2056 * \param[in] env pointer to the thread context
2057 * \param[in] di pointer to the iteration structure
2059 * \retval positive for end of the directory
2060 * \retval 0 for success
2061 * \retval negative error number on failure
2063 static int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
2065 struct osp_it *it = (struct osp_it *)di;
2066 struct lu_idxpage *idxpage;
2071 idxpage = it->ooi_cur_idxpage;
2072 if (idxpage != NULL) {
2073 if (idxpage->lip_nr == 0)
2077 if (it->ooi_pos_ent < idxpage->lip_nr) {
2078 if (it->ooi_rec_size ==
2079 sizeof(struct lu_orphan_rec_v3)) {
2081 (struct lu_orphan_ent_v3 *)idxpage->lip_entries+
2084 lustre_swab_orphan_ent_v3(it->ooi_ent);
2085 } else if (it->ooi_rec_size ==
2086 sizeof(struct lu_orphan_rec_v2)) {
2088 (struct lu_orphan_ent_v2 *)idxpage->lip_entries+
2091 lustre_swab_orphan_ent_v2(it->ooi_ent);
2094 (struct lu_orphan_ent *)idxpage->lip_entries +
2097 lustre_swab_orphan_ent(it->ooi_ent);
2103 rc = osp_it_next_page(env, di);
2110 int osp_it_get(const struct lu_env *env, struct dt_it *di,
2111 const struct dt_key *key)
2116 void osp_it_put(const struct lu_env *env, struct dt_it *di)
2120 static struct dt_key *osp_orphan_it_key(const struct lu_env *env,
2121 const struct dt_it *di)
2123 struct osp_it *it = (struct osp_it *)di;
2124 struct lu_orphan_ent *ent = (struct lu_orphan_ent *)it->ooi_ent;
2126 if (likely(ent != NULL))
2127 return (struct dt_key *)(&ent->loe_key);
2132 static int osp_orphan_it_key_size(const struct lu_env *env,
2133 const struct dt_it *di)
2135 return sizeof(struct lu_fid);
2138 static int osp_orphan_it_rec(const struct lu_env *env, const struct dt_it *di,
2139 struct dt_rec *rec, __u32 attr)
2141 struct osp_it *it = (struct osp_it *)di;
2143 if (likely(it->ooi_ent)) {
2144 if (it->ooi_rec_size == sizeof(struct lu_orphan_rec_v3)) {
2145 struct lu_orphan_ent_v3 *ent =
2146 (struct lu_orphan_ent_v3 *)it->ooi_ent;
2148 *(struct lu_orphan_rec_v3 *)rec = ent->loe_rec;
2149 } else if (it->ooi_rec_size ==
2150 sizeof(struct lu_orphan_rec_v2)) {
2151 struct lu_orphan_ent_v2 *ent =
2152 (struct lu_orphan_ent_v2 *)it->ooi_ent;
2154 *(struct lu_orphan_rec_v2 *)rec = ent->loe_rec;
2156 struct lu_orphan_ent *ent =
2157 (struct lu_orphan_ent *)it->ooi_ent;
2159 *(struct lu_orphan_rec *)rec = ent->loe_rec;
2167 __u64 osp_it_store(const struct lu_env *env, const struct dt_it *di)
2169 struct osp_it *it = (struct osp_it *)di;
2171 return it->ooi_next;
2175 * Locate the iteration cursor to the specified position (cookie).
2177 * \param[in] env pointer to the thread context
2178 * \param[in] di pointer to the iteration structure
2179 * \param[in] hash the specified position
2181 * \retval positive number for locating to the exactly position
2183 * \retval 0 for arriving at the end of the iteration
2184 * \retval negative error number on failure
2186 int osp_orphan_it_load(const struct lu_env *env, const struct dt_it *di,
2189 struct osp_it *it = (struct osp_it *)di;
2192 it->ooi_next = hash;
2193 rc = osp_orphan_it_next(env, (struct dt_it *)di);
2203 int osp_it_key_rec(const struct lu_env *env, const struct dt_it *di,
2209 static const struct dt_index_operations osp_orphan_index_ops = {
2210 .dio_lookup = osp_orphan_index_lookup,
2211 .dio_declare_insert = osp_orphan_index_declare_insert,
2212 .dio_insert = osp_orphan_index_insert,
2213 .dio_declare_delete = osp_orphan_index_declare_delete,
2214 .dio_delete = osp_orphan_index_delete,
2216 .init = osp_it_init,
2217 .fini = osp_it_fini,
2218 .next = osp_orphan_it_next,
2221 .key = osp_orphan_it_key,
2222 .key_size = osp_orphan_it_key_size,
2223 .rec = osp_orphan_it_rec,
2224 .store = osp_it_store,
2225 .load = osp_orphan_it_load,
2226 .key_rec = osp_it_key_rec,
2231 * Implement OSP layer dt_object_operations::do_index_try() interface.
2233 * Negotiate the index type.
2235 * If the target index is an IDIF object, then use osp_orphan_index_ops.
2236 * Otherwise, assign osp_md_index_ops to the dt_object::do_index_ops.
2237 * (\see lustre/include/lustre_fid.h for IDIF.)
2239 * \param[in] env pointer to the thread context
2240 * \param[in] dt pointer to the OSP layer dt_object
2241 * \param[in] feat unused
2243 * \retval 0 for success
2245 static int osp_index_try(const struct lu_env *env,
2246 struct dt_object *dt,
2247 const struct dt_index_features *feat)
2249 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2251 if (fid_is_last_id(fid) && fid_is_idif(fid))
2252 dt->do_index_ops = &osp_orphan_index_ops;
2254 dt->do_index_ops = &osp_md_index_ops;
2258 static const struct dt_object_operations osp_obj_ops = {
2259 .do_declare_attr_get = osp_declare_attr_get,
2260 .do_attr_get = osp_attr_get,
2261 .do_declare_attr_set = osp_declare_attr_set,
2262 .do_attr_set = osp_attr_set,
2263 .do_declare_xattr_get = osp_declare_xattr_get,
2264 .do_xattr_get = osp_xattr_get,
2265 .do_declare_xattr_set = osp_declare_xattr_set,
2266 .do_xattr_set = osp_xattr_set,
2267 .do_declare_create = osp_declare_create,
2268 .do_create = osp_create,
2269 .do_declare_destroy = osp_declare_destroy,
2270 .do_destroy = osp_destroy,
2271 .do_index_try = osp_index_try,
2275 * Implement OSP layer lu_object_operations::loo_object_init() interface.
2277 * Initialize the object.
2279 * If it is a remote MDT object, then call do_attr_get() to fetch
2280 * the attribute from the peer.
2282 * \param[in] env pointer to the thread context
2283 * \param[in] o pointer to the OSP layer lu_object
2284 * \param[in] conf unused
2286 * \retval 0 for success
2287 * \retval negative error number on failure
2289 static int osp_object_init(const struct lu_env *env, struct lu_object *o,
2290 const struct lu_object_conf *conf)
2292 struct osp_object *po = lu2osp_obj(o);
2297 o->lo_header->loh_attr |= LOHA_REMOTE;
2299 if (is_ost_obj(o)) {
2300 po->opo_obj.do_ops = &osp_obj_ops;
2302 struct lu_attr *la = &osp_env_info(env)->osi_attr;
2304 po->opo_obj.do_ops = &osp_md_obj_ops;
2305 po->opo_obj.do_body_ops = &osp_md_body_ops;
2307 if (conf != NULL && conf->loc_flags & LOC_F_NEW) {
2308 po->opo_non_exist = 1;
2310 rc = po->opo_obj.do_ops->do_attr_get(env, lu2dt_obj(o),
2313 o->lo_header->loh_attr |=
2314 LOHA_EXISTS | (la->la_mode & S_IFMT);
2315 if (rc == -ENOENT) {
2316 po->opo_non_exist = 1;
2325 static void osp_object_free_rcu(struct rcu_head *head)
2327 struct osp_object *obj = container_of(head, struct osp_object,
2328 opo_header.loh_rcu);
2330 kmem_cache_free(osp_object_kmem, obj);
2334 * Implement OSP layer lu_object_operations::loo_object_free() interface.
2336 * Finalize the object.
2338 * If the OSP object has attributes cache, then destroy the cache.
2339 * Free the object finally.
2341 * \param[in] env pointer to the thread context
2342 * \param[in] o pointer to the OSP layer lu_object
2344 static void osp_object_free(const struct lu_env *env, struct lu_object *o)
2346 struct osp_object *obj = lu2osp_obj(o);
2347 struct lu_object_header *h = o->lo_header;
2348 struct osp_xattr_entry *oxe;
2349 struct osp_xattr_entry *tmp;
2352 dt_object_fini(&obj->opo_obj);
2354 lu_object_header_fini(h);
2355 list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
2356 list_del_init(&oxe->oxe_list);
2357 count = atomic_read(&oxe->oxe_ref);
2358 LASSERTF(count == 1,
2359 "Still has %d users on the xattr entry %.*s\n",
2360 count-1, (int)oxe->oxe_namelen, oxe->oxe_name);
2362 osp_oac_xattr_free(oxe);
2364 OBD_FREE_PRE(obj, sizeof(*obj), "slab-freed");
2365 call_rcu(&obj->opo_header.loh_rcu, osp_object_free_rcu);
2369 * Implement OSP layer lu_object_operations::loo_object_release() interface.
2371 * Cleanup (not free) the object.
2373 * If it is a reserved object but failed to be created, or it is an OST
2374 * object, then mark the object as non-cached.
2376 * \param[in] env pointer to the thread context
2377 * \param[in] o pointer to the OSP layer lu_object
2379 static void osp_object_release(const struct lu_env *env, struct lu_object *o)
2381 struct osp_object *po = lu2osp_obj(o);
2382 struct osp_device *d = lu2osp_dev(o->lo_dev);
2387 * release reservation if object was declared but not created
2388 * this may require lu_object_put() in LOD
2390 if (unlikely(po->opo_reserved)) {
2391 LASSERT(d->opd_pre != NULL);
2392 LASSERT(d->opd_pre_reserved > 0);
2393 spin_lock(&d->opd_pre_lock);
2394 d->opd_pre_reserved--;
2395 spin_unlock(&d->opd_pre_lock);
2398 * Check that osp_precreate_cleanup_orphans is not blocked
2399 * due to opd_pre_reserved > 0.
2401 if (unlikely(d->opd_pre_reserved == 0 &&
2402 (d->opd_pre_recovering || d->opd_pre_status)))
2403 wake_up(&d->opd_pre_waitq);
2405 /* not needed in cache any more */
2406 set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
2410 /* XXX: Currently, NOT cache OST-object on MDT because:
2411 * 1. it is not often accessed on MDT.
2412 * 2. avoid up layer (such as LFSCK) to load too many
2413 * once-used OST-objects. */
2414 set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
2419 static int osp_object_print(const struct lu_env *env, void *cookie,
2420 lu_printer_t p, const struct lu_object *l)
2422 const struct osp_object *o = lu2osp_obj((struct lu_object *)l);
2424 return (*p)(env, cookie, LUSTRE_OSP_NAME"-object@%p", o);
2427 static int osp_object_invariant(const struct lu_object *o)
2432 const struct lu_object_operations osp_lu_obj_ops = {
2433 .loo_object_init = osp_object_init,
2434 .loo_object_free = osp_object_free,
2435 .loo_object_release = osp_object_release,
2436 .loo_object_print = osp_object_print,
2437 .loo_object_invariant = osp_object_invariant