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) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_handler.c
38 * Top-level entry points into osd module
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/module.h>
48 /* LUSTRE_VERSION_CODE */
49 #include <lustre_ver.h>
50 /* prerequisite for linux/xattr.h */
51 #include <linux/types.h>
52 /* prerequisite for linux/xattr.h */
54 /* XATTR_{REPLACE,CREATE} */
55 #include <linux/xattr.h>
60 * struct OBD_{ALLOC,FREE}*()
63 #include <obd_support.h>
64 /* struct ptlrpc_thread */
65 #include <lustre_net.h>
68 #include <lustre_fid.h>
70 #include "osd_internal.h"
73 /* llo_* api support */
74 #include <md_object.h>
75 /* dt_acct_features */
78 #ifdef HAVE_LDISKFS_PDO
80 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
81 "ldiskfs with parallel directory operations");
86 static const char dot[] = ".";
87 static const char dotdot[] = "..";
88 static const char remote_obj_dir[] = "REM_OBJ_DIR";
90 static const struct lu_object_operations osd_lu_obj_ops;
91 static const struct dt_object_operations osd_obj_ops;
92 static const struct dt_object_operations osd_obj_ea_ops;
93 static const struct dt_object_operations osd_obj_otable_it_ops;
94 static const struct dt_index_operations osd_index_iam_ops;
95 static const struct dt_index_operations osd_index_ea_ops;
97 static int osd_has_index(const struct osd_object *obj)
99 return obj->oo_dt.do_index_ops != NULL;
102 static int osd_object_invariant(const struct lu_object *l)
104 return osd_invariant(osd_obj(l));
107 #ifdef HAVE_QUOTA_SUPPORT
109 osd_push_ctxt(const struct lu_env *env, struct osd_ctxt *save, bool is_md)
122 save->oc_uid = current_fsuid();
123 save->oc_gid = current_fsgid();
124 save->oc_cap = current_cap();
125 if ((tc = prepare_creds())) {
126 tc->fsuid = uc->mu_fsuid;
127 tc->fsgid = uc->mu_fsgid;
130 /* XXX not suboptimal */
131 cfs_curproc_cap_unpack(uc->mu_cap);
135 osd_pop_ctxt(struct osd_ctxt *save, bool is_md)
143 if ((tc = prepare_creds())) {
144 tc->fsuid = save->oc_uid;
145 tc->fsgid = save->oc_gid;
146 tc->cap_effective = save->oc_cap;
153 * Concurrency: doesn't matter
155 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
157 return osd_oti_get(env)->oti_r_locks > 0;
161 * Concurrency: doesn't matter
163 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
165 struct osd_thread_info *oti = osd_oti_get(env);
166 return oti->oti_w_locks > 0 && o->oo_owner == env;
170 * Concurrency: doesn't access mutable data
172 static int osd_root_get(const struct lu_env *env,
173 struct dt_device *dev, struct lu_fid *f)
175 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
180 * OSD object methods.
184 * Concurrency: no concurrent access is possible that early in object
187 static struct lu_object *osd_object_alloc(const struct lu_env *env,
188 const struct lu_object_header *hdr,
191 struct osd_object *mo;
197 l = &mo->oo_dt.do_lu;
198 dt_object_init(&mo->oo_dt, NULL, d);
199 if (osd_dev(d)->od_iop_mode)
200 mo->oo_dt.do_ops = &osd_obj_ea_ops;
202 mo->oo_dt.do_ops = &osd_obj_ops;
204 l->lo_ops = &osd_lu_obj_ops;
205 cfs_init_rwsem(&mo->oo_sem);
206 cfs_init_rwsem(&mo->oo_ext_idx_sem);
207 cfs_spin_lock_init(&mo->oo_guard);
214 static int osd_get_lma(struct inode *inode, struct dentry *dentry,
215 struct lustre_mdt_attrs *lma)
219 dentry->d_inode = inode;
220 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)lma,
223 /* Check LMA compatibility */
224 if (lma->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP)) {
225 CWARN("%.16s: unsupported incompat LMA feature(s) "
227 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
228 inode->i_ino, le32_to_cpu(lma->lma_incompat) &
232 lustre_lma_swab(lma);
235 } else if (rc == 0) {
243 * retrieve object from backend ext fs.
245 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
246 struct osd_inode_id *id)
248 struct inode *inode = NULL;
250 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
252 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
253 id->oii_ino, PTR_ERR(inode));
254 } else if (id->oii_gen != OSD_OII_NOGEN &&
255 inode->i_generation != id->oii_gen) {
256 CDEBUG(D_INODE, "unmatched inode: ino = %u, gen0 = %u, "
258 id->oii_ino, id->oii_gen, inode->i_generation);
260 inode = ERR_PTR(-ESTALE);
261 } else if (inode->i_nlink == 0) {
262 /* due to parallel readdir and unlink,
263 * we can have dead inode here. */
264 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
265 make_bad_inode(inode);
267 inode = ERR_PTR(-ESTALE);
268 } else if (is_bad_inode(inode)) {
269 CWARN("%.16s: bad inode: ino = %u\n",
270 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
272 inode = ERR_PTR(-ENOENT);
274 if (id->oii_gen == OSD_OII_NOGEN)
275 osd_id_gen(id, inode->i_ino, inode->i_generation);
277 /* Do not update file c/mtime in ldiskfs.
278 * NB: we don't have any lock to protect this because we don't
279 * have reference on osd_object now, but contention with
280 * another lookup + attr_set can't happen in the tiny window
281 * between if (...) and set S_NOCMTIME. */
282 if (!(inode->i_flags & S_NOCMTIME))
283 inode->i_flags |= S_NOCMTIME;
288 struct inode *osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
289 struct osd_inode_id *id, struct lu_fid *fid)
291 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
295 inode = osd_iget(info, dev, id);
299 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
301 *fid = lma->lma_self_fid;
302 } else if (rc == -ENODATA) {
303 LU_IGIF_BUILD(fid, inode->i_ino, inode->i_generation);
311 static struct inode *
312 osd_iget_verify(struct osd_thread_info *info, struct osd_device *dev,
313 struct osd_inode_id *id, const struct lu_fid *fid)
315 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
319 inode = osd_iget(info, dev, id);
323 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
325 if (rc == -ENODATA) {
326 CDEBUG(D_LFSCK, "inconsistent obj: NULL, %lu, "DFID"\n",
327 inode->i_ino, PFID(fid));
334 if (!lu_fid_eq(fid, &lma->lma_self_fid)) {
335 CDEBUG(D_LFSCK, "inconsistent obj: "DFID", %lu, "DFID"\n",
336 PFID(&lma->lma_self_fid), inode->i_ino, PFID(fid));
338 return ERR_PTR(EREMCHG);
343 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
344 const struct lu_fid *fid,
345 const struct lu_object_conf *conf)
347 struct osd_thread_info *info;
348 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
349 struct osd_device *dev;
350 struct osd_idmap_cache *oic;
351 struct osd_inode_id *id;
353 struct osd_scrub *scrub;
354 struct scrub_file *sf;
359 LINVRNT(osd_invariant(obj));
360 LASSERT(obj->oo_inode == NULL);
361 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID, PFID(fid));
364 scrub = &dev->od_scrub;
365 sf = &scrub->os_file;
366 info = osd_oti_get(env);
368 oic = &info->oti_cache;
371 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
374 if (fid_is_norm(fid)) {
375 /* Search order: 1. per-thread cache. */
376 if (lu_fid_eq(fid, &oic->oic_fid)) {
378 } else if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
379 /* Search order: 2. OI scrub pending list. */
380 result = osd_oii_lookup(dev, fid, id);
385 if (sf->sf_flags & SF_INCONSISTENT)
390 * Objects are created as locking anchors or place holders for objects
391 * yet to be created. No need to osd_oi_lookup() at here because FID
392 * shouldn't never be re-used, if it's really a duplicate FID from
393 * unexpected reason, we should be able to detect it later by calling
394 * do_create->osd_oi_insert()
396 if (conf != NULL && (conf->loc_flags & LOC_F_NEW) != 0)
397 GOTO(out, result = 0);
399 /* Search order: 3. OI files. */
400 result = osd_oi_lookup(info, dev, fid, id);
401 if (result == -ENOENT) {
402 if (!fid_is_norm(fid) ||
403 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
405 GOTO(out, result = 0);
415 inode = osd_iget(info, dev, id);
417 inode = osd_iget_verify(info, dev, id, fid);
419 result = PTR_ERR(inode);
420 if (result == -ENOENT || result == -ESTALE) {
421 fid_zero(&oic->oic_fid);
423 } else if (result == -EREMCHG) {
426 if (thread_is_running(&scrub->os_thread)) {
427 result = -EINPROGRESS;
428 } else if (!scrub->os_no_scrub) {
429 result = osd_scrub_start(dev);
430 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC "
431 "for "DFID", rc = %d [1]\n",
432 LDISKFS_SB(osd_sb(dev))->s_es->\
433 s_volume_name,PFID(fid), result);
434 if (result == 0 || result == -EALREADY)
435 result = -EINPROGRESS;
444 obj->oo_inode = inode;
445 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
446 if (dev->od_iop_mode) {
447 obj->oo_compat_dot_created = 1;
448 obj->oo_compat_dotdot_created = 1;
451 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
452 GOTO(out, result = 0);
454 LASSERT(obj->oo_hl_head == NULL);
455 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
456 if (obj->oo_hl_head == NULL) {
457 obj->oo_inode = NULL;
459 GOTO(out, result = -ENOMEM);
461 GOTO(out, result = 0);
464 LINVRNT(osd_invariant(obj));
469 * Concurrency: shouldn't matter.
471 static void osd_object_init0(struct osd_object *obj)
473 LASSERT(obj->oo_inode != NULL);
474 obj->oo_dt.do_body_ops = &osd_body_ops;
475 obj->oo_dt.do_lu.lo_header->loh_attr |=
476 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
480 * Concurrency: no concurrent access is possible that early in object
483 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
484 const struct lu_object_conf *conf)
486 struct osd_object *obj = osd_obj(l);
489 LINVRNT(osd_invariant(obj));
491 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
492 obj->oo_dt.do_body_ops = &osd_body_ops_new;
494 if (obj->oo_inode != NULL) {
495 osd_object_init0(obj);
496 } else if (fid_is_otable_it(&l->lo_header->loh_fid)) {
497 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
498 /* LFSCK iterator object is special without inode */
499 l->lo_header->loh_attr |= LOHA_EXISTS;
502 LINVRNT(osd_invariant(obj));
507 * Concurrency: no concurrent access is possible that late in object
510 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
512 struct osd_object *obj = osd_obj(l);
514 LINVRNT(osd_invariant(obj));
516 dt_object_fini(&obj->oo_dt);
517 if (obj->oo_hl_head != NULL)
518 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
523 * Concurrency: no concurrent access is possible that late in object
526 static void osd_index_fini(struct osd_object *o)
528 struct iam_container *bag;
530 if (o->oo_dir != NULL) {
531 bag = &o->oo_dir->od_container;
532 if (o->oo_inode != NULL) {
533 if (bag->ic_object == o->oo_inode)
534 iam_container_fini(bag);
536 OBD_FREE_PTR(o->oo_dir);
542 * Concurrency: no concurrent access is possible that late in object
543 * life-cycle (for all existing callers, that is. New callers have to provide
544 * their own locking.)
546 static int osd_inode_unlinked(const struct inode *inode)
548 return inode->i_nlink == 0;
552 OSD_TXN_OI_DELETE_CREDITS = 20,
553 OSD_TXN_INODE_DELETE_CREDITS = 20
560 #if OSD_THANDLE_STATS
562 * Set time when the handle is allocated
564 static void osd_th_alloced(struct osd_thandle *oth)
566 oth->oth_alloced = cfs_time_current();
570 * Set time when the handle started
572 static void osd_th_started(struct osd_thandle *oth)
574 oth->oth_started = cfs_time_current();
578 * Helper function to convert time interval to microseconds packed in
579 * long int (default time units for the counter in "stats" initialized
580 * by lu_time_init() )
582 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
586 cfs_duration_usec(cfs_time_sub(end, start), &val);
587 return val.tv_sec * 1000000 + val.tv_usec;
591 * Check whether the we deal with this handle for too long.
593 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
594 cfs_time_t alloced, cfs_time_t started,
597 cfs_time_t now = cfs_time_current();
599 LASSERT(dev != NULL);
601 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
602 interval_to_usec(alloced, started));
603 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
604 interval_to_usec(started, closed));
605 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
606 interval_to_usec(closed, now));
608 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
609 CWARN("transaction handle %p was open for too long: "
611 "alloced "CFS_TIME_T" ,"
612 "started "CFS_TIME_T" ,"
613 "closed "CFS_TIME_T"\n",
614 oth, now, alloced, started, closed);
615 libcfs_debug_dumpstack(NULL);
619 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
621 cfs_time_t __closed = cfs_time_current(); \
622 cfs_time_t __alloced = oth->oth_alloced; \
623 cfs_time_t __started = oth->oth_started; \
626 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
629 #else /* OSD_THANDLE_STATS */
631 #define osd_th_alloced(h) do {} while(0)
632 #define osd_th_started(h) do {} while(0)
633 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
635 #endif /* OSD_THANDLE_STATS */
638 * Concurrency: doesn't access mutable data.
640 static int osd_param_is_sane(const struct osd_device *dev,
641 const struct thandle *th)
643 struct osd_thandle *oh;
644 oh = container_of0(th, struct osd_thandle, ot_super);
645 return oh->ot_credits <= osd_journal(dev)->j_max_transaction_buffers;
649 * Concurrency: shouldn't matter.
651 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
652 static void osd_trans_commit_cb(struct super_block *sb,
653 struct journal_callback *jcb, int error)
655 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
658 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
659 struct thandle *th = &oh->ot_super;
660 struct lu_device *lud = &th->th_dev->dd_lu_dev;
661 struct dt_txn_commit_cb *dcb, *tmp;
663 LASSERT(oh->ot_handle == NULL);
666 CERROR("transaction @0x%p commit error: %d\n", th, error);
668 dt_txn_hook_commit(th);
670 /* call per-transaction callbacks if any */
671 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
672 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
673 "commit callback entry: magic=%x name='%s'\n",
674 dcb->dcb_magic, dcb->dcb_name);
675 cfs_list_del_init(&dcb->dcb_linkage);
676 dcb->dcb_func(NULL, th, dcb, error);
679 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
683 lu_context_exit(&th->th_ctx);
684 lu_context_fini(&th->th_ctx);
688 static struct thandle *osd_trans_create(const struct lu_env *env,
691 struct osd_thread_info *oti = osd_oti_get(env);
692 struct osd_iobuf *iobuf = &oti->oti_iobuf;
693 struct osd_thandle *oh;
697 /* on pending IO in this thread should left from prev. request */
698 LASSERT(cfs_atomic_read(&iobuf->dr_numreqs) == 0);
700 th = ERR_PTR(-ENOMEM);
701 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
703 oh->ot_quota_trans = &oti->oti_quota_trans;
704 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
708 th->th_tags = LCT_TX_HANDLE;
710 oti->oti_dev = osd_dt_dev(d);
711 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
718 * Concurrency: shouldn't matter.
720 int osd_trans_start(const struct lu_env *env, struct dt_device *d,
723 struct osd_thread_info *oti = osd_oti_get(env);
724 struct osd_device *dev = osd_dt_dev(d);
726 struct osd_thandle *oh;
731 LASSERT(current->journal_info == NULL);
733 oh = container_of0(th, struct osd_thandle, ot_super);
735 LASSERT(oh->ot_handle == NULL);
737 rc = dt_txn_hook_start(env, d, th);
741 if (!osd_param_is_sane(dev, th)) {
742 CWARN("%.16s: too many transaction credits (%d > %d)\n",
743 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
745 osd_journal(dev)->j_max_transaction_buffers);
746 /* XXX Limit the credits to 'max_transaction_buffers', and
747 * let the underlying filesystem to catch the error if
748 * we really need so many credits.
750 * This should be removed when we can calculate the
751 * credits precisely. */
752 oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
753 #ifdef OSD_TRACK_DECLARES
754 CERROR(" attr_set: %d, punch: %d, xattr_set: %d,\n",
755 oh->ot_declare_attr_set, oh->ot_declare_punch,
756 oh->ot_declare_xattr_set);
757 CERROR(" create: %d, ref_add: %d, ref_del: %d, write: %d\n",
758 oh->ot_declare_create, oh->ot_declare_ref_add,
759 oh->ot_declare_ref_del, oh->ot_declare_write);
760 CERROR(" insert: %d, delete: %d, destroy: %d\n",
761 oh->ot_declare_insert, oh->ot_declare_delete,
762 oh->ot_declare_destroy);
767 * XXX temporary stuff. Some abstraction layer should
770 jh = ldiskfs_journal_start_sb(osd_sb(dev), oh->ot_credits);
774 LASSERT(oti->oti_txns == 0);
775 lu_context_init(&th->th_ctx, th->th_tags);
776 lu_context_enter(&th->th_ctx);
778 lu_device_get(&d->dd_lu_dev);
779 oh->ot_dev_link = lu_ref_add(&d->dd_lu_dev.ld_reference,
791 * Concurrency: shouldn't matter.
793 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
796 struct osd_thandle *oh;
797 struct osd_thread_info *oti = osd_oti_get(env);
798 struct osd_iobuf *iobuf = &oti->oti_iobuf;
799 struct qsd_instance *qsd = oti->oti_dev->od_quota_slave;
802 oh = container_of0(th, struct osd_thandle, ot_super);
805 /* inform the quota slave device that the transaction is
807 qsd_op_end(env, qsd, oh->ot_quota_trans);
808 oh->ot_quota_trans = NULL;
810 if (oh->ot_handle != NULL) {
811 handle_t *hdl = oh->ot_handle;
814 * add commit callback
815 * notice we don't do this in osd_trans_start()
816 * as underlying transaction can change during truncate
818 osd_journal_callback_set(hdl, osd_trans_commit_cb,
821 LASSERT(oti->oti_txns == 1);
823 rc = dt_txn_hook_stop(env, th);
825 CERROR("Failure in transaction hook: %d\n", rc);
827 /* hook functions might modify th_sync */
828 hdl->h_sync = th->th_sync;
830 oh->ot_handle = NULL;
831 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
832 rc = ldiskfs_journal_stop(hdl));
834 CERROR("Failure to stop transaction: %d\n", rc);
839 /* as we want IO to journal and data IO be concurrent, we don't block
840 * awaiting data IO completion in osd_do_bio(), instead we wait here
841 * once transaction is submitted to the journal. all reqular requests
842 * don't do direct IO (except read/write), thus this wait_event becomes
845 * IMPORTANT: we have to wait till any IO submited by the thread is
846 * completed otherwise iobuf may be corrupted by different request
848 cfs_wait_event(iobuf->dr_wait,
849 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
851 rc = iobuf->dr_error;
856 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
858 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
861 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
862 LASSERT(&dcb->dcb_func != NULL);
863 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
869 * Called just before object is freed. Releases all resources except for
870 * object itself (that is released by osd_object_free()).
872 * Concurrency: no concurrent access is possible that late in object
875 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
877 struct osd_object *obj = osd_obj(l);
878 struct inode *inode = obj->oo_inode;
880 LINVRNT(osd_invariant(obj));
883 * If object is unlinked remove fid->ino mapping from object index.
889 obj->oo_inode = NULL;
894 * Concurrency: ->loo_object_release() is called under site spin-lock.
896 static void osd_object_release(const struct lu_env *env,
902 * Concurrency: shouldn't matter.
904 static int osd_object_print(const struct lu_env *env, void *cookie,
905 lu_printer_t p, const struct lu_object *l)
907 struct osd_object *o = osd_obj(l);
910 if (o->oo_dir != NULL)
911 d = o->oo_dir->od_container.ic_descr;
914 return (*p)(env, cookie,
915 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
917 o->oo_inode ? o->oo_inode->i_ino : 0UL,
918 o->oo_inode ? o->oo_inode->i_generation : 0,
919 d ? d->id_ops->id_name : "plain");
923 * Concurrency: shouldn't matter.
925 int osd_statfs(const struct lu_env *env, struct dt_device *d,
926 struct obd_statfs *sfs)
928 struct osd_device *osd = osd_dt_dev(d);
929 struct super_block *sb = osd_sb(osd);
930 struct kstatfs *ksfs;
933 if (unlikely(osd->od_mnt == NULL))
936 /* osd_lproc.c call this without env, allocate ksfs for that case */
937 if (unlikely(env == NULL)) {
942 ksfs = &osd_oti_get(env)->oti_ksfs;
945 cfs_spin_lock(&osd->od_osfs_lock);
947 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
948 result = sb->s_op->statfs(sb->s_root, ksfs);
949 if (likely(result == 0)) { /* N.B. statfs can't really fail */
950 osd->od_osfs_age = cfs_time_current_64();
951 statfs_pack(&osd->od_statfs, ksfs);
955 if (likely(result == 0))
956 *sfs = osd->od_statfs;
957 cfs_spin_unlock(&osd->od_osfs_lock);
959 if (unlikely(env == NULL))
966 * Concurrency: doesn't access mutable data.
968 static void osd_conf_get(const struct lu_env *env,
969 const struct dt_device *dev,
970 struct dt_device_param *param)
972 struct super_block *sb = osd_sb(osd_dt_dev(dev));
975 * XXX should be taken from not-yet-existing fs abstraction layer.
977 param->ddp_mnt = osd_dt_dev(dev)->od_mnt;
978 param->ddp_max_name_len = LDISKFS_NAME_LEN;
979 param->ddp_max_nlink = LDISKFS_LINK_MAX;
980 param->ddp_block_shift = sb->s_blocksize_bits;
981 param->ddp_mount_type = LDD_MT_LDISKFS;
982 param->ddp_mntopts = 0;
983 if (test_opt(sb, XATTR_USER))
984 param->ddp_mntopts |= MNTOPT_USERXATTR;
985 if (test_opt(sb, POSIX_ACL))
986 param->ddp_mntopts |= MNTOPT_ACL;
988 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
989 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
990 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE;
993 param->ddp_max_ea_size = sb->s_blocksize;
998 * Helper function to get and fill the buffer with input values.
1000 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
1004 buf = &osd_oti_get(env)->oti_buf;
1011 * Concurrency: shouldn't matter.
1013 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1015 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1016 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1020 * Start commit for OSD device.
1022 * An implementation of dt_commit_async method for OSD device.
1023 * Asychronously starts underlayng fs sync and thereby a transaction
1026 * \param env environment
1027 * \param d dt device
1029 * \see dt_device_operations
1031 static int osd_commit_async(const struct lu_env *env,
1032 struct dt_device *d)
1034 struct super_block *s = osd_sb(osd_dt_dev(d));
1037 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1038 RETURN(s->s_op->sync_fs(s, 0));
1042 * Concurrency: shouldn't matter.
1045 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1047 struct super_block *sb = osd_sb(osd_dt_dev(d));
1051 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1053 rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
1058 * Concurrency: serialization provided by callers.
1060 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1061 int mode, unsigned long timeout, __u32 alg,
1062 struct lustre_capa_key *keys)
1064 struct osd_device *dev = osd_dt_dev(d);
1067 dev->od_fl_capa = mode;
1068 dev->od_capa_timeout = timeout;
1069 dev->od_capa_alg = alg;
1070 dev->od_capa_keys = keys;
1075 * Concurrency: serialization provided by callers.
1077 static void osd_init_quota_ctxt(const struct lu_env *env, struct dt_device *d,
1078 struct dt_quota_ctxt *ctxt, void *data)
1080 struct obd_device *obd = (void *)ctxt;
1081 struct vfsmount *mnt = (struct vfsmount *)data;
1084 obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
1085 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1086 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1087 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1088 obd->obd_lvfs_ctxt.fs = get_ds();
1094 * Note: we do not count into QUOTA here.
1095 * If we mount with --data_journal we may need more.
1097 const int osd_dto_credits_noquota[DTO_NR] = {
1100 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1101 * SINGLEDATA_TRANS_BLOCKS(8)
1102 * XXX Note: maybe iam need more, since iam have more level than
1105 [DTO_INDEX_INSERT] = 16,
1106 [DTO_INDEX_DELETE] = 16,
1110 [DTO_INDEX_UPDATE] = 16,
1112 * Create a object. The same as create object in EXT3.
1113 * DATA_TRANS_BLOCKS(14) +
1114 * INDEX_EXTRA_BLOCKS(8) +
1115 * 3(inode bits, groups, GDT)
1117 [DTO_OBJECT_CREATE] = 25,
1119 * XXX: real credits to be fixed
1121 [DTO_OBJECT_DELETE] = 25,
1123 * Attr set credits (inode)
1125 [DTO_ATTR_SET_BASE] = 1,
1127 * Xattr set. The same as xattr of EXT3.
1128 * DATA_TRANS_BLOCKS(14)
1129 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1130 * are also counted in. Do not know why?
1132 [DTO_XATTR_SET] = 14,
1135 * credits for inode change during write.
1137 [DTO_WRITE_BASE] = 3,
1139 * credits for single block write.
1141 [DTO_WRITE_BLOCK] = 14,
1143 * Attr set credits for chown.
1144 * This is extra credits for setattr, and it is null without quota
1146 [DTO_ATTR_SET_CHOWN]= 0
1149 static const struct dt_device_operations osd_dt_ops = {
1150 .dt_root_get = osd_root_get,
1151 .dt_statfs = osd_statfs,
1152 .dt_trans_create = osd_trans_create,
1153 .dt_trans_start = osd_trans_start,
1154 .dt_trans_stop = osd_trans_stop,
1155 .dt_trans_cb_add = osd_trans_cb_add,
1156 .dt_conf_get = osd_conf_get,
1157 .dt_sync = osd_sync,
1159 .dt_commit_async = osd_commit_async,
1160 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1161 .dt_init_quota_ctxt= osd_init_quota_ctxt,
1164 static void osd_object_read_lock(const struct lu_env *env,
1165 struct dt_object *dt, unsigned role)
1167 struct osd_object *obj = osd_dt_obj(dt);
1168 struct osd_thread_info *oti = osd_oti_get(env);
1170 LINVRNT(osd_invariant(obj));
1172 LASSERT(obj->oo_owner != env);
1173 cfs_down_read_nested(&obj->oo_sem, role);
1175 LASSERT(obj->oo_owner == NULL);
1179 static void osd_object_write_lock(const struct lu_env *env,
1180 struct dt_object *dt, unsigned role)
1182 struct osd_object *obj = osd_dt_obj(dt);
1183 struct osd_thread_info *oti = osd_oti_get(env);
1185 LINVRNT(osd_invariant(obj));
1187 LASSERT(obj->oo_owner != env);
1188 cfs_down_write_nested(&obj->oo_sem, role);
1190 LASSERT(obj->oo_owner == NULL);
1191 obj->oo_owner = env;
1195 static void osd_object_read_unlock(const struct lu_env *env,
1196 struct dt_object *dt)
1198 struct osd_object *obj = osd_dt_obj(dt);
1199 struct osd_thread_info *oti = osd_oti_get(env);
1201 LINVRNT(osd_invariant(obj));
1203 LASSERT(oti->oti_r_locks > 0);
1205 cfs_up_read(&obj->oo_sem);
1208 static void osd_object_write_unlock(const struct lu_env *env,
1209 struct dt_object *dt)
1211 struct osd_object *obj = osd_dt_obj(dt);
1212 struct osd_thread_info *oti = osd_oti_get(env);
1214 LINVRNT(osd_invariant(obj));
1216 LASSERT(obj->oo_owner == env);
1217 LASSERT(oti->oti_w_locks > 0);
1219 obj->oo_owner = NULL;
1220 cfs_up_write(&obj->oo_sem);
1223 static int osd_object_write_locked(const struct lu_env *env,
1224 struct dt_object *dt)
1226 struct osd_object *obj = osd_dt_obj(dt);
1228 LINVRNT(osd_invariant(obj));
1230 return obj->oo_owner == env;
1233 static int capa_is_sane(const struct lu_env *env,
1234 struct osd_device *dev,
1235 struct lustre_capa *capa,
1236 struct lustre_capa_key *keys)
1238 struct osd_thread_info *oti = osd_oti_get(env);
1239 struct lustre_capa *tcapa = &oti->oti_capa;
1240 struct obd_capa *oc;
1244 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1246 if (capa_is_expired(oc)) {
1247 DEBUG_CAPA(D_ERROR, capa, "expired");
1254 if (capa_is_expired_sec(capa)) {
1255 DEBUG_CAPA(D_ERROR, capa, "expired");
1259 cfs_spin_lock(&capa_lock);
1260 for (i = 0; i < 2; i++) {
1261 if (keys[i].lk_keyid == capa->lc_keyid) {
1262 oti->oti_capa_key = keys[i];
1266 cfs_spin_unlock(&capa_lock);
1269 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1273 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1277 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1278 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1282 oc = capa_add(dev->od_capa_hash, capa);
1288 int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1289 struct lustre_capa *capa, __u64 opc)
1291 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1292 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1293 struct md_capainfo *ci;
1296 if (!dev->od_fl_capa)
1299 if (capa == BYPASS_CAPA)
1302 ci = md_capainfo(env);
1306 if (ci->mc_auth == LC_ID_NONE)
1310 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1314 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1315 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1320 if (!capa_opc_supported(capa, opc)) {
1321 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1325 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1326 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1333 static struct timespec *osd_inode_time(const struct lu_env *env,
1334 struct inode *inode, __u64 seconds)
1336 struct osd_thread_info *oti = osd_oti_get(env);
1337 struct timespec *t = &oti->oti_time;
1339 t->tv_sec = seconds;
1341 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1346 static void osd_inode_getattr(const struct lu_env *env,
1347 struct inode *inode, struct lu_attr *attr)
1349 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1350 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1351 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1353 attr->la_atime = LTIME_S(inode->i_atime);
1354 attr->la_mtime = LTIME_S(inode->i_mtime);
1355 attr->la_ctime = LTIME_S(inode->i_ctime);
1356 attr->la_mode = inode->i_mode;
1357 attr->la_size = i_size_read(inode);
1358 attr->la_blocks = inode->i_blocks;
1359 attr->la_uid = inode->i_uid;
1360 attr->la_gid = inode->i_gid;
1361 attr->la_flags = LDISKFS_I(inode)->i_flags;
1362 attr->la_nlink = inode->i_nlink;
1363 attr->la_rdev = inode->i_rdev;
1364 attr->la_blksize = 1 << inode->i_blkbits;
1365 attr->la_blkbits = inode->i_blkbits;
1368 static int osd_attr_get(const struct lu_env *env,
1369 struct dt_object *dt,
1370 struct lu_attr *attr,
1371 struct lustre_capa *capa)
1373 struct osd_object *obj = osd_dt_obj(dt);
1375 LASSERT(dt_object_exists(dt));
1376 LINVRNT(osd_invariant(obj));
1378 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1381 cfs_spin_lock(&obj->oo_guard);
1382 osd_inode_getattr(env, obj->oo_inode, attr);
1383 cfs_spin_unlock(&obj->oo_guard);
1387 static int osd_declare_attr_set(const struct lu_env *env,
1388 struct dt_object *dt,
1389 const struct lu_attr *attr,
1390 struct thandle *handle)
1392 struct osd_thandle *oh;
1393 struct osd_object *obj;
1394 struct osd_thread_info *info = osd_oti_get(env);
1395 struct lquota_id_info *qi = &info->oti_qi;
1401 LASSERT(dt != NULL);
1402 LASSERT(handle != NULL);
1404 obj = osd_dt_obj(dt);
1405 LASSERT(osd_invariant(obj));
1407 oh = container_of0(handle, struct osd_thandle, ot_super);
1408 LASSERT(oh->ot_handle == NULL);
1410 OSD_DECLARE_OP(oh, attr_set);
1411 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
1413 if (attr == NULL || obj->oo_inode == NULL)
1416 bspace = obj->oo_inode->i_blocks;
1417 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1418 bspace = toqb(bspace);
1420 /* Changing ownership is always preformed by super user, it should not
1423 * We still need to call the osd_declare_qid() to calculate the journal
1424 * credits for updating quota accounting files and to trigger quota
1425 * space adjustment once the operation is completed.*/
1426 if ((attr->la_valid & LA_UID) != 0 &&
1427 attr->la_uid != obj->oo_inode->i_uid) {
1428 qi->lqi_type = USRQUOTA;
1430 /* inode accounting */
1431 qi->lqi_is_blk = false;
1433 /* one more inode for the new owner ... */
1434 qi->lqi_id.qid_uid = attr->la_uid;
1436 allocated = (attr->la_uid == 0) ? true : false;
1437 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1438 if (rc == -EDQUOT || rc == -EINPROGRESS)
1443 /* and one less inode for the current uid */
1444 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1446 rc = osd_declare_qid(env, oh, qi, true, NULL);
1447 if (rc == -EDQUOT || rc == -EINPROGRESS)
1452 /* block accounting */
1453 qi->lqi_is_blk = true;
1455 /* more blocks for the new owner ... */
1456 qi->lqi_id.qid_uid = attr->la_uid;
1457 qi->lqi_space = bspace;
1458 allocated = (attr->la_uid == 0) ? true : false;
1459 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1460 if (rc == -EDQUOT || rc == -EINPROGRESS)
1465 /* and finally less blocks for the current owner */
1466 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1467 qi->lqi_space = -bspace;
1468 rc = osd_declare_qid(env, oh, qi, true, NULL);
1469 if (rc == -EDQUOT || rc == -EINPROGRESS)
1475 if (attr->la_valid & LA_GID &&
1476 attr->la_gid != obj->oo_inode->i_gid) {
1477 qi->lqi_type = GRPQUOTA;
1479 /* inode accounting */
1480 qi->lqi_is_blk = false;
1482 /* one more inode for the new group owner ... */
1483 qi->lqi_id.qid_gid = attr->la_gid;
1485 allocated = (attr->la_gid == 0) ? true : false;
1486 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1487 if (rc == -EDQUOT || rc == -EINPROGRESS)
1492 /* and one less inode for the current gid */
1493 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1495 rc = osd_declare_qid(env, oh, qi, true, NULL);
1496 if (rc == -EDQUOT || rc == -EINPROGRESS)
1501 /* block accounting */
1502 qi->lqi_is_blk = true;
1504 /* more blocks for the new owner ... */
1505 qi->lqi_id.qid_gid = attr->la_gid;
1506 qi->lqi_space = bspace;
1507 allocated = (attr->la_gid == 0) ? true : false;
1508 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1509 if (rc == -EDQUOT || rc == -EINPROGRESS)
1514 /* and finally less blocks for the current owner */
1515 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1516 qi->lqi_space = -bspace;
1517 rc = osd_declare_qid(env, oh, qi, true, NULL);
1518 if (rc == -EDQUOT || rc == -EINPROGRESS)
1527 static int osd_inode_setattr(const struct lu_env *env,
1528 struct inode *inode, const struct lu_attr *attr)
1532 bits = attr->la_valid;
1534 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1536 if (bits & LA_ATIME)
1537 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1538 if (bits & LA_CTIME)
1539 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1540 if (bits & LA_MTIME)
1541 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1542 if (bits & LA_SIZE) {
1543 LDISKFS_I(inode)->i_disksize = attr->la_size;
1544 i_size_write(inode, attr->la_size);
1548 /* OSD should not change "i_blocks" which is used by quota.
1549 * "i_blocks" should be changed by ldiskfs only. */
1550 if (bits & LA_BLOCKS)
1551 inode->i_blocks = attr->la_blocks;
1554 inode->i_mode = (inode->i_mode & S_IFMT) |
1555 (attr->la_mode & ~S_IFMT);
1557 inode->i_uid = attr->la_uid;
1559 inode->i_gid = attr->la_gid;
1560 if (bits & LA_NLINK)
1561 inode->i_nlink = attr->la_nlink;
1563 inode->i_rdev = attr->la_rdev;
1565 if (bits & LA_FLAGS) {
1566 /* always keep S_NOCMTIME */
1567 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1573 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1575 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1576 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1581 if (attr->la_valid & LA_UID)
1582 iattr.ia_valid |= ATTR_UID;
1583 if (attr->la_valid & LA_GID)
1584 iattr.ia_valid |= ATTR_GID;
1585 iattr.ia_uid = attr->la_uid;
1586 iattr.ia_gid = attr->la_gid;
1588 rc = ll_vfs_dq_transfer(inode, &iattr);
1590 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1591 "enforcement enabled on the ldiskfs filesystem?",
1592 inode->i_sb->s_id, rc);
1599 static int osd_attr_set(const struct lu_env *env,
1600 struct dt_object *dt,
1601 const struct lu_attr *attr,
1602 struct thandle *handle,
1603 struct lustre_capa *capa)
1605 struct osd_object *obj = osd_dt_obj(dt);
1606 struct inode *inode;
1609 LASSERT(handle != NULL);
1610 LASSERT(dt_object_exists(dt));
1611 LASSERT(osd_invariant(obj));
1613 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1616 OSD_EXEC_OP(handle, attr_set);
1618 inode = obj->oo_inode;
1619 if (!osd_dt_dev(handle->th_dev)->od_is_md) {
1621 rc = osd_quota_transfer(inode, attr);
1625 #ifdef HAVE_QUOTA_SUPPORT
1626 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1627 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1628 struct osd_ctxt *save = &osd_oti_get(env)->oti_ctxt;
1633 if (attr->la_valid & LA_UID)
1634 iattr.ia_valid |= ATTR_UID;
1635 if (attr->la_valid & LA_GID)
1636 iattr.ia_valid |= ATTR_GID;
1637 iattr.ia_uid = attr->la_uid;
1638 iattr.ia_gid = attr->la_gid;
1639 osd_push_ctxt(env, save, 1);
1640 rc = ll_vfs_dq_transfer(inode, &iattr) ? -EDQUOT : 0;
1641 osd_pop_ctxt(save, 1);
1647 cfs_spin_lock(&obj->oo_guard);
1648 rc = osd_inode_setattr(env, inode, attr);
1649 cfs_spin_unlock(&obj->oo_guard);
1652 inode->i_sb->s_op->dirty_inode(inode);
1656 struct dentry *osd_child_dentry_get(const struct lu_env *env,
1657 struct osd_object *obj,
1658 const char *name, const int namelen)
1660 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1663 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1665 struct dt_allocation_hint *hint,
1669 struct osd_device *osd = osd_obj2dev(obj);
1670 struct osd_thandle *oth;
1671 struct dt_object *parent = NULL;
1672 struct inode *inode;
1673 #ifdef HAVE_QUOTA_SUPPORT
1674 struct osd_ctxt *save = &info->oti_ctxt;
1677 LINVRNT(osd_invariant(obj));
1678 LASSERT(obj->oo_inode == NULL);
1679 LASSERT(obj->oo_hl_head == NULL);
1681 if (S_ISDIR(mode) && ldiskfs_pdo) {
1682 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1683 if (obj->oo_hl_head == NULL)
1687 oth = container_of(th, struct osd_thandle, ot_super);
1688 LASSERT(oth->ot_handle->h_transaction != NULL);
1690 if (hint && hint->dah_parent)
1691 parent = hint->dah_parent;
1693 #ifdef HAVE_QUOTA_SUPPORT
1694 osd_push_ctxt(info->oti_env, save, osd_dt_dev(th->th_dev)->od_is_md);
1696 inode = ldiskfs_create_inode(oth->ot_handle,
1697 parent ? osd_dt_obj(parent)->oo_inode :
1698 osd_sb(osd)->s_root->d_inode,
1700 #ifdef HAVE_QUOTA_SUPPORT
1701 osd_pop_ctxt(save, osd_dt_dev(th->th_dev)->od_is_md);
1703 if (!IS_ERR(inode)) {
1704 /* Do not update file c/mtime in ldiskfs.
1705 * NB: don't need any lock because no contention at this
1707 inode->i_flags |= S_NOCMTIME;
1708 inode->i_state |= I_LUSTRE_NOSCRUB;
1709 obj->oo_inode = inode;
1712 if (obj->oo_hl_head != NULL) {
1713 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1714 obj->oo_hl_head = NULL;
1716 result = PTR_ERR(inode);
1718 LINVRNT(osd_invariant(obj));
1726 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1727 struct lu_attr *attr,
1728 struct dt_allocation_hint *hint,
1729 struct dt_object_format *dof,
1733 struct osd_thandle *oth;
1734 struct osd_device *osd = osd_obj2dev(obj);
1735 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1737 LASSERT(S_ISDIR(attr->la_mode));
1739 oth = container_of(th, struct osd_thandle, ot_super);
1740 LASSERT(oth->ot_handle->h_transaction != NULL);
1741 result = osd_mkfile(info, obj, mode, hint, th);
1742 if (result == 0 && osd->od_iop_mode == 0) {
1743 LASSERT(obj->oo_inode != NULL);
1745 * XXX uh-oh... call low-level iam function directly.
1748 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1749 sizeof (struct osd_fid_pack),
1755 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1756 struct lu_attr *attr,
1757 struct dt_allocation_hint *hint,
1758 struct dt_object_format *dof,
1762 struct osd_thandle *oth;
1763 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1765 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1767 LASSERT(S_ISREG(attr->la_mode));
1769 oth = container_of(th, struct osd_thandle, ot_super);
1770 LASSERT(oth->ot_handle->h_transaction != NULL);
1772 result = osd_mkfile(info, obj, mode, hint, th);
1774 LASSERT(obj->oo_inode != NULL);
1775 if (feat->dif_flags & DT_IND_VARKEY)
1776 result = iam_lvar_create(obj->oo_inode,
1777 feat->dif_keysize_max,
1779 feat->dif_recsize_max,
1782 result = iam_lfix_create(obj->oo_inode,
1783 feat->dif_keysize_max,
1785 feat->dif_recsize_max,
1792 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1793 struct lu_attr *attr,
1794 struct dt_allocation_hint *hint,
1795 struct dt_object_format *dof,
1798 LASSERT(S_ISREG(attr->la_mode));
1799 return osd_mkfile(info, obj, (attr->la_mode &
1800 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1803 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1804 struct lu_attr *attr,
1805 struct dt_allocation_hint *hint,
1806 struct dt_object_format *dof,
1809 LASSERT(S_ISLNK(attr->la_mode));
1810 return osd_mkfile(info, obj, (attr->la_mode &
1811 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1814 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1815 struct lu_attr *attr,
1816 struct dt_allocation_hint *hint,
1817 struct dt_object_format *dof,
1820 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1823 LINVRNT(osd_invariant(obj));
1824 LASSERT(obj->oo_inode == NULL);
1825 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1826 S_ISFIFO(mode) || S_ISSOCK(mode));
1828 result = osd_mkfile(info, obj, mode, hint, th);
1830 LASSERT(obj->oo_inode != NULL);
1832 * This inode should be marked dirty for i_rdev. Currently
1833 * that is done in the osd_attr_init().
1835 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1837 LINVRNT(osd_invariant(obj));
1841 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1843 struct dt_allocation_hint *hint,
1844 struct dt_object_format *dof,
1847 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1849 osd_obj_type_f result;
1865 result = osd_mk_index;
1876 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1877 struct dt_object *parent, struct dt_object *child,
1878 cfs_umode_t child_mode)
1882 memset(ah, 0, sizeof(*ah));
1883 ah->dah_parent = parent;
1884 ah->dah_mode = child_mode;
1887 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
1888 struct lu_attr *attr, struct dt_object_format *dof)
1890 struct inode *inode = obj->oo_inode;
1891 __u64 valid = attr->la_valid;
1894 attr->la_valid &= ~(LA_TYPE | LA_MODE);
1896 if (dof->dof_type != DFT_NODE)
1897 attr->la_valid &= ~LA_RDEV;
1898 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
1899 attr->la_valid &= ~LA_ATIME;
1900 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
1901 attr->la_valid &= ~LA_CTIME;
1902 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
1903 attr->la_valid &= ~LA_MTIME;
1905 if (!osd_obj2dev(obj)->od_is_md) {
1907 result = osd_quota_transfer(inode, attr);
1911 #ifdef HAVE_QUOTA_SUPPORT
1912 attr->la_valid &= ~(LA_UID | LA_GID);
1916 if (attr->la_valid != 0) {
1917 result = osd_inode_setattr(info->oti_env, inode, attr);
1919 * The osd_inode_setattr() should always succeed here. The
1920 * only error that could be returned is EDQUOT when we are
1921 * trying to change the UID or GID of the inode. However, this
1922 * should not happen since quota enforcement is no longer
1923 * enabled on ldiskfs (lquota takes care of it).
1925 LASSERTF(result == 0, "%d", result);
1926 inode->i_sb->s_op->dirty_inode(inode);
1929 attr->la_valid = valid;
1933 * Helper function for osd_object_create()
1935 * \retval 0, on success
1937 static int __osd_object_create(struct osd_thread_info *info,
1938 struct osd_object *obj, struct lu_attr *attr,
1939 struct dt_allocation_hint *hint,
1940 struct dt_object_format *dof,
1946 /* we drop umask so that permissions we pass are not affected */
1947 umask = current->fs->umask;
1948 current->fs->umask = 0;
1950 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1953 osd_attr_init(info, obj, attr, dof);
1954 osd_object_init0(obj);
1956 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1957 unlock_new_inode(obj->oo_inode);
1960 /* restore previous umask value */
1961 current->fs->umask = umask;
1967 * Helper function for osd_object_create()
1969 * \retval 0, on success
1971 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1972 const struct lu_fid *fid, struct thandle *th)
1974 struct osd_thread_info *info = osd_oti_get(env);
1975 struct osd_inode_id *id = &info->oti_id;
1976 struct osd_device *osd = osd_obj2dev(obj);
1978 LASSERT(obj->oo_inode != NULL);
1980 if (osd->od_is_md) {
1981 struct md_ucred *uc = md_ucred(env);
1982 LASSERT(uc != NULL);
1985 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
1986 return osd_oi_insert(info, osd, fid, id, th);
1989 static int osd_declare_object_create(const struct lu_env *env,
1990 struct dt_object *dt,
1991 struct lu_attr *attr,
1992 struct dt_allocation_hint *hint,
1993 struct dt_object_format *dof,
1994 struct thandle *handle)
1996 struct osd_thandle *oh;
2000 LASSERT(handle != NULL);
2002 oh = container_of0(handle, struct osd_thandle, ot_super);
2003 LASSERT(oh->ot_handle == NULL);
2005 OSD_DECLARE_OP(oh, create);
2006 oh->ot_credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
2007 /* XXX: So far, only normal fid needs be inserted into the oi,
2008 * things could be changed later. Revise following code then. */
2009 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
2010 OSD_DECLARE_OP(oh, insert);
2011 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
2012 /* Reuse idle OI block may cause additional one OI block
2014 oh->ot_credits += 1;
2016 /* If this is directory, then we expect . and .. to be inserted as
2017 * well. The one directory block always needs to be created for the
2018 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2019 * block), there is no danger of needing a tree for the first block.
2021 if (attr && S_ISDIR(attr->la_mode)) {
2022 OSD_DECLARE_OP(oh, insert);
2023 OSD_DECLARE_OP(oh, insert);
2024 oh->ot_credits += osd_dto_credits_noquota[DTO_WRITE_BASE];
2030 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2031 false, false, NULL, false);
2035 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2036 struct lu_attr *attr,
2037 struct dt_allocation_hint *hint,
2038 struct dt_object_format *dof,
2041 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2042 struct osd_object *obj = osd_dt_obj(dt);
2043 struct osd_thread_info *info = osd_oti_get(env);
2048 LINVRNT(osd_invariant(obj));
2049 LASSERT(!dt_object_exists(dt));
2050 LASSERT(osd_write_locked(env, obj));
2051 LASSERT(th != NULL);
2053 if (unlikely(fid_is_acct(fid)))
2054 /* Quota files can't be created from the kernel any more,
2055 * 'tune2fs -O quota' will take care of creating them */
2058 OSD_EXEC_OP(th, create);
2060 result = __osd_object_create(info, obj, attr, hint, dof, th);
2062 result = __osd_oi_insert(env, obj, fid, th);
2064 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2065 LASSERT(osd_invariant(obj));
2070 * Called to destroy on-disk representation of the object
2072 * Concurrency: must be locked
2074 static int osd_declare_object_destroy(const struct lu_env *env,
2075 struct dt_object *dt,
2078 struct osd_object *obj = osd_dt_obj(dt);
2079 struct inode *inode = obj->oo_inode;
2080 struct osd_thandle *oh;
2084 oh = container_of0(th, struct osd_thandle, ot_super);
2085 LASSERT(oh->ot_handle == NULL);
2088 OSD_DECLARE_OP(oh, destroy);
2089 OSD_DECLARE_OP(oh, delete);
2090 oh->ot_credits += osd_dto_credits_noquota[DTO_OBJECT_DELETE];
2091 /* XXX: So far, only normal fid needs to be inserted into the OI,
2092 * so only normal fid needs to be removed from the OI also. */
2093 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
2094 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
2095 /* Recycle idle OI leaf may cause additional three OI blocks
2097 oh->ot_credits += 3;
2100 /* one less inode */
2101 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2102 false, true, NULL, false);
2105 /* data to be truncated */
2106 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh, true,
2111 static int osd_object_destroy(const struct lu_env *env,
2112 struct dt_object *dt,
2115 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2116 struct osd_object *obj = osd_dt_obj(dt);
2117 struct inode *inode = obj->oo_inode;
2118 struct osd_device *osd = osd_obj2dev(obj);
2119 struct osd_thandle *oh;
2123 oh = container_of0(th, struct osd_thandle, ot_super);
2124 LASSERT(oh->ot_handle);
2126 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2128 if (unlikely(fid_is_acct(fid)))
2131 /* Parallel control for OI scrub. For most of cases, there is no
2132 * lock contention. So it will not affect unlink performance. */
2133 cfs_mutex_lock(&inode->i_mutex);
2134 if (S_ISDIR(inode->i_mode)) {
2135 LASSERT(osd_inode_unlinked(inode) ||
2136 inode->i_nlink == 1);
2137 cfs_spin_lock(&obj->oo_guard);
2139 cfs_spin_unlock(&obj->oo_guard);
2140 inode->i_sb->s_op->dirty_inode(inode);
2142 LASSERT(osd_inode_unlinked(inode));
2145 OSD_EXEC_OP(th, destroy);
2147 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2148 cfs_mutex_unlock(&inode->i_mutex);
2150 /* XXX: add to ext3 orphan list */
2151 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2153 /* not needed in the cache anymore */
2154 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2160 * Helper function for osd_xattr_set()
2162 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2163 const struct lu_buf *buf, const char *name, int fl)
2165 struct osd_object *obj = osd_dt_obj(dt);
2166 struct inode *inode = obj->oo_inode;
2167 struct osd_thread_info *info = osd_oti_get(env);
2168 struct dentry *dentry = &info->oti_child_dentry;
2172 LASSERT(dt_object_exists(dt));
2173 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2175 if (fl & LU_XATTR_REPLACE)
2176 fs_flags |= XATTR_REPLACE;
2178 if (fl & LU_XATTR_CREATE)
2179 fs_flags |= XATTR_CREATE;
2181 dentry->d_inode = inode;
2182 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2183 buf->lb_len, fs_flags);
2188 * Put the fid into lustre_mdt_attrs, and then place the structure
2189 * inode's ea. This fid should not be altered during the life time
2192 * \retval +ve, on success
2193 * \retval -ve, on error
2195 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2197 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2198 const struct lu_fid *fid)
2200 struct osd_thread_info *info = osd_oti_get(env);
2201 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2203 lustre_lma_init(mdt_attrs, fid);
2204 lustre_lma_swab(mdt_attrs);
2205 return __osd_xattr_set(env, dt,
2206 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2207 XATTR_NAME_LMA, LU_XATTR_CREATE);
2212 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2213 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2214 * To have compatilibility with 1.8 ldiskfs driver we need to have
2215 * magic number at start of fid data.
2216 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2219 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2220 const struct dt_rec *fid)
2222 param->edp_magic = LDISKFS_LUFID_MAGIC;
2223 param->edp_len = sizeof(struct lu_fid) + 1;
2225 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2226 (struct lu_fid *)fid);
2230 * Try to read the fid from inode ea into dt_rec, if return value
2231 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2233 * \param fid object fid.
2235 * \retval 0 on success
2237 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2238 __u32 ino, struct lu_fid *fid,
2239 struct osd_inode_id *id)
2241 struct osd_thread_info *info = osd_oti_get(env);
2242 struct inode *inode;
2245 osd_id_gen(id, ino, OSD_OII_NOGEN);
2246 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2248 RETURN(PTR_ERR(inode));
2255 * OSD layer object create function for interoperability mode (b11826).
2256 * This is mostly similar to osd_object_create(). Only difference being, fid is
2257 * inserted into inode ea here.
2259 * \retval 0, on success
2260 * \retval -ve, on error
2262 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2263 struct lu_attr *attr,
2264 struct dt_allocation_hint *hint,
2265 struct dt_object_format *dof,
2268 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2269 struct osd_object *obj = osd_dt_obj(dt);
2270 struct osd_thread_info *info = osd_oti_get(env);
2275 LASSERT(osd_invariant(obj));
2276 LASSERT(!dt_object_exists(dt));
2277 LASSERT(osd_write_locked(env, obj));
2278 LASSERT(th != NULL);
2280 if (unlikely(fid_is_acct(fid)))
2281 /* Quota files can't be created from the kernel any more,
2282 * 'tune2fs -O quota' will take care of creating them */
2285 OSD_EXEC_OP(th, create);
2287 result = __osd_object_create(info, obj, attr, hint, dof, th);
2288 /* objects under osd root shld have igif fid, so dont add fid EA */
2289 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2290 result = osd_ea_fid_set(env, dt, fid);
2293 result = __osd_oi_insert(env, obj, fid, th);
2295 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2296 LINVRNT(osd_invariant(obj));
2300 static int osd_declare_object_ref_add(const struct lu_env *env,
2301 struct dt_object *dt,
2302 struct thandle *handle)
2304 struct osd_thandle *oh;
2306 /* it's possible that object doesn't exist yet */
2307 LASSERT(handle != NULL);
2309 oh = container_of0(handle, struct osd_thandle, ot_super);
2310 LASSERT(oh->ot_handle == NULL);
2312 OSD_DECLARE_OP(oh, ref_add);
2313 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2319 * Concurrency: @dt is write locked.
2321 static int osd_object_ref_add(const struct lu_env *env,
2322 struct dt_object *dt, struct thandle *th)
2324 struct osd_object *obj = osd_dt_obj(dt);
2325 struct inode *inode = obj->oo_inode;
2327 LINVRNT(osd_invariant(obj));
2328 LASSERT(dt_object_exists(dt));
2329 LASSERT(osd_write_locked(env, obj));
2330 LASSERT(th != NULL);
2332 OSD_EXEC_OP(th, ref_add);
2335 * DIR_NLINK feature is set for compatibility reasons if:
2336 * 1) nlinks > LDISKFS_LINK_MAX, or
2337 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2339 * It is easier to always set this flag (rather than check and set),
2340 * since it has less overhead, and the superblock will be dirtied
2341 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2342 * do not actually care whether this flag is set or not.
2344 cfs_spin_lock(&obj->oo_guard);
2346 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2347 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2348 inode->i_nlink == 2)
2351 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2352 cfs_spin_unlock(&obj->oo_guard);
2353 inode->i_sb->s_op->dirty_inode(inode);
2354 LINVRNT(osd_invariant(obj));
2359 static int osd_declare_object_ref_del(const struct lu_env *env,
2360 struct dt_object *dt,
2361 struct thandle *handle)
2363 struct osd_thandle *oh;
2365 LASSERT(dt_object_exists(dt));
2366 LASSERT(handle != NULL);
2368 oh = container_of0(handle, struct osd_thandle, ot_super);
2369 LASSERT(oh->ot_handle == NULL);
2371 OSD_DECLARE_OP(oh, ref_del);
2372 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2378 * Concurrency: @dt is write locked.
2380 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2383 struct osd_object *obj = osd_dt_obj(dt);
2384 struct inode *inode = obj->oo_inode;
2386 LINVRNT(osd_invariant(obj));
2387 LASSERT(dt_object_exists(dt));
2388 LASSERT(osd_write_locked(env, obj));
2389 LASSERT(th != NULL);
2391 OSD_EXEC_OP(th, ref_del);
2393 cfs_spin_lock(&obj->oo_guard);
2394 LASSERT(inode->i_nlink > 0);
2396 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2397 * then the nlink count is 1. Don't let it be set to 0 or the directory
2398 * inode will be deleted incorrectly. */
2399 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2401 cfs_spin_unlock(&obj->oo_guard);
2402 inode->i_sb->s_op->dirty_inode(inode);
2403 LINVRNT(osd_invariant(obj));
2409 * Get the 64-bit version for an inode.
2411 static int osd_object_version_get(const struct lu_env *env,
2412 struct dt_object *dt, dt_obj_version_t *ver)
2414 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2416 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2417 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2418 *ver = LDISKFS_I(inode)->i_fs_version;
2423 * Concurrency: @dt is read locked.
2425 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2426 struct lu_buf *buf, const char *name,
2427 struct lustre_capa *capa)
2429 struct osd_object *obj = osd_dt_obj(dt);
2430 struct inode *inode = obj->oo_inode;
2431 struct osd_thread_info *info = osd_oti_get(env);
2432 struct dentry *dentry = &info->oti_obj_dentry;
2434 /* version get is not real XATTR but uses xattr API */
2435 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2436 /* for version we are just using xattr API but change inode
2438 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2439 osd_object_version_get(env, dt, buf->lb_buf);
2440 return sizeof(dt_obj_version_t);
2443 LASSERT(dt_object_exists(dt));
2444 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2446 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2449 dentry->d_inode = inode;
2450 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2454 static int osd_declare_xattr_set(const struct lu_env *env,
2455 struct dt_object *dt,
2456 const struct lu_buf *buf, const char *name,
2457 int fl, struct thandle *handle)
2459 struct osd_thandle *oh;
2461 LASSERT(handle != NULL);
2463 oh = container_of0(handle, struct osd_thandle, ot_super);
2464 LASSERT(oh->ot_handle == NULL);
2466 OSD_DECLARE_OP(oh, xattr_set);
2467 if (strcmp(name, XATTR_NAME_VERSION) == 0)
2468 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2470 oh->ot_credits += osd_dto_credits_noquota[DTO_XATTR_SET];
2476 * Set the 64-bit version for object
2478 static void osd_object_version_set(const struct lu_env *env,
2479 struct dt_object *dt,
2480 dt_obj_version_t *new_version)
2482 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2484 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2485 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2487 LDISKFS_I(inode)->i_fs_version = *new_version;
2488 /** Version is set after all inode operations are finished,
2489 * so we should mark it dirty here */
2490 inode->i_sb->s_op->dirty_inode(inode);
2494 * Concurrency: @dt is write locked.
2496 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2497 const struct lu_buf *buf, const char *name, int fl,
2498 struct thandle *handle, struct lustre_capa *capa)
2500 LASSERT(handle != NULL);
2502 /* version set is not real XATTR */
2503 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2504 /* for version we are just using xattr API but change inode
2506 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2507 osd_object_version_set(env, dt, buf->lb_buf);
2508 return sizeof(dt_obj_version_t);
2511 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2514 OSD_EXEC_OP(handle, xattr_set);
2515 return __osd_xattr_set(env, dt, buf, name, fl);
2519 * Concurrency: @dt is read locked.
2521 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2522 struct lu_buf *buf, struct lustre_capa *capa)
2524 struct osd_object *obj = osd_dt_obj(dt);
2525 struct inode *inode = obj->oo_inode;
2526 struct osd_thread_info *info = osd_oti_get(env);
2527 struct dentry *dentry = &info->oti_obj_dentry;
2529 LASSERT(dt_object_exists(dt));
2530 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2531 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2533 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2536 dentry->d_inode = inode;
2537 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2540 static int osd_declare_xattr_del(const struct lu_env *env,
2541 struct dt_object *dt, const char *name,
2542 struct thandle *handle)
2544 struct osd_thandle *oh;
2546 LASSERT(dt_object_exists(dt));
2547 LASSERT(handle != NULL);
2549 oh = container_of0(handle, struct osd_thandle, ot_super);
2550 LASSERT(oh->ot_handle == NULL);
2552 OSD_DECLARE_OP(oh, xattr_set);
2553 oh->ot_credits += osd_dto_credits_noquota[DTO_XATTR_SET];
2559 * Concurrency: @dt is write locked.
2561 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2562 const char *name, struct thandle *handle,
2563 struct lustre_capa *capa)
2565 struct osd_object *obj = osd_dt_obj(dt);
2566 struct inode *inode = obj->oo_inode;
2567 struct osd_thread_info *info = osd_oti_get(env);
2568 struct dentry *dentry = &info->oti_obj_dentry;
2571 LASSERT(dt_object_exists(dt));
2572 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2573 LASSERT(osd_write_locked(env, obj));
2574 LASSERT(handle != NULL);
2576 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2579 OSD_EXEC_OP(handle, xattr_set);
2581 dentry->d_inode = inode;
2582 rc = inode->i_op->removexattr(dentry, name);
2586 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2587 struct dt_object *dt,
2588 struct lustre_capa *old,
2591 struct osd_thread_info *info = osd_oti_get(env);
2592 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2593 struct osd_object *obj = osd_dt_obj(dt);
2594 struct osd_device *dev = osd_obj2dev(obj);
2595 struct lustre_capa_key *key = &info->oti_capa_key;
2596 struct lustre_capa *capa = &info->oti_capa;
2597 struct obd_capa *oc;
2598 struct md_capainfo *ci;
2602 if (!dev->od_fl_capa)
2603 RETURN(ERR_PTR(-ENOENT));
2605 LASSERT(dt_object_exists(dt));
2606 LINVRNT(osd_invariant(obj));
2608 /* renewal sanity check */
2609 if (old && osd_object_auth(env, dt, old, opc))
2610 RETURN(ERR_PTR(-EACCES));
2612 ci = md_capainfo(env);
2614 RETURN(ERR_PTR(-ENOENT));
2616 switch (ci->mc_auth) {
2620 capa->lc_uid = obj->oo_inode->i_uid;
2621 capa->lc_gid = obj->oo_inode->i_gid;
2622 capa->lc_flags = LC_ID_PLAIN;
2624 case LC_ID_CONVERT: {
2627 s[0] = obj->oo_inode->i_uid;
2628 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2629 s[2] = obj->oo_inode->i_gid;
2630 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2631 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2633 RETURN(ERR_PTR(rc));
2635 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2636 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2637 capa->lc_flags = LC_ID_CONVERT;
2641 RETURN(ERR_PTR(-EINVAL));
2644 capa->lc_fid = *fid;
2646 capa->lc_flags |= dev->od_capa_alg << 24;
2647 capa->lc_timeout = dev->od_capa_timeout;
2648 capa->lc_expiry = 0;
2650 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2652 LASSERT(!capa_is_expired(oc));
2656 cfs_spin_lock(&capa_lock);
2657 *key = dev->od_capa_keys[1];
2658 cfs_spin_unlock(&capa_lock);
2660 capa->lc_keyid = key->lk_keyid;
2661 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2663 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2665 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2666 RETURN(ERR_PTR(rc));
2669 oc = capa_add(dev->od_capa_hash, capa);
2673 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2675 struct osd_object *obj = osd_dt_obj(dt);
2676 struct inode *inode = obj->oo_inode;
2677 struct osd_thread_info *info = osd_oti_get(env);
2678 struct dentry *dentry = &info->oti_obj_dentry;
2679 struct file *file = &info->oti_file;
2684 dentry->d_inode = inode;
2685 file->f_dentry = dentry;
2686 file->f_mapping = inode->i_mapping;
2687 file->f_op = inode->i_fop;
2688 mutex_lock(&inode->i_mutex);
2689 rc = file->f_op->fsync(file, dentry, 0);
2690 mutex_unlock(&inode->i_mutex);
2694 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2697 struct osd_object *obj = osd_dt_obj(dt);
2700 *data = (void *)obj->oo_inode;
2708 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2709 const struct dt_index_features *feat)
2711 struct iam_descr *descr;
2713 if (osd_object_is_root(o))
2714 return feat == &dt_directory_features;
2716 LASSERT(o->oo_dir != NULL);
2718 descr = o->oo_dir->od_container.ic_descr;
2719 if (feat == &dt_directory_features) {
2720 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2726 feat->dif_keysize_min <= descr->id_key_size &&
2727 descr->id_key_size <= feat->dif_keysize_max &&
2728 feat->dif_recsize_min <= descr->id_rec_size &&
2729 descr->id_rec_size <= feat->dif_recsize_max &&
2730 !(feat->dif_flags & (DT_IND_VARKEY |
2731 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2732 ergo(feat->dif_flags & DT_IND_UPDATE,
2733 1 /* XXX check that object (and file system) is
2738 static int osd_iam_container_init(const struct lu_env *env,
2739 struct osd_object *obj,
2740 struct osd_directory *dir)
2742 struct iam_container *bag = &dir->od_container;
2745 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2749 result = iam_container_setup(bag);
2751 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2753 iam_container_fini(bag);
2760 * Concurrency: no external locking is necessary.
2762 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2763 const struct dt_index_features *feat)
2767 struct osd_object *obj = osd_dt_obj(dt);
2768 struct osd_device *osd = osd_obj2dev(obj);
2770 LINVRNT(osd_invariant(obj));
2771 LASSERT(dt_object_exists(dt));
2773 if (osd_object_is_root(obj)) {
2774 dt->do_index_ops = &osd_index_ea_ops;
2776 } else if (feat == &dt_directory_features && osd->od_iop_mode) {
2777 dt->do_index_ops = &osd_index_ea_ops;
2778 if (S_ISDIR(obj->oo_inode->i_mode))
2783 } else if (unlikely(feat == &dt_otable_features)) {
2784 dt->do_index_ops = &osd_otable_ops;
2786 } else if (feat == &dt_acct_features) {
2787 dt->do_index_ops = &osd_acct_index_ops;
2790 } else if (!osd_has_index(obj)) {
2791 struct osd_directory *dir;
2796 cfs_spin_lock(&obj->oo_guard);
2797 if (obj->oo_dir == NULL)
2801 * Concurrent thread allocated container data.
2804 cfs_spin_unlock(&obj->oo_guard);
2806 * Now, that we have container data, serialize its
2809 cfs_down_write(&obj->oo_ext_idx_sem);
2811 * recheck under lock.
2813 if (!osd_has_index(obj))
2814 result = osd_iam_container_init(env, obj, dir);
2817 cfs_up_write(&obj->oo_ext_idx_sem);
2825 if (result == 0 && skip_iam == 0) {
2826 if (!osd_iam_index_probe(env, obj, feat))
2829 LINVRNT(osd_invariant(obj));
2831 if (is_quota_glb_feat(feat))
2832 result = osd_quota_migration(env, dt, feat);
2837 static int osd_otable_it_attr_get(const struct lu_env *env,
2838 struct dt_object *dt,
2839 struct lu_attr *attr,
2840 struct lustre_capa *capa)
2846 static const struct dt_object_operations osd_obj_ops = {
2847 .do_read_lock = osd_object_read_lock,
2848 .do_write_lock = osd_object_write_lock,
2849 .do_read_unlock = osd_object_read_unlock,
2850 .do_write_unlock = osd_object_write_unlock,
2851 .do_write_locked = osd_object_write_locked,
2852 .do_attr_get = osd_attr_get,
2853 .do_declare_attr_set = osd_declare_attr_set,
2854 .do_attr_set = osd_attr_set,
2855 .do_ah_init = osd_ah_init,
2856 .do_declare_create = osd_declare_object_create,
2857 .do_create = osd_object_create,
2858 .do_declare_destroy = osd_declare_object_destroy,
2859 .do_destroy = osd_object_destroy,
2860 .do_index_try = osd_index_try,
2861 .do_declare_ref_add = osd_declare_object_ref_add,
2862 .do_ref_add = osd_object_ref_add,
2863 .do_declare_ref_del = osd_declare_object_ref_del,
2864 .do_ref_del = osd_object_ref_del,
2865 .do_xattr_get = osd_xattr_get,
2866 .do_declare_xattr_set = osd_declare_xattr_set,
2867 .do_xattr_set = osd_xattr_set,
2868 .do_declare_xattr_del = osd_declare_xattr_del,
2869 .do_xattr_del = osd_xattr_del,
2870 .do_xattr_list = osd_xattr_list,
2871 .do_capa_get = osd_capa_get,
2872 .do_object_sync = osd_object_sync,
2873 .do_data_get = osd_data_get,
2877 * dt_object_operations for interoperability mode
2878 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2880 static const struct dt_object_operations osd_obj_ea_ops = {
2881 .do_read_lock = osd_object_read_lock,
2882 .do_write_lock = osd_object_write_lock,
2883 .do_read_unlock = osd_object_read_unlock,
2884 .do_write_unlock = osd_object_write_unlock,
2885 .do_write_locked = osd_object_write_locked,
2886 .do_attr_get = osd_attr_get,
2887 .do_declare_attr_set = osd_declare_attr_set,
2888 .do_attr_set = osd_attr_set,
2889 .do_ah_init = osd_ah_init,
2890 .do_declare_create = osd_declare_object_create,
2891 .do_create = osd_object_ea_create,
2892 .do_declare_destroy = osd_declare_object_destroy,
2893 .do_destroy = osd_object_destroy,
2894 .do_index_try = osd_index_try,
2895 .do_declare_ref_add = osd_declare_object_ref_add,
2896 .do_ref_add = osd_object_ref_add,
2897 .do_declare_ref_del = osd_declare_object_ref_del,
2898 .do_ref_del = osd_object_ref_del,
2899 .do_xattr_get = osd_xattr_get,
2900 .do_declare_xattr_set = osd_declare_xattr_set,
2901 .do_xattr_set = osd_xattr_set,
2902 .do_declare_xattr_del = osd_declare_xattr_del,
2903 .do_xattr_del = osd_xattr_del,
2904 .do_xattr_list = osd_xattr_list,
2905 .do_capa_get = osd_capa_get,
2906 .do_object_sync = osd_object_sync,
2907 .do_data_get = osd_data_get,
2910 static const struct dt_object_operations osd_obj_otable_it_ops = {
2911 .do_attr_get = osd_otable_it_attr_get,
2912 .do_index_try = osd_index_try,
2915 static int osd_index_declare_iam_delete(const struct lu_env *env,
2916 struct dt_object *dt,
2917 const struct dt_key *key,
2918 struct thandle *handle)
2920 struct osd_thandle *oh;
2922 oh = container_of0(handle, struct osd_thandle, ot_super);
2923 LASSERT(oh->ot_handle == NULL);
2925 OSD_DECLARE_OP(oh, delete);
2926 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
2932 * delete a (key, value) pair from index \a dt specified by \a key
2934 * \param dt osd index object
2935 * \param key key for index
2936 * \param rec record reference
2937 * \param handle transaction handler
2940 * \retval -ve failure
2943 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2944 const struct dt_key *key,
2945 struct thandle *handle,
2946 struct lustre_capa *capa)
2948 struct osd_thread_info *oti = osd_oti_get(env);
2949 struct osd_object *obj = osd_dt_obj(dt);
2950 struct osd_thandle *oh;
2951 struct iam_path_descr *ipd;
2952 struct iam_container *bag = &obj->oo_dir->od_container;
2957 LINVRNT(osd_invariant(obj));
2958 LASSERT(dt_object_exists(dt));
2959 LASSERT(bag->ic_object == obj->oo_inode);
2960 LASSERT(handle != NULL);
2962 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2965 OSD_EXEC_OP(handle, delete);
2967 ipd = osd_idx_ipd_get(env, bag);
2968 if (unlikely(ipd == NULL))
2971 oh = container_of0(handle, struct osd_thandle, ot_super);
2972 LASSERT(oh->ot_handle != NULL);
2973 LASSERT(oh->ot_handle->h_transaction != NULL);
2975 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
2976 /* swab quota uid/gid provided by caller */
2977 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
2978 key = (const struct dt_key *)&oti->oti_quota_id;
2981 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2982 osd_ipd_put(env, bag, ipd);
2983 LINVRNT(osd_invariant(obj));
2987 static int osd_index_declare_ea_delete(const struct lu_env *env,
2988 struct dt_object *dt,
2989 const struct dt_key *key,
2990 struct thandle *handle)
2992 struct osd_thandle *oh;
2993 struct inode *inode;
2997 LASSERT(dt_object_exists(dt));
2998 LASSERT(handle != NULL);
3000 oh = container_of0(handle, struct osd_thandle, ot_super);
3001 LASSERT(oh->ot_handle == NULL);
3003 OSD_DECLARE_OP(oh, delete);
3004 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
3006 inode = osd_dt_obj(dt)->oo_inode;
3009 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3010 true, true, NULL, false);
3014 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3017 struct osd_fid_pack *rec;
3020 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3021 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3022 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3028 * Index delete function for interoperability mode (b11826).
3029 * It will remove the directory entry added by osd_index_ea_insert().
3030 * This entry is needed to maintain name->fid mapping.
3032 * \param key, key i.e. file entry to be deleted
3034 * \retval 0, on success
3035 * \retval -ve, on error
3037 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3038 const struct dt_key *key,
3039 struct thandle *handle,
3040 struct lustre_capa *capa)
3042 struct osd_object *obj = osd_dt_obj(dt);
3043 struct inode *dir = obj->oo_inode;
3044 struct dentry *dentry;
3045 struct osd_thandle *oh;
3046 struct ldiskfs_dir_entry_2 *de;
3047 struct buffer_head *bh;
3048 struct htree_lock *hlock = NULL;
3053 LINVRNT(osd_invariant(obj));
3054 LASSERT(dt_object_exists(dt));
3055 LASSERT(handle != NULL);
3057 OSD_EXEC_OP(handle, delete);
3059 oh = container_of(handle, struct osd_thandle, ot_super);
3060 LASSERT(oh->ot_handle != NULL);
3061 LASSERT(oh->ot_handle->h_transaction != NULL);
3063 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
3066 dentry = osd_child_dentry_get(env, obj,
3067 (char *)key, strlen((char *)key));
3069 if (obj->oo_hl_head != NULL) {
3070 hlock = osd_oti_get(env)->oti_hlock;
3071 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3072 dir, LDISKFS_HLOCK_DEL);
3074 cfs_down_write(&obj->oo_ext_idx_sem);
3077 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3079 rc = ldiskfs_delete_entry(oh->ot_handle,
3086 ldiskfs_htree_unlock(hlock);
3088 cfs_up_write(&obj->oo_ext_idx_sem);
3090 LASSERT(osd_invariant(obj));
3095 * Lookup index for \a key and copy record to \a rec.
3097 * \param dt osd index object
3098 * \param key key for index
3099 * \param rec record reference
3101 * \retval +ve success : exact mach
3102 * \retval 0 return record with key not greater than \a key
3103 * \retval -ve failure
3105 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3106 struct dt_rec *rec, const struct dt_key *key,
3107 struct lustre_capa *capa)
3109 struct osd_object *obj = osd_dt_obj(dt);
3110 struct iam_path_descr *ipd;
3111 struct iam_container *bag = &obj->oo_dir->od_container;
3112 struct osd_thread_info *oti = osd_oti_get(env);
3113 struct iam_iterator *it = &oti->oti_idx_it;
3114 struct iam_rec *iam_rec;
3119 LASSERT(osd_invariant(obj));
3120 LASSERT(dt_object_exists(dt));
3121 LASSERT(bag->ic_object == obj->oo_inode);
3123 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3126 ipd = osd_idx_ipd_get(env, bag);
3130 /* got ipd now we can start iterator. */
3131 iam_it_init(it, bag, 0, ipd);
3133 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3134 /* swab quota uid/gid provided by caller */
3135 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3136 key = (const struct dt_key *)&oti->oti_quota_id;
3139 rc = iam_it_get(it, (struct iam_key *)key);
3141 if (S_ISDIR(obj->oo_inode->i_mode))
3142 iam_rec = (struct iam_rec *)oti->oti_ldp;
3144 iam_rec = (struct iam_rec *) rec;
3146 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3148 if (S_ISDIR(obj->oo_inode->i_mode))
3149 osd_fid_unpack((struct lu_fid *) rec,
3150 (struct osd_fid_pack *)iam_rec);
3151 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3152 osd_quota_unpack(obj, rec);
3157 osd_ipd_put(env, bag, ipd);
3159 LINVRNT(osd_invariant(obj));
3164 static int osd_index_declare_iam_insert(const struct lu_env *env,
3165 struct dt_object *dt,
3166 const struct dt_rec *rec,
3167 const struct dt_key *key,
3168 struct thandle *handle)
3170 struct osd_thandle *oh;
3172 LASSERT(dt_object_exists(dt));
3173 LASSERT(handle != NULL);
3175 oh = container_of0(handle, struct osd_thandle, ot_super);
3176 LASSERT(oh->ot_handle == NULL);
3178 OSD_DECLARE_OP(oh, insert);
3179 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
3185 * Inserts (key, value) pair in \a dt index object.
3187 * \param dt osd index object
3188 * \param key key for index
3189 * \param rec record reference
3190 * \param th transaction handler
3193 * \retval -ve failure
3195 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3196 const struct dt_rec *rec,
3197 const struct dt_key *key, struct thandle *th,
3198 struct lustre_capa *capa, int ignore_quota)
3200 struct osd_object *obj = osd_dt_obj(dt);
3201 struct iam_path_descr *ipd;
3202 struct osd_thandle *oh;
3203 struct iam_container *bag = &obj->oo_dir->od_container;
3204 #ifdef HAVE_QUOTA_SUPPORT
3205 cfs_cap_t save = cfs_curproc_cap_pack();
3207 struct osd_thread_info *oti = osd_oti_get(env);
3208 struct iam_rec *iam_rec;
3213 LINVRNT(osd_invariant(obj));
3214 LASSERT(dt_object_exists(dt));
3215 LASSERT(bag->ic_object == obj->oo_inode);
3216 LASSERT(th != NULL);
3218 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3221 OSD_EXEC_OP(th, insert);
3223 ipd = osd_idx_ipd_get(env, bag);
3224 if (unlikely(ipd == NULL))
3227 oh = container_of0(th, struct osd_thandle, ot_super);
3228 LASSERT(oh->ot_handle != NULL);
3229 LASSERT(oh->ot_handle->h_transaction != NULL);
3230 #ifdef HAVE_QUOTA_SUPPORT
3232 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
3234 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
3236 if (S_ISDIR(obj->oo_inode->i_mode)) {
3237 iam_rec = (struct iam_rec *)oti->oti_ldp;
3238 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3239 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3240 /* pack quota uid/gid */
3241 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3242 key = (const struct dt_key *)&oti->oti_quota_id;
3243 /* pack quota record */
3244 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3245 iam_rec = (struct iam_rec *)rec;
3247 iam_rec = (struct iam_rec *)rec;
3250 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3252 #ifdef HAVE_QUOTA_SUPPORT
3253 cfs_curproc_cap_unpack(save);
3255 osd_ipd_put(env, bag, ipd);
3256 LINVRNT(osd_invariant(obj));
3261 * Calls ldiskfs_add_entry() to add directory entry
3262 * into the directory. This is required for
3263 * interoperability mode (b11826)
3265 * \retval 0, on success
3266 * \retval -ve, on error
3268 static int __osd_ea_add_rec(struct osd_thread_info *info,
3269 struct osd_object *pobj, struct inode *cinode,
3270 const char *name, const struct dt_rec *fid,
3271 struct htree_lock *hlock, struct thandle *th)
3273 struct ldiskfs_dentry_param *ldp;
3274 struct dentry *child;
3275 struct osd_thandle *oth;
3278 oth = container_of(th, struct osd_thandle, ot_super);
3279 LASSERT(oth->ot_handle != NULL);
3280 LASSERT(oth->ot_handle->h_transaction != NULL);
3282 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3284 /* XXX: remove fid_is_igif() check here.
3285 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3286 * it is IGIF now but needs FID in dir entry as well for readdir
3288 * LU-838 should fix that and remove fid_is_igif() check */
3289 if (fid_is_igif((struct lu_fid *)fid) ||
3290 fid_is_norm((struct lu_fid *)fid)) {
3291 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3292 osd_get_ldiskfs_dirent_param(ldp, fid);
3293 child->d_fsdata = (void *)ldp;
3295 child->d_fsdata = NULL;
3297 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3303 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3304 * into the directory.Also sets flags into osd object to
3305 * indicate dot and dotdot are created. This is required for
3306 * interoperability mode (b11826)
3308 * \param dir directory for dot and dotdot fixup.
3309 * \param obj child object for linking
3311 * \retval 0, on success
3312 * \retval -ve, on error
3314 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3315 struct osd_object *dir,
3316 struct inode *parent_dir, const char *name,
3317 const struct dt_rec *dot_fid,
3318 const struct dt_rec *dot_dot_fid,
3321 struct inode *inode = dir->oo_inode;
3322 struct ldiskfs_dentry_param *dot_ldp;
3323 struct ldiskfs_dentry_param *dot_dot_ldp;
3324 struct osd_thandle *oth;
3327 oth = container_of(th, struct osd_thandle, ot_super);
3328 LASSERT(oth->ot_handle->h_transaction != NULL);
3329 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3331 if (strcmp(name, dot) == 0) {
3332 if (dir->oo_compat_dot_created) {
3335 LASSERT(inode == parent_dir);
3336 dir->oo_compat_dot_created = 1;
3339 } else if(strcmp(name, dotdot) == 0) {
3340 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3341 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3343 if (!dir->oo_compat_dot_created)
3345 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3346 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3347 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3352 /* in case of rename, dotdot is already created */
3353 if (dir->oo_compat_dotdot_created) {
3354 return __osd_ea_add_rec(info, dir, parent_dir, name,
3355 dot_dot_fid, NULL, th);
3358 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3359 inode, dot_ldp, dot_dot_ldp);
3361 dir->oo_compat_dotdot_created = 1;
3369 * It will call the appropriate osd_add* function and return the
3370 * value, return by respective functions.
3372 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3373 struct inode *cinode, const char *name,
3374 const struct dt_rec *fid, struct thandle *th)
3376 struct osd_thread_info *info = osd_oti_get(env);
3377 struct htree_lock *hlock;
3380 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3382 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3384 if (hlock != NULL) {
3385 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3388 cfs_down_write(&pobj->oo_ext_idx_sem);
3390 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3391 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3394 if (hlock != NULL) {
3395 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3396 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3398 cfs_down_write(&pobj->oo_ext_idx_sem);
3401 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3405 ldiskfs_htree_unlock(hlock);
3407 cfs_up_write(&pobj->oo_ext_idx_sem);
3413 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3414 struct osd_idmap_cache *oic)
3416 struct osd_scrub *scrub = &dev->od_scrub;
3417 struct lu_fid *fid = &oic->oic_fid;
3418 struct osd_inode_id *id = &oti->oti_id;
3424 rc = osd_oi_lookup(oti, dev, fid, id);
3425 if (rc != 0 && rc != -ENOENT)
3428 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3431 if (thread_is_running(&scrub->os_thread)) {
3432 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3433 /* There is race condition between osd_oi_lookup and OI scrub.
3434 * The OI scrub finished just after osd_oi_lookup() failure.
3435 * Under such case, it is unnecessary to trigger OI scrub again,
3436 * but try to call osd_oi_lookup() again. */
3437 if (unlikely(rc == -EAGAIN))
3443 if (!scrub->os_no_scrub && ++once == 1) {
3444 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3446 rc = osd_scrub_start(dev);
3447 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3449 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3455 RETURN(rc = -EREMCHG);
3459 * Calls ->lookup() to find dentry. From dentry get inode and
3460 * read inode's ea to get fid. This is required for interoperability
3463 * \retval 0, on success
3464 * \retval -ve, on error
3466 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3467 struct dt_rec *rec, const struct dt_key *key)
3469 struct inode *dir = obj->oo_inode;
3470 struct dentry *dentry;
3471 struct ldiskfs_dir_entry_2 *de;
3472 struct buffer_head *bh;
3473 struct lu_fid *fid = (struct lu_fid *) rec;
3474 struct htree_lock *hlock = NULL;
3478 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3480 dentry = osd_child_dentry_get(env, obj,
3481 (char *)key, strlen((char *)key));
3483 if (obj->oo_hl_head != NULL) {
3484 hlock = osd_oti_get(env)->oti_hlock;
3485 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3486 dir, LDISKFS_HLOCK_LOOKUP);
3488 cfs_down_read(&obj->oo_ext_idx_sem);
3491 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3493 struct osd_thread_info *oti = osd_oti_get(env);
3494 struct osd_idmap_cache *oic = &oti->oti_cache;
3495 struct osd_device *dev = osd_obj2dev(obj);
3496 struct osd_scrub *scrub = &dev->od_scrub;
3497 struct scrub_file *sf = &scrub->os_file;
3499 ino = le32_to_cpu(de->inode);
3500 rc = osd_get_fid_from_dentry(de, rec);
3502 /* done with de, release bh */
3505 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3507 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3508 if (rc != 0 || !fid_is_norm(fid)) {
3509 fid_zero(&oic->oic_fid);
3513 oic->oic_fid = *fid;
3514 if ((scrub->os_pos_current <= ino) &&
3515 (sf->sf_flags & SF_INCONSISTENT ||
3516 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3518 rc = osd_consistency_check(oti, dev, oic);
3527 ldiskfs_htree_unlock(hlock);
3529 cfs_up_read(&obj->oo_ext_idx_sem);
3534 * Find the osd object for given fid.
3536 * \param fid need to find the osd object having this fid
3538 * \retval osd_object on success
3539 * \retval -ve on error
3541 struct osd_object *osd_object_find(const struct lu_env *env,
3542 struct dt_object *dt,
3543 const struct lu_fid *fid)
3545 struct lu_device *ludev = dt->do_lu.lo_dev;
3546 struct osd_object *child = NULL;
3547 struct lu_object *luch;
3548 struct lu_object *lo;
3551 * at this point topdev might not exist yet
3552 * (i.e. MGS is preparing profiles). so we can
3553 * not rely on topdev and instead lookup with
3554 * our device passed as topdev. this can't work
3555 * if the object isn't cached yet (as osd doesn't
3556 * allocate lu_header). IOW, the object must be
3557 * in the cache, otherwise lu_object_alloc() crashes
3560 luch = lu_object_find_at(env, ludev, fid, NULL);
3561 if (!IS_ERR(luch)) {
3562 if (lu_object_exists(luch)) {
3563 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3565 child = osd_obj(lo);
3567 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3568 "lu_object can't be located"
3569 DFID"\n", PFID(fid));
3571 if (child == NULL) {
3572 lu_object_put(env, luch);
3573 CERROR("Unable to get osd_object\n");
3574 child = ERR_PTR(-ENOENT);
3577 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3578 "lu_object does not exists "DFID"\n",
3580 lu_object_put(env, luch);
3581 child = ERR_PTR(-ENOENT);
3584 child = (void *)luch;
3590 * Put the osd object once done with it.
3592 * \param obj osd object that needs to be put
3594 static inline void osd_object_put(const struct lu_env *env,
3595 struct osd_object *obj)
3597 lu_object_put(env, &obj->oo_dt.do_lu);
3600 static int osd_index_declare_ea_insert(const struct lu_env *env,
3601 struct dt_object *dt,
3602 const struct dt_rec *rec,
3603 const struct dt_key *key,
3604 struct thandle *handle)
3606 struct osd_thandle *oh;
3607 struct inode *inode;
3611 LASSERT(dt_object_exists(dt));
3612 LASSERT(handle != NULL);
3614 oh = container_of0(handle, struct osd_thandle, ot_super);
3615 LASSERT(oh->ot_handle == NULL);
3617 OSD_DECLARE_OP(oh, insert);
3618 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
3620 inode = osd_dt_obj(dt)->oo_inode;
3623 /* We ignore block quota on meta pool (MDTs), so needn't
3624 * calculate how many blocks will be consumed by this index
3626 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3627 true, true, NULL, false);
3632 * Index add function for interoperability mode (b11826).
3633 * It will add the directory entry.This entry is needed to
3634 * maintain name->fid mapping.
3636 * \param key it is key i.e. file entry to be inserted
3637 * \param rec it is value of given key i.e. fid
3639 * \retval 0, on success
3640 * \retval -ve, on error
3642 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3643 const struct dt_rec *rec,
3644 const struct dt_key *key, struct thandle *th,
3645 struct lustre_capa *capa, int ignore_quota)
3647 struct osd_object *obj = osd_dt_obj(dt);
3648 struct lu_fid *fid = (struct lu_fid *) rec;
3649 const char *name = (const char *)key;
3650 struct osd_object *child;
3651 #ifdef HAVE_QUOTA_SUPPORT
3652 cfs_cap_t save = cfs_curproc_cap_pack();
3658 LASSERT(osd_invariant(obj));
3659 LASSERT(dt_object_exists(dt));
3660 LASSERT(th != NULL);
3662 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3665 child = osd_object_find(env, dt, fid);
3666 if (!IS_ERR(child)) {
3667 #ifdef HAVE_QUOTA_SUPPORT
3669 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
3671 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
3673 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3674 #ifdef HAVE_QUOTA_SUPPORT
3675 cfs_curproc_cap_unpack(save);
3677 osd_object_put(env, child);
3679 rc = PTR_ERR(child);
3682 LASSERT(osd_invariant(obj));
3687 * Initialize osd Iterator for given osd index object.
3689 * \param dt osd index object
3692 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3693 struct dt_object *dt,
3695 struct lustre_capa *capa)
3697 struct osd_it_iam *it;
3698 struct osd_thread_info *oti = osd_oti_get(env);
3699 struct osd_object *obj = osd_dt_obj(dt);
3700 struct lu_object *lo = &dt->do_lu;
3701 struct iam_path_descr *ipd;
3702 struct iam_container *bag = &obj->oo_dir->od_container;
3704 LASSERT(lu_object_exists(lo));
3706 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3707 return ERR_PTR(-EACCES);
3710 ipd = osd_it_ipd_get(env, bag);
3711 if (likely(ipd != NULL)) {
3715 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3716 return (struct dt_it *)it;
3718 return ERR_PTR(-ENOMEM);
3722 * free given Iterator.
3725 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3727 struct osd_it_iam *it = (struct osd_it_iam *)di;
3728 struct osd_object *obj = it->oi_obj;
3730 iam_it_fini(&it->oi_it);
3731 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3732 lu_object_put(env, &obj->oo_dt.do_lu);
3736 * Move Iterator to record specified by \a key
3738 * \param di osd iterator
3739 * \param key key for index
3741 * \retval +ve di points to record with least key not larger than key
3742 * \retval 0 di points to exact matched key
3743 * \retval -ve failure
3746 static int osd_it_iam_get(const struct lu_env *env,
3747 struct dt_it *di, const struct dt_key *key)
3749 struct osd_thread_info *oti = osd_oti_get(env);
3750 struct osd_it_iam *it = (struct osd_it_iam *)di;
3752 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3753 /* swab quota uid/gid */
3754 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3755 key = (struct dt_key *)&oti->oti_quota_id;
3758 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3764 * \param di osd iterator
3767 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3769 struct osd_it_iam *it = (struct osd_it_iam *)di;
3771 iam_it_put(&it->oi_it);
3775 * Move iterator by one record
3777 * \param di osd iterator
3779 * \retval +1 end of container reached
3781 * \retval -ve failure
3784 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3786 struct osd_it_iam *it = (struct osd_it_iam *)di;
3788 return iam_it_next(&it->oi_it);
3792 * Return pointer to the key under iterator.
3795 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3796 const struct dt_it *di)
3798 struct osd_thread_info *oti = osd_oti_get(env);
3799 struct osd_it_iam *it = (struct osd_it_iam *)di;
3800 struct osd_object *obj = it->oi_obj;
3803 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
3805 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
3806 /* swab quota uid/gid */
3807 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
3808 key = (struct dt_key *)&oti->oti_quota_id;
3815 * Return size of key under iterator (in bytes)
3818 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3820 struct osd_it_iam *it = (struct osd_it_iam *)di;
3822 return iam_it_key_size(&it->oi_it);
3825 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3826 int len, __u16 type)
3828 struct luda_type *lt;
3829 const unsigned align = sizeof(struct luda_type) - 1;
3831 /* check if file type is required */
3832 if (attr & LUDA_TYPE) {
3833 len = (len + align) & ~align;
3835 lt = (void *) ent->lde_name + len;
3836 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3837 ent->lde_attrs |= LUDA_TYPE;
3840 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3844 * build lu direct from backend fs dirent.
3847 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3848 struct lu_fid *fid, __u64 offset,
3849 char *name, __u16 namelen,
3850 __u16 type, __u32 attr)
3852 fid_cpu_to_le(&ent->lde_fid, fid);
3853 ent->lde_attrs = LUDA_FID;
3855 ent->lde_hash = cpu_to_le64(offset);
3856 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3858 strncpy(ent->lde_name, name, namelen);
3859 ent->lde_namelen = cpu_to_le16(namelen);
3861 /* append lustre attributes */
3862 osd_it_append_attrs(ent, attr, namelen, type);
3866 * Return pointer to the record under iterator.
3868 static int osd_it_iam_rec(const struct lu_env *env,
3869 const struct dt_it *di,
3870 struct dt_rec *dtrec, __u32 attr)
3872 struct osd_it_iam *it = (struct osd_it_iam *)di;
3873 struct osd_thread_info *info = osd_oti_get(env);
3876 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3877 const struct osd_fid_pack *rec;
3878 struct lu_fid *fid = &info->oti_fid;
3879 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3885 name = (char *)iam_it_key_get(&it->oi_it);
3887 RETURN(PTR_ERR(name));
3889 namelen = iam_it_key_size(&it->oi_it);
3891 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3893 RETURN(PTR_ERR(rec));
3895 rc = osd_fid_unpack(fid, rec);
3899 hash = iam_it_store(&it->oi_it);
3901 /* IAM does not store object type in IAM index (dir) */
3902 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3904 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3905 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3906 (struct iam_rec *)dtrec);
3907 osd_quota_unpack(it->oi_obj, dtrec);
3909 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3910 (struct iam_rec *)dtrec);
3917 * Returns cookie for current Iterator position.
3919 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3921 struct osd_it_iam *it = (struct osd_it_iam *)di;
3923 return iam_it_store(&it->oi_it);
3927 * Restore iterator from cookie.
3929 * \param di osd iterator
3930 * \param hash Iterator location cookie
3932 * \retval +ve di points to record with least key not larger than key.
3933 * \retval 0 di points to exact matched key
3934 * \retval -ve failure
3937 static int osd_it_iam_load(const struct lu_env *env,
3938 const struct dt_it *di, __u64 hash)
3940 struct osd_it_iam *it = (struct osd_it_iam *)di;
3942 return iam_it_load(&it->oi_it, hash);
3945 static const struct dt_index_operations osd_index_iam_ops = {
3946 .dio_lookup = osd_index_iam_lookup,
3947 .dio_declare_insert = osd_index_declare_iam_insert,
3948 .dio_insert = osd_index_iam_insert,
3949 .dio_declare_delete = osd_index_declare_iam_delete,
3950 .dio_delete = osd_index_iam_delete,
3952 .init = osd_it_iam_init,
3953 .fini = osd_it_iam_fini,
3954 .get = osd_it_iam_get,
3955 .put = osd_it_iam_put,
3956 .next = osd_it_iam_next,
3957 .key = osd_it_iam_key,
3958 .key_size = osd_it_iam_key_size,
3959 .rec = osd_it_iam_rec,
3960 .store = osd_it_iam_store,
3961 .load = osd_it_iam_load
3966 * Creates or initializes iterator context.
3968 * \retval struct osd_it_ea, iterator structure on success
3971 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3972 struct dt_object *dt,
3974 struct lustre_capa *capa)
3976 struct osd_object *obj = osd_dt_obj(dt);
3977 struct osd_thread_info *info = osd_oti_get(env);
3978 struct osd_it_ea *it = &info->oti_it_ea;
3979 struct lu_object *lo = &dt->do_lu;
3980 struct dentry *obj_dentry = &info->oti_it_dentry;
3982 LASSERT(lu_object_exists(lo));
3984 obj_dentry->d_inode = obj->oo_inode;
3985 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3986 obj_dentry->d_name.hash = 0;
3988 it->oie_rd_dirent = 0;
3989 it->oie_it_dirent = 0;
3990 it->oie_dirent = NULL;
3991 it->oie_buf = info->oti_it_ea_buf;
3993 it->oie_file.f_pos = 0;
3994 it->oie_file.f_dentry = obj_dentry;
3995 if (attr & LUDA_64BITHASH)
3996 it->oie_file.f_mode |= FMODE_64BITHASH;
3998 it->oie_file.f_mode |= FMODE_32BITHASH;
3999 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
4000 it->oie_file.f_op = obj->oo_inode->i_fop;
4001 it->oie_file.private_data = NULL;
4003 RETURN((struct dt_it *) it);
4007 * Destroy or finishes iterator context.
4009 * \param di iterator structure to be destroyed
4011 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
4013 struct osd_it_ea *it = (struct osd_it_ea *)di;
4014 struct osd_object *obj = it->oie_obj;
4015 struct inode *inode = obj->oo_inode;
4018 it->oie_file.f_op->release(inode, &it->oie_file);
4019 lu_object_put(env, &obj->oo_dt.do_lu);
4024 * It position the iterator at given key, so that next lookup continues from
4025 * that key Or it is similar to dio_it->load() but based on a key,
4026 * rather than file position.
4028 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4031 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4033 static int osd_it_ea_get(const struct lu_env *env,
4034 struct dt_it *di, const struct dt_key *key)
4036 struct osd_it_ea *it = (struct osd_it_ea *)di;
4039 LASSERT(((const char *)key)[0] == '\0');
4040 it->oie_file.f_pos = 0;
4041 it->oie_rd_dirent = 0;
4042 it->oie_it_dirent = 0;
4043 it->oie_dirent = NULL;
4051 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4056 * It is called internally by ->readdir(). It fills the
4057 * iterator's in-memory data structure with required
4058 * information i.e. name, namelen, rec_size etc.
4060 * \param buf in which information to be filled in.
4061 * \param name name of the file in given dir
4063 * \retval 0 on success
4064 * \retval 1 on buffer full
4066 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
4067 loff_t offset, __u64 ino,
4070 struct osd_it_ea *it = (struct osd_it_ea *)buf;
4071 struct osd_it_ea_dirent *ent = it->oie_dirent;
4072 struct lu_fid *fid = &ent->oied_fid;
4073 struct osd_fid_pack *rec;
4076 /* this should never happen */
4077 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4078 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4082 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4086 if (d_type & LDISKFS_DIRENT_LUFID) {
4087 rec = (struct osd_fid_pack*) (name + namelen + 1);
4089 if (osd_fid_unpack(fid, rec) != 0)
4092 d_type &= ~LDISKFS_DIRENT_LUFID;
4097 ent->oied_ino = ino;
4098 ent->oied_off = offset;
4099 ent->oied_namelen = namelen;
4100 ent->oied_type = d_type;
4102 memcpy(ent->oied_name, name, namelen);
4104 it->oie_rd_dirent++;
4105 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4110 * Calls ->readdir() to load a directory entry at a time
4111 * and stored it in iterator's in-memory data structure.
4113 * \param di iterator's in memory structure
4115 * \retval 0 on success
4116 * \retval -ve on error
4118 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4119 const struct dt_it *di)
4121 struct osd_it_ea *it = (struct osd_it_ea *)di;
4122 struct osd_object *obj = it->oie_obj;
4123 struct inode *inode = obj->oo_inode;
4124 struct htree_lock *hlock = NULL;
4128 it->oie_dirent = it->oie_buf;
4129 it->oie_rd_dirent = 0;
4131 if (obj->oo_hl_head != NULL) {
4132 hlock = osd_oti_get(env)->oti_hlock;
4133 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4134 inode, LDISKFS_HLOCK_READDIR);
4136 cfs_down_read(&obj->oo_ext_idx_sem);
4139 result = inode->i_fop->readdir(&it->oie_file, it,
4140 (filldir_t) osd_ldiskfs_filldir);
4143 ldiskfs_htree_unlock(hlock);
4145 cfs_up_read(&obj->oo_ext_idx_sem);
4147 if (it->oie_rd_dirent == 0) {
4150 it->oie_dirent = it->oie_buf;
4151 it->oie_it_dirent = 1;
4158 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4159 * to load a directory entry at a time and stored it in
4160 * iterator's in-memory data structure.
4162 * \param di iterator's in memory structure
4164 * \retval +ve iterator reached to end
4165 * \retval 0 iterator not reached to end
4166 * \retval -ve on error
4168 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4170 struct osd_it_ea *it = (struct osd_it_ea *)di;
4175 if (it->oie_it_dirent < it->oie_rd_dirent) {
4177 (void *) it->oie_dirent +
4178 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4179 it->oie_dirent->oied_namelen);
4180 it->oie_it_dirent++;
4183 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4186 rc = osd_ldiskfs_it_fill(env, di);
4193 * Returns the key at current position from iterator's in memory structure.
4195 * \param di iterator's in memory structure
4197 * \retval key i.e. struct dt_key on success
4199 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4200 const struct dt_it *di)
4202 struct osd_it_ea *it = (struct osd_it_ea *)di;
4204 return (struct dt_key *)it->oie_dirent->oied_name;
4208 * Returns the key's size at current position from iterator's in memory structure.
4210 * \param di iterator's in memory structure
4212 * \retval key_size i.e. struct dt_key on success
4214 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4216 struct osd_it_ea *it = (struct osd_it_ea *)di;
4218 return it->oie_dirent->oied_namelen;
4223 * Returns the value (i.e. fid/igif) at current position from iterator's
4224 * in memory structure.
4226 * \param di struct osd_it_ea, iterator's in memory structure
4227 * \param attr attr requested for dirent.
4228 * \param lde lustre dirent
4230 * \retval 0 no error and \param lde has correct lustre dirent.
4231 * \retval -ve on error
4233 static inline int osd_it_ea_rec(const struct lu_env *env,
4234 const struct dt_it *di,
4235 struct dt_rec *dtrec, __u32 attr)
4237 struct osd_it_ea *it = (struct osd_it_ea *)di;
4238 struct osd_object *obj = it->oie_obj;
4239 struct osd_device *dev = osd_obj2dev(obj);
4240 struct osd_scrub *scrub = &dev->od_scrub;
4241 struct scrub_file *sf = &scrub->os_file;
4242 struct osd_thread_info *oti = osd_oti_get(env);
4243 struct osd_idmap_cache *oic = &oti->oti_cache;
4244 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4245 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4246 __u32 ino = it->oie_dirent->oied_ino;
4250 if (!fid_is_sane(fid)) {
4251 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4255 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4258 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4259 it->oie_dirent->oied_name,
4260 it->oie_dirent->oied_namelen,
4261 it->oie_dirent->oied_type, attr);
4262 if (!fid_is_norm(fid)) {
4263 fid_zero(&oic->oic_fid);
4267 oic->oic_fid = *fid;
4268 if ((scrub->os_pos_current <= ino) &&
4269 (sf->sf_flags & SF_INCONSISTENT ||
4270 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4271 rc = osd_consistency_check(oti, dev, oic);
4277 * Returns a cookie for current position of the iterator head, so that
4278 * user can use this cookie to load/start the iterator next time.
4280 * \param di iterator's in memory structure
4282 * \retval cookie for current position, on success
4284 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4286 struct osd_it_ea *it = (struct osd_it_ea *)di;
4288 return it->oie_dirent->oied_off;
4292 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4293 * to load a directory entry at a time and stored it i inn,
4294 * in iterator's in-memory data structure.
4296 * \param di struct osd_it_ea, iterator's in memory structure
4298 * \retval +ve on success
4299 * \retval -ve on error
4301 static int osd_it_ea_load(const struct lu_env *env,
4302 const struct dt_it *di, __u64 hash)
4304 struct osd_it_ea *it = (struct osd_it_ea *)di;
4308 it->oie_file.f_pos = hash;
4310 rc = osd_ldiskfs_it_fill(env, di);
4318 * Index lookup function for interoperability mode (b11826).
4320 * \param key, key i.e. file name to be searched
4322 * \retval +ve, on success
4323 * \retval -ve, on error
4325 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4326 struct dt_rec *rec, const struct dt_key *key,
4327 struct lustre_capa *capa)
4329 struct osd_object *obj = osd_dt_obj(dt);
4334 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4335 LINVRNT(osd_invariant(obj));
4337 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4340 rc = osd_ea_lookup_rec(env, obj, rec, key);
4348 * Index and Iterator operations for interoperability
4349 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4351 static const struct dt_index_operations osd_index_ea_ops = {
4352 .dio_lookup = osd_index_ea_lookup,
4353 .dio_declare_insert = osd_index_declare_ea_insert,
4354 .dio_insert = osd_index_ea_insert,
4355 .dio_declare_delete = osd_index_declare_ea_delete,
4356 .dio_delete = osd_index_ea_delete,
4358 .init = osd_it_ea_init,
4359 .fini = osd_it_ea_fini,
4360 .get = osd_it_ea_get,
4361 .put = osd_it_ea_put,
4362 .next = osd_it_ea_next,
4363 .key = osd_it_ea_key,
4364 .key_size = osd_it_ea_key_size,
4365 .rec = osd_it_ea_rec,
4366 .store = osd_it_ea_store,
4367 .load = osd_it_ea_load
4371 static void *osd_key_init(const struct lu_context *ctx,
4372 struct lu_context_key *key)
4374 struct osd_thread_info *info;
4376 OBD_ALLOC_PTR(info);
4378 return ERR_PTR(-ENOMEM);
4380 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4381 if (info->oti_it_ea_buf == NULL)
4384 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4386 info->oti_hlock = ldiskfs_htree_lock_alloc();
4387 if (info->oti_hlock == NULL)
4393 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4396 return ERR_PTR(-ENOMEM);
4399 static void osd_key_fini(const struct lu_context *ctx,
4400 struct lu_context_key *key, void* data)
4402 struct osd_thread_info *info = data;
4404 if (info->oti_hlock != NULL)
4405 ldiskfs_htree_lock_free(info->oti_hlock);
4406 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4410 static void osd_key_exit(const struct lu_context *ctx,
4411 struct lu_context_key *key, void *data)
4413 struct osd_thread_info *info = data;
4415 LASSERT(info->oti_r_locks == 0);
4416 LASSERT(info->oti_w_locks == 0);
4417 LASSERT(info->oti_txns == 0);
4420 /* type constructor/destructor: osd_type_init, osd_type_fini */
4421 LU_TYPE_INIT_FINI(osd, &osd_key);
4423 struct lu_context_key osd_key = {
4424 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4425 .lct_init = osd_key_init,
4426 .lct_fini = osd_key_fini,
4427 .lct_exit = osd_key_exit
4431 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4432 const char *name, struct lu_device *next)
4434 struct osd_device *osd = osd_dev(d);
4436 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4437 return osd_procfs_init(osd, name);
4440 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4444 osd_scrub_cleanup(env, o);
4447 fsfilt_put_ops(o->od_fsops);
4451 /* shutdown quota slave instance associated with the device */
4452 if (o->od_quota_slave != NULL) {
4453 qsd_fini(env, o->od_quota_slave);
4454 o->od_quota_slave = NULL;
4460 static int osd_mount(const struct lu_env *env,
4461 struct osd_device *o, struct lustre_cfg *cfg)
4463 const char *name = lustre_cfg_string(cfg, 0);
4464 const char *dev = lustre_cfg_string(cfg, 1);
4466 unsigned long page, s_flags, lmd_flags = 0;
4467 struct page *__page;
4468 struct file_system_type *type;
4469 char *options = NULL;
4474 if (o->od_mnt != NULL)
4477 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4478 if (o->od_fsops == NULL) {
4479 CERROR("Can't find fsfilt_ldiskfs\n");
4483 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4485 GOTO(out, rc = -ENOMEM);
4487 str = lustre_cfg_string(cfg, 2);
4488 s_flags = simple_strtoul(str, NULL, 0);
4489 str = strstr(str, ":");
4491 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4492 opts = lustre_cfg_string(cfg, 3);
4493 page = (unsigned long)cfs_page_address(__page);
4494 options = (char *)page;
4497 strcat(options, "user_xattr,acl");
4499 strcat(options, opts);
4501 /* Glom up mount options */
4502 if (*options != '\0')
4503 strcat(options, ",");
4504 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4506 type = get_fs_type("ldiskfs");
4508 CERROR("%s: cannot find ldiskfs module\n", name);
4509 GOTO(out, rc = -ENODEV);
4512 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4513 cfs_module_put(type->owner);
4515 if (IS_ERR(o->od_mnt)) {
4516 rc = PTR_ERR(o->od_mnt);
4517 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4522 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4523 CERROR("%s: underlying device %s is marked as read-only. "
4524 "Setup failed\n", name, dev);
4527 GOTO(out, rc = -EROFS);
4530 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4531 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4532 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4535 GOTO(out, rc = -EINVAL);
4538 if (lmd_flags & LMD_FLG_IAM) {
4540 LCONSOLE_WARN("%s: OSD: IAM mode enabled\n", name);
4543 if (lmd_flags & LMD_FLG_NOSCRUB)
4544 o->od_scrub.os_no_scrub = 1;
4548 OBD_PAGE_FREE(__page);
4550 fsfilt_put_ops(o->od_fsops);
4555 static struct lu_device *osd_device_fini(const struct lu_env *env,
4556 struct lu_device *d)
4561 rc = osd_shutdown(env, osd_dev(d));
4563 osd_compat_fini(osd_dev(d));
4565 shrink_dcache_sb(osd_sb(osd_dev(d)));
4566 osd_sync(env, lu2dt_dev(d));
4568 rc = osd_procfs_fini(osd_dev(d));
4570 CERROR("proc fini error %d \n", rc);
4571 RETURN (ERR_PTR(rc));
4574 if (osd_dev(d)->od_mnt) {
4575 mntput(osd_dev(d)->od_mnt);
4576 osd_dev(d)->od_mnt = NULL;
4582 static int osd_device_init0(const struct lu_env *env,
4583 struct osd_device *o,
4584 struct lustre_cfg *cfg)
4586 struct lu_device *l = osd2lu_dev(o);
4587 struct osd_thread_info *info;
4590 /* if the module was re-loaded, env can loose its keys */
4591 rc = lu_env_refill((struct lu_env *) env);
4594 info = osd_oti_get(env);
4597 l->ld_ops = &osd_lu_ops;
4598 o->od_dt_dev.dd_ops = &osd_dt_ops;
4600 cfs_spin_lock_init(&o->od_osfs_lock);
4601 cfs_mutex_init(&o->od_otable_mutex);
4602 o->od_osfs_age = cfs_time_shift_64(-1000);
4604 o->od_capa_hash = init_capa_hash();
4605 if (o->od_capa_hash == NULL)
4606 GOTO(out, rc = -ENOMEM);
4608 o->od_read_cache = 1;
4609 o->od_writethrough_cache = 1;
4611 rc = osd_mount(env, o, cfg);
4615 /* setup scrub, including OI files initialization */
4616 rc = osd_scrub_setup(env, o);
4620 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4621 sizeof(o->od_svname) - 1);
4623 if (strstr(o->od_svname, "-OST")) {
4624 rc = osd_compat_init(o);
4629 rc = lu_site_init(&o->od_site, l);
4631 GOTO(out_compat, rc);
4633 rc = lu_site_init_finish(&o->od_site);
4635 GOTO(out_compat, rc);
4637 rc = osd_procfs_init(o, o->od_svname);
4639 CERROR("%s: can't initialize procfs: rc = %d\n",
4641 GOTO(out_compat, rc);
4644 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4650 osd_oi_fini(info, o);
4651 osd_shutdown(env, o);
4655 cleanup_capa_hash(o->od_capa_hash);
4660 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4661 struct lu_device_type *t,
4662 struct lustre_cfg *cfg)
4664 struct osd_device *o;
4669 return ERR_PTR(-ENOMEM);
4671 rc = dt_device_init(&o->od_dt_dev, t);
4673 rc = osd_device_init0(env, o, cfg);
4675 dt_device_fini(&o->od_dt_dev);
4678 if (unlikely(rc != 0))
4681 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4684 static struct lu_device *osd_device_free(const struct lu_env *env,
4685 struct lu_device *d)
4687 struct osd_device *o = osd_dev(d);
4690 cleanup_capa_hash(o->od_capa_hash);
4691 /* XXX: make osd top device in order to release reference */
4692 d->ld_site->ls_top_dev = d;
4693 lu_site_purge(env, d->ld_site, -1);
4694 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4695 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4696 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4698 lu_site_fini(&o->od_site);
4699 dt_device_fini(&o->od_dt_dev);
4704 static int osd_process_config(const struct lu_env *env,
4705 struct lu_device *d, struct lustre_cfg *cfg)
4707 struct osd_device *o = osd_dev(d);
4711 switch(cfg->lcfg_command) {
4713 err = osd_mount(env, o, cfg);
4716 lu_dev_del_linkage(d->ld_site, d);
4717 err = osd_shutdown(env, o);
4726 static int osd_recovery_complete(const struct lu_env *env,
4727 struct lu_device *d)
4733 * we use exports to track all osd users
4735 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4736 struct obd_device *obd, struct obd_uuid *cluuid,
4737 struct obd_connect_data *data, void *localdata)
4739 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4740 struct lustre_handle conn;
4744 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4746 rc = class_connect(&conn, obd, cluuid);
4750 *exp = class_conn2export(&conn);
4752 cfs_spin_lock(&osd->od_osfs_lock);
4754 cfs_spin_unlock(&osd->od_osfs_lock);
4760 * once last export (we don't count self-export) disappeared
4761 * osd can be released
4763 static int osd_obd_disconnect(struct obd_export *exp)
4765 struct obd_device *obd = exp->exp_obd;
4766 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4767 int rc, release = 0;
4770 /* Only disconnect the underlying layers on the final disconnect. */
4771 cfs_spin_lock(&osd->od_osfs_lock);
4773 if (osd->od_connects == 0)
4775 cfs_spin_unlock(&osd->od_osfs_lock);
4777 rc = class_disconnect(exp); /* bz 9811 */
4779 if (rc == 0 && release)
4780 class_manual_cleanup(obd);
4784 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4785 struct lu_device *dev)
4787 struct osd_device *osd = osd_dev(dev);
4791 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 55, 0)
4792 /* Unfortunately, the current MDD implementation relies on some specific
4793 * code to be executed in the OSD layer. Since OFD now also uses the OSD
4794 * module, we need a way to skip the metadata-specific code when running
4796 * The hack here is to check the type of the parent device which is
4797 * either MD (i.e. MDD device) with the current MDT stack or DT (i.e.
4798 * OFD device) on an OST. As a reminder, obdfilter does not use the OSD
4799 * layer and still relies on lvfs. This hack won't work any more when
4800 * LOD is landed since LOD is of DT type.
4801 * This code should be removed once the orion MDT changes (LOD/OSP, ...)
4802 * have been landed */
4803 osd->od_is_md = lu_device_is_md(pdev);
4805 #warning "all is_md checks must be removed from osd-ldiskfs"
4808 if (osd->od_is_md) {
4809 /* 1. setup local objects */
4810 result = llo_local_objects_setup(env, lu2md_dev(pdev),
4816 /* 2. setup quota slave instance */
4817 osd->od_quota_slave = qsd_init(env, osd->od_svname, &osd->od_dt_dev,
4818 osd->od_proc_entry);
4819 if (IS_ERR(osd->od_quota_slave)) {
4820 result = PTR_ERR(osd->od_quota_slave);
4821 osd->od_quota_slave = NULL;
4827 static const struct lu_object_operations osd_lu_obj_ops = {
4828 .loo_object_init = osd_object_init,
4829 .loo_object_delete = osd_object_delete,
4830 .loo_object_release = osd_object_release,
4831 .loo_object_free = osd_object_free,
4832 .loo_object_print = osd_object_print,
4833 .loo_object_invariant = osd_object_invariant
4836 const struct lu_device_operations osd_lu_ops = {
4837 .ldo_object_alloc = osd_object_alloc,
4838 .ldo_process_config = osd_process_config,
4839 .ldo_recovery_complete = osd_recovery_complete,
4840 .ldo_prepare = osd_prepare,
4843 static const struct lu_device_type_operations osd_device_type_ops = {
4844 .ldto_init = osd_type_init,
4845 .ldto_fini = osd_type_fini,
4847 .ldto_start = osd_type_start,
4848 .ldto_stop = osd_type_stop,
4850 .ldto_device_alloc = osd_device_alloc,
4851 .ldto_device_free = osd_device_free,
4853 .ldto_device_init = osd_device_init,
4854 .ldto_device_fini = osd_device_fini
4857 struct lu_device_type osd_device_type = {
4858 .ldt_tags = LU_DEVICE_DT,
4859 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4860 .ldt_ops = &osd_device_type_ops,
4861 .ldt_ctx_tags = LCT_LOCAL,
4865 * lprocfs legacy support.
4867 static struct obd_ops osd_obd_device_ops = {
4868 .o_owner = THIS_MODULE,
4869 .o_connect = osd_obd_connect,
4870 .o_disconnect = osd_obd_disconnect
4873 static int __init osd_mod_init(void)
4875 struct lprocfs_static_vars lvars;
4878 lprocfs_osd_init_vars(&lvars);
4879 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4880 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4883 static void __exit osd_mod_exit(void)
4885 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4888 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4889 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4890 MODULE_LICENSE("GPL");
4892 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);