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>
47 #include <linux/user_namespace.h>
48 #ifdef HAVE_UIDGID_HEADER
49 # include <linux/uidgid.h>
52 /* LUSTRE_VERSION_CODE */
53 #include <lustre_ver.h>
54 /* prerequisite for linux/xattr.h */
55 #include <linux/types.h>
56 /* prerequisite for linux/xattr.h */
58 /* XATTR_{REPLACE,CREATE} */
59 #include <linux/xattr.h>
61 #include <ldiskfs/ldiskfs.h>
62 #include <ldiskfs/xattr.h>
65 * struct OBD_{ALLOC,FREE}*()
68 #include <obd_support.h>
69 /* struct ptlrpc_thread */
70 #include <lustre_net.h>
71 #include <lustre_fid.h>
73 #include <lustre_param.h>
75 #include "osd_internal.h"
76 #include "osd_dynlocks.h"
78 /* llo_* api support */
79 #include <md_object.h>
80 #include <lustre_quota.h>
82 #include <lustre_linkea.h>
85 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
86 "ldiskfs with parallel directory operations");
88 int ldiskfs_track_declares_assert;
89 CFS_MODULE_PARM(ldiskfs_track_declares_assert, "i", int, 0644,
90 "LBUG during tracking of declares");
92 /* Slab to allocate dynlocks */
93 struct kmem_cache *dynlock_cachep;
95 /* Slab to allocate osd_it_ea */
96 struct kmem_cache *osd_itea_cachep;
98 static struct lu_kmem_descr ldiskfs_caches[] = {
100 .ckd_cache = &dynlock_cachep,
101 .ckd_name = "dynlock_cache",
102 .ckd_size = sizeof(struct dynlock_handle)
105 .ckd_cache = &osd_itea_cachep,
106 .ckd_name = "osd_itea_cache",
107 .ckd_size = sizeof(struct osd_it_ea)
114 static const char dot[] = ".";
115 static const char dotdot[] = "..";
116 static const char remote_obj_dir[] = "REM_OBJ_DIR";
118 static const struct lu_object_operations osd_lu_obj_ops;
119 static const struct dt_object_operations osd_obj_ops;
120 static const struct dt_object_operations osd_obj_ea_ops;
121 static const struct dt_object_operations osd_obj_otable_it_ops;
122 static const struct dt_index_operations osd_index_iam_ops;
123 static const struct dt_index_operations osd_index_ea_ops;
125 int osd_trans_declare_op2rb[] = {
126 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
127 [OSD_OT_PUNCH] = OSD_OT_MAX,
128 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
129 [OSD_OT_CREATE] = OSD_OT_DESTROY,
130 [OSD_OT_DESTROY] = OSD_OT_CREATE,
131 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
132 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
133 [OSD_OT_WRITE] = OSD_OT_WRITE,
134 [OSD_OT_INSERT] = OSD_OT_DELETE,
135 [OSD_OT_DELETE] = OSD_OT_INSERT,
136 [OSD_OT_QUOTA] = OSD_OT_MAX,
139 static int osd_has_index(const struct osd_object *obj)
141 return obj->oo_dt.do_index_ops != NULL;
144 static int osd_object_invariant(const struct lu_object *l)
146 return osd_invariant(osd_obj(l));
150 * Concurrency: doesn't matter
154 * Concurrency: doesn't matter
156 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
158 struct osd_thread_info *oti = osd_oti_get(env);
159 return oti->oti_w_locks > 0 && o->oo_owner == env;
163 * Concurrency: doesn't access mutable data
165 static int osd_root_get(const struct lu_env *env,
166 struct dt_device *dev, struct lu_fid *f)
168 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
173 * OSD object methods.
177 * Concurrency: no concurrent access is possible that early in object
180 static struct lu_object *osd_object_alloc(const struct lu_env *env,
181 const struct lu_object_header *hdr,
184 struct osd_object *mo;
190 l = &mo->oo_dt.do_lu;
191 dt_object_init(&mo->oo_dt, NULL, d);
192 mo->oo_dt.do_ops = &osd_obj_ea_ops;
193 l->lo_ops = &osd_lu_obj_ops;
194 init_rwsem(&mo->oo_sem);
195 init_rwsem(&mo->oo_ext_idx_sem);
196 spin_lock_init(&mo->oo_guard);
203 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
204 struct dentry *dentry, struct lustre_mdt_attrs *lma)
208 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
209 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
210 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
212 if ((void *)lma != (void *)info->oti_mdt_attrs_old)
213 memcpy(lma, info->oti_mdt_attrs_old, sizeof(*lma));
215 lustre_lma_swab(lma);
216 /* Check LMA compatibility */
217 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
218 CWARN("%.16s: unsupported incompat LMA feature(s) %#x "
219 "for fid = "DFID", ino = %lu\n",
220 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
221 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
222 PFID(&lma->lma_self_fid), inode->i_ino);
225 } else if (rc == 0) {
233 * retrieve object from backend ext fs.
235 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
236 struct osd_inode_id *id)
238 struct inode *inode = NULL;
240 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
242 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
243 id->oii_ino, PTR_ERR(inode));
244 } else if (id->oii_gen != OSD_OII_NOGEN &&
245 inode->i_generation != id->oii_gen) {
246 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
247 "i_generation = %u\n",
248 id->oii_ino, id->oii_gen, inode->i_generation);
250 inode = ERR_PTR(-ESTALE);
251 } else if (inode->i_nlink == 0) {
252 /* due to parallel readdir and unlink,
253 * we can have dead inode here. */
254 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
256 inode = ERR_PTR(-ESTALE);
257 } else if (is_bad_inode(inode)) {
258 CWARN("%.16s: bad inode: ino = %u\n",
259 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
261 inode = ERR_PTR(-ENOENT);
263 if (id->oii_gen == OSD_OII_NOGEN)
264 osd_id_gen(id, inode->i_ino, inode->i_generation);
266 /* Do not update file c/mtime in ldiskfs.
267 * NB: we don't have any lock to protect this because we don't
268 * have reference on osd_object now, but contention with
269 * another lookup + attr_set can't happen in the tiny window
270 * between if (...) and set S_NOCMTIME. */
271 if (!(inode->i_flags & S_NOCMTIME))
272 inode->i_flags |= S_NOCMTIME;
277 static struct inode *
278 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
279 struct osd_inode_id *id, struct lu_fid *fid)
281 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
285 inode = osd_iget(info, dev, id);
289 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
291 *fid = lma->lma_self_fid;
292 } else if (rc == -ENODATA) {
293 if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
294 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
296 lu_igif_build(fid, inode->i_ino, inode->i_generation);
304 static struct inode *osd_iget_check(struct osd_thread_info *info,
305 struct osd_device *dev,
306 const struct lu_fid *fid,
307 struct osd_inode_id *id,
314 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
317 if (!in_oi || (rc != -ENOENT && rc != -ESTALE)) {
318 CDEBUG(D_INODE, "no inode: ino = %u, rc = %d\n",
327 if (is_bad_inode(inode)) {
330 CDEBUG(D_INODE, "bad inode: ino = %u\n", id->oii_ino);
338 if (id->oii_gen != OSD_OII_NOGEN &&
339 inode->i_generation != id->oii_gen) {
342 CDEBUG(D_INODE, "unmatched inode: ino = %u, "
343 "oii_gen = %u, i_generation = %u\n",
344 id->oii_ino, id->oii_gen, inode->i_generation);
352 if (inode->i_nlink == 0) {
355 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
365 struct osd_inode_id saved_id = *id;
367 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
369 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
370 /* XXX: There are some possible cases:
372 * Backup/restore caused the OI invalid.
374 * Someone unlinked the object but NOT removed
375 * the OI mapping, such as mount target device
376 * as ldiskfs, and modify something directly.
378 * Someone just removed the object between the
379 * former oi_lookup and the iget. It is normal.
380 * 4. Other failure cases.
382 * Generally, when the device is mounted, it will
383 * auto check whether the system is restored from
384 * file-level backup or not. We trust such detect
385 * to distinguish the 1st case from the 2nd case. */
387 if (!IS_ERR(inode) && inode->i_generation != 0 &&
388 inode->i_generation == id->oii_gen) {
391 __u32 level = D_LFSCK;
394 if (!thread_is_running(&dev->od_scrub.os_thread))
397 CDEBUG(level, "%s: the OI mapping for the FID "
398 DFID" become inconsistent, the given ID "
399 "%u/%u, the ID in OI mapping %u/%u\n",
400 osd_name(dev), PFID(fid),
401 saved_id.oii_ino, saved_id.oii_gen,
402 id->oii_ino, id->oii_ino);
406 if (id->oii_gen == OSD_OII_NOGEN)
407 osd_id_gen(id, inode->i_ino, inode->i_generation);
409 /* Do not update file c/mtime in ldiskfs.
410 * NB: we don't have any lock to protect this because we don't
411 * have reference on osd_object now, but contention with
412 * another lookup + attr_set can't happen in the tiny window
413 * between if (...) and set S_NOCMTIME. */
414 if (!(inode->i_flags & S_NOCMTIME))
415 inode->i_flags |= S_NOCMTIME;
432 * \retval +v: new filter_fid, does not contain self-fid
433 * \retval 0: filter_fid_old, contains self-fid
434 * \retval -v: other failure cases
436 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
437 struct dentry *dentry, struct lu_fid *fid)
439 struct filter_fid_old *ff = &info->oti_ff;
440 struct ost_id *ostid = &info->oti_ostid;
443 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
444 if (rc == sizeof(*ff)) {
446 ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
447 ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
448 /* XXX: should use real OST index in the future. LU-3569 */
449 ostid_to_fid(fid, ostid, 0);
450 } else if (rc == sizeof(struct filter_fid)) {
452 } else if (rc >= 0) {
459 static int osd_lma_self_repair(struct osd_thread_info *info,
460 struct osd_device *osd, struct inode *inode,
461 const struct lu_fid *fid, __u32 compat)
466 LASSERT(current->journal_info == NULL);
468 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
469 osd_dto_credits_noquota[DTO_XATTR_SET]);
472 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
477 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
479 CWARN("%s: cannot self repair the LMA: rc = %d\n",
481 ldiskfs_journal_stop(jh);
485 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
487 struct osd_thread_info *info = osd_oti_get(env);
488 struct osd_device *osd = osd_obj2dev(obj);
489 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
490 struct inode *inode = obj->oo_inode;
491 struct dentry *dentry = &info->oti_obj_dentry;
492 struct lu_fid *fid = NULL;
493 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
497 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
498 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
499 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
500 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
501 fid = &lma->lma_self_fid;
502 rc = osd_get_idif(info, inode, dentry, fid);
503 if ((rc > 0) || (rc == -ENODATA && osd->od_index_in_idif)) {
504 /* For the given OST-object, if it has neither LMA nor
505 * FID in XATTR_NAME_FID, then the given FID (which is
506 * contained in the @obj, from client RPC for locating
507 * the OST-object) is trusted. We use it to generate
509 osd_lma_self_repair(info, osd, inode, rfid,
515 if (unlikely(rc == -ENODATA))
523 lustre_lma_swab(lma);
524 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
525 CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
526 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
527 "fid = "DFID", ino = %lu\n", osd_name(osd),
528 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
529 PFID(rfid), inode->i_ino);
532 fid = &lma->lma_self_fid;
536 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
537 __u32 level = D_LFSCK;
539 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
540 struct ost_id *oi = &info->oti_ostid;
541 struct lu_fid *fid1 = &info->oti_fid3;
542 __u32 idx = fid_idif_ost_idx(rfid);
544 /* For old IDIF, the OST index is not part of the IDIF,
545 * Means that different OSTs may have the same IDIFs.
546 * Under such case, we need to make some compatible
547 * check to make sure to trigger OI scrub properly. */
548 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
549 /* Given @rfid is new, LMA is old. */
550 fid_to_ostid(fid, oi);
551 ostid_to_fid(fid1, oi, idx);
552 if (lu_fid_eq(fid1, rfid)) {
553 if (osd->od_index_in_idif)
554 osd_lma_self_repair(info, osd,
564 if (!thread_is_running(&osd->od_scrub.os_thread))
567 CDEBUG(level, "%s: FID "DFID" != self_fid "DFID"\n",
568 osd_name(osd), PFID(rfid), PFID(fid));
574 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
575 const struct lu_fid *fid,
576 const struct lu_object_conf *conf)
578 struct osd_thread_info *info;
579 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
580 struct osd_device *dev;
581 struct osd_idmap_cache *oic;
582 struct osd_inode_id *id;
584 struct osd_scrub *scrub;
585 struct scrub_file *sf;
589 bool triggered = false;
592 LINVRNT(osd_invariant(obj));
593 LASSERT(obj->oo_inode == NULL);
594 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
597 scrub = &dev->od_scrub;
598 sf = &scrub->os_file;
599 info = osd_oti_get(env);
601 oic = &info->oti_cache;
603 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
606 /* For the object is created as locking anchor, or for the object to
607 * be created on disk. No need to osd_oi_lookup() at here because FID
608 * shouldn't never be re-used, if it's really a duplicate FID from
609 * unexpected reason, we should be able to detect it later by calling
610 * do_create->osd_oi_insert(). */
611 if (conf != NULL && conf->loc_flags & LOC_F_NEW)
612 GOTO(out, result = 0);
614 /* Search order: 1. per-thread cache. */
615 if (lu_fid_eq(fid, &oic->oic_fid) &&
616 likely(oic->oic_dev == dev)) {
622 if (!list_empty(&scrub->os_inconsistent_items)) {
623 /* Search order: 2. OI scrub pending list. */
624 result = osd_oii_lookup(dev, fid, id);
629 /* Search order: 3. OI files. */
630 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
631 if (result == -ENOENT) {
632 if (!fid_is_norm(fid) ||
633 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
634 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
636 GOTO(out, result = 0);
647 inode = osd_iget_check(info, dev, fid, id, in_oi);
649 result = PTR_ERR(inode);
650 if (result == -ENOENT || result == -ESTALE) {
652 fid_zero(&oic->oic_fid);
654 GOTO(out, result = -ENOENT);
655 } else if (result == -EREMCHG) {
659 fid_zero(&oic->oic_fid);
661 if (unlikely(triggered))
662 GOTO(out, result = saved);
665 if (thread_is_running(&scrub->os_thread)) {
666 result = -EINPROGRESS;
667 } else if (!dev->od_noscrub) {
668 /* Since we do not know the right OI mapping,
669 * we have to trigger OI scrub to scan the
671 result = osd_scrub_start(dev, SS_AUTO_FULL |
672 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
673 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI "
674 "scrub by RPC for "DFID", rc = %d [1]\n",
675 osd_name(dev), PFID(fid),result);
676 if (result == 0 || result == -EALREADY)
677 result = -EINPROGRESS;
682 /* We still have chance to get the valid inode: for the
683 * object which is referenced by remote name entry, the
684 * object on the local MDT will be linked under the dir
685 * of "/REMOTE_PARENT_DIR" with its FID string as name.
687 * We do not know whether the object for the given FID
688 * is referenced by some remote name entry or not, and
689 * especially for DNE II, a multiple-linked object may
690 * have many name entries reside on many MDTs.
692 * To simplify the operation, OSD will not distinguish
693 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
694 * only happened for the RPC from other MDT during the
695 * OI scrub, or for the client side RPC with FID only,
696 * such as FID to path, or from old connected client. */
698 result = osd_lookup_in_remote_parent(info, dev,
711 obj->oo_inode = inode;
712 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
714 result = osd_check_lma(env, obj);
717 obj->oo_inode = NULL;
718 if (result == -EREMCHG) {
720 result = osd_oi_lookup(info, dev, fid, id,
723 fid_zero(&oic->oic_fid);
734 obj->oo_compat_dot_created = 1;
735 obj->oo_compat_dotdot_created = 1;
737 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
738 GOTO(out, result = 0);
740 LASSERT(obj->oo_hl_head == NULL);
741 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
742 if (obj->oo_hl_head == NULL) {
743 obj->oo_inode = NULL;
745 GOTO(out, result = -ENOMEM);
747 GOTO(out, result = 0);
750 LINVRNT(osd_invariant(obj));
755 * Concurrency: shouldn't matter.
757 static void osd_object_init0(struct osd_object *obj)
759 LASSERT(obj->oo_inode != NULL);
760 obj->oo_dt.do_body_ops = &osd_body_ops;
761 obj->oo_dt.do_lu.lo_header->loh_attr |=
762 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
766 * Concurrency: no concurrent access is possible that early in object
769 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
770 const struct lu_object_conf *conf)
772 struct osd_object *obj = osd_obj(l);
775 LINVRNT(osd_invariant(obj));
777 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
778 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
779 l->lo_header->loh_attr |= LOHA_EXISTS;
783 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
784 obj->oo_dt.do_body_ops = &osd_body_ops_new;
785 if (result == 0 && obj->oo_inode != NULL)
786 osd_object_init0(obj);
788 LINVRNT(osd_invariant(obj));
793 * Concurrency: no concurrent access is possible that late in object
796 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
798 struct osd_object *obj = osd_obj(l);
800 LINVRNT(osd_invariant(obj));
802 dt_object_fini(&obj->oo_dt);
803 if (obj->oo_hl_head != NULL)
804 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
809 * Concurrency: no concurrent access is possible that late in object
812 static void osd_index_fini(struct osd_object *o)
814 struct iam_container *bag;
816 if (o->oo_dir != NULL) {
817 bag = &o->oo_dir->od_container;
818 if (o->oo_inode != NULL) {
819 if (bag->ic_object == o->oo_inode)
820 iam_container_fini(bag);
822 OBD_FREE_PTR(o->oo_dir);
828 * Concurrency: no concurrent access is possible that late in object
829 * life-cycle (for all existing callers, that is. New callers have to provide
830 * their own locking.)
832 static int osd_inode_unlinked(const struct inode *inode)
834 return inode->i_nlink == 0;
838 OSD_TXN_OI_DELETE_CREDITS = 20,
839 OSD_TXN_INODE_DELETE_CREDITS = 20
846 #if OSD_THANDLE_STATS
848 * Set time when the handle is allocated
850 static void osd_th_alloced(struct osd_thandle *oth)
852 oth->oth_alloced = cfs_time_current();
856 * Set time when the handle started
858 static void osd_th_started(struct osd_thandle *oth)
860 oth->oth_started = cfs_time_current();
864 * Helper function to convert time interval to microseconds packed in
867 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
871 cfs_duration_usec(cfs_time_sub(end, start), &val);
872 return val.tv_sec * 1000000 + val.tv_usec;
876 * Check whether the we deal with this handle for too long.
878 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
879 cfs_time_t alloced, cfs_time_t started,
882 cfs_time_t now = cfs_time_current();
884 LASSERT(dev != NULL);
886 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
887 interval_to_usec(alloced, started));
888 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
889 interval_to_usec(started, closed));
890 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
891 interval_to_usec(closed, now));
893 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
894 CWARN("transaction handle %p was open for too long: "
896 "alloced "CFS_TIME_T" ,"
897 "started "CFS_TIME_T" ,"
898 "closed "CFS_TIME_T"\n",
899 oth, now, alloced, started, closed);
900 libcfs_debug_dumpstack(NULL);
904 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
906 cfs_time_t __closed = cfs_time_current(); \
907 cfs_time_t __alloced = oth->oth_alloced; \
908 cfs_time_t __started = oth->oth_started; \
911 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
914 #else /* OSD_THANDLE_STATS */
916 #define osd_th_alloced(h) do {} while(0)
917 #define osd_th_started(h) do {} while(0)
918 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
920 #endif /* OSD_THANDLE_STATS */
923 * Concurrency: doesn't access mutable data.
925 static int osd_param_is_not_sane(const struct osd_device *dev,
926 const struct thandle *th)
928 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
930 return oh->ot_credits > osd_transaction_size(dev);
934 * Concurrency: shouldn't matter.
936 static void osd_trans_commit_cb(struct super_block *sb,
937 struct ldiskfs_journal_cb_entry *jcb, int error)
939 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
940 struct thandle *th = &oh->ot_super;
941 struct lu_device *lud = &th->th_dev->dd_lu_dev;
942 struct dt_txn_commit_cb *dcb, *tmp;
944 LASSERT(oh->ot_handle == NULL);
947 CERROR("transaction @0x%p commit error: %d\n", th, error);
949 dt_txn_hook_commit(th);
951 /* call per-transaction callbacks if any */
952 list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
953 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
954 "commit callback entry: magic=%x name='%s'\n",
955 dcb->dcb_magic, dcb->dcb_name);
956 list_del_init(&dcb->dcb_linkage);
957 dcb->dcb_func(NULL, th, dcb, error);
960 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
964 lu_context_exit(&th->th_ctx);
965 lu_context_fini(&th->th_ctx);
969 static struct thandle *osd_trans_create(const struct lu_env *env,
972 struct osd_thread_info *oti = osd_oti_get(env);
973 struct osd_iobuf *iobuf = &oti->oti_iobuf;
974 struct osd_thandle *oh;
978 /* on pending IO in this thread should left from prev. request */
979 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
981 th = ERR_PTR(-ENOMEM);
982 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
984 oh->ot_quota_trans = &oti->oti_quota_trans;
985 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
989 th->th_tags = LCT_TX_HANDLE;
991 INIT_LIST_HEAD(&oh->ot_dcb_list);
994 memset(oti->oti_declare_ops, 0,
995 sizeof(oti->oti_declare_ops));
996 memset(oti->oti_declare_ops_rb, 0,
997 sizeof(oti->oti_declare_ops_rb));
998 memset(oti->oti_declare_ops_cred, 0,
999 sizeof(oti->oti_declare_ops_cred));
1000 oti->oti_rollback = false;
1006 * Concurrency: shouldn't matter.
1008 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1011 struct osd_thread_info *oti = osd_oti_get(env);
1012 struct osd_device *dev = osd_dt_dev(d);
1014 struct osd_thandle *oh;
1019 LASSERT(current->journal_info == NULL);
1021 oh = container_of0(th, struct osd_thandle, ot_super);
1022 LASSERT(oh != NULL);
1023 LASSERT(oh->ot_handle == NULL);
1025 rc = dt_txn_hook_start(env, d, th);
1029 if (unlikely(osd_param_is_not_sane(dev, th))) {
1030 static unsigned long last_printed;
1031 static int last_credits;
1033 CWARN("%.16s: too many transaction credits (%d > %d)\n",
1034 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
1036 osd_journal(dev)->j_max_transaction_buffers);
1037 CWARN(" create: %u/%u, destroy: %u/%u\n",
1038 oti->oti_declare_ops[OSD_OT_CREATE],
1039 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1040 oti->oti_declare_ops[OSD_OT_DESTROY],
1041 oti->oti_declare_ops_cred[OSD_OT_DESTROY]);
1042 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
1043 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1044 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1045 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1046 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]);
1047 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
1048 oti->oti_declare_ops[OSD_OT_WRITE],
1049 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1050 oti->oti_declare_ops[OSD_OT_PUNCH],
1051 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1052 oti->oti_declare_ops[OSD_OT_QUOTA],
1053 oti->oti_declare_ops_cred[OSD_OT_QUOTA]);
1054 CWARN(" insert: %u/%u, delete: %u/%u\n",
1055 oti->oti_declare_ops[OSD_OT_INSERT],
1056 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1057 oti->oti_declare_ops[OSD_OT_DELETE],
1058 oti->oti_declare_ops_cred[OSD_OT_DELETE]);
1059 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
1060 oti->oti_declare_ops[OSD_OT_REF_ADD],
1061 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1062 oti->oti_declare_ops[OSD_OT_REF_DEL],
1063 oti->oti_declare_ops_cred[OSD_OT_REF_DEL]);
1065 if (last_credits != oh->ot_credits &&
1066 time_after(jiffies, last_printed +
1067 msecs_to_jiffies(60 * MSEC_PER_SEC))) {
1068 libcfs_debug_dumpstack(NULL);
1069 last_credits = oh->ot_credits;
1070 last_printed = jiffies;
1072 /* XXX Limit the credits to 'max_transaction_buffers', and
1073 * let the underlying filesystem to catch the error if
1074 * we really need so many credits.
1076 * This should be removed when we can calculate the
1077 * credits precisely. */
1078 oh->ot_credits = osd_transaction_size(dev);
1082 * XXX temporary stuff. Some abstraction layer should
1085 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1089 LASSERT(oti->oti_txns == 0);
1090 lu_context_init(&th->th_ctx, th->th_tags);
1091 lu_context_enter(&th->th_ctx);
1093 lu_device_get(&d->dd_lu_dev);
1094 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1105 static int osd_seq_exists(const struct lu_env *env,
1106 struct osd_device *osd, u64 seq)
1108 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1109 struct seq_server_site *ss = osd_seq_site(osd);
1113 LASSERT(ss != NULL);
1114 LASSERT(ss->ss_server_fld != NULL);
1116 rc = osd_fld_lookup(env, osd, seq, range);
1119 CERROR("%s: can't lookup FLD sequence "LPX64
1120 ": rc = %d\n", osd_name(osd), seq, rc);
1124 RETURN(ss->ss_node_id == range->lsr_index);
1128 * Concurrency: shouldn't matter.
1130 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1134 struct osd_thandle *oh;
1135 struct osd_thread_info *oti = osd_oti_get(env);
1136 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1137 struct osd_device *osd = osd_dt_dev(th->th_dev);
1138 struct qsd_instance *qsd = osd->od_quota_slave;
1139 struct lquota_trans *qtrans;
1142 oh = container_of0(th, struct osd_thandle, ot_super);
1144 qtrans = oh->ot_quota_trans;
1145 oh->ot_quota_trans = NULL;
1147 if (oh->ot_handle != NULL) {
1148 handle_t *hdl = oh->ot_handle;
1151 * add commit callback
1152 * notice we don't do this in osd_trans_start()
1153 * as underlying transaction can change during truncate
1155 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1158 LASSERT(oti->oti_txns == 1);
1160 rc = dt_txn_hook_stop(env, th);
1162 CERROR("%s: failed in transaction hook: rc = %d\n",
1165 /* hook functions might modify th_sync */
1166 hdl->h_sync = th->th_sync;
1168 oh->ot_handle = NULL;
1169 OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl));
1171 CERROR("%s: failed to stop transaction: rc = %d\n",
1177 /* inform the quota slave device that the transaction is stopping */
1178 qsd_op_end(env, qsd, qtrans);
1180 /* as we want IO to journal and data IO be concurrent, we don't block
1181 * awaiting data IO completion in osd_do_bio(), instead we wait here
1182 * once transaction is submitted to the journal. all reqular requests
1183 * don't do direct IO (except read/write), thus this wait_event becomes
1186 * IMPORTANT: we have to wait till any IO submited by the thread is
1187 * completed otherwise iobuf may be corrupted by different request
1189 wait_event(iobuf->dr_wait,
1190 atomic_read(&iobuf->dr_numreqs) == 0);
1191 osd_fini_iobuf(osd, iobuf);
1193 rc = iobuf->dr_error;
1198 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1200 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1203 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1204 LASSERT(&dcb->dcb_func != NULL);
1205 list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
1211 * Called just before object is freed. Releases all resources except for
1212 * object itself (that is released by osd_object_free()).
1214 * Concurrency: no concurrent access is possible that late in object
1217 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1219 struct osd_object *obj = osd_obj(l);
1220 struct inode *inode = obj->oo_inode;
1222 LINVRNT(osd_invariant(obj));
1225 * If object is unlinked remove fid->ino mapping from object index.
1228 osd_index_fini(obj);
1229 if (inode != NULL) {
1230 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1231 qid_t uid = i_uid_read(inode);
1232 qid_t gid = i_gid_read(inode);
1235 obj->oo_inode = NULL;
1238 struct osd_thread_info *info = osd_oti_get(env);
1239 struct lquota_id_info *qi = &info->oti_qi;
1241 /* Release granted quota to master if necessary */
1242 qi->lqi_id.qid_uid = uid;
1243 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1245 qi->lqi_id.qid_uid = gid;
1246 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
1252 * Concurrency: ->loo_object_release() is called under site spin-lock.
1254 static void osd_object_release(const struct lu_env *env,
1255 struct lu_object *l)
1260 * Concurrency: shouldn't matter.
1262 static int osd_object_print(const struct lu_env *env, void *cookie,
1263 lu_printer_t p, const struct lu_object *l)
1265 struct osd_object *o = osd_obj(l);
1266 struct iam_descr *d;
1268 if (o->oo_dir != NULL)
1269 d = o->oo_dir->od_container.ic_descr;
1272 return (*p)(env, cookie,
1273 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
1275 o->oo_inode ? o->oo_inode->i_ino : 0UL,
1276 o->oo_inode ? o->oo_inode->i_generation : 0,
1277 d ? d->id_ops->id_name : "plain");
1280 #define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */
1283 * Concurrency: shouldn't matter.
1285 int osd_statfs(const struct lu_env *env, struct dt_device *d,
1286 struct obd_statfs *sfs)
1288 struct osd_device *osd = osd_dt_dev(d);
1289 struct super_block *sb = osd_sb(osd);
1290 struct kstatfs *ksfs;
1293 if (unlikely(osd->od_mnt == NULL))
1294 return -EINPROGRESS;
1296 /* osd_lproc.c call this without env, allocate ksfs for that case */
1297 if (unlikely(env == NULL)) {
1298 OBD_ALLOC_PTR(ksfs);
1302 ksfs = &osd_oti_get(env)->oti_ksfs;
1305 spin_lock(&osd->od_osfs_lock);
1306 result = sb->s_op->statfs(sb->s_root, ksfs);
1307 if (likely(result == 0)) { /* N.B. statfs can't really fail */
1308 statfs_pack(sfs, ksfs);
1309 if (sb->s_flags & MS_RDONLY)
1310 sfs->os_state = OS_STATE_READONLY;
1313 spin_unlock(&osd->od_osfs_lock);
1315 if (unlikely(env == NULL))
1318 /* Reserve a small amount of space for local objects like last_rcvd,
1319 * llog, quota files, ... */
1320 if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) {
1323 sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS;
1324 /** Take out metadata overhead for indirect blocks */
1325 sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3);
1332 * Estimate space needed for file creations. We assume the largest filename
1333 * which is 2^64 - 1, hence a filename of 20 chars.
1334 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
1336 #ifdef __LDISKFS_DIR_REC_LEN
1337 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
1339 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
1343 * Concurrency: doesn't access mutable data.
1345 static void osd_conf_get(const struct lu_env *env,
1346 const struct dt_device *dev,
1347 struct dt_device_param *param)
1349 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1353 * XXX should be taken from not-yet-existing fs abstraction layer.
1355 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1356 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1357 param->ddp_block_shift = sb->s_blocksize_bits;
1358 param->ddp_mount_type = LDD_MT_LDISKFS;
1359 param->ddp_maxbytes = sb->s_maxbytes;
1360 /* Overhead estimate should be fairly accurate, so we really take a tiny
1361 * error margin which also avoids fragmenting the filesystem too much */
1362 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
1363 /* inode are statically allocated, so per-inode space consumption
1364 * is the space consumed by the directory entry */
1365 param->ddp_inodespace = PER_OBJ_USAGE;
1366 /* per-fragment overhead to be used by the client code */
1367 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
1368 param->ddp_mntopts = 0;
1369 if (test_opt(sb, XATTR_USER))
1370 param->ddp_mntopts |= MNTOPT_USERXATTR;
1371 if (test_opt(sb, POSIX_ACL))
1372 param->ddp_mntopts |= MNTOPT_ACL;
1374 /* LOD might calculate the max stripe count based on max_ea_size,
1375 * so we need take account in the overhead as well,
1376 * xattr_header + magic + xattr_entry_head */
1377 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
1378 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
1380 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1381 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1382 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
1386 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
1390 * Concurrency: shouldn't matter.
1392 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1396 CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1398 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1400 CDEBUG(D_CACHE, "synced OSD %s: rc = %d\n",
1401 LUSTRE_OSD_LDISKFS_NAME, rc);
1407 * Start commit for OSD device.
1409 * An implementation of dt_commit_async method for OSD device.
1410 * Asychronously starts underlayng fs sync and thereby a transaction
1413 * \param env environment
1414 * \param d dt device
1416 * \see dt_device_operations
1418 static int osd_commit_async(const struct lu_env *env,
1419 struct dt_device *d)
1421 struct super_block *s = osd_sb(osd_dt_dev(d));
1424 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1425 RETURN(s->s_op->sync_fs(s, 0));
1429 * Concurrency: shouldn't matter.
1432 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1434 struct super_block *sb = osd_sb(osd_dt_dev(d));
1435 struct block_device *dev = sb->s_bdev;
1436 #ifdef HAVE_DEV_SET_RDONLY
1437 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
1440 int rc = -EOPNOTSUPP;
1444 #ifdef HAVE_DEV_SET_RDONLY
1445 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1447 if (jdev && (jdev != dev)) {
1448 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
1450 dev_set_rdonly(jdev);
1452 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
1453 dev_set_rdonly(dev);
1455 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
1456 osd_dt_dev(d)->od_svname, (long)dev, rc);
1462 * Note: we do not count into QUOTA here.
1463 * If we mount with --data_journal we may need more.
1465 const int osd_dto_credits_noquota[DTO_NR] = {
1468 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1469 * SINGLEDATA_TRANS_BLOCKS(8)
1470 * XXX Note: maybe iam need more, since iam have more level than
1473 [DTO_INDEX_INSERT] = 16,
1476 * just modify a single entry, probably merge few within a block
1478 [DTO_INDEX_DELETE] = 1,
1482 [DTO_INDEX_UPDATE] = 16,
1484 * 4(inode, inode bits, groups, GDT)
1485 * notice: OI updates are counted separately with DTO_INDEX_INSERT
1487 [DTO_OBJECT_CREATE] = 4,
1489 * 4(inode, inode bits, groups, GDT)
1490 * notice: OI updates are counted separately with DTO_INDEX_DELETE
1492 [DTO_OBJECT_DELETE] = 4,
1494 * Attr set credits (inode)
1496 [DTO_ATTR_SET_BASE] = 1,
1498 * Xattr set. The same as xattr of EXT3.
1499 * DATA_TRANS_BLOCKS(14)
1500 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1501 * are also counted in. Do not know why?
1503 [DTO_XATTR_SET] = 14,
1505 * credits for inode change during write.
1507 [DTO_WRITE_BASE] = 3,
1509 * credits for single block write.
1511 [DTO_WRITE_BLOCK] = 14,
1513 * Attr set credits for chown.
1514 * This is extra credits for setattr, and it is null without quota
1516 [DTO_ATTR_SET_CHOWN] = 0
1519 static const struct dt_device_operations osd_dt_ops = {
1520 .dt_root_get = osd_root_get,
1521 .dt_statfs = osd_statfs,
1522 .dt_trans_create = osd_trans_create,
1523 .dt_trans_start = osd_trans_start,
1524 .dt_trans_stop = osd_trans_stop,
1525 .dt_trans_cb_add = osd_trans_cb_add,
1526 .dt_conf_get = osd_conf_get,
1527 .dt_sync = osd_sync,
1529 .dt_commit_async = osd_commit_async,
1532 static void osd_object_read_lock(const struct lu_env *env,
1533 struct dt_object *dt, unsigned role)
1535 struct osd_object *obj = osd_dt_obj(dt);
1536 struct osd_thread_info *oti = osd_oti_get(env);
1538 LINVRNT(osd_invariant(obj));
1540 LASSERT(obj->oo_owner != env);
1541 down_read_nested(&obj->oo_sem, role);
1543 LASSERT(obj->oo_owner == NULL);
1547 static void osd_object_write_lock(const struct lu_env *env,
1548 struct dt_object *dt, unsigned role)
1550 struct osd_object *obj = osd_dt_obj(dt);
1551 struct osd_thread_info *oti = osd_oti_get(env);
1553 LINVRNT(osd_invariant(obj));
1555 LASSERT(obj->oo_owner != env);
1556 down_write_nested(&obj->oo_sem, role);
1558 LASSERT(obj->oo_owner == NULL);
1559 obj->oo_owner = env;
1563 static void osd_object_read_unlock(const struct lu_env *env,
1564 struct dt_object *dt)
1566 struct osd_object *obj = osd_dt_obj(dt);
1567 struct osd_thread_info *oti = osd_oti_get(env);
1569 LINVRNT(osd_invariant(obj));
1571 LASSERT(oti->oti_r_locks > 0);
1573 up_read(&obj->oo_sem);
1576 static void osd_object_write_unlock(const struct lu_env *env,
1577 struct dt_object *dt)
1579 struct osd_object *obj = osd_dt_obj(dt);
1580 struct osd_thread_info *oti = osd_oti_get(env);
1582 LINVRNT(osd_invariant(obj));
1584 LASSERT(obj->oo_owner == env);
1585 LASSERT(oti->oti_w_locks > 0);
1587 obj->oo_owner = NULL;
1588 up_write(&obj->oo_sem);
1591 static int osd_object_write_locked(const struct lu_env *env,
1592 struct dt_object *dt)
1594 struct osd_object *obj = osd_dt_obj(dt);
1596 LINVRNT(osd_invariant(obj));
1598 return obj->oo_owner == env;
1601 static struct timespec *osd_inode_time(const struct lu_env *env,
1602 struct inode *inode, __u64 seconds)
1604 struct osd_thread_info *oti = osd_oti_get(env);
1605 struct timespec *t = &oti->oti_time;
1607 t->tv_sec = seconds;
1609 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1614 static void osd_inode_getattr(const struct lu_env *env,
1615 struct inode *inode, struct lu_attr *attr)
1617 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1618 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1619 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
1622 attr->la_atime = LTIME_S(inode->i_atime);
1623 attr->la_mtime = LTIME_S(inode->i_mtime);
1624 attr->la_ctime = LTIME_S(inode->i_ctime);
1625 attr->la_mode = inode->i_mode;
1626 attr->la_size = i_size_read(inode);
1627 attr->la_blocks = inode->i_blocks;
1628 attr->la_uid = i_uid_read(inode);
1629 attr->la_gid = i_gid_read(inode);
1630 attr->la_flags = LDISKFS_I(inode)->i_flags;
1631 attr->la_nlink = inode->i_nlink;
1632 attr->la_rdev = inode->i_rdev;
1633 attr->la_blksize = 1 << inode->i_blkbits;
1634 attr->la_blkbits = inode->i_blkbits;
1637 static int osd_attr_get(const struct lu_env *env,
1638 struct dt_object *dt,
1639 struct lu_attr *attr)
1641 struct osd_object *obj = osd_dt_obj(dt);
1643 if (!dt_object_exists(dt))
1646 LASSERT(!dt_object_remote(dt));
1647 LINVRNT(osd_invariant(obj));
1649 spin_lock(&obj->oo_guard);
1650 osd_inode_getattr(env, obj->oo_inode, attr);
1651 spin_unlock(&obj->oo_guard);
1655 static int osd_declare_attr_set(const struct lu_env *env,
1656 struct dt_object *dt,
1657 const struct lu_attr *attr,
1658 struct thandle *handle)
1660 struct osd_thandle *oh;
1661 struct osd_object *obj;
1662 struct osd_thread_info *info = osd_oti_get(env);
1663 struct lquota_id_info *qi = &info->oti_qi;
1671 LASSERT(dt != NULL);
1672 LASSERT(handle != NULL);
1674 obj = osd_dt_obj(dt);
1675 LASSERT(osd_invariant(obj));
1677 oh = container_of0(handle, struct osd_thandle, ot_super);
1678 LASSERT(oh->ot_handle == NULL);
1680 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
1681 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1683 if (attr == NULL || obj->oo_inode == NULL)
1686 bspace = obj->oo_inode->i_blocks;
1687 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1688 bspace = toqb(bspace);
1690 /* Changing ownership is always preformed by super user, it should not
1693 * We still need to call the osd_declare_qid() to calculate the journal
1694 * credits for updating quota accounting files and to trigger quota
1695 * space adjustment once the operation is completed.*/
1696 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
1698 uid = i_uid_read(obj->oo_inode);
1699 qi->lqi_type = USRQUOTA;
1700 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
1701 /* inode accounting */
1702 qi->lqi_is_blk = false;
1704 /* one more inode for the new uid ... */
1705 qi->lqi_id.qid_uid = attr->la_uid;
1707 /* Reserve credits for the new uid */
1708 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1709 if (rc == -EDQUOT || rc == -EINPROGRESS)
1714 /* and one less inode for the current uid */
1715 qi->lqi_id.qid_uid = uid;
1717 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1718 if (rc == -EDQUOT || rc == -EINPROGRESS)
1723 /* block accounting */
1724 qi->lqi_is_blk = true;
1726 /* more blocks for the new uid ... */
1727 qi->lqi_id.qid_uid = attr->la_uid;
1728 qi->lqi_space = bspace;
1730 * Credits for the new uid has been reserved, re-use "obj"
1731 * to save credit reservation.
1733 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1734 if (rc == -EDQUOT || rc == -EINPROGRESS)
1739 /* and finally less blocks for the current uid */
1740 qi->lqi_id.qid_uid = uid;
1741 qi->lqi_space = -bspace;
1742 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1743 if (rc == -EDQUOT || rc == -EINPROGRESS)
1749 gid = i_gid_read(obj->oo_inode);
1750 qi->lqi_type = GRPQUOTA;
1751 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
1753 /* inode accounting */
1754 qi->lqi_is_blk = false;
1756 /* one more inode for the new gid ... */
1757 qi->lqi_id.qid_gid = attr->la_gid;
1759 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1760 if (rc == -EDQUOT || rc == -EINPROGRESS)
1765 /* and one less inode for the current gid */
1766 qi->lqi_id.qid_gid = gid;
1768 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1769 if (rc == -EDQUOT || rc == -EINPROGRESS)
1774 /* block accounting */
1775 qi->lqi_is_blk = true;
1777 /* more blocks for the new gid ... */
1778 qi->lqi_id.qid_gid = attr->la_gid;
1779 qi->lqi_space = bspace;
1780 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1781 if (rc == -EDQUOT || rc == -EINPROGRESS)
1786 /* and finally less blocks for the current gid */
1787 qi->lqi_id.qid_gid = gid;
1788 qi->lqi_space = -bspace;
1789 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1790 if (rc == -EDQUOT || rc == -EINPROGRESS)
1799 static int osd_inode_setattr(const struct lu_env *env,
1800 struct inode *inode, const struct lu_attr *attr)
1802 __u64 bits = attr->la_valid;
1804 /* Only allow set size for regular file */
1805 if (!S_ISREG(inode->i_mode))
1806 bits &= ~(LA_SIZE | LA_BLOCKS);
1811 if (bits & LA_ATIME)
1812 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1813 if (bits & LA_CTIME)
1814 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1815 if (bits & LA_MTIME)
1816 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1817 if (bits & LA_SIZE) {
1818 LDISKFS_I(inode)->i_disksize = attr->la_size;
1819 i_size_write(inode, attr->la_size);
1823 /* OSD should not change "i_blocks" which is used by quota.
1824 * "i_blocks" should be changed by ldiskfs only. */
1825 if (bits & LA_BLOCKS)
1826 inode->i_blocks = attr->la_blocks;
1829 inode->i_mode = (inode->i_mode & S_IFMT) |
1830 (attr->la_mode & ~S_IFMT);
1832 i_uid_write(inode, attr->la_uid);
1834 i_gid_write(inode, attr->la_gid);
1835 if (bits & LA_NLINK)
1836 set_nlink(inode, attr->la_nlink);
1838 inode->i_rdev = attr->la_rdev;
1840 if (bits & LA_FLAGS) {
1841 /* always keep S_NOCMTIME */
1842 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1848 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1850 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
1851 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
1855 ll_vfs_dq_init(inode);
1857 if (attr->la_valid & LA_UID)
1858 iattr.ia_valid |= ATTR_UID;
1859 if (attr->la_valid & LA_GID)
1860 iattr.ia_valid |= ATTR_GID;
1861 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
1862 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
1864 rc = ll_vfs_dq_transfer(inode, &iattr);
1866 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1867 "enforcement enabled on the ldiskfs "
1868 "filesystem?\n", inode->i_sb->s_id, rc);
1875 static int osd_attr_set(const struct lu_env *env,
1876 struct dt_object *dt,
1877 const struct lu_attr *attr,
1878 struct thandle *handle)
1880 struct osd_object *obj = osd_dt_obj(dt);
1881 struct inode *inode;
1884 if (!dt_object_exists(dt))
1887 LASSERT(handle != NULL);
1888 LASSERT(!dt_object_remote(dt));
1889 LASSERT(osd_invariant(obj));
1891 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
1893 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING)) {
1894 struct osd_thread_info *oti = osd_oti_get(env);
1895 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
1896 struct lu_fid *fid1 = &oti->oti_fid;
1897 struct osd_inode_id *id = &oti->oti_id;
1898 struct iam_path_descr *ipd;
1899 struct iam_container *bag;
1900 struct osd_thandle *oh;
1903 fid_cpu_to_be(fid1, fid0);
1904 memset(id, 1, sizeof(*id));
1905 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
1906 fid0)->oi_dir.od_container;
1907 ipd = osd_idx_ipd_get(env, bag);
1908 if (unlikely(ipd == NULL))
1911 oh = container_of0(handle, struct osd_thandle, ot_super);
1912 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
1913 (const struct iam_rec *)id, ipd);
1914 osd_ipd_put(env, bag, ipd);
1915 return(rc > 0 ? 0 : rc);
1918 inode = obj->oo_inode;
1920 rc = osd_quota_transfer(inode, attr);
1924 spin_lock(&obj->oo_guard);
1925 rc = osd_inode_setattr(env, inode, attr);
1926 spin_unlock(&obj->oo_guard);
1929 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
1933 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
1934 struct osd_object *obj,
1935 const char *name, const int namelen)
1937 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1940 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1941 umode_t mode, struct dt_allocation_hint *hint,
1945 struct osd_device *osd = osd_obj2dev(obj);
1946 struct osd_thandle *oth;
1947 struct dt_object *parent = NULL;
1948 struct inode *inode;
1950 LINVRNT(osd_invariant(obj));
1951 LASSERT(obj->oo_inode == NULL);
1952 LASSERT(obj->oo_hl_head == NULL);
1954 if (S_ISDIR(mode) && ldiskfs_pdo) {
1955 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1956 if (obj->oo_hl_head == NULL)
1960 oth = container_of(th, struct osd_thandle, ot_super);
1961 LASSERT(oth->ot_handle->h_transaction != NULL);
1963 if (hint && hint->dah_parent)
1964 parent = hint->dah_parent;
1966 inode = ldiskfs_create_inode(oth->ot_handle,
1967 parent ? osd_dt_obj(parent)->oo_inode :
1968 osd_sb(osd)->s_root->d_inode,
1970 if (!IS_ERR(inode)) {
1971 /* Do not update file c/mtime in ldiskfs. */
1972 inode->i_flags |= S_NOCMTIME;
1974 /* For new created object, it must be consistent,
1975 * and it is unnecessary to scrub against it. */
1976 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
1978 obj->oo_inode = inode;
1981 if (obj->oo_hl_head != NULL) {
1982 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1983 obj->oo_hl_head = NULL;
1985 result = PTR_ERR(inode);
1987 LINVRNT(osd_invariant(obj));
1995 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1996 struct lu_attr *attr,
1997 struct dt_allocation_hint *hint,
1998 struct dt_object_format *dof,
2002 struct osd_thandle *oth;
2003 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
2005 LASSERT(S_ISDIR(attr->la_mode));
2007 oth = container_of(th, struct osd_thandle, ot_super);
2008 LASSERT(oth->ot_handle->h_transaction != NULL);
2009 result = osd_mkfile(info, obj, mode, hint, th);
2014 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
2015 struct lu_attr *attr,
2016 struct dt_allocation_hint *hint,
2017 struct dt_object_format *dof,
2021 struct osd_thandle *oth;
2022 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
2024 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
2026 LASSERT(S_ISREG(attr->la_mode));
2028 oth = container_of(th, struct osd_thandle, ot_super);
2029 LASSERT(oth->ot_handle->h_transaction != NULL);
2031 result = osd_mkfile(info, obj, mode, hint, th);
2033 LASSERT(obj->oo_inode != NULL);
2034 if (feat->dif_flags & DT_IND_VARKEY)
2035 result = iam_lvar_create(obj->oo_inode,
2036 feat->dif_keysize_max,
2038 feat->dif_recsize_max,
2041 result = iam_lfix_create(obj->oo_inode,
2042 feat->dif_keysize_max,
2044 feat->dif_recsize_max,
2051 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
2052 struct lu_attr *attr,
2053 struct dt_allocation_hint *hint,
2054 struct dt_object_format *dof,
2057 LASSERT(S_ISREG(attr->la_mode));
2058 return osd_mkfile(info, obj, (attr->la_mode &
2059 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2062 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
2063 struct lu_attr *attr,
2064 struct dt_allocation_hint *hint,
2065 struct dt_object_format *dof,
2068 LASSERT(S_ISLNK(attr->la_mode));
2069 return osd_mkfile(info, obj, (attr->la_mode &
2070 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2073 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
2074 struct lu_attr *attr,
2075 struct dt_allocation_hint *hint,
2076 struct dt_object_format *dof,
2079 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
2082 LINVRNT(osd_invariant(obj));
2083 LASSERT(obj->oo_inode == NULL);
2084 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
2085 S_ISFIFO(mode) || S_ISSOCK(mode));
2087 result = osd_mkfile(info, obj, mode, hint, th);
2089 LASSERT(obj->oo_inode != NULL);
2091 * This inode should be marked dirty for i_rdev. Currently
2092 * that is done in the osd_attr_init().
2094 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
2097 LINVRNT(osd_invariant(obj));
2101 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
2103 struct dt_allocation_hint *hint,
2104 struct dt_object_format *dof,
2107 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
2109 osd_obj_type_f result;
2125 result = osd_mk_index;
2136 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2137 struct dt_object *parent, struct dt_object *child,
2142 ah->dah_parent = parent;
2143 ah->dah_mode = child_mode;
2146 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
2147 struct lu_attr *attr, struct dt_object_format *dof)
2149 struct inode *inode = obj->oo_inode;
2150 __u64 valid = attr->la_valid;
2153 attr->la_valid &= ~(LA_TYPE | LA_MODE);
2155 if (dof->dof_type != DFT_NODE)
2156 attr->la_valid &= ~LA_RDEV;
2157 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
2158 attr->la_valid &= ~LA_ATIME;
2159 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
2160 attr->la_valid &= ~LA_CTIME;
2161 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
2162 attr->la_valid &= ~LA_MTIME;
2164 result = osd_quota_transfer(inode, attr);
2168 if (attr->la_valid != 0) {
2169 result = osd_inode_setattr(info->oti_env, inode, attr);
2171 * The osd_inode_setattr() should always succeed here. The
2172 * only error that could be returned is EDQUOT when we are
2173 * trying to change the UID or GID of the inode. However, this
2174 * should not happen since quota enforcement is no longer
2175 * enabled on ldiskfs (lquota takes care of it).
2177 LASSERTF(result == 0, "%d\n", result);
2178 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2181 attr->la_valid = valid;
2185 * Helper function for osd_object_create()
2187 * \retval 0, on success
2189 static int __osd_object_create(struct osd_thread_info *info,
2190 struct osd_object *obj, struct lu_attr *attr,
2191 struct dt_allocation_hint *hint,
2192 struct dt_object_format *dof,
2198 /* we drop umask so that permissions we pass are not affected */
2199 umask = current->fs->umask;
2200 current->fs->umask = 0;
2202 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
2205 osd_attr_init(info, obj, attr, dof);
2206 osd_object_init0(obj);
2209 if (obj->oo_inode != NULL) {
2210 LASSERT(obj->oo_inode->i_state & I_NEW);
2212 unlock_new_inode(obj->oo_inode);
2215 /* restore previous umask value */
2216 current->fs->umask = umask;
2222 * Helper function for osd_object_create()
2224 * \retval 0, on success
2226 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
2227 const struct lu_fid *fid, struct thandle *th)
2229 struct osd_thread_info *info = osd_oti_get(env);
2230 struct osd_inode_id *id = &info->oti_id;
2231 struct osd_device *osd = osd_obj2dev(obj);
2232 struct osd_thandle *oh;
2234 LASSERT(obj->oo_inode != NULL);
2236 oh = container_of0(th, struct osd_thandle, ot_super);
2237 LASSERT(oh->ot_handle);
2239 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2240 return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
2243 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
2244 u64 seq, struct lu_seq_range *range)
2246 struct seq_server_site *ss = osd_seq_site(osd);
2248 if (fid_seq_is_idif(seq)) {
2249 fld_range_set_ost(range);
2250 range->lsr_index = idif_ost_idx(seq);
2254 if (!fid_seq_in_fldb(seq)) {
2255 fld_range_set_mdt(range);
2257 /* FIXME: If ss is NULL, it suppose not get lsr_index
2259 range->lsr_index = ss->ss_node_id;
2263 LASSERT(ss != NULL);
2264 fld_range_set_any(range);
2265 /* OSD will only do local fld lookup */
2266 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
2270 * Concurrency: no external locking is necessary.
2272 static int osd_declare_object_create(const struct lu_env *env,
2273 struct dt_object *dt,
2274 struct lu_attr *attr,
2275 struct dt_allocation_hint *hint,
2276 struct dt_object_format *dof,
2277 struct thandle *handle)
2279 struct osd_thandle *oh;
2283 LASSERT(handle != NULL);
2285 oh = container_of0(handle, struct osd_thandle, ot_super);
2286 LASSERT(oh->ot_handle == NULL);
2288 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
2289 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
2290 /* Reuse idle OI block may cause additional one OI block
2292 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2293 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
2295 /* If this is directory, then we expect . and .. to be inserted as
2296 * well. The one directory block always needs to be created for the
2297 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2298 * block), there is no danger of needing a tree for the first block.
2300 if (attr && S_ISDIR(attr->la_mode)) {
2301 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2302 osd_dto_credits_noquota[DTO_WRITE_BASE]);
2303 osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0);
2309 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2310 osd_dt_obj(dt), false, NULL, false);
2317 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2318 struct lu_attr *attr,
2319 struct dt_allocation_hint *hint,
2320 struct dt_object_format *dof, struct thandle *th)
2322 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2323 struct osd_object *obj = osd_dt_obj(dt);
2324 struct osd_thread_info *info = osd_oti_get(env);
2328 if (dt_object_exists(dt))
2331 LINVRNT(osd_invariant(obj));
2332 LASSERT(!dt_object_remote(dt));
2333 LASSERT(osd_write_locked(env, obj));
2334 LASSERT(th != NULL);
2336 if (unlikely(fid_is_acct(fid)))
2337 /* Quota files can't be created from the kernel any more,
2338 * 'tune2fs -O quota' will take care of creating them */
2341 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2342 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2344 result = __osd_object_create(info, obj, attr, hint, dof, th);
2346 result = __osd_oi_insert(env, obj, fid, th);
2348 LASSERT(ergo(result == 0,
2349 dt_object_exists(dt) && !dt_object_remote(dt)));
2351 LASSERT(osd_invariant(obj));
2356 * Called to destroy on-disk representation of the object
2358 * Concurrency: must be locked
2360 static int osd_declare_object_destroy(const struct lu_env *env,
2361 struct dt_object *dt,
2364 struct osd_object *obj = osd_dt_obj(dt);
2365 struct inode *inode = obj->oo_inode;
2366 struct osd_thandle *oh;
2370 oh = container_of0(th, struct osd_thandle, ot_super);
2371 LASSERT(oh->ot_handle == NULL);
2374 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
2375 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2376 /* Recycle idle OI leaf may cause additional three OI blocks
2378 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
2379 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
2380 /* one less inode */
2381 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2382 -1, oh, obj, false, NULL, false);
2385 /* data to be truncated */
2386 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2387 0, oh, obj, true, NULL, false);
2391 static int osd_object_destroy(const struct lu_env *env,
2392 struct dt_object *dt,
2395 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2396 struct osd_object *obj = osd_dt_obj(dt);
2397 struct inode *inode = obj->oo_inode;
2398 struct osd_device *osd = osd_obj2dev(obj);
2399 struct osd_thandle *oh;
2403 oh = container_of0(th, struct osd_thandle, ot_super);
2404 LASSERT(oh->ot_handle);
2406 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2408 if (unlikely(fid_is_acct(fid)))
2411 if (S_ISDIR(inode->i_mode)) {
2412 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
2413 inode->i_nlink == 2);
2414 /* it will check/delete the inode from remote parent,
2415 * how to optimize it? unlink performance impaction XXX */
2416 result = osd_delete_from_remote_parent(env, osd, obj, oh);
2417 if (result != 0 && result != -ENOENT) {
2418 CERROR("%s: delete inode "DFID": rc = %d\n",
2419 osd_name(osd), PFID(fid), result);
2421 spin_lock(&obj->oo_guard);
2423 spin_unlock(&obj->oo_guard);
2424 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2427 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
2429 result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
2432 /* XXX: add to ext3 orphan list */
2433 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2435 /* not needed in the cache anymore */
2436 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2442 * Put the fid into lustre_mdt_attrs, and then place the structure
2443 * inode's ea. This fid should not be altered during the life time
2446 * \retval +ve, on success
2447 * \retval -ve, on error
2449 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2451 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
2452 const struct lu_fid *fid, __u32 compat, __u32 incompat)
2454 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2458 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
2461 lustre_lma_init(lma, fid, compat, incompat);
2462 lustre_lma_swab(lma);
2464 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma, sizeof(*lma),
2466 /* LMA may already exist, but we need to check that all the
2467 * desired compat/incompat flags have been added. */
2468 if (unlikely(rc == -EEXIST)) {
2469 if (compat == 0 && incompat == 0)
2472 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
2473 XATTR_NAME_LMA, info->oti_mdt_attrs_old,
2478 lustre_lma_swab(lma);
2479 if (!(~lma->lma_compat & compat) &&
2480 !(~lma->lma_incompat & incompat))
2483 lma->lma_compat |= compat;
2484 lma->lma_incompat |= incompat;
2485 lustre_lma_swab(lma);
2486 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2487 sizeof(*lma), XATTR_REPLACE);
2494 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2495 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2496 * To have compatilibility with 1.8 ldiskfs driver we need to have
2497 * magic number at start of fid data.
2498 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2501 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2502 const struct lu_fid *fid)
2504 if (!fid_is_namespace_visible(fid) ||
2505 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
2506 param->edp_magic = 0;
2510 param->edp_magic = LDISKFS_LUFID_MAGIC;
2511 param->edp_len = sizeof(struct lu_fid) + 1;
2512 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
2516 * Try to read the fid from inode ea into dt_rec.
2518 * \param fid object fid.
2520 * \retval 0 on success
2522 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2523 __u32 ino, struct lu_fid *fid,
2524 struct osd_inode_id *id)
2526 struct osd_thread_info *info = osd_oti_get(env);
2527 struct inode *inode;
2530 osd_id_gen(id, ino, OSD_OII_NOGEN);
2531 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2533 RETURN(PTR_ERR(inode));
2539 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
2541 struct inode *parent_dir,
2542 const struct lu_fid *dot_fid,
2543 const struct lu_fid *dot_dot_fid,
2544 struct osd_thandle *oth)
2546 struct ldiskfs_dentry_param *dot_ldp;
2547 struct ldiskfs_dentry_param *dot_dot_ldp;
2549 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
2550 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
2552 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
2553 dot_ldp->edp_magic = 0;
2554 return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
2555 dir, dot_ldp, dot_dot_ldp);
2559 * Create an local agent inode for remote entry
2561 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
2562 struct osd_device *osd,
2563 struct osd_object *pobj,
2564 const struct lu_fid *fid,
2568 struct osd_thread_info *info = osd_oti_get(env);
2569 struct inode *local;
2570 struct osd_thandle *oh;
2575 oh = container_of(th, struct osd_thandle, ot_super);
2576 LASSERT(oh->ot_handle->h_transaction != NULL);
2578 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
2579 if (IS_ERR(local)) {
2580 CERROR("%s: create local error %d\n", osd_name(osd),
2581 (int)PTR_ERR(local));
2585 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
2586 unlock_new_inode(local);
2588 /* Set special LMA flag for local agent inode */
2589 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
2591 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
2592 osd_name(osd), PFID(fid), rc);
2593 RETURN(ERR_PTR(rc));
2599 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
2600 lu_object_fid(&pobj->oo_dt.do_lu),
2603 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
2604 osd_name(osd), PFID(fid), rc);
2605 RETURN(ERR_PTR(rc));
2612 * Delete local agent inode for remote entry
2614 static int osd_delete_local_agent_inode(const struct lu_env *env,
2615 struct osd_device *osd,
2616 const struct lu_fid *fid,
2617 __u32 ino, struct osd_thandle *oh)
2619 struct osd_thread_info *oti = osd_oti_get(env);
2620 struct osd_inode_id *id = &oti->oti_id;
2621 struct inode *inode;
2624 id->oii_ino = le32_to_cpu(ino);
2625 id->oii_gen = OSD_OII_NOGEN;
2626 inode = osd_iget(oti, osd, id);
2627 if (IS_ERR(inode)) {
2628 CERROR("%s: iget error "DFID" id %u:%u\n", osd_name(osd),
2629 PFID(fid), id->oii_ino, id->oii_gen);
2630 RETURN(PTR_ERR(inode));
2634 mark_inode_dirty(inode);
2635 CDEBUG(D_INODE, "%s: delete remote inode "DFID" %lu\n",
2636 osd_name(osd), PFID(fid), inode->i_ino);
2642 * OSD layer object create function for interoperability mode (b11826).
2643 * This is mostly similar to osd_object_create(). Only difference being, fid is
2644 * inserted into inode ea here.
2646 * \retval 0, on success
2647 * \retval -ve, on error
2649 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2650 struct lu_attr *attr,
2651 struct dt_allocation_hint *hint,
2652 struct dt_object_format *dof,
2655 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2656 struct osd_object *obj = osd_dt_obj(dt);
2657 struct osd_thread_info *info = osd_oti_get(env);
2662 if (dt_object_exists(dt))
2665 LASSERT(osd_invariant(obj));
2666 LASSERT(!dt_object_remote(dt));
2667 LASSERT(osd_write_locked(env, obj));
2668 LASSERT(th != NULL);
2670 if (unlikely(fid_is_acct(fid)))
2671 /* Quota files can't be created from the kernel any more,
2672 * 'tune2fs -O quota' will take care of creating them */
2675 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2676 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2678 result = __osd_object_create(info, obj, attr, hint, dof, th);
2680 if (fid_is_idif(fid) &&
2681 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
2682 struct lu_fid *tfid = &info->oti_fid;
2683 struct ost_id *oi = &info->oti_ostid;
2685 fid_to_ostid(fid, oi);
2686 ostid_to_fid(tfid, oi, 0);
2687 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
2688 LMAC_FID_ON_OST, 0);
2690 result = osd_ea_fid_set(info, obj->oo_inode, fid,
2691 fid_is_on_ost(info, osd_obj2dev(obj),
2692 fid, OI_CHECK_FLD) ?
2693 LMAC_FID_ON_OST : 0, 0);
2698 result = __osd_oi_insert(env, obj, fid, th);
2700 LASSERT(ergo(result == 0,
2701 dt_object_exists(dt) && !dt_object_remote(dt)));
2702 LINVRNT(osd_invariant(obj));
2706 static int osd_declare_object_ref_add(const struct lu_env *env,
2707 struct dt_object *dt,
2708 struct thandle *handle)
2710 struct osd_thandle *oh;
2712 /* it's possible that object doesn't exist yet */
2713 LASSERT(handle != NULL);
2715 oh = container_of0(handle, struct osd_thandle, ot_super);
2716 LASSERT(oh->ot_handle == NULL);
2718 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
2719 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2725 * Concurrency: @dt is write locked.
2727 static int osd_object_ref_add(const struct lu_env *env,
2728 struct dt_object *dt, struct thandle *th)
2730 struct osd_object *obj = osd_dt_obj(dt);
2731 struct inode *inode = obj->oo_inode;
2732 struct osd_thandle *oh;
2735 if (!dt_object_exists(dt))
2738 LINVRNT(osd_invariant(obj));
2739 LASSERT(!dt_object_remote(dt));
2740 LASSERT(osd_write_locked(env, obj));
2741 LASSERT(th != NULL);
2743 oh = container_of0(th, struct osd_thandle, ot_super);
2744 LASSERT(oh->ot_handle != NULL);
2746 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
2748 CDEBUG(D_INODE, DFID" increase nlink %d\n",
2749 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2751 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
2752 * (65000) subdirectories by storing "1" in i_nlink if the link count
2753 * would otherwise overflow. Directory tranversal tools understand
2754 * that (st_nlink == 1) indicates that the filesystem dose not track
2755 * hard links count on the directory, and will not abort subdirectory
2756 * scanning early once (st_nlink - 2) subdirs have been found.
2758 * This also has to properly handle the case of inodes with nlink == 0
2759 * in case they are being linked into the PENDING directory
2761 spin_lock(&obj->oo_guard);
2762 if (unlikely(inode->i_nlink == 0))
2763 /* inc_nlink from 0 may cause WARN_ON */
2764 set_nlink(inode, 1);
2766 ldiskfs_inc_count(oh->ot_handle, inode);
2767 if (!S_ISDIR(inode->i_mode))
2768 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2770 spin_unlock(&obj->oo_guard);
2772 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2773 LINVRNT(osd_invariant(obj));
2778 static int osd_declare_object_ref_del(const struct lu_env *env,
2779 struct dt_object *dt,
2780 struct thandle *handle)
2782 struct osd_thandle *oh;
2784 LASSERT(!dt_object_remote(dt));
2785 LASSERT(handle != NULL);
2787 oh = container_of0(handle, struct osd_thandle, ot_super);
2788 LASSERT(oh->ot_handle == NULL);
2790 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
2791 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2797 * Concurrency: @dt is write locked.
2799 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2802 struct osd_object *obj = osd_dt_obj(dt);
2803 struct inode *inode = obj->oo_inode;
2804 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
2805 struct osd_thandle *oh;
2807 if (!dt_object_exists(dt))
2810 LINVRNT(osd_invariant(obj));
2811 LASSERT(!dt_object_remote(dt));
2812 LASSERT(osd_write_locked(env, obj));
2813 LASSERT(th != NULL);
2815 oh = container_of0(th, struct osd_thandle, ot_super);
2816 LASSERT(oh->ot_handle != NULL);
2818 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
2820 spin_lock(&obj->oo_guard);
2821 /* That can be result of upgrade from old Lustre version and
2822 * applied only to local files. Just skip this ref_del call.
2823 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
2824 if (inode->i_nlink == 0) {
2825 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2826 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
2827 ", maybe an upgraded file? (LU-3915)\n",
2828 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
2829 spin_unlock(&obj->oo_guard);
2833 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
2834 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2836 ldiskfs_dec_count(oh->ot_handle, inode);
2837 spin_unlock(&obj->oo_guard);
2839 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2840 LINVRNT(osd_invariant(obj));
2846 * Get the 64-bit version for an inode.
2848 static int osd_object_version_get(const struct lu_env *env,
2849 struct dt_object *dt, dt_obj_version_t *ver)
2851 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2853 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2854 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2855 *ver = LDISKFS_I(inode)->i_fs_version;
2860 * Concurrency: @dt is read locked.
2862 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2863 struct lu_buf *buf, const char *name)
2865 struct osd_object *obj = osd_dt_obj(dt);
2866 struct inode *inode = obj->oo_inode;
2867 struct osd_thread_info *info = osd_oti_get(env);
2868 struct dentry *dentry = &info->oti_obj_dentry;
2870 /* version get is not real XATTR but uses xattr API */
2871 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2872 /* for version we are just using xattr API but change inode
2874 if (buf->lb_len == 0)
2875 return sizeof(dt_obj_version_t);
2877 if (buf->lb_len < sizeof(dt_obj_version_t))
2880 osd_object_version_get(env, dt, buf->lb_buf);
2882 return sizeof(dt_obj_version_t);
2885 if (!dt_object_exists(dt))
2888 LASSERT(!dt_object_remote(dt));
2889 LASSERT(inode->i_op != NULL);
2890 LASSERT(inode->i_op->getxattr != NULL);
2892 return __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len);
2896 static int osd_declare_xattr_set(const struct lu_env *env,
2897 struct dt_object *dt,
2898 const struct lu_buf *buf, const char *name,
2899 int fl, struct thandle *handle)
2901 struct osd_thandle *oh;
2903 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2905 LASSERT(handle != NULL);
2907 oh = container_of0(handle, struct osd_thandle, ot_super);
2908 LASSERT(oh->ot_handle == NULL);
2910 /* optimistic optimization: LMA is set first and usually fit inode */
2911 if (strcmp(name, XATTR_NAME_LMA) == 0) {
2912 if (dt_object_exists(dt))
2916 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2919 credits = osd_dto_credits_noquota[DTO_XATTR_SET];
2920 if (buf && buf->lb_len > sb->s_blocksize) {
2921 credits *= (buf->lb_len + sb->s_blocksize - 1) >>
2922 sb->s_blocksize_bits;
2925 * xattr set may involve inode quota change, reserve credits for
2926 * dquot_initialize()
2928 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2931 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
2937 * Set the 64-bit version for object
2939 static void osd_object_version_set(const struct lu_env *env,
2940 struct dt_object *dt,
2941 dt_obj_version_t *new_version)
2943 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2945 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2946 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2948 LDISKFS_I(inode)->i_fs_version = *new_version;
2949 /** Version is set after all inode operations are finished,
2950 * so we should mark it dirty here */
2951 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2955 * Concurrency: @dt is write locked.
2957 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2958 const struct lu_buf *buf, const char *name, int fl,
2959 struct thandle *handle)
2961 struct osd_object *obj = osd_dt_obj(dt);
2962 struct inode *inode = obj->oo_inode;
2963 struct osd_thread_info *info = osd_oti_get(env);
2967 LASSERT(handle != NULL);
2969 /* version set is not real XATTR */
2970 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2971 /* for version we are just using xattr API but change inode
2973 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2974 osd_object_version_set(env, dt, buf->lb_buf);
2975 return sizeof(dt_obj_version_t);
2978 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
2979 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
2981 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2982 if (fl & LU_XATTR_REPLACE)
2983 fs_flags |= XATTR_REPLACE;
2985 if (fl & LU_XATTR_CREATE)
2986 fs_flags |= XATTR_CREATE;
2988 if (strcmp(name, XATTR_NAME_LMV) == 0) {
2989 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2992 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
2996 lma->lma_incompat |= LMAI_STRIPED;
2997 lustre_lma_swab(lma);
2998 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2999 sizeof(*lma), XATTR_REPLACE);
3004 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
3005 strcmp(name, XATTR_NAME_LINK) == 0)
3008 return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
3013 * Concurrency: @dt is read locked.
3015 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
3016 const struct lu_buf *buf)
3018 struct osd_object *obj = osd_dt_obj(dt);
3019 struct inode *inode = obj->oo_inode;
3020 struct osd_thread_info *info = osd_oti_get(env);
3021 struct dentry *dentry = &info->oti_obj_dentry;
3023 if (!dt_object_exists(dt))
3026 LASSERT(!dt_object_remote(dt));
3027 LASSERT(inode->i_op != NULL);
3028 LASSERT(inode->i_op->listxattr != NULL);
3030 dentry->d_inode = inode;
3031 dentry->d_sb = inode->i_sb;
3032 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
3035 static int osd_declare_xattr_del(const struct lu_env *env,
3036 struct dt_object *dt, const char *name,
3037 struct thandle *handle)
3039 struct osd_thandle *oh;
3040 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3042 LASSERT(!dt_object_remote(dt));
3043 LASSERT(handle != NULL);
3045 oh = container_of0(handle, struct osd_thandle, ot_super);
3046 LASSERT(oh->ot_handle == NULL);
3048 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
3049 osd_dto_credits_noquota[DTO_XATTR_SET]);
3051 * xattr del may involve inode quota change, reserve credits for
3052 * dquot_initialize()
3054 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
3060 * Concurrency: @dt is write locked.
3062 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
3063 const char *name, struct thandle *handle)
3065 struct osd_object *obj = osd_dt_obj(dt);
3066 struct inode *inode = obj->oo_inode;
3067 struct osd_thread_info *info = osd_oti_get(env);
3068 struct dentry *dentry = &info->oti_obj_dentry;
3071 if (!dt_object_exists(dt))
3074 LASSERT(!dt_object_remote(dt));
3075 LASSERT(inode->i_op != NULL);
3076 LASSERT(inode->i_op->removexattr != NULL);
3077 LASSERT(handle != NULL);
3079 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3081 ll_vfs_dq_init(inode);
3082 dentry->d_inode = inode;
3083 dentry->d_sb = inode->i_sb;
3084 rc = inode->i_op->removexattr(dentry, name);
3088 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
3089 __u64 start, __u64 end)
3091 struct osd_object *obj = osd_dt_obj(dt);
3092 struct inode *inode = obj->oo_inode;
3093 struct osd_thread_info *info = osd_oti_get(env);
3094 struct dentry *dentry = &info->oti_obj_dentry;
3095 struct file *file = &info->oti_file;
3100 dentry->d_inode = inode;
3101 dentry->d_sb = inode->i_sb;
3102 file->f_dentry = dentry;
3103 file->f_mapping = inode->i_mapping;
3104 file->f_op = inode->i_fop;
3105 set_file_inode(file, inode);
3107 rc = ll_vfs_fsync_range(file, start, end, 0);
3116 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
3117 const struct dt_index_features *feat)
3119 struct iam_descr *descr;
3121 if (osd_object_is_root(o))
3122 return feat == &dt_directory_features;
3124 LASSERT(o->oo_dir != NULL);
3126 descr = o->oo_dir->od_container.ic_descr;
3127 if (feat == &dt_directory_features) {
3128 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
3134 feat->dif_keysize_min <= descr->id_key_size &&
3135 descr->id_key_size <= feat->dif_keysize_max &&
3136 feat->dif_recsize_min <= descr->id_rec_size &&
3137 descr->id_rec_size <= feat->dif_recsize_max &&
3138 !(feat->dif_flags & (DT_IND_VARKEY |
3139 DT_IND_VARREC | DT_IND_NONUNQ)) &&
3140 ergo(feat->dif_flags & DT_IND_UPDATE,
3141 1 /* XXX check that object (and file system) is
3146 static int osd_iam_container_init(const struct lu_env *env,
3147 struct osd_object *obj,
3148 struct osd_directory *dir)
3150 struct iam_container *bag = &dir->od_container;
3153 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
3157 result = iam_container_setup(bag);
3159 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
3161 iam_container_fini(bag);
3168 * Concurrency: no external locking is necessary.
3170 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
3171 const struct dt_index_features *feat)
3175 struct osd_object *obj = osd_dt_obj(dt);
3177 LINVRNT(osd_invariant(obj));
3179 if (osd_object_is_root(obj)) {
3180 dt->do_index_ops = &osd_index_ea_ops;
3182 } else if (feat == &dt_directory_features) {
3183 dt->do_index_ops = &osd_index_ea_ops;
3184 if (obj->oo_inode != NULL && S_ISDIR(obj->oo_inode->i_mode))
3189 } else if (unlikely(feat == &dt_otable_features)) {
3190 dt->do_index_ops = &osd_otable_ops;
3192 } else if (unlikely(feat == &dt_acct_features)) {
3193 dt->do_index_ops = &osd_acct_index_ops;
3196 } else if (!osd_has_index(obj)) {
3197 struct osd_directory *dir;
3202 spin_lock(&obj->oo_guard);
3203 if (obj->oo_dir == NULL)
3207 * Concurrent thread allocated container data.
3210 spin_unlock(&obj->oo_guard);
3212 * Now, that we have container data, serialize its
3215 down_write(&obj->oo_ext_idx_sem);
3217 * recheck under lock.
3219 if (!osd_has_index(obj))
3220 result = osd_iam_container_init(env, obj,
3224 up_write(&obj->oo_ext_idx_sem);
3232 if (result == 0 && skip_iam == 0) {
3233 if (!osd_iam_index_probe(env, obj, feat))
3236 LINVRNT(osd_invariant(obj));
3238 if (result == 0 && is_quota_glb_feat(feat) &&
3239 fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
3240 result = osd_quota_migration(env, dt, feat);
3245 static int osd_otable_it_attr_get(const struct lu_env *env,
3246 struct dt_object *dt,
3247 struct lu_attr *attr)
3253 static const struct dt_object_operations osd_obj_ops = {
3254 .do_read_lock = osd_object_read_lock,
3255 .do_write_lock = osd_object_write_lock,
3256 .do_read_unlock = osd_object_read_unlock,
3257 .do_write_unlock = osd_object_write_unlock,
3258 .do_write_locked = osd_object_write_locked,
3259 .do_attr_get = osd_attr_get,
3260 .do_declare_attr_set = osd_declare_attr_set,
3261 .do_attr_set = osd_attr_set,
3262 .do_ah_init = osd_ah_init,
3263 .do_declare_create = osd_declare_object_create,
3264 .do_create = osd_object_create,
3265 .do_declare_destroy = osd_declare_object_destroy,
3266 .do_destroy = osd_object_destroy,
3267 .do_index_try = osd_index_try,
3268 .do_declare_ref_add = osd_declare_object_ref_add,
3269 .do_ref_add = osd_object_ref_add,
3270 .do_declare_ref_del = osd_declare_object_ref_del,
3271 .do_ref_del = osd_object_ref_del,
3272 .do_xattr_get = osd_xattr_get,
3273 .do_declare_xattr_set = osd_declare_xattr_set,
3274 .do_xattr_set = osd_xattr_set,
3275 .do_declare_xattr_del = osd_declare_xattr_del,
3276 .do_xattr_del = osd_xattr_del,
3277 .do_xattr_list = osd_xattr_list,
3278 .do_object_sync = osd_object_sync,
3282 * dt_object_operations for interoperability mode
3283 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
3285 static const struct dt_object_operations osd_obj_ea_ops = {
3286 .do_read_lock = osd_object_read_lock,
3287 .do_write_lock = osd_object_write_lock,
3288 .do_read_unlock = osd_object_read_unlock,
3289 .do_write_unlock = osd_object_write_unlock,
3290 .do_write_locked = osd_object_write_locked,
3291 .do_attr_get = osd_attr_get,
3292 .do_declare_attr_set = osd_declare_attr_set,
3293 .do_attr_set = osd_attr_set,
3294 .do_ah_init = osd_ah_init,
3295 .do_declare_create = osd_declare_object_create,
3296 .do_create = osd_object_ea_create,
3297 .do_declare_destroy = osd_declare_object_destroy,
3298 .do_destroy = osd_object_destroy,
3299 .do_index_try = osd_index_try,
3300 .do_declare_ref_add = osd_declare_object_ref_add,
3301 .do_ref_add = osd_object_ref_add,
3302 .do_declare_ref_del = osd_declare_object_ref_del,
3303 .do_ref_del = osd_object_ref_del,
3304 .do_xattr_get = osd_xattr_get,
3305 .do_declare_xattr_set = osd_declare_xattr_set,
3306 .do_xattr_set = osd_xattr_set,
3307 .do_declare_xattr_del = osd_declare_xattr_del,
3308 .do_xattr_del = osd_xattr_del,
3309 .do_xattr_list = osd_xattr_list,
3310 .do_object_sync = osd_object_sync,
3313 static const struct dt_object_operations osd_obj_otable_it_ops = {
3314 .do_attr_get = osd_otable_it_attr_get,
3315 .do_index_try = osd_index_try,
3318 static int osd_index_declare_iam_delete(const struct lu_env *env,
3319 struct dt_object *dt,
3320 const struct dt_key *key,
3321 struct thandle *handle)
3323 struct osd_thandle *oh;
3325 oh = container_of0(handle, struct osd_thandle, ot_super);
3326 LASSERT(oh->ot_handle == NULL);
3328 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3329 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3335 * delete a (key, value) pair from index \a dt specified by \a key
3337 * \param dt osd index object
3338 * \param key key for index
3339 * \param rec record reference
3340 * \param handle transaction handler
3343 * \retval -ve failure
3345 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
3346 const struct dt_key *key,
3347 struct thandle *handle)
3349 struct osd_thread_info *oti = osd_oti_get(env);
3350 struct osd_object *obj = osd_dt_obj(dt);
3351 struct osd_thandle *oh;
3352 struct iam_path_descr *ipd;
3353 struct iam_container *bag = &obj->oo_dir->od_container;
3357 if (!dt_object_exists(dt))
3360 LINVRNT(osd_invariant(obj));
3361 LASSERT(!dt_object_remote(dt));
3362 LASSERT(bag->ic_object == obj->oo_inode);
3363 LASSERT(handle != NULL);
3365 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3367 ipd = osd_idx_ipd_get(env, bag);
3368 if (unlikely(ipd == NULL))
3371 oh = container_of0(handle, struct osd_thandle, ot_super);
3372 LASSERT(oh->ot_handle != NULL);
3373 LASSERT(oh->ot_handle->h_transaction != NULL);
3375 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3376 /* swab quota uid/gid provided by caller */
3377 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3378 key = (const struct dt_key *)&oti->oti_quota_id;
3381 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
3382 osd_ipd_put(env, bag, ipd);
3383 LINVRNT(osd_invariant(obj));
3387 static int osd_index_declare_ea_delete(const struct lu_env *env,
3388 struct dt_object *dt,
3389 const struct dt_key *key,
3390 struct thandle *handle)
3392 struct osd_thandle *oh;
3393 struct inode *inode;
3397 LASSERT(!dt_object_remote(dt));
3398 LASSERT(handle != NULL);
3400 oh = container_of0(handle, struct osd_thandle, ot_super);
3401 LASSERT(oh->ot_handle == NULL);
3403 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3404 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3406 inode = osd_dt_obj(dt)->oo_inode;
3409 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3410 0, oh, osd_dt_obj(dt), true, NULL, false);
3414 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3417 struct osd_fid_pack *rec;
3420 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3421 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3422 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3427 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
3428 const struct lu_fid *fid)
3430 struct seq_server_site *ss = osd_seq_site(osd);
3433 /* FID seqs not in FLDB, must be local seq */
3434 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
3437 /* If FLD is not being initialized yet, it only happens during the
3438 * initialization, likely during mgs initialization, and we assume
3439 * this is local FID. */
3440 if (ss == NULL || ss->ss_server_fld == NULL)
3443 /* Only check the local FLDB here */
3444 if (osd_seq_exists(env, osd, fid_seq(fid)))
3451 * Index delete function for interoperability mode (b11826).
3452 * It will remove the directory entry added by osd_index_ea_insert().
3453 * This entry is needed to maintain name->fid mapping.
3455 * \param key, key i.e. file entry to be deleted
3457 * \retval 0, on success
3458 * \retval -ve, on error
3460 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3461 const struct dt_key *key, struct thandle *handle)
3463 struct osd_object *obj = osd_dt_obj(dt);
3464 struct inode *dir = obj->oo_inode;
3465 struct dentry *dentry;
3466 struct osd_thandle *oh;
3467 struct ldiskfs_dir_entry_2 *de = NULL;
3468 struct buffer_head *bh;
3469 struct htree_lock *hlock = NULL;
3470 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
3471 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3475 if (!dt_object_exists(dt))
3478 LINVRNT(osd_invariant(obj));
3479 LASSERT(!dt_object_remote(dt));
3480 LASSERT(handle != NULL);
3482 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3484 oh = container_of(handle, struct osd_thandle, ot_super);
3485 LASSERT(oh->ot_handle != NULL);
3486 LASSERT(oh->ot_handle->h_transaction != NULL);
3488 ll_vfs_dq_init(dir);
3489 dentry = osd_child_dentry_get(env, obj,
3490 (char *)key, strlen((char *)key));
3492 if (obj->oo_hl_head != NULL) {
3493 hlock = osd_oti_get(env)->oti_hlock;
3494 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3495 dir, LDISKFS_HLOCK_DEL);
3497 down_write(&obj->oo_ext_idx_sem);
3500 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
3504 /* If this is not the ".." entry, it might be a remote DNE
3505 * entry and we need to check if the FID is for a remote
3506 * MDT. If the FID is not in the directory entry (e.g.
3507 * upgraded 1.8 filesystem without dirdata enabled) then
3508 * we need to get the FID from the LMA. For a remote directory
3509 * there HAS to be an LMA, it cannot be an IGIF inode in this
3512 * Delete the entry before the agent inode in order to
3513 * simplify error handling. At worst an error after deleting
3514 * the entry first might leak the agent inode afterward. The
3515 * reverse would need filesystem abort in case of error deleting
3516 * the entry after the agent had been removed, or leave a
3517 * dangling entry pointing at a random inode. */
3518 if (strcmp((char *)key, dotdot) != 0) {
3519 LASSERT(de != NULL);
3520 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
3521 /* If Fid is not in dentry, try to get it from LMA */
3522 if (rc == -ENODATA) {
3523 struct osd_inode_id *id;
3524 struct inode *inode;
3526 /* Before trying to get fid from the inode,
3527 * check whether the inode is valid.
3529 * If the inode has been deleted, do not go
3530 * ahead to do osd_ea_fid_get, which will set
3531 * the inode to bad inode, which might cause
3532 * the inode to be deleted uncorrectly */
3533 inode = ldiskfs_iget(osd_sb(osd),
3534 le32_to_cpu(de->inode));
3535 if (IS_ERR(inode)) {
3536 CDEBUG(D_INODE, "%s: "DFID"get inode"
3537 "error.\n", osd_name(osd),
3539 rc = PTR_ERR(inode);
3541 if (likely(inode->i_nlink != 0)) {
3542 id = &osd_oti_get(env)->oti_id;
3543 rc = osd_ea_fid_get(env, obj,
3544 le32_to_cpu(de->inode),
3547 CDEBUG(D_INFO, "%s: %u "DFID
3550 le32_to_cpu(de->inode),
3558 unlikely(osd_remote_fid(env, osd, fid)))
3559 /* Need to delete agent inode */
3560 ino = le32_to_cpu(de->inode);
3562 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
3564 if (rc == 0 && unlikely(ino != 0)) {
3565 rc = osd_delete_local_agent_inode(env, osd, fid, ino,
3568 CERROR("%s: del local inode "DFID": rc = %d\n",
3569 osd_name(osd), PFID(fid), rc);
3575 ldiskfs_htree_unlock(hlock);
3577 up_write(&obj->oo_ext_idx_sem);
3582 /* For inode on the remote MDT, .. will point to
3583 * /Agent directory, Check whether it needs to delete
3584 * from agent directory */
3585 if (unlikely(strcmp((char *)key, dotdot) == 0)) {
3586 rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj,
3588 if (rc != 0 && rc != -ENOENT) {
3589 CERROR("%s: delete agent inode "DFID": rc = %d\n",
3590 osd_name(osd), PFID(fid), rc);
3600 LASSERT(osd_invariant(obj));
3605 * Lookup index for \a key and copy record to \a rec.
3607 * \param dt osd index object
3608 * \param key key for index
3609 * \param rec record reference
3611 * \retval +ve success : exact mach
3612 * \retval 0 return record with key not greater than \a key
3613 * \retval -ve failure
3615 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3616 struct dt_rec *rec, const struct dt_key *key)
3618 struct osd_object *obj = osd_dt_obj(dt);
3619 struct iam_path_descr *ipd;
3620 struct iam_container *bag = &obj->oo_dir->od_container;
3621 struct osd_thread_info *oti = osd_oti_get(env);
3622 struct iam_iterator *it = &oti->oti_idx_it;
3623 struct iam_rec *iam_rec;
3627 if (!dt_object_exists(dt))
3630 LASSERT(osd_invariant(obj));
3631 LASSERT(!dt_object_remote(dt));
3632 LASSERT(bag->ic_object == obj->oo_inode);
3634 ipd = osd_idx_ipd_get(env, bag);
3638 /* got ipd now we can start iterator. */
3639 iam_it_init(it, bag, 0, ipd);
3641 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3642 /* swab quota uid/gid provided by caller */
3643 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3644 key = (const struct dt_key *)&oti->oti_quota_id;
3647 rc = iam_it_get(it, (struct iam_key *)key);
3649 if (S_ISDIR(obj->oo_inode->i_mode))
3650 iam_rec = (struct iam_rec *)oti->oti_ldp;
3652 iam_rec = (struct iam_rec *) rec;
3654 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3656 if (S_ISDIR(obj->oo_inode->i_mode))
3657 osd_fid_unpack((struct lu_fid *) rec,
3658 (struct osd_fid_pack *)iam_rec);
3659 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3660 osd_quota_unpack(obj, rec);
3665 osd_ipd_put(env, bag, ipd);
3667 LINVRNT(osd_invariant(obj));
3672 static int osd_index_declare_iam_insert(const struct lu_env *env,
3673 struct dt_object *dt,
3674 const struct dt_rec *rec,
3675 const struct dt_key *key,
3676 struct thandle *handle)
3678 struct osd_thandle *oh;
3680 LASSERT(handle != NULL);
3682 oh = container_of0(handle, struct osd_thandle, ot_super);
3683 LASSERT(oh->ot_handle == NULL);
3685 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3686 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3692 * Inserts (key, value) pair in \a dt index object.
3694 * \param dt osd index object
3695 * \param key key for index
3696 * \param rec record reference
3697 * \param th transaction handler
3700 * \retval -ve failure
3702 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3703 const struct dt_rec *rec,
3704 const struct dt_key *key, struct thandle *th,
3707 struct osd_object *obj = osd_dt_obj(dt);
3708 struct iam_path_descr *ipd;
3709 struct osd_thandle *oh;
3710 struct iam_container *bag;
3711 struct osd_thread_info *oti = osd_oti_get(env);
3712 struct iam_rec *iam_rec;
3716 if (!dt_object_exists(dt))
3719 LINVRNT(osd_invariant(obj));
3720 LASSERT(!dt_object_remote(dt));
3722 bag = &obj->oo_dir->od_container;
3723 LASSERT(bag->ic_object == obj->oo_inode);
3724 LASSERT(th != NULL);
3726 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3728 ipd = osd_idx_ipd_get(env, bag);
3729 if (unlikely(ipd == NULL))
3732 oh = container_of0(th, struct osd_thandle, ot_super);
3733 LASSERT(oh->ot_handle != NULL);
3734 LASSERT(oh->ot_handle->h_transaction != NULL);
3735 if (S_ISDIR(obj->oo_inode->i_mode)) {
3736 iam_rec = (struct iam_rec *)oti->oti_ldp;
3737 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3738 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3739 /* pack quota uid/gid */
3740 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3741 key = (const struct dt_key *)&oti->oti_quota_id;
3742 /* pack quota record */
3743 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3744 iam_rec = (struct iam_rec *)rec;
3746 iam_rec = (struct iam_rec *)rec;
3749 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3751 osd_ipd_put(env, bag, ipd);
3752 LINVRNT(osd_invariant(obj));
3757 * Calls ldiskfs_add_entry() to add directory entry
3758 * into the directory. This is required for
3759 * interoperability mode (b11826)
3761 * \retval 0, on success
3762 * \retval -ve, on error
3764 static int __osd_ea_add_rec(struct osd_thread_info *info,
3765 struct osd_object *pobj, struct inode *cinode,
3766 const char *name, const struct lu_fid *fid,
3767 struct htree_lock *hlock, struct thandle *th)
3769 struct ldiskfs_dentry_param *ldp;
3770 struct dentry *child;
3771 struct osd_thandle *oth;
3774 oth = container_of(th, struct osd_thandle, ot_super);
3775 LASSERT(oth->ot_handle != NULL);
3776 LASSERT(oth->ot_handle->h_transaction != NULL);
3777 LASSERT(pobj->oo_inode);
3779 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3780 if (unlikely(pobj->oo_inode ==
3781 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
3784 osd_get_ldiskfs_dirent_param(ldp, fid);
3785 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3786 child->d_fsdata = (void *)ldp;
3787 ll_vfs_dq_init(pobj->oo_inode);
3788 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3789 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
3790 struct ldiskfs_dir_entry_2 *de;
3791 struct buffer_head *bh;
3794 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
3797 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
3800 if (S_ISDIR(cinode->i_mode))
3801 de->file_type = LDISKFS_DIRENT_LUFID |
3802 LDISKFS_FT_REG_FILE;
3804 de->file_type = LDISKFS_DIRENT_LUFID |
3806 ldiskfs_handle_dirty_metadata(oth->ot_handle,
3817 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3818 * into the directory.Also sets flags into osd object to
3819 * indicate dot and dotdot are created. This is required for
3820 * interoperability mode (b11826)
3822 * \param dir directory for dot and dotdot fixup.
3823 * \param obj child object for linking
3825 * \retval 0, on success
3826 * \retval -ve, on error
3828 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3829 struct osd_object *dir,
3830 struct inode *parent_dir, const char *name,
3831 const struct lu_fid *dot_fid,
3832 const struct lu_fid *dot_dot_fid,
3835 struct inode *inode = dir->oo_inode;
3836 struct osd_thandle *oth;
3839 oth = container_of(th, struct osd_thandle, ot_super);
3840 LASSERT(oth->ot_handle->h_transaction != NULL);
3841 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3843 if (strcmp(name, dot) == 0) {
3844 if (dir->oo_compat_dot_created) {
3847 LASSERT(inode == parent_dir);
3848 dir->oo_compat_dot_created = 1;
3851 } else if (strcmp(name, dotdot) == 0) {
3852 if (!dir->oo_compat_dot_created)
3854 /* in case of rename, dotdot is already created */
3855 if (dir->oo_compat_dotdot_created) {
3856 return __osd_ea_add_rec(info, dir, parent_dir, name,
3857 dot_dot_fid, NULL, th);
3860 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
3861 struct lu_fid tfid = *dot_dot_fid;
3864 result = osd_add_dot_dotdot_internal(info,
3865 dir->oo_inode, parent_dir, dot_fid,
3868 result = osd_add_dot_dotdot_internal(info,
3869 dir->oo_inode, parent_dir, dot_fid,
3874 dir->oo_compat_dotdot_created = 1;
3882 * It will call the appropriate osd_add* function and return the
3883 * value, return by respective functions.
3885 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3886 struct inode *cinode, const char *name,
3887 const struct lu_fid *fid, struct thandle *th)
3889 struct osd_thread_info *info = osd_oti_get(env);
3890 struct htree_lock *hlock;
3893 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3895 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3897 if (hlock != NULL) {
3898 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3901 down_write(&pobj->oo_ext_idx_sem);
3904 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3905 lu_object_fid(&pobj->oo_dt.do_lu),
3908 if (hlock != NULL) {
3909 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3910 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3912 down_write(&pobj->oo_ext_idx_sem);
3915 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
3916 struct lu_fid *tfid = &info->oti_fid;
3920 rc = __osd_ea_add_rec(info, pobj, cinode, name,
3923 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3928 ldiskfs_htree_unlock(hlock);
3930 up_write(&pobj->oo_ext_idx_sem);
3936 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3937 struct osd_idmap_cache *oic)
3939 struct osd_scrub *scrub = &dev->od_scrub;
3940 struct lu_fid *fid = &oic->oic_fid;
3941 struct osd_inode_id *id = &oti->oti_id;
3946 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3949 if (scrub->os_pos_current > id->oii_ino)
3953 rc = osd_oi_lookup(oti, dev, fid, id, OI_CHECK_FLD);
3954 if (rc != 0 && rc != -ENOENT)
3957 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3960 if (thread_is_running(&scrub->os_thread)) {
3961 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3962 /* There is race condition between osd_oi_lookup and OI scrub.
3963 * The OI scrub finished just after osd_oi_lookup() failure.
3964 * Under such case, it is unnecessary to trigger OI scrub again,
3965 * but try to call osd_oi_lookup() again. */
3966 if (unlikely(rc == -EAGAIN))
3972 if (!dev->od_noscrub && ++once == 1) {
3973 rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN |
3975 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC "
3976 "for "DFID", rc = %d [2]\n",
3977 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3979 if (rc == 0 || rc == -EALREADY)
3986 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
3987 struct osd_device *dev,
3988 struct osd_idmap_cache *oic,
3989 struct lu_fid *fid, __u32 ino)
3991 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
3992 struct inode *inode;
3995 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3996 inode = osd_iget(oti, dev, &oic->oic_lid);
3997 if (IS_ERR(inode)) {
3998 fid_zero(&oic->oic_fid);
3999 return PTR_ERR(inode);
4002 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, lma);
4005 fid_zero(&oic->oic_fid);
4007 *fid = oic->oic_fid = lma->lma_self_fid;
4011 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
4012 struct osd_inode_id *id, const struct lu_fid *fid)
4014 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
4015 id->oii_ino, id->oii_gen, info);
4016 info->oti_cache.oic_lid = *id;
4017 info->oti_cache.oic_fid = *fid;
4018 info->oti_cache.oic_dev = osd;
4022 * Get parent FID from the linkEA.
4024 * For a directory which parent resides on remote MDT, to satisfy the
4025 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
4026 * the other hand, to make the lookup(..) on the directory can return
4027 * the real parent FID, we append the real parent FID after its ".."
4028 * name entry in the /REMOTE_PARENT_DIR.
4030 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
4031 * backup. So after the restore, we cannot get the right parent FID from
4032 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
4033 * we have stored the real parent FID in the directory object's linkEA,
4034 * we can parse the linkEA for the real parent FID.
4036 * \param[in] env pointer to the thread context
4037 * \param[in] obj pointer to the object to be handled
4038 * \param[out]fid pointer to the buffer to hold the parent FID
4040 * \retval 0 for getting the real parent FID successfully
4041 * \retval negative error number on failure
4043 static int osd_get_pfid_from_linkea(const struct lu_env *env,
4044 struct osd_object *obj,
4047 struct osd_thread_info *oti = osd_oti_get(env);
4048 struct lu_buf *buf = &oti->oti_big_buf;
4049 struct dentry *dentry = &oti->oti_obj_dentry;
4050 struct inode *inode = obj->oo_inode;
4051 struct linkea_data ldata = { NULL };
4056 if (!S_ISDIR(inode->i_mode))
4060 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4061 buf->lb_buf, buf->lb_len);
4062 if (rc == -ERANGE) {
4063 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4066 lu_buf_realloc(buf, rc);
4067 if (buf->lb_buf == NULL)
4074 if (unlikely(rc == 0))
4080 if (unlikely(buf->lb_buf == NULL)) {
4081 lu_buf_realloc(buf, rc);
4082 if (buf->lb_buf == NULL)
4089 rc = linkea_init(&ldata);
4091 linkea_first_entry(&ldata);
4092 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
4099 * Calls ->lookup() to find dentry. From dentry get inode and
4100 * read inode's ea to get fid. This is required for interoperability
4103 * \retval 0, on success
4104 * \retval -ve, on error
4106 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
4107 struct dt_rec *rec, const struct dt_key *key)
4109 struct inode *dir = obj->oo_inode;
4110 struct dentry *dentry;
4111 struct ldiskfs_dir_entry_2 *de;
4112 struct buffer_head *bh;
4113 struct lu_fid *fid = (struct lu_fid *) rec;
4114 struct htree_lock *hlock = NULL;
4119 LASSERT(dir->i_op != NULL);
4120 LASSERT(dir->i_op->lookup != NULL);
4122 dentry = osd_child_dentry_get(env, obj,
4123 (char *)key, strlen((char *)key));
4125 if (obj->oo_hl_head != NULL) {
4126 hlock = osd_oti_get(env)->oti_hlock;
4127 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4128 dir, LDISKFS_HLOCK_LOOKUP);
4130 down_read(&obj->oo_ext_idx_sem);
4133 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4135 struct osd_thread_info *oti = osd_oti_get(env);
4136 struct osd_inode_id *id = &oti->oti_id;
4137 struct osd_idmap_cache *oic = &oti->oti_cache;
4138 struct osd_device *dev = osd_obj2dev(obj);
4140 ino = le32_to_cpu(de->inode);
4141 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
4143 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
4147 rc = osd_get_fid_from_dentry(de, rec);
4149 /* done with de, release bh */
4152 if (unlikely(ino == osd_remote_parent_ino(dev))) {
4153 const char *name = (const char *)key;
4155 /* If the parent is on remote MDT, and there
4156 * is no FID-in-dirent, then we have to get
4157 * the parent FID from the linkEA. */
4158 if (likely(strlen(name) == 2 &&
4159 name[0] == '.' && name[1] == '.'))
4160 rc = osd_get_pfid_from_linkea(env, obj,
4163 rc = osd_ea_fid_get(env, obj, ino, fid, id);
4166 osd_id_gen(id, ino, OSD_OII_NOGEN);
4170 fid_zero(&oic->oic_fid);
4174 if (osd_remote_fid(env, dev, fid))
4177 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
4178 osd_consistency_check(oti, dev, oic);
4187 ldiskfs_htree_unlock(hlock);
4189 up_read(&obj->oo_ext_idx_sem);
4194 * Find the osd object for given fid.
4196 * \param fid need to find the osd object having this fid
4198 * \retval osd_object on success
4199 * \retval -ve on error
4201 static struct osd_object *osd_object_find(const struct lu_env *env,
4202 struct dt_object *dt,
4203 const struct lu_fid *fid)
4205 struct lu_device *ludev = dt->do_lu.lo_dev;
4206 struct osd_object *child = NULL;
4207 struct lu_object *luch;
4208 struct lu_object *lo;
4211 * at this point topdev might not exist yet
4212 * (i.e. MGS is preparing profiles). so we can
4213 * not rely on topdev and instead lookup with
4214 * our device passed as topdev. this can't work
4215 * if the object isn't cached yet (as osd doesn't
4216 * allocate lu_header). IOW, the object must be
4217 * in the cache, otherwise lu_object_alloc() crashes
4220 luch = lu_object_find_at(env, ludev->ld_site->ls_top_dev == NULL ?
4221 ludev : ludev->ld_site->ls_top_dev,
4223 if (!IS_ERR(luch)) {
4224 if (lu_object_exists(luch)) {
4225 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
4227 child = osd_obj(lo);
4229 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4230 "lu_object can't be located"
4231 DFID"\n", PFID(fid));
4233 if (child == NULL) {
4234 lu_object_put(env, luch);
4235 CERROR("Unable to get osd_object\n");
4236 child = ERR_PTR(-ENOENT);
4239 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4240 "lu_object does not exists "DFID"\n",
4242 lu_object_put(env, luch);
4243 child = ERR_PTR(-ENOENT);
4246 child = ERR_CAST(luch);
4253 * Put the osd object once done with it.
4255 * \param obj osd object that needs to be put
4257 static inline void osd_object_put(const struct lu_env *env,
4258 struct osd_object *obj)
4260 lu_object_put(env, &obj->oo_dt.do_lu);
4263 static int osd_index_declare_ea_insert(const struct lu_env *env,
4264 struct dt_object *dt,
4265 const struct dt_rec *rec,
4266 const struct dt_key *key,
4267 struct thandle *handle)
4269 struct osd_thandle *oh;
4270 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4271 struct lu_fid *fid = (struct lu_fid *)rec;
4275 LASSERT(!dt_object_remote(dt));
4276 LASSERT(handle != NULL);
4278 oh = container_of0(handle, struct osd_thandle, ot_super);
4279 LASSERT(oh->ot_handle == NULL);
4281 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4282 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4284 if (osd_dt_obj(dt)->oo_inode != NULL) {
4285 struct inode *inode = osd_dt_obj(dt)->oo_inode;
4287 /* We ignore block quota on meta pool (MDTs), so needn't
4288 * calculate how many blocks will be consumed by this index
4290 rc = osd_declare_inode_qid(env, i_uid_read(inode),
4291 i_gid_read(inode), 0, oh,
4292 osd_dt_obj(dt), true, NULL, false);
4298 rc = osd_remote_fid(env, osd, fid);
4304 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
4305 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
4306 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4307 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4308 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4309 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4315 * Index add function for interoperability mode (b11826).
4316 * It will add the directory entry.This entry is needed to
4317 * maintain name->fid mapping.
4319 * \param key it is key i.e. file entry to be inserted
4320 * \param rec it is value of given key i.e. fid
4322 * \retval 0, on success
4323 * \retval -ve, on error
4325 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
4326 const struct dt_rec *rec,
4327 const struct dt_key *key, struct thandle *th,
4330 struct osd_object *obj = osd_dt_obj(dt);
4331 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4332 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4333 const struct lu_fid *fid = rec1->rec_fid;
4334 const char *name = (const char *)key;
4335 struct osd_thread_info *oti = osd_oti_get(env);
4336 struct osd_inode_id *id = &oti->oti_id;
4337 struct inode *child_inode = NULL;
4338 struct osd_object *child = NULL;
4342 if (!dt_object_exists(dt))
4345 LASSERT(osd_invariant(obj));
4346 LASSERT(!dt_object_remote(dt));
4347 LASSERT(th != NULL);
4349 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4351 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
4353 rc = osd_remote_fid(env, osd, fid);
4355 CERROR("%s: Can not find object "DFID" rc %d\n",
4356 osd_name(osd), PFID(fid), rc);
4361 /* Insert remote entry */
4362 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
4363 struct osd_mdobj_map *omm = osd->od_mdt_map;
4364 struct osd_thandle *oh;
4366 /* If parent on remote MDT, we need put this object
4368 oh = container_of(th, typeof(*oh), ot_super);
4369 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4371 CERROR("%s: add "DFID" error: rc = %d\n",
4373 PFID(lu_object_fid(&dt->do_lu)), rc);
4377 child_inode = igrab(omm->omm_remote_parent->d_inode);
4379 child_inode = osd_create_local_agent_inode(env, osd,
4380 obj, fid, rec1->rec_type & S_IFMT, th);
4381 if (IS_ERR(child_inode))
4382 RETURN(PTR_ERR(child_inode));
4385 /* Insert local entry */
4386 child = osd_object_find(env, dt, fid);
4387 if (IS_ERR(child)) {
4388 CERROR("%s: Can not find object "DFID"%u:%u: rc = %d\n",
4389 osd_name(osd), PFID(fid),
4390 id->oii_ino, id->oii_gen,
4391 (int)PTR_ERR(child));
4392 RETURN(PTR_ERR(child));
4394 child_inode = igrab(child->oo_inode);
4397 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
4399 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
4400 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
4404 osd_object_put(env, child);
4405 LASSERT(osd_invariant(obj));
4410 * Initialize osd Iterator for given osd index object.
4412 * \param dt osd index object
4415 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
4416 struct dt_object *dt,
4419 struct osd_it_iam *it;
4420 struct osd_object *obj = osd_dt_obj(dt);
4421 struct lu_object *lo = &dt->do_lu;
4422 struct iam_path_descr *ipd;
4423 struct iam_container *bag = &obj->oo_dir->od_container;
4425 if (!dt_object_exists(dt))
4426 return ERR_PTR(-ENOENT);
4430 return ERR_PTR(-ENOMEM);
4432 ipd = osd_it_ipd_get(env, bag);
4433 if (likely(ipd != NULL)) {
4437 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
4438 return (struct dt_it *)it;
4441 return ERR_PTR(-ENOMEM);
4446 * free given Iterator.
4449 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
4451 struct osd_it_iam *it = (struct osd_it_iam *)di;
4452 struct osd_object *obj = it->oi_obj;
4454 iam_it_fini(&it->oi_it);
4455 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
4456 lu_object_put(env, &obj->oo_dt.do_lu);
4461 * Move Iterator to record specified by \a key
4463 * \param di osd iterator
4464 * \param key key for index
4466 * \retval +ve di points to record with least key not larger than key
4467 * \retval 0 di points to exact matched key
4468 * \retval -ve failure
4471 static int osd_it_iam_get(const struct lu_env *env,
4472 struct dt_it *di, const struct dt_key *key)
4474 struct osd_thread_info *oti = osd_oti_get(env);
4475 struct osd_it_iam *it = (struct osd_it_iam *)di;
4477 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4478 /* swab quota uid/gid */
4479 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4480 key = (struct dt_key *)&oti->oti_quota_id;
4483 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
4489 * \param di osd iterator
4491 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
4493 struct osd_it_iam *it = (struct osd_it_iam *)di;
4495 iam_it_put(&it->oi_it);
4499 * Move iterator by one record
4501 * \param di osd iterator
4503 * \retval +1 end of container reached
4505 * \retval -ve failure
4508 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
4510 struct osd_it_iam *it = (struct osd_it_iam *)di;
4512 return iam_it_next(&it->oi_it);
4516 * Return pointer to the key under iterator.
4519 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
4520 const struct dt_it *di)
4522 struct osd_thread_info *oti = osd_oti_get(env);
4523 struct osd_it_iam *it = (struct osd_it_iam *)di;
4524 struct osd_object *obj = it->oi_obj;
4527 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
4529 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
4530 /* swab quota uid/gid */
4531 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
4532 key = (struct dt_key *)&oti->oti_quota_id;
4539 * Return size of key under iterator (in bytes)
4542 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
4544 struct osd_it_iam *it = (struct osd_it_iam *)di;
4546 return iam_it_key_size(&it->oi_it);
4550 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
4552 /* check if file type is required */
4553 if (ent->lde_attrs & LUDA_TYPE) {
4554 struct luda_type *lt;
4555 int align = sizeof(*lt) - 1;
4557 len = (len + align) & ~align;
4558 lt = (struct luda_type *)(ent->lde_name + len);
4559 lt->lt_type = cpu_to_le16(DTTOIF(type));
4562 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
4566 * build lu direct from backend fs dirent.
4570 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
4571 char *name, __u16 namelen, __u16 type, __u32 attr)
4573 ent->lde_attrs = attr | LUDA_FID;
4574 fid_cpu_to_le(&ent->lde_fid, fid);
4576 ent->lde_hash = cpu_to_le64(offset);
4577 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
4579 strncpy(ent->lde_name, name, namelen);
4580 ent->lde_name[namelen] = '\0';
4581 ent->lde_namelen = cpu_to_le16(namelen);
4583 /* append lustre attributes */
4584 osd_it_append_attrs(ent, namelen, type);
4588 * Return pointer to the record under iterator.
4590 static int osd_it_iam_rec(const struct lu_env *env,
4591 const struct dt_it *di,
4592 struct dt_rec *dtrec, __u32 attr)
4594 struct osd_it_iam *it = (struct osd_it_iam *)di;
4595 struct osd_thread_info *info = osd_oti_get(env);
4598 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
4599 const struct osd_fid_pack *rec;
4600 struct lu_fid *fid = &info->oti_fid;
4601 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4607 name = (char *)iam_it_key_get(&it->oi_it);
4609 RETURN(PTR_ERR(name));
4611 namelen = iam_it_key_size(&it->oi_it);
4613 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
4615 RETURN(PTR_ERR(rec));
4617 rc = osd_fid_unpack(fid, rec);
4621 hash = iam_it_store(&it->oi_it);
4623 /* IAM does not store object type in IAM index (dir) */
4624 osd_it_pack_dirent(lde, fid, hash, name, namelen,
4626 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4627 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4628 (struct iam_rec *)dtrec);
4629 osd_quota_unpack(it->oi_obj, dtrec);
4631 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4632 (struct iam_rec *)dtrec);
4639 * Returns cookie for current Iterator position.
4641 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
4643 struct osd_it_iam *it = (struct osd_it_iam *)di;
4645 return iam_it_store(&it->oi_it);
4649 * Restore iterator from cookie.
4651 * \param di osd iterator
4652 * \param hash Iterator location cookie
4654 * \retval +ve di points to record with least key not larger than key.
4655 * \retval 0 di points to exact matched key
4656 * \retval -ve failure
4659 static int osd_it_iam_load(const struct lu_env *env,
4660 const struct dt_it *di, __u64 hash)
4662 struct osd_it_iam *it = (struct osd_it_iam *)di;
4664 return iam_it_load(&it->oi_it, hash);
4667 static const struct dt_index_operations osd_index_iam_ops = {
4668 .dio_lookup = osd_index_iam_lookup,
4669 .dio_declare_insert = osd_index_declare_iam_insert,
4670 .dio_insert = osd_index_iam_insert,
4671 .dio_declare_delete = osd_index_declare_iam_delete,
4672 .dio_delete = osd_index_iam_delete,
4674 .init = osd_it_iam_init,
4675 .fini = osd_it_iam_fini,
4676 .get = osd_it_iam_get,
4677 .put = osd_it_iam_put,
4678 .next = osd_it_iam_next,
4679 .key = osd_it_iam_key,
4680 .key_size = osd_it_iam_key_size,
4681 .rec = osd_it_iam_rec,
4682 .store = osd_it_iam_store,
4683 .load = osd_it_iam_load
4689 * Creates or initializes iterator context.
4691 * \retval struct osd_it_ea, iterator structure on success
4694 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
4695 struct dt_object *dt,
4698 struct osd_object *obj = osd_dt_obj(dt);
4699 struct osd_thread_info *info = osd_oti_get(env);
4700 struct osd_it_ea *oie;
4702 struct lu_object *lo = &dt->do_lu;
4703 struct dentry *obj_dentry;
4706 if (!dt_object_exists(dt))
4707 RETURN(ERR_PTR(-ENOENT));
4709 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
4711 RETURN(ERR_PTR(-ENOMEM));
4712 obj_dentry = &oie->oie_dentry;
4714 obj_dentry->d_inode = obj->oo_inode;
4715 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
4716 obj_dentry->d_name.hash = 0;
4718 oie->oie_rd_dirent = 0;
4719 oie->oie_it_dirent = 0;
4720 oie->oie_dirent = NULL;
4721 if (unlikely(!info->oti_it_ea_buf_used)) {
4722 oie->oie_buf = info->oti_it_ea_buf;
4723 info->oti_it_ea_buf_used = 1;
4725 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4726 if (oie->oie_buf == NULL)
4727 RETURN(ERR_PTR(-ENOMEM));
4731 file = &oie->oie_file;
4733 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
4734 if (attr & LUDA_64BITHASH)
4735 file->f_mode = FMODE_64BITHASH;
4737 file->f_mode = FMODE_32BITHASH;
4738 file->f_dentry = obj_dentry;
4739 file->f_mapping = obj->oo_inode->i_mapping;
4740 file->f_op = obj->oo_inode->i_fop;
4741 set_file_inode(file, obj->oo_inode);
4744 RETURN((struct dt_it *) oie);
4748 * Destroy or finishes iterator context.
4750 * \param di iterator structure to be destroyed
4752 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
4754 struct osd_thread_info *info = osd_oti_get(env);
4755 struct osd_it_ea *oie = (struct osd_it_ea *)di;
4756 struct osd_object *obj = oie->oie_obj;
4757 struct inode *inode = obj->oo_inode;
4760 oie->oie_file.f_op->release(inode, &oie->oie_file);
4761 lu_object_put(env, &obj->oo_dt.do_lu);
4762 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
4763 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4765 info->oti_it_ea_buf_used = 0;
4766 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
4771 * It position the iterator at given key, so that next lookup continues from
4772 * that key Or it is similar to dio_it->load() but based on a key,
4773 * rather than file position.
4775 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4778 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4780 static int osd_it_ea_get(const struct lu_env *env,
4781 struct dt_it *di, const struct dt_key *key)
4783 struct osd_it_ea *it = (struct osd_it_ea *)di;
4786 LASSERT(((const char *)key)[0] == '\0');
4787 it->oie_file.f_pos = 0;
4788 it->oie_rd_dirent = 0;
4789 it->oie_it_dirent = 0;
4790 it->oie_dirent = NULL;
4798 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4802 struct osd_filldir_cbs {
4803 #ifdef HAVE_DIR_CONTEXT
4804 struct dir_context ctx;
4806 struct osd_it_ea *it;
4809 * It is called internally by ->readdir(). It fills the
4810 * iterator's in-memory data structure with required
4811 * information i.e. name, namelen, rec_size etc.
4813 * \param buf in which information to be filled in.
4814 * \param name name of the file in given dir
4816 * \retval 0 on success
4817 * \retval 1 on buffer full
4819 static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen,
4820 loff_t offset, __u64 ino,
4823 struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it;
4824 struct osd_object *obj = it->oie_obj;
4825 struct osd_it_ea_dirent *ent = it->oie_dirent;
4826 struct lu_fid *fid = &ent->oied_fid;
4827 struct osd_fid_pack *rec;
4830 /* this should never happen */
4831 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4832 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4836 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4840 /* "." is just the object itself. */
4841 if (namelen == 1 && name[0] == '.') {
4842 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4843 } else if (d_type & LDISKFS_DIRENT_LUFID) {
4844 rec = (struct osd_fid_pack*) (name + namelen + 1);
4845 if (osd_fid_unpack(fid, rec) != 0)
4850 d_type &= ~LDISKFS_DIRENT_LUFID;
4852 /* NOT export local root. */
4853 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
4854 ino = obj->oo_inode->i_ino;
4855 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4858 ent->oied_ino = ino;
4859 ent->oied_off = offset;
4860 ent->oied_namelen = namelen;
4861 ent->oied_type = d_type;
4863 memcpy(ent->oied_name, name, namelen);
4865 it->oie_rd_dirent++;
4866 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4871 * Calls ->readdir() to load a directory entry at a time
4872 * and stored it in iterator's in-memory data structure.
4874 * \param di iterator's in memory structure
4876 * \retval 0 on success
4877 * \retval -ve on error
4878 * \retval +1 reach the end of entry
4880 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4881 const struct dt_it *di)
4883 struct osd_it_ea *it = (struct osd_it_ea *)di;
4884 struct osd_object *obj = it->oie_obj;
4885 struct inode *inode = obj->oo_inode;
4886 struct htree_lock *hlock = NULL;
4887 struct file *filp = &it->oie_file;
4889 struct osd_filldir_cbs buf = {
4890 #ifdef HAVE_DIR_CONTEXT
4891 .ctx.actor = osd_ldiskfs_filldir,
4897 it->oie_dirent = it->oie_buf;
4898 it->oie_rd_dirent = 0;
4900 if (obj->oo_hl_head != NULL) {
4901 hlock = osd_oti_get(env)->oti_hlock;
4902 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4903 inode, LDISKFS_HLOCK_READDIR);
4905 down_read(&obj->oo_ext_idx_sem);
4908 #ifdef HAVE_DIR_CONTEXT
4909 buf.ctx.pos = filp->f_pos;
4910 rc = inode->i_fop->iterate(filp, &buf.ctx);
4911 filp->f_pos = buf.ctx.pos;
4913 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
4917 ldiskfs_htree_unlock(hlock);
4919 up_read(&obj->oo_ext_idx_sem);
4921 if (it->oie_rd_dirent == 0) {
4922 /*If it does not get any dirent, it means it has been reached
4923 *to the end of the dir */
4924 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
4928 it->oie_dirent = it->oie_buf;
4929 it->oie_it_dirent = 1;
4936 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4937 * to load a directory entry at a time and stored it in
4938 * iterator's in-memory data structure.
4940 * \param di iterator's in memory structure
4942 * \retval +ve iterator reached to end
4943 * \retval 0 iterator not reached to end
4944 * \retval -ve on error
4946 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4948 struct osd_it_ea *it = (struct osd_it_ea *)di;
4953 if (it->oie_it_dirent < it->oie_rd_dirent) {
4955 (void *) it->oie_dirent +
4956 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4957 it->oie_dirent->oied_namelen);
4958 it->oie_it_dirent++;
4961 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4964 rc = osd_ldiskfs_it_fill(env, di);
4971 * Returns the key at current position from iterator's in memory structure.
4973 * \param di iterator's in memory structure
4975 * \retval key i.e. struct dt_key on success
4977 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4978 const struct dt_it *di)
4980 struct osd_it_ea *it = (struct osd_it_ea *)di;
4982 return (struct dt_key *)it->oie_dirent->oied_name;
4986 * Returns the key's size at current position from iterator's in memory structure.
4988 * \param di iterator's in memory structure
4990 * \retval key_size i.e. struct dt_key on success
4992 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4994 struct osd_it_ea *it = (struct osd_it_ea *)di;
4996 return it->oie_dirent->oied_namelen;
5000 osd_dirent_update(handle_t *jh, struct super_block *sb,
5001 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
5002 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de)
5004 struct osd_fid_pack *rec;
5008 LASSERT(de->file_type & LDISKFS_DIRENT_LUFID);
5009 LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack));
5011 rc = ldiskfs_journal_get_write_access(jh, bh);
5015 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5016 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
5017 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5023 osd_dirent_has_space(__u16 reclen, __u16 namelen, unsigned blocksize)
5025 if (ldiskfs_rec_len_from_disk(reclen, blocksize) >=
5026 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
5033 osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot)
5035 LASSERTF(dot_dotdot == 1 || dot_dotdot == 2,
5036 "dot_dotdot = %d\n", dot_dotdot);
5038 if (LDISKFS_DIR_REC_LEN(de) >=
5039 __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack)))
5046 osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
5047 struct inode *dir, struct inode *inode,
5048 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
5049 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de,
5050 struct htree_lock *hlock)
5052 struct dentry *dentry;
5053 struct osd_fid_pack *rec;
5054 struct ldiskfs_dentry_param *ldp;
5058 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
5059 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5062 /* There is enough space to hold the FID-in-dirent. */
5063 if (osd_dirent_has_space(de->rec_len, ent->oied_namelen,
5064 dir->i_sb->s_blocksize)) {
5065 rc = ldiskfs_journal_get_write_access(jh, bh);
5069 de->name[de->name_len] = 0;
5070 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5071 rec->fp_len = sizeof(struct lu_fid) + 1;
5072 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
5073 de->file_type |= LDISKFS_DIRENT_LUFID;
5075 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5080 rc = ldiskfs_delete_entry(jh, dir, de, bh);
5084 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
5086 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
5087 osd_get_ldiskfs_dirent_param(ldp, fid);
5088 dentry->d_fsdata = (void *)ldp;
5089 ll_vfs_dq_init(dir);
5090 rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock);
5091 /* It is too bad, we cannot reinsert the name entry back.
5092 * That means we lose it! */
5094 CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
5095 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
5096 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
5097 dir->i_ino, dir->i_generation,
5098 ent->oied_namelen, ent->oied_name, PFID(fid), rc);
5104 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
5105 struct osd_it_ea *it, struct lu_fid *fid,
5106 struct osd_inode_id *id, __u32 *attr)
5108 struct osd_thread_info *info = osd_oti_get(env);
5109 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
5110 struct osd_device *dev = osd_obj2dev(obj);
5111 struct super_block *sb = osd_sb(dev);
5112 const char *devname =
5113 LDISKFS_SB(sb)->s_es->s_volume_name;
5114 struct osd_it_ea_dirent *ent = it->oie_dirent;
5115 struct inode *dir = obj->oo_inode;
5116 struct htree_lock *hlock = NULL;
5117 struct buffer_head *bh = NULL;
5118 handle_t *jh = NULL;
5119 struct ldiskfs_dir_entry_2 *de;
5120 struct dentry *dentry;
5121 struct inode *inode;
5128 if (ent->oied_name[0] == '.') {
5129 if (ent->oied_namelen == 1)
5131 else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
5135 dentry = osd_child_dentry_get(env, obj, ent->oied_name,
5138 /* We need to ensure that the name entry is still valid.
5139 * Because it may be removed or renamed by other already.
5141 * The unlink or rename operation will start journal before PDO lock,
5142 * so to avoid deadlock, here we need to start journal handle before
5143 * related PDO lock also. But because we do not know whether there
5144 * will be something to be repaired before PDO lock, we just start
5145 * journal without conditions.
5147 * We may need to remove the name entry firstly, then insert back.
5148 * One credit is for user quota file update.
5149 * One credit is for group quota file update.
5150 * Two credits are for dirty inode. */
5151 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
5152 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
5155 if (dev->od_dirent_journal != 0) {
5156 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
5159 CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
5160 "check_repair, dir = %lu/%u, credits = %d, "
5161 "name = %.*s: rc = %d\n",
5162 devname, dir->i_ino, dir->i_generation, credits,
5163 ent->oied_namelen, ent->oied_name, rc);
5167 if (obj->oo_hl_head != NULL) {
5168 hlock = osd_oti_get(env)->oti_hlock;
5169 /* "0" means exclusive lock for the whole directory.
5170 * We need to prevent others access such name entry
5171 * during the delete + insert. Neither HLOCK_ADD nor
5172 * HLOCK_DEL cannot guarantee the atomicity. */
5173 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
5175 down_write(&obj->oo_ext_idx_sem);
5178 if (obj->oo_hl_head != NULL) {
5179 hlock = osd_oti_get(env)->oti_hlock;
5180 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
5181 LDISKFS_HLOCK_LOOKUP);
5183 down_read(&obj->oo_ext_idx_sem);
5187 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5188 /* For dot/dotdot entry, if there is not enough space to hold the
5189 * FID-in-dirent, just keep them there. It only happens when the
5190 * device upgraded from 1.8 or restored from MDT file-level backup.
5191 * For the whole directory, only dot/dotdot entry have no FID-in-dirent
5192 * and needs to get FID from LMA when readdir, it will not affect the
5193 * performance much. */
5194 if ((bh == NULL) || (le32_to_cpu(de->inode) != ent->oied_ino) ||
5195 (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
5196 *attr |= LUDA_IGNORE;
5197 GOTO(out_journal, rc = 0);
5200 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
5201 inode = osd_iget(info, dev, id);
5202 if (IS_ERR(inode)) {
5203 rc = PTR_ERR(inode);
5204 if (rc == -ENOENT || rc == -ESTALE)
5207 CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
5208 "check_repair, dir = %lu/%u, name = %.*s: "
5210 devname, dir->i_ino, dir->i_generation,
5211 ent->oied_namelen, ent->oied_name, rc);
5213 GOTO(out_journal, rc);
5216 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
5218 LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI));
5220 if (fid_is_sane(fid)) {
5221 /* FID-in-dirent is valid. */
5222 if (lu_fid_eq(fid, &lma->lma_self_fid))
5223 GOTO(out_inode, rc = 0);
5225 /* Do not repair under dryrun mode. */
5226 if (*attr & LUDA_VERIFY_DRYRUN) {
5227 *attr |= LUDA_REPAIR;
5228 GOTO(out_inode, rc = 0);
5231 if (dev->od_dirent_journal == 0) {
5235 ldiskfs_htree_unlock(hlock);
5237 up_read(&obj->oo_ext_idx_sem);
5238 dev->od_dirent_journal = 1;
5242 *fid = lma->lma_self_fid;
5244 /* Update the FID-in-dirent. */
5245 rc = osd_dirent_update(jh, sb, ent, fid, bh, de);
5247 *attr |= LUDA_REPAIR;
5249 CDEBUG(D_LFSCK, "%.16s: fail to update FID "
5250 "in the dirent, dir = %lu/%u, "
5251 "name = %.*s, "DFID": rc = %d\n",
5252 devname, dir->i_ino, dir->i_generation,
5253 ent->oied_namelen, ent->oied_name,
5256 /* Do not repair under dryrun mode. */
5257 if (*attr & LUDA_VERIFY_DRYRUN) {
5258 *fid = lma->lma_self_fid;
5259 *attr |= LUDA_REPAIR;
5260 GOTO(out_inode, rc = 0);
5263 if (dev->od_dirent_journal == 0) {
5267 ldiskfs_htree_unlock(hlock);
5269 up_read(&obj->oo_ext_idx_sem);
5270 dev->od_dirent_journal = 1;
5274 *fid = lma->lma_self_fid;
5276 /* Append the FID-in-dirent. */
5277 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5278 fid, bh, de, hlock);
5280 *attr |= LUDA_REPAIR;
5282 CDEBUG(D_LFSCK, "%.16s: fail to append FID "
5283 "after the dirent, dir = %lu/%u, "
5284 "name = %.*s, "DFID": rc = %d\n",
5285 devname, dir->i_ino, dir->i_generation,
5286 ent->oied_namelen, ent->oied_name,
5289 } else if (rc == -ENODATA) {
5290 /* Do not repair under dryrun mode. */
5291 if (*attr & LUDA_VERIFY_DRYRUN) {
5292 if (fid_is_sane(fid)) {
5293 *attr |= LUDA_REPAIR;
5295 lu_igif_build(fid, inode->i_ino,
5296 inode->i_generation);
5297 *attr |= LUDA_UPGRADE;
5299 GOTO(out_inode, rc = 0);
5302 if (dev->od_dirent_journal == 0) {
5306 ldiskfs_htree_unlock(hlock);
5308 up_read(&obj->oo_ext_idx_sem);
5309 dev->od_dirent_journal = 1;
5314 if (unlikely(fid_is_sane(fid))) {
5315 /* FID-in-dirent exists, but FID-in-LMA is lost.
5316 * Trust the FID-in-dirent, and add FID-in-LMA. */
5317 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
5319 *attr |= LUDA_REPAIR;
5321 CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
5322 "update dirent, dir = %lu/%u, "
5323 "name = %.*s, "DFID": rc = %d\n",
5324 devname, dir->i_ino, dir->i_generation,
5325 ent->oied_namelen, ent->oied_name,
5328 lu_igif_build(fid, inode->i_ino, inode->i_generation);
5329 /* It is probably IGIF object. Only aappend the
5330 * FID-in-dirent. OI scrub will process FID-in-LMA. */
5331 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5332 fid, bh, de, hlock);
5334 *attr |= LUDA_UPGRADE;
5336 CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
5337 "after the dirent, dir = %lu/%u, "
5338 "name = %.*s, "DFID": rc = %d\n",
5339 devname, dir->i_ino, dir->i_generation,
5340 ent->oied_namelen, ent->oied_name,
5345 GOTO(out_inode, rc);
5352 if (hlock != NULL) {
5353 ldiskfs_htree_unlock(hlock);
5355 if (dev->od_dirent_journal != 0)
5356 up_write(&obj->oo_ext_idx_sem);
5358 up_read(&obj->oo_ext_idx_sem);
5361 ldiskfs_journal_stop(jh);
5362 if (rc >= 0 && !dirty)
5363 dev->od_dirent_journal = 0;
5368 * Returns the value at current position from iterator's in memory structure.
5370 * \param di struct osd_it_ea, iterator's in memory structure
5371 * \param attr attr requested for dirent.
5372 * \param lde lustre dirent
5374 * \retval 0 no error and \param lde has correct lustre dirent.
5375 * \retval -ve on error
5377 static inline int osd_it_ea_rec(const struct lu_env *env,
5378 const struct dt_it *di,
5379 struct dt_rec *dtrec, __u32 attr)
5381 struct osd_it_ea *it = (struct osd_it_ea *)di;
5382 struct osd_object *obj = it->oie_obj;
5383 struct osd_device *dev = osd_obj2dev(obj);
5384 struct osd_thread_info *oti = osd_oti_get(env);
5385 struct osd_inode_id *id = &oti->oti_id;
5386 struct lu_fid *fid = &it->oie_dirent->oied_fid;
5387 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5388 __u32 ino = it->oie_dirent->oied_ino;
5392 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
5394 if (attr & LUDA_VERIFY) {
5395 if (unlikely(ino == osd_remote_parent_ino(dev))) {
5396 attr |= LUDA_IGNORE;
5397 /* If the parent is on remote MDT, and there
5398 * is no FID-in-dirent, then we have to get
5399 * the parent FID from the linkEA. */
5400 if (!fid_is_sane(fid) &&
5401 it->oie_dirent->oied_namelen == 2 &&
5402 it->oie_dirent->oied_name[0] == '.' &&
5403 it->oie_dirent->oied_name[1] == '.')
5404 osd_get_pfid_from_linkea(env, obj, fid);
5406 rc = osd_dirent_check_repair(env, obj, it, fid, id,
5410 attr &= ~LU_DIRENT_ATTRS_MASK;
5411 if (!fid_is_sane(fid)) {
5412 if (it->oie_dirent->oied_namelen == 2 &&
5413 it->oie_dirent->oied_name[0] == '.' &&
5414 it->oie_dirent->oied_name[1] == '.') {
5415 /* If the parent is on remote MDT, and there
5416 * is no FID-in-dirent, then we have to get
5417 * the parent FID from the linkEA. */
5418 if (ino == osd_remote_parent_ino(dev))
5419 rc = osd_get_pfid_from_linkea(env, obj,
5422 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
5425 rc = osd_ea_fid_get(env, obj, ino, fid, id);
5428 osd_id_gen(id, ino, OSD_OII_NOGEN);
5432 /* Pack the entry anyway, at least the offset is right. */
5433 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
5434 it->oie_dirent->oied_name,
5435 it->oie_dirent->oied_namelen,
5436 it->oie_dirent->oied_type, attr);
5441 if (osd_remote_fid(env, dev, fid))
5444 if (likely(!(attr & LUDA_IGNORE) && rc == 0))
5445 osd_add_oi_cache(oti, dev, id, fid);
5447 RETURN(rc > 0 ? 0 : rc);
5451 * Returns the record size size at current position.
5453 * This function will return record(lu_dirent) size in bytes.
5455 * \param[in] env execution environment
5456 * \param[in] di iterator's in memory structure
5457 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
5458 * calculate the lu_dirent size.
5460 * \retval record size(in bytes & in memory) of the current lu_dirent
5463 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
5466 struct osd_it_ea *it = (struct osd_it_ea *)di;
5468 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
5472 * Returns a cookie for current position of the iterator head, so that
5473 * user can use this cookie to load/start the iterator next time.
5475 * \param di iterator's in memory structure
5477 * \retval cookie for current position, on success
5479 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
5481 struct osd_it_ea *it = (struct osd_it_ea *)di;
5483 return it->oie_dirent->oied_off;
5487 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
5488 * to load a directory entry at a time and stored it i inn,
5489 * in iterator's in-memory data structure.
5491 * \param di struct osd_it_ea, iterator's in memory structure
5493 * \retval +ve on success
5494 * \retval -ve on error
5496 static int osd_it_ea_load(const struct lu_env *env,
5497 const struct dt_it *di, __u64 hash)
5499 struct osd_it_ea *it = (struct osd_it_ea *)di;
5503 it->oie_file.f_pos = hash;
5505 rc = osd_ldiskfs_it_fill(env, di);
5516 * Index lookup function for interoperability mode (b11826).
5518 * \param key, key i.e. file name to be searched
5520 * \retval +ve, on success
5521 * \retval -ve, on error
5523 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
5524 struct dt_rec *rec, const struct dt_key *key)
5526 struct osd_object *obj = osd_dt_obj(dt);
5531 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
5532 LINVRNT(osd_invariant(obj));
5534 rc = osd_ea_lookup_rec(env, obj, rec, key);
5541 * Index and Iterator operations for interoperability
5542 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
5544 static const struct dt_index_operations osd_index_ea_ops = {
5545 .dio_lookup = osd_index_ea_lookup,
5546 .dio_declare_insert = osd_index_declare_ea_insert,
5547 .dio_insert = osd_index_ea_insert,
5548 .dio_declare_delete = osd_index_declare_ea_delete,
5549 .dio_delete = osd_index_ea_delete,
5551 .init = osd_it_ea_init,
5552 .fini = osd_it_ea_fini,
5553 .get = osd_it_ea_get,
5554 .put = osd_it_ea_put,
5555 .next = osd_it_ea_next,
5556 .key = osd_it_ea_key,
5557 .key_size = osd_it_ea_key_size,
5558 .rec = osd_it_ea_rec,
5559 .rec_size = osd_it_ea_rec_size,
5560 .store = osd_it_ea_store,
5561 .load = osd_it_ea_load
5565 static void *osd_key_init(const struct lu_context *ctx,
5566 struct lu_context_key *key)
5568 struct osd_thread_info *info;
5570 OBD_ALLOC_PTR(info);
5572 return ERR_PTR(-ENOMEM);
5574 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5575 if (info->oti_it_ea_buf == NULL)
5578 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
5580 info->oti_hlock = ldiskfs_htree_lock_alloc();
5581 if (info->oti_hlock == NULL)
5587 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5590 return ERR_PTR(-ENOMEM);
5593 static void osd_key_fini(const struct lu_context *ctx,
5594 struct lu_context_key *key, void* data)
5596 struct osd_thread_info *info = data;
5598 if (info->oti_inode != NULL)
5599 OBD_FREE_PTR(info->oti_inode);
5600 if (info->oti_hlock != NULL)
5601 ldiskfs_htree_lock_free(info->oti_hlock);
5602 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5603 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
5604 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
5605 lu_buf_free(&info->oti_big_buf);
5609 static void osd_key_exit(const struct lu_context *ctx,
5610 struct lu_context_key *key, void *data)
5612 struct osd_thread_info *info = data;
5614 LASSERT(info->oti_r_locks == 0);
5615 LASSERT(info->oti_w_locks == 0);
5616 LASSERT(info->oti_txns == 0);
5619 /* type constructor/destructor: osd_type_init, osd_type_fini */
5620 LU_TYPE_INIT_FINI(osd, &osd_key);
5622 struct lu_context_key osd_key = {
5623 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
5624 .lct_init = osd_key_init,
5625 .lct_fini = osd_key_fini,
5626 .lct_exit = osd_key_exit
5630 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
5631 const char *name, struct lu_device *next)
5633 struct osd_device *osd = osd_dev(d);
5635 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
5636 >= sizeof(osd->od_svname))
5638 return osd_procfs_init(osd, name);
5641 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
5643 struct seq_server_site *ss = osd_seq_site(osd);
5647 if (osd->od_is_ost || osd->od_cl_seq != NULL)
5650 if (unlikely(ss == NULL))
5653 OBD_ALLOC_PTR(osd->od_cl_seq);
5654 if (osd->od_cl_seq == NULL)
5657 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
5658 osd->od_svname, ss->ss_server_seq);
5661 OBD_FREE_PTR(osd->od_cl_seq);
5662 osd->od_cl_seq = NULL;
5668 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
5670 if (osd->od_cl_seq == NULL)
5673 seq_client_fini(osd->od_cl_seq);
5674 OBD_FREE_PTR(osd->od_cl_seq);
5675 osd->od_cl_seq = NULL;
5678 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
5682 /* shutdown quota slave instance associated with the device */
5683 if (o->od_quota_slave != NULL) {
5684 qsd_fini(env, o->od_quota_slave);
5685 o->od_quota_slave = NULL;
5688 osd_fid_fini(env, o);
5693 static void osd_umount(const struct lu_env *env, struct osd_device *o)
5697 if (o->od_mnt != NULL) {
5698 shrink_dcache_sb(osd_sb(o));
5699 osd_sync(env, &o->od_dt_dev);
5708 static int osd_mount(const struct lu_env *env,
5709 struct osd_device *o, struct lustre_cfg *cfg)
5711 const char *name = lustre_cfg_string(cfg, 0);
5712 const char *dev = lustre_cfg_string(cfg, 1);
5714 unsigned long page, s_flags, lmd_flags = 0;
5715 struct page *__page;
5716 struct file_system_type *type;
5717 char *options = NULL;
5719 struct osd_thread_info *info = osd_oti_get(env);
5720 struct lu_fid *fid = &info->oti_fid;
5721 struct inode *inode;
5722 int rc = 0, force_over_128tb = 0;
5725 if (o->od_mnt != NULL)
5728 if (strlen(dev) >= sizeof(o->od_mntdev))
5730 strcpy(o->od_mntdev, dev);
5732 str = lustre_cfg_string(cfg, 2);
5733 s_flags = simple_strtoul(str, NULL, 0);
5734 str = strstr(str, ":");
5736 lmd_flags = simple_strtoul(str + 1, NULL, 0);
5737 opts = lustre_cfg_string(cfg, 3);
5739 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
5740 CERROR("%s: device %s extents feature is not guaranteed to "
5741 "work on big-endian systems. Use \"bigendian_extents\" "
5742 "mount option to override.\n", name, dev);
5746 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
5747 force_over_128tb = 1;
5749 OBD_PAGE_ALLOC(__page, GFP_IOFS);
5751 GOTO(out, rc = -ENOMEM);
5752 page = (unsigned long)page_address(__page);
5753 options = (char *)page;
5756 /* strip out the options for back compatiblity */
5757 static char *sout[] = {
5764 /* strip out option we processed in osd */
5765 "bigendian_extents",
5769 strcat(options, opts);
5770 for (rc = 0, str = options; sout[rc]; ) {
5771 char *op = strstr(str, sout[rc]);
5777 if (op == options || *(op - 1) == ',') {
5778 str = op + strlen(sout[rc]);
5779 if (*str == ',' || *str == '\0') {
5780 *str == ',' ? str++ : str;
5781 memmove(op, str, strlen(str) + 1);
5784 for (str = op; *str != ',' && *str != '\0'; str++)
5788 strncat(options, "user_xattr,acl", 14);
5791 /* Glom up mount options */
5792 if (*options != '\0')
5793 strcat(options, ",");
5794 strlcat(options, "no_mbcache", PAGE_CACHE_SIZE);
5796 type = get_fs_type("ldiskfs");
5798 CERROR("%s: cannot find ldiskfs module\n", name);
5799 GOTO(out, rc = -ENODEV);
5802 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
5803 module_put(type->owner);
5805 if (IS_ERR(o->od_mnt)) {
5806 rc = PTR_ERR(o->od_mnt);
5808 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
5812 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (8ULL << 32) &&
5813 force_over_128tb == 0) {
5814 CERROR("%s: device %s LDISKFS does not support filesystems "
5815 "greater than 128TB and can cause data corruption. "
5816 "Use \"force_over_128tb\" mount option to override.\n",
5818 GOTO(out, rc = -EINVAL);
5821 #ifdef HAVE_DEV_SET_RDONLY
5822 if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
5823 CERROR("%s: underlying device %s is marked as read-only. "
5824 "Setup failed\n", name, dev);
5825 GOTO(out_mnt, rc = -EROFS);
5829 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
5830 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
5831 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
5832 GOTO(out_mnt, rc = -EINVAL);
5835 #ifdef LDISKFS_MOUNT_DIRDATA
5836 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
5837 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5838 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
5839 else if (!o->od_is_ost)
5840 CWARN("%s: device %s was upgraded from Lustre-1.x without "
5841 "enabling the dirdata feature. If you do not want to "
5842 "downgrade to Lustre-1.x again, you can enable it via "
5843 "'tune2fs -O dirdata device'\n", name, dev);
5845 inode = osd_sb(o)->s_root->d_inode;
5846 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
5847 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
5849 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
5853 if (lmd_flags & LMD_FLG_NOSCRUB)
5864 OBD_PAGE_FREE(__page);
5869 static struct lu_device *osd_device_fini(const struct lu_env *env,
5870 struct lu_device *d)
5872 struct osd_device *o = osd_dev(d);
5875 osd_shutdown(env, o);
5877 osd_scrub_cleanup(env, o);
5878 osd_obj_map_fini(o);
5884 static int osd_device_init0(const struct lu_env *env,
5885 struct osd_device *o,
5886 struct lustre_cfg *cfg)
5888 struct lu_device *l = osd2lu_dev(o);
5889 struct osd_thread_info *info;
5893 /* if the module was re-loaded, env can loose its keys */
5894 rc = lu_env_refill((struct lu_env *) env);
5897 info = osd_oti_get(env);
5900 l->ld_ops = &osd_lu_ops;
5901 o->od_dt_dev.dd_ops = &osd_dt_ops;
5903 spin_lock_init(&o->od_osfs_lock);
5904 mutex_init(&o->od_otable_mutex);
5906 o->od_read_cache = 1;
5907 o->od_writethrough_cache = 1;
5908 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
5910 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
5911 sizeof(o->od_svname));
5912 if (cplen >= sizeof(o->od_svname)) {
5917 if (server_name_is_ost(o->od_svname))
5920 o->od_full_scrub_ratio = OFSR_DEFAULT;
5921 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
5922 rc = osd_mount(env, o, cfg);
5926 rc = osd_obj_map_init(env, o);
5930 rc = lu_site_init(&o->od_site, l);
5932 GOTO(out_compat, rc);
5933 o->od_site.ls_bottom_dev = l;
5935 rc = lu_site_init_finish(&o->od_site);
5939 INIT_LIST_HEAD(&o->od_ios_list);
5940 /* setup scrub, including OI files initialization */
5941 rc = osd_scrub_setup(env, o);
5945 rc = osd_procfs_init(o, o->od_svname);
5947 CERROR("%s: can't initialize procfs: rc = %d\n",
5949 GOTO(out_scrub, rc);
5952 LASSERT(l->ld_site->ls_linkage.next != NULL);
5953 LASSERT(l->ld_site->ls_linkage.prev != NULL);
5955 /* initialize quota slave instance */
5956 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
5958 if (IS_ERR(o->od_quota_slave)) {
5959 rc = PTR_ERR(o->od_quota_slave);
5960 o->od_quota_slave = NULL;
5961 GOTO(out_procfs, rc);
5969 osd_scrub_cleanup(env, o);
5971 lu_site_fini(&o->od_site);
5973 osd_obj_map_fini(o);
5980 static struct lu_device *osd_device_alloc(const struct lu_env *env,
5981 struct lu_device_type *t,
5982 struct lustre_cfg *cfg)
5984 struct osd_device *o;
5989 return ERR_PTR(-ENOMEM);
5991 rc = dt_device_init(&o->od_dt_dev, t);
5993 /* Because the ctx might be revived in dt_device_init,
5994 * refill the env here */
5995 lu_env_refill((struct lu_env *)env);
5996 rc = osd_device_init0(env, o, cfg);
5998 dt_device_fini(&o->od_dt_dev);
6001 if (unlikely(rc != 0))
6004 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
6007 static struct lu_device *osd_device_free(const struct lu_env *env,
6008 struct lu_device *d)
6010 struct osd_device *o = osd_dev(d);
6013 /* XXX: make osd top device in order to release reference */
6014 d->ld_site->ls_top_dev = d;
6015 lu_site_purge(env, d->ld_site, -1);
6016 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
6017 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
6018 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
6020 lu_site_fini(&o->od_site);
6021 dt_device_fini(&o->od_dt_dev);
6026 static int osd_process_config(const struct lu_env *env,
6027 struct lu_device *d, struct lustre_cfg *cfg)
6029 struct osd_device *o = osd_dev(d);
6033 switch (cfg->lcfg_command) {
6035 rc = osd_mount(env, o, cfg);
6038 lu_dev_del_linkage(d->ld_site, d);
6039 rc = osd_shutdown(env, o);
6042 LASSERT(&o->od_dt_dev);
6043 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
6044 cfg, &o->od_dt_dev);
6045 if (rc > 0 || rc == -ENOSYS)
6046 rc = class_process_proc_param(PARAM_OST,
6047 lprocfs_osd_obd_vars,
6048 cfg, &o->od_dt_dev);
6057 static int osd_recovery_complete(const struct lu_env *env,
6058 struct lu_device *d)
6060 struct osd_device *osd = osd_dev(d);
6064 if (osd->od_quota_slave == NULL)
6067 /* start qsd instance on recovery completion, this notifies the quota
6068 * slave code that we are about to process new requests now */
6069 rc = qsd_start(env, osd->od_quota_slave);
6074 * we use exports to track all osd users
6076 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
6077 struct obd_device *obd, struct obd_uuid *cluuid,
6078 struct obd_connect_data *data, void *localdata)
6080 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6081 struct lustre_handle conn;
6085 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
6087 rc = class_connect(&conn, obd, cluuid);
6091 *exp = class_conn2export(&conn);
6093 spin_lock(&osd->od_osfs_lock);
6095 spin_unlock(&osd->od_osfs_lock);
6101 * once last export (we don't count self-export) disappeared
6102 * osd can be released
6104 static int osd_obd_disconnect(struct obd_export *exp)
6106 struct obd_device *obd = exp->exp_obd;
6107 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6108 int rc, release = 0;
6111 /* Only disconnect the underlying layers on the final disconnect. */
6112 spin_lock(&osd->od_osfs_lock);
6114 if (osd->od_connects == 0)
6116 spin_unlock(&osd->od_osfs_lock);
6118 rc = class_disconnect(exp); /* bz 9811 */
6120 if (rc == 0 && release)
6121 class_manual_cleanup(obd);
6125 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
6126 struct lu_device *dev)
6128 struct osd_device *osd = osd_dev(dev);
6129 struct lr_server_data *lsd =
6130 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
6134 if (osd->od_quota_slave != NULL) {
6135 /* set up quota slave objects */
6136 result = qsd_prepare(env, osd->od_quota_slave);
6141 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
6142 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
6143 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
6144 osd->od_index_in_idif = 1;
6146 osd->od_index_in_idif = 0;
6147 result = osd_register_proc_index_in_idif(osd);
6152 osd->od_index_in_idif = 1;
6156 result = osd_fid_init(env, osd);
6161 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
6162 struct lu_fid *fid, struct md_op_data *op_data)
6164 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
6166 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
6169 static const struct lu_object_operations osd_lu_obj_ops = {
6170 .loo_object_init = osd_object_init,
6171 .loo_object_delete = osd_object_delete,
6172 .loo_object_release = osd_object_release,
6173 .loo_object_free = osd_object_free,
6174 .loo_object_print = osd_object_print,
6175 .loo_object_invariant = osd_object_invariant
6178 const struct lu_device_operations osd_lu_ops = {
6179 .ldo_object_alloc = osd_object_alloc,
6180 .ldo_process_config = osd_process_config,
6181 .ldo_recovery_complete = osd_recovery_complete,
6182 .ldo_prepare = osd_prepare,
6185 static const struct lu_device_type_operations osd_device_type_ops = {
6186 .ldto_init = osd_type_init,
6187 .ldto_fini = osd_type_fini,
6189 .ldto_start = osd_type_start,
6190 .ldto_stop = osd_type_stop,
6192 .ldto_device_alloc = osd_device_alloc,
6193 .ldto_device_free = osd_device_free,
6195 .ldto_device_init = osd_device_init,
6196 .ldto_device_fini = osd_device_fini
6199 static struct lu_device_type osd_device_type = {
6200 .ldt_tags = LU_DEVICE_DT,
6201 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
6202 .ldt_ops = &osd_device_type_ops,
6203 .ldt_ctx_tags = LCT_LOCAL,
6206 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
6208 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6209 struct super_block *sb = osd_sb(osd);
6211 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
6215 * lprocfs legacy support.
6217 static struct obd_ops osd_obd_device_ops = {
6218 .o_owner = THIS_MODULE,
6219 .o_connect = osd_obd_connect,
6220 .o_disconnect = osd_obd_disconnect,
6221 .o_fid_alloc = osd_fid_alloc,
6222 .o_health_check = osd_health_check,
6225 static int __init osd_mod_init(void)
6229 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
6230 /* please, try to keep osd_thread_info smaller than a page */
6231 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
6236 rc = lu_kmem_init(ldiskfs_caches);
6240 rc = class_register_type(&osd_obd_device_ops, NULL, true,
6241 lprocfs_osd_module_vars,
6242 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
6244 lu_kmem_fini(ldiskfs_caches);
6248 static void __exit osd_mod_exit(void)
6250 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
6251 lu_kmem_fini(ldiskfs_caches);
6254 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6255 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
6256 MODULE_VERSION(LUSTRE_VERSION_STRING);
6257 MODULE_LICENSE("GPL");
6259 module_init(osd_mod_init);
6260 module_exit(osd_mod_exit);