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, 2014, Intel Corporation.
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_OSD
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>
57 #include <ldiskfs/ldiskfs.h>
58 #include <ldiskfs/xattr.h>
61 * struct OBD_{ALLOC,FREE}*()
64 #include <obd_support.h>
65 /* struct ptlrpc_thread */
66 #include <lustre_net.h>
67 #include <lustre_fid.h>
69 #include <lustre_param.h>
71 #include "osd_internal.h"
72 #include "osd_dynlocks.h"
74 /* llo_* api support */
75 #include <md_object.h>
76 #include <lustre_quota.h>
78 #include <lustre_linkea.h>
81 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
82 "ldiskfs with parallel directory operations");
84 int ldiskfs_track_declares_assert;
85 CFS_MODULE_PARM(ldiskfs_track_declares_assert, "i", int, 0644,
86 "LBUG during tracking of declares");
88 /* Slab to allocate dynlocks */
89 struct kmem_cache *dynlock_cachep;
91 /* Slab to allocate osd_it_ea */
92 struct kmem_cache *osd_itea_cachep;
94 static struct lu_kmem_descr ldiskfs_caches[] = {
96 .ckd_cache = &dynlock_cachep,
97 .ckd_name = "dynlock_cache",
98 .ckd_size = sizeof(struct dynlock_handle)
101 .ckd_cache = &osd_itea_cachep,
102 .ckd_name = "osd_itea_cache",
103 .ckd_size = sizeof(struct osd_it_ea)
110 static const char dot[] = ".";
111 static const char dotdot[] = "..";
112 static const char remote_obj_dir[] = "REM_OBJ_DIR";
114 static const struct lu_object_operations osd_lu_obj_ops;
115 static const struct dt_object_operations osd_obj_ops;
116 static const struct dt_object_operations osd_obj_ea_ops;
117 static const struct dt_object_operations osd_obj_otable_it_ops;
118 static const struct dt_index_operations osd_index_iam_ops;
119 static const struct dt_index_operations osd_index_ea_ops;
121 int osd_trans_declare_op2rb[] = {
122 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
123 [OSD_OT_PUNCH] = OSD_OT_MAX,
124 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
125 [OSD_OT_CREATE] = OSD_OT_DESTROY,
126 [OSD_OT_DESTROY] = OSD_OT_CREATE,
127 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
128 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
129 [OSD_OT_WRITE] = OSD_OT_WRITE,
130 [OSD_OT_INSERT] = OSD_OT_DELETE,
131 [OSD_OT_DELETE] = OSD_OT_INSERT,
132 [OSD_OT_QUOTA] = OSD_OT_MAX,
135 static int osd_has_index(const struct osd_object *obj)
137 return obj->oo_dt.do_index_ops != NULL;
140 static int osd_object_invariant(const struct lu_object *l)
142 return osd_invariant(osd_obj(l));
146 * Concurrency: doesn't matter
150 * Concurrency: doesn't matter
152 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
154 struct osd_thread_info *oti = osd_oti_get(env);
155 return oti->oti_w_locks > 0 && o->oo_owner == env;
159 * Concurrency: doesn't access mutable data
161 static int osd_root_get(const struct lu_env *env,
162 struct dt_device *dev, struct lu_fid *f)
164 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
169 * OSD object methods.
173 * Concurrency: no concurrent access is possible that early in object
176 static struct lu_object *osd_object_alloc(const struct lu_env *env,
177 const struct lu_object_header *hdr,
180 struct osd_object *mo;
186 l = &mo->oo_dt.do_lu;
187 dt_object_init(&mo->oo_dt, NULL, d);
188 mo->oo_dt.do_ops = &osd_obj_ea_ops;
189 l->lo_ops = &osd_lu_obj_ops;
190 init_rwsem(&mo->oo_sem);
191 init_rwsem(&mo->oo_ext_idx_sem);
192 spin_lock_init(&mo->oo_guard);
199 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
200 struct dentry *dentry, struct lustre_mdt_attrs *lma)
204 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
205 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
206 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
208 if ((void *)lma != (void *)info->oti_mdt_attrs_old)
209 memcpy(lma, info->oti_mdt_attrs_old, sizeof(*lma));
211 lustre_lma_swab(lma);
212 /* Check LMA compatibility */
213 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
214 CWARN("%.16s: unsupported incompat LMA feature(s) %#x "
215 "for fid = "DFID", ino = %lu\n",
216 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
217 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
218 PFID(&lma->lma_self_fid), inode->i_ino);
221 } else if (rc == 0) {
229 * retrieve object from backend ext fs.
231 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
232 struct osd_inode_id *id)
234 struct inode *inode = NULL;
236 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
238 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
239 id->oii_ino, PTR_ERR(inode));
240 } else if (id->oii_gen != OSD_OII_NOGEN &&
241 inode->i_generation != id->oii_gen) {
242 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
243 "i_generation = %u\n",
244 id->oii_ino, id->oii_gen, inode->i_generation);
246 inode = ERR_PTR(-ESTALE);
247 } else if (inode->i_nlink == 0) {
248 /* due to parallel readdir and unlink,
249 * we can have dead inode here. */
250 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
252 inode = ERR_PTR(-ESTALE);
253 } else if (is_bad_inode(inode)) {
254 CWARN("%.16s: bad inode: ino = %u\n",
255 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
257 inode = ERR_PTR(-ENOENT);
259 if (id->oii_gen == OSD_OII_NOGEN)
260 osd_id_gen(id, inode->i_ino, inode->i_generation);
262 /* Do not update file c/mtime in ldiskfs.
263 * NB: we don't have any lock to protect this because we don't
264 * have reference on osd_object now, but contention with
265 * another lookup + attr_set can't happen in the tiny window
266 * between if (...) and set S_NOCMTIME. */
267 if (!(inode->i_flags & S_NOCMTIME))
268 inode->i_flags |= S_NOCMTIME;
273 static struct inode *
274 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
275 struct osd_inode_id *id, struct lu_fid *fid)
277 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
281 inode = osd_iget(info, dev, id);
285 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
287 *fid = lma->lma_self_fid;
288 } else if (rc == -ENODATA) {
289 if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
290 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
292 lu_igif_build(fid, inode->i_ino, inode->i_generation);
300 static struct inode *osd_iget_check(struct osd_thread_info *info,
301 struct osd_device *dev,
302 const struct lu_fid *fid,
303 struct osd_inode_id *id,
310 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
313 if (!in_oi || (rc != -ENOENT && rc != -ESTALE)) {
314 CDEBUG(D_INODE, "no inode: ino = %u, rc = %d\n",
323 if (is_bad_inode(inode)) {
326 CDEBUG(D_INODE, "bad inode: ino = %u\n", id->oii_ino);
334 if (id->oii_gen != OSD_OII_NOGEN &&
335 inode->i_generation != id->oii_gen) {
338 CDEBUG(D_INODE, "unmatched inode: ino = %u, "
339 "oii_gen = %u, i_generation = %u\n",
340 id->oii_ino, id->oii_gen, inode->i_generation);
348 if (inode->i_nlink == 0) {
351 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
361 struct osd_inode_id saved_id = *id;
363 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
365 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
366 /* XXX: There are some possible cases:
368 * Backup/restore caused the OI invalid.
370 * Someone unlinked the object but NOT removed
371 * the OI mapping, such as mount target device
372 * as ldiskfs, and modify something directly.
374 * Someone just removed the object between the
375 * former oi_lookup and the iget. It is normal.
376 * 4. Other failure cases.
378 * Generally, when the device is mounted, it will
379 * auto check whether the system is restored from
380 * file-level backup or not. We trust such detect
381 * to distinguish the 1st case from the 2nd case. */
383 if (!IS_ERR(inode) && inode->i_generation != 0 &&
384 inode->i_generation == id->oii_gen) {
387 __u32 level = D_LFSCK;
390 if (!thread_is_running(&dev->od_scrub.os_thread))
393 CDEBUG(level, "%s: the OI mapping for the FID "
394 DFID" become inconsistent, the given ID "
395 "%u/%u, the ID in OI mapping %u/%u\n",
396 osd_name(dev), PFID(fid),
397 saved_id.oii_ino, saved_id.oii_gen,
398 id->oii_ino, id->oii_ino);
402 if (id->oii_gen == OSD_OII_NOGEN)
403 osd_id_gen(id, inode->i_ino, inode->i_generation);
405 /* Do not update file c/mtime in ldiskfs.
406 * NB: we don't have any lock to protect this because we don't
407 * have reference on osd_object now, but contention with
408 * another lookup + attr_set can't happen in the tiny window
409 * between if (...) and set S_NOCMTIME. */
410 if (!(inode->i_flags & S_NOCMTIME))
411 inode->i_flags |= S_NOCMTIME;
428 * \retval +v: new filter_fid, does not contain self-fid
429 * \retval 0: filter_fid_old, contains self-fid
430 * \retval -v: other failure cases
432 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
433 struct dentry *dentry, struct lu_fid *fid)
435 struct filter_fid_old *ff = &info->oti_ff;
436 struct ost_id *ostid = &info->oti_ostid;
439 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
440 if (rc == sizeof(*ff)) {
442 ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
443 ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
444 /* XXX: should use real OST index in the future. LU-3569 */
445 ostid_to_fid(fid, ostid, 0);
446 } else if (rc == sizeof(struct filter_fid)) {
448 } else if (rc >= 0) {
455 static int osd_lma_self_repair(struct osd_thread_info *info,
456 struct osd_device *osd, struct inode *inode,
457 const struct lu_fid *fid, __u32 compat)
462 LASSERT(current->journal_info == NULL);
464 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
465 osd_dto_credits_noquota[DTO_XATTR_SET]);
468 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
473 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
475 CWARN("%s: cannot self repair the LMA: rc = %d\n",
477 ldiskfs_journal_stop(jh);
481 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
483 struct osd_thread_info *info = osd_oti_get(env);
484 struct osd_device *osd = osd_obj2dev(obj);
485 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
486 struct inode *inode = obj->oo_inode;
487 struct dentry *dentry = &info->oti_obj_dentry;
488 struct lu_fid *fid = NULL;
489 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
493 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
494 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
495 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
496 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
497 fid = &lma->lma_self_fid;
498 rc = osd_get_idif(info, inode, dentry, fid);
499 if ((rc > 0) || (rc == -ENODATA && osd->od_index_in_idif)) {
500 /* For the given OST-object, if it has neither LMA nor
501 * FID in XATTR_NAME_FID, then the given FID (which is
502 * contained in the @obj, from client RPC for locating
503 * the OST-object) is trusted. We use it to generate
505 osd_lma_self_repair(info, osd, inode, rfid,
511 if (unlikely(rc == -ENODATA))
519 lustre_lma_swab(lma);
520 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
521 CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
522 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
523 "fid = "DFID", ino = %lu\n", osd_name(osd),
524 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
525 PFID(rfid), inode->i_ino);
528 fid = &lma->lma_self_fid;
532 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
533 __u32 level = D_LFSCK;
535 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
536 struct ost_id *oi = &info->oti_ostid;
537 struct lu_fid *fid1 = &info->oti_fid3;
538 __u32 idx = fid_idif_ost_idx(rfid);
540 /* For old IDIF, the OST index is not part of the IDIF,
541 * Means that different OSTs may have the same IDIFs.
542 * Under such case, we need to make some compatible
543 * check to make sure to trigger OI scrub properly. */
544 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
545 /* Given @rfid is new, LMA is old. */
546 fid_to_ostid(fid, oi);
547 ostid_to_fid(fid1, oi, idx);
548 if (lu_fid_eq(fid1, rfid)) {
549 if (osd->od_index_in_idif)
550 osd_lma_self_repair(info, osd,
560 if (!thread_is_running(&osd->od_scrub.os_thread))
563 CDEBUG(level, "%s: FID "DFID" != self_fid "DFID"\n",
564 osd_name(osd), PFID(rfid), PFID(fid));
570 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
571 const struct lu_fid *fid,
572 const struct lu_object_conf *conf)
574 struct osd_thread_info *info;
575 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
576 struct osd_device *dev;
577 struct osd_idmap_cache *oic;
578 struct osd_inode_id *id;
580 struct osd_scrub *scrub;
581 struct scrub_file *sf;
585 bool triggered = false;
588 LINVRNT(osd_invariant(obj));
589 LASSERT(obj->oo_inode == NULL);
590 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
593 scrub = &dev->od_scrub;
594 sf = &scrub->os_file;
595 info = osd_oti_get(env);
597 oic = &info->oti_cache;
599 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
602 /* For the object is created as locking anchor, or for the object to
603 * be created on disk. No need to osd_oi_lookup() at here because FID
604 * shouldn't never be re-used, if it's really a duplicate FID from
605 * unexpected reason, we should be able to detect it later by calling
606 * do_create->osd_oi_insert(). */
607 if (conf != NULL && conf->loc_flags & LOC_F_NEW)
608 GOTO(out, result = 0);
610 /* Search order: 1. per-thread cache. */
611 if (lu_fid_eq(fid, &oic->oic_fid) &&
612 likely(oic->oic_dev == dev)) {
618 if (!list_empty(&scrub->os_inconsistent_items)) {
619 /* Search order: 2. OI scrub pending list. */
620 result = osd_oii_lookup(dev, fid, id);
625 /* Search order: 3. OI files. */
626 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
627 if (result == -ENOENT) {
628 if (!fid_is_norm(fid) ||
629 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
630 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
632 GOTO(out, result = 0);
643 inode = osd_iget_check(info, dev, fid, id, in_oi);
645 result = PTR_ERR(inode);
646 if (result == -ENOENT || result == -ESTALE) {
648 fid_zero(&oic->oic_fid);
650 GOTO(out, result = -ENOENT);
651 } else if (result == -EREMCHG) {
655 fid_zero(&oic->oic_fid);
657 if (unlikely(triggered))
658 GOTO(out, result = saved);
661 if (thread_is_running(&scrub->os_thread)) {
662 result = -EINPROGRESS;
663 } else if (!dev->od_noscrub) {
664 /* Since we do not know the right OI mapping,
665 * we have to trigger OI scrub to scan the
667 result = osd_scrub_start(dev, SS_AUTO_FULL |
668 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
669 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI "
670 "scrub by RPC for "DFID", rc = %d [1]\n",
671 osd_name(dev), PFID(fid),result);
672 if (result == 0 || result == -EALREADY)
673 result = -EINPROGRESS;
678 /* We still have chance to get the valid inode: for the
679 * object which is referenced by remote name entry, the
680 * object on the local MDT will be linked under the dir
681 * of "/REMOTE_PARENT_DIR" with its FID string as name.
683 * We do not know whether the object for the given FID
684 * is referenced by some remote name entry or not, and
685 * especially for DNE II, a multiple-linked object may
686 * have many name entries reside on many MDTs.
688 * To simplify the operation, OSD will not distinguish
689 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
690 * only happened for the RPC from other MDT during the
691 * OI scrub, or for the client side RPC with FID only,
692 * such as FID to path, or from old connected client. */
694 result = osd_lookup_in_remote_parent(info, dev,
707 obj->oo_inode = inode;
708 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
710 result = osd_check_lma(env, obj);
713 obj->oo_inode = NULL;
714 if (result == -EREMCHG) {
716 result = osd_oi_lookup(info, dev, fid, id,
719 fid_zero(&oic->oic_fid);
730 obj->oo_compat_dot_created = 1;
731 obj->oo_compat_dotdot_created = 1;
733 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
734 GOTO(out, result = 0);
736 LASSERT(obj->oo_hl_head == NULL);
737 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
738 if (obj->oo_hl_head == NULL) {
739 obj->oo_inode = NULL;
741 GOTO(out, result = -ENOMEM);
743 GOTO(out, result = 0);
746 LINVRNT(osd_invariant(obj));
751 * Concurrency: shouldn't matter.
753 static void osd_object_init0(struct osd_object *obj)
755 LASSERT(obj->oo_inode != NULL);
756 obj->oo_dt.do_body_ops = &osd_body_ops;
757 obj->oo_dt.do_lu.lo_header->loh_attr |=
758 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
762 * Concurrency: no concurrent access is possible that early in object
765 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
766 const struct lu_object_conf *conf)
768 struct osd_object *obj = osd_obj(l);
771 LINVRNT(osd_invariant(obj));
773 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
774 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
775 l->lo_header->loh_attr |= LOHA_EXISTS;
779 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
780 obj->oo_dt.do_body_ops = &osd_body_ops_new;
781 if (result == 0 && obj->oo_inode != NULL)
782 osd_object_init0(obj);
784 LINVRNT(osd_invariant(obj));
789 * Concurrency: no concurrent access is possible that late in object
792 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
794 struct osd_object *obj = osd_obj(l);
796 LINVRNT(osd_invariant(obj));
798 dt_object_fini(&obj->oo_dt);
799 if (obj->oo_hl_head != NULL)
800 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
805 * Concurrency: no concurrent access is possible that late in object
808 static void osd_index_fini(struct osd_object *o)
810 struct iam_container *bag;
812 if (o->oo_dir != NULL) {
813 bag = &o->oo_dir->od_container;
814 if (o->oo_inode != NULL) {
815 if (bag->ic_object == o->oo_inode)
816 iam_container_fini(bag);
818 OBD_FREE_PTR(o->oo_dir);
824 * Concurrency: no concurrent access is possible that late in object
825 * life-cycle (for all existing callers, that is. New callers have to provide
826 * their own locking.)
828 static int osd_inode_unlinked(const struct inode *inode)
830 return inode->i_nlink == 0;
834 OSD_TXN_OI_DELETE_CREDITS = 20,
835 OSD_TXN_INODE_DELETE_CREDITS = 20
842 #if OSD_THANDLE_STATS
844 * Set time when the handle is allocated
846 static void osd_th_alloced(struct osd_thandle *oth)
848 oth->oth_alloced = cfs_time_current();
852 * Set time when the handle started
854 static void osd_th_started(struct osd_thandle *oth)
856 oth->oth_started = cfs_time_current();
860 * Helper function to convert time interval to microseconds packed in
863 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
867 cfs_duration_usec(cfs_time_sub(end, start), &val);
868 return val.tv_sec * 1000000 + val.tv_usec;
872 * Check whether the we deal with this handle for too long.
874 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
875 cfs_time_t alloced, cfs_time_t started,
878 cfs_time_t now = cfs_time_current();
880 LASSERT(dev != NULL);
882 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
883 interval_to_usec(alloced, started));
884 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
885 interval_to_usec(started, closed));
886 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
887 interval_to_usec(closed, now));
889 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
890 CWARN("transaction handle %p was open for too long: "
892 "alloced "CFS_TIME_T" ,"
893 "started "CFS_TIME_T" ,"
894 "closed "CFS_TIME_T"\n",
895 oth, now, alloced, started, closed);
896 libcfs_debug_dumpstack(NULL);
900 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
902 cfs_time_t __closed = cfs_time_current(); \
903 cfs_time_t __alloced = oth->oth_alloced; \
904 cfs_time_t __started = oth->oth_started; \
907 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
910 #else /* OSD_THANDLE_STATS */
912 #define osd_th_alloced(h) do {} while(0)
913 #define osd_th_started(h) do {} while(0)
914 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
916 #endif /* OSD_THANDLE_STATS */
919 * Concurrency: doesn't access mutable data.
921 static int osd_param_is_not_sane(const struct osd_device *dev,
922 const struct thandle *th)
924 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
926 return oh->ot_credits > osd_transaction_size(dev);
930 * Concurrency: shouldn't matter.
932 static void osd_trans_commit_cb(struct super_block *sb,
933 struct ldiskfs_journal_cb_entry *jcb, int error)
935 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
936 struct thandle *th = &oh->ot_super;
937 struct lu_device *lud = &th->th_dev->dd_lu_dev;
938 struct dt_txn_commit_cb *dcb, *tmp;
940 LASSERT(oh->ot_handle == NULL);
943 CERROR("transaction @0x%p commit error: %d\n", th, error);
945 dt_txn_hook_commit(th);
947 /* call per-transaction callbacks if any */
948 list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
949 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
950 "commit callback entry: magic=%x name='%s'\n",
951 dcb->dcb_magic, dcb->dcb_name);
952 list_del_init(&dcb->dcb_linkage);
953 dcb->dcb_func(NULL, th, dcb, error);
956 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
960 lu_context_exit(&th->th_ctx);
961 lu_context_fini(&th->th_ctx);
965 static struct thandle *osd_trans_create(const struct lu_env *env,
968 struct osd_thread_info *oti = osd_oti_get(env);
969 struct osd_iobuf *iobuf = &oti->oti_iobuf;
970 struct osd_thandle *oh;
974 /* on pending IO in this thread should left from prev. request */
975 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
977 th = ERR_PTR(-ENOMEM);
978 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
980 oh->ot_quota_trans = &oti->oti_quota_trans;
981 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
985 th->th_tags = LCT_TX_HANDLE;
987 atomic_set(&th->th_refc, 1);
988 th->th_alloc_size = sizeof(*oh);
989 INIT_LIST_HEAD(&oh->ot_dcb_list);
992 memset(oti->oti_declare_ops, 0,
993 sizeof(oti->oti_declare_ops));
994 memset(oti->oti_declare_ops_rb, 0,
995 sizeof(oti->oti_declare_ops_rb));
996 memset(oti->oti_declare_ops_cred, 0,
997 sizeof(oti->oti_declare_ops_cred));
998 oti->oti_rollback = false;
1004 * Concurrency: shouldn't matter.
1006 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1009 struct osd_thread_info *oti = osd_oti_get(env);
1010 struct osd_device *dev = osd_dt_dev(d);
1012 struct osd_thandle *oh;
1017 LASSERT(current->journal_info == NULL);
1019 oh = container_of0(th, struct osd_thandle, ot_super);
1020 LASSERT(oh != NULL);
1021 LASSERT(oh->ot_handle == NULL);
1023 rc = dt_txn_hook_start(env, d, th);
1027 if (unlikely(osd_param_is_not_sane(dev, th))) {
1028 static unsigned long last_printed;
1029 static int last_credits;
1031 CWARN("%.16s: too many transaction credits (%d > %d)\n",
1032 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
1034 osd_journal(dev)->j_max_transaction_buffers);
1035 CWARN(" create: %u/%u, destroy: %u/%u\n",
1036 oti->oti_declare_ops[OSD_OT_CREATE],
1037 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1038 oti->oti_declare_ops[OSD_OT_DESTROY],
1039 oti->oti_declare_ops_cred[OSD_OT_DESTROY]);
1040 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
1041 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1042 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1043 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1044 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]);
1045 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
1046 oti->oti_declare_ops[OSD_OT_WRITE],
1047 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1048 oti->oti_declare_ops[OSD_OT_PUNCH],
1049 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1050 oti->oti_declare_ops[OSD_OT_QUOTA],
1051 oti->oti_declare_ops_cred[OSD_OT_QUOTA]);
1052 CWARN(" insert: %u/%u, delete: %u/%u\n",
1053 oti->oti_declare_ops[OSD_OT_INSERT],
1054 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1055 oti->oti_declare_ops[OSD_OT_DELETE],
1056 oti->oti_declare_ops_cred[OSD_OT_DELETE]);
1057 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
1058 oti->oti_declare_ops[OSD_OT_REF_ADD],
1059 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1060 oti->oti_declare_ops[OSD_OT_REF_DEL],
1061 oti->oti_declare_ops_cred[OSD_OT_REF_DEL]);
1063 if (last_credits != oh->ot_credits &&
1064 time_after(jiffies, last_printed +
1065 msecs_to_jiffies(60 * MSEC_PER_SEC))) {
1066 libcfs_debug_dumpstack(NULL);
1067 last_credits = oh->ot_credits;
1068 last_printed = jiffies;
1070 /* XXX Limit the credits to 'max_transaction_buffers', and
1071 * let the underlying filesystem to catch the error if
1072 * we really need so many credits.
1074 * This should be removed when we can calculate the
1075 * credits precisely. */
1076 oh->ot_credits = osd_transaction_size(dev);
1080 * XXX temporary stuff. Some abstraction layer should
1083 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1087 LASSERT(oti->oti_txns == 0);
1088 lu_context_init(&th->th_ctx, th->th_tags);
1089 lu_context_enter(&th->th_ctx);
1091 lu_device_get(&d->dd_lu_dev);
1092 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1103 static int osd_seq_exists(const struct lu_env *env,
1104 struct osd_device *osd, u64 seq)
1106 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1107 struct seq_server_site *ss = osd_seq_site(osd);
1111 LASSERT(ss != NULL);
1112 LASSERT(ss->ss_server_fld != NULL);
1114 rc = osd_fld_lookup(env, osd, seq, range);
1117 CERROR("%s: can't lookup FLD sequence "LPX64
1118 ": rc = %d\n", osd_name(osd), seq, rc);
1122 RETURN(ss->ss_node_id == range->lsr_index);
1126 * Concurrency: shouldn't matter.
1128 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1132 struct osd_thandle *oh;
1133 struct osd_thread_info *oti = osd_oti_get(env);
1134 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1135 struct osd_device *osd = osd_dt_dev(th->th_dev);
1136 struct qsd_instance *qsd = osd->od_quota_slave;
1137 struct lquota_trans *qtrans;
1140 oh = container_of0(th, struct osd_thandle, ot_super);
1142 qtrans = oh->ot_quota_trans;
1143 oh->ot_quota_trans = NULL;
1145 if (oh->ot_handle != NULL) {
1146 handle_t *hdl = oh->ot_handle;
1149 * add commit callback
1150 * notice we don't do this in osd_trans_start()
1151 * as underlying transaction can change during truncate
1153 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1156 LASSERT(oti->oti_txns == 1);
1158 rc = dt_txn_hook_stop(env, th);
1160 CERROR("%s: failed in transaction hook: rc = %d\n",
1163 /* hook functions might modify th_sync */
1164 hdl->h_sync = th->th_sync;
1166 oh->ot_handle = NULL;
1167 OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl));
1169 CERROR("%s: failed to stop transaction: rc = %d\n",
1172 thandle_put(&oh->ot_super);
1175 /* inform the quota slave device that the transaction is stopping */
1176 qsd_op_end(env, qsd, qtrans);
1178 /* as we want IO to journal and data IO be concurrent, we don't block
1179 * awaiting data IO completion in osd_do_bio(), instead we wait here
1180 * once transaction is submitted to the journal. all reqular requests
1181 * don't do direct IO (except read/write), thus this wait_event becomes
1184 * IMPORTANT: we have to wait till any IO submited by the thread is
1185 * completed otherwise iobuf may be corrupted by different request
1187 wait_event(iobuf->dr_wait,
1188 atomic_read(&iobuf->dr_numreqs) == 0);
1189 osd_fini_iobuf(osd, iobuf);
1191 rc = iobuf->dr_error;
1196 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1198 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1201 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1202 LASSERT(&dcb->dcb_func != NULL);
1203 list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
1209 * Called just before object is freed. Releases all resources except for
1210 * object itself (that is released by osd_object_free()).
1212 * Concurrency: no concurrent access is possible that late in object
1215 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1217 struct osd_object *obj = osd_obj(l);
1218 struct inode *inode = obj->oo_inode;
1220 LINVRNT(osd_invariant(obj));
1223 * If object is unlinked remove fid->ino mapping from object index.
1226 osd_index_fini(obj);
1227 if (inode != NULL) {
1228 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1229 qid_t uid = i_uid_read(inode);
1230 qid_t gid = i_gid_read(inode);
1233 obj->oo_inode = NULL;
1236 struct osd_thread_info *info = osd_oti_get(env);
1237 struct lquota_id_info *qi = &info->oti_qi;
1239 /* Release granted quota to master if necessary */
1240 qi->lqi_id.qid_uid = uid;
1241 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1243 qi->lqi_id.qid_uid = gid;
1244 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
1250 * Concurrency: ->loo_object_release() is called under site spin-lock.
1252 static void osd_object_release(const struct lu_env *env,
1253 struct lu_object *l)
1258 * Concurrency: shouldn't matter.
1260 static int osd_object_print(const struct lu_env *env, void *cookie,
1261 lu_printer_t p, const struct lu_object *l)
1263 struct osd_object *o = osd_obj(l);
1264 struct iam_descr *d;
1266 if (o->oo_dir != NULL)
1267 d = o->oo_dir->od_container.ic_descr;
1270 return (*p)(env, cookie,
1271 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
1273 o->oo_inode ? o->oo_inode->i_ino : 0UL,
1274 o->oo_inode ? o->oo_inode->i_generation : 0,
1275 d ? d->id_ops->id_name : "plain");
1278 #define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */
1281 * Concurrency: shouldn't matter.
1283 int osd_statfs(const struct lu_env *env, struct dt_device *d,
1284 struct obd_statfs *sfs)
1286 struct osd_device *osd = osd_dt_dev(d);
1287 struct super_block *sb = osd_sb(osd);
1288 struct kstatfs *ksfs;
1291 if (unlikely(osd->od_mnt == NULL))
1292 return -EINPROGRESS;
1294 /* osd_lproc.c call this without env, allocate ksfs for that case */
1295 if (unlikely(env == NULL)) {
1296 OBD_ALLOC_PTR(ksfs);
1300 ksfs = &osd_oti_get(env)->oti_ksfs;
1303 spin_lock(&osd->od_osfs_lock);
1304 result = sb->s_op->statfs(sb->s_root, ksfs);
1305 if (likely(result == 0)) { /* N.B. statfs can't really fail */
1306 statfs_pack(sfs, ksfs);
1307 if (sb->s_flags & MS_RDONLY)
1308 sfs->os_state = OS_STATE_READONLY;
1311 spin_unlock(&osd->od_osfs_lock);
1313 if (unlikely(env == NULL))
1316 /* Reserve a small amount of space for local objects like last_rcvd,
1317 * llog, quota files, ... */
1318 if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) {
1321 sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS;
1322 /** Take out metadata overhead for indirect blocks */
1323 sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3);
1330 * Estimate space needed for file creations. We assume the largest filename
1331 * which is 2^64 - 1, hence a filename of 20 chars.
1332 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
1334 #ifdef __LDISKFS_DIR_REC_LEN
1335 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
1337 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
1341 * Concurrency: doesn't access mutable data.
1343 static void osd_conf_get(const struct lu_env *env,
1344 const struct dt_device *dev,
1345 struct dt_device_param *param)
1347 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1351 * XXX should be taken from not-yet-existing fs abstraction layer.
1353 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1354 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1355 param->ddp_block_shift = sb->s_blocksize_bits;
1356 param->ddp_mount_type = LDD_MT_LDISKFS;
1357 param->ddp_maxbytes = sb->s_maxbytes;
1358 /* Overhead estimate should be fairly accurate, so we really take a tiny
1359 * error margin which also avoids fragmenting the filesystem too much */
1360 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
1361 /* inode are statically allocated, so per-inode space consumption
1362 * is the space consumed by the directory entry */
1363 param->ddp_inodespace = PER_OBJ_USAGE;
1364 /* per-fragment overhead to be used by the client code */
1365 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
1366 param->ddp_mntopts = 0;
1367 if (test_opt(sb, XATTR_USER))
1368 param->ddp_mntopts |= MNTOPT_USERXATTR;
1369 if (test_opt(sb, POSIX_ACL))
1370 param->ddp_mntopts |= MNTOPT_ACL;
1372 /* LOD might calculate the max stripe count based on max_ea_size,
1373 * so we need take account in the overhead as well,
1374 * xattr_header + magic + xattr_entry_head */
1375 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
1376 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
1378 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1379 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1380 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
1384 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
1388 * Concurrency: shouldn't matter.
1390 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1394 CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1396 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1398 CDEBUG(D_CACHE, "synced OSD %s: rc = %d\n",
1399 LUSTRE_OSD_LDISKFS_NAME, rc);
1405 * Start commit for OSD device.
1407 * An implementation of dt_commit_async method for OSD device.
1408 * Asychronously starts underlayng fs sync and thereby a transaction
1411 * \param env environment
1412 * \param d dt device
1414 * \see dt_device_operations
1416 static int osd_commit_async(const struct lu_env *env,
1417 struct dt_device *d)
1419 struct super_block *s = osd_sb(osd_dt_dev(d));
1422 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1423 RETURN(s->s_op->sync_fs(s, 0));
1427 * Concurrency: shouldn't matter.
1430 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1432 struct super_block *sb = osd_sb(osd_dt_dev(d));
1433 struct block_device *dev = sb->s_bdev;
1434 #ifdef HAVE_DEV_SET_RDONLY
1435 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
1438 int rc = -EOPNOTSUPP;
1442 #ifdef HAVE_DEV_SET_RDONLY
1443 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1445 if (jdev && (jdev != dev)) {
1446 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
1448 dev_set_rdonly(jdev);
1450 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
1451 dev_set_rdonly(dev);
1453 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
1454 osd_dt_dev(d)->od_svname, (long)dev, rc);
1460 * Note: we do not count into QUOTA here.
1461 * If we mount with --data_journal we may need more.
1463 const int osd_dto_credits_noquota[DTO_NR] = {
1466 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1467 * SINGLEDATA_TRANS_BLOCKS(8)
1468 * XXX Note: maybe iam need more, since iam have more level than
1471 [DTO_INDEX_INSERT] = 16,
1474 * just modify a single entry, probably merge few within a block
1476 [DTO_INDEX_DELETE] = 1,
1480 [DTO_INDEX_UPDATE] = 16,
1482 * 4(inode, inode bits, groups, GDT)
1483 * notice: OI updates are counted separately with DTO_INDEX_INSERT
1485 [DTO_OBJECT_CREATE] = 4,
1487 * 4(inode, inode bits, groups, GDT)
1488 * notice: OI updates are counted separately with DTO_INDEX_DELETE
1490 [DTO_OBJECT_DELETE] = 4,
1492 * Attr set credits (inode)
1494 [DTO_ATTR_SET_BASE] = 1,
1496 * Xattr set. The same as xattr of EXT3.
1497 * DATA_TRANS_BLOCKS(14)
1498 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1499 * are also counted in. Do not know why?
1501 [DTO_XATTR_SET] = 14,
1503 * credits for inode change during write.
1505 [DTO_WRITE_BASE] = 3,
1507 * credits for single block write.
1509 [DTO_WRITE_BLOCK] = 14,
1511 * Attr set credits for chown.
1512 * This is extra credits for setattr, and it is null without quota
1514 [DTO_ATTR_SET_CHOWN] = 0
1517 static const struct dt_device_operations osd_dt_ops = {
1518 .dt_root_get = osd_root_get,
1519 .dt_statfs = osd_statfs,
1520 .dt_trans_create = osd_trans_create,
1521 .dt_trans_start = osd_trans_start,
1522 .dt_trans_stop = osd_trans_stop,
1523 .dt_trans_cb_add = osd_trans_cb_add,
1524 .dt_conf_get = osd_conf_get,
1525 .dt_sync = osd_sync,
1527 .dt_commit_async = osd_commit_async,
1530 static void osd_object_read_lock(const struct lu_env *env,
1531 struct dt_object *dt, unsigned role)
1533 struct osd_object *obj = osd_dt_obj(dt);
1534 struct osd_thread_info *oti = osd_oti_get(env);
1536 LINVRNT(osd_invariant(obj));
1538 LASSERT(obj->oo_owner != env);
1539 down_read_nested(&obj->oo_sem, role);
1541 LASSERT(obj->oo_owner == NULL);
1545 static void osd_object_write_lock(const struct lu_env *env,
1546 struct dt_object *dt, unsigned role)
1548 struct osd_object *obj = osd_dt_obj(dt);
1549 struct osd_thread_info *oti = osd_oti_get(env);
1551 LINVRNT(osd_invariant(obj));
1553 LASSERT(obj->oo_owner != env);
1554 down_write_nested(&obj->oo_sem, role);
1556 LASSERT(obj->oo_owner == NULL);
1557 obj->oo_owner = env;
1561 static void osd_object_read_unlock(const struct lu_env *env,
1562 struct dt_object *dt)
1564 struct osd_object *obj = osd_dt_obj(dt);
1565 struct osd_thread_info *oti = osd_oti_get(env);
1567 LINVRNT(osd_invariant(obj));
1569 LASSERT(oti->oti_r_locks > 0);
1571 up_read(&obj->oo_sem);
1574 static void osd_object_write_unlock(const struct lu_env *env,
1575 struct dt_object *dt)
1577 struct osd_object *obj = osd_dt_obj(dt);
1578 struct osd_thread_info *oti = osd_oti_get(env);
1580 LINVRNT(osd_invariant(obj));
1582 LASSERT(obj->oo_owner == env);
1583 LASSERT(oti->oti_w_locks > 0);
1585 obj->oo_owner = NULL;
1586 up_write(&obj->oo_sem);
1589 static int osd_object_write_locked(const struct lu_env *env,
1590 struct dt_object *dt)
1592 struct osd_object *obj = osd_dt_obj(dt);
1594 LINVRNT(osd_invariant(obj));
1596 return obj->oo_owner == env;
1599 static struct timespec *osd_inode_time(const struct lu_env *env,
1600 struct inode *inode, __u64 seconds)
1602 struct osd_thread_info *oti = osd_oti_get(env);
1603 struct timespec *t = &oti->oti_time;
1605 t->tv_sec = seconds;
1607 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1612 static void osd_inode_getattr(const struct lu_env *env,
1613 struct inode *inode, struct lu_attr *attr)
1615 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1616 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1617 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
1620 attr->la_atime = LTIME_S(inode->i_atime);
1621 attr->la_mtime = LTIME_S(inode->i_mtime);
1622 attr->la_ctime = LTIME_S(inode->i_ctime);
1623 attr->la_mode = inode->i_mode;
1624 attr->la_size = i_size_read(inode);
1625 attr->la_blocks = inode->i_blocks;
1626 attr->la_uid = i_uid_read(inode);
1627 attr->la_gid = i_gid_read(inode);
1628 attr->la_flags = LDISKFS_I(inode)->i_flags;
1629 attr->la_nlink = inode->i_nlink;
1630 attr->la_rdev = inode->i_rdev;
1631 attr->la_blksize = 1 << inode->i_blkbits;
1632 attr->la_blkbits = inode->i_blkbits;
1635 static int osd_attr_get(const struct lu_env *env,
1636 struct dt_object *dt,
1637 struct lu_attr *attr)
1639 struct osd_object *obj = osd_dt_obj(dt);
1641 if (!dt_object_exists(dt))
1644 LASSERT(!dt_object_remote(dt));
1645 LINVRNT(osd_invariant(obj));
1647 spin_lock(&obj->oo_guard);
1648 osd_inode_getattr(env, obj->oo_inode, attr);
1649 spin_unlock(&obj->oo_guard);
1653 static int osd_declare_attr_set(const struct lu_env *env,
1654 struct dt_object *dt,
1655 const struct lu_attr *attr,
1656 struct thandle *handle)
1658 struct osd_thandle *oh;
1659 struct osd_object *obj;
1660 struct osd_thread_info *info = osd_oti_get(env);
1661 struct lquota_id_info *qi = &info->oti_qi;
1669 LASSERT(dt != NULL);
1670 LASSERT(handle != NULL);
1672 obj = osd_dt_obj(dt);
1673 LASSERT(osd_invariant(obj));
1675 oh = container_of0(handle, struct osd_thandle, ot_super);
1676 LASSERT(oh->ot_handle == NULL);
1678 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
1679 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1681 if (attr == NULL || obj->oo_inode == NULL)
1684 bspace = obj->oo_inode->i_blocks;
1685 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1686 bspace = toqb(bspace);
1688 /* Changing ownership is always preformed by super user, it should not
1691 * We still need to call the osd_declare_qid() to calculate the journal
1692 * credits for updating quota accounting files and to trigger quota
1693 * space adjustment once the operation is completed.*/
1694 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
1696 uid = i_uid_read(obj->oo_inode);
1697 qi->lqi_type = USRQUOTA;
1698 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
1699 /* inode accounting */
1700 qi->lqi_is_blk = false;
1702 /* one more inode for the new uid ... */
1703 qi->lqi_id.qid_uid = attr->la_uid;
1705 /* Reserve credits for the new uid */
1706 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1707 if (rc == -EDQUOT || rc == -EINPROGRESS)
1712 /* and one less inode for the current uid */
1713 qi->lqi_id.qid_uid = uid;
1715 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1716 if (rc == -EDQUOT || rc == -EINPROGRESS)
1721 /* block accounting */
1722 qi->lqi_is_blk = true;
1724 /* more blocks for the new uid ... */
1725 qi->lqi_id.qid_uid = attr->la_uid;
1726 qi->lqi_space = bspace;
1728 * Credits for the new uid has been reserved, re-use "obj"
1729 * to save credit reservation.
1731 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1732 if (rc == -EDQUOT || rc == -EINPROGRESS)
1737 /* and finally less blocks for the current uid */
1738 qi->lqi_id.qid_uid = uid;
1739 qi->lqi_space = -bspace;
1740 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1741 if (rc == -EDQUOT || rc == -EINPROGRESS)
1747 gid = i_gid_read(obj->oo_inode);
1748 qi->lqi_type = GRPQUOTA;
1749 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
1751 /* inode accounting */
1752 qi->lqi_is_blk = false;
1754 /* one more inode for the new gid ... */
1755 qi->lqi_id.qid_gid = attr->la_gid;
1757 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1758 if (rc == -EDQUOT || rc == -EINPROGRESS)
1763 /* and one less inode for the current gid */
1764 qi->lqi_id.qid_gid = gid;
1766 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1767 if (rc == -EDQUOT || rc == -EINPROGRESS)
1772 /* block accounting */
1773 qi->lqi_is_blk = true;
1775 /* more blocks for the new gid ... */
1776 qi->lqi_id.qid_gid = attr->la_gid;
1777 qi->lqi_space = bspace;
1778 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1779 if (rc == -EDQUOT || rc == -EINPROGRESS)
1784 /* and finally less blocks for the current gid */
1785 qi->lqi_id.qid_gid = gid;
1786 qi->lqi_space = -bspace;
1787 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1788 if (rc == -EDQUOT || rc == -EINPROGRESS)
1797 static int osd_inode_setattr(const struct lu_env *env,
1798 struct inode *inode, const struct lu_attr *attr)
1800 __u64 bits = attr->la_valid;
1802 /* Only allow set size for regular file */
1803 if (!S_ISREG(inode->i_mode))
1804 bits &= ~(LA_SIZE | LA_BLOCKS);
1809 if (bits & LA_ATIME)
1810 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1811 if (bits & LA_CTIME)
1812 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1813 if (bits & LA_MTIME)
1814 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1815 if (bits & LA_SIZE) {
1816 LDISKFS_I(inode)->i_disksize = attr->la_size;
1817 i_size_write(inode, attr->la_size);
1821 /* OSD should not change "i_blocks" which is used by quota.
1822 * "i_blocks" should be changed by ldiskfs only. */
1823 if (bits & LA_BLOCKS)
1824 inode->i_blocks = attr->la_blocks;
1827 inode->i_mode = (inode->i_mode & S_IFMT) |
1828 (attr->la_mode & ~S_IFMT);
1830 i_uid_write(inode, attr->la_uid);
1832 i_gid_write(inode, attr->la_gid);
1833 if (bits & LA_NLINK)
1834 set_nlink(inode, attr->la_nlink);
1836 inode->i_rdev = attr->la_rdev;
1838 if (bits & LA_FLAGS) {
1839 /* always keep S_NOCMTIME */
1840 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1846 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1848 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
1849 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
1853 ll_vfs_dq_init(inode);
1855 if (attr->la_valid & LA_UID)
1856 iattr.ia_valid |= ATTR_UID;
1857 if (attr->la_valid & LA_GID)
1858 iattr.ia_valid |= ATTR_GID;
1859 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
1860 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
1862 rc = ll_vfs_dq_transfer(inode, &iattr);
1864 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1865 "enforcement enabled on the ldiskfs "
1866 "filesystem?\n", inode->i_sb->s_id, rc);
1873 static int osd_attr_set(const struct lu_env *env,
1874 struct dt_object *dt,
1875 const struct lu_attr *attr,
1876 struct thandle *handle)
1878 struct osd_object *obj = osd_dt_obj(dt);
1879 struct inode *inode;
1882 if (!dt_object_exists(dt))
1885 LASSERT(handle != NULL);
1886 LASSERT(!dt_object_remote(dt));
1887 LASSERT(osd_invariant(obj));
1889 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
1891 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING)) {
1892 struct osd_thread_info *oti = osd_oti_get(env);
1893 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
1894 struct lu_fid *fid1 = &oti->oti_fid;
1895 struct osd_inode_id *id = &oti->oti_id;
1896 struct iam_path_descr *ipd;
1897 struct iam_container *bag;
1898 struct osd_thandle *oh;
1901 fid_cpu_to_be(fid1, fid0);
1902 memset(id, 1, sizeof(*id));
1903 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
1904 fid0)->oi_dir.od_container;
1905 ipd = osd_idx_ipd_get(env, bag);
1906 if (unlikely(ipd == NULL))
1909 oh = container_of0(handle, struct osd_thandle, ot_super);
1910 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
1911 (const struct iam_rec *)id, ipd);
1912 osd_ipd_put(env, bag, ipd);
1913 return(rc > 0 ? 0 : rc);
1916 inode = obj->oo_inode;
1918 rc = osd_quota_transfer(inode, attr);
1922 spin_lock(&obj->oo_guard);
1923 rc = osd_inode_setattr(env, inode, attr);
1924 spin_unlock(&obj->oo_guard);
1927 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
1931 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
1932 struct osd_object *obj,
1933 const char *name, const int namelen)
1935 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1938 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1939 umode_t mode, struct dt_allocation_hint *hint,
1943 struct osd_device *osd = osd_obj2dev(obj);
1944 struct osd_thandle *oth;
1945 struct dt_object *parent = NULL;
1946 struct inode *inode;
1948 LINVRNT(osd_invariant(obj));
1949 LASSERT(obj->oo_inode == NULL);
1950 LASSERT(obj->oo_hl_head == NULL);
1952 if (S_ISDIR(mode) && ldiskfs_pdo) {
1953 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1954 if (obj->oo_hl_head == NULL)
1958 oth = container_of(th, struct osd_thandle, ot_super);
1959 LASSERT(oth->ot_handle->h_transaction != NULL);
1961 if (hint && hint->dah_parent)
1962 parent = hint->dah_parent;
1964 inode = ldiskfs_create_inode(oth->ot_handle,
1965 parent ? osd_dt_obj(parent)->oo_inode :
1966 osd_sb(osd)->s_root->d_inode,
1968 if (!IS_ERR(inode)) {
1969 /* Do not update file c/mtime in ldiskfs. */
1970 inode->i_flags |= S_NOCMTIME;
1972 /* For new created object, it must be consistent,
1973 * and it is unnecessary to scrub against it. */
1974 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
1976 obj->oo_inode = inode;
1979 if (obj->oo_hl_head != NULL) {
1980 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1981 obj->oo_hl_head = NULL;
1983 result = PTR_ERR(inode);
1985 LINVRNT(osd_invariant(obj));
1993 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1994 struct lu_attr *attr,
1995 struct dt_allocation_hint *hint,
1996 struct dt_object_format *dof,
2000 struct osd_thandle *oth;
2001 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
2003 LASSERT(S_ISDIR(attr->la_mode));
2005 oth = container_of(th, struct osd_thandle, ot_super);
2006 LASSERT(oth->ot_handle->h_transaction != NULL);
2007 result = osd_mkfile(info, obj, mode, hint, th);
2012 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
2013 struct lu_attr *attr,
2014 struct dt_allocation_hint *hint,
2015 struct dt_object_format *dof,
2019 struct osd_thandle *oth;
2020 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
2022 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
2024 LASSERT(S_ISREG(attr->la_mode));
2026 oth = container_of(th, struct osd_thandle, ot_super);
2027 LASSERT(oth->ot_handle->h_transaction != NULL);
2029 result = osd_mkfile(info, obj, mode, hint, th);
2031 LASSERT(obj->oo_inode != NULL);
2032 if (feat->dif_flags & DT_IND_VARKEY)
2033 result = iam_lvar_create(obj->oo_inode,
2034 feat->dif_keysize_max,
2036 feat->dif_recsize_max,
2039 result = iam_lfix_create(obj->oo_inode,
2040 feat->dif_keysize_max,
2042 feat->dif_recsize_max,
2049 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
2050 struct lu_attr *attr,
2051 struct dt_allocation_hint *hint,
2052 struct dt_object_format *dof,
2055 LASSERT(S_ISREG(attr->la_mode));
2056 return osd_mkfile(info, obj, (attr->la_mode &
2057 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2060 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
2061 struct lu_attr *attr,
2062 struct dt_allocation_hint *hint,
2063 struct dt_object_format *dof,
2066 LASSERT(S_ISLNK(attr->la_mode));
2067 return osd_mkfile(info, obj, (attr->la_mode &
2068 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2071 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
2072 struct lu_attr *attr,
2073 struct dt_allocation_hint *hint,
2074 struct dt_object_format *dof,
2077 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
2080 LINVRNT(osd_invariant(obj));
2081 LASSERT(obj->oo_inode == NULL);
2082 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
2083 S_ISFIFO(mode) || S_ISSOCK(mode));
2085 result = osd_mkfile(info, obj, mode, hint, th);
2087 LASSERT(obj->oo_inode != NULL);
2089 * This inode should be marked dirty for i_rdev. Currently
2090 * that is done in the osd_attr_init().
2092 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
2095 LINVRNT(osd_invariant(obj));
2099 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
2101 struct dt_allocation_hint *hint,
2102 struct dt_object_format *dof,
2105 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
2107 osd_obj_type_f result;
2123 result = osd_mk_index;
2134 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2135 struct dt_object *parent, struct dt_object *child,
2140 ah->dah_parent = parent;
2141 ah->dah_mode = child_mode;
2144 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
2145 struct lu_attr *attr, struct dt_object_format *dof)
2147 struct inode *inode = obj->oo_inode;
2148 __u64 valid = attr->la_valid;
2151 attr->la_valid &= ~(LA_TYPE | LA_MODE);
2153 if (dof->dof_type != DFT_NODE)
2154 attr->la_valid &= ~LA_RDEV;
2155 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
2156 attr->la_valid &= ~LA_ATIME;
2157 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
2158 attr->la_valid &= ~LA_CTIME;
2159 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
2160 attr->la_valid &= ~LA_MTIME;
2162 result = osd_quota_transfer(inode, attr);
2166 if (attr->la_valid != 0) {
2167 result = osd_inode_setattr(info->oti_env, inode, attr);
2169 * The osd_inode_setattr() should always succeed here. The
2170 * only error that could be returned is EDQUOT when we are
2171 * trying to change the UID or GID of the inode. However, this
2172 * should not happen since quota enforcement is no longer
2173 * enabled on ldiskfs (lquota takes care of it).
2175 LASSERTF(result == 0, "%d\n", result);
2176 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2179 attr->la_valid = valid;
2183 * Helper function for osd_object_create()
2185 * \retval 0, on success
2187 static int __osd_object_create(struct osd_thread_info *info,
2188 struct osd_object *obj, struct lu_attr *attr,
2189 struct dt_allocation_hint *hint,
2190 struct dt_object_format *dof,
2196 /* we drop umask so that permissions we pass are not affected */
2197 umask = current->fs->umask;
2198 current->fs->umask = 0;
2200 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
2203 osd_attr_init(info, obj, attr, dof);
2204 osd_object_init0(obj);
2207 if (obj->oo_inode != NULL) {
2208 LASSERT(obj->oo_inode->i_state & I_NEW);
2210 unlock_new_inode(obj->oo_inode);
2213 /* restore previous umask value */
2214 current->fs->umask = umask;
2220 * Helper function for osd_object_create()
2222 * \retval 0, on success
2224 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
2225 const struct lu_fid *fid, struct thandle *th)
2227 struct osd_thread_info *info = osd_oti_get(env);
2228 struct osd_inode_id *id = &info->oti_id;
2229 struct osd_device *osd = osd_obj2dev(obj);
2230 struct osd_thandle *oh;
2232 LASSERT(obj->oo_inode != NULL);
2234 oh = container_of0(th, struct osd_thandle, ot_super);
2235 LASSERT(oh->ot_handle);
2237 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2238 return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
2241 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
2242 u64 seq, struct lu_seq_range *range)
2244 struct seq_server_site *ss = osd_seq_site(osd);
2246 if (fid_seq_is_idif(seq)) {
2247 fld_range_set_ost(range);
2248 range->lsr_index = idif_ost_idx(seq);
2252 if (!fid_seq_in_fldb(seq)) {
2253 fld_range_set_mdt(range);
2255 /* FIXME: If ss is NULL, it suppose not get lsr_index
2257 range->lsr_index = ss->ss_node_id;
2261 LASSERT(ss != NULL);
2262 fld_range_set_any(range);
2263 /* OSD will only do local fld lookup */
2264 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
2268 * Concurrency: no external locking is necessary.
2270 static int osd_declare_object_create(const struct lu_env *env,
2271 struct dt_object *dt,
2272 struct lu_attr *attr,
2273 struct dt_allocation_hint *hint,
2274 struct dt_object_format *dof,
2275 struct thandle *handle)
2277 struct osd_thandle *oh;
2281 LASSERT(handle != NULL);
2283 oh = container_of0(handle, struct osd_thandle, ot_super);
2284 LASSERT(oh->ot_handle == NULL);
2286 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
2287 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
2288 /* Reuse idle OI block may cause additional one OI block
2290 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2291 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
2293 /* If this is directory, then we expect . and .. to be inserted as
2294 * well. The one directory block always needs to be created for the
2295 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2296 * block), there is no danger of needing a tree for the first block.
2298 if (attr && S_ISDIR(attr->la_mode)) {
2299 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2300 osd_dto_credits_noquota[DTO_WRITE_BASE]);
2301 osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0);
2307 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2308 osd_dt_obj(dt), false, NULL, false);
2315 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2316 struct lu_attr *attr,
2317 struct dt_allocation_hint *hint,
2318 struct dt_object_format *dof, struct thandle *th)
2320 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2321 struct osd_object *obj = osd_dt_obj(dt);
2322 struct osd_thread_info *info = osd_oti_get(env);
2326 if (dt_object_exists(dt))
2329 LINVRNT(osd_invariant(obj));
2330 LASSERT(!dt_object_remote(dt));
2331 LASSERT(osd_write_locked(env, obj));
2332 LASSERT(th != NULL);
2334 if (unlikely(fid_is_acct(fid)))
2335 /* Quota files can't be created from the kernel any more,
2336 * 'tune2fs -O quota' will take care of creating them */
2339 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2340 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2342 result = __osd_object_create(info, obj, attr, hint, dof, th);
2344 result = __osd_oi_insert(env, obj, fid, th);
2346 LASSERT(ergo(result == 0,
2347 dt_object_exists(dt) && !dt_object_remote(dt)));
2349 LASSERT(osd_invariant(obj));
2354 * Called to destroy on-disk representation of the object
2356 * Concurrency: must be locked
2358 static int osd_declare_object_destroy(const struct lu_env *env,
2359 struct dt_object *dt,
2362 struct osd_object *obj = osd_dt_obj(dt);
2363 struct inode *inode = obj->oo_inode;
2364 struct osd_thandle *oh;
2368 oh = container_of0(th, struct osd_thandle, ot_super);
2369 LASSERT(oh->ot_handle == NULL);
2372 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
2373 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2374 /* Recycle idle OI leaf may cause additional three OI blocks
2376 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
2377 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
2378 /* one less inode */
2379 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2380 -1, oh, obj, false, NULL, false);
2383 /* data to be truncated */
2384 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2385 0, oh, obj, true, NULL, false);
2389 static int osd_object_destroy(const struct lu_env *env,
2390 struct dt_object *dt,
2393 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2394 struct osd_object *obj = osd_dt_obj(dt);
2395 struct inode *inode = obj->oo_inode;
2396 struct osd_device *osd = osd_obj2dev(obj);
2397 struct osd_thandle *oh;
2401 oh = container_of0(th, struct osd_thandle, ot_super);
2402 LASSERT(oh->ot_handle);
2404 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2406 if (unlikely(fid_is_acct(fid)))
2409 if (S_ISDIR(inode->i_mode)) {
2410 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
2411 inode->i_nlink == 2);
2412 /* it will check/delete the inode from remote parent,
2413 * how to optimize it? unlink performance impaction XXX */
2414 result = osd_delete_from_remote_parent(env, osd, obj, oh);
2415 if (result != 0 && result != -ENOENT) {
2416 CERROR("%s: delete inode "DFID": rc = %d\n",
2417 osd_name(osd), PFID(fid), result);
2419 spin_lock(&obj->oo_guard);
2421 spin_unlock(&obj->oo_guard);
2422 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2425 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
2427 result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
2430 /* XXX: add to ext3 orphan list */
2431 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2433 /* not needed in the cache anymore */
2434 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2440 * Put the fid into lustre_mdt_attrs, and then place the structure
2441 * inode's ea. This fid should not be altered during the life time
2444 * \retval +ve, on success
2445 * \retval -ve, on error
2447 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2449 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
2450 const struct lu_fid *fid, __u32 compat, __u32 incompat)
2452 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2456 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
2459 lustre_lma_init(lma, fid, compat, incompat);
2460 lustre_lma_swab(lma);
2462 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma, sizeof(*lma),
2464 /* LMA may already exist, but we need to check that all the
2465 * desired compat/incompat flags have been added. */
2466 if (unlikely(rc == -EEXIST)) {
2467 if (compat == 0 && incompat == 0)
2470 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
2471 XATTR_NAME_LMA, info->oti_mdt_attrs_old,
2476 lustre_lma_swab(lma);
2477 if (!(~lma->lma_compat & compat) &&
2478 !(~lma->lma_incompat & incompat))
2481 lma->lma_compat |= compat;
2482 lma->lma_incompat |= incompat;
2483 lustre_lma_swab(lma);
2484 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2485 sizeof(*lma), XATTR_REPLACE);
2492 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2493 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2494 * To have compatilibility with 1.8 ldiskfs driver we need to have
2495 * magic number at start of fid data.
2496 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2499 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2500 const struct lu_fid *fid)
2502 if (!fid_is_namespace_visible(fid) ||
2503 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
2504 param->edp_magic = 0;
2508 param->edp_magic = LDISKFS_LUFID_MAGIC;
2509 param->edp_len = sizeof(struct lu_fid) + 1;
2510 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
2514 * Try to read the fid from inode ea into dt_rec.
2516 * \param fid object fid.
2518 * \retval 0 on success
2520 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2521 __u32 ino, struct lu_fid *fid,
2522 struct osd_inode_id *id)
2524 struct osd_thread_info *info = osd_oti_get(env);
2525 struct inode *inode;
2528 osd_id_gen(id, ino, OSD_OII_NOGEN);
2529 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2531 RETURN(PTR_ERR(inode));
2537 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
2539 struct inode *parent_dir,
2540 const struct lu_fid *dot_fid,
2541 const struct lu_fid *dot_dot_fid,
2542 struct osd_thandle *oth)
2544 struct ldiskfs_dentry_param *dot_ldp;
2545 struct ldiskfs_dentry_param *dot_dot_ldp;
2547 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
2548 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
2550 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
2551 dot_ldp->edp_magic = 0;
2552 return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
2553 dir, dot_ldp, dot_dot_ldp);
2557 * Create an local agent inode for remote entry
2559 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
2560 struct osd_device *osd,
2561 struct osd_object *pobj,
2562 const struct lu_fid *fid,
2566 struct osd_thread_info *info = osd_oti_get(env);
2567 struct inode *local;
2568 struct osd_thandle *oh;
2573 oh = container_of(th, struct osd_thandle, ot_super);
2574 LASSERT(oh->ot_handle->h_transaction != NULL);
2576 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
2577 if (IS_ERR(local)) {
2578 CERROR("%s: create local error %d\n", osd_name(osd),
2579 (int)PTR_ERR(local));
2583 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
2584 unlock_new_inode(local);
2586 /* Set special LMA flag for local agent inode */
2587 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
2589 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
2590 osd_name(osd), PFID(fid), rc);
2591 RETURN(ERR_PTR(rc));
2597 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
2598 lu_object_fid(&pobj->oo_dt.do_lu),
2601 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
2602 osd_name(osd), PFID(fid), rc);
2603 RETURN(ERR_PTR(rc));
2610 * Delete local agent inode for remote entry
2612 static int osd_delete_local_agent_inode(const struct lu_env *env,
2613 struct osd_device *osd,
2614 const struct lu_fid *fid,
2615 __u32 ino, struct osd_thandle *oh)
2617 struct osd_thread_info *oti = osd_oti_get(env);
2618 struct osd_inode_id *id = &oti->oti_id;
2619 struct inode *inode;
2622 id->oii_ino = le32_to_cpu(ino);
2623 id->oii_gen = OSD_OII_NOGEN;
2624 inode = osd_iget(oti, osd, id);
2625 if (IS_ERR(inode)) {
2626 CERROR("%s: iget error "DFID" id %u:%u\n", osd_name(osd),
2627 PFID(fid), id->oii_ino, id->oii_gen);
2628 RETURN(PTR_ERR(inode));
2632 mark_inode_dirty(inode);
2633 CDEBUG(D_INODE, "%s: delete remote inode "DFID" %lu\n",
2634 osd_name(osd), PFID(fid), inode->i_ino);
2640 * OSD layer object create function for interoperability mode (b11826).
2641 * This is mostly similar to osd_object_create(). Only difference being, fid is
2642 * inserted into inode ea here.
2644 * \retval 0, on success
2645 * \retval -ve, on error
2647 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2648 struct lu_attr *attr,
2649 struct dt_allocation_hint *hint,
2650 struct dt_object_format *dof,
2653 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2654 struct osd_object *obj = osd_dt_obj(dt);
2655 struct osd_thread_info *info = osd_oti_get(env);
2660 if (dt_object_exists(dt))
2663 LASSERT(osd_invariant(obj));
2664 LASSERT(!dt_object_remote(dt));
2665 LASSERT(osd_write_locked(env, obj));
2666 LASSERT(th != NULL);
2668 if (unlikely(fid_is_acct(fid)))
2669 /* Quota files can't be created from the kernel any more,
2670 * 'tune2fs -O quota' will take care of creating them */
2673 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2674 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2676 result = __osd_object_create(info, obj, attr, hint, dof, th);
2678 if (fid_is_idif(fid) &&
2679 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
2680 struct lu_fid *tfid = &info->oti_fid;
2681 struct ost_id *oi = &info->oti_ostid;
2683 fid_to_ostid(fid, oi);
2684 ostid_to_fid(tfid, oi, 0);
2685 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
2686 LMAC_FID_ON_OST, 0);
2688 result = osd_ea_fid_set(info, obj->oo_inode, fid,
2689 fid_is_on_ost(info, osd_obj2dev(obj),
2690 fid, OI_CHECK_FLD) ?
2691 LMAC_FID_ON_OST : 0, 0);
2696 result = __osd_oi_insert(env, obj, fid, th);
2698 LASSERT(ergo(result == 0,
2699 dt_object_exists(dt) && !dt_object_remote(dt)));
2700 LINVRNT(osd_invariant(obj));
2704 static int osd_declare_object_ref_add(const struct lu_env *env,
2705 struct dt_object *dt,
2706 struct thandle *handle)
2708 struct osd_thandle *oh;
2710 /* it's possible that object doesn't exist yet */
2711 LASSERT(handle != NULL);
2713 oh = container_of0(handle, struct osd_thandle, ot_super);
2714 LASSERT(oh->ot_handle == NULL);
2716 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
2717 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2723 * Concurrency: @dt is write locked.
2725 static int osd_object_ref_add(const struct lu_env *env,
2726 struct dt_object *dt, struct thandle *th)
2728 struct osd_object *obj = osd_dt_obj(dt);
2729 struct inode *inode = obj->oo_inode;
2730 struct osd_thandle *oh;
2733 if (!dt_object_exists(dt))
2736 LINVRNT(osd_invariant(obj));
2737 LASSERT(!dt_object_remote(dt));
2738 LASSERT(osd_write_locked(env, obj));
2739 LASSERT(th != NULL);
2741 oh = container_of0(th, struct osd_thandle, ot_super);
2742 LASSERT(oh->ot_handle != NULL);
2744 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
2746 CDEBUG(D_INODE, DFID" increase nlink %d\n",
2747 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2749 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
2750 * (65000) subdirectories by storing "1" in i_nlink if the link count
2751 * would otherwise overflow. Directory tranversal tools understand
2752 * that (st_nlink == 1) indicates that the filesystem dose not track
2753 * hard links count on the directory, and will not abort subdirectory
2754 * scanning early once (st_nlink - 2) subdirs have been found.
2756 * This also has to properly handle the case of inodes with nlink == 0
2757 * in case they are being linked into the PENDING directory
2759 spin_lock(&obj->oo_guard);
2760 if (unlikely(inode->i_nlink == 0))
2761 /* inc_nlink from 0 may cause WARN_ON */
2762 set_nlink(inode, 1);
2764 ldiskfs_inc_count(oh->ot_handle, inode);
2765 if (!S_ISDIR(inode->i_mode))
2766 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2768 spin_unlock(&obj->oo_guard);
2770 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2771 LINVRNT(osd_invariant(obj));
2776 static int osd_declare_object_ref_del(const struct lu_env *env,
2777 struct dt_object *dt,
2778 struct thandle *handle)
2780 struct osd_thandle *oh;
2782 LASSERT(!dt_object_remote(dt));
2783 LASSERT(handle != NULL);
2785 oh = container_of0(handle, struct osd_thandle, ot_super);
2786 LASSERT(oh->ot_handle == NULL);
2788 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
2789 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2795 * Concurrency: @dt is write locked.
2797 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2800 struct osd_object *obj = osd_dt_obj(dt);
2801 struct inode *inode = obj->oo_inode;
2802 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
2803 struct osd_thandle *oh;
2805 if (!dt_object_exists(dt))
2808 LINVRNT(osd_invariant(obj));
2809 LASSERT(!dt_object_remote(dt));
2810 LASSERT(osd_write_locked(env, obj));
2811 LASSERT(th != NULL);
2813 oh = container_of0(th, struct osd_thandle, ot_super);
2814 LASSERT(oh->ot_handle != NULL);
2816 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
2818 spin_lock(&obj->oo_guard);
2819 /* That can be result of upgrade from old Lustre version and
2820 * applied only to local files. Just skip this ref_del call.
2821 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
2822 if (inode->i_nlink == 0) {
2823 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2824 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
2825 ", maybe an upgraded file? (LU-3915)\n",
2826 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
2827 spin_unlock(&obj->oo_guard);
2831 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
2832 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2834 ldiskfs_dec_count(oh->ot_handle, inode);
2835 spin_unlock(&obj->oo_guard);
2837 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2838 LINVRNT(osd_invariant(obj));
2844 * Get the 64-bit version for an inode.
2846 static int osd_object_version_get(const struct lu_env *env,
2847 struct dt_object *dt, dt_obj_version_t *ver)
2849 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2851 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2852 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2853 *ver = LDISKFS_I(inode)->i_fs_version;
2858 * Concurrency: @dt is read locked.
2860 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2861 struct lu_buf *buf, const char *name)
2863 struct osd_object *obj = osd_dt_obj(dt);
2864 struct inode *inode = obj->oo_inode;
2865 struct osd_thread_info *info = osd_oti_get(env);
2866 struct dentry *dentry = &info->oti_obj_dentry;
2868 /* version get is not real XATTR but uses xattr API */
2869 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2870 /* for version we are just using xattr API but change inode
2872 if (buf->lb_len == 0)
2873 return sizeof(dt_obj_version_t);
2875 if (buf->lb_len < sizeof(dt_obj_version_t))
2878 osd_object_version_get(env, dt, buf->lb_buf);
2880 return sizeof(dt_obj_version_t);
2883 if (!dt_object_exists(dt))
2886 LASSERT(!dt_object_remote(dt));
2887 LASSERT(inode->i_op != NULL);
2888 LASSERT(inode->i_op->getxattr != NULL);
2890 return __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len);
2894 static int osd_declare_xattr_set(const struct lu_env *env,
2895 struct dt_object *dt,
2896 const struct lu_buf *buf, const char *name,
2897 int fl, struct thandle *handle)
2899 struct osd_thandle *oh;
2901 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2903 LASSERT(handle != NULL);
2905 oh = container_of0(handle, struct osd_thandle, ot_super);
2906 LASSERT(oh->ot_handle == NULL);
2908 /* optimistic optimization: LMA is set first and usually fit inode */
2909 if (strcmp(name, XATTR_NAME_LMA) == 0) {
2910 if (dt_object_exists(dt))
2914 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2917 credits = osd_dto_credits_noquota[DTO_XATTR_SET];
2918 if (buf && buf->lb_len > sb->s_blocksize) {
2919 credits *= (buf->lb_len + sb->s_blocksize - 1) >>
2920 sb->s_blocksize_bits;
2923 * xattr set may involve inode quota change, reserve credits for
2924 * dquot_initialize()
2926 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2929 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
2935 * Set the 64-bit version for object
2937 static void osd_object_version_set(const struct lu_env *env,
2938 struct dt_object *dt,
2939 dt_obj_version_t *new_version)
2941 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2943 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2944 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2946 LDISKFS_I(inode)->i_fs_version = *new_version;
2947 /** Version is set after all inode operations are finished,
2948 * so we should mark it dirty here */
2949 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2953 * Concurrency: @dt is write locked.
2955 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2956 const struct lu_buf *buf, const char *name, int fl,
2957 struct thandle *handle)
2959 struct osd_object *obj = osd_dt_obj(dt);
2960 struct inode *inode = obj->oo_inode;
2961 struct osd_thread_info *info = osd_oti_get(env);
2965 LASSERT(handle != NULL);
2967 /* version set is not real XATTR */
2968 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2969 /* for version we are just using xattr API but change inode
2971 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2972 osd_object_version_set(env, dt, buf->lb_buf);
2973 return sizeof(dt_obj_version_t);
2976 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
2977 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
2979 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2980 if (fl & LU_XATTR_REPLACE)
2981 fs_flags |= XATTR_REPLACE;
2983 if (fl & LU_XATTR_CREATE)
2984 fs_flags |= XATTR_CREATE;
2986 if (strcmp(name, XATTR_NAME_LMV) == 0) {
2987 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2990 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
2994 lma->lma_incompat |= LMAI_STRIPED;
2995 lustre_lma_swab(lma);
2996 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2997 sizeof(*lma), XATTR_REPLACE);
3002 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
3003 strcmp(name, XATTR_NAME_LINK) == 0)
3006 return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
3011 * Concurrency: @dt is read locked.
3013 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
3014 const struct lu_buf *buf)
3016 struct osd_object *obj = osd_dt_obj(dt);
3017 struct inode *inode = obj->oo_inode;
3018 struct osd_thread_info *info = osd_oti_get(env);
3019 struct dentry *dentry = &info->oti_obj_dentry;
3021 if (!dt_object_exists(dt))
3024 LASSERT(!dt_object_remote(dt));
3025 LASSERT(inode->i_op != NULL);
3026 LASSERT(inode->i_op->listxattr != NULL);
3028 dentry->d_inode = inode;
3029 dentry->d_sb = inode->i_sb;
3030 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
3033 static int osd_declare_xattr_del(const struct lu_env *env,
3034 struct dt_object *dt, const char *name,
3035 struct thandle *handle)
3037 struct osd_thandle *oh;
3038 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3040 LASSERT(!dt_object_remote(dt));
3041 LASSERT(handle != NULL);
3043 oh = container_of0(handle, struct osd_thandle, ot_super);
3044 LASSERT(oh->ot_handle == NULL);
3046 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
3047 osd_dto_credits_noquota[DTO_XATTR_SET]);
3049 * xattr del may involve inode quota change, reserve credits for
3050 * dquot_initialize()
3052 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
3058 * Concurrency: @dt is write locked.
3060 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
3061 const char *name, struct thandle *handle)
3063 struct osd_object *obj = osd_dt_obj(dt);
3064 struct inode *inode = obj->oo_inode;
3065 struct osd_thread_info *info = osd_oti_get(env);
3066 struct dentry *dentry = &info->oti_obj_dentry;
3069 if (!dt_object_exists(dt))
3072 LASSERT(!dt_object_remote(dt));
3073 LASSERT(inode->i_op != NULL);
3074 LASSERT(inode->i_op->removexattr != NULL);
3075 LASSERT(handle != NULL);
3077 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3079 ll_vfs_dq_init(inode);
3080 dentry->d_inode = inode;
3081 dentry->d_sb = inode->i_sb;
3082 rc = inode->i_op->removexattr(dentry, name);
3086 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
3087 __u64 start, __u64 end)
3089 struct osd_object *obj = osd_dt_obj(dt);
3090 struct inode *inode = obj->oo_inode;
3091 struct osd_thread_info *info = osd_oti_get(env);
3092 struct dentry *dentry = &info->oti_obj_dentry;
3093 struct file *file = &info->oti_file;
3098 dentry->d_inode = inode;
3099 dentry->d_sb = inode->i_sb;
3100 file->f_dentry = dentry;
3101 file->f_mapping = inode->i_mapping;
3102 file->f_op = inode->i_fop;
3103 set_file_inode(file, inode);
3105 rc = ll_vfs_fsync_range(file, start, end, 0);
3114 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
3115 const struct dt_index_features *feat)
3117 struct iam_descr *descr;
3119 if (osd_object_is_root(o))
3120 return feat == &dt_directory_features;
3122 LASSERT(o->oo_dir != NULL);
3124 descr = o->oo_dir->od_container.ic_descr;
3125 if (feat == &dt_directory_features) {
3126 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
3132 feat->dif_keysize_min <= descr->id_key_size &&
3133 descr->id_key_size <= feat->dif_keysize_max &&
3134 feat->dif_recsize_min <= descr->id_rec_size &&
3135 descr->id_rec_size <= feat->dif_recsize_max &&
3136 !(feat->dif_flags & (DT_IND_VARKEY |
3137 DT_IND_VARREC | DT_IND_NONUNQ)) &&
3138 ergo(feat->dif_flags & DT_IND_UPDATE,
3139 1 /* XXX check that object (and file system) is
3144 static int osd_iam_container_init(const struct lu_env *env,
3145 struct osd_object *obj,
3146 struct osd_directory *dir)
3148 struct iam_container *bag = &dir->od_container;
3151 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
3155 result = iam_container_setup(bag);
3157 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
3159 iam_container_fini(bag);
3166 * Concurrency: no external locking is necessary.
3168 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
3169 const struct dt_index_features *feat)
3173 struct osd_object *obj = osd_dt_obj(dt);
3175 LINVRNT(osd_invariant(obj));
3177 if (osd_object_is_root(obj)) {
3178 dt->do_index_ops = &osd_index_ea_ops;
3180 } else if (feat == &dt_directory_features) {
3181 dt->do_index_ops = &osd_index_ea_ops;
3182 if (obj->oo_inode != NULL && S_ISDIR(obj->oo_inode->i_mode))
3187 } else if (unlikely(feat == &dt_otable_features)) {
3188 dt->do_index_ops = &osd_otable_ops;
3190 } else if (unlikely(feat == &dt_acct_features)) {
3191 dt->do_index_ops = &osd_acct_index_ops;
3194 } else if (!osd_has_index(obj)) {
3195 struct osd_directory *dir;
3200 spin_lock(&obj->oo_guard);
3201 if (obj->oo_dir == NULL)
3205 * Concurrent thread allocated container data.
3208 spin_unlock(&obj->oo_guard);
3210 * Now, that we have container data, serialize its
3213 down_write(&obj->oo_ext_idx_sem);
3215 * recheck under lock.
3217 if (!osd_has_index(obj))
3218 result = osd_iam_container_init(env, obj,
3222 up_write(&obj->oo_ext_idx_sem);
3230 if (result == 0 && skip_iam == 0) {
3231 if (!osd_iam_index_probe(env, obj, feat))
3234 LINVRNT(osd_invariant(obj));
3236 if (result == 0 && is_quota_glb_feat(feat) &&
3237 fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
3238 result = osd_quota_migration(env, dt, feat);
3243 static int osd_otable_it_attr_get(const struct lu_env *env,
3244 struct dt_object *dt,
3245 struct lu_attr *attr)
3251 static const struct dt_object_operations osd_obj_ops = {
3252 .do_read_lock = osd_object_read_lock,
3253 .do_write_lock = osd_object_write_lock,
3254 .do_read_unlock = osd_object_read_unlock,
3255 .do_write_unlock = osd_object_write_unlock,
3256 .do_write_locked = osd_object_write_locked,
3257 .do_attr_get = osd_attr_get,
3258 .do_declare_attr_set = osd_declare_attr_set,
3259 .do_attr_set = osd_attr_set,
3260 .do_ah_init = osd_ah_init,
3261 .do_declare_create = osd_declare_object_create,
3262 .do_create = osd_object_create,
3263 .do_declare_destroy = osd_declare_object_destroy,
3264 .do_destroy = osd_object_destroy,
3265 .do_index_try = osd_index_try,
3266 .do_declare_ref_add = osd_declare_object_ref_add,
3267 .do_ref_add = osd_object_ref_add,
3268 .do_declare_ref_del = osd_declare_object_ref_del,
3269 .do_ref_del = osd_object_ref_del,
3270 .do_xattr_get = osd_xattr_get,
3271 .do_declare_xattr_set = osd_declare_xattr_set,
3272 .do_xattr_set = osd_xattr_set,
3273 .do_declare_xattr_del = osd_declare_xattr_del,
3274 .do_xattr_del = osd_xattr_del,
3275 .do_xattr_list = osd_xattr_list,
3276 .do_object_sync = osd_object_sync,
3280 * dt_object_operations for interoperability mode
3281 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
3283 static const struct dt_object_operations osd_obj_ea_ops = {
3284 .do_read_lock = osd_object_read_lock,
3285 .do_write_lock = osd_object_write_lock,
3286 .do_read_unlock = osd_object_read_unlock,
3287 .do_write_unlock = osd_object_write_unlock,
3288 .do_write_locked = osd_object_write_locked,
3289 .do_attr_get = osd_attr_get,
3290 .do_declare_attr_set = osd_declare_attr_set,
3291 .do_attr_set = osd_attr_set,
3292 .do_ah_init = osd_ah_init,
3293 .do_declare_create = osd_declare_object_create,
3294 .do_create = osd_object_ea_create,
3295 .do_declare_destroy = osd_declare_object_destroy,
3296 .do_destroy = osd_object_destroy,
3297 .do_index_try = osd_index_try,
3298 .do_declare_ref_add = osd_declare_object_ref_add,
3299 .do_ref_add = osd_object_ref_add,
3300 .do_declare_ref_del = osd_declare_object_ref_del,
3301 .do_ref_del = osd_object_ref_del,
3302 .do_xattr_get = osd_xattr_get,
3303 .do_declare_xattr_set = osd_declare_xattr_set,
3304 .do_xattr_set = osd_xattr_set,
3305 .do_declare_xattr_del = osd_declare_xattr_del,
3306 .do_xattr_del = osd_xattr_del,
3307 .do_xattr_list = osd_xattr_list,
3308 .do_object_sync = osd_object_sync,
3311 static const struct dt_object_operations osd_obj_otable_it_ops = {
3312 .do_attr_get = osd_otable_it_attr_get,
3313 .do_index_try = osd_index_try,
3316 static int osd_index_declare_iam_delete(const struct lu_env *env,
3317 struct dt_object *dt,
3318 const struct dt_key *key,
3319 struct thandle *handle)
3321 struct osd_thandle *oh;
3323 oh = container_of0(handle, struct osd_thandle, ot_super);
3324 LASSERT(oh->ot_handle == NULL);
3326 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3327 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3333 * delete a (key, value) pair from index \a dt specified by \a key
3335 * \param dt osd index object
3336 * \param key key for index
3337 * \param rec record reference
3338 * \param handle transaction handler
3341 * \retval -ve failure
3343 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
3344 const struct dt_key *key,
3345 struct thandle *handle)
3347 struct osd_thread_info *oti = osd_oti_get(env);
3348 struct osd_object *obj = osd_dt_obj(dt);
3349 struct osd_thandle *oh;
3350 struct iam_path_descr *ipd;
3351 struct iam_container *bag = &obj->oo_dir->od_container;
3355 if (!dt_object_exists(dt))
3358 LINVRNT(osd_invariant(obj));
3359 LASSERT(!dt_object_remote(dt));
3360 LASSERT(bag->ic_object == obj->oo_inode);
3361 LASSERT(handle != NULL);
3363 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3365 ipd = osd_idx_ipd_get(env, bag);
3366 if (unlikely(ipd == NULL))
3369 oh = container_of0(handle, struct osd_thandle, ot_super);
3370 LASSERT(oh->ot_handle != NULL);
3371 LASSERT(oh->ot_handle->h_transaction != NULL);
3373 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3374 /* swab quota uid/gid provided by caller */
3375 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3376 key = (const struct dt_key *)&oti->oti_quota_id;
3379 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
3380 osd_ipd_put(env, bag, ipd);
3381 LINVRNT(osd_invariant(obj));
3385 static int osd_index_declare_ea_delete(const struct lu_env *env,
3386 struct dt_object *dt,
3387 const struct dt_key *key,
3388 struct thandle *handle)
3390 struct osd_thandle *oh;
3391 struct inode *inode;
3395 LASSERT(!dt_object_remote(dt));
3396 LASSERT(handle != NULL);
3398 oh = container_of0(handle, struct osd_thandle, ot_super);
3399 LASSERT(oh->ot_handle == NULL);
3401 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3402 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3404 inode = osd_dt_obj(dt)->oo_inode;
3407 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3408 0, oh, osd_dt_obj(dt), true, NULL, false);
3412 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3415 struct osd_fid_pack *rec;
3418 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3419 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3420 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3425 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
3426 const struct lu_fid *fid)
3428 struct seq_server_site *ss = osd_seq_site(osd);
3431 /* FID seqs not in FLDB, must be local seq */
3432 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
3435 /* If FLD is not being initialized yet, it only happens during the
3436 * initialization, likely during mgs initialization, and we assume
3437 * this is local FID. */
3438 if (ss == NULL || ss->ss_server_fld == NULL)
3441 /* Only check the local FLDB here */
3442 if (osd_seq_exists(env, osd, fid_seq(fid)))
3449 * Index delete function for interoperability mode (b11826).
3450 * It will remove the directory entry added by osd_index_ea_insert().
3451 * This entry is needed to maintain name->fid mapping.
3453 * \param key, key i.e. file entry to be deleted
3455 * \retval 0, on success
3456 * \retval -ve, on error
3458 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3459 const struct dt_key *key, struct thandle *handle)
3461 struct osd_object *obj = osd_dt_obj(dt);
3462 struct inode *dir = obj->oo_inode;
3463 struct dentry *dentry;
3464 struct osd_thandle *oh;
3465 struct ldiskfs_dir_entry_2 *de = NULL;
3466 struct buffer_head *bh;
3467 struct htree_lock *hlock = NULL;
3468 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
3469 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3473 if (!dt_object_exists(dt))
3476 LINVRNT(osd_invariant(obj));
3477 LASSERT(!dt_object_remote(dt));
3478 LASSERT(handle != NULL);
3480 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3482 oh = container_of(handle, struct osd_thandle, ot_super);
3483 LASSERT(oh->ot_handle != NULL);
3484 LASSERT(oh->ot_handle->h_transaction != NULL);
3486 ll_vfs_dq_init(dir);
3487 dentry = osd_child_dentry_get(env, obj,
3488 (char *)key, strlen((char *)key));
3490 if (obj->oo_hl_head != NULL) {
3491 hlock = osd_oti_get(env)->oti_hlock;
3492 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3493 dir, LDISKFS_HLOCK_DEL);
3495 down_write(&obj->oo_ext_idx_sem);
3498 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
3502 /* If this is not the ".." entry, it might be a remote DNE
3503 * entry and we need to check if the FID is for a remote
3504 * MDT. If the FID is not in the directory entry (e.g.
3505 * upgraded 1.8 filesystem without dirdata enabled) then
3506 * we need to get the FID from the LMA. For a remote directory
3507 * there HAS to be an LMA, it cannot be an IGIF inode in this
3510 * Delete the entry before the agent inode in order to
3511 * simplify error handling. At worst an error after deleting
3512 * the entry first might leak the agent inode afterward. The
3513 * reverse would need filesystem abort in case of error deleting
3514 * the entry after the agent had been removed, or leave a
3515 * dangling entry pointing at a random inode. */
3516 if (strcmp((char *)key, dotdot) != 0) {
3517 LASSERT(de != NULL);
3518 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
3519 /* If Fid is not in dentry, try to get it from LMA */
3520 if (rc == -ENODATA) {
3521 struct osd_inode_id *id;
3522 struct inode *inode;
3524 /* Before trying to get fid from the inode,
3525 * check whether the inode is valid.
3527 * If the inode has been deleted, do not go
3528 * ahead to do osd_ea_fid_get, which will set
3529 * the inode to bad inode, which might cause
3530 * the inode to be deleted uncorrectly */
3531 inode = ldiskfs_iget(osd_sb(osd),
3532 le32_to_cpu(de->inode));
3533 if (IS_ERR(inode)) {
3534 CDEBUG(D_INODE, "%s: "DFID"get inode"
3535 "error.\n", osd_name(osd),
3537 rc = PTR_ERR(inode);
3539 if (likely(inode->i_nlink != 0)) {
3540 id = &osd_oti_get(env)->oti_id;
3541 rc = osd_ea_fid_get(env, obj,
3542 le32_to_cpu(de->inode),
3545 CDEBUG(D_INFO, "%s: %u "DFID
3548 le32_to_cpu(de->inode),
3556 unlikely(osd_remote_fid(env, osd, fid)))
3557 /* Need to delete agent inode */
3558 ino = le32_to_cpu(de->inode);
3560 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
3562 if (rc == 0 && unlikely(ino != 0)) {
3563 rc = osd_delete_local_agent_inode(env, osd, fid, ino,
3566 CERROR("%s: del local inode "DFID": rc = %d\n",
3567 osd_name(osd), PFID(fid), rc);
3573 ldiskfs_htree_unlock(hlock);
3575 up_write(&obj->oo_ext_idx_sem);
3580 /* For inode on the remote MDT, .. will point to
3581 * /Agent directory, Check whether it needs to delete
3582 * from agent directory */
3583 if (unlikely(strcmp((char *)key, dotdot) == 0)) {
3584 rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj,
3586 if (rc != 0 && rc != -ENOENT) {
3587 CERROR("%s: delete agent inode "DFID": rc = %d\n",
3588 osd_name(osd), PFID(fid), rc);
3598 LASSERT(osd_invariant(obj));
3603 * Lookup index for \a key and copy record to \a rec.
3605 * \param dt osd index object
3606 * \param key key for index
3607 * \param rec record reference
3609 * \retval +ve success : exact mach
3610 * \retval 0 return record with key not greater than \a key
3611 * \retval -ve failure
3613 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3614 struct dt_rec *rec, const struct dt_key *key)
3616 struct osd_object *obj = osd_dt_obj(dt);
3617 struct iam_path_descr *ipd;
3618 struct iam_container *bag = &obj->oo_dir->od_container;
3619 struct osd_thread_info *oti = osd_oti_get(env);
3620 struct iam_iterator *it = &oti->oti_idx_it;
3621 struct iam_rec *iam_rec;
3625 if (!dt_object_exists(dt))
3628 LASSERT(osd_invariant(obj));
3629 LASSERT(!dt_object_remote(dt));
3630 LASSERT(bag->ic_object == obj->oo_inode);
3632 ipd = osd_idx_ipd_get(env, bag);
3636 /* got ipd now we can start iterator. */
3637 iam_it_init(it, bag, 0, ipd);
3639 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3640 /* swab quota uid/gid provided by caller */
3641 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3642 key = (const struct dt_key *)&oti->oti_quota_id;
3645 rc = iam_it_get(it, (struct iam_key *)key);
3647 if (S_ISDIR(obj->oo_inode->i_mode))
3648 iam_rec = (struct iam_rec *)oti->oti_ldp;
3650 iam_rec = (struct iam_rec *) rec;
3652 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3654 if (S_ISDIR(obj->oo_inode->i_mode))
3655 osd_fid_unpack((struct lu_fid *) rec,
3656 (struct osd_fid_pack *)iam_rec);
3657 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3658 osd_quota_unpack(obj, rec);
3663 osd_ipd_put(env, bag, ipd);
3665 LINVRNT(osd_invariant(obj));
3670 static int osd_index_declare_iam_insert(const struct lu_env *env,
3671 struct dt_object *dt,
3672 const struct dt_rec *rec,
3673 const struct dt_key *key,
3674 struct thandle *handle)
3676 struct osd_thandle *oh;
3678 LASSERT(handle != NULL);
3680 oh = container_of0(handle, struct osd_thandle, ot_super);
3681 LASSERT(oh->ot_handle == NULL);
3683 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3684 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3690 * Inserts (key, value) pair in \a dt index object.
3692 * \param dt osd index object
3693 * \param key key for index
3694 * \param rec record reference
3695 * \param th transaction handler
3698 * \retval -ve failure
3700 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3701 const struct dt_rec *rec,
3702 const struct dt_key *key, struct thandle *th,
3705 struct osd_object *obj = osd_dt_obj(dt);
3706 struct iam_path_descr *ipd;
3707 struct osd_thandle *oh;
3708 struct iam_container *bag;
3709 struct osd_thread_info *oti = osd_oti_get(env);
3710 struct iam_rec *iam_rec;
3714 if (!dt_object_exists(dt))
3717 LINVRNT(osd_invariant(obj));
3718 LASSERT(!dt_object_remote(dt));
3720 bag = &obj->oo_dir->od_container;
3721 LASSERT(bag->ic_object == obj->oo_inode);
3722 LASSERT(th != NULL);
3724 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3726 ipd = osd_idx_ipd_get(env, bag);
3727 if (unlikely(ipd == NULL))
3730 oh = container_of0(th, struct osd_thandle, ot_super);
3731 LASSERT(oh->ot_handle != NULL);
3732 LASSERT(oh->ot_handle->h_transaction != NULL);
3733 if (S_ISDIR(obj->oo_inode->i_mode)) {
3734 iam_rec = (struct iam_rec *)oti->oti_ldp;
3735 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3736 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3737 /* pack quota uid/gid */
3738 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3739 key = (const struct dt_key *)&oti->oti_quota_id;
3740 /* pack quota record */
3741 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3742 iam_rec = (struct iam_rec *)rec;
3744 iam_rec = (struct iam_rec *)rec;
3747 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3749 osd_ipd_put(env, bag, ipd);
3750 LINVRNT(osd_invariant(obj));
3755 * Calls ldiskfs_add_entry() to add directory entry
3756 * into the directory. This is required for
3757 * interoperability mode (b11826)
3759 * \retval 0, on success
3760 * \retval -ve, on error
3762 static int __osd_ea_add_rec(struct osd_thread_info *info,
3763 struct osd_object *pobj, struct inode *cinode,
3764 const char *name, const struct lu_fid *fid,
3765 struct htree_lock *hlock, struct thandle *th)
3767 struct ldiskfs_dentry_param *ldp;
3768 struct dentry *child;
3769 struct osd_thandle *oth;
3772 oth = container_of(th, struct osd_thandle, ot_super);
3773 LASSERT(oth->ot_handle != NULL);
3774 LASSERT(oth->ot_handle->h_transaction != NULL);
3775 LASSERT(pobj->oo_inode);
3777 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3778 if (unlikely(pobj->oo_inode ==
3779 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
3782 osd_get_ldiskfs_dirent_param(ldp, fid);
3783 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3784 child->d_fsdata = (void *)ldp;
3785 ll_vfs_dq_init(pobj->oo_inode);
3786 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3787 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
3788 struct ldiskfs_dir_entry_2 *de;
3789 struct buffer_head *bh;
3792 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
3795 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
3798 if (S_ISDIR(cinode->i_mode))
3799 de->file_type = LDISKFS_DIRENT_LUFID |
3800 LDISKFS_FT_REG_FILE;
3802 de->file_type = LDISKFS_DIRENT_LUFID |
3804 ldiskfs_handle_dirty_metadata(oth->ot_handle,
3815 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3816 * into the directory.Also sets flags into osd object to
3817 * indicate dot and dotdot are created. This is required for
3818 * interoperability mode (b11826)
3820 * \param dir directory for dot and dotdot fixup.
3821 * \param obj child object for linking
3823 * \retval 0, on success
3824 * \retval -ve, on error
3826 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3827 struct osd_object *dir,
3828 struct inode *parent_dir, const char *name,
3829 const struct lu_fid *dot_fid,
3830 const struct lu_fid *dot_dot_fid,
3833 struct inode *inode = dir->oo_inode;
3834 struct osd_thandle *oth;
3837 oth = container_of(th, struct osd_thandle, ot_super);
3838 LASSERT(oth->ot_handle->h_transaction != NULL);
3839 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3841 if (strcmp(name, dot) == 0) {
3842 if (dir->oo_compat_dot_created) {
3845 LASSERT(inode == parent_dir);
3846 dir->oo_compat_dot_created = 1;
3849 } else if (strcmp(name, dotdot) == 0) {
3850 if (!dir->oo_compat_dot_created)
3852 /* in case of rename, dotdot is already created */
3853 if (dir->oo_compat_dotdot_created) {
3854 return __osd_ea_add_rec(info, dir, parent_dir, name,
3855 dot_dot_fid, NULL, th);
3858 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
3859 struct lu_fid tfid = *dot_dot_fid;
3862 result = osd_add_dot_dotdot_internal(info,
3863 dir->oo_inode, parent_dir, dot_fid,
3866 result = osd_add_dot_dotdot_internal(info,
3867 dir->oo_inode, parent_dir, dot_fid,
3872 dir->oo_compat_dotdot_created = 1;
3880 * It will call the appropriate osd_add* function and return the
3881 * value, return by respective functions.
3883 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3884 struct inode *cinode, const char *name,
3885 const struct lu_fid *fid, struct thandle *th)
3887 struct osd_thread_info *info = osd_oti_get(env);
3888 struct htree_lock *hlock;
3891 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3893 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3895 if (hlock != NULL) {
3896 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3899 down_write(&pobj->oo_ext_idx_sem);
3902 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3903 lu_object_fid(&pobj->oo_dt.do_lu),
3906 if (hlock != NULL) {
3907 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3908 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3910 down_write(&pobj->oo_ext_idx_sem);
3913 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
3914 struct lu_fid *tfid = &info->oti_fid;
3918 rc = __osd_ea_add_rec(info, pobj, cinode, name,
3921 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3926 ldiskfs_htree_unlock(hlock);
3928 up_write(&pobj->oo_ext_idx_sem);
3934 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3935 struct osd_idmap_cache *oic)
3937 struct osd_scrub *scrub = &dev->od_scrub;
3938 struct lu_fid *fid = &oic->oic_fid;
3939 struct osd_inode_id *id = &oti->oti_id;
3944 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3947 if (scrub->os_pos_current > id->oii_ino)
3951 rc = osd_oi_lookup(oti, dev, fid, id, OI_CHECK_FLD);
3952 if (rc != 0 && rc != -ENOENT)
3955 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3958 if (thread_is_running(&scrub->os_thread)) {
3959 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3960 /* There is race condition between osd_oi_lookup and OI scrub.
3961 * The OI scrub finished just after osd_oi_lookup() failure.
3962 * Under such case, it is unnecessary to trigger OI scrub again,
3963 * but try to call osd_oi_lookup() again. */
3964 if (unlikely(rc == -EAGAIN))
3970 if (!dev->od_noscrub && ++once == 1) {
3971 rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN |
3973 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC "
3974 "for "DFID", rc = %d [2]\n",
3975 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3977 if (rc == 0 || rc == -EALREADY)
3984 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
3985 struct osd_device *dev,
3986 struct osd_idmap_cache *oic,
3987 struct lu_fid *fid, __u32 ino)
3989 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
3990 struct inode *inode;
3993 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3994 inode = osd_iget(oti, dev, &oic->oic_lid);
3995 if (IS_ERR(inode)) {
3996 fid_zero(&oic->oic_fid);
3997 return PTR_ERR(inode);
4000 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, lma);
4003 fid_zero(&oic->oic_fid);
4005 *fid = oic->oic_fid = lma->lma_self_fid;
4009 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
4010 struct osd_inode_id *id, const struct lu_fid *fid)
4012 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
4013 id->oii_ino, id->oii_gen, info);
4014 info->oti_cache.oic_lid = *id;
4015 info->oti_cache.oic_fid = *fid;
4016 info->oti_cache.oic_dev = osd;
4020 * Get parent FID from the linkEA.
4022 * For a directory which parent resides on remote MDT, to satisfy the
4023 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
4024 * the other hand, to make the lookup(..) on the directory can return
4025 * the real parent FID, we append the real parent FID after its ".."
4026 * name entry in the /REMOTE_PARENT_DIR.
4028 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
4029 * backup. So after the restore, we cannot get the right parent FID from
4030 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
4031 * we have stored the real parent FID in the directory object's linkEA,
4032 * we can parse the linkEA for the real parent FID.
4034 * \param[in] env pointer to the thread context
4035 * \param[in] obj pointer to the object to be handled
4036 * \param[out]fid pointer to the buffer to hold the parent FID
4038 * \retval 0 for getting the real parent FID successfully
4039 * \retval negative error number on failure
4041 static int osd_get_pfid_from_linkea(const struct lu_env *env,
4042 struct osd_object *obj,
4045 struct osd_thread_info *oti = osd_oti_get(env);
4046 struct lu_buf *buf = &oti->oti_big_buf;
4047 struct dentry *dentry = &oti->oti_obj_dentry;
4048 struct inode *inode = obj->oo_inode;
4049 struct linkea_data ldata = { NULL };
4054 if (!S_ISDIR(inode->i_mode))
4058 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4059 buf->lb_buf, buf->lb_len);
4060 if (rc == -ERANGE) {
4061 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4064 lu_buf_realloc(buf, rc);
4065 if (buf->lb_buf == NULL)
4072 if (unlikely(rc == 0))
4078 if (unlikely(buf->lb_buf == NULL)) {
4079 lu_buf_realloc(buf, rc);
4080 if (buf->lb_buf == NULL)
4087 rc = linkea_init(&ldata);
4089 linkea_first_entry(&ldata);
4090 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
4097 * Calls ->lookup() to find dentry. From dentry get inode and
4098 * read inode's ea to get fid. This is required for interoperability
4101 * \retval 0, on success
4102 * \retval -ve, on error
4104 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
4105 struct dt_rec *rec, const struct dt_key *key)
4107 struct inode *dir = obj->oo_inode;
4108 struct dentry *dentry;
4109 struct ldiskfs_dir_entry_2 *de;
4110 struct buffer_head *bh;
4111 struct lu_fid *fid = (struct lu_fid *) rec;
4112 struct htree_lock *hlock = NULL;
4117 LASSERT(dir->i_op != NULL);
4118 LASSERT(dir->i_op->lookup != NULL);
4120 dentry = osd_child_dentry_get(env, obj,
4121 (char *)key, strlen((char *)key));
4123 if (obj->oo_hl_head != NULL) {
4124 hlock = osd_oti_get(env)->oti_hlock;
4125 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4126 dir, LDISKFS_HLOCK_LOOKUP);
4128 down_read(&obj->oo_ext_idx_sem);
4131 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4133 struct osd_thread_info *oti = osd_oti_get(env);
4134 struct osd_inode_id *id = &oti->oti_id;
4135 struct osd_idmap_cache *oic = &oti->oti_cache;
4136 struct osd_device *dev = osd_obj2dev(obj);
4138 ino = le32_to_cpu(de->inode);
4139 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
4141 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
4145 rc = osd_get_fid_from_dentry(de, rec);
4147 /* done with de, release bh */
4150 if (unlikely(ino == osd_remote_parent_ino(dev))) {
4151 const char *name = (const char *)key;
4153 /* If the parent is on remote MDT, and there
4154 * is no FID-in-dirent, then we have to get
4155 * the parent FID from the linkEA. */
4156 if (likely(strlen(name) == 2 &&
4157 name[0] == '.' && name[1] == '.'))
4158 rc = osd_get_pfid_from_linkea(env, obj,
4161 rc = osd_ea_fid_get(env, obj, ino, fid, id);
4164 osd_id_gen(id, ino, OSD_OII_NOGEN);
4168 fid_zero(&oic->oic_fid);
4172 if (osd_remote_fid(env, dev, fid))
4175 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
4176 osd_consistency_check(oti, dev, oic);
4185 ldiskfs_htree_unlock(hlock);
4187 up_read(&obj->oo_ext_idx_sem);
4192 * Find the osd object for given fid.
4194 * \param fid need to find the osd object having this fid
4196 * \retval osd_object on success
4197 * \retval -ve on error
4199 static struct osd_object *osd_object_find(const struct lu_env *env,
4200 struct dt_object *dt,
4201 const struct lu_fid *fid)
4203 struct lu_device *ludev = dt->do_lu.lo_dev;
4204 struct osd_object *child = NULL;
4205 struct lu_object *luch;
4206 struct lu_object *lo;
4209 * at this point topdev might not exist yet
4210 * (i.e. MGS is preparing profiles). so we can
4211 * not rely on topdev and instead lookup with
4212 * our device passed as topdev. this can't work
4213 * if the object isn't cached yet (as osd doesn't
4214 * allocate lu_header). IOW, the object must be
4215 * in the cache, otherwise lu_object_alloc() crashes
4218 luch = lu_object_find_at(env, ludev->ld_site->ls_top_dev == NULL ?
4219 ludev : ludev->ld_site->ls_top_dev,
4221 if (!IS_ERR(luch)) {
4222 if (lu_object_exists(luch)) {
4223 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
4225 child = osd_obj(lo);
4227 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4228 "lu_object can't be located"
4229 DFID"\n", PFID(fid));
4231 if (child == NULL) {
4232 lu_object_put(env, luch);
4233 CERROR("Unable to get osd_object\n");
4234 child = ERR_PTR(-ENOENT);
4237 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4238 "lu_object does not exists "DFID"\n",
4240 lu_object_put(env, luch);
4241 child = ERR_PTR(-ENOENT);
4244 child = ERR_CAST(luch);
4251 * Put the osd object once done with it.
4253 * \param obj osd object that needs to be put
4255 static inline void osd_object_put(const struct lu_env *env,
4256 struct osd_object *obj)
4258 lu_object_put(env, &obj->oo_dt.do_lu);
4261 static int osd_index_declare_ea_insert(const struct lu_env *env,
4262 struct dt_object *dt,
4263 const struct dt_rec *rec,
4264 const struct dt_key *key,
4265 struct thandle *handle)
4267 struct osd_thandle *oh;
4268 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4269 struct lu_fid *fid = (struct lu_fid *)rec;
4273 LASSERT(!dt_object_remote(dt));
4274 LASSERT(handle != NULL);
4276 oh = container_of0(handle, struct osd_thandle, ot_super);
4277 LASSERT(oh->ot_handle == NULL);
4279 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4280 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4282 if (osd_dt_obj(dt)->oo_inode != NULL) {
4283 struct inode *inode = osd_dt_obj(dt)->oo_inode;
4285 /* We ignore block quota on meta pool (MDTs), so needn't
4286 * calculate how many blocks will be consumed by this index
4288 rc = osd_declare_inode_qid(env, i_uid_read(inode),
4289 i_gid_read(inode), 0, oh,
4290 osd_dt_obj(dt), true, NULL, false);
4296 rc = osd_remote_fid(env, osd, fid);
4302 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
4303 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
4304 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4305 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4306 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4307 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4313 * Index add function for interoperability mode (b11826).
4314 * It will add the directory entry.This entry is needed to
4315 * maintain name->fid mapping.
4317 * \param key it is key i.e. file entry to be inserted
4318 * \param rec it is value of given key i.e. fid
4320 * \retval 0, on success
4321 * \retval -ve, on error
4323 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
4324 const struct dt_rec *rec,
4325 const struct dt_key *key, struct thandle *th,
4328 struct osd_object *obj = osd_dt_obj(dt);
4329 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4330 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4331 const struct lu_fid *fid = rec1->rec_fid;
4332 const char *name = (const char *)key;
4333 struct osd_thread_info *oti = osd_oti_get(env);
4334 struct osd_inode_id *id = &oti->oti_id;
4335 struct inode *child_inode = NULL;
4336 struct osd_object *child = NULL;
4340 if (!dt_object_exists(dt))
4343 LASSERT(osd_invariant(obj));
4344 LASSERT(!dt_object_remote(dt));
4345 LASSERT(th != NULL);
4347 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4349 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
4351 rc = osd_remote_fid(env, osd, fid);
4353 CERROR("%s: Can not find object "DFID" rc %d\n",
4354 osd_name(osd), PFID(fid), rc);
4359 /* Insert remote entry */
4360 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
4361 struct osd_mdobj_map *omm = osd->od_mdt_map;
4362 struct osd_thandle *oh;
4364 /* If parent on remote MDT, we need put this object
4366 oh = container_of(th, typeof(*oh), ot_super);
4367 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4369 CERROR("%s: add "DFID" error: rc = %d\n",
4371 PFID(lu_object_fid(&dt->do_lu)), rc);
4375 child_inode = igrab(omm->omm_remote_parent->d_inode);
4377 child_inode = osd_create_local_agent_inode(env, osd,
4378 obj, fid, rec1->rec_type & S_IFMT, th);
4379 if (IS_ERR(child_inode))
4380 RETURN(PTR_ERR(child_inode));
4383 /* Insert local entry */
4384 child = osd_object_find(env, dt, fid);
4385 if (IS_ERR(child)) {
4386 CERROR("%s: Can not find object "DFID"%u:%u: rc = %d\n",
4387 osd_name(osd), PFID(fid),
4388 id->oii_ino, id->oii_gen,
4389 (int)PTR_ERR(child));
4390 RETURN(PTR_ERR(child));
4392 child_inode = igrab(child->oo_inode);
4395 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
4397 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
4398 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
4402 osd_object_put(env, child);
4403 LASSERT(osd_invariant(obj));
4408 * Initialize osd Iterator for given osd index object.
4410 * \param dt osd index object
4413 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
4414 struct dt_object *dt,
4417 struct osd_it_iam *it;
4418 struct osd_object *obj = osd_dt_obj(dt);
4419 struct lu_object *lo = &dt->do_lu;
4420 struct iam_path_descr *ipd;
4421 struct iam_container *bag = &obj->oo_dir->od_container;
4423 if (!dt_object_exists(dt))
4424 return ERR_PTR(-ENOENT);
4428 return ERR_PTR(-ENOMEM);
4430 ipd = osd_it_ipd_get(env, bag);
4431 if (likely(ipd != NULL)) {
4435 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
4436 return (struct dt_it *)it;
4439 return ERR_PTR(-ENOMEM);
4444 * free given Iterator.
4447 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
4449 struct osd_it_iam *it = (struct osd_it_iam *)di;
4450 struct osd_object *obj = it->oi_obj;
4452 iam_it_fini(&it->oi_it);
4453 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
4454 lu_object_put(env, &obj->oo_dt.do_lu);
4459 * Move Iterator to record specified by \a key
4461 * \param di osd iterator
4462 * \param key key for index
4464 * \retval +ve di points to record with least key not larger than key
4465 * \retval 0 di points to exact matched key
4466 * \retval -ve failure
4469 static int osd_it_iam_get(const struct lu_env *env,
4470 struct dt_it *di, const struct dt_key *key)
4472 struct osd_thread_info *oti = osd_oti_get(env);
4473 struct osd_it_iam *it = (struct osd_it_iam *)di;
4475 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4476 /* swab quota uid/gid */
4477 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4478 key = (struct dt_key *)&oti->oti_quota_id;
4481 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
4487 * \param di osd iterator
4489 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
4491 struct osd_it_iam *it = (struct osd_it_iam *)di;
4493 iam_it_put(&it->oi_it);
4497 * Move iterator by one record
4499 * \param di osd iterator
4501 * \retval +1 end of container reached
4503 * \retval -ve failure
4506 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
4508 struct osd_it_iam *it = (struct osd_it_iam *)di;
4510 return iam_it_next(&it->oi_it);
4514 * Return pointer to the key under iterator.
4517 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
4518 const struct dt_it *di)
4520 struct osd_thread_info *oti = osd_oti_get(env);
4521 struct osd_it_iam *it = (struct osd_it_iam *)di;
4522 struct osd_object *obj = it->oi_obj;
4525 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
4527 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
4528 /* swab quota uid/gid */
4529 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
4530 key = (struct dt_key *)&oti->oti_quota_id;
4537 * Return size of key under iterator (in bytes)
4540 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
4542 struct osd_it_iam *it = (struct osd_it_iam *)di;
4544 return iam_it_key_size(&it->oi_it);
4548 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
4550 /* check if file type is required */
4551 if (ent->lde_attrs & LUDA_TYPE) {
4552 struct luda_type *lt;
4553 int align = sizeof(*lt) - 1;
4555 len = (len + align) & ~align;
4556 lt = (struct luda_type *)(ent->lde_name + len);
4557 lt->lt_type = cpu_to_le16(DTTOIF(type));
4560 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
4564 * build lu direct from backend fs dirent.
4568 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
4569 char *name, __u16 namelen, __u16 type, __u32 attr)
4571 ent->lde_attrs = attr | LUDA_FID;
4572 fid_cpu_to_le(&ent->lde_fid, fid);
4574 ent->lde_hash = cpu_to_le64(offset);
4575 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
4577 strncpy(ent->lde_name, name, namelen);
4578 ent->lde_name[namelen] = '\0';
4579 ent->lde_namelen = cpu_to_le16(namelen);
4581 /* append lustre attributes */
4582 osd_it_append_attrs(ent, namelen, type);
4586 * Return pointer to the record under iterator.
4588 static int osd_it_iam_rec(const struct lu_env *env,
4589 const struct dt_it *di,
4590 struct dt_rec *dtrec, __u32 attr)
4592 struct osd_it_iam *it = (struct osd_it_iam *)di;
4593 struct osd_thread_info *info = osd_oti_get(env);
4596 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
4597 const struct osd_fid_pack *rec;
4598 struct lu_fid *fid = &info->oti_fid;
4599 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4605 name = (char *)iam_it_key_get(&it->oi_it);
4607 RETURN(PTR_ERR(name));
4609 namelen = iam_it_key_size(&it->oi_it);
4611 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
4613 RETURN(PTR_ERR(rec));
4615 rc = osd_fid_unpack(fid, rec);
4619 hash = iam_it_store(&it->oi_it);
4621 /* IAM does not store object type in IAM index (dir) */
4622 osd_it_pack_dirent(lde, fid, hash, name, namelen,
4624 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4625 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4626 (struct iam_rec *)dtrec);
4627 osd_quota_unpack(it->oi_obj, dtrec);
4629 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4630 (struct iam_rec *)dtrec);
4637 * Returns cookie for current Iterator position.
4639 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
4641 struct osd_it_iam *it = (struct osd_it_iam *)di;
4643 return iam_it_store(&it->oi_it);
4647 * Restore iterator from cookie.
4649 * \param di osd iterator
4650 * \param hash Iterator location cookie
4652 * \retval +ve di points to record with least key not larger than key.
4653 * \retval 0 di points to exact matched key
4654 * \retval -ve failure
4657 static int osd_it_iam_load(const struct lu_env *env,
4658 const struct dt_it *di, __u64 hash)
4660 struct osd_it_iam *it = (struct osd_it_iam *)di;
4662 return iam_it_load(&it->oi_it, hash);
4665 static const struct dt_index_operations osd_index_iam_ops = {
4666 .dio_lookup = osd_index_iam_lookup,
4667 .dio_declare_insert = osd_index_declare_iam_insert,
4668 .dio_insert = osd_index_iam_insert,
4669 .dio_declare_delete = osd_index_declare_iam_delete,
4670 .dio_delete = osd_index_iam_delete,
4672 .init = osd_it_iam_init,
4673 .fini = osd_it_iam_fini,
4674 .get = osd_it_iam_get,
4675 .put = osd_it_iam_put,
4676 .next = osd_it_iam_next,
4677 .key = osd_it_iam_key,
4678 .key_size = osd_it_iam_key_size,
4679 .rec = osd_it_iam_rec,
4680 .store = osd_it_iam_store,
4681 .load = osd_it_iam_load
4687 * Creates or initializes iterator context.
4689 * \retval struct osd_it_ea, iterator structure on success
4692 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
4693 struct dt_object *dt,
4696 struct osd_object *obj = osd_dt_obj(dt);
4697 struct osd_thread_info *info = osd_oti_get(env);
4698 struct osd_it_ea *oie;
4700 struct lu_object *lo = &dt->do_lu;
4701 struct dentry *obj_dentry;
4704 if (!dt_object_exists(dt))
4705 RETURN(ERR_PTR(-ENOENT));
4707 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
4709 RETURN(ERR_PTR(-ENOMEM));
4710 obj_dentry = &oie->oie_dentry;
4712 obj_dentry->d_inode = obj->oo_inode;
4713 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
4714 obj_dentry->d_name.hash = 0;
4716 oie->oie_rd_dirent = 0;
4717 oie->oie_it_dirent = 0;
4718 oie->oie_dirent = NULL;
4719 if (unlikely(!info->oti_it_ea_buf_used)) {
4720 oie->oie_buf = info->oti_it_ea_buf;
4721 info->oti_it_ea_buf_used = 1;
4723 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4724 if (oie->oie_buf == NULL)
4725 RETURN(ERR_PTR(-ENOMEM));
4729 file = &oie->oie_file;
4731 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
4732 if (attr & LUDA_64BITHASH)
4733 file->f_mode = FMODE_64BITHASH;
4735 file->f_mode = FMODE_32BITHASH;
4736 file->f_dentry = obj_dentry;
4737 file->f_mapping = obj->oo_inode->i_mapping;
4738 file->f_op = obj->oo_inode->i_fop;
4739 set_file_inode(file, obj->oo_inode);
4742 RETURN((struct dt_it *) oie);
4746 * Destroy or finishes iterator context.
4748 * \param di iterator structure to be destroyed
4750 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
4752 struct osd_thread_info *info = osd_oti_get(env);
4753 struct osd_it_ea *oie = (struct osd_it_ea *)di;
4754 struct osd_object *obj = oie->oie_obj;
4755 struct inode *inode = obj->oo_inode;
4758 oie->oie_file.f_op->release(inode, &oie->oie_file);
4759 lu_object_put(env, &obj->oo_dt.do_lu);
4760 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
4761 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4763 info->oti_it_ea_buf_used = 0;
4764 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
4769 * It position the iterator at given key, so that next lookup continues from
4770 * that key Or it is similar to dio_it->load() but based on a key,
4771 * rather than file position.
4773 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4776 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4778 static int osd_it_ea_get(const struct lu_env *env,
4779 struct dt_it *di, const struct dt_key *key)
4781 struct osd_it_ea *it = (struct osd_it_ea *)di;
4784 LASSERT(((const char *)key)[0] == '\0');
4785 it->oie_file.f_pos = 0;
4786 it->oie_rd_dirent = 0;
4787 it->oie_it_dirent = 0;
4788 it->oie_dirent = NULL;
4796 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4800 struct osd_filldir_cbs {
4801 #ifdef HAVE_DIR_CONTEXT
4802 struct dir_context ctx;
4804 struct osd_it_ea *it;
4807 * It is called internally by ->readdir(). It fills the
4808 * iterator's in-memory data structure with required
4809 * information i.e. name, namelen, rec_size etc.
4811 * \param buf in which information to be filled in.
4812 * \param name name of the file in given dir
4814 * \retval 0 on success
4815 * \retval 1 on buffer full
4817 static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen,
4818 loff_t offset, __u64 ino,
4821 struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it;
4822 struct osd_object *obj = it->oie_obj;
4823 struct osd_it_ea_dirent *ent = it->oie_dirent;
4824 struct lu_fid *fid = &ent->oied_fid;
4825 struct osd_fid_pack *rec;
4828 /* this should never happen */
4829 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4830 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4834 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4838 /* "." is just the object itself. */
4839 if (namelen == 1 && name[0] == '.') {
4840 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4841 } else if (d_type & LDISKFS_DIRENT_LUFID) {
4842 rec = (struct osd_fid_pack*) (name + namelen + 1);
4843 if (osd_fid_unpack(fid, rec) != 0)
4848 d_type &= ~LDISKFS_DIRENT_LUFID;
4850 /* NOT export local root. */
4851 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
4852 ino = obj->oo_inode->i_ino;
4853 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4856 ent->oied_ino = ino;
4857 ent->oied_off = offset;
4858 ent->oied_namelen = namelen;
4859 ent->oied_type = d_type;
4861 memcpy(ent->oied_name, name, namelen);
4863 it->oie_rd_dirent++;
4864 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4869 * Calls ->readdir() to load a directory entry at a time
4870 * and stored it in iterator's in-memory data structure.
4872 * \param di iterator's in memory structure
4874 * \retval 0 on success
4875 * \retval -ve on error
4876 * \retval +1 reach the end of entry
4878 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4879 const struct dt_it *di)
4881 struct osd_it_ea *it = (struct osd_it_ea *)di;
4882 struct osd_object *obj = it->oie_obj;
4883 struct inode *inode = obj->oo_inode;
4884 struct htree_lock *hlock = NULL;
4885 struct file *filp = &it->oie_file;
4887 struct osd_filldir_cbs buf = {
4888 #ifdef HAVE_DIR_CONTEXT
4889 .ctx.actor = osd_ldiskfs_filldir,
4895 it->oie_dirent = it->oie_buf;
4896 it->oie_rd_dirent = 0;
4898 if (obj->oo_hl_head != NULL) {
4899 hlock = osd_oti_get(env)->oti_hlock;
4900 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4901 inode, LDISKFS_HLOCK_READDIR);
4903 down_read(&obj->oo_ext_idx_sem);
4906 #ifdef HAVE_DIR_CONTEXT
4907 buf.ctx.pos = filp->f_pos;
4908 rc = inode->i_fop->iterate(filp, &buf.ctx);
4909 filp->f_pos = buf.ctx.pos;
4911 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
4915 ldiskfs_htree_unlock(hlock);
4917 up_read(&obj->oo_ext_idx_sem);
4919 if (it->oie_rd_dirent == 0) {
4920 /*If it does not get any dirent, it means it has been reached
4921 *to the end of the dir */
4922 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
4926 it->oie_dirent = it->oie_buf;
4927 it->oie_it_dirent = 1;
4934 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4935 * to load a directory entry at a time and stored it in
4936 * iterator's in-memory data structure.
4938 * \param di iterator's in memory structure
4940 * \retval +ve iterator reached to end
4941 * \retval 0 iterator not reached to end
4942 * \retval -ve on error
4944 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4946 struct osd_it_ea *it = (struct osd_it_ea *)di;
4951 if (it->oie_it_dirent < it->oie_rd_dirent) {
4953 (void *) it->oie_dirent +
4954 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4955 it->oie_dirent->oied_namelen);
4956 it->oie_it_dirent++;
4959 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4962 rc = osd_ldiskfs_it_fill(env, di);
4969 * Returns the key at current position from iterator's in memory structure.
4971 * \param di iterator's in memory structure
4973 * \retval key i.e. struct dt_key on success
4975 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4976 const struct dt_it *di)
4978 struct osd_it_ea *it = (struct osd_it_ea *)di;
4980 return (struct dt_key *)it->oie_dirent->oied_name;
4984 * Returns the key's size at current position from iterator's in memory structure.
4986 * \param di iterator's in memory structure
4988 * \retval key_size i.e. struct dt_key on success
4990 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4992 struct osd_it_ea *it = (struct osd_it_ea *)di;
4994 return it->oie_dirent->oied_namelen;
4998 osd_dirent_update(handle_t *jh, struct super_block *sb,
4999 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
5000 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de)
5002 struct osd_fid_pack *rec;
5006 LASSERT(de->file_type & LDISKFS_DIRENT_LUFID);
5007 LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack));
5009 rc = ldiskfs_journal_get_write_access(jh, bh);
5013 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5014 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
5015 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5021 osd_dirent_has_space(__u16 reclen, __u16 namelen, unsigned blocksize)
5023 if (ldiskfs_rec_len_from_disk(reclen, blocksize) >=
5024 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
5031 osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot)
5033 LASSERTF(dot_dotdot == 1 || dot_dotdot == 2,
5034 "dot_dotdot = %d\n", dot_dotdot);
5036 if (LDISKFS_DIR_REC_LEN(de) >=
5037 __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack)))
5044 osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
5045 struct inode *dir, struct inode *inode,
5046 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
5047 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de,
5048 struct htree_lock *hlock)
5050 struct dentry *dentry;
5051 struct osd_fid_pack *rec;
5052 struct ldiskfs_dentry_param *ldp;
5056 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
5057 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5060 /* There is enough space to hold the FID-in-dirent. */
5061 if (osd_dirent_has_space(de->rec_len, ent->oied_namelen,
5062 dir->i_sb->s_blocksize)) {
5063 rc = ldiskfs_journal_get_write_access(jh, bh);
5067 de->name[de->name_len] = 0;
5068 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5069 rec->fp_len = sizeof(struct lu_fid) + 1;
5070 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
5071 de->file_type |= LDISKFS_DIRENT_LUFID;
5073 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5078 rc = ldiskfs_delete_entry(jh, dir, de, bh);
5082 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
5084 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
5085 osd_get_ldiskfs_dirent_param(ldp, fid);
5086 dentry->d_fsdata = (void *)ldp;
5087 ll_vfs_dq_init(dir);
5088 rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock);
5089 /* It is too bad, we cannot reinsert the name entry back.
5090 * That means we lose it! */
5092 CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
5093 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
5094 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
5095 dir->i_ino, dir->i_generation,
5096 ent->oied_namelen, ent->oied_name, PFID(fid), rc);
5102 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
5103 struct osd_it_ea *it, struct lu_fid *fid,
5104 struct osd_inode_id *id, __u32 *attr)
5106 struct osd_thread_info *info = osd_oti_get(env);
5107 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
5108 struct osd_device *dev = osd_obj2dev(obj);
5109 struct super_block *sb = osd_sb(dev);
5110 const char *devname =
5111 LDISKFS_SB(sb)->s_es->s_volume_name;
5112 struct osd_it_ea_dirent *ent = it->oie_dirent;
5113 struct inode *dir = obj->oo_inode;
5114 struct htree_lock *hlock = NULL;
5115 struct buffer_head *bh = NULL;
5116 handle_t *jh = NULL;
5117 struct ldiskfs_dir_entry_2 *de;
5118 struct dentry *dentry;
5119 struct inode *inode;
5126 if (ent->oied_name[0] == '.') {
5127 if (ent->oied_namelen == 1)
5129 else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
5133 dentry = osd_child_dentry_get(env, obj, ent->oied_name,
5136 /* We need to ensure that the name entry is still valid.
5137 * Because it may be removed or renamed by other already.
5139 * The unlink or rename operation will start journal before PDO lock,
5140 * so to avoid deadlock, here we need to start journal handle before
5141 * related PDO lock also. But because we do not know whether there
5142 * will be something to be repaired before PDO lock, we just start
5143 * journal without conditions.
5145 * We may need to remove the name entry firstly, then insert back.
5146 * One credit is for user quota file update.
5147 * One credit is for group quota file update.
5148 * Two credits are for dirty inode. */
5149 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
5150 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
5153 if (dev->od_dirent_journal != 0) {
5154 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
5157 CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
5158 "check_repair, dir = %lu/%u, credits = %d, "
5159 "name = %.*s: rc = %d\n",
5160 devname, dir->i_ino, dir->i_generation, credits,
5161 ent->oied_namelen, ent->oied_name, rc);
5165 if (obj->oo_hl_head != NULL) {
5166 hlock = osd_oti_get(env)->oti_hlock;
5167 /* "0" means exclusive lock for the whole directory.
5168 * We need to prevent others access such name entry
5169 * during the delete + insert. Neither HLOCK_ADD nor
5170 * HLOCK_DEL cannot guarantee the atomicity. */
5171 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
5173 down_write(&obj->oo_ext_idx_sem);
5176 if (obj->oo_hl_head != NULL) {
5177 hlock = osd_oti_get(env)->oti_hlock;
5178 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
5179 LDISKFS_HLOCK_LOOKUP);
5181 down_read(&obj->oo_ext_idx_sem);
5185 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5186 /* For dot/dotdot entry, if there is not enough space to hold the
5187 * FID-in-dirent, just keep them there. It only happens when the
5188 * device upgraded from 1.8 or restored from MDT file-level backup.
5189 * For the whole directory, only dot/dotdot entry have no FID-in-dirent
5190 * and needs to get FID from LMA when readdir, it will not affect the
5191 * performance much. */
5192 if ((bh == NULL) || (le32_to_cpu(de->inode) != ent->oied_ino) ||
5193 (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
5194 *attr |= LUDA_IGNORE;
5195 GOTO(out_journal, rc = 0);
5198 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
5199 inode = osd_iget(info, dev, id);
5200 if (IS_ERR(inode)) {
5201 rc = PTR_ERR(inode);
5202 if (rc == -ENOENT || rc == -ESTALE)
5205 CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
5206 "check_repair, dir = %lu/%u, name = %.*s: "
5208 devname, dir->i_ino, dir->i_generation,
5209 ent->oied_namelen, ent->oied_name, rc);
5211 GOTO(out_journal, rc);
5214 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
5216 LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI));
5218 if (fid_is_sane(fid)) {
5219 /* FID-in-dirent is valid. */
5220 if (lu_fid_eq(fid, &lma->lma_self_fid))
5221 GOTO(out_inode, rc = 0);
5223 /* Do not repair under dryrun mode. */
5224 if (*attr & LUDA_VERIFY_DRYRUN) {
5225 *attr |= LUDA_REPAIR;
5226 GOTO(out_inode, rc = 0);
5229 if (dev->od_dirent_journal == 0) {
5233 ldiskfs_htree_unlock(hlock);
5235 up_read(&obj->oo_ext_idx_sem);
5236 dev->od_dirent_journal = 1;
5240 *fid = lma->lma_self_fid;
5242 /* Update the FID-in-dirent. */
5243 rc = osd_dirent_update(jh, sb, ent, fid, bh, de);
5245 *attr |= LUDA_REPAIR;
5247 CDEBUG(D_LFSCK, "%.16s: fail to update FID "
5248 "in the dirent, dir = %lu/%u, "
5249 "name = %.*s, "DFID": rc = %d\n",
5250 devname, dir->i_ino, dir->i_generation,
5251 ent->oied_namelen, ent->oied_name,
5254 /* Do not repair under dryrun mode. */
5255 if (*attr & LUDA_VERIFY_DRYRUN) {
5256 *fid = lma->lma_self_fid;
5257 *attr |= LUDA_REPAIR;
5258 GOTO(out_inode, rc = 0);
5261 if (dev->od_dirent_journal == 0) {
5265 ldiskfs_htree_unlock(hlock);
5267 up_read(&obj->oo_ext_idx_sem);
5268 dev->od_dirent_journal = 1;
5272 *fid = lma->lma_self_fid;
5274 /* Append the FID-in-dirent. */
5275 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5276 fid, bh, de, hlock);
5278 *attr |= LUDA_REPAIR;
5280 CDEBUG(D_LFSCK, "%.16s: fail to append FID "
5281 "after the dirent, dir = %lu/%u, "
5282 "name = %.*s, "DFID": rc = %d\n",
5283 devname, dir->i_ino, dir->i_generation,
5284 ent->oied_namelen, ent->oied_name,
5287 } else if (rc == -ENODATA) {
5288 /* Do not repair under dryrun mode. */
5289 if (*attr & LUDA_VERIFY_DRYRUN) {
5290 if (fid_is_sane(fid)) {
5291 *attr |= LUDA_REPAIR;
5293 lu_igif_build(fid, inode->i_ino,
5294 inode->i_generation);
5295 *attr |= LUDA_UPGRADE;
5297 GOTO(out_inode, rc = 0);
5300 if (dev->od_dirent_journal == 0) {
5304 ldiskfs_htree_unlock(hlock);
5306 up_read(&obj->oo_ext_idx_sem);
5307 dev->od_dirent_journal = 1;
5312 if (unlikely(fid_is_sane(fid))) {
5313 /* FID-in-dirent exists, but FID-in-LMA is lost.
5314 * Trust the FID-in-dirent, and add FID-in-LMA. */
5315 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
5317 *attr |= LUDA_REPAIR;
5319 CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
5320 "update dirent, dir = %lu/%u, "
5321 "name = %.*s, "DFID": rc = %d\n",
5322 devname, dir->i_ino, dir->i_generation,
5323 ent->oied_namelen, ent->oied_name,
5326 lu_igif_build(fid, inode->i_ino, inode->i_generation);
5327 /* It is probably IGIF object. Only aappend the
5328 * FID-in-dirent. OI scrub will process FID-in-LMA. */
5329 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5330 fid, bh, de, hlock);
5332 *attr |= LUDA_UPGRADE;
5334 CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
5335 "after the dirent, dir = %lu/%u, "
5336 "name = %.*s, "DFID": rc = %d\n",
5337 devname, dir->i_ino, dir->i_generation,
5338 ent->oied_namelen, ent->oied_name,
5343 GOTO(out_inode, rc);
5350 if (hlock != NULL) {
5351 ldiskfs_htree_unlock(hlock);
5353 if (dev->od_dirent_journal != 0)
5354 up_write(&obj->oo_ext_idx_sem);
5356 up_read(&obj->oo_ext_idx_sem);
5359 ldiskfs_journal_stop(jh);
5360 if (rc >= 0 && !dirty)
5361 dev->od_dirent_journal = 0;
5366 * Returns the value at current position from iterator's in memory structure.
5368 * \param di struct osd_it_ea, iterator's in memory structure
5369 * \param attr attr requested for dirent.
5370 * \param lde lustre dirent
5372 * \retval 0 no error and \param lde has correct lustre dirent.
5373 * \retval -ve on error
5375 static inline int osd_it_ea_rec(const struct lu_env *env,
5376 const struct dt_it *di,
5377 struct dt_rec *dtrec, __u32 attr)
5379 struct osd_it_ea *it = (struct osd_it_ea *)di;
5380 struct osd_object *obj = it->oie_obj;
5381 struct osd_device *dev = osd_obj2dev(obj);
5382 struct osd_thread_info *oti = osd_oti_get(env);
5383 struct osd_inode_id *id = &oti->oti_id;
5384 struct lu_fid *fid = &it->oie_dirent->oied_fid;
5385 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5386 __u32 ino = it->oie_dirent->oied_ino;
5390 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
5392 if (attr & LUDA_VERIFY) {
5393 if (unlikely(ino == osd_remote_parent_ino(dev))) {
5394 attr |= LUDA_IGNORE;
5395 /* If the parent is on remote MDT, and there
5396 * is no FID-in-dirent, then we have to get
5397 * the parent FID from the linkEA. */
5398 if (!fid_is_sane(fid) &&
5399 it->oie_dirent->oied_namelen == 2 &&
5400 it->oie_dirent->oied_name[0] == '.' &&
5401 it->oie_dirent->oied_name[1] == '.')
5402 osd_get_pfid_from_linkea(env, obj, fid);
5404 rc = osd_dirent_check_repair(env, obj, it, fid, id,
5408 attr &= ~LU_DIRENT_ATTRS_MASK;
5409 if (!fid_is_sane(fid)) {
5410 if (it->oie_dirent->oied_namelen == 2 &&
5411 it->oie_dirent->oied_name[0] == '.' &&
5412 it->oie_dirent->oied_name[1] == '.') {
5413 /* If the parent is on remote MDT, and there
5414 * is no FID-in-dirent, then we have to get
5415 * the parent FID from the linkEA. */
5416 if (ino == osd_remote_parent_ino(dev))
5417 rc = osd_get_pfid_from_linkea(env, obj,
5420 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
5423 rc = osd_ea_fid_get(env, obj, ino, fid, id);
5426 osd_id_gen(id, ino, OSD_OII_NOGEN);
5430 /* Pack the entry anyway, at least the offset is right. */
5431 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
5432 it->oie_dirent->oied_name,
5433 it->oie_dirent->oied_namelen,
5434 it->oie_dirent->oied_type, attr);
5439 if (osd_remote_fid(env, dev, fid))
5442 if (likely(!(attr & LUDA_IGNORE) && rc == 0))
5443 osd_add_oi_cache(oti, dev, id, fid);
5445 RETURN(rc > 0 ? 0 : rc);
5449 * Returns the record size size at current position.
5451 * This function will return record(lu_dirent) size in bytes.
5453 * \param[in] env execution environment
5454 * \param[in] di iterator's in memory structure
5455 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
5456 * calculate the lu_dirent size.
5458 * \retval record size(in bytes & in memory) of the current lu_dirent
5461 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
5464 struct osd_it_ea *it = (struct osd_it_ea *)di;
5466 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
5470 * Returns a cookie for current position of the iterator head, so that
5471 * user can use this cookie to load/start the iterator next time.
5473 * \param di iterator's in memory structure
5475 * \retval cookie for current position, on success
5477 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
5479 struct osd_it_ea *it = (struct osd_it_ea *)di;
5481 return it->oie_dirent->oied_off;
5485 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
5486 * to load a directory entry at a time and stored it i inn,
5487 * in iterator's in-memory data structure.
5489 * \param di struct osd_it_ea, iterator's in memory structure
5491 * \retval +ve on success
5492 * \retval -ve on error
5494 static int osd_it_ea_load(const struct lu_env *env,
5495 const struct dt_it *di, __u64 hash)
5497 struct osd_it_ea *it = (struct osd_it_ea *)di;
5501 it->oie_file.f_pos = hash;
5503 rc = osd_ldiskfs_it_fill(env, di);
5514 * Index lookup function for interoperability mode (b11826).
5516 * \param key, key i.e. file name to be searched
5518 * \retval +ve, on success
5519 * \retval -ve, on error
5521 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
5522 struct dt_rec *rec, const struct dt_key *key)
5524 struct osd_object *obj = osd_dt_obj(dt);
5529 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
5530 LINVRNT(osd_invariant(obj));
5532 rc = osd_ea_lookup_rec(env, obj, rec, key);
5539 * Index and Iterator operations for interoperability
5540 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
5542 static const struct dt_index_operations osd_index_ea_ops = {
5543 .dio_lookup = osd_index_ea_lookup,
5544 .dio_declare_insert = osd_index_declare_ea_insert,
5545 .dio_insert = osd_index_ea_insert,
5546 .dio_declare_delete = osd_index_declare_ea_delete,
5547 .dio_delete = osd_index_ea_delete,
5549 .init = osd_it_ea_init,
5550 .fini = osd_it_ea_fini,
5551 .get = osd_it_ea_get,
5552 .put = osd_it_ea_put,
5553 .next = osd_it_ea_next,
5554 .key = osd_it_ea_key,
5555 .key_size = osd_it_ea_key_size,
5556 .rec = osd_it_ea_rec,
5557 .rec_size = osd_it_ea_rec_size,
5558 .store = osd_it_ea_store,
5559 .load = osd_it_ea_load
5563 static void *osd_key_init(const struct lu_context *ctx,
5564 struct lu_context_key *key)
5566 struct osd_thread_info *info;
5568 OBD_ALLOC_PTR(info);
5570 return ERR_PTR(-ENOMEM);
5572 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5573 if (info->oti_it_ea_buf == NULL)
5576 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
5578 info->oti_hlock = ldiskfs_htree_lock_alloc();
5579 if (info->oti_hlock == NULL)
5585 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5588 return ERR_PTR(-ENOMEM);
5591 static void osd_key_fini(const struct lu_context *ctx,
5592 struct lu_context_key *key, void* data)
5594 struct osd_thread_info *info = data;
5596 if (info->oti_inode != NULL)
5597 OBD_FREE_PTR(info->oti_inode);
5598 if (info->oti_hlock != NULL)
5599 ldiskfs_htree_lock_free(info->oti_hlock);
5600 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5601 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
5602 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
5603 lu_buf_free(&info->oti_big_buf);
5607 static void osd_key_exit(const struct lu_context *ctx,
5608 struct lu_context_key *key, void *data)
5610 struct osd_thread_info *info = data;
5612 LASSERT(info->oti_r_locks == 0);
5613 LASSERT(info->oti_w_locks == 0);
5614 LASSERT(info->oti_txns == 0);
5617 /* type constructor/destructor: osd_type_init, osd_type_fini */
5618 LU_TYPE_INIT_FINI(osd, &osd_key);
5620 struct lu_context_key osd_key = {
5621 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
5622 .lct_init = osd_key_init,
5623 .lct_fini = osd_key_fini,
5624 .lct_exit = osd_key_exit
5628 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
5629 const char *name, struct lu_device *next)
5631 struct osd_device *osd = osd_dev(d);
5633 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
5634 >= sizeof(osd->od_svname))
5636 return osd_procfs_init(osd, name);
5639 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
5641 struct seq_server_site *ss = osd_seq_site(osd);
5645 if (osd->od_is_ost || osd->od_cl_seq != NULL)
5648 if (unlikely(ss == NULL))
5651 OBD_ALLOC_PTR(osd->od_cl_seq);
5652 if (osd->od_cl_seq == NULL)
5655 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
5656 osd->od_svname, ss->ss_server_seq);
5659 OBD_FREE_PTR(osd->od_cl_seq);
5660 osd->od_cl_seq = NULL;
5666 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
5668 if (osd->od_cl_seq == NULL)
5671 seq_client_fini(osd->od_cl_seq);
5672 OBD_FREE_PTR(osd->od_cl_seq);
5673 osd->od_cl_seq = NULL;
5676 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
5680 /* shutdown quota slave instance associated with the device */
5681 if (o->od_quota_slave != NULL) {
5682 qsd_fini(env, o->od_quota_slave);
5683 o->od_quota_slave = NULL;
5686 osd_fid_fini(env, o);
5691 static void osd_umount(const struct lu_env *env, struct osd_device *o)
5695 if (o->od_mnt != NULL) {
5696 shrink_dcache_sb(osd_sb(o));
5697 osd_sync(env, &o->od_dt_dev);
5706 static int osd_mount(const struct lu_env *env,
5707 struct osd_device *o, struct lustre_cfg *cfg)
5709 const char *name = lustre_cfg_string(cfg, 0);
5710 const char *dev = lustre_cfg_string(cfg, 1);
5712 unsigned long page, s_flags, lmd_flags = 0;
5713 struct page *__page;
5714 struct file_system_type *type;
5715 char *options = NULL;
5717 struct osd_thread_info *info = osd_oti_get(env);
5718 struct lu_fid *fid = &info->oti_fid;
5719 struct inode *inode;
5720 int rc = 0, force_over_128tb = 0;
5723 if (o->od_mnt != NULL)
5726 if (strlen(dev) >= sizeof(o->od_mntdev))
5728 strcpy(o->od_mntdev, dev);
5730 str = lustre_cfg_string(cfg, 2);
5731 s_flags = simple_strtoul(str, NULL, 0);
5732 str = strstr(str, ":");
5734 lmd_flags = simple_strtoul(str + 1, NULL, 0);
5735 opts = lustre_cfg_string(cfg, 3);
5737 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
5738 CERROR("%s: device %s extents feature is not guaranteed to "
5739 "work on big-endian systems. Use \"bigendian_extents\" "
5740 "mount option to override.\n", name, dev);
5744 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
5745 force_over_128tb = 1;
5747 OBD_PAGE_ALLOC(__page, GFP_IOFS);
5749 GOTO(out, rc = -ENOMEM);
5750 page = (unsigned long)page_address(__page);
5751 options = (char *)page;
5754 /* strip out the options for back compatiblity */
5755 static char *sout[] = {
5762 /* strip out option we processed in osd */
5763 "bigendian_extents",
5767 strcat(options, opts);
5768 for (rc = 0, str = options; sout[rc]; ) {
5769 char *op = strstr(str, sout[rc]);
5775 if (op == options || *(op - 1) == ',') {
5776 str = op + strlen(sout[rc]);
5777 if (*str == ',' || *str == '\0') {
5778 *str == ',' ? str++ : str;
5779 memmove(op, str, strlen(str) + 1);
5782 for (str = op; *str != ',' && *str != '\0'; str++)
5786 strncat(options, "user_xattr,acl", 14);
5789 /* Glom up mount options */
5790 if (*options != '\0')
5791 strcat(options, ",");
5792 strlcat(options, "no_mbcache", PAGE_CACHE_SIZE);
5794 type = get_fs_type("ldiskfs");
5796 CERROR("%s: cannot find ldiskfs module\n", name);
5797 GOTO(out, rc = -ENODEV);
5800 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
5801 module_put(type->owner);
5803 if (IS_ERR(o->od_mnt)) {
5804 rc = PTR_ERR(o->od_mnt);
5806 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
5810 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (8ULL << 32) &&
5811 force_over_128tb == 0) {
5812 CERROR("%s: device %s LDISKFS does not support filesystems "
5813 "greater than 128TB and can cause data corruption. "
5814 "Use \"force_over_128tb\" mount option to override.\n",
5816 GOTO(out, rc = -EINVAL);
5819 #ifdef HAVE_DEV_SET_RDONLY
5820 if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
5821 CERROR("%s: underlying device %s is marked as read-only. "
5822 "Setup failed\n", name, dev);
5823 GOTO(out_mnt, rc = -EROFS);
5827 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
5828 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
5829 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
5830 GOTO(out_mnt, rc = -EINVAL);
5833 #ifdef LDISKFS_MOUNT_DIRDATA
5834 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
5835 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5836 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
5837 else if (!o->od_is_ost)
5838 CWARN("%s: device %s was upgraded from Lustre-1.x without "
5839 "enabling the dirdata feature. If you do not want to "
5840 "downgrade to Lustre-1.x again, you can enable it via "
5841 "'tune2fs -O dirdata device'\n", name, dev);
5843 inode = osd_sb(o)->s_root->d_inode;
5844 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
5845 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
5847 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
5851 if (lmd_flags & LMD_FLG_NOSCRUB)
5862 OBD_PAGE_FREE(__page);
5867 static struct lu_device *osd_device_fini(const struct lu_env *env,
5868 struct lu_device *d)
5870 struct osd_device *o = osd_dev(d);
5873 osd_shutdown(env, o);
5875 osd_scrub_cleanup(env, o);
5876 osd_obj_map_fini(o);
5882 static int osd_device_init0(const struct lu_env *env,
5883 struct osd_device *o,
5884 struct lustre_cfg *cfg)
5886 struct lu_device *l = osd2lu_dev(o);
5887 struct osd_thread_info *info;
5891 /* if the module was re-loaded, env can loose its keys */
5892 rc = lu_env_refill((struct lu_env *) env);
5895 info = osd_oti_get(env);
5898 l->ld_ops = &osd_lu_ops;
5899 o->od_dt_dev.dd_ops = &osd_dt_ops;
5901 spin_lock_init(&o->od_osfs_lock);
5902 mutex_init(&o->od_otable_mutex);
5904 o->od_read_cache = 1;
5905 o->od_writethrough_cache = 1;
5906 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
5908 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
5909 sizeof(o->od_svname));
5910 if (cplen >= sizeof(o->od_svname)) {
5915 if (server_name_is_ost(o->od_svname))
5918 o->od_full_scrub_ratio = OFSR_DEFAULT;
5919 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
5920 rc = osd_mount(env, o, cfg);
5924 rc = osd_obj_map_init(env, o);
5928 rc = lu_site_init(&o->od_site, l);
5930 GOTO(out_compat, rc);
5931 o->od_site.ls_bottom_dev = l;
5933 rc = lu_site_init_finish(&o->od_site);
5937 INIT_LIST_HEAD(&o->od_ios_list);
5938 /* setup scrub, including OI files initialization */
5939 rc = osd_scrub_setup(env, o);
5943 rc = osd_procfs_init(o, o->od_svname);
5945 CERROR("%s: can't initialize procfs: rc = %d\n",
5947 GOTO(out_scrub, rc);
5950 LASSERT(l->ld_site->ls_linkage.next != NULL);
5951 LASSERT(l->ld_site->ls_linkage.prev != NULL);
5953 /* initialize quota slave instance */
5954 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
5956 if (IS_ERR(o->od_quota_slave)) {
5957 rc = PTR_ERR(o->od_quota_slave);
5958 o->od_quota_slave = NULL;
5959 GOTO(out_procfs, rc);
5967 osd_scrub_cleanup(env, o);
5969 lu_site_fini(&o->od_site);
5971 osd_obj_map_fini(o);
5978 static struct lu_device *osd_device_alloc(const struct lu_env *env,
5979 struct lu_device_type *t,
5980 struct lustre_cfg *cfg)
5982 struct osd_device *o;
5987 return ERR_PTR(-ENOMEM);
5989 rc = dt_device_init(&o->od_dt_dev, t);
5991 /* Because the ctx might be revived in dt_device_init,
5992 * refill the env here */
5993 lu_env_refill((struct lu_env *)env);
5994 rc = osd_device_init0(env, o, cfg);
5996 dt_device_fini(&o->od_dt_dev);
5999 if (unlikely(rc != 0))
6002 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
6005 static struct lu_device *osd_device_free(const struct lu_env *env,
6006 struct lu_device *d)
6008 struct osd_device *o = osd_dev(d);
6011 /* XXX: make osd top device in order to release reference */
6012 d->ld_site->ls_top_dev = d;
6013 lu_site_purge(env, d->ld_site, -1);
6014 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
6015 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
6016 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
6018 lu_site_fini(&o->od_site);
6019 dt_device_fini(&o->od_dt_dev);
6024 static int osd_process_config(const struct lu_env *env,
6025 struct lu_device *d, struct lustre_cfg *cfg)
6027 struct osd_device *o = osd_dev(d);
6031 switch (cfg->lcfg_command) {
6033 rc = osd_mount(env, o, cfg);
6036 lu_dev_del_linkage(d->ld_site, d);
6037 rc = osd_shutdown(env, o);
6040 LASSERT(&o->od_dt_dev);
6041 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
6042 cfg, &o->od_dt_dev);
6043 if (rc > 0 || rc == -ENOSYS)
6044 rc = class_process_proc_param(PARAM_OST,
6045 lprocfs_osd_obd_vars,
6046 cfg, &o->od_dt_dev);
6055 static int osd_recovery_complete(const struct lu_env *env,
6056 struct lu_device *d)
6058 struct osd_device *osd = osd_dev(d);
6062 if (osd->od_quota_slave == NULL)
6065 /* start qsd instance on recovery completion, this notifies the quota
6066 * slave code that we are about to process new requests now */
6067 rc = qsd_start(env, osd->od_quota_slave);
6072 * we use exports to track all osd users
6074 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
6075 struct obd_device *obd, struct obd_uuid *cluuid,
6076 struct obd_connect_data *data, void *localdata)
6078 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6079 struct lustre_handle conn;
6083 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
6085 rc = class_connect(&conn, obd, cluuid);
6089 *exp = class_conn2export(&conn);
6091 spin_lock(&osd->od_osfs_lock);
6093 spin_unlock(&osd->od_osfs_lock);
6099 * once last export (we don't count self-export) disappeared
6100 * osd can be released
6102 static int osd_obd_disconnect(struct obd_export *exp)
6104 struct obd_device *obd = exp->exp_obd;
6105 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6106 int rc, release = 0;
6109 /* Only disconnect the underlying layers on the final disconnect. */
6110 spin_lock(&osd->od_osfs_lock);
6112 if (osd->od_connects == 0)
6114 spin_unlock(&osd->od_osfs_lock);
6116 rc = class_disconnect(exp); /* bz 9811 */
6118 if (rc == 0 && release)
6119 class_manual_cleanup(obd);
6123 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
6124 struct lu_device *dev)
6126 struct osd_device *osd = osd_dev(dev);
6127 struct lr_server_data *lsd =
6128 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
6132 if (osd->od_quota_slave != NULL) {
6133 /* set up quota slave objects */
6134 result = qsd_prepare(env, osd->od_quota_slave);
6139 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
6140 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
6141 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
6142 osd->od_index_in_idif = 1;
6144 osd->od_index_in_idif = 0;
6145 result = osd_register_proc_index_in_idif(osd);
6150 osd->od_index_in_idif = 1;
6154 result = osd_fid_init(env, osd);
6159 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
6160 struct lu_fid *fid, struct md_op_data *op_data)
6162 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
6164 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
6167 static const struct lu_object_operations osd_lu_obj_ops = {
6168 .loo_object_init = osd_object_init,
6169 .loo_object_delete = osd_object_delete,
6170 .loo_object_release = osd_object_release,
6171 .loo_object_free = osd_object_free,
6172 .loo_object_print = osd_object_print,
6173 .loo_object_invariant = osd_object_invariant
6176 const struct lu_device_operations osd_lu_ops = {
6177 .ldo_object_alloc = osd_object_alloc,
6178 .ldo_process_config = osd_process_config,
6179 .ldo_recovery_complete = osd_recovery_complete,
6180 .ldo_prepare = osd_prepare,
6183 static const struct lu_device_type_operations osd_device_type_ops = {
6184 .ldto_init = osd_type_init,
6185 .ldto_fini = osd_type_fini,
6187 .ldto_start = osd_type_start,
6188 .ldto_stop = osd_type_stop,
6190 .ldto_device_alloc = osd_device_alloc,
6191 .ldto_device_free = osd_device_free,
6193 .ldto_device_init = osd_device_init,
6194 .ldto_device_fini = osd_device_fini
6197 static struct lu_device_type osd_device_type = {
6198 .ldt_tags = LU_DEVICE_DT,
6199 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
6200 .ldt_ops = &osd_device_type_ops,
6201 .ldt_ctx_tags = LCT_LOCAL,
6204 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
6206 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6207 struct super_block *sb = osd_sb(osd);
6209 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
6213 * lprocfs legacy support.
6215 static struct obd_ops osd_obd_device_ops = {
6216 .o_owner = THIS_MODULE,
6217 .o_connect = osd_obd_connect,
6218 .o_disconnect = osd_obd_disconnect,
6219 .o_fid_alloc = osd_fid_alloc,
6220 .o_health_check = osd_health_check,
6223 static int __init osd_mod_init(void)
6227 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
6228 /* please, try to keep osd_thread_info smaller than a page */
6229 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
6234 rc = lu_kmem_init(ldiskfs_caches);
6238 rc = class_register_type(&osd_obd_device_ops, NULL, true,
6239 lprocfs_osd_module_vars,
6240 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
6242 lu_kmem_fini(ldiskfs_caches);
6246 static void __exit osd_mod_exit(void)
6248 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
6249 lu_kmem_fini(ldiskfs_caches);
6252 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6253 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
6254 MODULE_LICENSE("GPL");
6256 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);