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, 2015, 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>
63 #include <ldiskfs/ldiskfs_extents.h>
66 * struct OBD_{ALLOC,FREE}*()
69 #include <obd_support.h>
70 /* struct ptlrpc_thread */
71 #include <lustre_net.h>
72 #include <lustre_fid.h>
74 #include <lustre_param.h>
76 #include "osd_internal.h"
77 #include "osd_dynlocks.h"
79 /* llo_* api support */
80 #include <md_object.h>
81 #include <lustre_quota.h>
83 #include <lustre_linkea.h>
86 module_param(ldiskfs_pdo, int, 0644);
87 MODULE_PARM_DESC(ldiskfs_pdo, "ldiskfs with parallel directory operations");
89 int ldiskfs_track_declares_assert;
90 module_param(ldiskfs_track_declares_assert, int, 0644);
91 MODULE_PARM_DESC(ldiskfs_track_declares_assert, "LBUG during tracking of declares");
93 /* Slab to allocate dynlocks */
94 struct kmem_cache *dynlock_cachep;
96 /* Slab to allocate osd_it_ea */
97 struct kmem_cache *osd_itea_cachep;
99 static struct lu_kmem_descr ldiskfs_caches[] = {
101 .ckd_cache = &dynlock_cachep,
102 .ckd_name = "dynlock_cache",
103 .ckd_size = sizeof(struct dynlock_handle)
106 .ckd_cache = &osd_itea_cachep,
107 .ckd_name = "osd_itea_cache",
108 .ckd_size = sizeof(struct osd_it_ea)
115 static const char dot[] = ".";
116 static const char dotdot[] = "..";
117 static const char remote_obj_dir[] = "REM_OBJ_DIR";
119 static const struct lu_object_operations osd_lu_obj_ops;
120 static const struct dt_object_operations osd_obj_ops;
121 static const struct dt_object_operations osd_obj_ea_ops;
122 static const struct dt_object_operations osd_obj_otable_it_ops;
123 static const struct dt_index_operations osd_index_iam_ops;
124 static const struct dt_index_operations osd_index_ea_ops;
126 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
127 const struct lu_fid *fid);
128 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
129 struct osd_device *osd);
131 int osd_trans_declare_op2rb[] = {
132 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
133 [OSD_OT_PUNCH] = OSD_OT_MAX,
134 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
135 [OSD_OT_CREATE] = OSD_OT_DESTROY,
136 [OSD_OT_DESTROY] = OSD_OT_CREATE,
137 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
138 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
139 [OSD_OT_WRITE] = OSD_OT_WRITE,
140 [OSD_OT_INSERT] = OSD_OT_DELETE,
141 [OSD_OT_DELETE] = OSD_OT_INSERT,
142 [OSD_OT_QUOTA] = OSD_OT_MAX,
145 static int osd_has_index(const struct osd_object *obj)
147 return obj->oo_dt.do_index_ops != NULL;
150 static int osd_object_invariant(const struct lu_object *l)
152 return osd_invariant(osd_obj(l));
156 * Concurrency: doesn't matter
160 * Concurrency: doesn't matter
162 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
164 struct osd_thread_info *oti = osd_oti_get(env);
165 return oti->oti_w_locks > 0 && o->oo_owner == env;
169 * Concurrency: doesn't access mutable data
171 static int osd_root_get(const struct lu_env *env,
172 struct dt_device *dev, struct lu_fid *f)
174 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
179 * the following set of functions are used to maintain per-thread
180 * cache of FID->ino mapping. this mechanism is needed to resolve
181 * FID to inode at dt_insert() which in turn stores ino in the
182 * directory entries to keep ldiskfs compatible with ext[34].
183 * due to locking-originated restrictions we can't lookup ino
184 * using LU cache (deadlock is possible). lookup using OI is quite
185 * expensive. so instead we maintain this cache and methods like
186 * dt_create() fill it. so in the majority of cases dt_insert() is
187 * able to find needed mapping in lockless manner.
189 static struct osd_idmap_cache *
190 osd_idc_find(const struct lu_env *env, struct osd_device *osd,
191 const struct lu_fid *fid)
193 struct osd_thread_info *oti = osd_oti_get(env);
194 struct osd_idmap_cache *idc = oti->oti_ins_cache;
196 for (i = 0; i < oti->oti_ins_cache_used; i++) {
197 if (!lu_fid_eq(&idc[i].oic_fid, fid))
199 if (idc[i].oic_dev != osd)
208 static struct osd_idmap_cache *
209 osd_idc_add(const struct lu_env *env, struct osd_device *osd,
210 const struct lu_fid *fid)
212 struct osd_thread_info *oti = osd_oti_get(env);
213 struct osd_idmap_cache *idc;
216 if (unlikely(oti->oti_ins_cache_used >= oti->oti_ins_cache_size)) {
217 i = oti->oti_ins_cache_size * 2;
219 i = OSD_INS_CACHE_SIZE;
220 OBD_ALLOC(idc, sizeof(*idc) * i);
222 return ERR_PTR(-ENOMEM);
223 if (oti->oti_ins_cache != NULL) {
224 memcpy(idc, oti->oti_ins_cache,
225 oti->oti_ins_cache_used * sizeof(*idc));
226 OBD_FREE(oti->oti_ins_cache,
227 oti->oti_ins_cache_used * sizeof(*idc));
229 oti->oti_ins_cache = idc;
230 oti->oti_ins_cache_size = i;
233 idc = oti->oti_ins_cache + oti->oti_ins_cache_used++;
236 idc->oic_lid.oii_ino = 0;
237 idc->oic_lid.oii_gen = 0;
244 * lookup mapping for the given fid in the cache, initialize a
245 * new one if not found. the initialization checks whether the
246 * object is local or remote. for local objects, OI is used to
247 * learn ino/generation. the function is used when the caller
248 * has no information about the object, e.g. at dt_insert().
250 static struct osd_idmap_cache *
251 osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd,
252 const struct lu_fid *fid)
254 struct osd_idmap_cache *idc;
257 idc = osd_idc_find(env, osd, fid);
258 LASSERT(!IS_ERR(idc));
262 /* new mapping is needed */
263 idc = osd_idc_add(env, osd, fid);
268 rc = osd_remote_fid(env, osd, fid);
269 if (unlikely(rc < 0))
273 /* the object is local, lookup in OI */
274 /* XXX: probably cheaper to lookup in LU first? */
275 rc = osd_oi_lookup(osd_oti_get(env), osd, fid,
277 if (unlikely(rc < 0)) {
278 CERROR("can't lookup: rc = %d\n", rc);
282 /* the object is remote */
290 * lookup mapping for given FID and fill it from the given object.
291 * the object is lolcal by definition.
293 static int osd_idc_find_and_init(const struct lu_env *env,
294 struct osd_device *osd,
295 struct osd_object *obj)
297 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
298 struct osd_idmap_cache *idc;
300 idc = osd_idc_find(env, osd, fid);
301 LASSERT(!IS_ERR(idc));
303 if (obj->oo_inode == NULL)
305 if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) {
306 LASSERT(idc->oic_lid.oii_ino == 0);
307 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
308 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
313 /* new mapping is needed */
314 idc = osd_idc_add(env, osd, fid);
318 if (obj->oo_inode != NULL) {
319 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
320 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
326 * OSD object methods.
330 * Concurrency: no concurrent access is possible that early in object
333 static struct lu_object *osd_object_alloc(const struct lu_env *env,
334 const struct lu_object_header *hdr,
337 struct osd_object *mo;
343 l = &mo->oo_dt.do_lu;
344 dt_object_init(&mo->oo_dt, NULL, d);
345 mo->oo_dt.do_ops = &osd_obj_ea_ops;
346 l->lo_ops = &osd_lu_obj_ops;
347 init_rwsem(&mo->oo_sem);
348 init_rwsem(&mo->oo_ext_idx_sem);
349 spin_lock_init(&mo->oo_guard);
350 INIT_LIST_HEAD(&mo->oo_xattr_list);
357 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
358 struct dentry *dentry, struct lustre_mdt_attrs *lma)
362 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
363 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
364 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
366 if ((void *)lma != (void *)info->oti_mdt_attrs_old)
367 memcpy(lma, info->oti_mdt_attrs_old, sizeof(*lma));
369 lustre_lma_swab(lma);
370 /* Check LMA compatibility */
371 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
372 CWARN("%.16s: unsupported incompat LMA feature(s) %#x "
373 "for fid = "DFID", ino = %lu\n",
374 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
375 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
376 PFID(&lma->lma_self_fid), inode->i_ino);
379 } else if (rc == 0) {
387 * retrieve object from backend ext fs.
389 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
390 struct osd_inode_id *id)
392 struct inode *inode = NULL;
394 /* if we look for an inode withing a running
395 * transaction, then we risk to deadlock */
396 /* osd_dirent_check_repair() breaks this */
397 /*LASSERT(current->journal_info == NULL);*/
399 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
401 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
402 id->oii_ino, PTR_ERR(inode));
403 } else if (id->oii_gen != OSD_OII_NOGEN &&
404 inode->i_generation != id->oii_gen) {
405 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
406 "i_generation = %u\n",
407 id->oii_ino, id->oii_gen, inode->i_generation);
409 inode = ERR_PTR(-ESTALE);
410 } else if (inode->i_nlink == 0) {
411 /* due to parallel readdir and unlink,
412 * we can have dead inode here. */
413 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
415 inode = ERR_PTR(-ESTALE);
416 } else if (is_bad_inode(inode)) {
417 CWARN("%.16s: bad inode: ino = %u\n",
418 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
420 inode = ERR_PTR(-ENOENT);
422 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
423 if (id->oii_gen == OSD_OII_NOGEN)
424 osd_id_gen(id, inode->i_ino, inode->i_generation);
426 /* Do not update file c/mtime in ldiskfs.
427 * NB: we don't have any lock to protect this because we don't
428 * have reference on osd_object now, but contention with
429 * another lookup + attr_set can't happen in the tiny window
430 * between if (...) and set S_NOCMTIME. */
431 if (!(inode->i_flags & S_NOCMTIME))
432 inode->i_flags |= S_NOCMTIME;
437 int osd_ldiskfs_add_entry(struct osd_thread_info *info,
438 handle_t *handle, struct dentry *child,
439 struct inode *inode, struct htree_lock *hlock)
443 rc = __ldiskfs_add_entry(handle, child, inode, hlock);
444 if (rc == -ENOBUFS || rc == -ENOSPC) {
445 char fidbuf[FID_LEN + 1];
446 struct lustre_mdt_attrs lma;
447 struct lu_fid fid = { };
449 struct dentry *p_dentry = child->d_parent;
451 rc2 = osd_get_lma(info, p_dentry->d_inode, p_dentry,
454 fid = lma.lma_self_fid;
455 snprintf(fidbuf, sizeof(fidbuf), DFID, PFID(&fid));
456 } else if (rc2 == -ENODATA) {
457 if (unlikely(p_dentry->d_inode ==
458 inode->i_sb->s_root->d_inode))
459 lu_local_obj_fid(&fid, OSD_FS_ROOT_OID);
460 else if (info->oti_dev && !info->oti_dev->od_is_ost &&
461 fid_seq_is_mdt0(fid_seq(&fid)))
462 lu_igif_build(&fid, p_dentry->d_inode->i_ino,
463 p_dentry->d_inode->i_generation);
464 snprintf(fidbuf, sizeof(fidbuf), DFID, PFID(&fid));
466 snprintf(fidbuf, FID_LEN, "%s", "unknown");
470 errstr = "has reached";
472 errstr = "is approaching";
473 CWARN("%.16s: directory (inode: %lu FID: %s) %s maximum entry limit\n",
474 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
475 p_dentry->d_inode->i_ino, fidbuf, errstr);
476 /* ignore such error now */
484 static struct inode *
485 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
486 struct osd_inode_id *id, struct lu_fid *fid)
488 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
492 inode = osd_iget(info, dev, id);
496 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
498 *fid = lma->lma_self_fid;
499 } else if (rc == -ENODATA) {
500 if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
501 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
503 lu_igif_build(fid, inode->i_ino, inode->i_generation);
511 static struct inode *osd_iget_check(struct osd_thread_info *info,
512 struct osd_device *dev,
513 const struct lu_fid *fid,
514 struct osd_inode_id *id,
521 /* The cached OI mapping is trustable. If we cannot locate the inode
522 * via the cached OI mapping, then return the failure to the caller
523 * directly without further OI checking. */
525 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
528 if (cached || (rc != -ENOENT && rc != -ESTALE)) {
529 CDEBUG(D_INODE, "no inode: ino = %u, rc = %d\n",
538 if (is_bad_inode(inode)) {
541 CDEBUG(D_INODE, "bad inode: ino = %u\n", id->oii_ino);
549 if (id->oii_gen != OSD_OII_NOGEN &&
550 inode->i_generation != id->oii_gen) {
553 CDEBUG(D_INODE, "unmatched inode: ino = %u, "
554 "oii_gen = %u, i_generation = %u\n",
555 id->oii_ino, id->oii_gen, inode->i_generation);
563 if (inode->i_nlink == 0) {
566 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
574 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
578 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
580 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
581 /* XXX: There are four possible cases:
583 * Backup/restore caused the OI invalid.
585 * Someone unlinked the object but NOT removed
586 * the OI mapping, such as mount target device
587 * as ldiskfs, and modify something directly.
589 * Someone just removed the object between the
590 * former oi_lookup and the iget. It is normal.
591 * 4. Other failure cases.
593 * Generally, when the device is mounted, it will
594 * auto check whether the system is restored from
595 * file-level backup or not. We trust such detect
596 * to distinguish the 1st case from the 2nd case. */
598 if (!IS_ERR(inode) && inode->i_generation != 0 &&
599 inode->i_generation == id->oii_gen)
600 /* "id->oii_gen != OSD_OII_NOGEN" is for
601 * "@cached == false" case. */
606 /* If the OI mapping was in OI file before the
607 * osd_iget_check(), but now, it is disappear,
608 * then it must be removed by race. That is a
609 * normal race case. */
612 if (id->oii_gen == OSD_OII_NOGEN)
613 osd_id_gen(id, inode->i_ino, inode->i_generation);
615 /* Do not update file c/mtime in ldiskfs.
616 * NB: we don't have any lock to protect this because we don't
617 * have reference on osd_object now, but contention with
618 * another lookup + attr_set can't happen in the tiny window
619 * between if (...) and set S_NOCMTIME. */
620 if (!(inode->i_flags & S_NOCMTIME))
621 inode->i_flags |= S_NOCMTIME;
638 * \retval +v: new filter_fid, does not contain self-fid
639 * \retval 0: filter_fid_old, contains self-fid
640 * \retval -v: other failure cases
642 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
643 struct dentry *dentry, struct lu_fid *fid)
645 struct filter_fid_old *ff = &info->oti_ff;
646 struct ost_id *ostid = &info->oti_ostid;
649 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
650 if (rc == sizeof(*ff)) {
652 ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
653 ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
654 /* XXX: use 0 as the index for compatibility, the caller will
655 * handle index related issues when necessarry. */
656 ostid_to_fid(fid, ostid, 0);
657 } else if (rc == sizeof(struct filter_fid)) {
659 } else if (rc >= 0) {
666 static int osd_lma_self_repair(struct osd_thread_info *info,
667 struct osd_device *osd, struct inode *inode,
668 const struct lu_fid *fid, __u32 compat)
673 LASSERT(current->journal_info == NULL);
675 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
676 osd_dto_credits_noquota[DTO_XATTR_SET]);
679 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
684 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
686 CWARN("%s: cannot self repair the LMA: rc = %d\n",
688 ldiskfs_journal_stop(jh);
692 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
694 struct osd_thread_info *info = osd_oti_get(env);
695 struct osd_device *osd = osd_obj2dev(obj);
696 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
697 struct inode *inode = obj->oo_inode;
698 struct dentry *dentry = &info->oti_obj_dentry;
699 struct lu_fid *fid = NULL;
700 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
704 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
705 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
706 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
707 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
708 fid = &lma->lma_self_fid;
709 rc = osd_get_idif(info, inode, dentry, fid);
710 if ((rc > 0) || (rc == -ENODATA && osd->od_index_in_idif)) {
711 /* For the given OST-object, if it has neither LMA nor
712 * FID in XATTR_NAME_FID, then the given FID (which is
713 * contained in the @obj, from client RPC for locating
714 * the OST-object) is trusted. We use it to generate
716 osd_lma_self_repair(info, osd, inode, rfid,
727 lustre_lma_swab(lma);
728 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
729 CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
730 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
731 "fid = "DFID", ino = %lu\n", osd_name(osd),
732 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
733 PFID(rfid), inode->i_ino);
736 fid = &lma->lma_self_fid;
740 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
741 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
742 struct ost_id *oi = &info->oti_ostid;
743 struct lu_fid *fid1 = &info->oti_fid3;
744 __u32 idx = fid_idif_ost_idx(rfid);
746 /* For old IDIF, the OST index is not part of the IDIF,
747 * Means that different OSTs may have the same IDIFs.
748 * Under such case, we need to make some compatible
749 * check to make sure to trigger OI scrub properly. */
750 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
751 /* Given @rfid is new, LMA is old. */
752 fid_to_ostid(fid, oi);
753 ostid_to_fid(fid1, oi, idx);
754 if (lu_fid_eq(fid1, rfid)) {
755 if (osd->od_index_in_idif)
756 osd_lma_self_repair(info, osd,
770 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
771 const struct lu_fid *fid,
772 const struct lu_object_conf *conf)
774 struct osd_thread_info *info;
775 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
776 struct osd_device *dev;
777 struct osd_idmap_cache *oic;
778 struct osd_inode_id *id;
779 struct inode *inode = NULL;
780 struct osd_scrub *scrub;
781 struct scrub_file *sf;
782 __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT |
790 LINVRNT(osd_invariant(obj));
791 LASSERT(obj->oo_inode == NULL);
792 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
795 scrub = &dev->od_scrub;
796 sf = &scrub->os_file;
797 info = osd_oti_get(env);
799 oic = &info->oti_cache;
801 if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
804 /* For the object is created as locking anchor, or for the object to
805 * be created on disk. No need to osd_oi_lookup() at here because FID
806 * shouldn't never be re-used, if it's really a duplicate FID from
807 * unexpected reason, we should be able to detect it later by calling
808 * do_create->osd_oi_insert(). */
809 if (conf != NULL && conf->loc_flags & LOC_F_NEW)
810 GOTO(out, result = 0);
812 /* Search order: 1. per-thread cache. */
813 if (lu_fid_eq(fid, &oic->oic_fid) &&
814 likely(oic->oic_dev == dev)) {
820 if (!list_empty(&scrub->os_inconsistent_items)) {
821 /* Search order: 2. OI scrub pending list. */
822 result = osd_oii_lookup(dev, fid, id);
828 /* Search order: 3. OI files. */
829 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
830 if (result == -ENOENT) {
831 if (!(fid_is_norm(fid) || fid_is_igif(fid)) ||
832 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
833 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
835 GOTO(out, result = 0);
844 inode = osd_iget_check(info, dev, fid, id, cached);
846 result = PTR_ERR(inode);
847 if (result == -ENOENT || result == -ESTALE)
848 GOTO(out, result = -ENOENT);
850 if (result == -EREMCHG) {
853 /* We still have chance to get the valid inode: for the
854 * object which is referenced by remote name entry, the
855 * object on the local MDT will be linked under the dir
856 * of "/REMOTE_PARENT_DIR" with its FID string as name.
858 * We do not know whether the object for the given FID
859 * is referenced by some remote name entry or not, and
860 * especially for DNE II, a multiple-linked object may
861 * have many name entries reside on many MDTs.
863 * To simplify the operation, OSD will not distinguish
864 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
865 * only happened for the RPC from other MDT during the
866 * OI scrub, or for the client side RPC with FID only,
867 * such as FID to path, or from old connected client. */
869 !fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) {
870 rc1 = osd_lookup_in_remote_parent(info, dev,
875 flags |= SS_AUTO_PARTIAL;
876 flags &= ~SS_AUTO_FULL;
881 if (thread_is_running(&scrub->os_thread)) {
882 if (scrub->os_partial_scan &&
883 !scrub->os_in_join) {
886 if (inode != NULL && !IS_ERR(inode)) {
889 osd_add_oi_cache(info, dev, id,
891 osd_oii_insert(dev, oic, true);
893 result = -EINPROGRESS;
896 } else if (!dev->od_noscrub) {
899 rc1 = osd_scrub_start(dev, flags);
900 LCONSOLE_WARN("%.16s: trigger OI scrub by RPC "
901 "for the "DFID" with flags 0x%x,"
902 " rc = %d\n", osd_name(dev),
903 PFID(fid), flags, rc1);
904 if (rc1 == 0 || rc1 == -EALREADY) {
905 if (inode != NULL && !IS_ERR(inode)) {
908 osd_add_oi_cache(info, dev, id,
910 osd_oii_insert(dev, oic, true);
912 result = -EINPROGRESS;
922 if (inode == NULL || IS_ERR(inode))
928 obj->oo_inode = inode;
929 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
931 result = osd_check_lma(env, obj);
933 if (result == -ENODATA) {
935 result = osd_oi_lookup(info, dev, fid, id,
938 /* result == -ENOENT means that the OI
939 * mapping has been removed by race,
940 * the target inode belongs to other
943 * Others error also can be returned
946 obj->oo_inode = NULL;
949 /* result == 0 means the cached OI
950 * mapping is still in the OI file,
951 * the target the inode is valid. */
954 /* The current OI mapping is from the OI file,
955 * since the inode has been found via
956 * osd_iget_check(), no need recheck OI. */
964 obj->oo_inode = NULL;
965 if (result != -EREMCHG)
969 result = osd_oi_lookup(info, dev, fid, id,
971 /* result == -ENOENT means the cached OI mapping
972 * has been removed from the OI file by race,
973 * above target inode belongs to other object.
975 * Others error also can be returned directly. */
979 /* result == 0, goto trigger */
981 /* The current OI mapping is from the OI file,
982 * since the inode has been found via
983 * osd_iget_check(), no need recheck OI. */
990 obj->oo_compat_dot_created = 1;
991 obj->oo_compat_dotdot_created = 1;
993 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
994 GOTO(out, result = 0);
996 LASSERT(obj->oo_hl_head == NULL);
997 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
998 if (obj->oo_hl_head == NULL) {
999 obj->oo_inode = NULL;
1001 GOTO(out, result = -ENOMEM);
1003 GOTO(out, result = 0);
1006 if (result != 0 && cached)
1007 fid_zero(&oic->oic_fid);
1009 LINVRNT(osd_invariant(obj));
1014 * Concurrency: shouldn't matter.
1016 static void osd_object_init0(struct osd_object *obj)
1018 LASSERT(obj->oo_inode != NULL);
1019 obj->oo_dt.do_body_ops = &osd_body_ops;
1020 obj->oo_dt.do_lu.lo_header->loh_attr |=
1021 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
1025 * Concurrency: no concurrent access is possible that early in object
1028 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
1029 const struct lu_object_conf *conf)
1031 struct osd_object *obj = osd_obj(l);
1034 LINVRNT(osd_invariant(obj));
1036 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
1037 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
1038 l->lo_header->loh_attr |= LOHA_EXISTS;
1042 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
1043 obj->oo_dt.do_body_ops = &osd_body_ops_new;
1044 if (result == 0 && obj->oo_inode != NULL) {
1045 struct osd_thread_info *oti = osd_oti_get(env);
1046 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
1048 osd_object_init0(obj);
1049 result = osd_get_lma(oti, obj->oo_inode,
1050 &oti->oti_obj_dentry, lma);
1052 /* Convert LMAI flags to lustre LMA flags
1053 * and cache it to oo_lma_flags */
1055 lma_to_lustre_flags(lma->lma_incompat);
1056 } else if (result == -ENODATA) {
1061 LINVRNT(osd_invariant(obj));
1065 /* The first part of oxe_buf is xattr name, and is '\0' terminated.
1066 * The left part is for value, binary mode. */
1067 struct osd_xattr_entry {
1068 struct list_head oxe_list;
1072 struct rcu_head oxe_rcu;
1076 static struct osd_xattr_entry *osd_oxc_lookup(struct osd_object *obj,
1080 struct osd_xattr_entry *oxe;
1082 list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) {
1083 if (namelen == oxe->oxe_namelen &&
1084 strncmp(name, oxe->oxe_buf, namelen) == 0)
1091 static int osd_oxc_get(struct osd_object *obj, const char *name,
1094 struct osd_xattr_entry *oxe;
1099 oxe = osd_oxc_lookup(obj, name, strlen(name));
1105 if (!oxe->oxe_exist) {
1110 vallen = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1;
1111 LASSERT(vallen > 0);
1113 if (buf->lb_buf == NULL) {
1118 if (buf->lb_len < vallen) {
1123 memcpy(buf->lb_buf, oxe->oxe_buf + oxe->oxe_namelen + 1, vallen);
1129 static void osd_oxc_free(struct rcu_head *head)
1131 struct osd_xattr_entry *oxe;
1133 oxe = container_of(head, struct osd_xattr_entry, oxe_rcu);
1134 OBD_FREE(oxe, oxe->oxe_len);
1137 static inline void __osd_oxc_del(struct osd_object *obj, const char *name)
1139 struct osd_xattr_entry *oxe;
1141 oxe = osd_oxc_lookup(obj, name, strlen(name));
1143 list_del(&oxe->oxe_list);
1144 call_rcu(&oxe->oxe_rcu, osd_oxc_free);
1148 static void osd_oxc_add(struct osd_object *obj, const char *name,
1149 const char *buf, int buflen)
1151 struct osd_xattr_entry *oxe;
1152 size_t namelen = strlen(name);
1153 size_t len = sizeof(*oxe) + namelen + 1 + buflen;
1155 OBD_ALLOC(oxe, len);
1159 INIT_LIST_HEAD(&oxe->oxe_list);
1161 oxe->oxe_namelen = namelen;
1162 memcpy(oxe->oxe_buf, name, namelen);
1164 LASSERT(buf != NULL);
1165 memcpy(oxe->oxe_buf + namelen + 1, buf, buflen);
1166 oxe->oxe_exist = true;
1168 oxe->oxe_exist = false;
1171 /* this should be rarely called, just remove old and add new */
1172 spin_lock(&obj->oo_guard);
1173 __osd_oxc_del(obj, name);
1174 list_add_tail(&oxe->oxe_list, &obj->oo_xattr_list);
1175 spin_unlock(&obj->oo_guard);
1178 static void osd_oxc_del(struct osd_object *obj, const char *name)
1180 spin_lock(&obj->oo_guard);
1181 __osd_oxc_del(obj, name);
1182 spin_unlock(&obj->oo_guard);
1185 static void osd_oxc_fini(struct osd_object *obj)
1187 struct osd_xattr_entry *oxe, *next;
1189 list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) {
1190 list_del(&oxe->oxe_list);
1191 OBD_FREE(oxe, oxe->oxe_len);
1196 * Concurrency: no concurrent access is possible that late in object
1199 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
1201 struct osd_object *obj = osd_obj(l);
1203 LINVRNT(osd_invariant(obj));
1206 dt_object_fini(&obj->oo_dt);
1207 if (obj->oo_hl_head != NULL)
1208 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1213 * Concurrency: no concurrent access is possible that late in object
1216 static void osd_index_fini(struct osd_object *o)
1218 struct iam_container *bag;
1220 if (o->oo_dir != NULL) {
1221 bag = &o->oo_dir->od_container;
1222 if (o->oo_inode != NULL) {
1223 if (bag->ic_object == o->oo_inode)
1224 iam_container_fini(bag);
1226 OBD_FREE_PTR(o->oo_dir);
1232 * Concurrency: no concurrent access is possible that late in object
1233 * life-cycle (for all existing callers, that is. New callers have to provide
1234 * their own locking.)
1236 static int osd_inode_unlinked(const struct inode *inode)
1238 return inode->i_nlink == 0;
1242 OSD_TXN_OI_DELETE_CREDITS = 20,
1243 OSD_TXN_INODE_DELETE_CREDITS = 20
1250 #if OSD_THANDLE_STATS
1252 * Set time when the handle is allocated
1254 static void osd_th_alloced(struct osd_thandle *oth)
1256 oth->oth_alloced = cfs_time_current();
1260 * Set time when the handle started
1262 static void osd_th_started(struct osd_thandle *oth)
1264 oth->oth_started = cfs_time_current();
1268 * Helper function to convert time interval to microseconds packed in
1271 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
1275 cfs_duration_usec(cfs_time_sub(end, start), &val);
1276 return val.tv_sec * 1000000 + val.tv_usec;
1280 * Check whether the we deal with this handle for too long.
1282 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
1283 cfs_time_t alloced, cfs_time_t started,
1286 cfs_time_t now = cfs_time_current();
1288 LASSERT(dev != NULL);
1290 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
1291 interval_to_usec(alloced, started));
1292 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
1293 interval_to_usec(started, closed));
1294 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
1295 interval_to_usec(closed, now));
1297 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
1298 CWARN("transaction handle %p was open for too long: "
1299 "now "CFS_TIME_T" ,"
1300 "alloced "CFS_TIME_T" ,"
1301 "started "CFS_TIME_T" ,"
1302 "closed "CFS_TIME_T"\n",
1303 oth, now, alloced, started, closed);
1304 libcfs_debug_dumpstack(NULL);
1308 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
1310 cfs_time_t __closed = cfs_time_current(); \
1311 cfs_time_t __alloced = oth->oth_alloced; \
1312 cfs_time_t __started = oth->oth_started; \
1315 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
1318 #else /* OSD_THANDLE_STATS */
1320 #define osd_th_alloced(h) do {} while(0)
1321 #define osd_th_started(h) do {} while(0)
1322 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
1324 #endif /* OSD_THANDLE_STATS */
1327 * Concurrency: doesn't access mutable data.
1329 static int osd_param_is_not_sane(const struct osd_device *dev,
1330 const struct thandle *th)
1332 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
1334 return oh->ot_credits > osd_transaction_size(dev);
1338 * Concurrency: shouldn't matter.
1340 static void osd_trans_commit_cb(struct super_block *sb,
1341 struct ldiskfs_journal_cb_entry *jcb, int error)
1343 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
1344 struct thandle *th = &oh->ot_super;
1345 struct lu_device *lud = &th->th_dev->dd_lu_dev;
1346 struct dt_txn_commit_cb *dcb, *tmp;
1348 LASSERT(oh->ot_handle == NULL);
1351 CERROR("transaction @0x%p commit error: %d\n", th, error);
1353 dt_txn_hook_commit(th);
1355 /* call per-transaction callbacks if any */
1356 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
1358 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1359 "commit callback entry: magic=%x name='%s'\n",
1360 dcb->dcb_magic, dcb->dcb_name);
1361 list_del_init(&dcb->dcb_linkage);
1362 dcb->dcb_func(NULL, th, dcb, error);
1365 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
1369 lu_context_exit(&th->th_ctx);
1370 lu_context_fini(&th->th_ctx);
1374 #ifndef HAVE_SB_START_WRITE
1375 # define sb_start_write(sb) do {} while (0)
1376 # define sb_end_write(sb) do {} while (0)
1379 static struct thandle *osd_trans_create(const struct lu_env *env,
1380 struct dt_device *d)
1382 struct osd_thread_info *oti = osd_oti_get(env);
1383 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1384 struct osd_thandle *oh;
1388 /* on pending IO in this thread should left from prev. request */
1389 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
1391 sb_start_write(osd_sb(osd_dt_dev(d)));
1393 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
1395 oh->ot_quota_trans = &oti->oti_quota_trans;
1396 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
1400 th->th_tags = LCT_TX_HANDLE;
1402 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
1403 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
1406 memset(oti->oti_declare_ops, 0,
1407 sizeof(oti->oti_declare_ops));
1408 memset(oti->oti_declare_ops_cred, 0,
1409 sizeof(oti->oti_declare_ops_cred));
1410 memset(oti->oti_declare_ops_used, 0,
1411 sizeof(oti->oti_declare_ops_used));
1413 sb_end_write(osd_sb(osd_dt_dev(d)));
1414 th = ERR_PTR(-ENOMEM);
1419 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
1421 struct osd_thread_info *oti = osd_oti_get(env);
1422 struct osd_thandle *oh;
1424 oh = container_of0(th, struct osd_thandle, ot_super);
1425 LASSERT(oh != NULL);
1427 CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n",
1428 oti->oti_declare_ops[OSD_OT_CREATE],
1429 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1430 oti->oti_declare_ops_used[OSD_OT_CREATE],
1431 oti->oti_declare_ops[OSD_OT_DESTROY],
1432 oti->oti_declare_ops_cred[OSD_OT_DESTROY],
1433 oti->oti_declare_ops_used[OSD_OT_DESTROY]);
1434 CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
1435 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1436 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1437 oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
1438 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1439 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
1440 oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
1441 CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
1442 oti->oti_declare_ops[OSD_OT_WRITE],
1443 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1444 oti->oti_declare_ops_used[OSD_OT_WRITE],
1445 oti->oti_declare_ops[OSD_OT_PUNCH],
1446 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1447 oti->oti_declare_ops_used[OSD_OT_PUNCH],
1448 oti->oti_declare_ops[OSD_OT_QUOTA],
1449 oti->oti_declare_ops_cred[OSD_OT_QUOTA],
1450 oti->oti_declare_ops_used[OSD_OT_QUOTA]);
1451 CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n",
1452 oti->oti_declare_ops[OSD_OT_INSERT],
1453 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1454 oti->oti_declare_ops_used[OSD_OT_INSERT],
1455 oti->oti_declare_ops[OSD_OT_DELETE],
1456 oti->oti_declare_ops_cred[OSD_OT_DELETE],
1457 oti->oti_declare_ops_used[OSD_OT_DELETE]);
1458 CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
1459 oti->oti_declare_ops[OSD_OT_REF_ADD],
1460 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1461 oti->oti_declare_ops_used[OSD_OT_REF_ADD],
1462 oti->oti_declare_ops[OSD_OT_REF_DEL],
1463 oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
1464 oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
1468 * Concurrency: shouldn't matter.
1470 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1473 struct osd_thread_info *oti = osd_oti_get(env);
1474 struct osd_device *dev = osd_dt_dev(d);
1476 struct osd_thandle *oh;
1481 LASSERT(current->journal_info == NULL);
1483 oh = container_of0(th, struct osd_thandle, ot_super);
1484 LASSERT(oh != NULL);
1485 LASSERT(oh->ot_handle == NULL);
1487 rc = dt_txn_hook_start(env, d, th);
1491 if (unlikely(osd_param_is_not_sane(dev, th))) {
1492 static unsigned long last_printed;
1493 static int last_credits;
1495 /* don't make noise on a tiny testing systems
1496 * actual credits misuse will be caught anyway */
1497 if (last_credits != oh->ot_credits &&
1498 time_after(jiffies, last_printed +
1499 msecs_to_jiffies(60 * MSEC_PER_SEC)) &&
1500 osd_transaction_size(dev) > 512) {
1501 osd_trans_dump_creds(env, th);
1502 libcfs_debug_dumpstack(NULL);
1503 last_credits = oh->ot_credits;
1504 last_printed = jiffies;
1506 /* XXX Limit the credits to 'max_transaction_buffers', and
1507 * let the underlying filesystem to catch the error if
1508 * we really need so many credits.
1510 * This should be removed when we can calculate the
1511 * credits precisely. */
1512 oh->ot_credits = osd_transaction_size(dev);
1516 * XXX temporary stuff. Some abstraction layer should
1519 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1523 LASSERT(oti->oti_txns == 0);
1524 lu_context_init(&th->th_ctx, th->th_tags);
1525 lu_context_enter(&th->th_ctx);
1527 lu_device_get(&d->dd_lu_dev);
1528 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1539 static int osd_seq_exists(const struct lu_env *env,
1540 struct osd_device *osd, u64 seq)
1542 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1543 struct seq_server_site *ss = osd_seq_site(osd);
1547 LASSERT(ss != NULL);
1548 LASSERT(ss->ss_server_fld != NULL);
1550 rc = osd_fld_lookup(env, osd, seq, range);
1553 CERROR("%s: can't lookup FLD sequence "LPX64
1554 ": rc = %d\n", osd_name(osd), seq, rc);
1558 RETURN(ss->ss_node_id == range->lsr_index);
1561 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
1563 struct dt_txn_commit_cb *dcb;
1564 struct dt_txn_commit_cb *tmp;
1566 /* call per-transaction stop callbacks if any */
1567 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
1569 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1570 "commit callback entry: magic=%x name='%s'\n",
1571 dcb->dcb_magic, dcb->dcb_name);
1572 list_del_init(&dcb->dcb_linkage);
1573 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
1578 * Concurrency: shouldn't matter.
1580 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1583 int rc = 0, remove_agents = 0;
1584 struct osd_thandle *oh;
1585 struct osd_thread_info *oti = osd_oti_get(env);
1586 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1587 struct osd_device *osd = osd_dt_dev(th->th_dev);
1588 struct qsd_instance *qsd = osd->od_quota_slave;
1589 struct lquota_trans *qtrans;
1592 oh = container_of0(th, struct osd_thandle, ot_super);
1594 /* reset OI cache for safety */
1595 oti->oti_ins_cache_used = 0;
1597 remove_agents = oh->ot_remove_agents;
1599 qtrans = oh->ot_quota_trans;
1600 oh->ot_quota_trans = NULL;
1602 if (oh->ot_handle != NULL) {
1603 handle_t *hdl = oh->ot_handle;
1606 * add commit callback
1607 * notice we don't do this in osd_trans_start()
1608 * as underlying transaction can change during truncate
1610 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1613 LASSERT(oti->oti_txns == 1);
1616 rc = dt_txn_hook_stop(env, th);
1618 CERROR("%s: failed in transaction hook: rc = %d\n",
1621 osd_trans_stop_cb(oh, rc);
1622 /* hook functions might modify th_sync */
1623 hdl->h_sync = th->th_sync;
1625 oh->ot_handle = NULL;
1626 OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl));
1628 CERROR("%s: failed to stop transaction: rc = %d\n",
1631 osd_trans_stop_cb(oh, th->th_result);
1635 /* inform the quota slave device that the transaction is stopping */
1636 qsd_op_end(env, qsd, qtrans);
1638 /* as we want IO to journal and data IO be concurrent, we don't block
1639 * awaiting data IO completion in osd_do_bio(), instead we wait here
1640 * once transaction is submitted to the journal. all reqular requests
1641 * don't do direct IO (except read/write), thus this wait_event becomes
1644 * IMPORTANT: we have to wait till any IO submited by the thread is
1645 * completed otherwise iobuf may be corrupted by different request
1647 wait_event(iobuf->dr_wait,
1648 atomic_read(&iobuf->dr_numreqs) == 0);
1649 osd_fini_iobuf(osd, iobuf);
1651 rc = iobuf->dr_error;
1653 if (unlikely(remove_agents != 0))
1654 osd_process_scheduled_agent_removals(env, osd);
1656 sb_end_write(osd_sb(osd));
1661 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1663 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1666 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1667 LASSERT(&dcb->dcb_func != NULL);
1668 if (dcb->dcb_flags & DCB_TRANS_STOP)
1669 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
1671 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
1677 * Called just before object is freed. Releases all resources except for
1678 * object itself (that is released by osd_object_free()).
1680 * Concurrency: no concurrent access is possible that late in object
1683 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1685 struct osd_object *obj = osd_obj(l);
1686 struct inode *inode = obj->oo_inode;
1688 LINVRNT(osd_invariant(obj));
1691 * If object is unlinked remove fid->ino mapping from object index.
1694 osd_index_fini(obj);
1695 if (inode != NULL) {
1696 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1697 qid_t uid = i_uid_read(inode);
1698 qid_t gid = i_gid_read(inode);
1701 obj->oo_inode = NULL;
1704 struct osd_thread_info *info = osd_oti_get(env);
1705 struct lquota_id_info *qi = &info->oti_qi;
1707 /* Release granted quota to master if necessary */
1708 qi->lqi_id.qid_uid = uid;
1709 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1711 qi->lqi_id.qid_uid = gid;
1712 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
1718 * Concurrency: ->loo_object_release() is called under site spin-lock.
1720 static void osd_object_release(const struct lu_env *env,
1721 struct lu_object *l)
1723 struct osd_object *o = osd_obj(l);
1724 /* nobody should be releasing a non-destroyed object with nlink=0
1725 * the API allows this, but ldiskfs doesn't like and then report
1726 * this inode as deleted */
1727 if (unlikely(!o->oo_destroyed && o->oo_inode && o->oo_inode->i_nlink == 0))
1732 * Concurrency: shouldn't matter.
1734 static int osd_object_print(const struct lu_env *env, void *cookie,
1735 lu_printer_t p, const struct lu_object *l)
1737 struct osd_object *o = osd_obj(l);
1738 struct iam_descr *d;
1740 if (o->oo_dir != NULL)
1741 d = o->oo_dir->od_container.ic_descr;
1744 return (*p)(env, cookie,
1745 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
1747 o->oo_inode ? o->oo_inode->i_ino : 0UL,
1748 o->oo_inode ? o->oo_inode->i_generation : 0,
1749 d ? d->id_ops->id_name : "plain");
1753 * Concurrency: shouldn't matter.
1755 int osd_statfs(const struct lu_env *env, struct dt_device *d,
1756 struct obd_statfs *sfs)
1758 struct osd_device *osd = osd_dt_dev(d);
1759 struct super_block *sb = osd_sb(osd);
1760 struct kstatfs *ksfs;
1764 if (unlikely(osd->od_mnt == NULL))
1765 return -EINPROGRESS;
1767 /* osd_lproc.c call this without env, allocate ksfs for that case */
1768 if (unlikely(env == NULL)) {
1769 OBD_ALLOC_PTR(ksfs);
1773 ksfs = &osd_oti_get(env)->oti_ksfs;
1776 result = sb->s_op->statfs(sb->s_root, ksfs);
1780 statfs_pack(sfs, ksfs);
1781 if (unlikely(sb->s_flags & MS_RDONLY))
1782 sfs->os_state = OS_STATE_READONLY;
1783 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb,
1784 LDISKFS_FEATURE_INCOMPAT_EXTENTS))
1785 sfs->os_maxbytes = sb->s_maxbytes;
1787 sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
1790 * Reserve some space so to avoid fragmenting the filesystem too much.
1791 * Fragmentation not only impacts performance, but can also increase
1792 * metadata overhead significantly, causing grant calculation to be
1795 * Reserve 0.78% of total space, at least 8MB for small filesystems.
1797 CLASSERT(OSD_STATFS_RESERVED > LDISKFS_MAX_BLOCK_SIZE);
1798 reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits;
1799 if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT))
1800 reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT;
1802 sfs->os_blocks -= reserved;
1803 sfs->os_bfree -= min(reserved, sfs->os_bfree);
1804 sfs->os_bavail -= min(reserved, sfs->os_bavail);
1807 if (unlikely(env == NULL))
1813 * Estimate space needed for file creations. We assume the largest filename
1814 * which is 2^64 - 1, hence a filename of 20 chars.
1815 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
1817 #ifdef __LDISKFS_DIR_REC_LEN
1818 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
1820 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
1824 * Concurrency: doesn't access mutable data.
1826 static void osd_conf_get(const struct lu_env *env,
1827 const struct dt_device *dev,
1828 struct dt_device_param *param)
1830 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1834 * XXX should be taken from not-yet-existing fs abstraction layer.
1836 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1837 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1838 param->ddp_symlink_max = sb->s_blocksize;
1839 param->ddp_mount_type = LDD_MT_LDISKFS;
1840 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS))
1841 param->ddp_maxbytes = sb->s_maxbytes;
1843 param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
1844 /* inode are statically allocated, so per-inode space consumption
1845 * is the space consumed by the directory entry */
1846 param->ddp_inodespace = PER_OBJ_USAGE;
1847 /* EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks
1848 * = 128MB) which is unlikely to be hit in real life. Report a smaller
1849 * maximum length to not under count the actual number of extents
1850 * needed for writing a file. */
1851 param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 2;
1852 /* worst-case extent insertion metadata overhead */
1853 param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb);
1854 param->ddp_mntopts = 0;
1855 if (test_opt(sb, XATTR_USER))
1856 param->ddp_mntopts |= MNTOPT_USERXATTR;
1857 if (test_opt(sb, POSIX_ACL))
1858 param->ddp_mntopts |= MNTOPT_ACL;
1860 /* LOD might calculate the max stripe count based on max_ea_size,
1861 * so we need take account in the overhead as well,
1862 * xattr_header + magic + xattr_entry_head */
1863 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
1864 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
1866 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1867 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1868 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
1872 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
1876 * Concurrency: shouldn't matter.
1878 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1882 CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1884 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1886 CDEBUG(D_CACHE, "synced OSD %s: rc = %d\n",
1887 LUSTRE_OSD_LDISKFS_NAME, rc);
1893 * Start commit for OSD device.
1895 * An implementation of dt_commit_async method for OSD device.
1896 * Asychronously starts underlayng fs sync and thereby a transaction
1899 * \param env environment
1900 * \param d dt device
1902 * \see dt_device_operations
1904 static int osd_commit_async(const struct lu_env *env,
1905 struct dt_device *d)
1907 struct super_block *s = osd_sb(osd_dt_dev(d));
1910 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1911 RETURN(s->s_op->sync_fs(s, 0));
1915 * Concurrency: shouldn't matter.
1918 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1920 struct super_block *sb = osd_sb(osd_dt_dev(d));
1921 struct block_device *dev = sb->s_bdev;
1922 #ifdef HAVE_DEV_SET_RDONLY
1923 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
1926 int rc = -EOPNOTSUPP;
1930 #ifdef HAVE_DEV_SET_RDONLY
1931 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1933 if (sb->s_op->freeze_fs) {
1934 rc = sb->s_op->freeze_fs(sb);
1939 if (jdev && (jdev != dev)) {
1940 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
1942 dev_set_rdonly(jdev);
1944 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
1945 dev_set_rdonly(dev);
1947 if (sb->s_op->unfreeze_fs)
1948 sb->s_op->unfreeze_fs(sb);
1953 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
1954 osd_dt_dev(d)->od_svname, (long)dev, rc);
1960 * Note: we do not count into QUOTA here.
1961 * If we mount with --data_journal we may need more.
1963 const int osd_dto_credits_noquota[DTO_NR] = {
1966 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1967 * SINGLEDATA_TRANS_BLOCKS(8)
1968 * XXX Note: maybe iam need more, since iam have more level than
1971 [DTO_INDEX_INSERT] = 16,
1974 * just modify a single entry, probably merge few within a block
1976 [DTO_INDEX_DELETE] = 1,
1980 [DTO_INDEX_UPDATE] = 16,
1982 * 4(inode, inode bits, groups, GDT)
1983 * notice: OI updates are counted separately with DTO_INDEX_INSERT
1985 [DTO_OBJECT_CREATE] = 4,
1987 * 4(inode, inode bits, groups, GDT)
1988 * notice: OI updates are counted separately with DTO_INDEX_DELETE
1990 [DTO_OBJECT_DELETE] = 4,
1992 * Attr set credits (inode)
1994 [DTO_ATTR_SET_BASE] = 1,
1996 * Xattr set. The same as xattr of EXT3.
1997 * DATA_TRANS_BLOCKS(14)
1998 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1999 * are also counted in. Do not know why?
2001 [DTO_XATTR_SET] = 14,
2003 * credits for inode change during write.
2005 [DTO_WRITE_BASE] = 3,
2007 * credits for single block write.
2009 [DTO_WRITE_BLOCK] = 14,
2011 * Attr set credits for chown.
2012 * This is extra credits for setattr, and it is null without quota
2014 [DTO_ATTR_SET_CHOWN] = 0
2017 static const struct dt_device_operations osd_dt_ops = {
2018 .dt_root_get = osd_root_get,
2019 .dt_statfs = osd_statfs,
2020 .dt_trans_create = osd_trans_create,
2021 .dt_trans_start = osd_trans_start,
2022 .dt_trans_stop = osd_trans_stop,
2023 .dt_trans_cb_add = osd_trans_cb_add,
2024 .dt_conf_get = osd_conf_get,
2025 .dt_sync = osd_sync,
2027 .dt_commit_async = osd_commit_async,
2030 static void osd_object_read_lock(const struct lu_env *env,
2031 struct dt_object *dt, unsigned role)
2033 struct osd_object *obj = osd_dt_obj(dt);
2034 struct osd_thread_info *oti = osd_oti_get(env);
2036 LINVRNT(osd_invariant(obj));
2038 LASSERT(obj->oo_owner != env);
2039 down_read_nested(&obj->oo_sem, role);
2041 LASSERT(obj->oo_owner == NULL);
2045 static void osd_object_write_lock(const struct lu_env *env,
2046 struct dt_object *dt, unsigned role)
2048 struct osd_object *obj = osd_dt_obj(dt);
2049 struct osd_thread_info *oti = osd_oti_get(env);
2051 LINVRNT(osd_invariant(obj));
2053 LASSERT(obj->oo_owner != env);
2054 down_write_nested(&obj->oo_sem, role);
2056 LASSERT(obj->oo_owner == NULL);
2057 obj->oo_owner = env;
2061 static void osd_object_read_unlock(const struct lu_env *env,
2062 struct dt_object *dt)
2064 struct osd_object *obj = osd_dt_obj(dt);
2065 struct osd_thread_info *oti = osd_oti_get(env);
2067 LINVRNT(osd_invariant(obj));
2069 LASSERT(oti->oti_r_locks > 0);
2071 up_read(&obj->oo_sem);
2074 static void osd_object_write_unlock(const struct lu_env *env,
2075 struct dt_object *dt)
2077 struct osd_object *obj = osd_dt_obj(dt);
2078 struct osd_thread_info *oti = osd_oti_get(env);
2080 LINVRNT(osd_invariant(obj));
2082 LASSERT(obj->oo_owner == env);
2083 LASSERT(oti->oti_w_locks > 0);
2085 obj->oo_owner = NULL;
2086 up_write(&obj->oo_sem);
2089 static int osd_object_write_locked(const struct lu_env *env,
2090 struct dt_object *dt)
2092 struct osd_object *obj = osd_dt_obj(dt);
2094 LINVRNT(osd_invariant(obj));
2096 return obj->oo_owner == env;
2099 static struct timespec *osd_inode_time(const struct lu_env *env,
2100 struct inode *inode, __u64 seconds)
2102 struct osd_thread_info *oti = osd_oti_get(env);
2103 struct timespec *t = &oti->oti_time;
2105 t->tv_sec = seconds;
2107 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
2111 static void osd_inode_getattr(const struct lu_env *env,
2112 struct inode *inode, struct lu_attr *attr)
2114 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2115 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2116 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
2119 attr->la_atime = LTIME_S(inode->i_atime);
2120 attr->la_mtime = LTIME_S(inode->i_mtime);
2121 attr->la_ctime = LTIME_S(inode->i_ctime);
2122 attr->la_mode = inode->i_mode;
2123 attr->la_size = i_size_read(inode);
2124 attr->la_blocks = inode->i_blocks;
2125 attr->la_uid = i_uid_read(inode);
2126 attr->la_gid = i_gid_read(inode);
2127 attr->la_flags = ll_inode_to_ext_flags(inode->i_flags);
2128 attr->la_nlink = inode->i_nlink;
2129 attr->la_rdev = inode->i_rdev;
2130 attr->la_blksize = 1 << inode->i_blkbits;
2131 attr->la_blkbits = inode->i_blkbits;
2134 static int osd_attr_get(const struct lu_env *env,
2135 struct dt_object *dt,
2136 struct lu_attr *attr)
2138 struct osd_object *obj = osd_dt_obj(dt);
2140 if (unlikely(!dt_object_exists(dt)))
2142 if (unlikely(obj->oo_destroyed))
2145 LASSERT(!dt_object_remote(dt));
2146 LINVRNT(osd_invariant(obj));
2148 spin_lock(&obj->oo_guard);
2149 osd_inode_getattr(env, obj->oo_inode, attr);
2150 if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL)
2151 attr->la_flags |= LUSTRE_ORPHAN_FL;
2152 spin_unlock(&obj->oo_guard);
2157 static int osd_declare_attr_set(const struct lu_env *env,
2158 struct dt_object *dt,
2159 const struct lu_attr *attr,
2160 struct thandle *handle)
2162 struct osd_thandle *oh;
2163 struct osd_object *obj;
2164 struct osd_thread_info *info = osd_oti_get(env);
2165 struct lquota_id_info *qi = &info->oti_qi;
2173 LASSERT(dt != NULL);
2174 LASSERT(handle != NULL);
2176 obj = osd_dt_obj(dt);
2177 LASSERT(osd_invariant(obj));
2179 oh = container_of0(handle, struct osd_thandle, ot_super);
2180 LASSERT(oh->ot_handle == NULL);
2182 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
2183 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2185 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2186 osd_dto_credits_noquota[DTO_XATTR_SET]);
2188 if (attr == NULL || obj->oo_inode == NULL)
2191 bspace = obj->oo_inode->i_blocks;
2192 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
2193 bspace = toqb(bspace);
2195 /* Changing ownership is always preformed by super user, it should not
2198 * We still need to call the osd_declare_qid() to calculate the journal
2199 * credits for updating quota accounting files and to trigger quota
2200 * space adjustment once the operation is completed.*/
2201 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
2203 uid = i_uid_read(obj->oo_inode);
2204 qi->lqi_type = USRQUOTA;
2205 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
2206 /* inode accounting */
2207 qi->lqi_is_blk = false;
2209 /* one more inode for the new uid ... */
2210 qi->lqi_id.qid_uid = attr->la_uid;
2212 /* Reserve credits for the new uid */
2213 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2214 if (rc == -EDQUOT || rc == -EINPROGRESS)
2219 /* and one less inode for the current uid */
2220 qi->lqi_id.qid_uid = uid;
2222 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2223 if (rc == -EDQUOT || rc == -EINPROGRESS)
2228 /* block accounting */
2229 qi->lqi_is_blk = true;
2231 /* more blocks for the new uid ... */
2232 qi->lqi_id.qid_uid = attr->la_uid;
2233 qi->lqi_space = bspace;
2235 * Credits for the new uid has been reserved, re-use "obj"
2236 * to save credit reservation.
2238 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2239 if (rc == -EDQUOT || rc == -EINPROGRESS)
2244 /* and finally less blocks for the current uid */
2245 qi->lqi_id.qid_uid = uid;
2246 qi->lqi_space = -bspace;
2247 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2248 if (rc == -EDQUOT || rc == -EINPROGRESS)
2254 gid = i_gid_read(obj->oo_inode);
2255 qi->lqi_type = GRPQUOTA;
2256 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
2258 /* inode accounting */
2259 qi->lqi_is_blk = false;
2261 /* one more inode for the new gid ... */
2262 qi->lqi_id.qid_gid = attr->la_gid;
2264 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2265 if (rc == -EDQUOT || rc == -EINPROGRESS)
2270 /* and one less inode for the current gid */
2271 qi->lqi_id.qid_gid = gid;
2273 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2274 if (rc == -EDQUOT || rc == -EINPROGRESS)
2279 /* block accounting */
2280 qi->lqi_is_blk = true;
2282 /* more blocks for the new gid ... */
2283 qi->lqi_id.qid_gid = attr->la_gid;
2284 qi->lqi_space = bspace;
2285 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2286 if (rc == -EDQUOT || rc == -EINPROGRESS)
2291 /* and finally less blocks for the current gid */
2292 qi->lqi_id.qid_gid = gid;
2293 qi->lqi_space = -bspace;
2294 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2295 if (rc == -EDQUOT || rc == -EINPROGRESS)
2304 static int osd_inode_setattr(const struct lu_env *env,
2305 struct inode *inode, const struct lu_attr *attr)
2307 __u64 bits = attr->la_valid;
2309 /* Only allow set size for regular file */
2310 if (!S_ISREG(inode->i_mode))
2311 bits &= ~(LA_SIZE | LA_BLOCKS);
2316 if (bits & LA_ATIME)
2317 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
2318 if (bits & LA_CTIME)
2319 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
2320 if (bits & LA_MTIME)
2321 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
2322 if (bits & LA_SIZE) {
2323 LDISKFS_I(inode)->i_disksize = attr->la_size;
2324 i_size_write(inode, attr->la_size);
2328 /* OSD should not change "i_blocks" which is used by quota.
2329 * "i_blocks" should be changed by ldiskfs only. */
2330 if (bits & LA_BLOCKS)
2331 inode->i_blocks = attr->la_blocks;
2334 inode->i_mode = (inode->i_mode & S_IFMT) |
2335 (attr->la_mode & ~S_IFMT);
2337 i_uid_write(inode, attr->la_uid);
2339 i_gid_write(inode, attr->la_gid);
2340 if (bits & LA_NLINK)
2341 set_nlink(inode, attr->la_nlink);
2343 inode->i_rdev = attr->la_rdev;
2345 if (bits & LA_FLAGS) {
2346 /* always keep S_NOCMTIME */
2347 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
2353 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
2355 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
2356 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
2360 ll_vfs_dq_init(inode);
2362 if (attr->la_valid & LA_UID)
2363 iattr.ia_valid |= ATTR_UID;
2364 if (attr->la_valid & LA_GID)
2365 iattr.ia_valid |= ATTR_GID;
2366 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
2367 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
2369 rc = ll_vfs_dq_transfer(inode, &iattr);
2371 CERROR("%s: quota transfer failed: rc = %d. Is quota "
2372 "enforcement enabled on the ldiskfs "
2373 "filesystem?\n", inode->i_sb->s_id, rc);
2380 static int osd_attr_set(const struct lu_env *env,
2381 struct dt_object *dt,
2382 const struct lu_attr *attr,
2383 struct thandle *handle)
2385 struct osd_object *obj = osd_dt_obj(dt);
2386 struct inode *inode;
2389 if (!dt_object_exists(dt))
2392 LASSERT(handle != NULL);
2393 LASSERT(!dt_object_remote(dt));
2394 LASSERT(osd_invariant(obj));
2396 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
2398 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING)) {
2399 struct osd_thread_info *oti = osd_oti_get(env);
2400 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
2401 struct lu_fid *fid1 = &oti->oti_fid;
2402 struct osd_inode_id *id = &oti->oti_id;
2403 struct iam_path_descr *ipd;
2404 struct iam_container *bag;
2405 struct osd_thandle *oh;
2408 fid_cpu_to_be(fid1, fid0);
2409 memset(id, 1, sizeof(*id));
2410 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
2411 fid0)->oi_dir.od_container;
2412 ipd = osd_idx_ipd_get(env, bag);
2413 if (unlikely(ipd == NULL))
2416 oh = container_of0(handle, struct osd_thandle, ot_super);
2417 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
2418 (const struct iam_rec *)id, ipd);
2419 osd_ipd_put(env, bag, ipd);
2420 return(rc > 0 ? 0 : rc);
2423 inode = obj->oo_inode;
2425 rc = osd_quota_transfer(inode, attr);
2429 spin_lock(&obj->oo_guard);
2430 rc = osd_inode_setattr(env, inode, attr);
2431 spin_unlock(&obj->oo_guard);
2435 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2437 if (!(attr->la_valid & LA_FLAGS))
2440 /* Let's check if there are extra flags need to be set into LMA */
2441 if (attr->la_flags & LUSTRE_LMA_FL_MASKS) {
2442 struct osd_thread_info *info = osd_oti_get(env);
2443 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2445 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
2449 lma->lma_incompat |=
2450 lustre_to_lma_flags(attr->la_flags);
2451 lustre_lma_swab(lma);
2452 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA,
2453 lma, sizeof(*lma), XATTR_REPLACE);
2455 struct osd_device *osd = osd_obj2dev(obj);
2457 CWARN("%s: set "DFID" lma flags %u failed: rc = %d\n",
2458 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)),
2459 lma->lma_incompat, rc);
2462 attr->la_flags & LUSTRE_LMA_FL_MASKS;
2464 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
2467 osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
2472 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
2473 struct osd_object *obj,
2474 const char *name, const int namelen)
2476 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
2479 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
2480 umode_t mode, struct dt_allocation_hint *hint,
2484 struct osd_device *osd = osd_obj2dev(obj);
2485 struct osd_thandle *oth;
2486 struct dt_object *parent = NULL;
2487 struct inode *inode;
2489 LINVRNT(osd_invariant(obj));
2490 LASSERT(obj->oo_inode == NULL);
2491 LASSERT(obj->oo_hl_head == NULL);
2493 if (S_ISDIR(mode) && ldiskfs_pdo) {
2494 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
2495 if (obj->oo_hl_head == NULL)
2499 oth = container_of(th, struct osd_thandle, ot_super);
2500 LASSERT(oth->ot_handle->h_transaction != NULL);
2502 if (hint != NULL && hint->dah_parent != NULL &&
2503 !dt_object_remote(hint->dah_parent))
2504 parent = hint->dah_parent;
2506 inode = ldiskfs_create_inode(oth->ot_handle,
2507 parent ? osd_dt_obj(parent)->oo_inode :
2508 osd_sb(osd)->s_root->d_inode,
2510 if (!IS_ERR(inode)) {
2511 /* Do not update file c/mtime in ldiskfs. */
2512 inode->i_flags |= S_NOCMTIME;
2514 /* For new created object, it must be consistent,
2515 * and it is unnecessary to scrub against it. */
2516 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
2518 obj->oo_inode = inode;
2521 if (obj->oo_hl_head != NULL) {
2522 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
2523 obj->oo_hl_head = NULL;
2525 result = PTR_ERR(inode);
2527 LINVRNT(osd_invariant(obj));
2535 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
2536 struct lu_attr *attr,
2537 struct dt_allocation_hint *hint,
2538 struct dt_object_format *dof,
2542 struct osd_thandle *oth;
2543 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
2545 LASSERT(S_ISDIR(attr->la_mode));
2547 oth = container_of(th, struct osd_thandle, ot_super);
2548 LASSERT(oth->ot_handle->h_transaction != NULL);
2549 result = osd_mkfile(info, obj, mode, hint, th);
2554 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
2555 struct lu_attr *attr,
2556 struct dt_allocation_hint *hint,
2557 struct dt_object_format *dof,
2561 struct osd_thandle *oth;
2562 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
2564 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
2566 LASSERT(S_ISREG(attr->la_mode));
2568 oth = container_of(th, struct osd_thandle, ot_super);
2569 LASSERT(oth->ot_handle->h_transaction != NULL);
2571 result = osd_mkfile(info, obj, mode, hint, th);
2573 LASSERT(obj->oo_inode != NULL);
2574 if (feat->dif_flags & DT_IND_VARKEY)
2575 result = iam_lvar_create(obj->oo_inode,
2576 feat->dif_keysize_max,
2578 feat->dif_recsize_max,
2581 result = iam_lfix_create(obj->oo_inode,
2582 feat->dif_keysize_max,
2584 feat->dif_recsize_max,
2591 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
2592 struct lu_attr *attr,
2593 struct dt_allocation_hint *hint,
2594 struct dt_object_format *dof,
2597 LASSERT(S_ISREG(attr->la_mode));
2598 return osd_mkfile(info, obj, (attr->la_mode &
2599 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2602 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
2603 struct lu_attr *attr,
2604 struct dt_allocation_hint *hint,
2605 struct dt_object_format *dof,
2608 LASSERT(S_ISLNK(attr->la_mode));
2609 return osd_mkfile(info, obj, (attr->la_mode &
2610 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2613 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
2614 struct lu_attr *attr,
2615 struct dt_allocation_hint *hint,
2616 struct dt_object_format *dof,
2619 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
2622 LINVRNT(osd_invariant(obj));
2623 LASSERT(obj->oo_inode == NULL);
2624 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
2625 S_ISFIFO(mode) || S_ISSOCK(mode));
2627 result = osd_mkfile(info, obj, mode, hint, th);
2629 LASSERT(obj->oo_inode != NULL);
2631 * This inode should be marked dirty for i_rdev. Currently
2632 * that is done in the osd_attr_init().
2634 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
2637 LINVRNT(osd_invariant(obj));
2641 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
2643 struct dt_allocation_hint *hint,
2644 struct dt_object_format *dof,
2647 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
2649 osd_obj_type_f result;
2665 result = osd_mk_index;
2676 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2677 struct dt_object *parent, struct dt_object *child,
2682 ah->dah_parent = parent;
2683 ah->dah_mode = child_mode;
2685 if (parent != NULL && !dt_object_remote(parent)) {
2686 /* will help to find FID->ino at dt_insert("..") */
2687 struct osd_object *pobj = osd_dt_obj(parent);
2688 osd_idc_find_and_init(env, osd_obj2dev(pobj), pobj);
2692 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
2693 struct lu_attr *attr, struct dt_object_format *dof)
2695 struct inode *inode = obj->oo_inode;
2696 __u64 valid = attr->la_valid;
2699 attr->la_valid &= ~(LA_TYPE | LA_MODE);
2701 if (dof->dof_type != DFT_NODE)
2702 attr->la_valid &= ~LA_RDEV;
2703 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
2704 attr->la_valid &= ~LA_ATIME;
2705 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
2706 attr->la_valid &= ~LA_CTIME;
2707 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
2708 attr->la_valid &= ~LA_MTIME;
2710 result = osd_quota_transfer(inode, attr);
2714 if (attr->la_valid != 0) {
2715 result = osd_inode_setattr(info->oti_env, inode, attr);
2717 * The osd_inode_setattr() should always succeed here. The
2718 * only error that could be returned is EDQUOT when we are
2719 * trying to change the UID or GID of the inode. However, this
2720 * should not happen since quota enforcement is no longer
2721 * enabled on ldiskfs (lquota takes care of it).
2723 LASSERTF(result == 0, "%d\n", result);
2724 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2727 attr->la_valid = valid;
2731 * Helper function for osd_object_create()
2733 * \retval 0, on success
2735 static int __osd_object_create(struct osd_thread_info *info,
2736 struct osd_object *obj, struct lu_attr *attr,
2737 struct dt_allocation_hint *hint,
2738 struct dt_object_format *dof,
2744 osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE);
2746 /* we drop umask so that permissions we pass are not affected */
2747 umask = current->fs->umask;
2748 current->fs->umask = 0;
2750 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
2752 if (likely(obj->oo_inode != NULL)) {
2753 LASSERT(obj->oo_inode->i_state & I_NEW);
2755 /* Unlock the inode before attr initialization to avoid
2756 * unnecessary dqget operations. LU-6378 */
2757 unlock_new_inode(obj->oo_inode);
2760 if (likely(result == 0)) {
2761 osd_attr_init(info, obj, attr, dof);
2762 osd_object_init0(obj);
2765 /* restore previous umask value */
2766 current->fs->umask = umask;
2768 osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE);
2774 * Helper function for osd_object_create()
2776 * \retval 0, on success
2778 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
2779 const struct lu_fid *fid, struct thandle *th)
2781 struct osd_thread_info *info = osd_oti_get(env);
2782 struct osd_inode_id *id = &info->oti_id;
2783 struct osd_device *osd = osd_obj2dev(obj);
2784 struct osd_thandle *oh;
2787 LASSERT(obj->oo_inode != NULL);
2789 oh = container_of0(th, struct osd_thandle, ot_super);
2790 LASSERT(oh->ot_handle);
2791 osd_trans_exec_op(env, th, OSD_OT_INSERT);
2793 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2794 rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle,
2795 OI_CHECK_FLD, NULL);
2796 osd_trans_exec_check(env, th, OSD_OT_INSERT);
2801 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
2802 u64 seq, struct lu_seq_range *range)
2804 struct seq_server_site *ss = osd_seq_site(osd);
2806 if (fid_seq_is_idif(seq)) {
2807 fld_range_set_ost(range);
2808 range->lsr_index = idif_ost_idx(seq);
2812 if (!fid_seq_in_fldb(seq)) {
2813 fld_range_set_mdt(range);
2815 /* FIXME: If ss is NULL, it suppose not get lsr_index
2817 range->lsr_index = ss->ss_node_id;
2821 LASSERT(ss != NULL);
2822 fld_range_set_any(range);
2823 /* OSD will only do local fld lookup */
2824 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
2828 * Concurrency: no external locking is necessary.
2830 static int osd_declare_object_create(const struct lu_env *env,
2831 struct dt_object *dt,
2832 struct lu_attr *attr,
2833 struct dt_allocation_hint *hint,
2834 struct dt_object_format *dof,
2835 struct thandle *handle)
2837 struct osd_thandle *oh;
2841 LASSERT(handle != NULL);
2843 oh = container_of0(handle, struct osd_thandle, ot_super);
2844 LASSERT(oh->ot_handle == NULL);
2846 /* EA object consumes more credits than regular object: osd_mk_index
2847 * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and
2848 * leaf_node, could involves the block, block bitmap, groups, GDT
2849 * change for each block, so add 4 * 2 credits in that case. */
2850 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
2851 osd_dto_credits_noquota[DTO_OBJECT_CREATE] +
2852 (dof->dof_type == DFT_INDEX) ? 4 * 2 : 0);
2853 /* Reuse idle OI block may cause additional one OI block
2855 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2856 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
2861 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2862 osd_dt_obj(dt), false, NULL, false);
2866 /* will help to find FID->ino mapping at dt_insert() */
2867 rc = osd_idc_find_and_init(env, osd_obj2dev(osd_dt_obj(dt)),
2873 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2874 struct lu_attr *attr,
2875 struct dt_allocation_hint *hint,
2876 struct dt_object_format *dof, struct thandle *th)
2878 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2879 struct osd_object *obj = osd_dt_obj(dt);
2880 struct osd_thread_info *info = osd_oti_get(env);
2884 if (dt_object_exists(dt))
2887 LINVRNT(osd_invariant(obj));
2888 LASSERT(!dt_object_remote(dt));
2889 LASSERT(osd_write_locked(env, obj));
2890 LASSERT(th != NULL);
2892 if (unlikely(fid_is_acct(fid)))
2893 /* Quota files can't be created from the kernel any more,
2894 * 'tune2fs -O quota' will take care of creating them */
2897 result = __osd_object_create(info, obj, attr, hint, dof, th);
2899 result = __osd_oi_insert(env, obj, fid, th);
2900 if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
2901 obj->oo_dt.do_body_ops = &osd_body_ops;
2903 LASSERT(ergo(result == 0,
2904 dt_object_exists(dt) && !dt_object_remote(dt)));
2906 LASSERT(osd_invariant(obj));
2911 * Called to destroy on-disk representation of the object
2913 * Concurrency: must be locked
2915 static int osd_declare_object_destroy(const struct lu_env *env,
2916 struct dt_object *dt,
2919 struct osd_object *obj = osd_dt_obj(dt);
2920 struct inode *inode = obj->oo_inode;
2921 struct osd_thandle *oh;
2928 oh = container_of0(th, struct osd_thandle, ot_super);
2929 LASSERT(oh->ot_handle == NULL);
2931 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
2932 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2933 /* Recycle idle OI leaf may cause additional three OI blocks
2935 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
2936 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
2937 /* one less inode */
2938 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2939 -1, oh, obj, false, NULL, false);
2942 /* data to be truncated */
2943 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2944 0, oh, obj, true, NULL, false);
2948 /* will help to find FID->ino when this object is being
2949 * added to PENDING/ */
2950 rc = osd_idc_find_and_init(env, osd_obj2dev(obj), obj);
2955 static int osd_object_destroy(const struct lu_env *env,
2956 struct dt_object *dt,
2959 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2960 struct osd_object *obj = osd_dt_obj(dt);
2961 struct inode *inode = obj->oo_inode;
2962 struct osd_device *osd = osd_obj2dev(obj);
2963 struct osd_thandle *oh;
2967 oh = container_of0(th, struct osd_thandle, ot_super);
2968 LASSERT(oh->ot_handle);
2970 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2972 if (unlikely(fid_is_acct(fid)))
2975 if (S_ISDIR(inode->i_mode)) {
2976 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
2977 inode->i_nlink == 2);
2978 /* it will check/delete the inode from remote parent,
2979 * how to optimize it? unlink performance impaction XXX */
2980 result = osd_delete_from_remote_parent(env, osd, obj, oh);
2981 if (result != 0 && result != -ENOENT) {
2982 CERROR("%s: delete inode "DFID": rc = %d\n",
2983 osd_name(osd), PFID(fid), result);
2985 spin_lock(&obj->oo_guard);
2987 spin_unlock(&obj->oo_guard);
2988 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2991 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
2993 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
2994 result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
2997 osd_trans_exec_check(env, th, OSD_OT_DESTROY);
2998 /* XXX: add to ext3 orphan list */
2999 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
3001 /* not needed in the cache anymore */
3002 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
3003 obj->oo_destroyed = 1;
3009 * Put the fid into lustre_mdt_attrs, and then place the structure
3010 * inode's ea. This fid should not be altered during the life time
3013 * \retval +ve, on success
3014 * \retval -ve, on error
3016 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
3018 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
3019 const struct lu_fid *fid, __u32 compat, __u32 incompat)
3021 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
3025 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
3028 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
3031 lustre_lma_init(lma, fid, compat, incompat);
3032 lustre_lma_swab(lma);
3034 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma, sizeof(*lma),
3036 /* LMA may already exist, but we need to check that all the
3037 * desired compat/incompat flags have been added. */
3038 if (unlikely(rc == -EEXIST)) {
3039 if (compat == 0 && incompat == 0)
3042 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
3043 XATTR_NAME_LMA, info->oti_mdt_attrs_old,
3048 lustre_lma_swab(lma);
3049 if (!(~lma->lma_compat & compat) &&
3050 !(~lma->lma_incompat & incompat))
3053 lma->lma_compat |= compat;
3054 lma->lma_incompat |= incompat;
3055 lustre_lma_swab(lma);
3056 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3057 sizeof(*lma), XATTR_REPLACE);
3064 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
3065 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
3066 * To have compatilibility with 1.8 ldiskfs driver we need to have
3067 * magic number at start of fid data.
3068 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
3071 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
3072 const struct lu_fid *fid)
3074 if (!fid_is_namespace_visible(fid) ||
3075 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
3076 param->edp_magic = 0;
3080 param->edp_magic = LDISKFS_LUFID_MAGIC;
3081 param->edp_len = sizeof(struct lu_fid) + 1;
3082 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
3086 * Try to read the fid from inode ea into dt_rec.
3088 * \param fid object fid.
3090 * \retval 0 on success
3092 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
3093 __u32 ino, struct lu_fid *fid,
3094 struct osd_inode_id *id)
3096 struct osd_thread_info *info = osd_oti_get(env);
3097 struct inode *inode;
3100 osd_id_gen(id, ino, OSD_OII_NOGEN);
3101 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
3103 RETURN(PTR_ERR(inode));
3109 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
3111 struct inode *parent_dir,
3112 const struct lu_fid *dot_fid,
3113 const struct lu_fid *dot_dot_fid,
3114 struct osd_thandle *oth)
3116 struct ldiskfs_dentry_param *dot_ldp;
3117 struct ldiskfs_dentry_param *dot_dot_ldp;
3118 __u32 saved_nlink = dir->i_nlink;
3121 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3122 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3124 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3125 dot_ldp->edp_magic = 0;
3127 rc = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3128 dir, dot_ldp, dot_dot_ldp);
3129 /* The ldiskfs_add_dot_dotdot() may dir->i_nlink as 2, then
3130 * the subseqent ref_add() will increase the dir->i_nlink
3131 * as 3. That is incorrect for new created directory.
3133 * It looks like hack, because we want to make the OSD API
3134 * to be order-independent for new created directory object
3135 * between dt_insert(..) and ref_add() operations.
3137 * Here, we only restore the in-RAM dir-inode's nlink attr,
3138 * becuase if the nlink attr is not 2, then there will be
3139 * ref_add() called following the dt_insert(..), such call
3140 * will make both the in-RAM and on-disk dir-inode's nlink
3141 * attr to be set as 2. LU-7447 */
3142 set_nlink(dir, saved_nlink);
3147 * Create an local agent inode for remote entry
3149 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
3150 struct osd_device *osd,
3151 struct osd_object *pobj,
3152 const struct lu_fid *fid,
3156 struct osd_thread_info *info = osd_oti_get(env);
3157 struct inode *local;
3158 struct osd_thandle *oh;
3163 oh = container_of(th, struct osd_thandle, ot_super);
3164 LASSERT(oh->ot_handle->h_transaction != NULL);
3166 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
3167 if (IS_ERR(local)) {
3168 CERROR("%s: create local error %d\n", osd_name(osd),
3169 (int)PTR_ERR(local));
3173 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
3174 unlock_new_inode(local);
3176 /* Set special LMA flag for local agent inode */
3177 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
3179 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
3180 osd_name(osd), PFID(fid), rc);
3181 RETURN(ERR_PTR(rc));
3187 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
3188 lu_object_fid(&pobj->oo_dt.do_lu),
3191 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
3192 osd_name(osd), PFID(fid), rc);
3193 RETURN(ERR_PTR(rc));
3200 * when direntry is deleted, we have to take care of possible agent inode
3201 * referenced by that. unfortunately we can't do this at that point:
3202 * iget() within a running transaction leads to deadlock and we better do
3203 * not call that every delete declaration to save performance. so we put
3204 * a potention agent inode on a list and process that once the transaction
3205 * is over. Notice it's not any worse in terms of real orphans as regular
3206 * object destroy doesn't put inodes on the on-disk orphan list. this should
3207 * be addressed separately
3209 static int osd_schedule_agent_inode_removal(const struct lu_env *env,
3210 struct osd_thandle *oh,
3213 struct osd_device *osd = osd_dt_dev(oh->ot_super.th_dev);
3214 struct osd_obj_orphan *oor;
3221 oor->oor_env = (struct lu_env *)env;
3222 spin_lock(&osd->od_osfs_lock);
3223 list_add(&oor->oor_list, &osd->od_orphan_list);
3224 spin_unlock(&osd->od_osfs_lock);
3226 oh->ot_remove_agents = 1;
3232 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
3233 struct osd_device *osd)
3235 struct osd_thread_info *info = osd_oti_get(env);
3236 struct osd_obj_orphan *oor, *tmp;
3237 struct osd_inode_id id;
3238 struct list_head list;
3239 struct inode *inode;
3244 INIT_LIST_HEAD(&list);
3246 spin_lock(&osd->od_osfs_lock);
3247 list_for_each_entry_safe(oor, tmp, &osd->od_orphan_list, oor_list) {
3248 if (oor->oor_env == env) {
3249 list_del(&oor->oor_list);
3250 list_add(&oor->oor_list, &list);
3253 spin_unlock(&osd->od_osfs_lock);
3255 list_for_each_entry_safe(oor, tmp, &list, oor_list) {
3259 list_del(&oor->oor_list);
3262 osd_id_gen(&id, ino, OSD_OII_NOGEN);
3263 inode = osd_iget_fid(info, osd, &id, &fid);
3267 if (!osd_remote_fid(env, osd, &fid)) {
3272 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC, 1);
3274 mark_inode_dirty(inode);
3275 ldiskfs_journal_stop(jh);
3283 * OSD layer object create function for interoperability mode (b11826).
3284 * This is mostly similar to osd_object_create(). Only difference being, fid is
3285 * inserted into inode ea here.
3287 * \retval 0, on success
3288 * \retval -ve, on error
3290 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
3291 struct lu_attr *attr,
3292 struct dt_allocation_hint *hint,
3293 struct dt_object_format *dof,
3296 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
3297 struct osd_object *obj = osd_dt_obj(dt);
3298 struct osd_thread_info *info = osd_oti_get(env);
3299 int result, on_ost = 0;
3303 if (dt_object_exists(dt))
3306 LASSERT(osd_invariant(obj));
3307 LASSERT(!dt_object_remote(dt));
3308 LASSERT(osd_write_locked(env, obj));
3309 LASSERT(th != NULL);
3311 if (unlikely(fid_is_acct(fid)))
3312 /* Quota files can't be created from the kernel any more,
3313 * 'tune2fs -O quota' will take care of creating them */
3316 result = __osd_object_create(info, obj, attr, hint, dof, th);
3318 if (fid_is_idif(fid) &&
3319 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
3320 struct lu_fid *tfid = &info->oti_fid;
3321 struct ost_id *oi = &info->oti_ostid;
3323 fid_to_ostid(fid, oi);
3324 ostid_to_fid(tfid, oi, 0);
3326 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
3327 LMAC_FID_ON_OST, 0);
3329 on_ost = fid_is_on_ost(info, osd_obj2dev(obj),
3331 result = osd_ea_fid_set(info, obj->oo_inode, fid,
3332 on_ost ? LMAC_FID_ON_OST : 0,
3335 if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
3336 obj->oo_dt.do_body_ops = &osd_body_ops;
3340 result = __osd_oi_insert(env, obj, fid, th);
3342 /* a small optimization - dt_insert() isn't usually applied
3343 * to OST objects, so we don't need to cache OI mapping for
3345 if (result == 0 && on_ost == 0) {
3346 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3347 result = osd_idc_find_and_init(env, osd, obj);
3348 LASSERT(result == 0);
3351 LASSERT(ergo(result == 0,
3352 dt_object_exists(dt) && !dt_object_remote(dt)));
3353 LINVRNT(osd_invariant(obj));
3357 static int osd_declare_object_ref_add(const struct lu_env *env,
3358 struct dt_object *dt,
3359 struct thandle *handle)
3361 struct osd_thandle *oh;
3363 /* it's possible that object doesn't exist yet */
3364 LASSERT(handle != NULL);
3366 oh = container_of0(handle, struct osd_thandle, ot_super);
3367 LASSERT(oh->ot_handle == NULL);
3369 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
3370 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3376 * Concurrency: @dt is write locked.
3378 static int osd_object_ref_add(const struct lu_env *env,
3379 struct dt_object *dt, struct thandle *th)
3381 struct osd_object *obj = osd_dt_obj(dt);
3382 struct inode *inode = obj->oo_inode;
3383 struct osd_thandle *oh;
3386 if (!dt_object_exists(dt) || obj->oo_destroyed)
3389 LINVRNT(osd_invariant(obj));
3390 LASSERT(!dt_object_remote(dt));
3391 LASSERT(osd_write_locked(env, obj));
3392 LASSERT(th != NULL);
3394 oh = container_of0(th, struct osd_thandle, ot_super);
3395 LASSERT(oh->ot_handle != NULL);
3397 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
3399 CDEBUG(D_INODE, DFID" increase nlink %d\n",
3400 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
3402 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
3403 * (65000) subdirectories by storing "1" in i_nlink if the link count
3404 * would otherwise overflow. Directory tranversal tools understand
3405 * that (st_nlink == 1) indicates that the filesystem dose not track
3406 * hard links count on the directory, and will not abort subdirectory
3407 * scanning early once (st_nlink - 2) subdirs have been found.
3409 * This also has to properly handle the case of inodes with nlink == 0
3410 * in case they are being linked into the PENDING directory
3412 spin_lock(&obj->oo_guard);
3413 if (unlikely(inode->i_nlink == 0))
3414 /* inc_nlink from 0 may cause WARN_ON */
3415 set_nlink(inode, 1);
3417 ldiskfs_inc_count(oh->ot_handle, inode);
3418 if (!S_ISDIR(inode->i_mode))
3419 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
3421 spin_unlock(&obj->oo_guard);
3423 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3424 LINVRNT(osd_invariant(obj));
3426 osd_trans_exec_check(env, th, OSD_OT_REF_ADD);
3431 static int osd_declare_object_ref_del(const struct lu_env *env,
3432 struct dt_object *dt,
3433 struct thandle *handle)
3435 struct osd_thandle *oh;
3437 if (!dt_object_exists(dt))
3440 LASSERT(!dt_object_remote(dt));
3441 LASSERT(handle != NULL);
3443 oh = container_of0(handle, struct osd_thandle, ot_super);
3444 LASSERT(oh->ot_handle == NULL);
3446 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
3447 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3453 * Concurrency: @dt is write locked.
3455 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
3458 struct osd_object *obj = osd_dt_obj(dt);
3459 struct inode *inode = obj->oo_inode;
3460 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3461 struct osd_thandle *oh;
3463 if (!dt_object_exists(dt))
3466 LINVRNT(osd_invariant(obj));
3467 LASSERT(!dt_object_remote(dt));
3468 LASSERT(osd_write_locked(env, obj));
3469 LASSERT(th != NULL);
3471 oh = container_of0(th, struct osd_thandle, ot_super);
3472 LASSERT(oh->ot_handle != NULL);
3474 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
3476 spin_lock(&obj->oo_guard);
3477 /* That can be result of upgrade from old Lustre version and
3478 * applied only to local files. Just skip this ref_del call.
3479 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
3480 if (inode->i_nlink == 0) {
3481 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
3482 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
3483 ", maybe an upgraded file? (LU-3915)\n",
3484 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
3485 spin_unlock(&obj->oo_guard);
3489 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
3490 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
3492 ldiskfs_dec_count(oh->ot_handle, inode);
3493 spin_unlock(&obj->oo_guard);
3495 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3496 LINVRNT(osd_invariant(obj));
3498 osd_trans_exec_check(env, th, OSD_OT_REF_DEL);
3504 * Get the 64-bit version for an inode.
3506 static int osd_object_version_get(const struct lu_env *env,
3507 struct dt_object *dt, dt_obj_version_t *ver)
3509 struct inode *inode = osd_dt_obj(dt)->oo_inode;
3511 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
3512 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
3513 *ver = LDISKFS_I(inode)->i_fs_version;
3518 * Concurrency: @dt is read locked.
3520 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
3521 struct lu_buf *buf, const char *name)
3523 struct osd_object *obj = osd_dt_obj(dt);
3524 struct inode *inode = obj->oo_inode;
3525 struct osd_thread_info *info = osd_oti_get(env);
3526 struct dentry *dentry = &info->oti_obj_dentry;
3527 bool cache_xattr = false;
3530 /* version get is not real XATTR but uses xattr API */
3531 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
3532 /* for version we are just using xattr API but change inode
3534 if (buf->lb_len == 0)
3535 return sizeof(dt_obj_version_t);
3537 if (buf->lb_len < sizeof(dt_obj_version_t))
3540 osd_object_version_get(env, dt, buf->lb_buf);
3542 return sizeof(dt_obj_version_t);
3545 if (!dt_object_exists(dt))
3548 LASSERT(!dt_object_remote(dt));
3549 LASSERT(inode->i_op != NULL);
3550 LASSERT(inode->i_op->getxattr != NULL);
3552 if (strcmp(name, XATTR_NAME_LOV) == 0 ||
3553 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
3557 rc = osd_oxc_get(obj, name, buf);
3562 rc = __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len);
3564 if (rc == -ENOENT || rc == -ENODATA)
3565 osd_oxc_add(obj, name, NULL, 0);
3566 else if (rc > 0 && buf->lb_buf != NULL)
3567 osd_oxc_add(obj, name, buf->lb_buf, rc);
3573 static int osd_declare_xattr_set(const struct lu_env *env,
3574 struct dt_object *dt,
3575 const struct lu_buf *buf, const char *name,
3576 int fl, struct thandle *handle)
3578 struct osd_thandle *oh;
3580 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3582 LASSERT(handle != NULL);
3584 oh = container_of0(handle, struct osd_thandle, ot_super);
3585 LASSERT(oh->ot_handle == NULL);
3587 if (strcmp(name, XATTR_NAME_LMA) == 0) {
3588 /* For non-upgrading case, the LMA is set first and
3589 * usually fit inode. But for upgrade case, the LMA
3590 * may be in another separated EA block. */
3591 if (!dt_object_exists(dt))
3593 else if (fl == LU_XATTR_REPLACE)
3597 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
3601 credits = osd_dto_credits_noquota[DTO_XATTR_SET];
3606 if (buf->lb_buf == NULL && dt_object_exists(dt)) {
3607 /* learn xattr size from osd_xattr_get if
3608 attribute has not been read yet */
3609 buflen = __osd_xattr_get(
3610 osd_dt_obj(dt)->oo_inode,
3611 &osd_oti_get(env)->oti_obj_dentry,
3616 buflen = buf->lb_len;
3619 if (buflen > sb->s_blocksize) {
3620 credits += osd_calc_bkmap_credits(
3622 (buflen + sb->s_blocksize - 1) >>
3623 sb->s_blocksize_bits);
3627 * xattr set may involve inode quota change, reserve credits for
3628 * dquot_initialize()
3630 credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
3633 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
3639 * Set the 64-bit version for object
3641 static void osd_object_version_set(const struct lu_env *env,
3642 struct dt_object *dt,
3643 dt_obj_version_t *new_version)
3645 struct inode *inode = osd_dt_obj(dt)->oo_inode;
3647 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
3648 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
3650 LDISKFS_I(inode)->i_fs_version = *new_version;
3651 /** Version is set after all inode operations are finished,
3652 * so we should mark it dirty here */
3653 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3657 * Concurrency: @dt is write locked.
3659 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
3660 const struct lu_buf *buf, const char *name, int fl,
3661 struct thandle *handle)
3663 struct osd_object *obj = osd_dt_obj(dt);
3664 struct inode *inode = obj->oo_inode;
3665 struct osd_thread_info *info = osd_oti_get(env);
3670 LASSERT(handle != NULL);
3672 /* version set is not real XATTR */
3673 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
3674 /* for version we are just using xattr API but change inode
3676 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
3677 osd_object_version_set(env, dt, buf->lb_buf);
3678 return sizeof(dt_obj_version_t);
3681 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
3682 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
3684 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3685 if (fl & LU_XATTR_REPLACE)
3686 fs_flags |= XATTR_REPLACE;
3688 if (fl & LU_XATTR_CREATE)
3689 fs_flags |= XATTR_CREATE;
3691 if (strcmp(name, XATTR_NAME_LMV) == 0) {
3692 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
3695 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
3699 lma->lma_incompat |= LMAI_STRIPED;
3700 lustre_lma_swab(lma);
3701 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3702 sizeof(*lma), XATTR_REPLACE);
3707 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
3708 strcmp(name, XATTR_NAME_LINK) == 0)
3711 rc = __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
3713 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
3716 (strcmp(name, XATTR_NAME_LOV) == 0 ||
3717 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
3718 osd_oxc_add(obj, name, buf->lb_buf, buf->lb_len);
3724 * Concurrency: @dt is read locked.
3726 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
3727 const struct lu_buf *buf)
3729 struct osd_object *obj = osd_dt_obj(dt);
3730 struct inode *inode = obj->oo_inode;
3731 struct osd_thread_info *info = osd_oti_get(env);
3732 struct dentry *dentry = &info->oti_obj_dentry;
3734 if (!dt_object_exists(dt))
3737 LASSERT(!dt_object_remote(dt));
3738 LASSERT(inode->i_op != NULL);
3739 LASSERT(inode->i_op->listxattr != NULL);
3741 dentry->d_inode = inode;
3742 dentry->d_sb = inode->i_sb;
3743 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
3746 static int osd_declare_xattr_del(const struct lu_env *env,
3747 struct dt_object *dt, const char *name,
3748 struct thandle *handle)
3750 struct osd_thandle *oh;
3751 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3753 LASSERT(!dt_object_remote(dt));
3754 LASSERT(handle != NULL);
3756 oh = container_of0(handle, struct osd_thandle, ot_super);
3757 LASSERT(oh->ot_handle == NULL);
3759 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
3760 osd_dto_credits_noquota[DTO_XATTR_SET]);
3762 * xattr del may involve inode quota change, reserve credits for
3763 * dquot_initialize()
3765 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
3771 * Concurrency: @dt is write locked.
3773 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
3774 const char *name, struct thandle *handle)
3776 struct osd_object *obj = osd_dt_obj(dt);
3777 struct inode *inode = obj->oo_inode;
3778 struct osd_thread_info *info = osd_oti_get(env);
3779 struct dentry *dentry = &info->oti_obj_dentry;
3782 if (!dt_object_exists(dt))
3785 LASSERT(!dt_object_remote(dt));
3786 LASSERT(inode->i_op != NULL);
3787 LASSERT(inode->i_op->removexattr != NULL);
3788 LASSERT(handle != NULL);
3790 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3792 ll_vfs_dq_init(inode);
3793 dentry->d_inode = inode;
3794 dentry->d_sb = inode->i_sb;
3795 rc = inode->i_op->removexattr(dentry, name);
3796 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
3799 (strcmp(name, XATTR_NAME_LOV) == 0 ||
3800 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
3801 osd_oxc_del(obj, name);
3806 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
3807 __u64 start, __u64 end)
3809 struct osd_object *obj = osd_dt_obj(dt);
3810 struct inode *inode = obj->oo_inode;
3811 struct osd_thread_info *info = osd_oti_get(env);
3812 struct dentry *dentry = &info->oti_obj_dentry;
3813 struct file *file = &info->oti_file;
3818 dentry->d_inode = inode;
3819 dentry->d_sb = inode->i_sb;
3820 file->f_path.dentry = dentry;
3821 file->f_mapping = inode->i_mapping;
3822 file->f_op = inode->i_fop;
3823 set_file_inode(file, inode);
3825 rc = ll_vfs_fsync_range(file, start, end, 0);
3834 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
3835 const struct dt_index_features *feat)
3837 struct iam_descr *descr;
3839 if (osd_object_is_root(o))
3840 return feat == &dt_directory_features;
3842 LASSERT(o->oo_dir != NULL);
3844 descr = o->oo_dir->od_container.ic_descr;
3845 if (feat == &dt_directory_features) {
3846 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
3852 feat->dif_keysize_min <= descr->id_key_size &&
3853 descr->id_key_size <= feat->dif_keysize_max &&
3854 feat->dif_recsize_min <= descr->id_rec_size &&
3855 descr->id_rec_size <= feat->dif_recsize_max &&
3856 !(feat->dif_flags & (DT_IND_VARKEY |
3857 DT_IND_VARREC | DT_IND_NONUNQ)) &&
3858 ergo(feat->dif_flags & DT_IND_UPDATE,
3859 1 /* XXX check that object (and file system) is
3864 static int osd_iam_container_init(const struct lu_env *env,
3865 struct osd_object *obj,
3866 struct osd_directory *dir)
3868 struct iam_container *bag = &dir->od_container;
3871 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
3875 result = iam_container_setup(bag);
3877 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
3879 iam_container_fini(bag);
3886 * Concurrency: no external locking is necessary.
3888 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
3889 const struct dt_index_features *feat)
3893 struct osd_object *obj = osd_dt_obj(dt);
3895 LINVRNT(osd_invariant(obj));
3897 if (osd_object_is_root(obj)) {
3898 dt->do_index_ops = &osd_index_ea_ops;
3900 } else if (feat == &dt_directory_features) {
3901 dt->do_index_ops = &osd_index_ea_ops;
3902 if (obj->oo_inode == NULL || S_ISDIR(obj->oo_inode->i_mode))
3907 } else if (unlikely(feat == &dt_otable_features)) {
3908 dt->do_index_ops = &osd_otable_ops;
3910 } else if (unlikely(feat == &dt_acct_features)) {
3911 dt->do_index_ops = &osd_acct_index_ops;
3914 } else if (!osd_has_index(obj)) {
3915 struct osd_directory *dir;
3920 spin_lock(&obj->oo_guard);
3921 if (obj->oo_dir == NULL)
3925 * Concurrent thread allocated container data.
3928 spin_unlock(&obj->oo_guard);
3930 * Now, that we have container data, serialize its
3933 down_write(&obj->oo_ext_idx_sem);
3935 * recheck under lock.
3937 if (!osd_has_index(obj))
3938 result = osd_iam_container_init(env, obj,
3942 up_write(&obj->oo_ext_idx_sem);
3950 if (result == 0 && skip_iam == 0) {
3951 if (!osd_iam_index_probe(env, obj, feat))
3954 LINVRNT(osd_invariant(obj));
3956 if (result == 0 && feat == &dt_quota_glb_features &&
3957 fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
3958 result = osd_quota_migration(env, dt);
3963 static int osd_otable_it_attr_get(const struct lu_env *env,
3964 struct dt_object *dt,
3965 struct lu_attr *attr)
3971 static const struct dt_object_operations osd_obj_ops = {
3972 .do_read_lock = osd_object_read_lock,
3973 .do_write_lock = osd_object_write_lock,
3974 .do_read_unlock = osd_object_read_unlock,
3975 .do_write_unlock = osd_object_write_unlock,
3976 .do_write_locked = osd_object_write_locked,
3977 .do_attr_get = osd_attr_get,
3978 .do_declare_attr_set = osd_declare_attr_set,
3979 .do_attr_set = osd_attr_set,
3980 .do_ah_init = osd_ah_init,
3981 .do_declare_create = osd_declare_object_create,
3982 .do_create = osd_object_create,
3983 .do_declare_destroy = osd_declare_object_destroy,
3984 .do_destroy = osd_object_destroy,
3985 .do_index_try = osd_index_try,
3986 .do_declare_ref_add = osd_declare_object_ref_add,
3987 .do_ref_add = osd_object_ref_add,
3988 .do_declare_ref_del = osd_declare_object_ref_del,
3989 .do_ref_del = osd_object_ref_del,
3990 .do_xattr_get = osd_xattr_get,
3991 .do_declare_xattr_set = osd_declare_xattr_set,
3992 .do_xattr_set = osd_xattr_set,
3993 .do_declare_xattr_del = osd_declare_xattr_del,
3994 .do_xattr_del = osd_xattr_del,
3995 .do_xattr_list = osd_xattr_list,
3996 .do_object_sync = osd_object_sync,
4000 * dt_object_operations for interoperability mode
4001 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4003 static const struct dt_object_operations osd_obj_ea_ops = {
4004 .do_read_lock = osd_object_read_lock,
4005 .do_write_lock = osd_object_write_lock,
4006 .do_read_unlock = osd_object_read_unlock,
4007 .do_write_unlock = osd_object_write_unlock,
4008 .do_write_locked = osd_object_write_locked,
4009 .do_attr_get = osd_attr_get,
4010 .do_declare_attr_set = osd_declare_attr_set,
4011 .do_attr_set = osd_attr_set,
4012 .do_ah_init = osd_ah_init,
4013 .do_declare_create = osd_declare_object_create,
4014 .do_create = osd_object_ea_create,
4015 .do_declare_destroy = osd_declare_object_destroy,
4016 .do_destroy = osd_object_destroy,
4017 .do_index_try = osd_index_try,
4018 .do_declare_ref_add = osd_declare_object_ref_add,
4019 .do_ref_add = osd_object_ref_add,
4020 .do_declare_ref_del = osd_declare_object_ref_del,
4021 .do_ref_del = osd_object_ref_del,
4022 .do_xattr_get = osd_xattr_get,
4023 .do_declare_xattr_set = osd_declare_xattr_set,
4024 .do_xattr_set = osd_xattr_set,
4025 .do_declare_xattr_del = osd_declare_xattr_del,
4026 .do_xattr_del = osd_xattr_del,
4027 .do_xattr_list = osd_xattr_list,
4028 .do_object_sync = osd_object_sync,
4031 static const struct dt_object_operations osd_obj_otable_it_ops = {
4032 .do_attr_get = osd_otable_it_attr_get,
4033 .do_index_try = osd_index_try,
4036 static int osd_index_declare_iam_delete(const struct lu_env *env,
4037 struct dt_object *dt,
4038 const struct dt_key *key,
4039 struct thandle *handle)
4041 struct osd_thandle *oh;
4043 oh = container_of0(handle, struct osd_thandle, ot_super);
4044 LASSERT(oh->ot_handle == NULL);
4046 /* Recycle may cause additional three blocks to be changed. */
4047 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
4048 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
4054 * delete a (key, value) pair from index \a dt specified by \a key
4056 * \param dt osd index object
4057 * \param key key for index
4058 * \param rec record reference
4059 * \param handle transaction handler
4062 * \retval -ve failure
4064 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
4065 const struct dt_key *key,
4066 struct thandle *handle)
4068 struct osd_thread_info *oti = osd_oti_get(env);
4069 struct osd_object *obj = osd_dt_obj(dt);
4070 struct osd_thandle *oh;
4071 struct iam_path_descr *ipd;
4072 struct iam_container *bag = &obj->oo_dir->od_container;
4076 if (!dt_object_exists(dt))
4079 LINVRNT(osd_invariant(obj));
4080 LASSERT(!dt_object_remote(dt));
4081 LASSERT(bag->ic_object == obj->oo_inode);
4082 LASSERT(handle != NULL);
4084 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
4086 ipd = osd_idx_ipd_get(env, bag);
4087 if (unlikely(ipd == NULL))
4090 oh = container_of0(handle, struct osd_thandle, ot_super);
4091 LASSERT(oh->ot_handle != NULL);
4092 LASSERT(oh->ot_handle->h_transaction != NULL);
4094 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4095 /* swab quota uid/gid provided by caller */
4096 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4097 key = (const struct dt_key *)&oti->oti_quota_id;
4100 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
4101 osd_ipd_put(env, bag, ipd);
4102 LINVRNT(osd_invariant(obj));
4103 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
4107 static int osd_index_declare_ea_delete(const struct lu_env *env,
4108 struct dt_object *dt,
4109 const struct dt_key *key,
4110 struct thandle *handle)
4112 struct osd_thandle *oh;
4113 struct inode *inode;
4117 LASSERT(!dt_object_remote(dt));
4118 LASSERT(handle != NULL);
4120 oh = container_of0(handle, struct osd_thandle, ot_super);
4121 LASSERT(oh->ot_handle == NULL);
4123 /* due to DNE we may need to remove an agent inode */
4124 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
4125 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
4126 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
4128 inode = osd_dt_obj(dt)->oo_inode;
4132 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
4133 0, oh, osd_dt_obj(dt), true, NULL, false);
4137 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
4140 struct osd_fid_pack *rec;
4143 if (de->file_type & LDISKFS_DIRENT_LUFID) {
4144 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
4145 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
4146 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
4152 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
4153 const struct lu_fid *fid)
4155 struct seq_server_site *ss = osd_seq_site(osd);
4158 /* FID seqs not in FLDB, must be local seq */
4159 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
4162 /* If FLD is not being initialized yet, it only happens during the
4163 * initialization, likely during mgs initialization, and we assume
4164 * this is local FID. */
4165 if (ss == NULL || ss->ss_server_fld == NULL)
4168 /* Only check the local FLDB here */
4169 if (osd_seq_exists(env, osd, fid_seq(fid)))
4176 * Index delete function for interoperability mode (b11826).
4177 * It will remove the directory entry added by osd_index_ea_insert().
4178 * This entry is needed to maintain name->fid mapping.
4180 * \param key, key i.e. file entry to be deleted
4182 * \retval 0, on success
4183 * \retval -ve, on error
4185 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
4186 const struct dt_key *key, struct thandle *handle)
4188 struct osd_object *obj = osd_dt_obj(dt);
4189 struct inode *dir = obj->oo_inode;
4190 struct dentry *dentry;
4191 struct osd_thandle *oh;
4192 struct ldiskfs_dir_entry_2 *de = NULL;
4193 struct buffer_head *bh;
4194 struct htree_lock *hlock = NULL;
4195 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
4196 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4200 if (!dt_object_exists(dt))
4203 LINVRNT(osd_invariant(obj));
4204 LASSERT(!dt_object_remote(dt));
4205 LASSERT(handle != NULL);
4207 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
4209 oh = container_of(handle, struct osd_thandle, ot_super);
4210 LASSERT(oh->ot_handle != NULL);
4211 LASSERT(oh->ot_handle->h_transaction != NULL);
4213 ll_vfs_dq_init(dir);
4214 dentry = osd_child_dentry_get(env, obj,
4215 (char *)key, strlen((char *)key));
4217 if (obj->oo_hl_head != NULL) {
4218 hlock = osd_oti_get(env)->oti_hlock;
4219 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4220 dir, LDISKFS_HLOCK_DEL);
4222 down_write(&obj->oo_ext_idx_sem);
4225 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4227 /* If this is not the ".." entry, it might be a remote DNE
4228 * entry and we need to check if the FID is for a remote
4229 * MDT. If the FID is not in the directory entry (e.g.
4230 * upgraded 1.8 filesystem without dirdata enabled) then
4231 * we need to get the FID from the LMA. For a remote directory
4232 * there HAS to be an LMA, it cannot be an IGIF inode in this
4235 * Delete the entry before the agent inode in order to
4236 * simplify error handling. At worst an error after deleting
4237 * the entry first might leak the agent inode afterward. The
4238 * reverse would need filesystem abort in case of error deleting
4239 * the entry after the agent had been removed, or leave a
4240 * dangling entry pointing at a random inode. */
4241 if (strcmp((char *)key, dotdot) != 0) {
4242 LASSERT(de != NULL);
4243 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
4244 if (rc == -ENODATA) {
4245 /* can't get FID, postpone to the end of the
4246 * transaction when iget() is safe */
4247 osd_schedule_agent_inode_removal(env, oh,
4248 le32_to_cpu(de->inode));
4249 } else if (rc == 0 &&
4250 unlikely(osd_remote_fid(env, osd, fid))) {
4251 osd_schedule_agent_inode_removal(env, oh,
4252 le32_to_cpu(de->inode));
4255 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
4261 ldiskfs_htree_unlock(hlock);
4263 up_write(&obj->oo_ext_idx_sem);
4268 /* For inode on the remote MDT, .. will point to
4269 * /Agent directory, Check whether it needs to delete
4270 * from agent directory */
4271 if (unlikely(strcmp((char *)key, dotdot) == 0)) {
4272 rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj,
4274 if (rc != 0 && rc != -ENOENT) {
4275 CERROR("%s: delete agent inode "DFID": rc = %d\n",
4276 osd_name(osd), PFID(fid), rc);
4286 LASSERT(osd_invariant(obj));
4287 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
4292 * Lookup index for \a key and copy record to \a rec.
4294 * \param dt osd index object
4295 * \param key key for index
4296 * \param rec record reference
4298 * \retval +ve success : exact mach
4299 * \retval 0 return record with key not greater than \a key
4300 * \retval -ve failure
4302 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
4303 struct dt_rec *rec, const struct dt_key *key)
4305 struct osd_object *obj = osd_dt_obj(dt);
4306 struct iam_path_descr *ipd;
4307 struct iam_container *bag = &obj->oo_dir->od_container;
4308 struct osd_thread_info *oti = osd_oti_get(env);
4309 struct iam_iterator *it = &oti->oti_idx_it;
4310 struct iam_rec *iam_rec;
4314 if (!dt_object_exists(dt))
4317 LASSERT(osd_invariant(obj));
4318 LASSERT(!dt_object_remote(dt));
4319 LASSERT(bag->ic_object == obj->oo_inode);
4321 ipd = osd_idx_ipd_get(env, bag);
4325 /* got ipd now we can start iterator. */
4326 iam_it_init(it, bag, 0, ipd);
4328 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4329 /* swab quota uid/gid provided by caller */
4330 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4331 key = (const struct dt_key *)&oti->oti_quota_id;
4334 rc = iam_it_get(it, (struct iam_key *)key);
4336 if (S_ISDIR(obj->oo_inode->i_mode))
4337 iam_rec = (struct iam_rec *)oti->oti_ldp;
4339 iam_rec = (struct iam_rec *) rec;
4341 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
4343 if (S_ISDIR(obj->oo_inode->i_mode))
4344 osd_fid_unpack((struct lu_fid *) rec,
4345 (struct osd_fid_pack *)iam_rec);
4346 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
4347 osd_quota_unpack(obj, rec);
4352 osd_ipd_put(env, bag, ipd);
4354 LINVRNT(osd_invariant(obj));
4359 static int osd_index_declare_iam_insert(const struct lu_env *env,
4360 struct dt_object *dt,
4361 const struct dt_rec *rec,
4362 const struct dt_key *key,
4363 struct thandle *handle)
4365 struct osd_thandle *oh;
4367 LASSERT(handle != NULL);
4369 oh = container_of0(handle, struct osd_thandle, ot_super);
4370 LASSERT(oh->ot_handle == NULL);
4372 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4373 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4379 * Inserts (key, value) pair in \a dt index object.
4381 * \param dt osd index object
4382 * \param key key for index
4383 * \param rec record reference
4384 * \param th transaction handler
4387 * \retval -ve failure
4389 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
4390 const struct dt_rec *rec,
4391 const struct dt_key *key, struct thandle *th,
4394 struct osd_object *obj = osd_dt_obj(dt);
4395 struct iam_path_descr *ipd;
4396 struct osd_thandle *oh;
4397 struct iam_container *bag;
4398 struct osd_thread_info *oti = osd_oti_get(env);
4399 struct iam_rec *iam_rec;
4403 if (!dt_object_exists(dt))
4406 LINVRNT(osd_invariant(obj));
4407 LASSERT(!dt_object_remote(dt));
4409 bag = &obj->oo_dir->od_container;
4410 LASSERT(bag->ic_object == obj->oo_inode);
4411 LASSERT(th != NULL);
4413 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4415 ipd = osd_idx_ipd_get(env, bag);
4416 if (unlikely(ipd == NULL))
4419 oh = container_of0(th, struct osd_thandle, ot_super);
4420 LASSERT(oh->ot_handle != NULL);
4421 LASSERT(oh->ot_handle->h_transaction != NULL);
4422 if (S_ISDIR(obj->oo_inode->i_mode)) {
4423 iam_rec = (struct iam_rec *)oti->oti_ldp;
4424 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
4425 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4426 /* pack quota uid/gid */
4427 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4428 key = (const struct dt_key *)&oti->oti_quota_id;
4429 /* pack quota record */
4430 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
4431 iam_rec = (struct iam_rec *)rec;
4433 iam_rec = (struct iam_rec *)rec;
4436 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
4438 osd_ipd_put(env, bag, ipd);
4439 LINVRNT(osd_invariant(obj));
4440 osd_trans_exec_check(env, th, OSD_OT_INSERT);
4445 * Calls ldiskfs_add_entry() to add directory entry
4446 * into the directory. This is required for
4447 * interoperability mode (b11826)
4449 * \retval 0, on success
4450 * \retval -ve, on error
4452 static int __osd_ea_add_rec(struct osd_thread_info *info,
4453 struct osd_object *pobj, struct inode *cinode,
4454 const char *name, const struct lu_fid *fid,
4455 struct htree_lock *hlock, struct thandle *th)
4457 struct ldiskfs_dentry_param *ldp;
4458 struct dentry *child;
4459 struct osd_thandle *oth;
4462 oth = container_of(th, struct osd_thandle, ot_super);
4463 LASSERT(oth->ot_handle != NULL);
4464 LASSERT(oth->ot_handle->h_transaction != NULL);
4465 LASSERT(pobj->oo_inode);
4467 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
4468 if (unlikely(pobj->oo_inode ==
4469 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
4472 osd_get_ldiskfs_dirent_param(ldp, fid);
4473 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
4474 child->d_fsdata = (void *)ldp;
4475 ll_vfs_dq_init(pobj->oo_inode);
4476 rc = osd_ldiskfs_add_entry(info, oth->ot_handle, child,
4478 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
4479 struct ldiskfs_dir_entry_2 *de;
4480 struct buffer_head *bh;
4483 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
4486 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
4489 if (S_ISDIR(cinode->i_mode))
4490 de->file_type = LDISKFS_DIRENT_LUFID |
4491 LDISKFS_FT_REG_FILE;
4493 de->file_type = LDISKFS_DIRENT_LUFID |
4495 ldiskfs_handle_dirty_metadata(oth->ot_handle,
4506 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
4507 * into the directory.Also sets flags into osd object to
4508 * indicate dot and dotdot are created. This is required for
4509 * interoperability mode (b11826)
4511 * \param dir directory for dot and dotdot fixup.
4512 * \param obj child object for linking
4514 * \retval 0, on success
4515 * \retval -ve, on error
4517 static int osd_add_dot_dotdot(struct osd_thread_info *info,
4518 struct osd_object *dir,
4519 struct inode *parent_dir, const char *name,
4520 const struct lu_fid *dot_fid,
4521 const struct lu_fid *dot_dot_fid,
4524 struct inode *inode = dir->oo_inode;
4525 struct osd_thandle *oth;
4528 oth = container_of(th, struct osd_thandle, ot_super);
4529 LASSERT(oth->ot_handle->h_transaction != NULL);
4530 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
4532 if (strcmp(name, dot) == 0) {
4533 if (dir->oo_compat_dot_created) {
4536 LASSERT(inode->i_ino == parent_dir->i_ino);
4537 dir->oo_compat_dot_created = 1;
4540 } else if (strcmp(name, dotdot) == 0) {
4541 if (!dir->oo_compat_dot_created)
4543 /* in case of rename, dotdot is already created */
4544 if (dir->oo_compat_dotdot_created) {
4545 return __osd_ea_add_rec(info, dir, parent_dir, name,
4546 dot_dot_fid, NULL, th);
4549 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
4550 struct lu_fid tfid = *dot_dot_fid;
4553 result = osd_add_dot_dotdot_internal(info,
4554 dir->oo_inode, parent_dir, dot_fid,
4557 result = osd_add_dot_dotdot_internal(info,
4558 dir->oo_inode, parent_dir, dot_fid,
4563 dir->oo_compat_dotdot_created = 1;
4571 * It will call the appropriate osd_add* function and return the
4572 * value, return by respective functions.
4574 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
4575 struct inode *cinode, const char *name,
4576 const struct lu_fid *fid, struct thandle *th)
4578 struct osd_thread_info *info = osd_oti_get(env);
4579 struct htree_lock *hlock;
4582 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
4584 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
4586 if (hlock != NULL) {
4587 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
4590 down_write(&pobj->oo_ext_idx_sem);
4593 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
4594 lu_object_fid(&pobj->oo_dt.do_lu),
4597 if (hlock != NULL) {
4598 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
4599 pobj->oo_inode, LDISKFS_HLOCK_ADD);
4601 down_write(&pobj->oo_ext_idx_sem);
4604 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
4605 struct lu_fid *tfid = &info->oti_fid;
4609 rc = __osd_ea_add_rec(info, pobj, cinode, name,
4612 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
4617 ldiskfs_htree_unlock(hlock);
4619 up_write(&pobj->oo_ext_idx_sem);
4625 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
4626 struct osd_idmap_cache *oic)
4628 struct osd_scrub *scrub = &dev->od_scrub;
4629 struct lu_fid *fid = &oic->oic_fid;
4630 struct osd_inode_id *id = &oti->oti_id;
4635 if (!fid_is_norm(fid) && !fid_is_igif(fid))
4638 if (scrub->os_pos_current > id->oii_ino)
4642 rc = osd_oi_lookup(oti, dev, fid, id, 0);
4643 if (rc == -ENOENT) {
4644 struct inode *inode;
4647 inode = osd_iget(oti, dev, &oic->oic_lid);
4649 /* The inode has been removed (by race maybe). */
4650 if (IS_ERR(inode)) {
4651 rc = PTR_ERR(inode);
4653 RETURN(rc == -ESTALE ? -ENOENT : rc);
4657 /* The OI mapping is lost. */
4658 if (id->oii_gen != OSD_OII_NOGEN)
4661 /* The inode may has been reused by others, we do not know,
4662 * leave it to be handled by subsequent osd_fid_lookup(). */
4664 } else if (rc != 0 || osd_id_eq(id, &oic->oic_lid)) {
4669 if (thread_is_running(&scrub->os_thread)) {
4670 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
4671 /* There is race condition between osd_oi_lookup and OI scrub.
4672 * The OI scrub finished just after osd_oi_lookup() failure.
4673 * Under such case, it is unnecessary to trigger OI scrub again,
4674 * but try to call osd_oi_lookup() again. */
4675 if (unlikely(rc == -EAGAIN))
4681 if (!dev->od_noscrub && ++once == 1) {
4682 rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN |
4684 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC "
4685 "for "DFID", rc = %d [2]\n",
4686 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
4688 if (rc == 0 || rc == -EALREADY)
4695 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
4696 struct osd_device *dev,
4697 struct osd_idmap_cache *oic,
4698 struct lu_fid *fid, __u32 ino)
4700 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
4701 struct inode *inode;
4704 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4705 inode = osd_iget(oti, dev, &oic->oic_lid);
4706 if (IS_ERR(inode)) {
4707 fid_zero(&oic->oic_fid);
4708 return PTR_ERR(inode);
4711 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, lma);
4714 fid_zero(&oic->oic_fid);
4716 *fid = oic->oic_fid = lma->lma_self_fid;
4720 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
4721 struct osd_inode_id *id, const struct lu_fid *fid)
4723 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
4724 id->oii_ino, id->oii_gen, info);
4725 info->oti_cache.oic_lid = *id;
4726 info->oti_cache.oic_fid = *fid;
4727 info->oti_cache.oic_dev = osd;
4731 * Get parent FID from the linkEA.
4733 * For a directory which parent resides on remote MDT, to satisfy the
4734 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
4735 * the other hand, to make the lookup(..) on the directory can return
4736 * the real parent FID, we append the real parent FID after its ".."
4737 * name entry in the /REMOTE_PARENT_DIR.
4739 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
4740 * backup. So after the restore, we cannot get the right parent FID from
4741 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
4742 * we have stored the real parent FID in the directory object's linkEA,
4743 * we can parse the linkEA for the real parent FID.
4745 * \param[in] env pointer to the thread context
4746 * \param[in] obj pointer to the object to be handled
4747 * \param[out]fid pointer to the buffer to hold the parent FID
4749 * \retval 0 for getting the real parent FID successfully
4750 * \retval negative error number on failure
4752 static int osd_get_pfid_from_linkea(const struct lu_env *env,
4753 struct osd_object *obj,
4756 struct osd_thread_info *oti = osd_oti_get(env);
4757 struct lu_buf *buf = &oti->oti_big_buf;
4758 struct dentry *dentry = &oti->oti_obj_dentry;
4759 struct inode *inode = obj->oo_inode;
4760 struct linkea_data ldata = { NULL };
4765 if (!S_ISDIR(inode->i_mode))
4769 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4770 buf->lb_buf, buf->lb_len);
4771 if (rc == -ERANGE) {
4772 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
4775 lu_buf_realloc(buf, rc);
4776 if (buf->lb_buf == NULL)
4783 if (unlikely(rc == 0))
4789 if (unlikely(buf->lb_buf == NULL)) {
4790 lu_buf_realloc(buf, rc);
4791 if (buf->lb_buf == NULL)
4798 rc = linkea_init(&ldata);
4800 linkea_first_entry(&ldata);
4801 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
4808 * Calls ->lookup() to find dentry. From dentry get inode and
4809 * read inode's ea to get fid. This is required for interoperability
4812 * \retval 0, on success
4813 * \retval -ve, on error
4815 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
4816 struct dt_rec *rec, const struct dt_key *key)
4818 struct inode *dir = obj->oo_inode;
4819 struct dentry *dentry;
4820 struct ldiskfs_dir_entry_2 *de;
4821 struct buffer_head *bh;
4822 struct lu_fid *fid = (struct lu_fid *) rec;
4823 struct htree_lock *hlock = NULL;
4828 LASSERT(dir->i_op != NULL);
4829 LASSERT(dir->i_op->lookup != NULL);
4831 dentry = osd_child_dentry_get(env, obj,
4832 (char *)key, strlen((char *)key));
4834 if (obj->oo_hl_head != NULL) {
4835 hlock = osd_oti_get(env)->oti_hlock;
4836 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4837 dir, LDISKFS_HLOCK_LOOKUP);
4839 down_read(&obj->oo_ext_idx_sem);
4842 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4844 struct osd_thread_info *oti = osd_oti_get(env);
4845 struct osd_inode_id *id = &oti->oti_id;
4846 struct osd_idmap_cache *oic = &oti->oti_cache;
4847 struct osd_device *dev = osd_obj2dev(obj);
4849 ino = le32_to_cpu(de->inode);
4850 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
4852 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
4856 rc = osd_get_fid_from_dentry(de, rec);
4858 /* done with de, release bh */
4861 if (unlikely(ino == osd_remote_parent_ino(dev))) {
4862 const char *name = (const char *)key;
4864 /* If the parent is on remote MDT, and there
4865 * is no FID-in-dirent, then we have to get
4866 * the parent FID from the linkEA. */
4867 if (likely(strlen(name) == 2 &&
4868 name[0] == '.' && name[1] == '.'))
4869 rc = osd_get_pfid_from_linkea(env, obj,
4872 rc = osd_ea_fid_get(env, obj, ino, fid, id);
4875 osd_id_gen(id, ino, OSD_OII_NOGEN);
4878 if (rc != 0 || osd_remote_fid(env, dev, fid)) {
4879 fid_zero(&oic->oic_fid);
4884 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
4885 rc = osd_consistency_check(oti, dev, oic);
4887 fid_zero(&oic->oic_fid);
4896 ldiskfs_htree_unlock(hlock);
4898 up_read(&obj->oo_ext_idx_sem);
4903 * Put the osd object once done with it.
4905 * \param obj osd object that needs to be put
4907 static inline void osd_object_put(const struct lu_env *env,
4908 struct osd_object *obj)
4910 lu_object_put(env, &obj->oo_dt.do_lu);
4913 static int osd_index_declare_ea_insert(const struct lu_env *env,
4914 struct dt_object *dt,
4915 const struct dt_rec *rec,
4916 const struct dt_key *key,
4917 struct thandle *handle)
4919 struct osd_thandle *oh;
4920 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4921 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4922 const struct lu_fid *fid = rec1->rec_fid;
4923 int credits, rc = 0;
4924 struct osd_idmap_cache *idc;
4927 LASSERT(!dt_object_remote(dt));
4928 LASSERT(handle != NULL);
4929 LASSERT(fid != NULL);
4930 LASSERT(rec1->rec_type != 0);
4932 oh = container_of0(handle, struct osd_thandle, ot_super);
4933 LASSERT(oh->ot_handle == NULL);
4935 credits = osd_dto_credits_noquota[DTO_INDEX_INSERT];
4937 /* we can't call iget() while a transactions is running
4938 * (this can lead to a deadlock), but we need to know
4939 * inum and object type. so we find this information at
4940 * declaration and cache in per-thread info */
4941 idc = osd_idc_find_or_init(env, osd, fid);
4943 RETURN(PTR_ERR(idc));
4944 if (idc->oic_remote) {
4945 /* a reference to remote inode is represented by an
4946 * agent inode which we have to create */
4947 credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
4948 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
4951 osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits);
4953 if (osd_dt_obj(dt)->oo_inode != NULL) {
4954 struct inode *inode = osd_dt_obj(dt)->oo_inode;
4956 /* We ignore block quota on meta pool (MDTs), so needn't
4957 * calculate how many blocks will be consumed by this index
4959 rc = osd_declare_inode_qid(env, i_uid_read(inode),
4960 i_gid_read(inode), 0, oh,
4961 osd_dt_obj(dt), true, NULL, false);
4968 * Index add function for interoperability mode (b11826).
4969 * It will add the directory entry.This entry is needed to
4970 * maintain name->fid mapping.
4972 * \param key it is key i.e. file entry to be inserted
4973 * \param rec it is value of given key i.e. fid
4975 * \retval 0, on success
4976 * \retval -ve, on error
4978 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
4979 const struct dt_rec *rec,
4980 const struct dt_key *key, struct thandle *th,
4983 struct osd_object *obj = osd_dt_obj(dt);
4984 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4985 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4986 const struct lu_fid *fid = rec1->rec_fid;
4987 const char *name = (const char *)key;
4988 struct osd_thread_info *oti = osd_oti_get(env);
4989 struct inode *child_inode = NULL;
4990 struct osd_idmap_cache *idc;
4994 if (!dt_object_exists(dt))
4997 LASSERT(osd_invariant(obj));
4998 LASSERT(!dt_object_remote(dt));
4999 LASSERT(th != NULL);
5001 osd_trans_exec_op(env, th, OSD_OT_INSERT);
5003 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
5005 idc = osd_idc_find(env, osd, fid);
5006 if (unlikely(idc == NULL)) {
5007 /* this dt_insert() wasn't declared properly, so
5008 * FID is missing in OI cache. we better do not
5009 * lookup FID in FLDB/OI and don't risk to deadlock,
5010 * but in some special cases (lfsck testing, etc)
5011 * it's much simpler than fixing a caller */
5012 CERROR("%s: "DFID" wasn't declared for insert\n",
5013 osd_name(osd), PFID(fid));
5015 idc = osd_idc_find_or_init(env, osd, fid);
5017 RETURN(PTR_ERR(idc));
5020 if (idc->oic_remote) {
5021 /* Insert remote entry */
5022 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
5023 struct osd_mdobj_map *omm = osd->od_mdt_map;
5024 struct osd_thandle *oh;
5026 /* If parent on remote MDT, we need put this object
5028 oh = container_of(th, typeof(*oh), ot_super);
5029 rc = osd_add_to_remote_parent(env, osd, obj, oh);
5031 CERROR("%s: add "DFID" error: rc = %d\n",
5033 PFID(lu_object_fid(&dt->do_lu)), rc);
5037 child_inode = igrab(omm->omm_remote_parent->d_inode);
5039 child_inode = osd_create_local_agent_inode(env, osd,
5040 obj, fid, rec1->rec_type & S_IFMT, th);
5041 if (IS_ERR(child_inode))
5042 RETURN(PTR_ERR(child_inode));
5045 /* Insert local entry */
5046 if (unlikely(idc->oic_lid.oii_ino == 0)) {
5047 /* for a reason OI cache wasn't filled properly */
5048 CERROR("%s: OIC for "DFID" isn't filled\n",
5049 osd_name(osd), PFID(fid));
5052 child_inode = oti->oti_inode;
5053 if (unlikely(child_inode == NULL)) {
5054 struct ldiskfs_inode_info *lii;
5058 child_inode = oti->oti_inode = &lii->vfs_inode;
5060 child_inode->i_sb = osd_sb(osd);
5061 child_inode->i_ino = idc->oic_lid.oii_ino;
5062 child_inode->i_mode = rec1->rec_type & S_IFMT;
5065 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
5067 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
5068 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
5070 if (child_inode && child_inode != oti->oti_inode)
5072 LASSERT(osd_invariant(obj));
5073 osd_trans_exec_check(env, th, OSD_OT_INSERT);
5078 * Initialize osd Iterator for given osd index object.
5080 * \param dt osd index object
5083 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
5084 struct dt_object *dt,
5087 struct osd_it_iam *it;
5088 struct osd_object *obj = osd_dt_obj(dt);
5089 struct lu_object *lo = &dt->do_lu;
5090 struct iam_path_descr *ipd;
5091 struct iam_container *bag = &obj->oo_dir->od_container;
5093 if (!dt_object_exists(dt))
5094 return ERR_PTR(-ENOENT);
5098 return ERR_PTR(-ENOMEM);
5100 ipd = osd_it_ipd_get(env, bag);
5101 if (likely(ipd != NULL)) {
5105 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
5106 return (struct dt_it *)it;
5109 return ERR_PTR(-ENOMEM);
5114 * free given Iterator.
5117 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
5119 struct osd_it_iam *it = (struct osd_it_iam *)di;
5120 struct osd_object *obj = it->oi_obj;
5122 iam_it_fini(&it->oi_it);
5123 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
5124 lu_object_put(env, &obj->oo_dt.do_lu);
5129 * Move Iterator to record specified by \a key
5131 * \param di osd iterator
5132 * \param key key for index
5134 * \retval +ve di points to record with least key not larger than key
5135 * \retval 0 di points to exact matched key
5136 * \retval -ve failure
5139 static int osd_it_iam_get(const struct lu_env *env,
5140 struct dt_it *di, const struct dt_key *key)
5142 struct osd_thread_info *oti = osd_oti_get(env);
5143 struct osd_it_iam *it = (struct osd_it_iam *)di;
5145 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
5146 /* swab quota uid/gid */
5147 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5148 key = (struct dt_key *)&oti->oti_quota_id;
5151 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
5157 * \param di osd iterator
5159 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
5161 struct osd_it_iam *it = (struct osd_it_iam *)di;
5163 iam_it_put(&it->oi_it);
5167 * Move iterator by one record
5169 * \param di osd iterator
5171 * \retval +1 end of container reached
5173 * \retval -ve failure
5176 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
5178 struct osd_it_iam *it = (struct osd_it_iam *)di;
5180 return iam_it_next(&it->oi_it);
5184 * Return pointer to the key under iterator.
5187 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
5188 const struct dt_it *di)
5190 struct osd_thread_info *oti = osd_oti_get(env);
5191 struct osd_it_iam *it = (struct osd_it_iam *)di;
5192 struct osd_object *obj = it->oi_obj;
5195 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
5197 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
5198 /* swab quota uid/gid */
5199 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
5200 key = (struct dt_key *)&oti->oti_quota_id;
5207 * Return size of key under iterator (in bytes)
5210 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
5212 struct osd_it_iam *it = (struct osd_it_iam *)di;
5214 return iam_it_key_size(&it->oi_it);
5218 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
5220 /* check if file type is required */
5221 if (ent->lde_attrs & LUDA_TYPE) {
5222 struct luda_type *lt;
5223 int align = sizeof(*lt) - 1;
5225 len = (len + align) & ~align;
5226 lt = (struct luda_type *)(ent->lde_name + len);
5227 lt->lt_type = cpu_to_le16(DTTOIF(type));
5230 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
5234 * build lu direct from backend fs dirent.
5238 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
5239 char *name, __u16 namelen, __u16 type, __u32 attr)
5241 ent->lde_attrs = attr | LUDA_FID;
5242 fid_cpu_to_le(&ent->lde_fid, fid);
5244 ent->lde_hash = cpu_to_le64(offset);
5245 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
5247 strncpy(ent->lde_name, name, namelen);
5248 ent->lde_name[namelen] = '\0';
5249 ent->lde_namelen = cpu_to_le16(namelen);
5251 /* append lustre attributes */
5252 osd_it_append_attrs(ent, namelen, type);
5256 * Return pointer to the record under iterator.
5258 static int osd_it_iam_rec(const struct lu_env *env,
5259 const struct dt_it *di,
5260 struct dt_rec *dtrec, __u32 attr)
5262 struct osd_it_iam *it = (struct osd_it_iam *)di;
5263 struct osd_thread_info *info = osd_oti_get(env);
5266 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
5267 const struct osd_fid_pack *rec;
5268 struct lu_fid *fid = &info->oti_fid;
5269 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5275 name = (char *)iam_it_key_get(&it->oi_it);
5277 RETURN(PTR_ERR(name));
5279 namelen = iam_it_key_size(&it->oi_it);
5281 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
5283 RETURN(PTR_ERR(rec));
5285 rc = osd_fid_unpack(fid, rec);
5289 hash = iam_it_store(&it->oi_it);
5291 /* IAM does not store object type in IAM index (dir) */
5292 osd_it_pack_dirent(lde, fid, hash, name, namelen,
5294 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
5295 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
5296 (struct iam_rec *)dtrec);
5297 osd_quota_unpack(it->oi_obj, dtrec);
5299 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
5300 (struct iam_rec *)dtrec);
5307 * Returns cookie for current Iterator position.
5309 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
5311 struct osd_it_iam *it = (struct osd_it_iam *)di;
5313 return iam_it_store(&it->oi_it);
5317 * Restore iterator from cookie.
5319 * \param di osd iterator
5320 * \param hash Iterator location cookie
5322 * \retval +ve di points to record with least key not larger than key.
5323 * \retval 0 di points to exact matched key
5324 * \retval -ve failure
5327 static int osd_it_iam_load(const struct lu_env *env,
5328 const struct dt_it *di, __u64 hash)
5330 struct osd_it_iam *it = (struct osd_it_iam *)di;
5332 return iam_it_load(&it->oi_it, hash);
5335 static const struct dt_index_operations osd_index_iam_ops = {
5336 .dio_lookup = osd_index_iam_lookup,
5337 .dio_declare_insert = osd_index_declare_iam_insert,
5338 .dio_insert = osd_index_iam_insert,
5339 .dio_declare_delete = osd_index_declare_iam_delete,
5340 .dio_delete = osd_index_iam_delete,
5342 .init = osd_it_iam_init,
5343 .fini = osd_it_iam_fini,
5344 .get = osd_it_iam_get,
5345 .put = osd_it_iam_put,
5346 .next = osd_it_iam_next,
5347 .key = osd_it_iam_key,
5348 .key_size = osd_it_iam_key_size,
5349 .rec = osd_it_iam_rec,
5350 .store = osd_it_iam_store,
5351 .load = osd_it_iam_load
5357 * Creates or initializes iterator context.
5359 * \retval struct osd_it_ea, iterator structure on success
5362 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
5363 struct dt_object *dt,
5366 struct osd_object *obj = osd_dt_obj(dt);
5367 struct osd_thread_info *info = osd_oti_get(env);
5368 struct osd_it_ea *oie;
5370 struct lu_object *lo = &dt->do_lu;
5371 struct dentry *obj_dentry;
5374 if (!dt_object_exists(dt) || obj->oo_destroyed)
5375 RETURN(ERR_PTR(-ENOENT));
5377 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
5379 RETURN(ERR_PTR(-ENOMEM));
5380 obj_dentry = &oie->oie_dentry;
5382 obj_dentry->d_inode = obj->oo_inode;
5383 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
5384 obj_dentry->d_name.hash = 0;
5386 oie->oie_rd_dirent = 0;
5387 oie->oie_it_dirent = 0;
5388 oie->oie_dirent = NULL;
5389 if (unlikely(!info->oti_it_ea_buf_used)) {
5390 oie->oie_buf = info->oti_it_ea_buf;
5391 info->oti_it_ea_buf_used = 1;
5393 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
5394 if (oie->oie_buf == NULL)
5395 RETURN(ERR_PTR(-ENOMEM));
5399 file = &oie->oie_file;
5401 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
5402 if (attr & LUDA_64BITHASH)
5403 file->f_mode = FMODE_64BITHASH;
5405 file->f_mode = FMODE_32BITHASH;
5406 file->f_path.dentry = obj_dentry;
5407 file->f_mapping = obj->oo_inode->i_mapping;
5408 file->f_op = obj->oo_inode->i_fop;
5409 set_file_inode(file, obj->oo_inode);
5412 RETURN((struct dt_it *) oie);
5416 * Destroy or finishes iterator context.
5418 * \param di iterator structure to be destroyed
5420 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
5422 struct osd_thread_info *info = osd_oti_get(env);
5423 struct osd_it_ea *oie = (struct osd_it_ea *)di;
5424 struct osd_object *obj = oie->oie_obj;
5425 struct inode *inode = obj->oo_inode;
5428 oie->oie_file.f_op->release(inode, &oie->oie_file);
5429 lu_object_put(env, &obj->oo_dt.do_lu);
5430 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
5431 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
5433 info->oti_it_ea_buf_used = 0;
5434 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
5439 * It position the iterator at given key, so that next lookup continues from
5440 * that key Or it is similar to dio_it->load() but based on a key,
5441 * rather than file position.
5443 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
5446 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
5448 static int osd_it_ea_get(const struct lu_env *env,
5449 struct dt_it *di, const struct dt_key *key)
5451 struct osd_it_ea *it = (struct osd_it_ea *)di;
5454 LASSERT(((const char *)key)[0] == '\0');
5455 it->oie_file.f_pos = 0;
5456 it->oie_rd_dirent = 0;
5457 it->oie_it_dirent = 0;
5458 it->oie_dirent = NULL;
5466 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
5470 struct osd_filldir_cbs {
5471 #ifdef HAVE_DIR_CONTEXT
5472 struct dir_context ctx;
5474 struct osd_it_ea *it;
5477 * It is called internally by ->readdir(). It fills the
5478 * iterator's in-memory data structure with required
5479 * information i.e. name, namelen, rec_size etc.
5481 * \param buf in which information to be filled in.
5482 * \param name name of the file in given dir
5484 * \retval 0 on success
5485 * \retval 1 on buffer full
5487 #ifdef HAVE_FILLDIR_USE_CTX
5488 static int osd_ldiskfs_filldir(struct dir_context *buf,
5489 const char *name, int namelen,
5491 static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen,
5493 loff_t offset, __u64 ino,
5496 struct osd_it_ea *it =
5497 ((struct osd_filldir_cbs *)buf)->it;
5498 struct osd_object *obj = it->oie_obj;
5499 struct osd_it_ea_dirent *ent = it->oie_dirent;
5500 struct lu_fid *fid = &ent->oied_fid;
5501 struct osd_fid_pack *rec;
5504 /* this should never happen */
5505 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
5506 CERROR("ldiskfs return invalid namelen %d\n", namelen);
5510 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
5514 /* "." is just the object itself. */
5515 if (namelen == 1 && name[0] == '.') {
5516 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
5517 } else if (d_type & LDISKFS_DIRENT_LUFID) {
5518 rec = (struct osd_fid_pack*) (name + namelen + 1);
5519 if (osd_fid_unpack(fid, rec) != 0)
5524 d_type &= ~LDISKFS_DIRENT_LUFID;
5526 /* NOT export local root. */
5527 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
5528 ino = obj->oo_inode->i_ino;
5529 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
5532 ent->oied_ino = ino;
5533 ent->oied_off = offset;
5534 ent->oied_namelen = namelen;
5535 ent->oied_type = d_type;
5537 memcpy(ent->oied_name, name, namelen);
5539 it->oie_rd_dirent++;
5540 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
5545 * Calls ->readdir() to load a directory entry at a time
5546 * and stored it in iterator's in-memory data structure.
5548 * \param di iterator's in memory structure
5550 * \retval 0 on success
5551 * \retval -ve on error
5552 * \retval +1 reach the end of entry
5554 static int osd_ldiskfs_it_fill(const struct lu_env *env,
5555 const struct dt_it *di)
5557 struct osd_it_ea *it = (struct osd_it_ea *)di;
5558 struct osd_object *obj = it->oie_obj;
5559 struct inode *inode = obj->oo_inode;
5560 struct htree_lock *hlock = NULL;
5561 struct file *filp = &it->oie_file;
5563 struct osd_filldir_cbs buf = {
5564 #ifdef HAVE_DIR_CONTEXT
5565 .ctx.actor = osd_ldiskfs_filldir,
5571 it->oie_dirent = it->oie_buf;
5572 it->oie_rd_dirent = 0;
5574 if (obj->oo_hl_head != NULL) {
5575 hlock = osd_oti_get(env)->oti_hlock;
5576 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
5577 inode, LDISKFS_HLOCK_READDIR);
5579 down_read(&obj->oo_ext_idx_sem);
5582 #ifdef HAVE_DIR_CONTEXT
5583 buf.ctx.pos = filp->f_pos;
5584 rc = inode->i_fop->iterate(filp, &buf.ctx);
5585 filp->f_pos = buf.ctx.pos;
5587 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
5591 ldiskfs_htree_unlock(hlock);
5593 up_read(&obj->oo_ext_idx_sem);
5595 if (it->oie_rd_dirent == 0) {
5596 /*If it does not get any dirent, it means it has been reached
5597 *to the end of the dir */
5598 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
5602 it->oie_dirent = it->oie_buf;
5603 it->oie_it_dirent = 1;
5610 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
5611 * to load a directory entry at a time and stored it in
5612 * iterator's in-memory data structure.
5614 * \param di iterator's in memory structure
5616 * \retval +ve iterator reached to end
5617 * \retval 0 iterator not reached to end
5618 * \retval -ve on error
5620 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
5622 struct osd_it_ea *it = (struct osd_it_ea *)di;
5627 if (it->oie_it_dirent < it->oie_rd_dirent) {
5629 (void *) it->oie_dirent +
5630 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
5631 it->oie_dirent->oied_namelen);
5632 it->oie_it_dirent++;
5635 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
5638 rc = osd_ldiskfs_it_fill(env, di);
5645 * Returns the key at current position from iterator's in memory structure.
5647 * \param di iterator's in memory structure
5649 * \retval key i.e. struct dt_key on success
5651 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
5652 const struct dt_it *di)
5654 struct osd_it_ea *it = (struct osd_it_ea *)di;
5656 return (struct dt_key *)it->oie_dirent->oied_name;
5660 * Returns the key's size at current position from iterator's in memory structure.
5662 * \param di iterator's in memory structure
5664 * \retval key_size i.e. struct dt_key on success
5666 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
5668 struct osd_it_ea *it = (struct osd_it_ea *)di;
5670 return it->oie_dirent->oied_namelen;
5674 osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot)
5676 LASSERTF(dot_dotdot == 1 || dot_dotdot == 2,
5677 "dot_dotdot = %d\n", dot_dotdot);
5679 if (LDISKFS_DIR_REC_LEN(de) >=
5680 __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack)))
5687 osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen,
5688 unsigned blocksize, int dot_dotdot)
5691 return osd_dot_dotdot_has_space(de, dot_dotdot);
5693 if (ldiskfs_rec_len_from_disk(de->rec_len, blocksize) >=
5694 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
5701 osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
5702 struct dentry *dentry, const struct lu_fid *fid,
5703 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de,
5704 struct htree_lock *hlock, int dot_dotdot)
5706 struct inode *dir = dentry->d_parent->d_inode;
5707 struct inode *inode = dentry->d_inode;
5708 struct osd_fid_pack *rec;
5709 struct ldiskfs_dentry_param *ldp;
5710 int namelen = dentry->d_name.len;
5712 struct osd_thread_info *info = osd_oti_get(env);
5715 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
5716 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5719 /* There is enough space to hold the FID-in-dirent. */
5720 if (osd_dirent_has_space(de, namelen, dir->i_sb->s_blocksize,
5722 rc = ldiskfs_journal_get_write_access(jh, bh);
5726 de->name[namelen] = 0;
5727 rec = (struct osd_fid_pack *)(de->name + namelen + 1);
5728 rec->fp_len = sizeof(struct lu_fid) + 1;
5729 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
5730 de->file_type |= LDISKFS_DIRENT_LUFID;
5731 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5736 LASSERTF(dot_dotdot == 0, "dot_dotdot = %d\n", dot_dotdot);
5738 rc = ldiskfs_delete_entry(jh, dir, de, bh);
5742 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
5743 osd_get_ldiskfs_dirent_param(ldp, fid);
5744 dentry->d_fsdata = (void *)ldp;
5745 ll_vfs_dq_init(dir);
5746 rc = osd_ldiskfs_add_entry(info, jh, dentry, inode, hlock);
5747 /* It is too bad, we cannot reinsert the name entry back.
5748 * That means we lose it! */
5750 CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
5751 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
5752 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
5753 dir->i_ino, dir->i_generation, namelen,
5754 dentry->d_name.name, PFID(fid), rc);
5760 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
5761 struct osd_it_ea *it, struct lu_fid *fid,
5762 struct osd_inode_id *id, __u32 *attr)
5764 struct osd_thread_info *info = osd_oti_get(env);
5765 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
5766 struct osd_device *dev = osd_obj2dev(obj);
5767 struct super_block *sb = osd_sb(dev);
5768 const char *devname =
5769 LDISKFS_SB(sb)->s_es->s_volume_name;
5770 struct osd_it_ea_dirent *ent = it->oie_dirent;
5771 struct inode *dir = obj->oo_inode;
5772 struct htree_lock *hlock = NULL;
5773 struct buffer_head *bh = NULL;
5774 handle_t *jh = NULL;
5775 struct ldiskfs_dir_entry_2 *de;
5776 struct dentry *dentry;
5777 struct inode *inode;
5784 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
5785 inode = osd_iget(info, dev, id);
5786 if (IS_ERR(inode)) {
5787 rc = PTR_ERR(inode);
5788 if (rc == -ENOENT || rc == -ESTALE) {
5789 *attr |= LUDA_UNKNOWN;
5792 CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
5793 "check_repair, dir = %lu/%u, name = %.*s: "
5795 devname, dir->i_ino, dir->i_generation,
5796 ent->oied_namelen, ent->oied_name, rc);
5802 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
5804 rc = osd_get_lma(info, inode, dentry, lma);
5810 if (ent->oied_name[0] == '.') {
5811 if (ent->oied_namelen == 1)
5813 else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
5817 /* We need to ensure that the name entry is still valid.
5818 * Because it may be removed or renamed by other already.
5820 * The unlink or rename operation will start journal before PDO lock,
5821 * so to avoid deadlock, here we need to start journal handle before
5822 * related PDO lock also. But because we do not know whether there
5823 * will be something to be repaired before PDO lock, we just start
5824 * journal without conditions.
5826 * We may need to remove the name entry firstly, then insert back.
5827 * One credit is for user quota file update.
5828 * One credit is for group quota file update.
5829 * Two credits are for dirty inode. */
5830 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
5831 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
5833 if (dev->od_dirent_journal != 0) {
5836 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
5839 CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
5840 "check_repair, dir = %lu/%u, credits = %d, "
5841 "name = %.*s: rc = %d\n",
5842 devname, dir->i_ino, dir->i_generation, credits,
5843 ent->oied_namelen, ent->oied_name, rc);
5845 GOTO(out_inode, rc);
5848 if (obj->oo_hl_head != NULL) {
5849 hlock = osd_oti_get(env)->oti_hlock;
5850 /* "0" means exclusive lock for the whole directory.
5851 * We need to prevent others access such name entry
5852 * during the delete + insert. Neither HLOCK_ADD nor
5853 * HLOCK_DEL cannot guarantee the atomicity. */
5854 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
5856 down_write(&obj->oo_ext_idx_sem);
5859 if (obj->oo_hl_head != NULL) {
5860 hlock = osd_oti_get(env)->oti_hlock;
5861 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
5862 LDISKFS_HLOCK_LOOKUP);
5864 down_read(&obj->oo_ext_idx_sem);
5868 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5869 /* For dot/dotdot entry, if there is not enough space to hold the
5870 * FID-in-dirent, just keep them there. It only happens when the
5871 * device upgraded from 1.8 or restored from MDT file-level backup.
5872 * For the whole directory, only dot/dotdot entry have no FID-in-dirent
5873 * and needs to get FID from LMA when readdir, it will not affect the
5874 * performance much. */
5875 if ((bh == NULL) || (le32_to_cpu(de->inode) != inode->i_ino) ||
5876 (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
5877 *attr |= LUDA_IGNORE;
5883 if (unlikely(lma->lma_compat & LMAC_NOT_IN_OI)) {
5884 struct lu_fid *tfid = &lma->lma_self_fid;
5886 *attr |= LUDA_IGNORE;
5887 /* It must be REMOTE_PARENT_DIR and as the
5888 * dotdot entry of remote directory */
5889 if (unlikely(dot_dotdot != 2 ||
5890 fid_seq(tfid) != FID_SEQ_LOCAL_FILE ||
5891 fid_oid(tfid) != REMOTE_PARENT_DIR_OID)) {
5892 CDEBUG(D_LFSCK, "%.16s: expect remote agent "
5893 "parent directory, but got %.*s under "
5894 "dir = %lu/%u with the FID "DFID"\n",
5895 devname, ent->oied_namelen,
5896 ent->oied_name, dir->i_ino,
5897 dir->i_generation, PFID(tfid));
5899 GOTO(out, rc = -EIO);
5905 if (fid_is_sane(fid)) {
5906 /* FID-in-dirent is valid. */
5907 if (lu_fid_eq(fid, &lma->lma_self_fid))
5910 /* Do not repair under dryrun mode. */
5911 if (*attr & LUDA_VERIFY_DRYRUN) {
5912 *attr |= LUDA_REPAIR;
5919 dev->od_dirent_journal = 1;
5920 if (hlock != NULL) {
5921 ldiskfs_htree_unlock(hlock);
5924 up_read(&obj->oo_ext_idx_sem);
5930 *fid = lma->lma_self_fid;
5932 /* Update the FID-in-dirent. */
5933 rc = osd_dirent_reinsert(env, jh, dentry, fid, bh, de,
5936 *attr |= LUDA_REPAIR;
5938 CDEBUG(D_LFSCK, "%.16s: fail to update FID "
5939 "in the dirent, dir = %lu/%u, "
5940 "name = %.*s, "DFID": rc = %d\n",
5941 devname, dir->i_ino, dir->i_generation,
5942 ent->oied_namelen, ent->oied_name,
5945 /* Do not repair under dryrun mode. */
5946 if (*attr & LUDA_VERIFY_DRYRUN) {
5947 *fid = lma->lma_self_fid;
5948 *attr |= LUDA_REPAIR;
5955 dev->od_dirent_journal = 1;
5956 if (hlock != NULL) {
5957 ldiskfs_htree_unlock(hlock);
5960 up_read(&obj->oo_ext_idx_sem);
5966 *fid = lma->lma_self_fid;
5968 /* Append the FID-in-dirent. */
5969 rc = osd_dirent_reinsert(env, jh, dentry, fid, bh, de,
5972 *attr |= LUDA_REPAIR;
5974 CDEBUG(D_LFSCK, "%.16s: fail to append FID "
5975 "after the dirent, dir = %lu/%u, "
5976 "name = %.*s, "DFID": rc = %d\n",
5977 devname, dir->i_ino, dir->i_generation,
5978 ent->oied_namelen, ent->oied_name,
5982 /* Do not repair under dryrun mode. */
5983 if (*attr & LUDA_VERIFY_DRYRUN) {
5984 if (fid_is_sane(fid)) {
5985 *attr |= LUDA_REPAIR;
5987 lu_igif_build(fid, inode->i_ino,
5988 inode->i_generation);
5989 *attr |= LUDA_UPGRADE;
5997 dev->od_dirent_journal = 1;
5998 if (hlock != NULL) {
5999 ldiskfs_htree_unlock(hlock);
6002 up_read(&obj->oo_ext_idx_sem);
6009 if (unlikely(fid_is_sane(fid))) {
6010 /* FID-in-dirent exists, but FID-in-LMA is lost.
6011 * Trust the FID-in-dirent, and add FID-in-LMA. */
6012 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
6014 *attr |= LUDA_REPAIR;
6016 CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
6017 "update dirent, dir = %lu/%u, "
6018 "name = %.*s, "DFID": rc = %d\n",
6019 devname, dir->i_ino, dir->i_generation,
6020 ent->oied_namelen, ent->oied_name,
6023 lu_igif_build(fid, inode->i_ino, inode->i_generation);
6024 /* It is probably IGIF object. Only aappend the
6025 * FID-in-dirent. OI scrub will process FID-in-LMA. */
6026 rc = osd_dirent_reinsert(env, jh, dentry, fid, bh, de,
6029 *attr |= LUDA_UPGRADE;
6031 CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
6032 "after the dirent, dir = %lu/%u, "
6033 "name = %.*s, "DFID": rc = %d\n",
6034 devname, dir->i_ino, dir->i_generation,
6035 ent->oied_namelen, ent->oied_name,
6044 if (hlock != NULL) {
6045 ldiskfs_htree_unlock(hlock);
6047 if (dev->od_dirent_journal != 0)
6048 up_write(&obj->oo_ext_idx_sem);
6050 up_read(&obj->oo_ext_idx_sem);
6054 ldiskfs_journal_stop(jh);
6058 if (rc >= 0 && !dirty)
6059 dev->od_dirent_journal = 0;
6065 * Returns the value at current position from iterator's in memory structure.
6067 * \param di struct osd_it_ea, iterator's in memory structure
6068 * \param attr attr requested for dirent.
6069 * \param lde lustre dirent
6071 * \retval 0 no error and \param lde has correct lustre dirent.
6072 * \retval -ve on error
6074 static inline int osd_it_ea_rec(const struct lu_env *env,
6075 const struct dt_it *di,
6076 struct dt_rec *dtrec, __u32 attr)
6078 struct osd_it_ea *it = (struct osd_it_ea *)di;
6079 struct osd_object *obj = it->oie_obj;
6080 struct osd_device *dev = osd_obj2dev(obj);
6081 struct osd_thread_info *oti = osd_oti_get(env);
6082 struct osd_inode_id *id = &oti->oti_id;
6083 struct lu_fid *fid = &it->oie_dirent->oied_fid;
6084 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
6085 __u32 ino = it->oie_dirent->oied_ino;
6089 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
6091 if (attr & LUDA_VERIFY) {
6092 if (unlikely(ino == osd_remote_parent_ino(dev))) {
6093 attr |= LUDA_IGNORE;
6094 /* If the parent is on remote MDT, and there
6095 * is no FID-in-dirent, then we have to get
6096 * the parent FID from the linkEA. */
6097 if (!fid_is_sane(fid) &&
6098 it->oie_dirent->oied_namelen == 2 &&
6099 it->oie_dirent->oied_name[0] == '.' &&
6100 it->oie_dirent->oied_name[1] == '.')
6101 osd_get_pfid_from_linkea(env, obj, fid);
6103 rc = osd_dirent_check_repair(env, obj, it, fid, id,
6107 if (!fid_is_sane(fid)) {
6108 attr &= ~LUDA_IGNORE;
6109 attr |= LUDA_UNKNOWN;
6112 attr &= ~LU_DIRENT_ATTRS_MASK;
6113 if (!fid_is_sane(fid)) {
6114 bool is_dotdot = false;
6115 if (it->oie_dirent->oied_namelen == 2 &&
6116 it->oie_dirent->oied_name[0] == '.' &&
6117 it->oie_dirent->oied_name[1] == '.')
6119 /* If the parent is on remote MDT, and there
6120 * is no FID-in-dirent, then we have to get
6121 * the parent FID from the linkEA. */
6122 if (ino == osd_remote_parent_ino(dev) && is_dotdot) {
6123 rc = osd_get_pfid_from_linkea(env, obj, fid);
6125 if (is_dotdot == false &&
6126 OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
6129 rc = osd_ea_fid_get(env, obj, ino, fid, id);
6132 osd_id_gen(id, ino, OSD_OII_NOGEN);
6136 /* Pack the entry anyway, at least the offset is right. */
6137 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
6138 it->oie_dirent->oied_name,
6139 it->oie_dirent->oied_namelen,
6140 it->oie_dirent->oied_type, attr);
6145 if (osd_remote_fid(env, dev, fid))
6148 if (likely(!(attr & (LUDA_IGNORE | LUDA_UNKNOWN)) && rc == 0))
6149 osd_add_oi_cache(oti, dev, id, fid);
6151 RETURN(rc > 0 ? 0 : rc);
6155 * Returns the record size size at current position.
6157 * This function will return record(lu_dirent) size in bytes.
6159 * \param[in] env execution environment
6160 * \param[in] di iterator's in memory structure
6161 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
6162 * calculate the lu_dirent size.
6164 * \retval record size(in bytes & in memory) of the current lu_dirent
6167 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
6170 struct osd_it_ea *it = (struct osd_it_ea *)di;
6172 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
6176 * Returns a cookie for current position of the iterator head, so that
6177 * user can use this cookie to load/start the iterator next time.
6179 * \param di iterator's in memory structure
6181 * \retval cookie for current position, on success
6183 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
6185 struct osd_it_ea *it = (struct osd_it_ea *)di;
6187 return it->oie_dirent->oied_off;
6191 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
6192 * to load a directory entry at a time and stored it i inn,
6193 * in iterator's in-memory data structure.
6195 * \param di struct osd_it_ea, iterator's in memory structure
6197 * \retval +ve on success
6198 * \retval -ve on error
6200 static int osd_it_ea_load(const struct lu_env *env,
6201 const struct dt_it *di, __u64 hash)
6203 struct osd_it_ea *it = (struct osd_it_ea *)di;
6207 it->oie_file.f_pos = hash;
6209 rc = osd_ldiskfs_it_fill(env, di);
6220 * Index lookup function for interoperability mode (b11826).
6222 * \param key, key i.e. file name to be searched
6224 * \retval +ve, on success
6225 * \retval -ve, on error
6227 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
6228 struct dt_rec *rec, const struct dt_key *key)
6230 struct osd_object *obj = osd_dt_obj(dt);
6235 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
6236 LINVRNT(osd_invariant(obj));
6238 rc = osd_ea_lookup_rec(env, obj, rec, key);
6245 * Index and Iterator operations for interoperability
6246 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
6248 static const struct dt_index_operations osd_index_ea_ops = {
6249 .dio_lookup = osd_index_ea_lookup,
6250 .dio_declare_insert = osd_index_declare_ea_insert,
6251 .dio_insert = osd_index_ea_insert,
6252 .dio_declare_delete = osd_index_declare_ea_delete,
6253 .dio_delete = osd_index_ea_delete,
6255 .init = osd_it_ea_init,
6256 .fini = osd_it_ea_fini,
6257 .get = osd_it_ea_get,
6258 .put = osd_it_ea_put,
6259 .next = osd_it_ea_next,
6260 .key = osd_it_ea_key,
6261 .key_size = osd_it_ea_key_size,
6262 .rec = osd_it_ea_rec,
6263 .rec_size = osd_it_ea_rec_size,
6264 .store = osd_it_ea_store,
6265 .load = osd_it_ea_load
6269 static void *osd_key_init(const struct lu_context *ctx,
6270 struct lu_context_key *key)
6272 struct osd_thread_info *info;
6274 OBD_ALLOC_PTR(info);
6276 return ERR_PTR(-ENOMEM);
6278 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6279 if (info->oti_it_ea_buf == NULL)
6282 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
6284 info->oti_hlock = ldiskfs_htree_lock_alloc();
6285 if (info->oti_hlock == NULL)
6291 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6294 return ERR_PTR(-ENOMEM);
6297 static void osd_key_fini(const struct lu_context *ctx,
6298 struct lu_context_key *key, void* data)
6300 struct osd_thread_info *info = data;
6301 struct ldiskfs_inode_info *lli = LDISKFS_I(info->oti_inode);
6302 struct osd_idmap_cache *idc = info->oti_ins_cache;
6304 if (info->oti_inode != NULL)
6306 if (info->oti_hlock != NULL)
6307 ldiskfs_htree_lock_free(info->oti_hlock);
6308 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6309 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
6310 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
6311 lu_buf_free(&info->oti_big_buf);
6313 LASSERT(info->oti_ins_cache_size > 0);
6314 OBD_FREE(idc, sizeof(*idc) * info->oti_ins_cache_size);
6315 info->oti_ins_cache = NULL;
6316 info->oti_ins_cache_size = 0;
6321 static void osd_key_exit(const struct lu_context *ctx,
6322 struct lu_context_key *key, void *data)
6324 struct osd_thread_info *info = data;
6326 LASSERT(info->oti_r_locks == 0);
6327 LASSERT(info->oti_w_locks == 0);
6328 LASSERT(info->oti_txns == 0);
6331 /* type constructor/destructor: osd_type_init, osd_type_fini */
6332 LU_TYPE_INIT_FINI(osd, &osd_key);
6334 struct lu_context_key osd_key = {
6335 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
6336 .lct_init = osd_key_init,
6337 .lct_fini = osd_key_fini,
6338 .lct_exit = osd_key_exit
6342 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
6343 const char *name, struct lu_device *next)
6345 struct osd_device *osd = osd_dev(d);
6347 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
6348 >= sizeof(osd->od_svname))
6350 return osd_procfs_init(osd, name);
6353 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
6355 struct seq_server_site *ss = osd_seq_site(osd);
6359 if (osd->od_is_ost || osd->od_cl_seq != NULL)
6362 if (unlikely(ss == NULL))
6365 OBD_ALLOC_PTR(osd->od_cl_seq);
6366 if (osd->od_cl_seq == NULL)
6369 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
6370 osd->od_svname, ss->ss_server_seq);
6372 OBD_FREE_PTR(osd->od_cl_seq);
6373 osd->od_cl_seq = NULL;
6377 if (ss->ss_node_id == 0) {
6378 /* If the OSD on the sequence controller(MDT0), then allocate
6379 * sequence here, otherwise allocate sequence after connected
6380 * to MDT0 (see mdt_register_lwp_callback()). */
6381 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
6382 &osd->od_cl_seq->lcs_space, env);
6388 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
6390 if (osd->od_cl_seq == NULL)
6393 seq_client_fini(osd->od_cl_seq);
6394 OBD_FREE_PTR(osd->od_cl_seq);
6395 osd->od_cl_seq = NULL;
6398 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
6402 /* shutdown quota slave instance associated with the device */
6403 if (o->od_quota_slave != NULL) {
6404 qsd_fini(env, o->od_quota_slave);
6405 o->od_quota_slave = NULL;
6408 osd_fid_fini(env, o);
6413 static void osd_umount(const struct lu_env *env, struct osd_device *o)
6417 if (o->od_mnt != NULL) {
6418 shrink_dcache_sb(osd_sb(o));
6419 osd_sync(env, &o->od_dt_dev);
6428 static int osd_mount(const struct lu_env *env,
6429 struct osd_device *o, struct lustre_cfg *cfg)
6431 const char *name = lustre_cfg_string(cfg, 0);
6432 const char *dev = lustre_cfg_string(cfg, 1);
6434 unsigned long page, s_flags, lmd_flags = 0;
6435 struct page *__page;
6436 struct file_system_type *type;
6437 char *options = NULL;
6439 struct osd_thread_info *info = osd_oti_get(env);
6440 struct lu_fid *fid = &info->oti_fid;
6441 struct inode *inode;
6442 int rc = 0, force_over_256tb = 0;
6445 if (o->od_mnt != NULL)
6448 if (strlen(dev) >= sizeof(o->od_mntdev))
6450 strcpy(o->od_mntdev, dev);
6452 str = lustre_cfg_string(cfg, 2);
6453 s_flags = simple_strtoul(str, NULL, 0);
6454 str = strstr(str, ":");
6456 lmd_flags = simple_strtoul(str + 1, NULL, 0);
6457 opts = lustre_cfg_string(cfg, 3);
6459 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
6460 CERROR("%s: device %s extents feature is not guaranteed to "
6461 "work on big-endian systems. Use \"bigendian_extents\" "
6462 "mount option to override.\n", name, dev);
6466 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) {
6467 CWARN("force_over_128tb option is depricated."
6468 "Filesystems less then 256TB can be created without any"
6469 "force options. Use force_over_256tb option for"
6470 "filesystems greather then 256TB.\n");
6473 if (opts != NULL && strstr(opts, "force_over_256tb") != NULL)
6474 force_over_256tb = 1;
6476 __page = alloc_page(GFP_KERNEL);
6478 GOTO(out, rc = -ENOMEM);
6479 page = (unsigned long)page_address(__page);
6480 options = (char *)page;
6483 /* strip out the options for back compatiblity */
6484 static char *sout[] = {
6491 /* strip out option we processed in osd */
6492 "bigendian_extents",
6493 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(3,0,53,0)
6494 #warning "remove force_over_128 option"
6496 "force_over_128tb (deprecated)",
6501 strcat(options, opts);
6502 for (rc = 0, str = options; sout[rc]; ) {
6503 char *op = strstr(str, sout[rc]);
6509 if (op == options || *(op - 1) == ',') {
6510 str = op + strlen(sout[rc]);
6511 if (*str == ',' || *str == '\0') {
6512 *str == ',' ? str++ : str;
6513 memmove(op, str, strlen(str) + 1);
6516 for (str = op; *str != ',' && *str != '\0'; str++)
6520 strncat(options, "user_xattr,acl", 14);
6523 /* Glom up mount options */
6524 if (*options != '\0')
6525 strcat(options, ",");
6526 strlcat(options, "no_mbcache", PAGE_CACHE_SIZE);
6528 type = get_fs_type("ldiskfs");
6530 CERROR("%s: cannot find ldiskfs module\n", name);
6531 GOTO(out, rc = -ENODEV);
6534 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
6535 module_put(type->owner);
6537 if (IS_ERR(o->od_mnt)) {
6538 rc = PTR_ERR(o->od_mnt);
6540 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
6544 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (64ULL << 30) &&
6545 force_over_256tb == 0) {
6546 CERROR("%s: device %s LDISKFS does not support filesystems "
6547 "greater than 256TB and can cause data corruption. "
6548 "Use \"force_over_256tb\" mount option to override.\n",
6550 GOTO(out, rc = -EINVAL);
6553 #ifdef HAVE_DEV_SET_RDONLY
6554 if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
6555 CERROR("%s: underlying device %s is marked as read-only. "
6556 "Setup failed\n", name, dev);
6557 GOTO(out_mnt, rc = -EROFS);
6561 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
6562 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
6563 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
6564 GOTO(out_mnt, rc = -EINVAL);
6567 #ifdef LDISKFS_MOUNT_DIRDATA
6568 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
6569 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
6570 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
6571 else if (!o->od_is_ost)
6572 CWARN("%s: device %s was upgraded from Lustre-1.x without "
6573 "enabling the dirdata feature. If you do not want to "
6574 "downgrade to Lustre-1.x again, you can enable it via "
6575 "'tune2fs -O dirdata device'\n", name, dev);
6577 inode = osd_sb(o)->s_root->d_inode;
6578 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
6579 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
6581 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
6585 if (lmd_flags & LMD_FLG_NOSCRUB)
6596 __free_page(__page);
6601 static struct lu_device *osd_device_fini(const struct lu_env *env,
6602 struct lu_device *d)
6604 struct osd_device *o = osd_dev(d);
6607 osd_shutdown(env, o);
6609 osd_scrub_cleanup(env, o);
6610 osd_obj_map_fini(o);
6616 static int osd_device_init0(const struct lu_env *env,
6617 struct osd_device *o,
6618 struct lustre_cfg *cfg)
6620 struct lu_device *l = osd2lu_dev(o);
6621 struct osd_thread_info *info;
6625 /* if the module was re-loaded, env can loose its keys */
6626 rc = lu_env_refill((struct lu_env *) env);
6629 info = osd_oti_get(env);
6632 l->ld_ops = &osd_lu_ops;
6633 o->od_dt_dev.dd_ops = &osd_dt_ops;
6635 spin_lock_init(&o->od_osfs_lock);
6636 mutex_init(&o->od_otable_mutex);
6637 INIT_LIST_HEAD(&o->od_orphan_list);
6639 o->od_read_cache = 1;
6640 o->od_writethrough_cache = 1;
6641 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
6643 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
6644 sizeof(o->od_svname));
6645 if (cplen >= sizeof(o->od_svname)) {
6650 o->od_index = -1; /* -1 means index is invalid */
6651 rc = server_name2index(o->od_svname, &o->od_index, NULL);
6652 if (rc == LDD_F_SV_TYPE_OST)
6655 o->od_full_scrub_ratio = OFSR_DEFAULT;
6656 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
6657 rc = osd_mount(env, o, cfg);
6661 rc = osd_obj_map_init(env, o);
6665 rc = lu_site_init(&o->od_site, l);
6667 GOTO(out_compat, rc);
6668 o->od_site.ls_bottom_dev = l;
6670 rc = lu_site_init_finish(&o->od_site);
6674 INIT_LIST_HEAD(&o->od_ios_list);
6675 /* setup scrub, including OI files initialization */
6676 rc = osd_scrub_setup(env, o);
6680 rc = osd_procfs_init(o, o->od_svname);
6682 CERROR("%s: can't initialize procfs: rc = %d\n",
6684 GOTO(out_scrub, rc);
6687 LASSERT(l->ld_site->ls_linkage.next != NULL);
6688 LASSERT(l->ld_site->ls_linkage.prev != NULL);
6690 /* initialize quota slave instance */
6691 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
6693 if (IS_ERR(o->od_quota_slave)) {
6694 rc = PTR_ERR(o->od_quota_slave);
6695 o->od_quota_slave = NULL;
6696 GOTO(out_procfs, rc);
6704 osd_scrub_cleanup(env, o);
6706 lu_site_fini(&o->od_site);
6708 osd_obj_map_fini(o);
6715 static struct lu_device *osd_device_alloc(const struct lu_env *env,
6716 struct lu_device_type *t,
6717 struct lustre_cfg *cfg)
6719 struct osd_device *o;
6724 return ERR_PTR(-ENOMEM);
6726 rc = dt_device_init(&o->od_dt_dev, t);
6728 /* Because the ctx might be revived in dt_device_init,
6729 * refill the env here */
6730 lu_env_refill((struct lu_env *)env);
6731 rc = osd_device_init0(env, o, cfg);
6733 dt_device_fini(&o->od_dt_dev);
6736 if (unlikely(rc != 0))
6739 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
6742 static struct lu_device *osd_device_free(const struct lu_env *env,
6743 struct lu_device *d)
6745 struct osd_device *o = osd_dev(d);
6748 /* XXX: make osd top device in order to release reference */
6749 d->ld_site->ls_top_dev = d;
6750 lu_site_purge(env, d->ld_site, -1);
6751 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
6752 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
6753 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
6755 lu_site_fini(&o->od_site);
6756 dt_device_fini(&o->od_dt_dev);
6761 static int osd_process_config(const struct lu_env *env,
6762 struct lu_device *d, struct lustre_cfg *cfg)
6764 struct osd_device *o = osd_dev(d);
6768 switch (cfg->lcfg_command) {
6770 rc = osd_mount(env, o, cfg);
6773 lu_dev_del_linkage(d->ld_site, d);
6774 rc = osd_shutdown(env, o);
6777 LASSERT(&o->od_dt_dev);
6778 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
6779 cfg, &o->od_dt_dev);
6780 if (rc > 0 || rc == -ENOSYS)
6781 rc = class_process_proc_param(PARAM_OST,
6782 lprocfs_osd_obd_vars,
6783 cfg, &o->od_dt_dev);
6792 static int osd_recovery_complete(const struct lu_env *env,
6793 struct lu_device *d)
6795 struct osd_device *osd = osd_dev(d);
6799 if (osd->od_quota_slave == NULL)
6802 /* start qsd instance on recovery completion, this notifies the quota
6803 * slave code that we are about to process new requests now */
6804 rc = qsd_start(env, osd->od_quota_slave);
6809 * we use exports to track all osd users
6811 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
6812 struct obd_device *obd, struct obd_uuid *cluuid,
6813 struct obd_connect_data *data, void *localdata)
6815 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6816 struct lustre_handle conn;
6820 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
6822 rc = class_connect(&conn, obd, cluuid);
6826 *exp = class_conn2export(&conn);
6828 spin_lock(&osd->od_osfs_lock);
6830 spin_unlock(&osd->od_osfs_lock);
6836 * once last export (we don't count self-export) disappeared
6837 * osd can be released
6839 static int osd_obd_disconnect(struct obd_export *exp)
6841 struct obd_device *obd = exp->exp_obd;
6842 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6843 int rc, release = 0;
6846 /* Only disconnect the underlying layers on the final disconnect. */
6847 spin_lock(&osd->od_osfs_lock);
6849 if (osd->od_connects == 0)
6851 spin_unlock(&osd->od_osfs_lock);
6853 rc = class_disconnect(exp); /* bz 9811 */
6855 if (rc == 0 && release)
6856 class_manual_cleanup(obd);
6860 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
6861 struct lu_device *dev)
6863 struct osd_device *osd = osd_dev(dev);
6864 struct lr_server_data *lsd =
6865 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
6869 if (osd->od_quota_slave != NULL) {
6870 /* set up quota slave objects */
6871 result = qsd_prepare(env, osd->od_quota_slave);
6876 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
6877 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
6878 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
6879 osd->od_index_in_idif = 1;
6881 osd->od_index_in_idif = 0;
6882 result = osd_register_proc_index_in_idif(osd);
6887 osd->od_index_in_idif = 1;
6891 result = osd_fid_init(env, osd);
6896 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
6897 struct lu_fid *fid, struct md_op_data *op_data)
6899 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
6901 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
6904 static const struct lu_object_operations osd_lu_obj_ops = {
6905 .loo_object_init = osd_object_init,
6906 .loo_object_delete = osd_object_delete,
6907 .loo_object_release = osd_object_release,
6908 .loo_object_free = osd_object_free,
6909 .loo_object_print = osd_object_print,
6910 .loo_object_invariant = osd_object_invariant
6913 const struct lu_device_operations osd_lu_ops = {
6914 .ldo_object_alloc = osd_object_alloc,
6915 .ldo_process_config = osd_process_config,
6916 .ldo_recovery_complete = osd_recovery_complete,
6917 .ldo_prepare = osd_prepare,
6920 static const struct lu_device_type_operations osd_device_type_ops = {
6921 .ldto_init = osd_type_init,
6922 .ldto_fini = osd_type_fini,
6924 .ldto_start = osd_type_start,
6925 .ldto_stop = osd_type_stop,
6927 .ldto_device_alloc = osd_device_alloc,
6928 .ldto_device_free = osd_device_free,
6930 .ldto_device_init = osd_device_init,
6931 .ldto_device_fini = osd_device_fini
6934 static struct lu_device_type osd_device_type = {
6935 .ldt_tags = LU_DEVICE_DT,
6936 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
6937 .ldt_ops = &osd_device_type_ops,
6938 .ldt_ctx_tags = LCT_LOCAL,
6941 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
6943 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6944 struct super_block *sb = osd_sb(osd);
6946 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
6950 * lprocfs legacy support.
6952 static struct obd_ops osd_obd_device_ops = {
6953 .o_owner = THIS_MODULE,
6954 .o_connect = osd_obd_connect,
6955 .o_disconnect = osd_obd_disconnect,
6956 .o_fid_alloc = osd_fid_alloc,
6957 .o_health_check = osd_health_check,
6960 static int __init osd_init(void)
6964 LASSERT(BH_DXLock < sizeof(((struct buffer_head *)0)->b_state) * 8);
6965 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
6966 /* please, try to keep osd_thread_info smaller than a page */
6967 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
6972 rc = lu_kmem_init(ldiskfs_caches);
6976 rc = class_register_type(&osd_obd_device_ops, NULL, true,
6977 lprocfs_osd_module_vars,
6978 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
6980 lu_kmem_fini(ldiskfs_caches);
6984 static void __exit osd_exit(void)
6986 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
6987 lu_kmem_fini(ldiskfs_caches);
6990 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
6991 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
6992 MODULE_VERSION(LUSTRE_VERSION_STRING);
6993 MODULE_LICENSE("GPL");
6995 module_init(osd_init);
6996 module_exit(osd_exit);