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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osp/osp_object.c
38 * Lustre OST Proxy Device
40 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41 * Author: Mikhail Pershin <mike.tappro@intel.com>
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include "osp_internal.h"
48 static inline __u32 osp_dev2node(struct osp_device *osp)
50 return osp->opd_storage->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
53 static inline bool is_ost_obj(struct lu_object *lo)
55 return !lu2osp_dev(lo->lo_dev)->opd_connect_mdt;
58 static void osp_object_assign_fid(const struct lu_env *env,
59 struct osp_device *d, struct osp_object *o)
61 struct osp_thread_info *osi = osp_env_info(env);
63 LASSERT(fid_is_zero(lu_object_fid(&o->opo_obj.do_lu)));
64 LASSERT(o->opo_reserved);
67 osp_precreate_get_fid(env, d, &osi->osi_fid);
69 lu_object_assign_fid(env, &o->opo_obj.do_lu, &osi->osi_fid);
72 static int osp_oac_init(struct osp_object *obj)
74 struct osp_object_attr *ooa;
80 INIT_LIST_HEAD(&ooa->ooa_xattr_list);
81 spin_lock(&obj->opo_lock);
82 if (likely(obj->opo_ooa == NULL)) {
84 spin_unlock(&obj->opo_lock);
86 spin_unlock(&obj->opo_lock);
93 static struct osp_xattr_entry *
94 osp_oac_xattr_find_locked(struct osp_object_attr *ooa,
95 const char *name, size_t namelen)
97 struct osp_xattr_entry *oxe;
99 list_for_each_entry(oxe, &ooa->ooa_xattr_list, oxe_list) {
100 if (namelen == oxe->oxe_namelen &&
101 strncmp(name, oxe->oxe_buf, namelen) == 0)
108 static struct osp_xattr_entry *osp_oac_xattr_find(struct osp_object *obj,
109 const char *name, bool unlink)
111 struct osp_xattr_entry *oxe = NULL;
113 spin_lock(&obj->opo_lock);
114 if (obj->opo_ooa != NULL) {
115 oxe = osp_oac_xattr_find_locked(obj->opo_ooa, name,
119 list_del_init(&oxe->oxe_list);
121 atomic_inc(&oxe->oxe_ref);
124 spin_unlock(&obj->opo_lock);
129 static struct osp_xattr_entry *
130 osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
132 struct osp_object_attr *ooa = obj->opo_ooa;
133 struct osp_xattr_entry *oxe;
134 struct osp_xattr_entry *tmp = NULL;
135 size_t namelen = strlen(name);
136 size_t size = sizeof(*oxe) + namelen + 1 + len;
138 LASSERT(ooa != NULL);
140 oxe = osp_oac_xattr_find(obj, name, false);
144 OBD_ALLOC(oxe, size);
145 if (unlikely(oxe == NULL))
148 INIT_LIST_HEAD(&oxe->oxe_list);
149 oxe->oxe_buflen = size;
150 oxe->oxe_namelen = namelen;
151 memcpy(oxe->oxe_buf, name, namelen);
152 oxe->oxe_value = oxe->oxe_buf + namelen + 1;
153 /* One ref is for the caller, the other is for the entry on the list. */
154 atomic_set(&oxe->oxe_ref, 2);
156 spin_lock(&obj->opo_lock);
157 tmp = osp_oac_xattr_find_locked(ooa, name, namelen);
159 list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
161 atomic_inc(&tmp->oxe_ref);
162 spin_unlock(&obj->opo_lock);
172 static struct osp_xattr_entry *
173 osp_oac_xattr_replace(struct osp_object *obj,
174 struct osp_xattr_entry **poxe, size_t len)
176 struct osp_object_attr *ooa = obj->opo_ooa;
177 struct osp_xattr_entry *oxe;
178 size_t namelen = (*poxe)->oxe_namelen;
179 size_t size = sizeof(*oxe) + namelen + 1 + len;
181 LASSERT(ooa != NULL);
183 OBD_ALLOC(oxe, size);
184 if (unlikely(oxe == NULL))
187 INIT_LIST_HEAD(&oxe->oxe_list);
188 oxe->oxe_buflen = size;
189 oxe->oxe_namelen = namelen;
190 memcpy(oxe->oxe_buf, (*poxe)->oxe_buf, namelen);
191 oxe->oxe_value = oxe->oxe_buf + namelen + 1;
192 /* One ref is for the caller, the other is for the entry on the list. */
193 atomic_set(&oxe->oxe_ref, 2);
195 spin_lock(&obj->opo_lock);
196 *poxe = osp_oac_xattr_find_locked(ooa, oxe->oxe_buf, namelen);
197 LASSERT(*poxe != NULL);
199 list_del_init(&(*poxe)->oxe_list);
200 list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
201 spin_unlock(&obj->opo_lock);
206 static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
208 if (atomic_dec_and_test(&oxe->oxe_ref)) {
209 LASSERT(list_empty(&oxe->oxe_list));
211 OBD_FREE(oxe, oxe->oxe_buflen);
215 static int osp_get_attr_from_reply(const struct lu_env *env,
216 struct object_update_reply *reply,
217 struct ptlrpc_request *req,
218 struct lu_attr *attr,
219 struct osp_object *obj, int index)
221 struct osp_thread_info *osi = osp_env_info(env);
222 struct lu_buf *rbuf = &osi->osi_lb2;
223 struct obdo *lobdo = &osi->osi_obdo;
227 rc = object_update_result_data_get(reply, rbuf, index);
231 wobdo = rbuf->lb_buf;
232 if (rbuf->lb_len != sizeof(*wobdo))
235 LASSERT(req != NULL);
236 if (ptlrpc_req_need_swab(req))
237 lustre_swab_obdo(wobdo);
239 lustre_get_wire_obdo(NULL, lobdo, wobdo);
240 spin_lock(&obj->opo_lock);
241 if (obj->opo_ooa != NULL) {
242 la_from_obdo(&obj->opo_ooa->ooa_attr, lobdo, lobdo->o_valid);
244 *attr = obj->opo_ooa->ooa_attr;
246 LASSERT(attr != NULL);
248 la_from_obdo(attr, lobdo, lobdo->o_valid);
250 spin_unlock(&obj->opo_lock);
255 static int osp_attr_get_interpterer(const struct lu_env *env,
256 struct object_update_reply *reply,
257 struct ptlrpc_request *req,
258 struct osp_object *obj,
259 void *data, int index, int rc)
261 struct lu_attr *attr = data;
263 LASSERT(obj->opo_ooa != NULL);
266 osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
267 obj->opo_non_exist = 0;
269 return osp_get_attr_from_reply(env, reply, req, NULL, obj,
273 osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
274 obj->opo_non_exist = 1;
277 spin_lock(&obj->opo_lock);
279 spin_unlock(&obj->opo_lock);
285 static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt,
286 struct lustre_capa *capa)
288 struct osp_object *obj = dt2osp_obj(dt);
289 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
292 if (obj->opo_ooa == NULL) {
293 rc = osp_oac_init(obj);
298 mutex_lock(&osp->opd_async_requests_mutex);
299 rc = osp_insert_async_request(env, OUT_ATTR_GET, obj, 0, NULL, NULL,
300 &obj->opo_ooa->ooa_attr,
301 osp_attr_get_interpterer);
302 mutex_unlock(&osp->opd_async_requests_mutex);
307 int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
308 struct lu_attr *attr, struct lustre_capa *capa)
310 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
311 struct osp_object *obj = dt2osp_obj(dt);
312 struct dt_device *dev = &osp->opd_dt_dev;
313 struct dt_update_request *update;
314 struct object_update_reply *reply;
315 struct ptlrpc_request *req = NULL;
319 if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
322 if (obj->opo_ooa != NULL) {
323 spin_lock(&obj->opo_lock);
324 if (obj->opo_ooa->ooa_attr.la_valid != 0) {
325 *attr = obj->opo_ooa->ooa_attr;
326 spin_unlock(&obj->opo_lock);
330 spin_unlock(&obj->opo_lock);
333 update = out_create_update_req(dev);
335 RETURN(PTR_ERR(update));
337 rc = out_insert_update(env, update, OUT_ATTR_GET,
338 lu_object_fid(&dt->do_lu), 0, NULL, NULL);
340 CERROR("%s: Insert update error "DFID": rc = %d\n",
341 dev->dd_lu_dev.ld_obd->obd_name,
342 PFID(lu_object_fid(&dt->do_lu)), rc);
347 rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import, update, &req);
350 osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
351 obj->opo_non_exist = 1;
353 CERROR("%s:osp_attr_get update error "DFID": rc = %d\n",
354 dev->dd_lu_dev.ld_obd->obd_name,
355 PFID(lu_object_fid(&dt->do_lu)), rc);
361 osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
362 obj->opo_non_exist = 0;
363 reply = req_capsule_server_sized_get(&req->rq_pill,
364 &RMF_OUT_UPDATE_REPLY,
365 OUT_UPDATE_REPLY_SIZE);
366 if (reply == NULL || reply->ourp_magic != UPDATE_REPLY_MAGIC)
367 GOTO(out, rc = -EPROTO);
369 rc = osp_get_attr_from_reply(env, reply, req, attr, obj, 0);
377 ptlrpc_req_finished(req);
379 out_destroy_update_req(update);
384 static int __osp_attr_set(const struct lu_env *env, struct dt_object *dt,
385 const struct lu_attr *attr, struct thandle *th)
387 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
388 struct osp_object *o = dt2osp_obj(dt);
394 * Usually we don't allow server stack to manipulate size
395 * but there is a special case when striping is created
396 * late, after stripless file got truncated to non-zero.
398 * In this case we do the following:
400 * 1) grab id in declare - this can lead to leaked OST objects
401 * but we don't currently have proper mechanism and the only
402 * options we have are to do truncate RPC holding transaction
403 * open (very bad) or to grab id in declare at cost of leaked
404 * OST object in same very rare unfortunate case (just bad)
405 * notice 1.6-2.0 do assignment outside of running transaction
406 * all the time, meaning many more chances for leaked objects.
408 * 2) send synchronous truncate RPC with just assigned id
411 /* there are few places in MDD code still passing NULL
412 * XXX: to be fixed soon */
416 if (attr->la_valid & LA_SIZE && attr->la_size > 0 &&
417 fid_is_zero(lu_object_fid(&o->opo_obj.do_lu))) {
418 LASSERT(!dt_object_exists(dt));
419 osp_object_assign_fid(env, d, o);
420 rc = osp_object_truncate(env, dt, attr->la_size);
426 /* no need in logging for new objects being created */
429 if (!(attr->la_valid & (LA_UID | LA_GID)))
432 if (!is_only_remote_trans(th))
434 * track all UID/GID changes via llog
436 rc = osp_sync_declare_add(env, o, MDS_SETATTR64_REC, th);
438 /* It is for OST-object attr_set directly without updating
439 * local MDT-object attribute. It is usually used by LFSCK. */
440 rc = osp_md_declare_attr_set(env, dt, attr, th);
442 if (rc != 0 || o->opo_ooa == NULL)
445 /* Update the OSP object attributes cache. */
446 la = &o->opo_ooa->ooa_attr;
447 spin_lock(&o->opo_lock);
448 if (attr->la_valid & LA_UID) {
449 la->la_uid = attr->la_uid;
450 la->la_valid |= LA_UID;
453 if (attr->la_valid & LA_GID) {
454 la->la_gid = attr->la_gid;
455 la->la_valid |= LA_GID;
457 spin_unlock(&o->opo_lock);
463 * XXX: NOT prepare set_{attr,xattr} RPC for remote transaction.
465 * According to our current transaction/dt_object_lock framework (to make
466 * the cross-MDTs modification for DNE1 to be workable), the transaction
467 * sponsor will start the transaction firstly, then try to acquire related
468 * dt_object_lock if needed. Under such rules, if we want to prepare the
469 * set_{attr,xattr} RPC in the RPC declare phase, then related attr/xattr
470 * should be known without dt_object_lock. But such condition maybe not
471 * true for some remote transaction case. For example:
473 * For linkEA repairing (by LFSCK) case, before the LFSCK thread obtained
474 * the dt_object_lock on the target MDT-object, it cannot know whether
475 * the MDT-object has linkEA or not, neither invalid or not.
477 * Since the LFSCK thread cannot hold dt_object_lock before the (remote)
478 * transaction start (otherwise there will be some potential deadlock),
479 * it cannot prepare related RPC for repairing during the declare phase
480 * as other normal transactions do.
482 * To resolve the trouble, we will make OSP to prepare related RPC
483 * (set_attr/set_xattr/del_xattr) after remote transaction started,
484 * and trigger the remote updating (RPC sending) when trans_stop.
485 * Then the up layer users, such as LFSCK, can follow the general
486 * rule to handle trans_start/dt_object_lock for repairing linkEA
487 * inconsistency without distinguishing remote MDT-object.
489 * In fact, above solution for remote transaction should be the normal
490 * model without considering DNE1. The trouble brought by DNE1 will be
491 * resolved in DNE2. At that time, this patch can be removed.
493 static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
494 const struct lu_attr *attr, struct thandle *th)
498 if (!is_only_remote_trans(th))
499 rc = __osp_attr_set(env, dt, attr, th);
504 static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
505 const struct lu_attr *attr, struct thandle *th,
506 struct lustre_capa *capa)
508 struct osp_object *o = dt2osp_obj(dt);
512 if (is_only_remote_trans(th)) {
513 rc = __osp_attr_set(env, dt, attr, th);
518 /* we're interested in uid/gid changes only */
519 if (!(attr->la_valid & (LA_UID | LA_GID)))
522 /* new object, the very first ->attr_set()
523 * initializing attributes needs no logging
524 * all subsequent one are subject to the
525 * logging and synchronization with OST */
531 if (!is_only_remote_trans(th))
533 * once transaction is committed put proper command on
534 * the queue going to our OST
536 rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
537 /* XXX: send new uid/gid to OST ASAP? */
539 /* It is for OST-object attr_set directly without updating
540 * local MDT-object attribute. It is usually used by LFSCK. */
541 rc = osp_md_attr_set(env, dt, attr, th, capa);
546 static int osp_xattr_get_interpterer(const struct lu_env *env,
547 struct object_update_reply *reply,
548 struct ptlrpc_request *req,
549 struct osp_object *obj,
550 void *data, int index, int rc)
552 struct osp_object_attr *ooa = obj->opo_ooa;
553 struct osp_xattr_entry *oxe = data;
554 struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
556 LASSERT(ooa != NULL);
559 size_t len = sizeof(*oxe) + oxe->oxe_namelen + 1;
561 rc = object_update_result_data_get(reply, rbuf, index);
562 if (rc < 0 || rbuf->lb_len > (oxe->oxe_buflen - len)) {
563 spin_lock(&obj->opo_lock);
565 spin_unlock(&obj->opo_lock);
566 osp_oac_xattr_put(oxe);
568 return rc < 0 ? rc : -ERANGE;
571 spin_lock(&obj->opo_lock);
572 oxe->oxe_vallen = rbuf->lb_len;
573 memcpy(oxe->oxe_value, rbuf->lb_buf, rbuf->lb_len);
576 spin_unlock(&obj->opo_lock);
577 } else if (rc == -ENOENT || rc == -ENODATA) {
578 spin_lock(&obj->opo_lock);
581 spin_unlock(&obj->opo_lock);
583 spin_lock(&obj->opo_lock);
585 spin_unlock(&obj->opo_lock);
588 osp_oac_xattr_put(oxe);
593 static int osp_declare_xattr_get(const struct lu_env *env, struct dt_object *dt,
594 struct lu_buf *buf, const char *name,
595 struct lustre_capa *capa)
597 struct osp_object *obj = dt2osp_obj(dt);
598 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
599 struct osp_xattr_entry *oxe;
600 int namelen = strlen(name);
603 LASSERT(buf != NULL);
604 LASSERT(name != NULL);
606 /* If only for xattr size, return directly. */
607 if (unlikely(buf->lb_len == 0))
610 if (obj->opo_ooa == NULL) {
611 rc = osp_oac_init(obj);
616 oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
620 mutex_lock(&osp->opd_async_requests_mutex);
621 rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
622 &namelen, &name, oxe,
623 osp_xattr_get_interpterer);
625 mutex_unlock(&osp->opd_async_requests_mutex);
626 osp_oac_xattr_put(oxe);
628 struct dt_update_request *update;
630 /* XXX: Currently, we trigger the batched async OUT
631 * RPC via dt_declare_xattr_get(). It is not
632 * perfect solution, but works well now.
634 * We will improve it in the future. */
635 update = osp->opd_async_requests;
636 if (update != NULL && update->dur_req != NULL &&
637 update->dur_req->ourq_count > 0) {
638 osp->opd_async_requests = NULL;
639 mutex_unlock(&osp->opd_async_requests_mutex);
640 rc = osp_unplug_async_request(env, osp, update);
642 mutex_unlock(&osp->opd_async_requests_mutex);
649 int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
650 struct lu_buf *buf, const char *name,
651 struct lustre_capa *capa)
653 struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
654 struct osp_object *obj = dt2osp_obj(dt);
655 struct dt_device *dev = &osp->opd_dt_dev;
656 struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
657 struct dt_update_request *update = NULL;
658 struct ptlrpc_request *req = NULL;
659 struct object_update_reply *reply;
660 struct osp_xattr_entry *oxe = NULL;
661 const char *dname = dt->do_lu.lo_dev->ld_obd->obd_name;
666 LASSERT(buf != NULL);
667 LASSERT(name != NULL);
669 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NETWORK) &&
670 osp->opd_index == cfs_fail_val &&
671 osp_dev2node(osp) == cfs_fail_val)
674 if (unlikely(obj->opo_non_exist))
677 oxe = osp_oac_xattr_find(obj, name, false);
679 spin_lock(&obj->opo_lock);
680 if (oxe->oxe_ready) {
682 GOTO(unlock, rc = -ENODATA);
684 if (buf->lb_buf == NULL)
685 GOTO(unlock, rc = oxe->oxe_vallen);
687 if (buf->lb_len < oxe->oxe_vallen)
688 GOTO(unlock, rc = -ERANGE);
690 memcpy(buf->lb_buf, oxe->oxe_value, oxe->oxe_vallen);
692 GOTO(unlock, rc = oxe->oxe_vallen);
695 spin_unlock(&obj->opo_lock);
696 osp_oac_xattr_put(oxe);
700 spin_unlock(&obj->opo_lock);
703 update = out_create_update_req(dev);
705 GOTO(out, rc = PTR_ERR(update));
707 namelen = strlen(name) + 1;
708 rc = out_insert_update(env, update, OUT_XATTR_GET,
709 lu_object_fid(&dt->do_lu), 1, &namelen, &name);
711 CERROR("%s: Insert update error "DFID": rc = %d\n",
712 dname, PFID(lu_object_fid(&dt->do_lu)), rc);
717 rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import, update, &req);
719 if (obj->opo_ooa == NULL)
723 oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
726 CWARN("%s: Fail to add xattr (%s) to cache for "
727 DFID" (1): rc = %d\n", dname, name,
728 PFID(lu_object_fid(&dt->do_lu)), rc);
733 spin_lock(&obj->opo_lock);
734 if (rc == -ENOENT || rc == -ENODATA) {
740 spin_unlock(&obj->opo_lock);
745 reply = req_capsule_server_sized_get(&req->rq_pill,
746 &RMF_OUT_UPDATE_REPLY,
747 OUT_UPDATE_REPLY_SIZE);
748 if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
749 CERROR("%s: Wrong version %x expected %x "DFID": rc = %d\n",
750 dname, reply->ourp_magic, UPDATE_REPLY_MAGIC,
751 PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
753 GOTO(out, rc = -EPROTO);
756 rc = object_update_result_data_get(reply, rbuf, 0);
760 if (buf->lb_buf == NULL)
761 GOTO(out, rc = rbuf->lb_len);
763 if (unlikely(buf->lb_len < rbuf->lb_len))
764 GOTO(out, rc = -ERANGE);
766 memcpy(buf->lb_buf, rbuf->lb_buf, rbuf->lb_len);
768 if (obj->opo_ooa == NULL)
772 oxe = osp_oac_xattr_find_or_add(obj, name, rbuf->lb_len);
774 CWARN("%s: Fail to add xattr (%s) to "
775 "cache for "DFID" (2): rc = %d\n",
776 dname, name, PFID(lu_object_fid(&dt->do_lu)), rc);
782 if (oxe->oxe_buflen - oxe->oxe_namelen - 1 < rbuf->lb_len) {
783 struct osp_xattr_entry *old = oxe;
784 struct osp_xattr_entry *tmp;
786 tmp = osp_oac_xattr_replace(obj, &old, rbuf->lb_len);
787 osp_oac_xattr_put(oxe);
790 CWARN("%s: Fail to update xattr (%s) to "
791 "cache for "DFID": rc = %d\n",
792 dname, name, PFID(lu_object_fid(&dt->do_lu)), rc);
793 spin_lock(&obj->opo_lock);
795 spin_unlock(&obj->opo_lock);
800 /* Drop the ref for entry on list. */
801 osp_oac_xattr_put(old);
804 spin_lock(&obj->opo_lock);
805 oxe->oxe_vallen = rbuf->lb_len;
806 memcpy(oxe->oxe_value, rbuf->lb_buf, rbuf->lb_len);
809 spin_unlock(&obj->opo_lock);
815 ptlrpc_req_finished(req);
817 if (update != NULL && !IS_ERR(update))
818 out_destroy_update_req(update);
821 osp_oac_xattr_put(oxe);
826 static int __osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
827 const struct lu_buf *buf, const char *name,
828 int flag, struct thandle *th)
830 struct dt_update_request *update;
832 int sizes[3] = { strlen(name),
835 char *bufs[3] = { (char *)name,
836 (char *)buf->lb_buf };
837 struct osp_xattr_entry *oxe;
838 struct osp_object *o = dt2osp_obj(dt);
842 LASSERT(buf->lb_len > 0 && buf->lb_buf != NULL);
844 update = out_find_create_update_loc(th, dt);
845 if (IS_ERR(update)) {
846 CERROR("%s: Get OSP update buf failed "DFID": rc = %d\n",
847 dt->do_lu.lo_dev->ld_obd->obd_name,
848 PFID(lu_object_fid(&dt->do_lu)),
849 (int)PTR_ERR(update));
851 RETURN(PTR_ERR(update));
854 flag = cpu_to_le32(flag);
855 bufs[2] = (char *)&flag;
857 fid = (struct lu_fid *)lu_object_fid(&dt->do_lu);
858 rc = out_insert_update(env, update, OUT_XATTR_SET, fid,
859 ARRAY_SIZE(sizes), sizes, (const char **)bufs);
860 if (rc != 0 || o->opo_ooa == NULL)
863 oxe = osp_oac_xattr_find_or_add(o, name, buf->lb_len);
865 CWARN("%s: Fail to add xattr (%s) to cache for "DFID,
866 dt->do_lu.lo_dev->ld_obd->obd_name,
867 name, PFID(lu_object_fid(&dt->do_lu)));
872 if (oxe->oxe_buflen - oxe->oxe_namelen - 1 < buf->lb_len) {
873 struct osp_xattr_entry *old = oxe;
874 struct osp_xattr_entry *tmp;
876 tmp = osp_oac_xattr_replace(o, &old, buf->lb_len);
877 osp_oac_xattr_put(oxe);
880 CWARN("%s: Fail to update xattr (%s) to cache for "DFID,
881 dt->do_lu.lo_dev->ld_obd->obd_name,
882 name, PFID(lu_object_fid(&dt->do_lu)));
883 spin_lock(&o->opo_lock);
885 spin_unlock(&o->opo_lock);
890 /* Drop the ref for entry on list. */
891 osp_oac_xattr_put(old);
894 spin_lock(&o->opo_lock);
895 oxe->oxe_vallen = buf->lb_len;
896 memcpy(oxe->oxe_value, buf->lb_buf, buf->lb_len);
899 spin_unlock(&o->opo_lock);
900 osp_oac_xattr_put(oxe);
905 int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
906 const struct lu_buf *buf, const char *name,
907 int flag, struct thandle *th)
911 /* Please check the comment in osp_attr_set() for handling
912 * remote transaction. */
913 if (!is_only_remote_trans(th))
914 rc = __osp_xattr_set(env, dt, buf, name, flag, th);
919 int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
920 const struct lu_buf *buf, const char *name, int fl,
921 struct thandle *th, struct lustre_capa *capa)
925 CDEBUG(D_INFO, "xattr %s set object "DFID"\n", name,
926 PFID(&dt->do_lu.lo_header->loh_fid));
928 /* Please check the comment in osp_attr_set() for handling
929 * remote transaction. */
930 if (is_only_remote_trans(th))
931 rc = __osp_xattr_set(env, dt, buf, name, fl, th);
936 static int __osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
937 const char *name, struct thandle *th)
939 struct dt_update_request *update;
940 const struct lu_fid *fid;
941 struct osp_object *o = dt2osp_obj(dt);
942 struct osp_xattr_entry *oxe;
943 int size = strlen(name);
946 update = out_find_create_update_loc(th, dt);
948 return PTR_ERR(update);
950 fid = lu_object_fid(&dt->do_lu);
952 rc = out_insert_update(env, update, OUT_XATTR_DEL, fid, 1, &size,
953 (const char **)&name);
954 if (rc != 0 || o->opo_ooa == NULL)
957 oxe = osp_oac_xattr_find(o, name, true);
959 /* Drop the ref for entry on list. */
960 osp_oac_xattr_put(oxe);
965 int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
966 const char *name, struct thandle *th)
970 /* Please check the comment in osp_attr_set() for handling
971 * remote transaction. */
972 if (!is_only_remote_trans(th))
973 rc = __osp_xattr_del(env, dt, name, th);
978 int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
979 const char *name, struct thandle *th,
980 struct lustre_capa *capa)
984 CDEBUG(D_INFO, "xattr %s del object "DFID"\n", name,
985 PFID(&dt->do_lu.lo_header->loh_fid));
987 /* Please check the comment in osp_attr_set() for handling
988 * remote transaction. */
989 if (is_only_remote_trans(th))
990 rc = __osp_xattr_del(env, dt, name, th);
995 static int osp_declare_object_create(const struct lu_env *env,
996 struct dt_object *dt,
997 struct lu_attr *attr,
998 struct dt_allocation_hint *hint,
999 struct dt_object_format *dof,
1002 struct osp_thread_info *osi = osp_env_info(env);
1003 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
1004 struct osp_object *o = dt2osp_obj(dt);
1005 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1010 if (is_only_remote_trans(th)) {
1011 LASSERT(fid_is_sane(fid));
1013 rc = osp_md_declare_object_create(env, dt, attr, hint, dof, th);
1018 /* should happen to non-0 OSP only so that at least one object
1019 * has been already declared in the scenario and LOD should
1021 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL) && d->opd_index == 1)
1024 LASSERT(d->opd_last_used_oid_file);
1027 * There can be gaps in precreated ids and record to unlink llog
1028 * XXX: we do not handle gaps yet, implemented before solution
1029 * was found to be racy, so we disabled that. there is no
1030 * point in making useless but expensive llog declaration.
1032 /* rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th); */
1034 if (unlikely(!fid_is_zero(fid))) {
1035 /* replay case: caller knows fid */
1036 osi->osi_off = sizeof(osi->osi_id) * d->opd_index;
1037 osi->osi_lb.lb_len = sizeof(osi->osi_id);
1038 osi->osi_lb.lb_buf = NULL;
1039 rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
1040 &osi->osi_lb, osi->osi_off, th);
1045 * in declaration we need to reserve object so that we don't block
1046 * awaiting precreation RPC to complete
1048 rc = osp_precreate_reserve(env, d);
1050 * we also need to declare update to local "last used id" file for
1051 * recovery if object isn't used for a reason, we need to release
1052 * reservation, this can be made in osd_object_release()
1055 /* mark id is reserved: in create we don't want to talk
1057 LASSERT(o->opo_reserved == 0);
1058 o->opo_reserved = 1;
1060 /* common for all OSPs file hystorically */
1061 osi->osi_off = sizeof(osi->osi_id) * d->opd_index;
1062 osi->osi_lb.lb_len = sizeof(osi->osi_id);
1063 osi->osi_lb.lb_buf = NULL;
1064 rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
1065 &osi->osi_lb, osi->osi_off, th);
1067 /* not needed in the cache anymore */
1068 set_bit(LU_OBJECT_HEARD_BANSHEE,
1069 &dt->do_lu.lo_header->loh_flags);
1074 static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
1075 struct lu_attr *attr,
1076 struct dt_allocation_hint *hint,
1077 struct dt_object_format *dof, struct thandle *th)
1079 struct osp_thread_info *osi = osp_env_info(env);
1080 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
1081 struct osp_object *o = dt2osp_obj(dt);
1083 struct lu_fid *fid = &osi->osi_fid;
1086 if (is_only_remote_trans(th)) {
1087 LASSERT(fid_is_sane(lu_object_fid(&dt->do_lu)));
1089 rc = osp_md_object_create(env, dt, attr, hint, dof, th);
1091 o->opo_non_exist = 0;
1096 o->opo_non_exist = 0;
1097 if (o->opo_reserved) {
1098 /* regular case, fid is assigned holding trunsaction open */
1099 osp_object_assign_fid(env, d, o);
1102 memcpy(fid, lu_object_fid(&dt->do_lu), sizeof(*fid));
1104 LASSERTF(fid_is_sane(fid), "fid for osp_object %p is insane"DFID"!\n",
1107 if (!o->opo_reserved) {
1108 /* special case, id was assigned outside of transaction
1109 * see comments in osp_declare_attr_set */
1110 LASSERT(d->opd_pre != NULL);
1111 spin_lock(&d->opd_pre_lock);
1112 osp_update_last_fid(d, fid);
1113 spin_unlock(&d->opd_pre_lock);
1116 CDEBUG(D_INODE, "fid for osp_object %p is "DFID"\n", o, PFID(fid));
1118 /* If the precreate ends, it means it will be ready to rollover to
1119 * the new sequence soon, all the creation should be synchronized,
1120 * otherwise during replay, the replay fid will be inconsistent with
1121 * last_used/create fid */
1122 if (osp_precreate_end_seq(env, d) && osp_is_fid_client(d))
1126 * it's OK if the import is inactive by this moment - id was created
1127 * by OST earlier, we just need to maintain it consistently on the disk
1128 * once import is reconnected, OSP will claim this and other objects
1129 * used and OST either keep them, if they exist or recreate
1132 /* we might have lost precreated objects */
1133 if (unlikely(d->opd_gap_count) > 0) {
1134 LASSERT(d->opd_pre != NULL);
1135 spin_lock(&d->opd_pre_lock);
1136 if (d->opd_gap_count > 0) {
1137 int count = d->opd_gap_count;
1139 ostid_set_id(&osi->osi_oi,
1140 fid_oid(&d->opd_gap_start_fid));
1141 d->opd_gap_count = 0;
1142 spin_unlock(&d->opd_pre_lock);
1144 CDEBUG(D_HA, "Writting gap "DFID"+%d in llog\n",
1145 PFID(&d->opd_gap_start_fid), count);
1146 /* real gap handling is disabled intil ORI-692 will be
1147 * fixed, now we only report gaps */
1149 spin_unlock(&d->opd_pre_lock);
1153 /* new object, the very first ->attr_set()
1154 * initializing attributes needs no logging */
1157 /* Only need update last_used oid file, seq file will only be update
1158 * during seq rollover */
1159 osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off,
1160 &d->opd_last_used_fid.f_oid, d->opd_index);
1162 rc = dt_record_write(env, d->opd_last_used_oid_file, &osi->osi_lb,
1165 CDEBUG(D_HA, "%s: Wrote last used FID: "DFID", index %d: %d\n",
1166 d->opd_obd->obd_name, PFID(fid), d->opd_index, rc);
1171 int osp_declare_object_destroy(const struct lu_env *env,
1172 struct dt_object *dt, struct thandle *th)
1174 struct osp_object *o = dt2osp_obj(dt);
1180 * track objects to be destroyed via llog
1182 rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th);
1187 int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
1190 struct osp_object *o = dt2osp_obj(dt);
1195 o->opo_non_exist = 1;
1197 * once transaction is committed put proper command on
1198 * the queue going to our OST
1200 rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
1202 /* not needed in cache any more */
1203 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
1208 static int osp_orphan_index_lookup(const struct lu_env *env,
1209 struct dt_object *dt,
1211 const struct dt_key *key,
1212 struct lustre_capa *capa)
1217 static int osp_orphan_index_declare_insert(const struct lu_env *env,
1218 struct dt_object *dt,
1219 const struct dt_rec *rec,
1220 const struct dt_key *key,
1221 struct thandle *handle)
1226 static int osp_orphan_index_insert(const struct lu_env *env,
1227 struct dt_object *dt,
1228 const struct dt_rec *rec,
1229 const struct dt_key *key,
1230 struct thandle *handle,
1231 struct lustre_capa *capa,
1237 static int osp_orphan_index_declare_delete(const struct lu_env *env,
1238 struct dt_object *dt,
1239 const struct dt_key *key,
1240 struct thandle *handle)
1245 static int osp_orphan_index_delete(const struct lu_env *env,
1246 struct dt_object *dt,
1247 const struct dt_key *key,
1248 struct thandle *handle,
1249 struct lustre_capa *capa)
1254 struct dt_it *osp_it_init(const struct lu_env *env, struct dt_object *dt,
1255 __u32 attr, struct lustre_capa *capa)
1261 return ERR_PTR(-ENOMEM);
1263 it->ooi_pos_ent = -1;
1266 return (struct dt_it *)it;
1269 void osp_it_fini(const struct lu_env *env, struct dt_it *di)
1271 struct osp_it *it = (struct osp_it *)di;
1272 struct page **pages = it->ooi_pages;
1273 int npages = it->ooi_total_npages;
1276 if (pages != NULL) {
1277 for (i = 0; i < npages; i++) {
1278 if (pages[i] != NULL) {
1279 if (pages[i] == it->ooi_cur_page) {
1281 it->ooi_cur_page = NULL;
1283 __free_page(pages[i]);
1286 OBD_FREE(pages, npages * sizeof(*pages));
1291 static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
1293 struct lu_device *dev = it->ooi_obj->do_lu.lo_dev;
1294 struct osp_device *osp = lu2osp_dev(dev);
1295 struct page **pages;
1296 struct ptlrpc_request *req = NULL;
1297 struct ptlrpc_bulk_desc *desc;
1298 struct idx_info *ii;
1305 npages = min_t(unsigned int, OFD_MAX_BRW_SIZE, 1 << 20);
1306 npages /= PAGE_CACHE_SIZE;
1308 OBD_ALLOC(pages, npages * sizeof(*pages));
1312 it->ooi_pages = pages;
1313 it->ooi_total_npages = npages;
1314 for (i = 0; i < npages; i++) {
1315 pages[i] = alloc_page(GFP_IOFS);
1316 if (pages[i] == NULL)
1320 req = ptlrpc_request_alloc(osp->opd_obd->u.cli.cl_import,
1325 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, OBD_IDX_READ);
1327 ptlrpc_request_free(req);
1331 req->rq_request_portal = OUT_PORTAL;
1332 ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
1333 memset(ii, 0, sizeof(*ii));
1334 if (fid_is_last_id(lu_object_fid(&it->ooi_obj->do_lu))) {
1335 /* LFSCK will iterate orphan object[FID_SEQ_LAYOUT_BTREE,
1336 * ost_index, 0] with LAST_ID FID, so it needs to replace
1337 * the FID with orphan FID here */
1338 ii->ii_fid.f_seq = FID_SEQ_LAYOUT_RBTREE;
1339 ii->ii_fid.f_oid = osp->opd_index;
1340 ii->ii_fid.f_ver = 0;
1341 ii->ii_flags = II_FL_NOHASH;
1343 ii->ii_fid = *lu_object_fid(&it->ooi_obj->do_lu);
1344 ii->ii_flags = II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
1347 ii->ii_magic = IDX_INFO_MAGIC;
1348 ii->ii_count = npages * LU_PAGE_COUNT;
1349 ii->ii_hash_start = it->ooi_next;
1350 ii->ii_attrs = osp_dev2node(osp);
1352 ptlrpc_at_set_req_timeout(req);
1354 desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
1357 ptlrpc_request_free(req);
1361 for (i = 0; i < npages; i++)
1362 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1364 ptlrpc_request_set_replen(req);
1365 rc = ptlrpc_queue_wait(req);
1369 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1370 req->rq_bulk->bd_nob_transferred);
1375 ii = req_capsule_server_get(&req->rq_pill, &RMF_IDX_INFO);
1376 if (ii->ii_magic != IDX_INFO_MAGIC)
1377 GOTO(out, rc = -EPROTO);
1379 npages = (ii->ii_count + LU_PAGE_COUNT - 1) >>
1380 (PAGE_CACHE_SHIFT - LU_PAGE_SHIFT);
1381 if (npages > it->ooi_total_npages) {
1382 CERROR("%s: returned more pages than expected, %u > %u\n",
1383 osp->opd_obd->obd_name, npages, it->ooi_total_npages);
1384 GOTO(out, rc = -EINVAL);
1387 it->ooi_valid_npages = npages;
1388 if (ptlrpc_rep_need_swab(req))
1391 it->ooi_next = ii->ii_hash_end;
1394 ptlrpc_req_finished(req);
1399 int osp_it_next_page(const struct lu_env *env, struct dt_it *di)
1401 struct osp_it *it = (struct osp_it *)di;
1402 struct lu_idxpage *idxpage;
1403 struct page **pages;
1409 idxpage = it->ooi_cur_idxpage;
1410 if (idxpage != NULL) {
1411 if (idxpage->lip_nr == 0)
1414 if (it->ooi_pos_ent < idxpage->lip_nr) {
1415 CDEBUG(D_INFO, "ooi_pos %d nr %d\n",
1416 (int)it->ooi_pos_ent, (int)idxpage->lip_nr);
1419 it->ooi_cur_idxpage = NULL;
1420 it->ooi_pos_lu_page++;
1422 if (it->ooi_pos_lu_page < LU_PAGE_COUNT) {
1423 it->ooi_cur_idxpage = (void *)it->ooi_cur_page +
1424 LU_PAGE_SIZE * it->ooi_pos_lu_page;
1426 lustre_swab_lip_header(it->ooi_cur_idxpage);
1427 if (it->ooi_cur_idxpage->lip_magic != LIP_MAGIC) {
1428 struct osp_device *osp =
1429 lu2osp_dev(it->ooi_obj->do_lu.lo_dev);
1431 CERROR("%s: invalid magic (%x != %x) for page "
1432 "%d/%d while read layout orphan index\n",
1433 osp->opd_obd->obd_name,
1434 it->ooi_cur_idxpage->lip_magic,
1435 LIP_MAGIC, it->ooi_pos_page,
1436 it->ooi_pos_lu_page);
1437 /* Skip this lu_page next time. */
1438 it->ooi_pos_ent = idxpage->lip_nr - 1;
1441 it->ooi_pos_ent = -1;
1445 kunmap(it->ooi_cur_page);
1446 it->ooi_cur_page = NULL;
1450 pages = it->ooi_pages;
1451 if (it->ooi_pos_page < it->ooi_valid_npages) {
1452 it->ooi_cur_page = kmap(pages[it->ooi_pos_page]);
1453 it->ooi_pos_lu_page = 0;
1457 for (i = 0; i < it->ooi_total_npages; i++) {
1458 if (pages[i] != NULL)
1459 __free_page(pages[i]);
1461 OBD_FREE(pages, it->ooi_total_npages * sizeof(*pages));
1463 it->ooi_pos_page = 0;
1464 it->ooi_total_npages = 0;
1465 it->ooi_valid_npages = 0;
1468 it->ooi_cur_page = NULL;
1469 it->ooi_cur_idxpage = NULL;
1470 it->ooi_pages = NULL;
1473 if (it->ooi_next == II_END_OFF)
1476 rc = osp_it_fetch(env, it);
1483 int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
1485 struct osp_it *it = (struct osp_it *)di;
1486 struct lu_idxpage *idxpage;
1491 idxpage = it->ooi_cur_idxpage;
1492 if (idxpage != NULL) {
1493 if (idxpage->lip_nr == 0)
1497 if (it->ooi_pos_ent < idxpage->lip_nr) {
1499 (struct lu_orphan_ent *)idxpage->lip_entries +
1502 lustre_swab_orphan_ent(it->ooi_ent);
1507 rc = osp_it_next_page(env, di);
1514 int osp_it_get(const struct lu_env *env, struct dt_it *di,
1515 const struct dt_key *key)
1520 void osp_it_put(const struct lu_env *env, struct dt_it *di)
1524 struct dt_key *osp_orphan_it_key(const struct lu_env *env,
1525 const struct dt_it *di)
1527 struct osp_it *it = (struct osp_it *)di;
1528 struct lu_orphan_ent *ent = (struct lu_orphan_ent *)it->ooi_ent;
1530 if (likely(ent != NULL))
1531 return (struct dt_key *)(&ent->loe_key);
1536 int osp_orphan_it_key_size(const struct lu_env *env, const struct dt_it *di)
1538 return sizeof(struct lu_fid);
1541 int osp_orphan_it_rec(const struct lu_env *env, const struct dt_it *di,
1542 struct dt_rec *rec, __u32 attr)
1544 struct osp_it *it = (struct osp_it *)di;
1545 struct lu_orphan_ent *ent = (struct lu_orphan_ent *)it->ooi_ent;
1547 if (likely(ent != NULL)) {
1548 *(struct lu_orphan_rec *)rec = ent->loe_rec;
1555 __u64 osp_it_store(const struct lu_env *env, const struct dt_it *di)
1557 struct osp_it *it = (struct osp_it *)di;
1559 return it->ooi_next;
1563 * \retval +1: locate to the exactly position
1564 * \retval 0: cannot locate to the exactly position,
1565 * call next() to move to a valid position.
1566 * \retval -ve: on error
1568 int osp_orphan_it_load(const struct lu_env *env, const struct dt_it *di,
1571 struct osp_it *it = (struct osp_it *)di;
1574 it->ooi_next = hash;
1575 rc = osp_orphan_it_next(env, (struct dt_it *)di);
1585 int osp_it_key_rec(const struct lu_env *env, const struct dt_it *di,
1591 static const struct dt_index_operations osp_orphan_index_ops = {
1592 .dio_lookup = osp_orphan_index_lookup,
1593 .dio_declare_insert = osp_orphan_index_declare_insert,
1594 .dio_insert = osp_orphan_index_insert,
1595 .dio_declare_delete = osp_orphan_index_declare_delete,
1596 .dio_delete = osp_orphan_index_delete,
1598 .init = osp_it_init,
1599 .fini = osp_it_fini,
1600 .next = osp_orphan_it_next,
1603 .key = osp_orphan_it_key,
1604 .key_size = osp_orphan_it_key_size,
1605 .rec = osp_orphan_it_rec,
1606 .store = osp_it_store,
1607 .load = osp_orphan_it_load,
1608 .key_rec = osp_it_key_rec,
1612 static int osp_index_try(const struct lu_env *env,
1613 struct dt_object *dt,
1614 const struct dt_index_features *feat)
1616 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1618 if (fid_is_last_id(fid) && fid_is_idif(fid))
1619 dt->do_index_ops = &osp_orphan_index_ops;
1621 dt->do_index_ops = &osp_md_index_ops;
1625 struct dt_object_operations osp_obj_ops = {
1626 .do_declare_attr_get = osp_declare_attr_get,
1627 .do_attr_get = osp_attr_get,
1628 .do_declare_attr_set = osp_declare_attr_set,
1629 .do_attr_set = osp_attr_set,
1630 .do_declare_xattr_get = osp_declare_xattr_get,
1631 .do_xattr_get = osp_xattr_get,
1632 .do_declare_xattr_set = osp_declare_xattr_set,
1633 .do_xattr_set = osp_xattr_set,
1634 .do_declare_create = osp_declare_object_create,
1635 .do_create = osp_object_create,
1636 .do_declare_destroy = osp_declare_object_destroy,
1637 .do_destroy = osp_object_destroy,
1638 .do_index_try = osp_index_try,
1641 static int osp_object_init(const struct lu_env *env, struct lu_object *o,
1642 const struct lu_object_conf *conf)
1644 struct osp_object *po = lu2osp_obj(o);
1648 spin_lock_init(&po->opo_lock);
1649 o->lo_header->loh_attr |= LOHA_REMOTE;
1651 if (is_ost_obj(o)) {
1652 po->opo_obj.do_ops = &osp_obj_ops;
1654 struct lu_attr *la = &osp_env_info(env)->osi_attr;
1656 po->opo_obj.do_ops = &osp_md_obj_ops;
1657 po->opo_obj.do_body_ops = &osp_md_body_ops;
1658 rc = po->opo_obj.do_ops->do_attr_get(env, lu2dt_obj(o),
1661 o->lo_header->loh_attr |=
1662 LOHA_EXISTS | (la->la_mode & S_IFMT);
1663 if (rc == -ENOENT) {
1664 po->opo_non_exist = 1;
1667 init_rwsem(&po->opo_sem);
1672 static void osp_object_free(const struct lu_env *env, struct lu_object *o)
1674 struct osp_object *obj = lu2osp_obj(o);
1675 struct lu_object_header *h = o->lo_header;
1677 dt_object_fini(&obj->opo_obj);
1678 lu_object_header_fini(h);
1679 if (obj->opo_ooa != NULL) {
1680 struct osp_xattr_entry *oxe;
1681 struct osp_xattr_entry *tmp;
1684 list_for_each_entry_safe(oxe, tmp,
1685 &obj->opo_ooa->ooa_xattr_list,
1687 list_del(&oxe->oxe_list);
1688 count = atomic_read(&oxe->oxe_ref);
1689 LASSERTF(count == 1,
1690 "Still has %d users on the xattr entry %.*s\n",
1691 count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
1693 OBD_FREE(oxe, oxe->oxe_buflen);
1695 OBD_FREE_PTR(obj->opo_ooa);
1697 OBD_SLAB_FREE_PTR(obj, osp_object_kmem);
1700 static void osp_object_release(const struct lu_env *env, struct lu_object *o)
1702 struct osp_object *po = lu2osp_obj(o);
1703 struct osp_device *d = lu2osp_dev(o->lo_dev);
1708 * release reservation if object was declared but not created
1709 * this may require lu_object_put() in LOD
1711 if (unlikely(po->opo_reserved)) {
1712 LASSERT(d->opd_pre != NULL);
1713 LASSERT(d->opd_pre_reserved > 0);
1714 spin_lock(&d->opd_pre_lock);
1715 d->opd_pre_reserved--;
1716 spin_unlock(&d->opd_pre_lock);
1718 /* not needed in cache any more */
1719 set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
1723 /* XXX: Currently, NOT cache OST-object on MDT because:
1724 * 1. it is not often accessed on MDT.
1725 * 2. avoid up layer (such as LFSCK) to load too many
1726 * once-used OST-objects. */
1727 set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
1732 static int osp_object_print(const struct lu_env *env, void *cookie,
1733 lu_printer_t p, const struct lu_object *l)
1735 const struct osp_object *o = lu2osp_obj((struct lu_object *)l);
1737 return (*p)(env, cookie, LUSTRE_OSP_NAME"-object@%p", o);
1740 static int osp_object_invariant(const struct lu_object *o)
1745 struct lu_object_operations osp_lu_obj_ops = {
1746 .loo_object_init = osp_object_init,
1747 .loo_object_free = osp_object_free,
1748 .loo_object_release = osp_object_release,
1749 .loo_object_print = osp_object_print,
1750 .loo_object_invariant = osp_object_invariant