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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/osd/osd_handler.c
34 * Top-level entry points into osd module
36 * Author: Nikita Danilov <nikita@clusterfs.com>
37 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
40 #define DEBUG_SUBSYSTEM S_OSD
42 #include <linux/module.h>
43 #include <linux/user_namespace.h>
44 #ifdef HAVE_UIDGID_HEADER
45 # include <linux/uidgid.h>
48 /* prerequisite for linux/xattr.h */
49 #include <linux/types.h>
50 /* prerequisite for linux/xattr.h */
52 /* XATTR_{REPLACE,CREATE} */
53 #include <linux/xattr.h>
55 #include <ldiskfs/ldiskfs.h>
56 #include <ldiskfs/xattr.h>
57 #include <ldiskfs/ldiskfs_extents.h>
60 * struct OBD_{ALLOC,FREE}*()
63 #include <obd_support.h>
64 /* struct ptlrpc_thread */
65 #include <lustre_net.h>
66 #include <lustre_fid.h>
68 #include <uapi/linux/lustre/lustre_param.h>
70 #include "osd_internal.h"
71 #include "osd_dynlocks.h"
73 /* llo_* api support */
74 #include <md_object.h>
75 #include <lustre_quota.h>
77 #include <lustre_linkea.h>
80 module_param(ldiskfs_pdo, int, 0644);
81 MODULE_PARM_DESC(ldiskfs_pdo, "ldiskfs with parallel directory operations");
83 int ldiskfs_track_declares_assert;
84 module_param(ldiskfs_track_declares_assert, int, 0644);
85 MODULE_PARM_DESC(ldiskfs_track_declares_assert, "LBUG during tracking of declares");
87 /* Slab to allocate dynlocks */
88 struct kmem_cache *dynlock_cachep;
90 /* Slab to allocate osd_it_ea */
91 struct kmem_cache *osd_itea_cachep;
93 static struct lu_kmem_descr ldiskfs_caches[] = {
95 .ckd_cache = &dynlock_cachep,
96 .ckd_name = "dynlock_cache",
97 .ckd_size = sizeof(struct dynlock_handle)
100 .ckd_cache = &osd_itea_cachep,
101 .ckd_name = "osd_itea_cache",
102 .ckd_size = sizeof(struct osd_it_ea)
109 static const char dot[] = ".";
110 static const char dotdot[] = "..";
112 static const struct lu_object_operations osd_lu_obj_ops;
113 static const struct dt_object_operations osd_obj_ops;
114 static const struct dt_object_operations osd_obj_otable_it_ops;
115 static const struct dt_index_operations osd_index_iam_ops;
116 static const struct dt_index_operations osd_index_ea_ops;
118 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
119 const struct lu_fid *fid);
120 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
121 struct osd_device *osd);
123 int osd_trans_declare_op2rb[] = {
124 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
125 [OSD_OT_PUNCH] = OSD_OT_MAX,
126 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
127 [OSD_OT_CREATE] = OSD_OT_DESTROY,
128 [OSD_OT_DESTROY] = OSD_OT_CREATE,
129 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
130 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
131 [OSD_OT_WRITE] = OSD_OT_WRITE,
132 [OSD_OT_INSERT] = OSD_OT_DELETE,
133 [OSD_OT_DELETE] = OSD_OT_INSERT,
134 [OSD_OT_QUOTA] = OSD_OT_MAX,
137 static int osd_has_index(const struct osd_object *obj)
139 return obj->oo_dt.do_index_ops != NULL;
142 static int osd_object_invariant(const struct lu_object *l)
144 return osd_invariant(osd_obj(l));
148 * Concurrency: doesn't matter
150 static int osd_is_write_locked(const struct lu_env *env, struct osd_object *o)
152 struct osd_thread_info *oti = osd_oti_get(env);
153 return oti->oti_w_locks > 0 && o->oo_owner == env;
157 * Concurrency: doesn't access mutable data
159 static int osd_root_get(const struct lu_env *env,
160 struct dt_device *dev, struct lu_fid *f)
162 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
167 * the following set of functions are used to maintain per-thread
168 * cache of FID->ino mapping. this mechanism is needed to resolve
169 * FID to inode at dt_insert() which in turn stores ino in the
170 * directory entries to keep ldiskfs compatible with ext[34].
171 * due to locking-originated restrictions we can't lookup ino
172 * using LU cache (deadlock is possible). lookup using OI is quite
173 * expensive. so instead we maintain this cache and methods like
174 * dt_create() fill it. so in the majority of cases dt_insert() is
175 * able to find needed mapping in lockless manner.
177 static struct osd_idmap_cache *
178 osd_idc_find(const struct lu_env *env, struct osd_device *osd,
179 const struct lu_fid *fid)
181 struct osd_thread_info *oti = osd_oti_get(env);
182 struct osd_idmap_cache *idc = oti->oti_ins_cache;
184 for (i = 0; i < oti->oti_ins_cache_used; i++) {
185 if (!lu_fid_eq(&idc[i].oic_fid, fid))
187 if (idc[i].oic_dev != osd)
196 static struct osd_idmap_cache *
197 osd_idc_add(const struct lu_env *env, struct osd_device *osd,
198 const struct lu_fid *fid)
200 struct osd_thread_info *oti = osd_oti_get(env);
201 struct osd_idmap_cache *idc;
204 if (unlikely(oti->oti_ins_cache_used >= oti->oti_ins_cache_size)) {
205 i = oti->oti_ins_cache_size * 2;
207 i = OSD_INS_CACHE_SIZE;
208 OBD_ALLOC(idc, sizeof(*idc) * i);
210 return ERR_PTR(-ENOMEM);
211 if (oti->oti_ins_cache != NULL) {
212 memcpy(idc, oti->oti_ins_cache,
213 oti->oti_ins_cache_used * sizeof(*idc));
214 OBD_FREE(oti->oti_ins_cache,
215 oti->oti_ins_cache_used * sizeof(*idc));
217 oti->oti_ins_cache = idc;
218 oti->oti_ins_cache_size = i;
221 idc = oti->oti_ins_cache + oti->oti_ins_cache_used++;
224 idc->oic_lid.oii_ino = 0;
225 idc->oic_lid.oii_gen = 0;
232 * lookup mapping for the given fid in the cache, initialize a
233 * new one if not found. the initialization checks whether the
234 * object is local or remote. for local objects, OI is used to
235 * learn ino/generation. the function is used when the caller
236 * has no information about the object, e.g. at dt_insert().
238 static struct osd_idmap_cache *
239 osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd,
240 const struct lu_fid *fid)
242 struct osd_idmap_cache *idc;
245 idc = osd_idc_find(env, osd, fid);
246 LASSERT(!IS_ERR(idc));
250 /* new mapping is needed */
251 idc = osd_idc_add(env, osd, fid);
256 rc = osd_remote_fid(env, osd, fid);
257 if (unlikely(rc < 0))
261 /* the object is local, lookup in OI */
262 /* XXX: probably cheaper to lookup in LU first? */
263 rc = osd_oi_lookup(osd_oti_get(env), osd, fid,
265 if (unlikely(rc < 0)) {
266 CERROR("can't lookup: rc = %d\n", rc);
270 /* the object is remote */
278 * lookup mapping for given FID and fill it from the given object.
279 * the object is lolcal by definition.
281 static int osd_idc_find_and_init(const struct lu_env *env,
282 struct osd_device *osd,
283 struct osd_object *obj)
285 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
286 struct osd_idmap_cache *idc;
288 idc = osd_idc_find(env, osd, fid);
289 LASSERT(!IS_ERR(idc));
291 if (obj->oo_inode == NULL)
293 if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) {
294 LASSERT(idc->oic_lid.oii_ino == 0);
295 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
296 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
301 /* new mapping is needed */
302 idc = osd_idc_add(env, osd, fid);
306 if (obj->oo_inode != NULL) {
307 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
308 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
314 * OSD object methods.
318 * Concurrency: no concurrent access is possible that early in object
321 static struct lu_object *osd_object_alloc(const struct lu_env *env,
322 const struct lu_object_header *hdr,
325 struct osd_object *mo;
330 struct lu_object_header *h;
332 l = &mo->oo_dt.do_lu;
333 h = &osd_dev(d)->od_scrub.os_scrub.os_obj_header;
334 if (unlikely(fid_is_zero(&h->loh_fid))) {
335 /* For the OI_scrub object during OSD device init. */
336 lu_object_header_init(h);
337 lu_object_init(l, h, d);
338 lu_object_add_top(h, l);
340 dt_object_init(&mo->oo_dt, NULL, d);
342 mo->oo_dt.do_ops = &osd_obj_ops;
343 l->lo_ops = &osd_lu_obj_ops;
344 init_rwsem(&mo->oo_sem);
345 init_rwsem(&mo->oo_ext_idx_sem);
346 spin_lock_init(&mo->oo_guard);
347 INIT_LIST_HEAD(&mo->oo_xattr_list);
354 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
355 struct dentry *dentry, struct lustre_ost_attrs *loa)
359 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
360 (void *)loa, sizeof(*loa));
362 struct lustre_mdt_attrs *lma = &loa->loa_lma;
364 if (rc < sizeof(*lma))
368 lustre_loa_swab(loa, true);
369 /* Check LMA compatibility */
370 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
371 CWARN("%s: unsupported incompat LMA feature(s) %#x "
372 "for fid = "DFID", ino = %lu\n",
374 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
375 PFID(&lma->lma_self_fid), inode->i_ino);
378 } else if (rc == 0) {
386 * retrieve object from backend ext fs.
388 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
389 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("%s: bad inode: ino = %u\n",
418 osd_dev2name(dev), id->oii_ino);
420 inode = ERR_PTR(-ENOENT);
421 } else if ((rc = osd_attach_jinode(inode))) {
425 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
426 if (id->oii_gen == OSD_OII_NOGEN)
427 osd_id_gen(id, inode->i_ino, inode->i_generation);
429 /* Do not update file c/mtime in ldiskfs.
430 * NB: we don't have any lock to protect this because we don't
431 * have reference on osd_object now, but contention with
432 * another lookup + attr_set can't happen in the tiny window
433 * between if (...) and set S_NOCMTIME. */
434 if (!(inode->i_flags & S_NOCMTIME))
435 inode->i_flags |= S_NOCMTIME;
440 int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd,
441 handle_t *handle, struct dentry *child,
442 struct inode *inode, struct htree_lock *hlock)
446 rc = __ldiskfs_add_entry(handle, child, inode, hlock);
447 if (rc == -ENOBUFS || rc == -ENOSPC) {
448 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
449 struct inode *parent = child->d_parent->d_inode;
450 struct lu_fid *fid = NULL;
452 rc2 = osd_get_lma(info, parent, child->d_parent, loa);
454 fid = &loa->loa_lma.lma_self_fid;
455 } else if (rc2 == -ENODATA) {
456 if (unlikely(parent == inode->i_sb->s_root->d_inode)) {
457 fid = &info->oti_fid3;
458 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
459 } else if (!osd->od_is_ost && osd->od_index == 0) {
460 fid = &info->oti_fid3;
461 lu_igif_build(fid, parent->i_ino,
462 parent->i_generation);
467 CWARN("%s: directory (inode: %lu, FID: "DFID") %s "
468 "maximum entry limit\n",
469 osd_name(osd), parent->i_ino, PFID(fid),
470 rc == -ENOSPC ? "has reached" : "is approaching");
472 CWARN("%s: directory (inode: %lu, FID: unknown) %s "
473 "maximum entry limit\n",
474 osd_name(osd), parent->i_ino,
475 rc == -ENOSPC ? "has reached" : "is approaching");
477 /* ignore such error now */
486 static struct inode *
487 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
488 struct osd_inode_id *id, struct lu_fid *fid)
490 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
494 inode = osd_iget(info, dev, id);
498 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
500 *fid = loa->loa_lma.lma_self_fid;
501 } else if (rc == -ENODATA) {
502 if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
503 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
505 lu_igif_build(fid, inode->i_ino, inode->i_generation);
513 static struct inode *osd_iget_check(struct osd_thread_info *info,
514 struct osd_device *dev,
515 const struct lu_fid *fid,
516 struct osd_inode_id *id,
523 /* The cached OI mapping is trustable. If we cannot locate the inode
524 * via the cached OI mapping, then return the failure to the caller
525 * directly without further OI checking. */
528 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
531 if (!trusted && (rc == -ENOENT || rc == -ESTALE))
534 CDEBUG(D_INODE, "no inode for FID: "DFID", ino = %u, rc = %d\n",
535 PFID(fid), id->oii_ino, rc);
539 if (is_bad_inode(inode)) {
544 CDEBUG(D_INODE, "bad inode for FID: "DFID", ino = %u\n",
545 PFID(fid), id->oii_ino);
549 if (id->oii_gen != OSD_OII_NOGEN &&
550 inode->i_generation != id->oii_gen) {
555 CDEBUG(D_INODE, "unmatched inode for FID: "DFID", ino = %u, "
556 "oii_gen = %u, i_generation = %u\n", PFID(fid),
557 id->oii_ino, id->oii_gen, inode->i_generation);
561 if (inode->i_nlink == 0) {
566 CDEBUG(D_INODE, "stale inode for FID: "DFID", ino = %u\n",
567 PFID(fid), id->oii_ino);
571 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
575 __u32 saved_ino = id->oii_ino;
576 __u32 saved_gen = id->oii_gen;
579 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
581 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
582 /* XXX: There are four possible cases:
584 * Backup/restore caused the OI invalid.
586 * Someone unlinked the object but NOT removed
587 * the OI mapping, such as mount target device
588 * as ldiskfs, and modify something directly.
590 * Someone just removed the object between the
591 * former oi_lookup and the iget. It is normal.
592 * 4. Other failure cases.
594 * Generally, when the device is mounted, it will
595 * auto check whether the system is restored from
596 * file-level backup or not. We trust such detect
597 * to distinguish the 1st case from the 2nd case:
598 * if the OI files are consistent but may contain
599 * stale OI mappings because of case 2, if iget()
600 * returns -ENOENT or -ESTALE, then it should be
603 /* If the OI mapping was in OI file before the
604 * osd_iget_check(), but now, it is disappear,
605 * then it must be removed by race. That is a
606 * normal race case. */
609 /* It is the OI scrub updated the OI mapping by race.
610 * The new OI mapping must be valid. */
611 if (saved_ino != id->oii_ino ||
612 (saved_gen != id->oii_gen && saved_gen != OSD_OII_NOGEN)) {
621 if (dev->od_scrub.os_scrub.os_file.sf_flags &
623 /* It still can be the case 2, but we cannot
624 * distinguish it from the case 1. So return
625 * -EREMCHG to block current operation until
626 * OI scrub rebuilt the OI mappings. */
634 if (inode->i_generation == id->oii_gen)
639 if (id->oii_gen == OSD_OII_NOGEN)
640 osd_id_gen(id, inode->i_ino, inode->i_generation);
642 /* Do not update file c/mtime in ldiskfs.
643 * NB: we don't have any lock to protect this because we don't
644 * have reference on osd_object now, but contention with
645 * another lookup + attr_set can't happen in the tiny window
646 * between if (...) and set S_NOCMTIME. */
647 if (!(inode->i_flags & S_NOCMTIME))
648 inode->i_flags |= S_NOCMTIME;
665 * \retval +v: new filter_fid, does not contain self-fid
666 * \retval 0: filter_fid_old, contains self-fid
667 * \retval -v: other failure cases
669 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
670 struct dentry *dentry, struct lu_fid *fid)
672 struct filter_fid_old *ff = &info->oti_ff;
673 struct ost_id *ostid = &info->oti_ostid;
676 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
677 if (rc == sizeof(*ff)) {
679 ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
680 rc = ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
682 * XXX: use 0 as the index for compatibility, the caller will
683 * handle index related issues when necessary.
686 ostid_to_fid(fid, ostid, 0);
687 } else if (rc == sizeof(struct filter_fid)) {
689 } else if (rc >= 0) {
696 static int osd_lma_self_repair(struct osd_thread_info *info,
697 struct osd_device *osd, struct inode *inode,
698 const struct lu_fid *fid, __u32 compat)
703 LASSERT(current->journal_info == NULL);
705 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
706 osd_dto_credits_noquota[DTO_XATTR_SET]);
709 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
714 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
716 CWARN("%s: cannot self repair the LMA: rc = %d\n",
718 ldiskfs_journal_stop(jh);
722 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
724 struct osd_thread_info *info = osd_oti_get(env);
725 struct osd_device *osd = osd_obj2dev(obj);
726 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
727 struct lustre_mdt_attrs *lma = &loa->loa_lma;
728 struct inode *inode = obj->oo_inode;
729 struct dentry *dentry = &info->oti_obj_dentry;
730 struct lu_fid *fid = NULL;
731 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
735 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
736 (void *)loa, sizeof(*loa));
737 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
738 fid = &lma->lma_self_fid;
739 rc = osd_get_idif(info, inode, dentry, fid);
740 if ((rc > 0) || (rc == -ENODATA && osd->od_index_in_idif)) {
741 /* For the given OST-object, if it has neither LMA nor
742 * FID in XATTR_NAME_FID, then the given FID (which is
743 * contained in the @obj, from client RPC for locating
744 * the OST-object) is trusted. We use it to generate
746 osd_lma_self_repair(info, osd, inode, rfid,
757 lustre_lma_swab(lma);
758 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
759 (CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT) &&
760 S_ISREG(inode->i_mode)))) {
761 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
762 "fid = "DFID", ino = %lu\n", osd_name(osd),
763 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
764 PFID(rfid), inode->i_ino);
767 fid = &lma->lma_self_fid;
768 if (lma->lma_compat & LMAC_STRIPE_INFO &&
770 obj->oo_pfid_in_lma = 1;
771 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
773 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
777 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
778 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
779 struct ost_id *oi = &info->oti_ostid;
780 struct lu_fid *fid1 = &info->oti_fid3;
781 __u32 idx = fid_idif_ost_idx(rfid);
783 /* For old IDIF, the OST index is not part of the IDIF,
784 * Means that different OSTs may have the same IDIFs.
785 * Under such case, we need to make some compatible
786 * check to make sure to trigger OI scrub properly. */
787 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
788 /* Given @rfid is new, LMA is old. */
789 fid_to_ostid(fid, oi);
790 ostid_to_fid(fid1, oi, idx);
791 if (lu_fid_eq(fid1, rfid)) {
792 if (osd->od_index_in_idif)
793 osd_lma_self_repair(info, osd,
807 struct osd_check_lmv_buf {
808 #ifdef HAVE_DIR_CONTEXT
809 /* please keep it as first member */
810 struct dir_context ctx;
812 struct osd_thread_info *oclb_info;
813 struct osd_device *oclb_dev;
814 struct osd_idmap_cache *oclb_oic;
818 * It is called internally by ->readdir() to filter out the
819 * local slave object's FID of the striped directory.
821 * \retval 1 found the local slave's FID
822 * \retval 0 continue to check next item
823 * \retval -ve for failure
825 #ifdef HAVE_FILLDIR_USE_CTX
826 static int osd_stripe_dir_filldir(struct dir_context *buf,
828 static int osd_stripe_dir_filldir(void *buf,
830 const char *name, int namelen,
831 loff_t offset, __u64 ino, unsigned d_type)
833 struct osd_check_lmv_buf *oclb = (struct osd_check_lmv_buf *)buf;
834 struct osd_thread_info *oti = oclb->oclb_info;
835 struct lu_fid *fid = &oti->oti_fid3;
836 struct osd_inode_id *id = &oti->oti_id3;
837 struct osd_device *dev = oclb->oclb_dev;
838 struct osd_idmap_cache *oic = oclb->oclb_oic;
846 sscanf(name + 1, SFID, RFID(fid));
847 if (!fid_is_sane(fid))
850 if (osd_remote_fid(oti->oti_env, dev, fid))
853 osd_id_gen(id, ino, OSD_OII_NOGEN);
854 inode = osd_iget(oti, dev, id);
856 return PTR_ERR(inode);
859 osd_add_oi_cache(oti, dev, id, fid);
863 rc = osd_oii_insert(dev, oic, true);
865 return rc == 0 ? 1 : rc;
868 /* When lookup item under striped directory, we need to locate the master
869 * MDT-object of the striped directory firstly, then the client will send
870 * lookup (getattr_by_name) RPC to the MDT with some slave MDT-object's FID
871 * and the item's name. If the system is restored from MDT file level backup,
872 * then before the OI scrub completely built the OI files, the OI mappings of
873 * the master MDT-object and slave MDT-object may be invalid. Usually, it is
874 * not a problem for the master MDT-object. Because when locate the master
875 * MDT-object, we will do name based lookup (for the striped directory itself)
876 * firstly, during such process we can setup the correct OI mapping for the
877 * master MDT-object. But it will be trouble for the slave MDT-object. Because
878 * the client will not trigger name based lookup on the MDT to locate the slave
879 * MDT-object before locating item under the striped directory, then when
880 * osd_fid_lookup(), it will find that the OI mapping for the slave MDT-object
881 * is invalid and does not know what the right OI mapping is, then the MDT has
882 * to return -EINPROGRESS to the client to notify that the OI scrub is rebuiding
883 * the OI file, related OI mapping is unknown yet, please try again later. And
884 * then client will re-try the RPC again and again until related OI mapping has
885 * been updated. That is quite inefficient.
887 * To resolve above trouble, we will handle it as the following two cases:
889 * 1) The slave MDT-object and the master MDT-object are on different MDTs.
890 * It is relative easy. Be as one of remote MDT-objects, the slave MDT-object
891 * is linked under /REMOTE_PARENT_DIR with the name of its FID string.
892 * We can locate the slave MDT-object via lookup the /REMOTE_PARENT_DIR
893 * directly. Please check osd_fid_lookup().
895 * 2) The slave MDT-object and the master MDT-object reside on the same MDT.
896 * Under such case, during lookup the master MDT-object, we will lookup the
897 * slave MDT-object via readdir against the master MDT-object, because the
898 * slave MDT-objects information are stored as sub-directories with the name
899 * "${FID}:${index}". Then when find the local slave MDT-object, its OI
900 * mapping will be recorded. Then subsequent osd_fid_lookup() will know
901 * the correct OI mapping for the slave MDT-object. */
902 static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev,
903 struct inode *inode, struct osd_idmap_cache *oic)
905 struct lu_buf *buf = &oti->oti_big_buf;
906 struct dentry *dentry = &oti->oti_obj_dentry;
907 struct file *filp = &oti->oti_file;
908 const struct file_operations *fops;
909 struct lmv_mds_md_v1 *lmv1;
910 struct osd_check_lmv_buf oclb = {
911 #ifdef HAVE_DIR_CONTEXT
912 .ctx.actor = osd_stripe_dir_filldir,
922 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, buf->lb_buf,
925 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, NULL, 0);
927 lu_buf_realloc(buf, rc);
928 if (buf->lb_buf == NULL)
929 GOTO(out, rc = -ENOMEM);
935 if (unlikely(rc == 0 || rc == -ENODATA))
941 if (unlikely(buf->lb_buf == NULL)) {
942 lu_buf_realloc(buf, rc);
943 if (buf->lb_buf == NULL)
944 GOTO(out, rc = -ENOMEM);
950 if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
954 dentry->d_inode = inode;
955 dentry->d_sb = inode->i_sb;
957 filp->f_path.dentry = dentry;
958 filp->f_mode = FMODE_64BITHASH;
959 filp->f_mapping = inode->i_mapping;
961 filp->private_data = NULL;
962 set_file_inode(filp, inode);
964 #ifdef HAVE_DIR_CONTEXT
965 oclb.ctx.pos = filp->f_pos;
966 rc = fops->iterate(filp, &oclb.ctx);
967 filp->f_pos = oclb.ctx.pos;
969 rc = fops->readdir(filp, &oclb, osd_stripe_dir_filldir);
971 fops->release(inode, filp);
975 CDEBUG(D_LFSCK, "%s: fail to check LMV EA, inode = %lu/%u,"
976 DFID": rc = %d\n", osd_ino2name(inode),
977 inode->i_ino, inode->i_generation,
978 PFID(&oic->oic_fid), rc);
985 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
986 const struct lu_fid *fid,
987 const struct lu_object_conf *conf)
989 struct osd_thread_info *info;
990 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
991 struct osd_device *dev;
992 struct osd_idmap_cache *oic;
993 struct osd_inode_id *id;
994 struct inode *inode = NULL;
995 struct lustre_scrub *scrub;
996 struct scrub_file *sf;
997 __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT | SS_AUTO_FULL;
1002 bool remote = false;
1003 bool trusted = true;
1004 bool updated = false;
1005 bool checked = false;
1008 LINVRNT(osd_invariant(obj));
1009 LASSERT(obj->oo_inode == NULL);
1010 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
1012 dev = osd_dev(ldev);
1013 scrub = &dev->od_scrub.os_scrub;
1014 sf = &scrub->os_file;
1015 info = osd_oti_get(env);
1017 oic = &info->oti_cache;
1019 if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
1022 /* For the object is created as locking anchor, or for the object to
1023 * be created on disk. No need to osd_oi_lookup() at here because FID
1024 * shouldn't never be re-used, if it's really a duplicate FID from
1025 * unexpected reason, we should be able to detect it later by calling
1026 * do_create->osd_oi_insert(). */
1027 if (conf && conf->loc_flags & LOC_F_NEW)
1028 GOTO(out, result = 0);
1030 /* Search order: 1. per-thread cache. */
1031 if (lu_fid_eq(fid, &oic->oic_fid) && likely(oic->oic_dev == dev)) {
1037 if (!list_empty(&scrub->os_inconsistent_items)) {
1038 /* Search order: 2. OI scrub pending list. */
1039 result = osd_oii_lookup(dev, fid, id);
1044 /* The OI mapping in the OI file can be updated by the OI scrub
1045 * when we locate the inode via FID. So it may be not trustable. */
1048 /* Search order: 3. OI files. */
1049 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1050 if (result == -ENOENT) {
1051 if (!(fid_is_norm(fid) || fid_is_igif(fid)) ||
1052 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
1053 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
1055 GOTO(out, result = 0);
1064 obj->oo_inode = NULL;
1065 /* for later passes through checks, not true on first pass */
1066 if (!IS_ERR_OR_NULL(inode))
1069 inode = osd_iget_check(info, dev, fid, id, trusted);
1070 if (!IS_ERR(inode)) {
1071 obj->oo_inode = inode;
1079 result = PTR_ERR(inode);
1080 if (result == -ENOENT || result == -ESTALE)
1081 GOTO(out, result = 0);
1083 if (result != -EREMCHG)
1087 /* We still have chance to get the valid inode: for the
1088 * object which is referenced by remote name entry, the
1089 * object on the local MDT will be linked under the dir
1090 * of "/REMOTE_PARENT_DIR" with its FID string as name.
1092 * We do not know whether the object for the given FID
1093 * is referenced by some remote name entry or not, and
1094 * especially for DNE II, a multiple-linked object may
1095 * have many name entries reside on many MDTs.
1097 * To simplify the operation, OSD will not distinguish
1098 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
1099 * only happened for the RPC from other MDT during the
1100 * OI scrub, or for the client side RPC with FID only,
1101 * such as FID to path, or from old connected client. */
1102 if (!remote && !fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) {
1103 rc1 = osd_lookup_in_remote_parent(info, dev, fid, id);
1107 flags |= SS_AUTO_PARTIAL;
1108 flags &= ~SS_AUTO_FULL;
1113 if (thread_is_running(&scrub->os_thread)) {
1114 if (scrub->os_partial_scan && !scrub->os_in_join)
1117 if (IS_ERR_OR_NULL(inode) || result)
1118 GOTO(out, result = -EINPROGRESS);
1121 LASSERT(obj->oo_inode == inode);
1123 osd_add_oi_cache(info, dev, id, fid);
1124 osd_oii_insert(dev, oic, true);
1128 if (dev->od_auto_scrub_interval == AS_NEVER) {
1130 GOTO(out, result = -EREMCHG);
1133 LASSERT(obj->oo_inode == inode);
1135 osd_add_oi_cache(info, dev, id, fid);
1140 rc1 = osd_scrub_start(env, dev, flags);
1141 LCONSOLE_WARN("%s: trigger OI scrub by RPC for the " DFID" with flags "
1142 "0x%x, rc = %d\n", osd_name(dev), PFID(fid), flags, rc1);
1143 if (rc1 && rc1 != -EALREADY)
1144 GOTO(out, result = -EREMCHG);
1146 if (IS_ERR_OR_NULL(inode) || result)
1147 GOTO(out, result = -EINPROGRESS);
1150 LASSERT(obj->oo_inode == inode);
1152 osd_add_oi_cache(info, dev, id, fid);
1153 osd_oii_insert(dev, oic, true);
1157 result = osd_check_lma(env, obj);
1162 LASSERTF(id->oii_ino == inode->i_ino &&
1163 id->oii_gen == inode->i_generation,
1164 "locate wrong inode for FID: "DFID", %u/%u => %ld/%u\n",
1165 PFID(fid), id->oii_ino, id->oii_gen,
1166 inode->i_ino, inode->i_generation);
1168 saved_ino = inode->i_ino;
1169 saved_gen = inode->i_generation;
1171 if (unlikely(result == -ENODATA)) {
1172 /* If the OI scrub updated the OI mapping by race, it
1173 * must be valid. Trust the inode that has no LMA EA. */
1177 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1179 /* The OI mapping is still there, the inode is still
1180 * valid. It is just becaues the inode has no LMA EA. */
1181 if (saved_ino == id->oii_ino &&
1182 saved_gen == id->oii_gen)
1185 /* It is the OI scrub updated the OI mapping by race.
1186 * The new OI mapping must be valid. */
1192 /* "result == -ENOENT" means that the OI mappinghas been
1193 * removed by race, so the inode belongs to other object.
1195 * Others error can be returned directly. */
1196 if (result == -ENOENT) {
1199 obj->oo_inode = NULL;
1204 if (result != -EREMCHG)
1209 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1210 /* "result == -ENOENT" means the cached OI mapping has been removed
1211 * from the OI file by race, above inode belongs to other object. */
1212 if (result == -ENOENT) {
1215 obj->oo_inode = NULL;
1216 GOTO(out, result = 0);
1222 if (saved_ino == id->oii_ino && saved_gen == id->oii_gen) {
1227 /* It is the OI scrub updated the OI mapping by race.
1228 * The new OI mapping must be valid. */
1235 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
1236 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1238 result = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
1240 if (lma->lma_compat & LMAC_STRIPE_INFO &&
1242 obj->oo_pfid_in_lma = 1;
1243 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
1245 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
1246 } else if (result != -ENODATA) {
1251 obj->oo_compat_dot_created = 1;
1252 obj->oo_compat_dotdot_created = 1;
1254 if (S_ISDIR(inode->i_mode) &&
1255 (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING))
1256 osd_check_lmv(info, dev, inode, oic);
1258 result = osd_attach_jinode(inode);
1263 GOTO(out, result = 0);
1265 LASSERT(!obj->oo_hl_head);
1266 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1268 GOTO(out, result = (!obj->oo_hl_head ? -ENOMEM : 0));
1271 if (result || !obj->oo_inode) {
1272 if (!IS_ERR_OR_NULL(inode))
1275 obj->oo_inode = NULL;
1277 fid_zero(&oic->oic_fid);
1280 LINVRNT(osd_invariant(obj));
1285 * Concurrency: shouldn't matter.
1287 static void osd_object_init0(struct osd_object *obj)
1289 LASSERT(obj->oo_inode != NULL);
1290 obj->oo_dt.do_body_ops = &osd_body_ops;
1291 obj->oo_dt.do_lu.lo_header->loh_attr |=
1292 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
1296 * Concurrency: no concurrent access is possible that early in object
1299 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
1300 const struct lu_object_conf *conf)
1302 struct osd_object *obj = osd_obj(l);
1305 LINVRNT(osd_invariant(obj));
1307 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
1308 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
1309 l->lo_header->loh_attr |= LOHA_EXISTS;
1313 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
1314 if (unlikely(l->lo_header ==
1315 &osd_obj2dev(obj)->od_scrub.os_scrub.os_obj_header)) {
1316 /* For the OI_scrub object during OSD device init. */
1317 l->lo_header->loh_attr |= LOHA_EXISTS;
1318 obj->oo_dt.do_body_ops = &osd_body_ops;
1320 obj->oo_dt.do_body_ops = &osd_body_ops_new;
1322 if (result == 0 && obj->oo_inode != NULL) {
1323 struct osd_thread_info *oti = osd_oti_get(env);
1324 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
1326 osd_object_init0(obj);
1327 result = osd_get_lma(oti, obj->oo_inode,
1328 &oti->oti_obj_dentry, loa);
1330 /* Convert LMAI flags to lustre LMA flags
1331 * and cache it to oo_lma_flags */
1333 lma_to_lustre_flags(loa->loa_lma.lma_incompat);
1334 } else if (result == -ENODATA) {
1339 LINVRNT(osd_invariant(obj));
1343 /* The first part of oxe_buf is xattr name, and is '\0' terminated.
1344 * The left part is for value, binary mode. */
1345 struct osd_xattr_entry {
1346 struct list_head oxe_list;
1350 struct rcu_head oxe_rcu;
1354 static int osd_oxc_get(struct osd_object *obj, const char *name,
1357 struct osd_xattr_entry *tmp;
1358 struct osd_xattr_entry *oxe = NULL;
1359 size_t namelen = strlen(name);
1364 list_for_each_entry_rcu(tmp, &obj->oo_xattr_list, oxe_list) {
1365 if (namelen == tmp->oxe_namelen &&
1366 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1373 GOTO(out, rc = -ENOENT);
1375 if (!oxe->oxe_exist)
1376 GOTO(out, rc = -ENODATA);
1379 rc = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1;
1382 if (buf->lb_buf == NULL)
1385 if (buf->lb_len < rc)
1386 GOTO(out, rc = -ERANGE);
1388 memcpy(buf->lb_buf, &oxe->oxe_buf[namelen + 1], rc);
1396 static void osd_oxc_free(struct rcu_head *head)
1398 struct osd_xattr_entry *oxe;
1400 oxe = container_of(head, struct osd_xattr_entry, oxe_rcu);
1401 OBD_FREE(oxe, oxe->oxe_len);
1404 static void osd_oxc_add(struct osd_object *obj, const char *name,
1405 const char *buf, int buflen)
1407 struct osd_xattr_entry *oxe;
1408 struct osd_xattr_entry *old = NULL;
1409 struct osd_xattr_entry *tmp;
1410 size_t namelen = strlen(name);
1411 size_t len = sizeof(*oxe) + namelen + 1 + buflen;
1413 OBD_ALLOC(oxe, len);
1417 INIT_LIST_HEAD(&oxe->oxe_list);
1419 oxe->oxe_namelen = namelen;
1420 memcpy(oxe->oxe_buf, name, namelen);
1422 LASSERT(buf != NULL);
1423 memcpy(oxe->oxe_buf + namelen + 1, buf, buflen);
1424 oxe->oxe_exist = true;
1426 oxe->oxe_exist = false;
1429 /* this should be rarely called, just remove old and add new */
1430 spin_lock(&obj->oo_guard);
1431 list_for_each_entry(tmp, &obj->oo_xattr_list, oxe_list) {
1432 if (namelen == tmp->oxe_namelen &&
1433 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1439 list_replace_rcu(&old->oxe_list, &oxe->oxe_list);
1440 call_rcu(&old->oxe_rcu, osd_oxc_free);
1442 list_add_tail_rcu(&oxe->oxe_list, &obj->oo_xattr_list);
1444 spin_unlock(&obj->oo_guard);
1447 static void osd_oxc_del(struct osd_object *obj, const char *name)
1449 struct osd_xattr_entry *oxe;
1450 size_t namelen = strlen(name);
1452 spin_lock(&obj->oo_guard);
1453 list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) {
1454 if (namelen == oxe->oxe_namelen &&
1455 strncmp(name, oxe->oxe_buf, namelen) == 0) {
1456 list_del_rcu(&oxe->oxe_list);
1457 call_rcu(&oxe->oxe_rcu, osd_oxc_free);
1461 spin_unlock(&obj->oo_guard);
1464 static void osd_oxc_fini(struct osd_object *obj)
1466 struct osd_xattr_entry *oxe, *next;
1468 list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) {
1469 list_del(&oxe->oxe_list);
1470 OBD_FREE(oxe, oxe->oxe_len);
1475 * Concurrency: no concurrent access is possible that late in object
1478 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
1480 struct osd_object *obj = osd_obj(l);
1481 struct lu_object_header *h = NULL;
1483 LINVRNT(osd_invariant(obj));
1485 if (unlikely(l->lo_header ==
1486 &osd_obj2dev(obj)->od_scrub.os_scrub.os_obj_header))
1490 dt_object_fini(&obj->oo_dt);
1491 if (obj->oo_hl_head != NULL)
1492 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1495 lu_object_header_fini(h);
1499 * Concurrency: no concurrent access is possible that late in object
1502 static void osd_index_fini(struct osd_object *o)
1504 struct iam_container *bag;
1506 if (o->oo_dir != NULL) {
1507 bag = &o->oo_dir->od_container;
1508 if (o->oo_inode != NULL) {
1509 if (bag->ic_object == o->oo_inode)
1510 iam_container_fini(bag);
1512 OBD_FREE_PTR(o->oo_dir);
1518 * Concurrency: no concurrent access is possible that late in object
1519 * life-cycle (for all existing callers, that is. New callers have to provide
1520 * their own locking.)
1522 static int osd_inode_unlinked(const struct inode *inode)
1524 return inode->i_nlink == 0;
1528 OSD_TXN_OI_DELETE_CREDITS = 20,
1529 OSD_TXN_INODE_DELETE_CREDITS = 20
1536 #if OSD_THANDLE_STATS
1538 * Set time when the handle is allocated
1540 static void osd_th_alloced(struct osd_thandle *oth)
1542 oth->oth_alloced = ktime_get();
1546 * Set time when the handle started
1548 static void osd_th_started(struct osd_thandle *oth)
1550 oth->oth_started = ktime_get();
1554 * Check whether the we deal with this handle for too long.
1556 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
1557 ktime_t alloced, ktime_t started,
1560 ktime_t now = ktime_get();
1562 LASSERT(dev != NULL);
1564 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
1565 ktime_us_delta(started, alloced));
1566 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
1567 ktime_us_delta(closed, started));
1568 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
1569 ktime_us_delta(now, closed));
1571 if (ktime_before(ktime_add_ns(alloced, 30 * NSEC_PER_SEC), now)) {
1572 CWARN("transaction handle %p was open for too long: now %lld, alloced %lld, started %lld, closed %lld\n",
1573 oth, now, alloced, started, closed);
1574 libcfs_debug_dumpstack(NULL);
1578 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
1580 ktime_t __closed = ktime_get(); \
1581 ktime_t __alloced = oth->oth_alloced; \
1582 ktime_t __started = oth->oth_started; \
1585 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
1588 #else /* OSD_THANDLE_STATS */
1590 #define osd_th_alloced(h) do {} while(0)
1591 #define osd_th_started(h) do {} while(0)
1592 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
1594 #endif /* OSD_THANDLE_STATS */
1597 * Concurrency: doesn't access mutable data.
1599 static int osd_param_is_not_sane(const struct osd_device *dev,
1600 const struct thandle *th)
1602 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
1604 return oh->ot_credits > osd_transaction_size(dev);
1608 * Concurrency: shouldn't matter.
1610 static void osd_trans_commit_cb(struct super_block *sb,
1611 struct ldiskfs_journal_cb_entry *jcb, int error)
1613 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
1614 struct thandle *th = &oh->ot_super;
1615 struct lu_device *lud = &th->th_dev->dd_lu_dev;
1616 struct dt_txn_commit_cb *dcb, *tmp;
1618 LASSERT(oh->ot_handle == NULL);
1621 CERROR("transaction @0x%p commit error: %d\n", th, error);
1623 dt_txn_hook_commit(th);
1625 /* call per-transaction callbacks if any */
1626 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
1628 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1629 "commit callback entry: magic=%x name='%s'\n",
1630 dcb->dcb_magic, dcb->dcb_name);
1631 list_del_init(&dcb->dcb_linkage);
1632 dcb->dcb_func(NULL, th, dcb, error);
1635 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
1642 #ifndef HAVE_SB_START_WRITE
1643 # define sb_start_write(sb) do {} while (0)
1644 # define sb_end_write(sb) do {} while (0)
1647 static struct thandle *osd_trans_create(const struct lu_env *env,
1648 struct dt_device *d)
1650 struct osd_thread_info *oti = osd_oti_get(env);
1651 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1652 struct osd_thandle *oh;
1657 CERROR("%s: someone try to start transaction under "
1658 "readonly mode, should be disabled.\n",
1659 osd_name(osd_dt_dev(d)));
1661 RETURN(ERR_PTR(-EROFS));
1664 /* on pending IO in this thread should left from prev. request */
1665 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
1667 sb_start_write(osd_sb(osd_dt_dev(d)));
1669 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
1671 oh->ot_quota_trans = &oti->oti_quota_trans;
1672 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
1677 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
1678 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
1681 memset(oti->oti_declare_ops, 0,
1682 sizeof(oti->oti_declare_ops));
1683 memset(oti->oti_declare_ops_cred, 0,
1684 sizeof(oti->oti_declare_ops_cred));
1685 memset(oti->oti_declare_ops_used, 0,
1686 sizeof(oti->oti_declare_ops_used));
1688 sb_end_write(osd_sb(osd_dt_dev(d)));
1689 th = ERR_PTR(-ENOMEM);
1694 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
1696 struct osd_thread_info *oti = osd_oti_get(env);
1697 struct osd_thandle *oh;
1699 oh = container_of0(th, struct osd_thandle, ot_super);
1700 LASSERT(oh != NULL);
1702 CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n",
1703 oti->oti_declare_ops[OSD_OT_CREATE],
1704 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1705 oti->oti_declare_ops_used[OSD_OT_CREATE],
1706 oti->oti_declare_ops[OSD_OT_DESTROY],
1707 oti->oti_declare_ops_cred[OSD_OT_DESTROY],
1708 oti->oti_declare_ops_used[OSD_OT_DESTROY]);
1709 CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
1710 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1711 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1712 oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
1713 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1714 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
1715 oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
1716 CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
1717 oti->oti_declare_ops[OSD_OT_WRITE],
1718 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1719 oti->oti_declare_ops_used[OSD_OT_WRITE],
1720 oti->oti_declare_ops[OSD_OT_PUNCH],
1721 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1722 oti->oti_declare_ops_used[OSD_OT_PUNCH],
1723 oti->oti_declare_ops[OSD_OT_QUOTA],
1724 oti->oti_declare_ops_cred[OSD_OT_QUOTA],
1725 oti->oti_declare_ops_used[OSD_OT_QUOTA]);
1726 CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n",
1727 oti->oti_declare_ops[OSD_OT_INSERT],
1728 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1729 oti->oti_declare_ops_used[OSD_OT_INSERT],
1730 oti->oti_declare_ops[OSD_OT_DELETE],
1731 oti->oti_declare_ops_cred[OSD_OT_DELETE],
1732 oti->oti_declare_ops_used[OSD_OT_DELETE]);
1733 CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
1734 oti->oti_declare_ops[OSD_OT_REF_ADD],
1735 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1736 oti->oti_declare_ops_used[OSD_OT_REF_ADD],
1737 oti->oti_declare_ops[OSD_OT_REF_DEL],
1738 oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
1739 oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
1743 * Concurrency: shouldn't matter.
1745 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1748 struct osd_thread_info *oti = osd_oti_get(env);
1749 struct osd_device *dev = osd_dt_dev(d);
1751 struct osd_thandle *oh;
1756 LASSERT(current->journal_info == NULL);
1758 oh = container_of0(th, struct osd_thandle, ot_super);
1759 LASSERT(oh != NULL);
1760 LASSERT(oh->ot_handle == NULL);
1762 rc = dt_txn_hook_start(env, d, th);
1766 if (unlikely(osd_param_is_not_sane(dev, th))) {
1767 static unsigned long last_printed;
1768 static int last_credits;
1770 /* don't make noise on a tiny testing systems
1771 * actual credits misuse will be caught anyway */
1772 if (last_credits != oh->ot_credits &&
1773 time_after(jiffies, last_printed +
1774 msecs_to_jiffies(60 * MSEC_PER_SEC)) &&
1775 osd_transaction_size(dev) > 512) {
1776 CWARN("%s: credits %u > trans_max %u\n", osd_name(dev),
1777 oh->ot_credits, osd_transaction_size(dev));
1778 osd_trans_dump_creds(env, th);
1779 libcfs_debug_dumpstack(NULL);
1780 last_credits = oh->ot_credits;
1781 last_printed = jiffies;
1783 /* XXX Limit the credits to 'max_transaction_buffers', and
1784 * let the underlying filesystem to catch the error if
1785 * we really need so many credits.
1787 * This should be removed when we can calculate the
1788 * credits precisely. */
1789 oh->ot_credits = osd_transaction_size(dev);
1790 } else if (ldiskfs_track_declares_assert != 0) {
1791 /* reserve few credits to prevent an assertion in JBD
1792 * our debugging mechanism will be able to detected
1793 * overuse. this can help to debug single-update
1795 oh->ot_credits += 10;
1796 if (unlikely(osd_param_is_not_sane(dev, th)))
1797 oh->ot_credits = osd_transaction_size(dev);
1801 * XXX temporary stuff. Some abstraction layer should
1804 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1808 LASSERT(oti->oti_txns == 0);
1810 lu_device_get(&d->dd_lu_dev);
1811 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1822 static int osd_seq_exists(const struct lu_env *env,
1823 struct osd_device *osd, u64 seq)
1825 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1826 struct seq_server_site *ss = osd_seq_site(osd);
1830 LASSERT(ss != NULL);
1831 LASSERT(ss->ss_server_fld != NULL);
1833 rc = osd_fld_lookup(env, osd, seq, range);
1836 CERROR("%s: can't lookup FLD sequence %#llx: rc = %d\n",
1837 osd_name(osd), seq, rc);
1841 RETURN(ss->ss_node_id == range->lsr_index);
1844 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
1846 struct dt_txn_commit_cb *dcb;
1847 struct dt_txn_commit_cb *tmp;
1849 /* call per-transaction stop callbacks if any */
1850 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
1852 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1853 "commit callback entry: magic=%x name='%s'\n",
1854 dcb->dcb_magic, dcb->dcb_name);
1855 list_del_init(&dcb->dcb_linkage);
1856 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
1861 * Concurrency: shouldn't matter.
1863 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1866 int rc = 0, remove_agents = 0;
1867 struct osd_thandle *oh;
1868 struct osd_thread_info *oti = osd_oti_get(env);
1869 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1870 struct osd_device *osd = osd_dt_dev(th->th_dev);
1871 struct qsd_instance *qsd = osd->od_quota_slave;
1872 struct lquota_trans *qtrans;
1875 oh = container_of0(th, struct osd_thandle, ot_super);
1877 /* reset OI cache for safety */
1878 oti->oti_ins_cache_used = 0;
1880 remove_agents = oh->ot_remove_agents;
1882 qtrans = oh->ot_quota_trans;
1883 oh->ot_quota_trans = NULL;
1885 if (oh->ot_handle != NULL) {
1887 handle_t *hdl = oh->ot_handle;
1890 * add commit callback
1891 * notice we don't do this in osd_trans_start()
1892 * as underlying transaction can change during truncate
1894 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1897 LASSERT(oti->oti_txns == 1);
1900 rc = dt_txn_hook_stop(env, th);
1902 CERROR("%s: failed in transaction hook: rc = %d\n",
1905 osd_trans_stop_cb(oh, rc);
1906 /* hook functions might modify th_sync */
1907 hdl->h_sync = th->th_sync;
1909 oh->ot_handle = NULL;
1910 OSD_CHECK_SLOW_TH(oh, osd, rc2 = ldiskfs_journal_stop(hdl));
1912 CERROR("%s: failed to stop transaction: rc = %d\n",
1913 osd_name(osd), rc2);
1917 osd_trans_stop_cb(oh, th->th_result);
1921 /* inform the quota slave device that the transaction is stopping */
1922 qsd_op_end(env, qsd, qtrans);
1924 /* as we want IO to journal and data IO be concurrent, we don't block
1925 * awaiting data IO completion in osd_do_bio(), instead we wait here
1926 * once transaction is submitted to the journal. all reqular requests
1927 * don't do direct IO (except read/write), thus this wait_event becomes
1930 * IMPORTANT: we have to wait till any IO submited by the thread is
1931 * completed otherwise iobuf may be corrupted by different request
1933 wait_event(iobuf->dr_wait,
1934 atomic_read(&iobuf->dr_numreqs) == 0);
1935 osd_fini_iobuf(osd, iobuf);
1937 rc = iobuf->dr_error;
1939 if (unlikely(remove_agents != 0))
1940 osd_process_scheduled_agent_removals(env, osd);
1942 sb_end_write(osd_sb(osd));
1947 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1949 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1952 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1953 LASSERT(&dcb->dcb_func != NULL);
1954 if (dcb->dcb_flags & DCB_TRANS_STOP)
1955 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
1957 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
1963 * Called just before object is freed. Releases all resources except for
1964 * object itself (that is released by osd_object_free()).
1966 * Concurrency: no concurrent access is possible that late in object
1969 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1971 struct osd_object *obj = osd_obj(l);
1972 struct inode *inode = obj->oo_inode;
1974 LINVRNT(osd_invariant(obj));
1977 * If object is unlinked remove fid->ino mapping from object index.
1980 osd_index_fini(obj);
1981 if (inode != NULL) {
1982 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1983 qid_t uid = i_uid_read(inode);
1984 qid_t gid = i_gid_read(inode);
1987 obj->oo_inode = NULL;
1990 struct osd_thread_info *info = osd_oti_get(env);
1991 struct lquota_id_info *qi = &info->oti_qi;
1993 /* Release granted quota to master if necessary */
1994 qi->lqi_id.qid_uid = uid;
1995 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1997 qi->lqi_id.qid_uid = gid;
1998 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
2000 qi->lqi_id.qid_uid = i_projid_read(inode);
2001 qsd_op_adjust(env, qsd, &qi->lqi_id, PRJQUOTA);
2007 * Concurrency: ->loo_object_release() is called under site spin-lock.
2009 static void osd_object_release(const struct lu_env *env,
2010 struct lu_object *l)
2012 struct osd_object *o = osd_obj(l);
2013 /* nobody should be releasing a non-destroyed object with nlink=0
2014 * the API allows this, but ldiskfs doesn't like and then report
2015 * this inode as deleted */
2016 if (unlikely(!o->oo_destroyed && o->oo_inode && o->oo_inode->i_nlink == 0))
2021 * Concurrency: shouldn't matter.
2023 static int osd_object_print(const struct lu_env *env, void *cookie,
2024 lu_printer_t p, const struct lu_object *l)
2026 struct osd_object *o = osd_obj(l);
2027 struct iam_descr *d;
2029 if (o->oo_dir != NULL)
2030 d = o->oo_dir->od_container.ic_descr;
2033 return (*p)(env, cookie,
2034 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
2036 o->oo_inode ? o->oo_inode->i_ino : 0UL,
2037 o->oo_inode ? o->oo_inode->i_generation : 0,
2038 d ? d->id_ops->id_name : "plain");
2042 * Concurrency: shouldn't matter.
2044 int osd_statfs(const struct lu_env *env, struct dt_device *d,
2045 struct obd_statfs *sfs)
2047 struct osd_device *osd = osd_dt_dev(d);
2048 struct super_block *sb = osd_sb(osd);
2049 struct kstatfs *ksfs;
2053 if (unlikely(osd->od_mnt == NULL))
2054 return -EINPROGRESS;
2056 /* osd_lproc.c call this without env, allocate ksfs for that case */
2057 if (unlikely(env == NULL)) {
2058 OBD_ALLOC_PTR(ksfs);
2062 ksfs = &osd_oti_get(env)->oti_ksfs;
2065 result = sb->s_op->statfs(sb->s_root, ksfs);
2069 statfs_pack(sfs, ksfs);
2070 if (unlikely(sb->s_flags & MS_RDONLY))
2071 sfs->os_state |= OS_STATE_READONLY;
2072 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb,
2073 LDISKFS_FEATURE_INCOMPAT_EXTENTS))
2074 sfs->os_maxbytes = sb->s_maxbytes;
2076 sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2079 * Reserve some space so to avoid fragmenting the filesystem too much.
2080 * Fragmentation not only impacts performance, but can also increase
2081 * metadata overhead significantly, causing grant calculation to be
2084 * Reserve 0.78% of total space, at least 8MB for small filesystems.
2086 CLASSERT(OSD_STATFS_RESERVED > LDISKFS_MAX_BLOCK_SIZE);
2087 reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits;
2088 if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT))
2089 reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT;
2091 sfs->os_blocks -= reserved;
2092 sfs->os_bfree -= min(reserved, sfs->os_bfree);
2093 sfs->os_bavail -= min(reserved, sfs->os_bavail);
2096 if (unlikely(env == NULL))
2102 * Estimate space needed for file creations. We assume the largest filename
2103 * which is 2^64 - 1, hence a filename of 20 chars.
2104 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
2106 #ifdef __LDISKFS_DIR_REC_LEN
2107 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
2109 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
2113 * Concurrency: doesn't access mutable data.
2115 static void osd_conf_get(const struct lu_env *env,
2116 const struct dt_device *dev,
2117 struct dt_device_param *param)
2119 struct super_block *sb = osd_sb(osd_dt_dev(dev));
2123 * XXX should be taken from not-yet-existing fs abstraction layer.
2125 param->ddp_max_name_len = LDISKFS_NAME_LEN;
2126 param->ddp_max_nlink = LDISKFS_LINK_MAX;
2127 param->ddp_symlink_max = sb->s_blocksize;
2128 param->ddp_mount_type = LDD_MT_LDISKFS;
2129 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS))
2130 param->ddp_maxbytes = sb->s_maxbytes;
2132 param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2133 /* inode are statically allocated, so per-inode space consumption
2134 * is the space consumed by the directory entry */
2135 param->ddp_inodespace = PER_OBJ_USAGE;
2136 /* EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks
2137 * = 128MB) which is unlikely to be hit in real life. Report a smaller
2138 * maximum length to not under count the actual number of extents
2139 * needed for writing a file. */
2140 param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 2;
2141 /* worst-case extent insertion metadata overhead */
2142 param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb);
2143 param->ddp_mntopts = 0;
2144 if (test_opt(sb, XATTR_USER))
2145 param->ddp_mntopts |= MNTOPT_USERXATTR;
2146 if (test_opt(sb, POSIX_ACL))
2147 param->ddp_mntopts |= MNTOPT_ACL;
2149 /* LOD might calculate the max stripe count based on max_ea_size,
2150 * so we need take account in the overhead as well,
2151 * xattr_header + magic + xattr_entry_head */
2152 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
2153 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
2155 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
2156 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
2157 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
2161 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
2165 * Concurrency: shouldn't matter.
2167 static int osd_sync(const struct lu_env *env, struct dt_device *d)
2171 CDEBUG(D_CACHE, "%s: syncing OSD\n", osd_dt_dev(d)->od_svname);
2173 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
2175 CDEBUG(D_CACHE, "%s: synced OSD: rc = %d\n", osd_dt_dev(d)->od_svname,
2182 * Start commit for OSD device.
2184 * An implementation of dt_commit_async method for OSD device.
2185 * Asychronously starts underlayng fs sync and thereby a transaction
2188 * \param env environment
2189 * \param d dt device
2191 * \see dt_device_operations
2193 static int osd_commit_async(const struct lu_env *env,
2194 struct dt_device *d)
2196 struct super_block *s = osd_sb(osd_dt_dev(d));
2199 CDEBUG(D_HA, "%s: async commit OSD\n", osd_dt_dev(d)->od_svname);
2200 RETURN(s->s_op->sync_fs(s, 0));
2203 /* Our own copy of the set readonly functions if present, or NU if not. */
2204 static int (*priv_dev_set_rdonly)(struct block_device *bdev);
2205 static int (*priv_dev_check_rdonly)(struct block_device *bdev);
2206 /* static int (*priv_dev_clear_rdonly)(struct block_device *bdev); */
2209 * Concurrency: shouldn't matter.
2211 static int osd_ro(const struct lu_env *env, struct dt_device *d)
2213 struct super_block *sb = osd_sb(osd_dt_dev(d));
2214 struct block_device *dev = sb->s_bdev;
2215 int rc = -EOPNOTSUPP;
2218 if (priv_dev_set_rdonly) {
2219 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
2222 CERROR("*** setting %s read-only ***\n",
2223 osd_dt_dev(d)->od_svname);
2225 if (sb->s_op->freeze_fs) {
2226 rc = sb->s_op->freeze_fs(sb);
2231 if (jdev && (jdev != dev)) {
2232 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
2234 priv_dev_set_rdonly(jdev);
2236 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
2237 priv_dev_set_rdonly(dev);
2239 if (sb->s_op->unfreeze_fs)
2240 sb->s_op->unfreeze_fs(sb);
2245 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
2246 osd_dt_dev(d)->od_svname, (long)dev, rc);
2252 * Note: we do not count into QUOTA here.
2253 * If we mount with --data_journal we may need more.
2255 const int osd_dto_credits_noquota[DTO_NR] = {
2258 * INDEX_EXTRA_TRANS_BLOCKS(8) +
2259 * SINGLEDATA_TRANS_BLOCKS(8)
2260 * XXX Note: maybe iam need more, since iam have more level than
2263 [DTO_INDEX_INSERT] = 16,
2266 * just modify a single entry, probably merge few within a block
2268 [DTO_INDEX_DELETE] = 1,
2272 [DTO_INDEX_UPDATE] = 16,
2274 * 4(inode, inode bits, groups, GDT)
2275 * notice: OI updates are counted separately with DTO_INDEX_INSERT
2277 [DTO_OBJECT_CREATE] = 4,
2279 * 4(inode, inode bits, groups, GDT)
2280 * notice: OI updates are counted separately with DTO_INDEX_DELETE
2282 [DTO_OBJECT_DELETE] = 4,
2284 * Attr set credits (inode)
2286 [DTO_ATTR_SET_BASE] = 1,
2288 * Xattr set. The same as xattr of EXT3.
2289 * DATA_TRANS_BLOCKS(14)
2290 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
2291 * are also counted in. Do not know why?
2293 [DTO_XATTR_SET] = 14,
2295 * credits for inode change during write.
2297 [DTO_WRITE_BASE] = 3,
2299 * credits for single block write.
2301 [DTO_WRITE_BLOCK] = 14,
2303 * Attr set credits for chown.
2304 * This is extra credits for setattr, and it is null without quota
2306 [DTO_ATTR_SET_CHOWN] = 0
2309 static const struct dt_device_operations osd_dt_ops = {
2310 .dt_root_get = osd_root_get,
2311 .dt_statfs = osd_statfs,
2312 .dt_trans_create = osd_trans_create,
2313 .dt_trans_start = osd_trans_start,
2314 .dt_trans_stop = osd_trans_stop,
2315 .dt_trans_cb_add = osd_trans_cb_add,
2316 .dt_conf_get = osd_conf_get,
2317 .dt_sync = osd_sync,
2319 .dt_commit_async = osd_commit_async,
2322 static void osd_read_lock(const struct lu_env *env, struct dt_object *dt,
2325 struct osd_object *obj = osd_dt_obj(dt);
2326 struct osd_thread_info *oti = osd_oti_get(env);
2328 LINVRNT(osd_invariant(obj));
2330 LASSERT(obj->oo_owner != env);
2331 down_read_nested(&obj->oo_sem, role);
2333 LASSERT(obj->oo_owner == NULL);
2337 static void osd_write_lock(const struct lu_env *env, struct dt_object *dt,
2340 struct osd_object *obj = osd_dt_obj(dt);
2341 struct osd_thread_info *oti = osd_oti_get(env);
2343 LINVRNT(osd_invariant(obj));
2345 LASSERT(obj->oo_owner != env);
2346 down_write_nested(&obj->oo_sem, role);
2348 LASSERT(obj->oo_owner == NULL);
2349 obj->oo_owner = env;
2353 static void osd_read_unlock(const struct lu_env *env, struct dt_object *dt)
2355 struct osd_object *obj = osd_dt_obj(dt);
2356 struct osd_thread_info *oti = osd_oti_get(env);
2358 LINVRNT(osd_invariant(obj));
2360 LASSERT(oti->oti_r_locks > 0);
2362 up_read(&obj->oo_sem);
2365 static void osd_write_unlock(const struct lu_env *env, struct dt_object *dt)
2367 struct osd_object *obj = osd_dt_obj(dt);
2368 struct osd_thread_info *oti = osd_oti_get(env);
2370 LINVRNT(osd_invariant(obj));
2372 LASSERT(obj->oo_owner == env);
2373 LASSERT(oti->oti_w_locks > 0);
2375 obj->oo_owner = NULL;
2376 up_write(&obj->oo_sem);
2379 static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
2381 struct osd_object *obj = osd_dt_obj(dt);
2383 LINVRNT(osd_invariant(obj));
2385 return obj->oo_owner == env;
2388 static struct timespec *osd_inode_time(const struct lu_env *env,
2389 struct inode *inode, __u64 seconds)
2391 struct osd_thread_info *oti = osd_oti_get(env);
2392 struct timespec *t = &oti->oti_time;
2394 t->tv_sec = seconds;
2396 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
2400 static void osd_inode_getattr(const struct lu_env *env,
2401 struct inode *inode, struct lu_attr *attr)
2403 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2404 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2405 LA_PROJID | LA_FLAGS | LA_NLINK | LA_RDEV |
2406 LA_BLKSIZE | LA_TYPE;
2408 attr->la_atime = LTIME_S(inode->i_atime);
2409 attr->la_mtime = LTIME_S(inode->i_mtime);
2410 attr->la_ctime = LTIME_S(inode->i_ctime);
2411 attr->la_mode = inode->i_mode;
2412 attr->la_size = i_size_read(inode);
2413 attr->la_blocks = inode->i_blocks;
2414 attr->la_uid = i_uid_read(inode);
2415 attr->la_gid = i_gid_read(inode);
2416 attr->la_projid = i_projid_read(inode);
2417 attr->la_flags = ll_inode_to_ext_flags(inode->i_flags);
2418 attr->la_nlink = inode->i_nlink;
2419 attr->la_rdev = inode->i_rdev;
2420 attr->la_blksize = 1 << inode->i_blkbits;
2421 attr->la_blkbits = inode->i_blkbits;
2423 * Ext4 did not transfer inherit flags from raw inode
2424 * to inode flags, and ext4 internally test raw inode
2425 * @i_flags directly. Instead of patching ext4, we do it here.
2427 if (LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL)
2428 attr->la_flags |= LUSTRE_PROJINHERIT_FL;
2431 static int osd_attr_get(const struct lu_env *env,
2432 struct dt_object *dt,
2433 struct lu_attr *attr)
2435 struct osd_object *obj = osd_dt_obj(dt);
2437 if (unlikely(!dt_object_exists(dt)))
2439 if (unlikely(obj->oo_destroyed))
2442 LASSERT(!dt_object_remote(dt));
2443 LINVRNT(osd_invariant(obj));
2445 spin_lock(&obj->oo_guard);
2446 osd_inode_getattr(env, obj->oo_inode, attr);
2447 if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL)
2448 attr->la_flags |= LUSTRE_ORPHAN_FL;
2449 spin_unlock(&obj->oo_guard);
2454 static int osd_declare_attr_qid(const struct lu_env *env,
2455 struct osd_object *obj,
2456 struct osd_thandle *oh, long long bspace,
2457 qid_t old_id, qid_t new_id, bool enforce,
2461 struct osd_thread_info *info = osd_oti_get(env);
2462 struct lquota_id_info *qi = &info->oti_qi;
2464 qi->lqi_type = type;
2465 /* inode accounting */
2466 qi->lqi_is_blk = false;
2468 /* one more inode for the new id ... */
2469 qi->lqi_id.qid_uid = new_id;
2471 /* Reserve credits for the new id */
2472 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2473 if (rc == -EDQUOT || rc == -EINPROGRESS)
2478 /* and one less inode for the current id */
2479 qi->lqi_id.qid_uid = old_id;
2481 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2482 if (rc == -EDQUOT || rc == -EINPROGRESS)
2487 /* block accounting */
2488 qi->lqi_is_blk = true;
2490 /* more blocks for the new id ... */
2491 qi->lqi_id.qid_uid = new_id;
2492 qi->lqi_space = bspace;
2494 * Credits for the new uid has been reserved, re-use "obj"
2495 * to save credit reservation.
2497 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2498 if (rc == -EDQUOT || rc == -EINPROGRESS)
2503 /* and finally less blocks for the current uid */
2504 qi->lqi_id.qid_uid = old_id;
2505 qi->lqi_space = -bspace;
2506 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2507 if (rc == -EDQUOT || rc == -EINPROGRESS)
2513 static int osd_declare_attr_set(const struct lu_env *env,
2514 struct dt_object *dt,
2515 const struct lu_attr *attr,
2516 struct thandle *handle)
2518 struct osd_thandle *oh;
2519 struct osd_object *obj;
2527 LASSERT(dt != NULL);
2528 LASSERT(handle != NULL);
2530 obj = osd_dt_obj(dt);
2531 LASSERT(osd_invariant(obj));
2533 oh = container_of0(handle, struct osd_thandle, ot_super);
2534 LASSERT(oh->ot_handle == NULL);
2536 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
2537 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2539 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2540 osd_dto_credits_noquota[DTO_XATTR_SET]);
2542 if (attr == NULL || obj->oo_inode == NULL)
2545 bspace = obj->oo_inode->i_blocks;
2546 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
2547 bspace = toqb(bspace);
2549 /* Changing ownership is always preformed by super user, it should not
2552 * We still need to call the osd_declare_qid() to calculate the journal
2553 * credits for updating quota accounting files and to trigger quota
2554 * space adjustment once the operation is completed.*/
2555 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
2557 uid = i_uid_read(obj->oo_inode);
2558 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
2559 rc = osd_declare_attr_qid(env, obj, oh, bspace, uid,
2560 attr->la_uid, enforce, USRQUOTA);
2564 gid = i_gid_read(obj->oo_inode);
2565 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
2566 rc = osd_declare_attr_qid(env, obj, oh, bspace,
2567 i_gid_read(obj->oo_inode),
2568 attr->la_gid, enforce, GRPQUOTA);
2573 #ifdef HAVE_PROJECT_QUOTA
2574 if (attr->la_valid & LA_PROJID) {
2575 __u32 projid = i_projid_read(obj->oo_inode);
2576 enforce = (attr->la_valid & LA_PROJID) &&
2577 (attr->la_projid != projid);
2578 rc = osd_declare_attr_qid(env, obj, oh, bspace,
2579 (qid_t)projid, (qid_t)attr->la_projid,
2588 static int osd_inode_setattr(const struct lu_env *env,
2589 struct inode *inode, const struct lu_attr *attr)
2591 __u64 bits = attr->la_valid;
2593 /* Only allow set size for regular file */
2594 if (!S_ISREG(inode->i_mode))
2595 bits &= ~(LA_SIZE | LA_BLOCKS);
2600 if (bits & LA_ATIME)
2601 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
2602 if (bits & LA_CTIME)
2603 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
2604 if (bits & LA_MTIME)
2605 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
2606 if (bits & LA_SIZE) {
2607 spin_lock(&inode->i_lock);
2608 LDISKFS_I(inode)->i_disksize = attr->la_size;
2609 i_size_write(inode, attr->la_size);
2610 spin_unlock(&inode->i_lock);
2613 /* OSD should not change "i_blocks" which is used by quota.
2614 * "i_blocks" should be changed by ldiskfs only. */
2616 inode->i_mode = (inode->i_mode & S_IFMT) |
2617 (attr->la_mode & ~S_IFMT);
2619 i_uid_write(inode, attr->la_uid);
2621 i_gid_write(inode, attr->la_gid);
2622 if (bits & LA_PROJID)
2623 i_projid_write(inode, attr->la_projid);
2624 if (bits & LA_NLINK)
2625 set_nlink(inode, attr->la_nlink);
2627 inode->i_rdev = attr->la_rdev;
2629 if (bits & LA_FLAGS) {
2630 /* always keep S_NOCMTIME */
2631 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
2634 * Ext4 did not transfer inherit flags from
2635 * @inode->i_flags to raw inode i_flags when writing
2636 * flags, we do it explictly here.
2638 if (attr->la_flags & LUSTRE_PROJINHERIT_FL)
2639 LDISKFS_I(inode)->i_flags |= LUSTRE_PROJINHERIT_FL;
2641 LDISKFS_I(inode)->i_flags &= ~LUSTRE_PROJINHERIT_FL;
2646 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
2650 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
2651 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
2654 ll_vfs_dq_init(inode);
2656 if (attr->la_valid & LA_UID)
2657 iattr.ia_valid |= ATTR_UID;
2658 if (attr->la_valid & LA_GID)
2659 iattr.ia_valid |= ATTR_GID;
2660 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
2661 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
2663 rc = ll_vfs_dq_transfer(inode, &iattr);
2665 CERROR("%s: quota transfer failed: rc = %d. Is quota "
2666 "enforcement enabled on the ldiskfs "
2667 "filesystem?\n", inode->i_sb->s_id, rc);
2672 /* Handle project id transfer here properly */
2673 if (attr->la_valid & LA_PROJID &&
2674 attr->la_projid != i_projid_read(inode)) {
2675 #ifdef HAVE_PROJECT_QUOTA
2676 rc = ldiskfs_transfer_project(inode, attr->la_projid);
2681 CERROR("%s: quota transfer failed: rc = %d. Is project "
2682 "enforcement enabled on the ldiskfs "
2683 "filesystem?\n", inode->i_sb->s_id, rc);
2690 static int osd_attr_set(const struct lu_env *env,
2691 struct dt_object *dt,
2692 const struct lu_attr *attr,
2693 struct thandle *handle)
2695 struct osd_object *obj = osd_dt_obj(dt);
2696 struct inode *inode;
2699 if (!dt_object_exists(dt))
2702 LASSERT(handle != NULL);
2703 LASSERT(!dt_object_remote(dt));
2704 LASSERT(osd_invariant(obj));
2706 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
2708 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING) &&
2709 !osd_obj2dev(obj)->od_is_ost) {
2710 struct osd_thread_info *oti = osd_oti_get(env);
2711 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
2712 struct lu_fid *fid1 = &oti->oti_fid;
2713 struct osd_inode_id *id = &oti->oti_id;
2714 struct iam_path_descr *ipd;
2715 struct iam_container *bag;
2716 struct osd_thandle *oh;
2719 fid_cpu_to_be(fid1, fid0);
2720 memset(id, 1, sizeof(*id));
2721 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
2722 fid0)->oi_dir.od_container;
2723 ipd = osd_idx_ipd_get(env, bag);
2724 if (unlikely(ipd == NULL))
2727 oh = container_of0(handle, struct osd_thandle, ot_super);
2728 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
2729 (const struct iam_rec *)id, ipd);
2730 osd_ipd_put(env, bag, ipd);
2731 return(rc > 0 ? 0 : rc);
2734 inode = obj->oo_inode;
2736 rc = osd_quota_transfer(inode, attr);
2740 spin_lock(&obj->oo_guard);
2741 rc = osd_inode_setattr(env, inode, attr);
2742 spin_unlock(&obj->oo_guard);
2746 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2748 if (!(attr->la_valid & LA_FLAGS))
2751 /* Let's check if there are extra flags need to be set into LMA */
2752 if (attr->la_flags & LUSTRE_LMA_FL_MASKS) {
2753 struct osd_thread_info *info = osd_oti_get(env);
2754 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
2756 LASSERT(!obj->oo_pfid_in_lma);
2758 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
2759 &info->oti_ost_attrs);
2763 lma->lma_incompat |=
2764 lustre_to_lma_flags(attr->la_flags);
2765 lustre_lma_swab(lma);
2766 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA,
2767 lma, sizeof(*lma), XATTR_REPLACE);
2769 struct osd_device *osd = osd_obj2dev(obj);
2771 CWARN("%s: set "DFID" lma flags %u failed: rc = %d\n",
2772 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)),
2773 lma->lma_incompat, rc);
2776 attr->la_flags & LUSTRE_LMA_FL_MASKS;
2778 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
2781 osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
2786 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
2787 struct osd_object *obj,
2788 const char *name, const int namelen)
2790 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
2793 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
2794 umode_t mode, struct dt_allocation_hint *hint,
2798 struct osd_device *osd = osd_obj2dev(obj);
2799 struct osd_thandle *oth;
2800 struct dt_object *parent = NULL;
2801 struct inode *inode;
2803 LINVRNT(osd_invariant(obj));
2804 LASSERT(obj->oo_inode == NULL);
2805 LASSERT(obj->oo_hl_head == NULL);
2807 if (S_ISDIR(mode) && ldiskfs_pdo) {
2808 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
2809 if (obj->oo_hl_head == NULL)
2813 oth = container_of(th, struct osd_thandle, ot_super);
2814 LASSERT(oth->ot_handle->h_transaction != NULL);
2816 if (hint != NULL && hint->dah_parent != NULL &&
2817 !dt_object_remote(hint->dah_parent))
2818 parent = hint->dah_parent;
2820 inode = ldiskfs_create_inode(oth->ot_handle,
2821 parent ? osd_dt_obj(parent)->oo_inode :
2822 osd_sb(osd)->s_root->d_inode,
2824 if (!IS_ERR(inode)) {
2825 /* Do not update file c/mtime in ldiskfs. */
2826 inode->i_flags |= S_NOCMTIME;
2828 /* For new created object, it must be consistent,
2829 * and it is unnecessary to scrub against it. */
2830 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
2832 obj->oo_inode = inode;
2835 if (obj->oo_hl_head != NULL) {
2836 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
2837 obj->oo_hl_head = NULL;
2839 result = PTR_ERR(inode);
2841 LINVRNT(osd_invariant(obj));
2849 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
2850 struct lu_attr *attr,
2851 struct dt_allocation_hint *hint,
2852 struct dt_object_format *dof,
2856 struct osd_thandle *oth;
2857 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX | S_ISGID));
2859 LASSERT(S_ISDIR(attr->la_mode));
2861 oth = container_of(th, struct osd_thandle, ot_super);
2862 LASSERT(oth->ot_handle->h_transaction != NULL);
2863 result = osd_mkfile(info, obj, mode, hint, th);
2868 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
2869 struct lu_attr *attr,
2870 struct dt_allocation_hint *hint,
2871 struct dt_object_format *dof,
2875 struct osd_thandle *oth;
2876 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
2878 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
2880 LASSERT(S_ISREG(attr->la_mode));
2882 oth = container_of(th, struct osd_thandle, ot_super);
2883 LASSERT(oth->ot_handle->h_transaction != NULL);
2885 result = osd_mkfile(info, obj, mode, hint, th);
2887 LASSERT(obj->oo_inode != NULL);
2888 if (feat->dif_flags & DT_IND_VARKEY)
2889 result = iam_lvar_create(obj->oo_inode,
2890 feat->dif_keysize_max,
2892 feat->dif_recsize_max,
2895 result = iam_lfix_create(obj->oo_inode,
2896 feat->dif_keysize_max,
2898 feat->dif_recsize_max,
2905 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
2906 struct lu_attr *attr,
2907 struct dt_allocation_hint *hint,
2908 struct dt_object_format *dof,
2911 LASSERT(S_ISREG(attr->la_mode));
2912 return osd_mkfile(info, obj, (attr->la_mode &
2913 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2916 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
2917 struct lu_attr *attr,
2918 struct dt_allocation_hint *hint,
2919 struct dt_object_format *dof,
2922 LASSERT(S_ISLNK(attr->la_mode));
2923 return osd_mkfile(info, obj, (attr->la_mode &
2924 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
2927 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
2928 struct lu_attr *attr,
2929 struct dt_allocation_hint *hint,
2930 struct dt_object_format *dof,
2933 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
2936 LINVRNT(osd_invariant(obj));
2937 LASSERT(obj->oo_inode == NULL);
2938 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
2939 S_ISFIFO(mode) || S_ISSOCK(mode));
2941 result = osd_mkfile(info, obj, mode, hint, th);
2943 LASSERT(obj->oo_inode != NULL);
2945 * This inode should be marked dirty for i_rdev. Currently
2946 * that is done in the osd_attr_init().
2948 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
2951 LINVRNT(osd_invariant(obj));
2955 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
2957 struct dt_allocation_hint *hint,
2958 struct dt_object_format *dof,
2961 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
2963 osd_obj_type_f result;
2979 result = osd_mk_index;
2990 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2991 struct dt_object *parent, struct dt_object *child,
2996 ah->dah_parent = parent;
2997 ah->dah_mode = child_mode;
2999 if (parent != NULL && !dt_object_remote(parent)) {
3000 /* will help to find FID->ino at dt_insert("..") */
3001 struct osd_object *pobj = osd_dt_obj(parent);
3002 osd_idc_find_and_init(env, osd_obj2dev(pobj), pobj);
3006 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
3007 struct lu_attr *attr, struct dt_object_format *dof)
3009 struct inode *inode = obj->oo_inode;
3010 __u64 valid = attr->la_valid;
3013 attr->la_valid &= ~(LA_TYPE | LA_MODE);
3015 if (dof->dof_type != DFT_NODE)
3016 attr->la_valid &= ~LA_RDEV;
3017 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
3018 attr->la_valid &= ~LA_ATIME;
3019 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
3020 attr->la_valid &= ~LA_CTIME;
3021 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
3022 attr->la_valid &= ~LA_MTIME;
3024 result = osd_quota_transfer(inode, attr);
3028 if (attr->la_valid != 0) {
3029 result = osd_inode_setattr(info->oti_env, inode, attr);
3031 * The osd_inode_setattr() should always succeed here. The
3032 * only error that could be returned is EDQUOT when we are
3033 * trying to change the UID or GID of the inode. However, this
3034 * should not happen since quota enforcement is no longer
3035 * enabled on ldiskfs (lquota takes care of it).
3037 LASSERTF(result == 0, "%d\n", result);
3038 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3041 attr->la_valid = valid;
3045 * Helper function for osd_create()
3047 * \retval 0, on success
3049 static int __osd_create(struct osd_thread_info *info, struct osd_object *obj,
3050 struct lu_attr *attr, struct dt_allocation_hint *hint,
3051 struct dt_object_format *dof, struct thandle *th)
3056 osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE);
3058 /* we drop umask so that permissions we pass are not affected */
3059 umask = current->fs->umask;
3060 current->fs->umask = 0;
3062 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
3064 if (likely(obj->oo_inode != NULL)) {
3065 LASSERT(obj->oo_inode->i_state & I_NEW);
3067 /* Unlock the inode before attr initialization to avoid
3068 * unnecessary dqget operations. LU-6378 */
3069 unlock_new_inode(obj->oo_inode);
3072 if (likely(result == 0)) {
3073 osd_attr_init(info, obj, attr, dof);
3074 osd_object_init0(obj);
3077 /* restore previous umask value */
3078 current->fs->umask = umask;
3080 osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE);
3086 * Helper function for osd_create()
3088 * \retval 0, on success
3090 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
3091 const struct lu_fid *fid, struct thandle *th)
3093 struct osd_thread_info *info = osd_oti_get(env);
3094 struct osd_inode_id *id = &info->oti_id;
3095 struct osd_device *osd = osd_obj2dev(obj);
3096 struct osd_thandle *oh;
3099 LASSERT(obj->oo_inode != NULL);
3101 oh = container_of0(th, struct osd_thandle, ot_super);
3102 LASSERT(oh->ot_handle);
3103 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3105 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
3106 rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle,
3107 OI_CHECK_FLD, NULL);
3108 osd_trans_exec_check(env, th, OSD_OT_INSERT);
3113 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
3114 u64 seq, struct lu_seq_range *range)
3116 struct seq_server_site *ss = osd_seq_site(osd);
3118 if (fid_seq_is_idif(seq)) {
3119 fld_range_set_ost(range);
3120 range->lsr_index = idif_ost_idx(seq);
3124 if (!fid_seq_in_fldb(seq)) {
3125 fld_range_set_mdt(range);
3127 /* FIXME: If ss is NULL, it suppose not get lsr_index
3129 range->lsr_index = ss->ss_node_id;
3133 LASSERT(ss != NULL);
3134 fld_range_set_any(range);
3135 /* OSD will only do local fld lookup */
3136 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
3139 static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
3140 struct lu_attr *attr,
3141 struct dt_allocation_hint *hint,
3142 struct dt_object_format *dof,
3143 struct thandle *handle)
3145 struct osd_thandle *oh;
3149 LASSERT(handle != NULL);
3151 oh = container_of0(handle, struct osd_thandle, ot_super);
3152 LASSERT(oh->ot_handle == NULL);
3154 /* EA object consumes more credits than regular object: osd_mk_index
3155 * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and
3156 * leaf_node, could involves the block, block bitmap, groups, GDT
3157 * change for each block, so add 4 * 2 credits in that case. */
3158 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
3159 osd_dto_credits_noquota[DTO_OBJECT_CREATE] +
3160 (dof->dof_type == DFT_INDEX) ? 4 * 2 : 0);
3161 /* Reuse idle OI block may cause additional one OI block
3163 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3164 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
3169 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid,
3170 attr->la_projid, 1, oh, osd_dt_obj(dt),
3171 NULL, OSD_QID_INODE);
3175 /* will help to find FID->ino mapping at dt_insert() */
3176 rc = osd_idc_find_and_init(env, osd_obj2dev(osd_dt_obj(dt)),
3183 * Called to destroy on-disk representation of the object
3185 * Concurrency: must be locked
3187 static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
3190 struct osd_object *obj = osd_dt_obj(dt);
3191 struct inode *inode = obj->oo_inode;
3192 struct osd_thandle *oh;
3199 oh = container_of0(th, struct osd_thandle, ot_super);
3200 LASSERT(oh->ot_handle == NULL);
3202 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
3203 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
3205 /* For removing agent entry */
3206 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu))
3207 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
3209 /* Recycle idle OI leaf may cause additional three OI blocks
3211 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3212 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3213 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
3214 /* one less inode */
3215 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3216 i_projid_read(inode), -1, oh, obj, NULL,
3220 /* data to be truncated */
3221 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3222 i_projid_read(inode), 0, oh, obj, NULL,
3227 /* will help to find FID->ino when this object is being
3228 * added to PENDING/ */
3229 rc = osd_idc_find_and_init(env, osd_obj2dev(obj), obj);
3234 static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
3237 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
3238 struct osd_object *obj = osd_dt_obj(dt);
3239 struct inode *inode = obj->oo_inode;
3240 struct osd_device *osd = osd_obj2dev(obj);
3241 struct osd_thandle *oh;
3245 oh = container_of0(th, struct osd_thandle, ot_super);
3246 LASSERT(oh->ot_handle);
3248 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
3250 if (unlikely(fid_is_acct(fid)))
3253 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu)) {
3254 result = osd_delete_from_remote_parent(env, osd, obj, oh, true);
3256 CERROR("%s: remove agent entry "DFID": rc = %d\n",
3257 osd_name(osd), PFID(fid), result);
3260 if (S_ISDIR(inode->i_mode)) {
3261 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
3262 inode->i_nlink == 2);
3264 spin_lock(&obj->oo_guard);
3266 spin_unlock(&obj->oo_guard);
3267 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3270 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
3272 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
3274 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3275 result = osd_oi_delete(osd_oti_get(env), osd, fid,
3276 oh->ot_handle, OI_CHECK_FLD);
3278 osd_trans_exec_check(env, th, OSD_OT_DESTROY);
3279 /* XXX: add to ext3 orphan list */
3280 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
3282 /* not needed in the cache anymore */
3283 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
3284 obj->oo_destroyed = 1;
3290 * Put the fid into lustre_mdt_attrs, and then place the structure
3291 * inode's ea. This fid should not be altered during the life time
3294 * \retval +ve, on success
3295 * \retval -ve, on error
3297 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
3299 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
3300 const struct lu_fid *fid, __u32 compat, __u32 incompat)
3302 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
3303 struct lustre_mdt_attrs *lma = &loa->loa_lma;
3307 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
3310 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
3313 lustre_loa_init(loa, fid, compat, incompat);
3314 lustre_loa_swab(loa, false);
3316 /* For the OST device with 256 bytes inode size by default,
3317 * the PFID EA will be stored together with LMA EA to avoid
3318 * performance trouble. Otherwise the PFID EA can be stored
3319 * independently. LU-8998 */
3320 if ((compat & LMAC_FID_ON_OST) &&
3321 LDISKFS_INODE_SIZE(inode->i_sb) <= 256)
3322 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3323 sizeof(*loa), XATTR_CREATE);
3325 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3326 sizeof(*lma), XATTR_CREATE);
3327 /* LMA may already exist, but we need to check that all the
3328 * desired compat/incompat flags have been added. */
3329 if (unlikely(rc == -EEXIST)) {
3330 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
3331 XATTR_NAME_LMA, (void *)loa, sizeof(*loa));
3335 if (rc < sizeof(*lma))
3338 lustre_loa_swab(loa, true);
3339 if (lu_fid_eq(fid, &lma->lma_self_fid) &&
3340 ((compat == 0 && incompat == 0) ||
3341 (!(~lma->lma_compat & compat) &&
3342 !(~lma->lma_incompat & incompat))))
3345 lma->lma_self_fid = *fid;
3346 lma->lma_compat |= compat;
3347 lma->lma_incompat |= incompat;
3348 if (rc == sizeof(*lma)) {
3349 lustre_lma_swab(lma);
3350 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3351 sizeof(*lma), XATTR_REPLACE);
3353 lustre_loa_swab(loa, false);
3354 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3355 sizeof(*loa), XATTR_REPLACE);
3363 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
3364 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
3365 * To have compatilibility with 1.8 ldiskfs driver we need to have
3366 * magic number at start of fid data.
3367 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
3370 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
3371 const struct lu_fid *fid)
3373 if (!fid_is_namespace_visible(fid) ||
3374 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
3375 param->edp_magic = 0;
3379 param->edp_magic = LDISKFS_LUFID_MAGIC;
3380 param->edp_len = sizeof(struct lu_fid) + 1;
3381 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
3385 * Try to read the fid from inode ea into dt_rec.
3387 * \param fid object fid.
3389 * \retval 0 on success
3391 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
3392 __u32 ino, struct lu_fid *fid,
3393 struct osd_inode_id *id)
3395 struct osd_thread_info *info = osd_oti_get(env);
3396 struct inode *inode;
3399 osd_id_gen(id, ino, OSD_OII_NOGEN);
3400 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
3402 RETURN(PTR_ERR(inode));
3408 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
3410 struct inode *parent_dir,
3411 const struct lu_fid *dot_fid,
3412 const struct lu_fid *dot_dot_fid,
3413 struct osd_thandle *oth)
3415 struct ldiskfs_dentry_param *dot_ldp;
3416 struct ldiskfs_dentry_param *dot_dot_ldp;
3417 __u32 saved_nlink = dir->i_nlink;
3420 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3421 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3423 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3424 dot_ldp->edp_magic = 0;
3426 rc = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3427 dir, dot_ldp, dot_dot_ldp);
3428 /* The ldiskfs_add_dot_dotdot() may dir->i_nlink as 2, then
3429 * the subseqent ref_add() will increase the dir->i_nlink
3430 * as 3. That is incorrect for new created directory.
3432 * It looks like hack, because we want to make the OSD API
3433 * to be order-independent for new created directory object
3434 * between dt_insert(..) and ref_add() operations.
3436 * Here, we only restore the in-RAM dir-inode's nlink attr,
3437 * becuase if the nlink attr is not 2, then there will be
3438 * ref_add() called following the dt_insert(..), such call
3439 * will make both the in-RAM and on-disk dir-inode's nlink
3440 * attr to be set as 2. LU-7447 */
3441 set_nlink(dir, saved_nlink);
3446 * Create an local agent inode for remote entry
3448 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
3449 struct osd_device *osd,
3450 struct osd_object *pobj,
3451 const struct lu_fid *fid,
3455 struct osd_thread_info *info = osd_oti_get(env);
3456 struct inode *local;
3457 struct osd_thandle *oh;
3462 oh = container_of(th, struct osd_thandle, ot_super);
3463 LASSERT(oh->ot_handle->h_transaction != NULL);
3465 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
3466 if (IS_ERR(local)) {
3467 CERROR("%s: create local error %d\n", osd_name(osd),
3468 (int)PTR_ERR(local));
3472 /* restore i_gid in case S_ISGID is set, we will inherit S_ISGID and set
3473 * correct gid on remote file, not agent here */
3474 local->i_gid = current_fsgid();
3475 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
3476 unlock_new_inode(local);
3478 /* Agent inode should not have project ID */
3479 #ifdef HAVE_PROJECT_QUOTA
3480 if (LDISKFS_I(pobj->oo_inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
3481 i_projid_read(pobj->oo_inode) != 0) {
3482 rc = ldiskfs_transfer_project(local, 0);
3484 CERROR("%s: quota transfer failed: rc = %d. Is project "
3485 "quota enforcement enabled on the ldiskfs "
3486 "filesystem?\n", local->i_sb->s_id, rc);
3487 RETURN(ERR_PTR(rc));
3491 /* Set special LMA flag for local agent inode */
3492 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
3494 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
3495 osd_name(osd), PFID(fid), rc);
3496 RETURN(ERR_PTR(rc));
3502 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
3503 lu_object_fid(&pobj->oo_dt.do_lu),
3506 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
3507 osd_name(osd), PFID(fid), rc);
3508 RETURN(ERR_PTR(rc));
3515 * when direntry is deleted, we have to take care of possible agent inode
3516 * referenced by that. unfortunately we can't do this at that point:
3517 * iget() within a running transaction leads to deadlock and we better do
3518 * not call that every delete declaration to save performance. so we put
3519 * a potention agent inode on a list and process that once the transaction
3520 * is over. Notice it's not any worse in terms of real orphans as regular
3521 * object destroy doesn't put inodes on the on-disk orphan list. this should
3522 * be addressed separately
3524 static int osd_schedule_agent_inode_removal(const struct lu_env *env,
3525 struct osd_thandle *oh,
3528 struct osd_device *osd = osd_dt_dev(oh->ot_super.th_dev);
3529 struct osd_obj_orphan *oor;
3536 oor->oor_env = (struct lu_env *)env;
3537 spin_lock(&osd->od_osfs_lock);
3538 list_add(&oor->oor_list, &osd->od_orphan_list);
3539 spin_unlock(&osd->od_osfs_lock);
3541 oh->ot_remove_agents = 1;
3547 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
3548 struct osd_device *osd)
3550 struct osd_thread_info *info = osd_oti_get(env);
3551 struct osd_obj_orphan *oor, *tmp;
3552 struct osd_inode_id id;
3553 struct list_head list;
3554 struct inode *inode;
3559 INIT_LIST_HEAD(&list);
3561 spin_lock(&osd->od_osfs_lock);
3562 list_for_each_entry_safe(oor, tmp, &osd->od_orphan_list, oor_list) {
3563 if (oor->oor_env == env) {
3564 list_del(&oor->oor_list);
3565 list_add(&oor->oor_list, &list);
3568 spin_unlock(&osd->od_osfs_lock);
3570 list_for_each_entry_safe(oor, tmp, &list, oor_list) {
3574 list_del(&oor->oor_list);
3577 osd_id_gen(&id, ino, OSD_OII_NOGEN);
3578 inode = osd_iget_fid(info, osd, &id, &fid);
3582 if (!osd_remote_fid(env, osd, &fid)) {
3587 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC, 1);
3589 mark_inode_dirty(inode);
3590 ldiskfs_journal_stop(jh);
3598 * OSD layer object create function for OST objects (b=11826).
3600 * The FID is inserted into inode xattr here.
3602 * \retval 0, on success
3603 * \retval -ve, on error
3605 static int osd_create(const struct lu_env *env, struct dt_object *dt,
3606 struct lu_attr *attr, struct dt_allocation_hint *hint,
3607 struct dt_object_format *dof, struct thandle *th)
3609 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
3610 struct osd_object *obj = osd_dt_obj(dt);
3611 struct osd_thread_info *info = osd_oti_get(env);
3612 int result, on_ost = 0;
3616 if (dt_object_exists(dt))
3619 LINVRNT(osd_invariant(obj));
3620 LASSERT(!dt_object_remote(dt));
3621 LASSERT(osd_is_write_locked(env, obj));
3622 LASSERT(th != NULL);
3624 if (unlikely(fid_is_acct(fid)))
3625 /* Quota files can't be created from the kernel any more,
3626 * 'tune2fs -O quota' will take care of creating them */
3629 result = __osd_create(info, obj, attr, hint, dof, th);
3631 if (fid_is_idif(fid) &&
3632 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
3633 struct lu_fid *tfid = &info->oti_fid;
3634 struct ost_id *oi = &info->oti_ostid;
3636 fid_to_ostid(fid, oi);
3637 ostid_to_fid(tfid, oi, 0);
3639 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
3640 LMAC_FID_ON_OST, 0);
3642 on_ost = fid_is_on_ost(info, osd_obj2dev(obj),
3644 result = osd_ea_fid_set(info, obj->oo_inode, fid,
3645 on_ost ? LMAC_FID_ON_OST : 0,
3648 if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
3649 obj->oo_dt.do_body_ops = &osd_body_ops;
3653 result = __osd_oi_insert(env, obj, fid, th);
3655 /* a small optimization - dt_insert() isn't usually applied
3656 * to OST objects, so we don't need to cache OI mapping for
3658 if (result == 0 && on_ost == 0) {
3659 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3660 result = osd_idc_find_and_init(env, osd, obj);
3661 LASSERT(result == 0);
3664 LASSERT(ergo(result == 0,
3665 dt_object_exists(dt) && !dt_object_remote(dt)));
3666 LINVRNT(osd_invariant(obj));
3670 static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
3671 struct thandle *handle)
3673 struct osd_thandle *oh;
3675 /* it's possible that object doesn't exist yet */
3676 LASSERT(handle != NULL);
3678 oh = container_of0(handle, struct osd_thandle, ot_super);
3679 LASSERT(oh->ot_handle == NULL);
3681 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
3682 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3688 * Concurrency: @dt is write locked.
3690 static int osd_ref_add(const struct lu_env *env, struct dt_object *dt,
3693 struct osd_object *obj = osd_dt_obj(dt);
3694 struct inode *inode = obj->oo_inode;
3695 struct osd_thandle *oh;
3698 if (!dt_object_exists(dt) || obj->oo_destroyed)
3701 LINVRNT(osd_invariant(obj));
3702 LASSERT(!dt_object_remote(dt));
3703 LASSERT(osd_is_write_locked(env, obj));
3704 LASSERT(th != NULL);
3706 oh = container_of0(th, struct osd_thandle, ot_super);
3707 LASSERT(oh->ot_handle != NULL);
3709 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
3711 CDEBUG(D_INODE, DFID" increase nlink %d\n",
3712 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
3714 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
3715 * (65000) subdirectories by storing "1" in i_nlink if the link count
3716 * would otherwise overflow. Directory tranversal tools understand
3717 * that (st_nlink == 1) indicates that the filesystem dose not track
3718 * hard links count on the directory, and will not abort subdirectory
3719 * scanning early once (st_nlink - 2) subdirs have been found.
3721 * This also has to properly handle the case of inodes with nlink == 0
3722 * in case they are being linked into the PENDING directory
3724 spin_lock(&obj->oo_guard);
3725 if (unlikely(inode->i_nlink == 0))
3726 /* inc_nlink from 0 may cause WARN_ON */
3727 set_nlink(inode, 1);
3729 ldiskfs_inc_count(oh->ot_handle, inode);
3730 if (!S_ISDIR(inode->i_mode))
3731 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
3733 spin_unlock(&obj->oo_guard);
3735 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3736 LINVRNT(osd_invariant(obj));
3738 osd_trans_exec_check(env, th, OSD_OT_REF_ADD);
3743 static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
3744 struct thandle *handle)
3746 struct osd_thandle *oh;
3748 if (!dt_object_exists(dt))
3751 LASSERT(!dt_object_remote(dt));
3752 LASSERT(handle != NULL);
3754 oh = container_of0(handle, struct osd_thandle, ot_super);
3755 LASSERT(oh->ot_handle == NULL);
3757 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
3758 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
3764 * Concurrency: @dt is write locked.
3766 static int osd_ref_del(const struct lu_env *env, struct dt_object *dt,
3769 struct osd_object *obj = osd_dt_obj(dt);
3770 struct inode *inode = obj->oo_inode;
3771 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3772 struct osd_thandle *oh;
3774 if (!dt_object_exists(dt))
3777 LINVRNT(osd_invariant(obj));
3778 LASSERT(!dt_object_remote(dt));
3779 LASSERT(osd_is_write_locked(env, obj));
3780 LASSERT(th != NULL);
3782 oh = container_of0(th, struct osd_thandle, ot_super);
3783 LASSERT(oh->ot_handle != NULL);
3785 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
3787 spin_lock(&obj->oo_guard);
3788 /* That can be result of upgrade from old Lustre version and
3789 * applied only to local files. Just skip this ref_del call.
3790 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
3791 if (inode->i_nlink == 0) {
3792 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
3793 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
3794 ", maybe an upgraded file? (LU-3915)\n",
3795 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
3796 spin_unlock(&obj->oo_guard);
3800 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
3801 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
3803 ldiskfs_dec_count(oh->ot_handle, inode);
3804 spin_unlock(&obj->oo_guard);
3806 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
3807 LINVRNT(osd_invariant(obj));
3809 osd_trans_exec_check(env, th, OSD_OT_REF_DEL);
3815 * Concurrency: @dt is read locked.
3817 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
3818 struct lu_buf *buf, const char *name)
3820 struct osd_object *obj = osd_dt_obj(dt);
3821 struct inode *inode = obj->oo_inode;
3822 struct osd_thread_info *info = osd_oti_get(env);
3823 struct dentry *dentry = &info->oti_obj_dentry;
3824 bool cache_xattr = false;
3829 /* version get is not real XATTR but uses xattr API */
3830 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
3831 dt_obj_version_t *ver = buf->lb_buf;
3833 /* for version we are just using xattr API but change inode
3835 if (buf->lb_len == 0)
3836 return sizeof(dt_obj_version_t);
3838 if (buf->lb_len < sizeof(dt_obj_version_t))
3841 CDEBUG(D_INODE, "Get version %#llx for inode %lu\n",
3842 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
3844 *ver = LDISKFS_I(inode)->i_fs_version;
3846 return sizeof(dt_obj_version_t);
3849 if (!dt_object_exists(dt))
3852 LASSERT(!dt_object_remote(dt));
3853 LASSERT(inode->i_op != NULL);
3854 LASSERT(inode->i_op->getxattr != NULL);
3856 if (strcmp(name, XATTR_NAME_LOV) == 0 ||
3857 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
3861 rc = osd_oxc_get(obj, name, buf);
3866 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
3867 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
3868 struct lustre_mdt_attrs *lma = &loa->loa_lma;
3869 struct filter_fid *ff;
3870 struct ost_layout *ol;
3872 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
3876 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
3879 if (buf->lb_len == 0 || !buf->lb_buf)
3882 if (buf->lb_len < rc)
3886 ol = &ff->ff_layout;
3887 ol->ol_stripe_count = cpu_to_le32(loa->loa_parent_fid.f_ver >>
3888 PFID_STRIPE_IDX_BITS);
3889 ol->ol_stripe_size = cpu_to_le32(loa->loa_stripe_size);
3890 loa->loa_parent_fid.f_ver &= PFID_STRIPE_COUNT_MASK;
3891 fid_cpu_to_le(&ff->ff_parent, &loa->loa_parent_fid);
3892 if (lma->lma_compat & LMAC_COMP_INFO) {
3893 ol->ol_comp_start = cpu_to_le64(loa->loa_comp_start);
3894 ol->ol_comp_end = cpu_to_le64(loa->loa_comp_end);
3895 ol->ol_comp_id = cpu_to_le32(loa->loa_comp_id);
3897 ol->ol_comp_start = 0;
3898 ol->ol_comp_end = 0;
3902 rc = __osd_xattr_get(inode, dentry, name,
3903 buf->lb_buf, buf->lb_len);
3907 if (rc == -ENOENT || rc == -ENODATA)
3908 osd_oxc_add(obj, name, NULL, 0);
3909 else if (rc > 0 && buf->lb_buf != NULL)
3910 osd_oxc_add(obj, name, buf->lb_buf, rc);
3916 static int osd_declare_xattr_set(const struct lu_env *env,
3917 struct dt_object *dt,
3918 const struct lu_buf *buf, const char *name,
3919 int fl, struct thandle *handle)
3921 struct osd_thandle *oh;
3923 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3925 LASSERT(handle != NULL);
3927 oh = container_of0(handle, struct osd_thandle, ot_super);
3928 LASSERT(oh->ot_handle == NULL);
3930 if (strcmp(name, XATTR_NAME_LMA) == 0) {
3931 /* For non-upgrading case, the LMA is set first and
3932 * usually fit inode. But for upgrade case, the LMA
3933 * may be in another separated EA block. */
3934 if (dt_object_exists(dt)) {
3935 if (fl == LU_XATTR_REPLACE)
3940 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
3942 } else if (strcmp(name, XATTR_NAME_FID) == 0) {
3943 /* We may need to delete the old PFID EA. */
3944 credits = LDISKFS_MAXQUOTAS_DEL_BLOCKS(sb);
3945 if (fl == LU_XATTR_REPLACE)
3950 /* If some name entry resides on remote MDT, then will create
3951 * agent entry under remote parent. On the other hand, if the
3952 * remote entry will be removed, then related agent entry may
3953 * need to be removed from the remote parent. So there may be
3954 * kinds of cases, let's declare enough credits. The credits
3955 * for create agent entry is enough for remove case. */
3956 if (strcmp(name, XATTR_NAME_LINK) == 0) {
3957 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
3958 if (dt_object_exists(dt))
3959 credits += 1; /* For updating LMA */
3963 credits += osd_dto_credits_noquota[DTO_XATTR_SET];
3968 if (buf->lb_buf == NULL && dt_object_exists(dt)) {
3969 /* learn xattr size from osd_xattr_get if
3970 attribute has not been read yet */
3971 buflen = __osd_xattr_get(
3972 osd_dt_obj(dt)->oo_inode,
3973 &osd_oti_get(env)->oti_obj_dentry,
3978 buflen = buf->lb_len;
3981 if (buflen > sb->s_blocksize) {
3982 credits += osd_calc_bkmap_credits(
3984 (buflen + sb->s_blocksize - 1) >>
3985 sb->s_blocksize_bits);
3989 * xattr set may involve inode quota change, reserve credits for
3990 * dquot_initialize()
3992 credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
3995 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
4000 static int osd_xattr_set_pfid(const struct lu_env *env, struct osd_object *obj,
4001 const struct lu_buf *buf, int fl,
4002 struct thandle *handle)
4004 struct osd_thread_info *info = osd_oti_get(env);
4005 struct dentry *dentry = &info->oti_obj_dentry;
4006 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4007 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4008 struct inode *inode = obj->oo_inode;
4009 struct filter_fid *ff = buf->lb_buf;
4010 struct ost_layout *ol = &ff->ff_layout;
4011 int flags = XATTR_REPLACE;
4015 if (buf->lb_len != sizeof(*ff) && buf->lb_len != sizeof(struct lu_fid))
4018 rc = osd_get_lma(info, inode, dentry, loa);
4019 if (rc == -ENODATA) {
4020 /* Usually for upgarding from old device */
4021 lustre_loa_init(loa, lu_object_fid(&obj->oo_dt.do_lu),
4022 LMAC_FID_ON_OST, 0);
4023 flags = XATTR_CREATE;
4028 if (!rc && lma->lma_compat & LMAC_STRIPE_INFO) {
4029 if ((fl & LU_XATTR_CREATE) && !(fl & LU_XATTR_REPLACE))
4032 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256) {
4033 /* Separate PFID EA from LMA */
4034 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4035 lustre_lma_swab(lma);
4036 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4037 sizeof(*lma), XATTR_REPLACE);
4039 obj->oo_pfid_in_lma = 0;
4040 rc = LU_XATTR_CREATE;
4046 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256)
4049 /* Old client does not send stripe information,
4050 * then store the PFID EA on disk separatedly. */
4051 if (unlikely(buf->lb_len == sizeof(struct lu_fid) ||
4052 ol->ol_stripe_size == 0))
4055 /* Remove old PFID EA entry firstly. */
4056 ll_vfs_dq_init(inode);
4057 rc = inode->i_op->removexattr(dentry, XATTR_NAME_FID);
4058 if (rc == -ENODATA) {
4059 if ((fl & LU_XATTR_REPLACE) && !(fl & LU_XATTR_CREATE))
4066 fid_le_to_cpu(&loa->loa_parent_fid, &ff->ff_parent);
4067 if (likely(ol->ol_stripe_size != 0)) {
4068 loa->loa_parent_fid.f_ver |= le32_to_cpu(ol->ol_stripe_count) <<
4069 PFID_STRIPE_IDX_BITS;
4070 loa->loa_stripe_size = le32_to_cpu(ol->ol_stripe_size);
4071 lma->lma_compat |= LMAC_STRIPE_INFO;
4072 if (ol->ol_comp_id != 0) {
4073 loa->loa_comp_id = le32_to_cpu(ol->ol_comp_id);
4074 loa->loa_comp_start = le64_to_cpu(ol->ol_comp_start);
4075 loa->loa_comp_end = le64_to_cpu(ol->ol_comp_end);
4076 lma->lma_compat |= LMAC_COMP_INFO;
4080 lustre_loa_swab(loa, false);
4082 /* Store the PFID EA inside LMA. */
4083 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa, sizeof(*loa),
4086 obj->oo_pfid_in_lma = 1;
4092 * In DNE environment, the object (in spite of regular file or directory)
4093 * and its name entry may reside on different MDTs. Under such case, we will
4094 * create an agent entry on the MDT where the object resides. The agent entry
4095 * references the object locally, that makes the object to be visible to the
4096 * userspace when mounted as 'ldiskfs' directly. Then the userspace tools,
4097 * such as 'tar' can handle the object properly.
4099 * We handle the agent entry during set linkEA that is the common interface
4100 * for both regular file and directroy, can handle kinds of cases, such as
4101 * create/link/unlink/rename, and so on.
4103 * NOTE: we can NOT do that when ea_{insert,delete} that is only for directory.
4105 * XXX: There are two known issues:
4106 * 1. For one object, we will create at most one agent entry even if there
4107 * may be more than one cross-MDTs hard links on the object. So the local
4108 * e2fsck may claim that the object's nlink is larger than the name entries
4109 * that reference such inode. And in further, the e2fsck will fix the nlink
4110 * attribute to match the local references. Then it will cause the object's
4111 * nlink attribute to be inconsistent with the global references. it is bad
4112 * but not fatal. The ref_del() can handle the zero-referenced case. On the
4113 * other hand, the global namespace LFSCK can repair the object's attribute
4114 * according to the linkEA.
4115 * 2. There may be too many hard links on the object as to its linkEA overflow,
4116 * then the linkEA entry for cross-MDTs reference may be discarded. If such
4117 * case happened, then at this point, we do not know whether there are some
4118 * cross-MDTs reference. But there are local references, it guarantees that
4119 * object is visible to userspace when mounted as 'ldiskfs'. That is enough.
4121 static int osd_xattr_handle_linkea(const struct lu_env *env,
4122 struct osd_device *osd,
4123 struct osd_object *obj,
4124 const struct lu_buf *buf,
4125 struct thandle *handle)
4127 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
4128 struct lu_fid *tfid = &osd_oti_get(env)->oti_fid3;
4129 struct linkea_data ldata = { .ld_buf = (struct lu_buf *)buf };
4130 struct lu_name tmpname;
4131 struct osd_thandle *oh;
4133 bool remote = false;
4136 oh = container_of0(handle, struct osd_thandle, ot_super);
4137 LASSERT(oh->ot_handle != NULL);
4139 rc = linkea_init_with_rec(&ldata);
4141 linkea_first_entry(&ldata);
4142 while (ldata.ld_lee != NULL && !remote) {
4143 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
4145 if (osd_remote_fid(env, osd, tfid) > 0)
4148 linkea_next_entry(&ldata);
4150 } else if (rc == -ENODATA) {
4156 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu) && !remote) {
4157 rc = osd_delete_from_remote_parent(env, osd, obj, oh, false);
4159 CERROR("%s: failed to remove agent entry for "DFID
4160 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4161 } else if (!lu_object_has_agent_entry(&obj->oo_dt.do_lu) && remote) {
4162 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4164 CERROR("%s: failed to create agent entry for "DFID
4165 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4172 * Concurrency: @dt is write locked.
4174 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
4175 const struct lu_buf *buf, const char *name, int fl,
4176 struct thandle *handle)
4178 struct osd_object *obj = osd_dt_obj(dt);
4179 struct osd_device *osd = osd_obj2dev(obj);
4180 struct inode *inode = obj->oo_inode;
4181 struct osd_thread_info *info = osd_oti_get(env);
4190 /* version set is not real XATTR */
4191 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4192 dt_obj_version_t *version = buf->lb_buf;
4194 /* for version we are just using xattr API but change inode
4196 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
4198 CDEBUG(D_INODE, "Set version %#llx (old %#llx) for inode %lu\n",
4199 *version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
4201 LDISKFS_I(inode)->i_fs_version = *version;
4202 /* Version is set after all inode operations are finished,
4203 * so we should mark it dirty here */
4204 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
4209 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
4210 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
4213 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4215 /* For the OST device with 256 bytes inode size by default,
4216 * the PFID EA will be stored together with LMA EA to avoid
4217 * performance trouble. Otherwise the PFID EA can be stored
4218 * independently. LU-8998 */
4219 if (strcmp(name, XATTR_NAME_FID) == 0 && osd->od_is_ost &&
4220 (LDISKFS_INODE_SIZE(inode->i_sb) <= 256 || obj->oo_pfid_in_lma)) {
4221 LASSERT(buf->lb_buf);
4223 fl = osd_xattr_set_pfid(env, obj, buf, fl, handle);
4226 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
4227 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4228 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4230 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
4234 lma->lma_incompat |= LMAI_STRIPED;
4235 lustre_lma_swab(lma);
4236 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4237 sizeof(*lma), XATTR_REPLACE);
4240 } else if (strcmp(name, XATTR_NAME_LINK) == 0) {
4241 LASSERT(!osd->od_is_ost);
4243 rc = osd_xattr_handle_linkea(env, osd, obj, buf, handle);
4248 if (fl & LU_XATTR_REPLACE)
4249 fs_flags |= XATTR_REPLACE;
4251 if (fl & LU_XATTR_CREATE)
4252 fs_flags |= XATTR_CREATE;
4254 rc = __osd_xattr_set(info, inode, name, buf->lb_buf, len, fs_flags);
4255 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4258 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4259 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4260 osd_oxc_add(obj, name, buf->lb_buf, buf->lb_len);
4266 * Concurrency: @dt is read locked.
4268 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
4269 const struct lu_buf *buf)
4271 struct osd_object *obj = osd_dt_obj(dt);
4272 struct inode *inode = obj->oo_inode;
4273 struct osd_thread_info *info = osd_oti_get(env);
4274 struct dentry *dentry = &info->oti_obj_dentry;
4276 if (!dt_object_exists(dt))
4279 LASSERT(!dt_object_remote(dt));
4280 LASSERT(inode->i_op != NULL);
4281 LASSERT(inode->i_op->listxattr != NULL);
4283 dentry->d_inode = inode;
4284 dentry->d_sb = inode->i_sb;
4285 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
4288 static int osd_declare_xattr_del(const struct lu_env *env,
4289 struct dt_object *dt, const char *name,
4290 struct thandle *handle)
4292 struct osd_thandle *oh;
4293 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
4295 LASSERT(!dt_object_remote(dt));
4296 LASSERT(handle != NULL);
4298 oh = container_of0(handle, struct osd_thandle, ot_super);
4299 LASSERT(oh->ot_handle == NULL);
4301 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
4302 osd_dto_credits_noquota[DTO_XATTR_SET]);
4304 * xattr del may involve inode quota change, reserve credits for
4305 * dquot_initialize()
4307 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
4313 * Concurrency: @dt is write locked.
4315 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
4316 const char *name, struct thandle *handle)
4318 struct osd_object *obj = osd_dt_obj(dt);
4319 struct inode *inode = obj->oo_inode;
4320 struct osd_thread_info *info = osd_oti_get(env);
4321 struct dentry *dentry = &info->oti_obj_dentry;
4324 if (!dt_object_exists(dt))
4327 LASSERT(!dt_object_remote(dt));
4328 LASSERT(inode->i_op != NULL);
4329 LASSERT(inode->i_op->removexattr != NULL);
4330 LASSERT(handle != NULL);
4332 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4334 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
4335 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
4337 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
4338 &info->oti_ost_attrs);
4340 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
4342 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4343 lustre_lma_swab(lma);
4344 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4345 sizeof(*lma), XATTR_REPLACE);
4347 obj->oo_pfid_in_lma = 0;
4350 ll_vfs_dq_init(inode);
4351 dentry->d_inode = inode;
4352 dentry->d_sb = inode->i_sb;
4353 rc = inode->i_op->removexattr(dentry, name);
4356 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4359 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4360 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4361 osd_oxc_del(obj, name);
4366 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
4367 __u64 start, __u64 end)
4369 struct osd_object *obj = osd_dt_obj(dt);
4370 struct inode *inode = obj->oo_inode;
4371 struct osd_thread_info *info = osd_oti_get(env);
4372 struct dentry *dentry = &info->oti_obj_dentry;
4373 struct file *file = &info->oti_file;
4378 dentry->d_inode = inode;
4379 dentry->d_sb = inode->i_sb;
4380 file->f_path.dentry = dentry;
4381 file->f_mapping = inode->i_mapping;
4382 file->f_op = inode->i_fop;
4383 set_file_inode(file, inode);
4385 rc = ll_vfs_fsync_range(file, start, end, 0);
4390 static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
4399 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
4400 const struct dt_index_features *feat)
4402 struct iam_descr *descr;
4404 if (osd_object_is_root(o))
4405 return feat == &dt_directory_features;
4407 LASSERT(o->oo_dir != NULL);
4409 descr = o->oo_dir->od_container.ic_descr;
4410 if (feat == &dt_directory_features) {
4411 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
4417 feat->dif_keysize_min <= descr->id_key_size &&
4418 descr->id_key_size <= feat->dif_keysize_max &&
4419 feat->dif_recsize_min <= descr->id_rec_size &&
4420 descr->id_rec_size <= feat->dif_recsize_max &&
4421 !(feat->dif_flags & (DT_IND_VARKEY |
4422 DT_IND_VARREC | DT_IND_NONUNQ)) &&
4423 ergo(feat->dif_flags & DT_IND_UPDATE,
4424 1 /* XXX check that object (and file system) is
4429 static int osd_iam_container_init(const struct lu_env *env,
4430 struct osd_object *obj,
4431 struct osd_directory *dir)
4433 struct iam_container *bag = &dir->od_container;
4436 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
4440 result = iam_container_setup(bag);
4442 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
4444 iam_container_fini(bag);
4451 * Concurrency: no external locking is necessary.
4453 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
4454 const struct dt_index_features *feat)
4458 struct osd_object *obj = osd_dt_obj(dt);
4460 LINVRNT(osd_invariant(obj));
4462 if (osd_object_is_root(obj)) {
4463 dt->do_index_ops = &osd_index_ea_ops;
4465 } else if (feat == &dt_directory_features) {
4466 dt->do_index_ops = &osd_index_ea_ops;
4467 if (obj->oo_inode == NULL || S_ISDIR(obj->oo_inode->i_mode))
4472 } else if (unlikely(feat == &dt_otable_features)) {
4473 dt->do_index_ops = &osd_otable_ops;
4475 } else if (unlikely(feat == &dt_acct_features)) {
4476 dt->do_index_ops = &osd_acct_index_ops;
4479 } else if (!osd_has_index(obj)) {
4480 struct osd_directory *dir;
4485 spin_lock(&obj->oo_guard);
4486 if (obj->oo_dir == NULL)
4490 * Concurrent thread allocated container data.
4493 spin_unlock(&obj->oo_guard);
4495 * Now, that we have container data, serialize its
4498 down_write(&obj->oo_ext_idx_sem);
4500 * recheck under lock.
4502 if (!osd_has_index(obj))
4503 result = osd_iam_container_init(env, obj,
4507 up_write(&obj->oo_ext_idx_sem);
4515 if (result == 0 && skip_iam == 0) {
4516 if (!osd_iam_index_probe(env, obj, feat))
4519 LINVRNT(osd_invariant(obj));
4524 static int osd_otable_it_attr_get(const struct lu_env *env,
4525 struct dt_object *dt,
4526 struct lu_attr *attr)
4532 static const struct dt_object_operations osd_obj_ops = {
4533 .do_read_lock = osd_read_lock,
4534 .do_write_lock = osd_write_lock,
4535 .do_read_unlock = osd_read_unlock,
4536 .do_write_unlock = osd_write_unlock,
4537 .do_write_locked = osd_write_locked,
4538 .do_attr_get = osd_attr_get,
4539 .do_declare_attr_set = osd_declare_attr_set,
4540 .do_attr_set = osd_attr_set,
4541 .do_ah_init = osd_ah_init,
4542 .do_declare_create = osd_declare_create,
4543 .do_create = osd_create,
4544 .do_declare_destroy = osd_declare_destroy,
4545 .do_destroy = osd_destroy,
4546 .do_index_try = osd_index_try,
4547 .do_declare_ref_add = osd_declare_ref_add,
4548 .do_ref_add = osd_ref_add,
4549 .do_declare_ref_del = osd_declare_ref_del,
4550 .do_ref_del = osd_ref_del,
4551 .do_xattr_get = osd_xattr_get,
4552 .do_declare_xattr_set = osd_declare_xattr_set,
4553 .do_xattr_set = osd_xattr_set,
4554 .do_declare_xattr_del = osd_declare_xattr_del,
4555 .do_xattr_del = osd_xattr_del,
4556 .do_xattr_list = osd_xattr_list,
4557 .do_object_sync = osd_object_sync,
4558 .do_invalidate = osd_invalidate,
4561 static const struct dt_object_operations osd_obj_otable_it_ops = {
4562 .do_attr_get = osd_otable_it_attr_get,
4563 .do_index_try = osd_index_try,
4566 static int osd_index_declare_iam_delete(const struct lu_env *env,
4567 struct dt_object *dt,
4568 const struct dt_key *key,
4569 struct thandle *handle)
4571 struct osd_thandle *oh;
4573 oh = container_of0(handle, struct osd_thandle, ot_super);
4574 LASSERT(oh->ot_handle == NULL);
4576 /* Recycle may cause additional three blocks to be changed. */
4577 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
4578 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
4584 * delete a (key, value) pair from index \a dt specified by \a key
4586 * \param dt osd index object
4587 * \param key key for index
4588 * \param rec record reference
4589 * \param handle transaction handler
4592 * \retval -ve failure
4594 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
4595 const struct dt_key *key,
4596 struct thandle *handle)
4598 struct osd_thread_info *oti = osd_oti_get(env);
4599 struct osd_object *obj = osd_dt_obj(dt);
4600 struct osd_thandle *oh;
4601 struct iam_path_descr *ipd;
4602 struct iam_container *bag = &obj->oo_dir->od_container;
4606 if (!dt_object_exists(dt))
4609 LINVRNT(osd_invariant(obj));
4610 LASSERT(!dt_object_remote(dt));
4611 LASSERT(bag->ic_object == obj->oo_inode);
4612 LASSERT(handle != NULL);
4614 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
4616 ipd = osd_idx_ipd_get(env, bag);
4617 if (unlikely(ipd == NULL))
4620 oh = container_of0(handle, struct osd_thandle, ot_super);
4621 LASSERT(oh->ot_handle != NULL);
4622 LASSERT(oh->ot_handle->h_transaction != NULL);
4624 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4625 /* swab quota uid/gid provided by caller */
4626 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4627 key = (const struct dt_key *)&oti->oti_quota_id;
4630 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
4631 osd_ipd_put(env, bag, ipd);
4632 LINVRNT(osd_invariant(obj));
4633 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
4637 static int osd_index_declare_ea_delete(const struct lu_env *env,
4638 struct dt_object *dt,
4639 const struct dt_key *key,
4640 struct thandle *handle)
4642 struct osd_thandle *oh;
4643 struct inode *inode;
4647 LASSERT(!dt_object_remote(dt));
4648 LASSERT(handle != NULL);
4650 oh = container_of0(handle, struct osd_thandle, ot_super);
4651 LASSERT(oh->ot_handle == NULL);
4653 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE];
4654 osd_trans_declare_op(env, oh, OSD_OT_DELETE, credits);
4656 inode = osd_dt_obj(dt)->oo_inode;
4660 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
4661 i_projid_read(inode), 0, oh, osd_dt_obj(dt),
4666 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
4669 struct osd_fid_pack *rec;
4672 if (de->file_type & LDISKFS_DIRENT_LUFID) {
4673 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
4674 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
4675 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
4681 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
4682 const struct lu_fid *fid)
4684 struct seq_server_site *ss = osd_seq_site(osd);
4687 /* FID seqs not in FLDB, must be local seq */
4688 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
4691 /* If FLD is not being initialized yet, it only happens during the
4692 * initialization, likely during mgs initialization, and we assume
4693 * this is local FID. */
4694 if (ss == NULL || ss->ss_server_fld == NULL)
4697 /* Only check the local FLDB here */
4698 if (osd_seq_exists(env, osd, fid_seq(fid)))
4705 * Index delete function for interoperability mode (b11826).
4706 * It will remove the directory entry added by osd_index_ea_insert().
4707 * This entry is needed to maintain name->fid mapping.
4709 * \param key, key i.e. file entry to be deleted
4711 * \retval 0, on success
4712 * \retval -ve, on error
4714 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
4715 const struct dt_key *key, struct thandle *handle)
4717 struct osd_object *obj = osd_dt_obj(dt);
4718 struct inode *dir = obj->oo_inode;
4719 struct dentry *dentry;
4720 struct osd_thandle *oh;
4721 struct ldiskfs_dir_entry_2 *de = NULL;
4722 struct buffer_head *bh;
4723 struct htree_lock *hlock = NULL;
4724 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
4725 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4729 if (!dt_object_exists(dt))
4732 LINVRNT(osd_invariant(obj));
4733 LASSERT(!dt_object_remote(dt));
4734 LASSERT(handle != NULL);
4736 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
4738 oh = container_of(handle, struct osd_thandle, ot_super);
4739 LASSERT(oh->ot_handle != NULL);
4740 LASSERT(oh->ot_handle->h_transaction != NULL);
4742 ll_vfs_dq_init(dir);
4743 dentry = osd_child_dentry_get(env, obj,
4744 (char *)key, strlen((char *)key));
4746 if (obj->oo_hl_head != NULL) {
4747 hlock = osd_oti_get(env)->oti_hlock;
4748 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4749 dir, LDISKFS_HLOCK_DEL);
4751 down_write(&obj->oo_ext_idx_sem);
4754 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4756 /* If this is not the ".." entry, it might be a remote DNE
4757 * entry and we need to check if the FID is for a remote
4758 * MDT. If the FID is not in the directory entry (e.g.
4759 * upgraded 1.8 filesystem without dirdata enabled) then
4760 * we need to get the FID from the LMA. For a remote directory
4761 * there HAS to be an LMA, it cannot be an IGIF inode in this
4764 * Delete the entry before the agent inode in order to
4765 * simplify error handling. At worst an error after deleting
4766 * the entry first might leak the agent inode afterward. The
4767 * reverse would need filesystem abort in case of error deleting
4768 * the entry after the agent had been removed, or leave a
4769 * dangling entry pointing at a random inode. */
4770 if (strcmp((char *)key, dotdot) != 0) {
4771 LASSERT(de != NULL);
4772 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
4773 if (rc == -ENODATA) {
4774 /* can't get FID, postpone to the end of the
4775 * transaction when iget() is safe */
4776 osd_schedule_agent_inode_removal(env, oh,
4777 le32_to_cpu(de->inode));
4778 } else if (rc == 0 &&
4779 unlikely(osd_remote_fid(env, osd, fid))) {
4780 osd_schedule_agent_inode_removal(env, oh,
4781 le32_to_cpu(de->inode));
4784 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
4790 ldiskfs_htree_unlock(hlock);
4792 up_write(&obj->oo_ext_idx_sem);
4797 LASSERT(osd_invariant(obj));
4798 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
4803 * Lookup index for \a key and copy record to \a rec.
4805 * \param dt osd index object
4806 * \param key key for index
4807 * \param rec record reference
4809 * \retval +ve success : exact mach
4810 * \retval 0 return record with key not greater than \a key
4811 * \retval -ve failure
4813 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
4814 struct dt_rec *rec, const struct dt_key *key)
4816 struct osd_object *obj = osd_dt_obj(dt);
4817 struct iam_path_descr *ipd;
4818 struct iam_container *bag = &obj->oo_dir->od_container;
4819 struct osd_thread_info *oti = osd_oti_get(env);
4820 struct iam_iterator *it = &oti->oti_idx_it;
4821 struct iam_rec *iam_rec;
4825 if (!dt_object_exists(dt))
4828 LASSERT(osd_invariant(obj));
4829 LASSERT(!dt_object_remote(dt));
4830 LASSERT(bag->ic_object == obj->oo_inode);
4832 ipd = osd_idx_ipd_get(env, bag);
4836 /* got ipd now we can start iterator. */
4837 iam_it_init(it, bag, 0, ipd);
4839 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4840 /* swab quota uid/gid provided by caller */
4841 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4842 key = (const struct dt_key *)&oti->oti_quota_id;
4845 rc = iam_it_get(it, (struct iam_key *)key);
4847 if (S_ISDIR(obj->oo_inode->i_mode))
4848 iam_rec = (struct iam_rec *)oti->oti_ldp;
4850 iam_rec = (struct iam_rec *) rec;
4852 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
4854 if (S_ISDIR(obj->oo_inode->i_mode))
4855 osd_fid_unpack((struct lu_fid *) rec,
4856 (struct osd_fid_pack *)iam_rec);
4857 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
4858 osd_quota_unpack(obj, rec);
4863 osd_ipd_put(env, bag, ipd);
4865 LINVRNT(osd_invariant(obj));
4870 static int osd_index_declare_iam_insert(const struct lu_env *env,
4871 struct dt_object *dt,
4872 const struct dt_rec *rec,
4873 const struct dt_key *key,
4874 struct thandle *handle)
4876 struct osd_thandle *oh;
4878 LASSERT(handle != NULL);
4880 oh = container_of0(handle, struct osd_thandle, ot_super);
4881 LASSERT(oh->ot_handle == NULL);
4883 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4884 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4890 * Inserts (key, value) pair in \a dt index object.
4892 * \param dt osd index object
4893 * \param key key for index
4894 * \param rec record reference
4895 * \param th transaction handler
4898 * \retval -ve failure
4900 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
4901 const struct dt_rec *rec,
4902 const struct dt_key *key, struct thandle *th,
4905 struct osd_object *obj = osd_dt_obj(dt);
4906 struct iam_path_descr *ipd;
4907 struct osd_thandle *oh;
4908 struct iam_container *bag;
4909 struct osd_thread_info *oti = osd_oti_get(env);
4910 struct iam_rec *iam_rec;
4914 if (!dt_object_exists(dt))
4917 LINVRNT(osd_invariant(obj));
4918 LASSERT(!dt_object_remote(dt));
4920 bag = &obj->oo_dir->od_container;
4921 LASSERT(bag->ic_object == obj->oo_inode);
4922 LASSERT(th != NULL);
4924 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4926 ipd = osd_idx_ipd_get(env, bag);
4927 if (unlikely(ipd == NULL))
4930 oh = container_of0(th, struct osd_thandle, ot_super);
4931 LASSERT(oh->ot_handle != NULL);
4932 LASSERT(oh->ot_handle->h_transaction != NULL);
4933 if (S_ISDIR(obj->oo_inode->i_mode)) {
4934 iam_rec = (struct iam_rec *)oti->oti_ldp;
4935 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
4936 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
4937 /* pack quota uid/gid */
4938 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4939 key = (const struct dt_key *)&oti->oti_quota_id;
4940 /* pack quota record */
4941 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
4942 iam_rec = (struct iam_rec *)rec;
4944 iam_rec = (struct iam_rec *)rec;
4947 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
4949 osd_ipd_put(env, bag, ipd);
4950 LINVRNT(osd_invariant(obj));
4951 osd_trans_exec_check(env, th, OSD_OT_INSERT);
4956 * Calls ldiskfs_add_entry() to add directory entry
4957 * into the directory. This is required for
4958 * interoperability mode (b11826)
4960 * \retval 0, on success
4961 * \retval -ve, on error
4963 static int __osd_ea_add_rec(struct osd_thread_info *info,
4964 struct osd_object *pobj, struct inode *cinode,
4965 const char *name, const struct lu_fid *fid,
4966 struct htree_lock *hlock, struct thandle *th)
4968 struct ldiskfs_dentry_param *ldp;
4969 struct dentry *child;
4970 struct osd_thandle *oth;
4973 oth = container_of(th, struct osd_thandle, ot_super);
4974 LASSERT(oth->ot_handle != NULL);
4975 LASSERT(oth->ot_handle->h_transaction != NULL);
4976 LASSERT(pobj->oo_inode);
4978 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
4979 if (unlikely(pobj->oo_inode ==
4980 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
4983 osd_get_ldiskfs_dirent_param(ldp, fid);
4984 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
4985 child->d_fsdata = (void *)ldp;
4986 ll_vfs_dq_init(pobj->oo_inode);
4987 rc = osd_ldiskfs_add_entry(info, osd_obj2dev(pobj), oth->ot_handle,
4988 child, cinode, hlock);
4989 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
4990 struct ldiskfs_dir_entry_2 *de;
4991 struct buffer_head *bh;
4994 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
4997 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
5000 if (S_ISDIR(cinode->i_mode))
5001 de->file_type = LDISKFS_DIRENT_LUFID |
5002 LDISKFS_FT_REG_FILE;
5004 de->file_type = LDISKFS_DIRENT_LUFID |
5006 ldiskfs_handle_dirty_metadata(oth->ot_handle,
5017 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
5018 * into the directory.Also sets flags into osd object to
5019 * indicate dot and dotdot are created. This is required for
5020 * interoperability mode (b11826)
5022 * \param dir directory for dot and dotdot fixup.
5023 * \param obj child object for linking
5025 * \retval 0, on success
5026 * \retval -ve, on error
5028 static int osd_add_dot_dotdot(struct osd_thread_info *info,
5029 struct osd_object *dir,
5030 struct inode *parent_dir, const char *name,
5031 const struct lu_fid *dot_fid,
5032 const struct lu_fid *dot_dot_fid,
5035 struct inode *inode = dir->oo_inode;
5036 struct osd_thandle *oth;
5039 oth = container_of(th, struct osd_thandle, ot_super);
5040 LASSERT(oth->ot_handle->h_transaction != NULL);
5041 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
5043 if (strcmp(name, dot) == 0) {
5044 if (dir->oo_compat_dot_created) {
5047 LASSERT(inode->i_ino == parent_dir->i_ino);
5048 dir->oo_compat_dot_created = 1;
5051 } else if (strcmp(name, dotdot) == 0) {
5052 if (!dir->oo_compat_dot_created)
5054 /* in case of rename, dotdot is already created */
5055 if (dir->oo_compat_dotdot_created) {
5056 return __osd_ea_add_rec(info, dir, parent_dir, name,
5057 dot_dot_fid, NULL, th);
5060 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
5061 struct lu_fid tfid = *dot_dot_fid;
5064 result = osd_add_dot_dotdot_internal(info,
5065 dir->oo_inode, parent_dir, dot_fid,
5068 result = osd_add_dot_dotdot_internal(info,
5069 dir->oo_inode, parent_dir, dot_fid,
5074 dir->oo_compat_dotdot_created = 1;
5082 * It will call the appropriate osd_add* function and return the
5083 * value, return by respective functions.
5085 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
5086 struct inode *cinode, const char *name,
5087 const struct lu_fid *fid, struct thandle *th)
5089 struct osd_thread_info *info = osd_oti_get(env);
5090 struct htree_lock *hlock;
5093 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
5095 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
5097 if (hlock != NULL) {
5098 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5101 down_write(&pobj->oo_ext_idx_sem);
5104 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
5105 lu_object_fid(&pobj->oo_dt.do_lu),
5108 if (hlock != NULL) {
5109 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5110 pobj->oo_inode, LDISKFS_HLOCK_ADD);
5112 down_write(&pobj->oo_ext_idx_sem);
5115 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
5116 struct lu_fid *tfid = &info->oti_fid;
5120 rc = __osd_ea_add_rec(info, pobj, cinode, name,
5123 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
5128 ldiskfs_htree_unlock(hlock);
5130 up_write(&pobj->oo_ext_idx_sem);
5136 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
5137 struct osd_idmap_cache *oic)
5139 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
5140 struct lu_fid *fid = &oic->oic_fid;
5141 struct osd_inode_id *id = &oic->oic_lid;
5142 struct inode *inode = NULL;
5148 if (!fid_is_norm(fid) && !fid_is_igif(fid))
5151 if (thread_is_running(&scrub->os_thread) &&
5152 scrub->os_pos_current > id->oii_ino)
5155 if (dev->od_auto_scrub_interval == AS_NEVER ||
5156 cfs_time_before(ktime_get_real_seconds(),
5157 scrub->os_file.sf_time_last_complete +
5158 dev->od_auto_scrub_interval))
5162 rc = osd_oi_lookup(oti, dev, fid, &oti->oti_id, 0);
5163 if (rc == -ENOENT) {
5164 __u32 gen = id->oii_gen;
5170 inode = osd_iget(oti, dev, id);
5171 /* The inode has been removed (by race maybe). */
5172 if (IS_ERR(inode)) {
5173 rc = PTR_ERR(inode);
5175 RETURN(rc == -ESTALE ? -ENOENT : rc);
5178 /* The OI mapping is lost. */
5179 if (gen != OSD_OII_NOGEN)
5182 /* The inode may has been reused by others, we do not know,
5183 * leave it to be handled by subsequent osd_fid_lookup(). */
5185 } else if (rc || osd_id_eq(id, &oti->oti_id)) {
5192 if (thread_is_running(&scrub->os_thread)) {
5193 if (inode == NULL) {
5194 inode = osd_iget(oti, dev, id);
5195 /* The inode has been removed (by race maybe). */
5196 if (IS_ERR(inode)) {
5197 rc = PTR_ERR(inode);
5199 RETURN(rc == -ESTALE ? -ENOENT : rc);
5203 rc = osd_oii_insert(dev, oic, insert);
5204 /* There is race condition between osd_oi_lookup and OI scrub.
5205 * The OI scrub finished just after osd_oi_lookup() failure.
5206 * Under such case, it is unnecessary to trigger OI scrub again,
5207 * but try to call osd_oi_lookup() again. */
5208 if (unlikely(rc == -EAGAIN))
5211 if (!S_ISDIR(inode->i_mode))
5214 rc = osd_check_lmv(oti, dev, inode, oic);
5219 if (dev->od_auto_scrub_interval != AS_NEVER && ++once == 1) {
5220 rc = osd_scrub_start(oti->oti_env, dev, SS_AUTO_PARTIAL |
5221 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
5222 CDEBUG(D_LFSCK | D_CONSOLE | D_WARNING,
5223 "%s: trigger partial OI scrub for RPC inconsistency "
5224 "checking FID "DFID": rc = %d\n",
5225 osd_dev2name(dev), PFID(fid), rc);
5226 if (rc == 0 || rc == -EALREADY)
5239 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
5240 struct osd_device *dev,
5241 struct osd_idmap_cache *oic,
5242 struct lu_fid *fid, __u32 ino)
5244 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
5245 struct inode *inode;
5248 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
5249 inode = osd_iget(oti, dev, &oic->oic_lid);
5250 if (IS_ERR(inode)) {
5251 fid_zero(&oic->oic_fid);
5252 return PTR_ERR(inode);
5255 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, loa);
5258 fid_zero(&oic->oic_fid);
5260 *fid = oic->oic_fid = loa->loa_lma.lma_self_fid;
5264 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
5265 struct osd_inode_id *id, const struct lu_fid *fid)
5267 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
5268 id->oii_ino, id->oii_gen, info);
5269 info->oti_cache.oic_lid = *id;
5270 info->oti_cache.oic_fid = *fid;
5271 info->oti_cache.oic_dev = osd;
5275 * Get parent FID from the linkEA.
5277 * For a directory which parent resides on remote MDT, to satisfy the
5278 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
5279 * the other hand, to make the lookup(..) on the directory can return
5280 * the real parent FID, we append the real parent FID after its ".."
5281 * name entry in the /REMOTE_PARENT_DIR.
5283 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
5284 * backup. So after the restore, we cannot get the right parent FID from
5285 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
5286 * we have stored the real parent FID in the directory object's linkEA,
5287 * we can parse the linkEA for the real parent FID.
5289 * \param[in] env pointer to the thread context
5290 * \param[in] obj pointer to the object to be handled
5291 * \param[out]fid pointer to the buffer to hold the parent FID
5293 * \retval 0 for getting the real parent FID successfully
5294 * \retval negative error number on failure
5296 static int osd_get_pfid_from_linkea(const struct lu_env *env,
5297 struct osd_object *obj,
5300 struct osd_thread_info *oti = osd_oti_get(env);
5301 struct lu_buf *buf = &oti->oti_big_buf;
5302 struct dentry *dentry = &oti->oti_obj_dentry;
5303 struct inode *inode = obj->oo_inode;
5304 struct linkea_data ldata = { NULL };
5309 if (!S_ISDIR(inode->i_mode))
5313 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
5314 buf->lb_buf, buf->lb_len);
5315 if (rc == -ERANGE) {
5316 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
5319 lu_buf_realloc(buf, rc);
5320 if (buf->lb_buf == NULL)
5327 if (unlikely(rc == 0))
5333 if (unlikely(buf->lb_buf == NULL)) {
5334 lu_buf_realloc(buf, rc);
5335 if (buf->lb_buf == NULL)
5342 rc = linkea_init_with_rec(&ldata);
5344 linkea_first_entry(&ldata);
5345 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
5351 static int osd_verify_ent_by_linkea(const struct lu_env *env,
5352 struct inode *inode,
5353 const struct lu_fid *pfid,
5354 const char *name, const int namelen)
5356 struct osd_thread_info *oti = osd_oti_get(env);
5357 struct lu_buf *buf = &oti->oti_big_buf;
5358 struct dentry *dentry = &oti->oti_obj_dentry;
5359 struct linkea_data ldata = { NULL };
5360 struct lu_name cname = { .ln_name = name,
5361 .ln_namelen = namelen };
5366 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
5367 buf->lb_buf, buf->lb_len);
5369 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK, NULL, 0);
5374 if (unlikely(rc == 0))
5377 if (buf->lb_len < rc) {
5378 lu_buf_realloc(buf, rc);
5379 if (buf->lb_buf == NULL)
5386 rc = linkea_init_with_rec(&ldata);
5388 rc = linkea_links_find(&ldata, &cname, pfid);
5394 * Calls ->lookup() to find dentry. From dentry get inode and
5395 * read inode's ea to get fid. This is required for interoperability
5398 * \retval 0, on success
5399 * \retval -ve, on error
5401 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
5402 struct dt_rec *rec, const struct dt_key *key)
5404 struct inode *dir = obj->oo_inode;
5405 struct dentry *dentry;
5406 struct ldiskfs_dir_entry_2 *de;
5407 struct buffer_head *bh;
5408 struct lu_fid *fid = (struct lu_fid *) rec;
5409 struct htree_lock *hlock = NULL;
5414 LASSERT(dir->i_op != NULL);
5415 LASSERT(dir->i_op->lookup != NULL);
5417 dentry = osd_child_dentry_get(env, obj,
5418 (char *)key, strlen((char *)key));
5420 if (obj->oo_hl_head != NULL) {
5421 hlock = osd_oti_get(env)->oti_hlock;
5422 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
5423 dir, LDISKFS_HLOCK_LOOKUP);
5425 down_read(&obj->oo_ext_idx_sem);
5428 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5430 struct osd_thread_info *oti = osd_oti_get(env);
5431 struct osd_inode_id *id = &oti->oti_id;
5432 struct osd_idmap_cache *oic = &oti->oti_cache;
5433 struct osd_device *dev = osd_obj2dev(obj);
5435 ino = le32_to_cpu(de->inode);
5436 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
5438 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
5442 rc = osd_get_fid_from_dentry(de, rec);
5444 /* done with de, release bh */
5447 if (unlikely(ino == osd_remote_parent_ino(dev))) {
5448 const char *name = (const char *)key;
5450 /* If the parent is on remote MDT, and there
5451 * is no FID-in-dirent, then we have to get
5452 * the parent FID from the linkEA. */
5453 if (likely(strlen(name) == 2 &&
5454 name[0] == '.' && name[1] == '.'))
5455 rc = osd_get_pfid_from_linkea(env, obj,
5458 rc = osd_ea_fid_get(env, obj, ino, fid, id);
5461 osd_id_gen(id, ino, OSD_OII_NOGEN);
5464 if (rc != 0 || osd_remote_fid(env, dev, fid)) {
5465 fid_zero(&oic->oic_fid);
5470 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
5471 rc = osd_consistency_check(oti, dev, oic);
5473 fid_zero(&oic->oic_fid);
5475 /* Other error should not affect lookup result. */
5485 ldiskfs_htree_unlock(hlock);
5487 up_read(&obj->oo_ext_idx_sem);
5491 static int osd_index_declare_ea_insert(const struct lu_env *env,
5492 struct dt_object *dt,
5493 const struct dt_rec *rec,
5494 const struct dt_key *key,
5495 struct thandle *handle)
5497 struct osd_thandle *oh;
5498 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
5499 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
5500 const struct lu_fid *fid = rec1->rec_fid;
5501 int credits, rc = 0;
5502 struct osd_idmap_cache *idc;
5505 LASSERT(!dt_object_remote(dt));
5506 LASSERT(handle != NULL);
5507 LASSERT(fid != NULL);
5508 LASSERT(rec1->rec_type != 0);
5510 oh = container_of0(handle, struct osd_thandle, ot_super);
5511 LASSERT(oh->ot_handle == NULL);
5513 credits = osd_dto_credits_noquota[DTO_INDEX_INSERT];
5515 /* we can't call iget() while a transactions is running
5516 * (this can lead to a deadlock), but we need to know
5517 * inum and object type. so we find this information at
5518 * declaration and cache in per-thread info */
5519 idc = osd_idc_find_or_init(env, osd, fid);
5521 RETURN(PTR_ERR(idc));
5522 if (idc->oic_remote) {
5523 /* a reference to remote inode is represented by an
5524 * agent inode which we have to create */
5525 credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
5526 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
5529 osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits);
5531 if (osd_dt_obj(dt)->oo_inode != NULL) {
5532 struct inode *inode = osd_dt_obj(dt)->oo_inode;
5534 /* We ignore block quota on meta pool (MDTs), so needn't
5535 * calculate how many blocks will be consumed by this index
5537 rc = osd_declare_inode_qid(env, i_uid_read(inode),
5539 i_projid_read(inode), 0,
5540 oh, osd_dt_obj(dt), NULL,
5545 #ifdef HAVE_PROJECT_QUOTA
5546 /* Reserve credits for local agent inode to transfer
5547 * to 0, quota enforcement is ignored in this case.
5549 if (idc->oic_remote &&
5550 LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
5551 i_projid_read(inode) != 0)
5552 rc = osd_declare_attr_qid(env, osd_dt_obj(dt), oh,
5553 0, i_projid_read(inode),
5554 0, false, PRJQUOTA);
5563 * Index add function for interoperability mode (b11826).
5564 * It will add the directory entry.This entry is needed to
5565 * maintain name->fid mapping.
5567 * \param key it is key i.e. file entry to be inserted
5568 * \param rec it is value of given key i.e. fid
5570 * \retval 0, on success
5571 * \retval -ve, on error
5573 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
5574 const struct dt_rec *rec,
5575 const struct dt_key *key, struct thandle *th,
5578 struct osd_object *obj = osd_dt_obj(dt);
5579 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
5580 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
5581 const struct lu_fid *fid = rec1->rec_fid;
5582 const char *name = (const char *)key;
5583 struct osd_thread_info *oti = osd_oti_get(env);
5584 struct inode *child_inode = NULL;
5585 struct osd_idmap_cache *idc;
5589 if (!dt_object_exists(dt))
5592 LASSERT(osd_invariant(obj));
5593 LASSERT(!dt_object_remote(dt));
5594 LASSERT(th != NULL);
5596 osd_trans_exec_op(env, th, OSD_OT_INSERT);
5598 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
5600 idc = osd_idc_find(env, osd, fid);
5601 if (unlikely(idc == NULL)) {
5602 /* this dt_insert() wasn't declared properly, so
5603 * FID is missing in OI cache. we better do not
5604 * lookup FID in FLDB/OI and don't risk to deadlock,
5605 * but in some special cases (lfsck testing, etc)
5606 * it's much simpler than fixing a caller */
5607 CERROR("%s: "DFID" wasn't declared for insert\n",
5608 osd_name(osd), PFID(fid));
5610 idc = osd_idc_find_or_init(env, osd, fid);
5612 RETURN(PTR_ERR(idc));
5615 if (idc->oic_remote) {
5616 /* Insert remote entry */
5617 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
5619 igrab(osd->od_mdt_map->omm_remote_parent->d_inode);
5621 child_inode = osd_create_local_agent_inode(env, osd,
5622 obj, fid, rec1->rec_type & S_IFMT, th);
5623 if (IS_ERR(child_inode))
5624 RETURN(PTR_ERR(child_inode));
5627 /* Insert local entry */
5628 if (unlikely(idc->oic_lid.oii_ino == 0)) {
5629 /* for a reason OI cache wasn't filled properly */
5630 CERROR("%s: OIC for "DFID" isn't filled\n",
5631 osd_name(osd), PFID(fid));
5634 child_inode = oti->oti_inode;
5635 if (unlikely(child_inode == NULL)) {
5636 struct ldiskfs_inode_info *lii;
5640 child_inode = oti->oti_inode = &lii->vfs_inode;
5642 child_inode->i_sb = osd_sb(osd);
5643 child_inode->i_ino = idc->oic_lid.oii_ino;
5644 child_inode->i_mode = rec1->rec_type & S_IFMT;
5647 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
5649 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
5650 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
5652 if (child_inode && child_inode != oti->oti_inode)
5654 LASSERT(osd_invariant(obj));
5655 osd_trans_exec_check(env, th, OSD_OT_INSERT);
5660 * Initialize osd Iterator for given osd index object.
5662 * \param dt osd index object
5665 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
5666 struct dt_object *dt,
5669 struct osd_it_iam *it;
5670 struct osd_object *obj = osd_dt_obj(dt);
5671 struct lu_object *lo = &dt->do_lu;
5672 struct iam_path_descr *ipd;
5673 struct iam_container *bag = &obj->oo_dir->od_container;
5675 if (!dt_object_exists(dt))
5676 return ERR_PTR(-ENOENT);
5680 return ERR_PTR(-ENOMEM);
5682 ipd = osd_it_ipd_get(env, bag);
5683 if (likely(ipd != NULL)) {
5687 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
5688 return (struct dt_it *)it;
5691 return ERR_PTR(-ENOMEM);
5696 * free given Iterator.
5698 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
5700 struct osd_it_iam *it = (struct osd_it_iam *)di;
5701 struct osd_object *obj = it->oi_obj;
5703 iam_it_fini(&it->oi_it);
5704 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
5705 osd_object_put(env, obj);
5710 * Move Iterator to record specified by \a key
5712 * \param di osd iterator
5713 * \param key key for index
5715 * \retval +ve di points to record with least key not larger than key
5716 * \retval 0 di points to exact matched key
5717 * \retval -ve failure
5720 static int osd_it_iam_get(const struct lu_env *env,
5721 struct dt_it *di, const struct dt_key *key)
5723 struct osd_thread_info *oti = osd_oti_get(env);
5724 struct osd_it_iam *it = (struct osd_it_iam *)di;
5726 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
5727 /* swab quota uid/gid */
5728 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5729 key = (struct dt_key *)&oti->oti_quota_id;
5732 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
5738 * \param di osd iterator
5740 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
5742 struct osd_it_iam *it = (struct osd_it_iam *)di;
5744 iam_it_put(&it->oi_it);
5748 * Move iterator by one record
5750 * \param di osd iterator
5752 * \retval +1 end of container reached
5754 * \retval -ve failure
5757 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
5759 struct osd_it_iam *it = (struct osd_it_iam *)di;
5761 return iam_it_next(&it->oi_it);
5765 * Return pointer to the key under iterator.
5768 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
5769 const struct dt_it *di)
5771 struct osd_thread_info *oti = osd_oti_get(env);
5772 struct osd_it_iam *it = (struct osd_it_iam *)di;
5773 struct osd_object *obj = it->oi_obj;
5776 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
5778 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
5779 /* swab quota uid/gid */
5780 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
5781 key = (struct dt_key *)&oti->oti_quota_id;
5788 * Return size of key under iterator (in bytes)
5791 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
5793 struct osd_it_iam *it = (struct osd_it_iam *)di;
5795 return iam_it_key_size(&it->oi_it);
5799 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
5801 /* check if file type is required */
5802 if (ent->lde_attrs & LUDA_TYPE) {
5803 struct luda_type *lt;
5804 int align = sizeof(*lt) - 1;
5806 len = (len + align) & ~align;
5807 lt = (struct luda_type *)(ent->lde_name + len);
5808 lt->lt_type = cpu_to_le16(DTTOIF(type));
5811 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
5815 * build lu direct from backend fs dirent.
5819 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
5820 char *name, __u16 namelen, __u16 type, __u32 attr)
5822 ent->lde_attrs = attr | LUDA_FID;
5823 fid_cpu_to_le(&ent->lde_fid, fid);
5825 ent->lde_hash = cpu_to_le64(offset);
5826 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
5828 strncpy(ent->lde_name, name, namelen);
5829 ent->lde_name[namelen] = '\0';
5830 ent->lde_namelen = cpu_to_le16(namelen);
5832 /* append lustre attributes */
5833 osd_it_append_attrs(ent, namelen, type);
5837 * Return pointer to the record under iterator.
5839 static int osd_it_iam_rec(const struct lu_env *env,
5840 const struct dt_it *di,
5841 struct dt_rec *dtrec, __u32 attr)
5843 struct osd_it_iam *it = (struct osd_it_iam *)di;
5844 struct osd_thread_info *info = osd_oti_get(env);
5847 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
5848 const struct osd_fid_pack *rec;
5849 struct lu_fid *fid = &info->oti_fid;
5850 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5856 name = (char *)iam_it_key_get(&it->oi_it);
5858 RETURN(PTR_ERR(name));
5860 namelen = iam_it_key_size(&it->oi_it);
5862 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
5864 RETURN(PTR_ERR(rec));
5866 rc = osd_fid_unpack(fid, rec);
5870 hash = iam_it_store(&it->oi_it);
5872 /* IAM does not store object type in IAM index (dir) */
5873 osd_it_pack_dirent(lde, fid, hash, name, namelen,
5875 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
5876 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
5877 (struct iam_rec *)dtrec);
5878 osd_quota_unpack(it->oi_obj, dtrec);
5880 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
5881 (struct iam_rec *)dtrec);
5888 * Returns cookie for current Iterator position.
5890 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
5892 struct osd_it_iam *it = (struct osd_it_iam *)di;
5894 return iam_it_store(&it->oi_it);
5898 * Restore iterator from cookie.
5900 * \param di osd iterator
5901 * \param hash Iterator location cookie
5903 * \retval +ve di points to record with least key not larger than key.
5904 * \retval 0 di points to exact matched key
5905 * \retval -ve failure
5908 static int osd_it_iam_load(const struct lu_env *env,
5909 const struct dt_it *di, __u64 hash)
5911 struct osd_it_iam *it = (struct osd_it_iam *)di;
5913 return iam_it_load(&it->oi_it, hash);
5916 static const struct dt_index_operations osd_index_iam_ops = {
5917 .dio_lookup = osd_index_iam_lookup,
5918 .dio_declare_insert = osd_index_declare_iam_insert,
5919 .dio_insert = osd_index_iam_insert,
5920 .dio_declare_delete = osd_index_declare_iam_delete,
5921 .dio_delete = osd_index_iam_delete,
5923 .init = osd_it_iam_init,
5924 .fini = osd_it_iam_fini,
5925 .get = osd_it_iam_get,
5926 .put = osd_it_iam_put,
5927 .next = osd_it_iam_next,
5928 .key = osd_it_iam_key,
5929 .key_size = osd_it_iam_key_size,
5930 .rec = osd_it_iam_rec,
5931 .store = osd_it_iam_store,
5932 .load = osd_it_iam_load
5938 * Creates or initializes iterator context.
5940 * \retval struct osd_it_ea, iterator structure on success
5943 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
5944 struct dt_object *dt,
5947 struct osd_object *obj = osd_dt_obj(dt);
5948 struct osd_thread_info *info = osd_oti_get(env);
5949 struct osd_it_ea *oie;
5951 struct lu_object *lo = &dt->do_lu;
5952 struct dentry *obj_dentry;
5955 if (!dt_object_exists(dt) || obj->oo_destroyed)
5956 RETURN(ERR_PTR(-ENOENT));
5958 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
5960 RETURN(ERR_PTR(-ENOMEM));
5961 obj_dentry = &oie->oie_dentry;
5963 obj_dentry->d_inode = obj->oo_inode;
5964 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
5965 obj_dentry->d_name.hash = 0;
5967 oie->oie_rd_dirent = 0;
5968 oie->oie_it_dirent = 0;
5969 oie->oie_dirent = NULL;
5970 if (unlikely(!info->oti_it_ea_buf_used)) {
5971 oie->oie_buf = info->oti_it_ea_buf;
5972 info->oti_it_ea_buf_used = 1;
5974 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
5975 if (oie->oie_buf == NULL)
5976 RETURN(ERR_PTR(-ENOMEM));
5980 file = &oie->oie_file;
5982 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
5983 if (attr & LUDA_64BITHASH)
5984 file->f_mode = FMODE_64BITHASH;
5986 file->f_mode = FMODE_32BITHASH;
5987 file->f_path.dentry = obj_dentry;
5988 file->f_mapping = obj->oo_inode->i_mapping;
5989 file->f_op = obj->oo_inode->i_fop;
5990 set_file_inode(file, obj->oo_inode);
5993 RETURN((struct dt_it *) oie);
5997 * Destroy or finishes iterator context.
5999 * \param di iterator structure to be destroyed
6001 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
6003 struct osd_thread_info *info = osd_oti_get(env);
6004 struct osd_it_ea *oie = (struct osd_it_ea *)di;
6005 struct osd_object *obj = oie->oie_obj;
6006 struct inode *inode = obj->oo_inode;
6009 oie->oie_file.f_op->release(inode, &oie->oie_file);
6010 osd_object_put(env, obj);
6011 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
6012 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
6014 info->oti_it_ea_buf_used = 0;
6015 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
6020 * It position the iterator at given key, so that next lookup continues from
6021 * that key Or it is similar to dio_it->load() but based on a key,
6022 * rather than file position.
6024 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
6027 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
6029 static int osd_it_ea_get(const struct lu_env *env,
6030 struct dt_it *di, const struct dt_key *key)
6032 struct osd_it_ea *it = (struct osd_it_ea *)di;
6035 LASSERT(((const char *)key)[0] == '\0');
6036 it->oie_file.f_pos = 0;
6037 it->oie_rd_dirent = 0;
6038 it->oie_it_dirent = 0;
6039 it->oie_dirent = NULL;
6047 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
6051 struct osd_filldir_cbs {
6052 #ifdef HAVE_DIR_CONTEXT
6053 struct dir_context ctx;
6055 struct osd_it_ea *it;
6058 * It is called internally by ->readdir(). It fills the
6059 * iterator's in-memory data structure with required
6060 * information i.e. name, namelen, rec_size etc.
6062 * \param buf in which information to be filled in.
6063 * \param name name of the file in given dir
6065 * \retval 0 on success
6066 * \retval 1 on buffer full
6068 #ifdef HAVE_FILLDIR_USE_CTX
6069 static int osd_ldiskfs_filldir(struct dir_context *buf,
6071 static int osd_ldiskfs_filldir(void *buf,
6073 const char *name, int namelen,
6074 loff_t offset, __u64 ino, unsigned d_type)
6076 struct osd_it_ea *it =
6077 ((struct osd_filldir_cbs *)buf)->it;
6078 struct osd_object *obj = it->oie_obj;
6079 struct osd_it_ea_dirent *ent = it->oie_dirent;
6080 struct lu_fid *fid = &ent->oied_fid;
6081 struct osd_fid_pack *rec;
6084 /* this should never happen */
6085 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
6086 CERROR("ldiskfs return invalid namelen %d\n", namelen);
6090 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
6094 /* "." is just the object itself. */
6095 if (namelen == 1 && name[0] == '.') {
6096 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6097 } else if (d_type & LDISKFS_DIRENT_LUFID) {
6098 rec = (struct osd_fid_pack*) (name + namelen + 1);
6099 if (osd_fid_unpack(fid, rec) != 0)
6104 d_type &= ~LDISKFS_DIRENT_LUFID;
6106 /* NOT export local root. */
6107 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
6108 ino = obj->oo_inode->i_ino;
6109 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6112 ent->oied_ino = ino;
6113 ent->oied_off = offset;
6114 ent->oied_namelen = namelen;
6115 ent->oied_type = d_type;
6117 memcpy(ent->oied_name, name, namelen);
6119 it->oie_rd_dirent++;
6120 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
6125 * Calls ->readdir() to load a directory entry at a time
6126 * and stored it in iterator's in-memory data structure.
6128 * \param di iterator's in memory structure
6130 * \retval 0 on success
6131 * \retval -ve on error
6132 * \retval +1 reach the end of entry
6134 static int osd_ldiskfs_it_fill(const struct lu_env *env,
6135 const struct dt_it *di)
6137 struct osd_it_ea *it = (struct osd_it_ea *)di;
6138 struct osd_object *obj = it->oie_obj;
6139 struct inode *inode = obj->oo_inode;
6140 struct htree_lock *hlock = NULL;
6141 struct file *filp = &it->oie_file;
6143 struct osd_filldir_cbs buf = {
6144 #ifdef HAVE_DIR_CONTEXT
6145 .ctx.actor = osd_ldiskfs_filldir,
6151 it->oie_dirent = it->oie_buf;
6152 it->oie_rd_dirent = 0;
6154 if (obj->oo_hl_head != NULL) {
6155 hlock = osd_oti_get(env)->oti_hlock;
6156 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
6157 inode, LDISKFS_HLOCK_READDIR);
6159 down_read(&obj->oo_ext_idx_sem);
6162 #ifdef HAVE_DIR_CONTEXT
6163 buf.ctx.pos = filp->f_pos;
6164 rc = inode->i_fop->iterate(filp, &buf.ctx);
6165 filp->f_pos = buf.ctx.pos;
6167 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
6171 ldiskfs_htree_unlock(hlock);
6173 up_read(&obj->oo_ext_idx_sem);
6175 if (it->oie_rd_dirent == 0) {
6176 /*If it does not get any dirent, it means it has been reached
6177 *to the end of the dir */
6178 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
6182 it->oie_dirent = it->oie_buf;
6183 it->oie_it_dirent = 1;
6190 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
6191 * to load a directory entry at a time and stored it in
6192 * iterator's in-memory data structure.
6194 * \param di iterator's in memory structure
6196 * \retval +ve iterator reached to end
6197 * \retval 0 iterator not reached to end
6198 * \retval -ve on error
6200 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
6202 struct osd_it_ea *it = (struct osd_it_ea *)di;
6207 if (it->oie_it_dirent < it->oie_rd_dirent) {
6209 (void *) it->oie_dirent +
6210 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
6211 it->oie_dirent->oied_namelen);
6212 it->oie_it_dirent++;
6215 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
6218 rc = osd_ldiskfs_it_fill(env, di);
6225 * Returns the key at current position from iterator's in memory structure.
6227 * \param di iterator's in memory structure
6229 * \retval key i.e. struct dt_key on success
6231 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
6232 const struct dt_it *di)
6234 struct osd_it_ea *it = (struct osd_it_ea *)di;
6236 return (struct dt_key *)it->oie_dirent->oied_name;
6240 * Returns the key's size at current position from iterator's in memory structure.
6242 * \param di iterator's in memory structure
6244 * \retval key_size i.e. struct dt_key on success
6246 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
6248 struct osd_it_ea *it = (struct osd_it_ea *)di;
6250 return it->oie_dirent->oied_namelen;
6253 static inline bool osd_dotdot_has_space(struct ldiskfs_dir_entry_2 *de)
6255 if (LDISKFS_DIR_REC_LEN(de) >=
6256 __LDISKFS_DIR_REC_LEN(2 + 1 + sizeof(struct osd_fid_pack)))
6263 osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen,
6264 unsigned blocksize, bool dotdot)
6267 return osd_dotdot_has_space(de);
6269 if (ldiskfs_rec_len_from_disk(de->rec_len, blocksize) >=
6270 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
6277 osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev,
6278 handle_t *jh, struct dentry *dentry,
6279 const struct lu_fid *fid, struct buffer_head *bh,
6280 struct ldiskfs_dir_entry_2 *de, struct htree_lock *hlock,
6283 struct inode *dir = dentry->d_parent->d_inode;
6284 struct inode *inode = dentry->d_inode;
6285 struct osd_fid_pack *rec;
6286 struct ldiskfs_dentry_param *ldp;
6287 int namelen = dentry->d_name.len;
6289 struct osd_thread_info *info = osd_oti_get(env);
6292 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
6293 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
6296 /* There is enough space to hold the FID-in-dirent. */
6297 if (osd_dirent_has_space(de, namelen, dir->i_sb->s_blocksize, dotdot)) {
6298 rc = ldiskfs_journal_get_write_access(jh, bh);
6302 de->name[namelen] = 0;
6303 rec = (struct osd_fid_pack *)(de->name + namelen + 1);
6304 rec->fp_len = sizeof(struct lu_fid) + 1;
6305 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
6306 de->file_type |= LDISKFS_DIRENT_LUFID;
6307 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
6314 rc = ldiskfs_delete_entry(jh, dir, de, bh);
6318 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
6319 osd_get_ldiskfs_dirent_param(ldp, fid);
6320 dentry->d_fsdata = (void *)ldp;
6321 ll_vfs_dq_init(dir);
6322 rc = osd_ldiskfs_add_entry(info, dev, jh, dentry, inode, hlock);
6323 /* It is too bad, we cannot reinsert the name entry back.
6324 * That means we lose it! */
6326 CDEBUG(D_LFSCK, "%s: fail to reinsert the dirent, "
6327 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
6328 osd_ino2name(inode),
6329 dir->i_ino, dir->i_generation, namelen,
6330 dentry->d_name.name, PFID(fid), rc);
6336 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
6337 struct osd_it_ea *it, struct lu_fid *fid,
6338 struct osd_inode_id *id, __u32 *attr)
6340 struct osd_thread_info *info = osd_oti_get(env);
6341 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
6342 struct osd_device *dev = osd_obj2dev(obj);
6343 struct super_block *sb = osd_sb(dev);
6344 const char *devname = osd_name(dev);
6345 struct osd_it_ea_dirent *ent = it->oie_dirent;
6346 struct inode *dir = obj->oo_inode;
6347 struct htree_lock *hlock = NULL;
6348 struct buffer_head *bh = NULL;
6349 handle_t *jh = NULL;
6350 struct ldiskfs_dir_entry_2 *de;
6351 struct dentry *dentry;
6352 struct inode *inode;
6353 const struct lu_fid *pfid = lu_object_fid(&obj->oo_dt.do_lu);
6356 bool dotdot = false;
6360 if (ent->oied_name[0] == '.') {
6361 if (ent->oied_namelen == 1)
6364 if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
6368 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
6369 inode = osd_iget(info, dev, id);
6370 if (IS_ERR(inode)) {
6371 rc = PTR_ERR(inode);
6372 if (rc == -ENOENT || rc == -ESTALE) {
6373 /* Maybe dangling name entry, or
6374 * corrupted directory entry. */
6375 *attr |= LUDA_UNKNOWN;
6378 CDEBUG(D_LFSCK, "%s: fail to iget() for dirent "
6379 "check_repair, dir = %lu/%u, name = %.*s, "
6380 "ino = %llu, rc = %d\n",
6381 devname, dir->i_ino, dir->i_generation,
6382 ent->oied_namelen, ent->oied_name,
6389 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
6391 rc = osd_get_lma(info, inode, dentry, &info->oti_ost_attrs);
6392 if (rc == -ENODATA || !fid_is_sane(&lma->lma_self_fid))
6397 /* We need to ensure that the name entry is still valid.
6398 * Because it may be removed or renamed by other already.
6400 * The unlink or rename operation will start journal before PDO lock,
6401 * so to avoid deadlock, here we need to start journal handle before
6402 * related PDO lock also. But because we do not know whether there
6403 * will be something to be repaired before PDO lock, we just start
6404 * journal without conditions.
6406 * We may need to remove the name entry firstly, then insert back.
6407 * One credit is for user quota file update.
6408 * One credit is for group quota file update.
6409 * Two credits are for dirty inode. */
6410 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
6411 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
6413 if (dev->od_dirent_journal != 0) {
6416 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
6419 CDEBUG(D_LFSCK, "%s: fail to start trans for dirent "
6420 "check_repair, dir = %lu/%u, credits = %d, "
6421 "name = %.*s, ino = %llu: rc = %d\n",
6422 devname, dir->i_ino, dir->i_generation, credits,
6423 ent->oied_namelen, ent->oied_name,
6426 GOTO(out_inode, rc);
6429 if (obj->oo_hl_head != NULL) {
6430 hlock = osd_oti_get(env)->oti_hlock;
6431 /* "0" means exclusive lock for the whole directory.
6432 * We need to prevent others access such name entry
6433 * during the delete + insert. Neither HLOCK_ADD nor
6434 * HLOCK_DEL cannot guarantee the atomicity. */
6435 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
6437 down_write(&obj->oo_ext_idx_sem);
6440 if (obj->oo_hl_head != NULL) {
6441 hlock = osd_oti_get(env)->oti_hlock;
6442 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
6443 LDISKFS_HLOCK_LOOKUP);
6445 down_read(&obj->oo_ext_idx_sem);
6449 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
6450 if (IS_ERR(bh) || le32_to_cpu(de->inode) != inode->i_ino) {
6451 *attr |= LUDA_IGNORE;
6456 /* For dotdot entry, if there is not enough space to hold the
6457 * FID-in-dirent, just keep them there. It only happens when the
6458 * device upgraded from 1.8 or restored from MDT file-level backup.
6459 * For the whole directory, only dotdot entry have no FID-in-dirent
6460 * and needs to get FID from LMA when readdir, it will not affect the
6461 * performance much. */
6462 if (dotdot && !osd_dotdot_has_space(de)) {
6463 *attr |= LUDA_UNKNOWN;
6469 if (lu_fid_eq(fid, &lma->lma_self_fid))
6472 if (unlikely(lma->lma_compat & LMAC_NOT_IN_OI)) {
6473 struct lu_fid *tfid = &lma->lma_self_fid;
6475 if (likely(dotdot &&
6476 fid_seq(tfid) == FID_SEQ_LOCAL_FILE &&
6477 fid_oid(tfid) == REMOTE_PARENT_DIR_OID)) {
6478 /* It must be REMOTE_PARENT_DIR and as the
6479 * 'dotdot' entry of remote directory */
6480 *attr |= LUDA_IGNORE;
6482 CDEBUG(D_LFSCK, "%s: expect remote agent "
6483 "parent directory, but got %.*s under "
6484 "dir = %lu/%u with the FID "DFID"\n",
6485 devname, ent->oied_namelen,
6486 ent->oied_name, dir->i_ino,
6487 dir->i_generation, PFID(tfid));
6489 *attr |= LUDA_UNKNOWN;
6496 if (!fid_is_zero(fid)) {
6497 rc = osd_verify_ent_by_linkea(env, inode, pfid, ent->oied_name,
6499 if (rc == -ENOENT ||
6501 !(dev->od_scrub.os_scrub.os_file.sf_flags & SF_UPGRADE))) {
6502 /* linkEA does not recognize the dirent entry,
6503 * it may because the dirent entry corruption
6504 * and points to other's inode. */
6505 CDEBUG(D_LFSCK, "%s: the target inode does not "
6506 "recognize the dirent, dir = %lu/%u, "
6507 " name = %.*s, ino = %llu, "
6508 DFID": rc = %d\n", devname, dir->i_ino,
6509 dir->i_generation, ent->oied_namelen,
6510 ent->oied_name, ent->oied_ino, PFID(fid), rc);
6511 *attr |= LUDA_UNKNOWN;
6516 if (rc && rc != -ENODATA) {
6517 CDEBUG(D_LFSCK, "%s: fail to verify FID in the dirent, "
6518 "dir = %lu/%u, name = %.*s, ino = %llu, "
6519 DFID": rc = %d\n", devname, dir->i_ino,
6520 dir->i_generation, ent->oied_namelen,
6521 ent->oied_name, ent->oied_ino, PFID(fid), rc);
6522 *attr |= LUDA_UNKNOWN;
6529 /* linkEA recognizes the dirent entry, the FID-in-LMA is
6530 * valid, trusted, in spite of fid_is_sane(fid) or not. */
6531 if (*attr & LUDA_VERIFY_DRYRUN) {
6532 *fid = lma->lma_self_fid;
6533 *attr |= LUDA_REPAIR;
6540 dev->od_dirent_journal = 1;
6541 if (hlock != NULL) {
6542 ldiskfs_htree_unlock(hlock);
6545 up_read(&obj->oo_ext_idx_sem);
6551 *fid = lma->lma_self_fid;
6553 /* Update or append the FID-in-dirent. */
6554 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
6555 bh, de, hlock, dotdot);
6557 *attr |= LUDA_REPAIR;
6559 CDEBUG(D_LFSCK, "%s: fail to re-insert FID after "
6560 "the dirent, dir = %lu/%u, name = %.*s, "
6561 "ino = %llu, "DFID": rc = %d\n",
6562 devname, dir->i_ino, dir->i_generation,
6563 ent->oied_namelen, ent->oied_name,
6564 ent->oied_ino, PFID(fid), rc);
6566 /* lma is NULL, trust the FID-in-dirent if it is valid. */
6567 if (*attr & LUDA_VERIFY_DRYRUN) {
6568 if (fid_is_sane(fid)) {
6569 *attr |= LUDA_REPAIR;
6570 } else if (dev->od_index == 0) {
6571 lu_igif_build(fid, inode->i_ino,
6572 inode->i_generation);
6573 *attr |= LUDA_UPGRADE;
6581 dev->od_dirent_journal = 1;
6582 if (hlock != NULL) {
6583 ldiskfs_htree_unlock(hlock);
6586 up_read(&obj->oo_ext_idx_sem);
6593 if (unlikely(fid_is_sane(fid))) {
6594 /* FID-in-dirent exists, but FID-in-LMA is lost.
6595 * Trust the FID-in-dirent, and add FID-in-LMA. */
6596 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
6598 *attr |= LUDA_REPAIR;
6600 CDEBUG(D_LFSCK, "%s: fail to set LMA for "
6601 "update dirent, dir = %lu/%u, "
6602 "name = %.*s, ino = %llu, "
6604 devname, dir->i_ino, dir->i_generation,
6605 ent->oied_namelen, ent->oied_name,
6606 ent->oied_ino, PFID(fid), rc);
6607 } else if (dev->od_index == 0) {
6608 lu_igif_build(fid, inode->i_ino, inode->i_generation);
6609 /* It is probably IGIF object. Only aappend the
6610 * FID-in-dirent. OI scrub will process FID-in-LMA. */
6611 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
6612 bh, de, hlock, dotdot);
6614 *attr |= LUDA_UPGRADE;
6616 CDEBUG(D_LFSCK, "%s: fail to append IGIF "
6617 "after the dirent, dir = %lu/%u, "
6618 "name = %.*s, ino = %llu, "
6620 devname, dir->i_ino, dir->i_generation,
6621 ent->oied_namelen, ent->oied_name,
6622 ent->oied_ino, PFID(fid), rc);
6631 if (hlock != NULL) {
6632 ldiskfs_htree_unlock(hlock);
6634 if (dev->od_dirent_journal != 0)
6635 up_write(&obj->oo_ext_idx_sem);
6637 up_read(&obj->oo_ext_idx_sem);
6641 ldiskfs_journal_stop(jh);
6645 if (rc >= 0 && !dirty)
6646 dev->od_dirent_journal = 0;
6652 * Returns the value at current position from iterator's in memory structure.
6654 * \param di struct osd_it_ea, iterator's in memory structure
6655 * \param attr attr requested for dirent.
6656 * \param lde lustre dirent
6658 * \retval 0 no error and \param lde has correct lustre dirent.
6659 * \retval -ve on error
6661 static inline int osd_it_ea_rec(const struct lu_env *env,
6662 const struct dt_it *di,
6663 struct dt_rec *dtrec, __u32 attr)
6665 struct osd_it_ea *it = (struct osd_it_ea *)di;
6666 struct osd_object *obj = it->oie_obj;
6667 struct osd_device *dev = osd_obj2dev(obj);
6668 struct osd_thread_info *oti = osd_oti_get(env);
6669 struct osd_inode_id *id = &oti->oti_id;
6670 struct lu_fid *fid = &it->oie_dirent->oied_fid;
6671 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
6672 __u32 ino = it->oie_dirent->oied_ino;
6676 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
6678 if (attr & LUDA_VERIFY) {
6679 if (unlikely(ino == osd_remote_parent_ino(dev))) {
6680 attr |= LUDA_IGNORE;
6681 /* If the parent is on remote MDT, and there
6682 * is no FID-in-dirent, then we have to get
6683 * the parent FID from the linkEA. */
6684 if (!fid_is_sane(fid) &&
6685 it->oie_dirent->oied_namelen == 2 &&
6686 it->oie_dirent->oied_name[0] == '.' &&
6687 it->oie_dirent->oied_name[1] == '.')
6688 osd_get_pfid_from_linkea(env, obj, fid);
6690 rc = osd_dirent_check_repair(env, obj, it, fid, id,
6694 if (!fid_is_sane(fid))
6695 attr |= LUDA_UNKNOWN;
6697 attr &= ~LU_DIRENT_ATTRS_MASK;
6698 if (!fid_is_sane(fid)) {
6699 bool is_dotdot = false;
6700 if (it->oie_dirent->oied_namelen == 2 &&
6701 it->oie_dirent->oied_name[0] == '.' &&
6702 it->oie_dirent->oied_name[1] == '.')
6704 /* If the parent is on remote MDT, and there
6705 * is no FID-in-dirent, then we have to get
6706 * the parent FID from the linkEA. */
6707 if (ino == osd_remote_parent_ino(dev) && is_dotdot) {
6708 rc = osd_get_pfid_from_linkea(env, obj, fid);
6710 if (is_dotdot == false &&
6711 OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
6714 rc = osd_ea_fid_get(env, obj, ino, fid, id);
6717 osd_id_gen(id, ino, OSD_OII_NOGEN);
6721 /* Pack the entry anyway, at least the offset is right. */
6722 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
6723 it->oie_dirent->oied_name,
6724 it->oie_dirent->oied_namelen,
6725 it->oie_dirent->oied_type, attr);
6730 if (osd_remote_fid(env, dev, fid))
6733 if (likely(!(attr & (LUDA_IGNORE | LUDA_UNKNOWN)) && rc == 0))
6734 osd_add_oi_cache(oti, dev, id, fid);
6736 RETURN(rc > 0 ? 0 : rc);
6740 * Returns the record size size at current position.
6742 * This function will return record(lu_dirent) size in bytes.
6744 * \param[in] env execution environment
6745 * \param[in] di iterator's in memory structure
6746 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
6747 * calculate the lu_dirent size.
6749 * \retval record size(in bytes & in memory) of the current lu_dirent
6752 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
6755 struct osd_it_ea *it = (struct osd_it_ea *)di;
6757 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
6761 * Returns a cookie for current position of the iterator head, so that
6762 * user can use this cookie to load/start the iterator next time.
6764 * \param di iterator's in memory structure
6766 * \retval cookie for current position, on success
6768 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
6770 struct osd_it_ea *it = (struct osd_it_ea *)di;
6772 return it->oie_dirent->oied_off;
6776 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
6777 * to load a directory entry at a time and stored it i inn,
6778 * in iterator's in-memory data structure.
6780 * \param di struct osd_it_ea, iterator's in memory structure
6782 * \retval +ve on success
6783 * \retval -ve on error
6785 static int osd_it_ea_load(const struct lu_env *env,
6786 const struct dt_it *di, __u64 hash)
6788 struct osd_it_ea *it = (struct osd_it_ea *)di;
6792 it->oie_file.f_pos = hash;
6794 rc = osd_ldiskfs_it_fill(env, di);
6805 * Index lookup function for interoperability mode (b11826).
6807 * \param key, key i.e. file name to be searched
6809 * \retval +ve, on success
6810 * \retval -ve, on error
6812 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
6813 struct dt_rec *rec, const struct dt_key *key)
6815 struct osd_object *obj = osd_dt_obj(dt);
6820 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
6821 LINVRNT(osd_invariant(obj));
6823 rc = osd_ea_lookup_rec(env, obj, rec, key);
6830 * Index and Iterator operations for interoperability
6831 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
6833 static const struct dt_index_operations osd_index_ea_ops = {
6834 .dio_lookup = osd_index_ea_lookup,
6835 .dio_declare_insert = osd_index_declare_ea_insert,
6836 .dio_insert = osd_index_ea_insert,
6837 .dio_declare_delete = osd_index_declare_ea_delete,
6838 .dio_delete = osd_index_ea_delete,
6840 .init = osd_it_ea_init,
6841 .fini = osd_it_ea_fini,
6842 .get = osd_it_ea_get,
6843 .put = osd_it_ea_put,
6844 .next = osd_it_ea_next,
6845 .key = osd_it_ea_key,
6846 .key_size = osd_it_ea_key_size,
6847 .rec = osd_it_ea_rec,
6848 .rec_size = osd_it_ea_rec_size,
6849 .store = osd_it_ea_store,
6850 .load = osd_it_ea_load
6854 static void *osd_key_init(const struct lu_context *ctx,
6855 struct lu_context_key *key)
6857 struct osd_thread_info *info;
6859 OBD_ALLOC_PTR(info);
6861 return ERR_PTR(-ENOMEM);
6863 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6864 if (info->oti_it_ea_buf == NULL)
6867 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
6869 info->oti_hlock = ldiskfs_htree_lock_alloc();
6870 if (info->oti_hlock == NULL)
6876 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6879 return ERR_PTR(-ENOMEM);
6882 static void osd_key_fini(const struct lu_context *ctx,
6883 struct lu_context_key *key, void* data)
6885 struct osd_thread_info *info = data;
6886 struct ldiskfs_inode_info *lli = LDISKFS_I(info->oti_inode);
6887 struct osd_idmap_cache *idc = info->oti_ins_cache;
6889 if (info->oti_inode != NULL)
6891 if (info->oti_hlock != NULL)
6892 ldiskfs_htree_lock_free(info->oti_hlock);
6893 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
6894 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
6895 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
6896 lu_buf_free(&info->oti_big_buf);
6898 LASSERT(info->oti_ins_cache_size > 0);
6899 OBD_FREE(idc, sizeof(*idc) * info->oti_ins_cache_size);
6900 info->oti_ins_cache = NULL;
6901 info->oti_ins_cache_size = 0;
6906 static void osd_key_exit(const struct lu_context *ctx,
6907 struct lu_context_key *key, void *data)
6909 struct osd_thread_info *info = data;
6911 LASSERT(info->oti_r_locks == 0);
6912 LASSERT(info->oti_w_locks == 0);
6913 LASSERT(info->oti_txns == 0);
6916 /* type constructor/destructor: osd_type_init, osd_type_fini */
6917 LU_TYPE_INIT_FINI(osd, &osd_key);
6919 struct lu_context_key osd_key = {
6920 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
6921 .lct_init = osd_key_init,
6922 .lct_fini = osd_key_fini,
6923 .lct_exit = osd_key_exit
6927 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
6928 const char *name, struct lu_device *next)
6930 struct osd_device *osd = osd_dev(d);
6932 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
6933 >= sizeof(osd->od_svname))
6935 return osd_procfs_init(osd, name);
6938 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
6940 struct seq_server_site *ss = osd_seq_site(osd);
6944 if (osd->od_is_ost || osd->od_cl_seq != NULL)
6947 if (unlikely(ss == NULL))
6950 OBD_ALLOC_PTR(osd->od_cl_seq);
6951 if (osd->od_cl_seq == NULL)
6954 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
6955 osd->od_svname, ss->ss_server_seq);
6957 OBD_FREE_PTR(osd->od_cl_seq);
6958 osd->od_cl_seq = NULL;
6962 if (ss->ss_node_id == 0) {
6963 /* If the OSD on the sequence controller(MDT0), then allocate
6964 * sequence here, otherwise allocate sequence after connected
6965 * to MDT0 (see mdt_register_lwp_callback()). */
6966 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
6967 &osd->od_cl_seq->lcs_space, env);
6973 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
6975 if (osd->od_cl_seq == NULL)
6978 seq_client_fini(osd->od_cl_seq);
6979 OBD_FREE_PTR(osd->od_cl_seq);
6980 osd->od_cl_seq = NULL;
6983 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
6987 /* shutdown quota slave instance associated with the device */
6988 if (o->od_quota_slave != NULL) {
6989 qsd_fini(env, o->od_quota_slave);
6990 o->od_quota_slave = NULL;
6993 osd_fid_fini(env, o);
6994 osd_scrub_cleanup(env, o);
6999 static void osd_umount(const struct lu_env *env, struct osd_device *o)
7003 if (o->od_mnt != NULL) {
7004 shrink_dcache_sb(osd_sb(o));
7005 osd_sync(env, &o->od_dt_dev);
7014 static int osd_mount(const struct lu_env *env,
7015 struct osd_device *o, struct lustre_cfg *cfg)
7017 const char *name = lustre_cfg_string(cfg, 0);
7018 const char *dev = lustre_cfg_string(cfg, 1);
7020 unsigned long page, s_flags, lmd_flags = 0;
7021 struct page *__page;
7022 struct file_system_type *type;
7023 char *options = NULL;
7025 struct osd_thread_info *info = osd_oti_get(env);
7026 struct lu_fid *fid = &info->oti_fid;
7027 struct inode *inode;
7028 int rc = 0, force_over_512tb = 0;
7031 if (o->od_mnt != NULL)
7034 if (strlen(dev) >= sizeof(o->od_mntdev))
7036 strcpy(o->od_mntdev, dev);
7038 str = lustre_cfg_string(cfg, 2);
7039 s_flags = simple_strtoul(str, NULL, 0);
7040 str = strstr(str, ":");
7042 lmd_flags = simple_strtoul(str + 1, NULL, 0);
7043 opts = lustre_cfg_string(cfg, 3);
7045 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
7046 CERROR("%s: device %s extents feature is not guaranteed to "
7047 "work on big-endian systems. Use \"bigendian_extents\" "
7048 "mount option to override.\n", name, dev);
7052 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
7053 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) {
7054 CWARN("force_over_128tb option is deprecated. "
7055 "Filesystems less than 512TB can be created without any "
7056 "force options. Use force_over_512tb option for "
7057 "filesystems greater than 512TB.\n");
7060 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 1, 53, 0)
7061 if (opts != NULL && strstr(opts, "force_over_256tb") != NULL) {
7062 CWARN("force_over_256tb option is deprecated. "
7063 "Filesystems less than 512TB can be created without any "
7064 "force options. Use force_over_512tb option for "
7065 "filesystems greater than 512TB.\n");
7069 if (opts != NULL && strstr(opts, "force_over_512tb") != NULL)
7070 force_over_512tb = 1;
7072 __page = alloc_page(GFP_KERNEL);
7074 GOTO(out, rc = -ENOMEM);
7075 page = (unsigned long)page_address(__page);
7076 options = (char *)page;
7079 /* strip out the options for back compatiblity */
7080 static char *sout[] = {
7087 /* strip out option we processed in osd */
7088 "bigendian_extents",
7094 strcat(options, opts);
7095 for (rc = 0, str = options; sout[rc]; ) {
7096 char *op = strstr(str, sout[rc]);
7102 if (op == options || *(op - 1) == ',') {
7103 str = op + strlen(sout[rc]);
7104 if (*str == ',' || *str == '\0') {
7105 *str == ',' ? str++ : str;
7106 memmove(op, str, strlen(str) + 1);
7109 for (str = op; *str != ',' && *str != '\0'; str++)
7113 strncat(options, "user_xattr,acl", 14);
7116 /* Glom up mount options */
7117 if (*options != '\0')
7118 strcat(options, ",");
7119 strlcat(options, "no_mbcache,nodelalloc", PAGE_SIZE);
7121 type = get_fs_type("ldiskfs");
7123 CERROR("%s: cannot find ldiskfs module\n", name);
7124 GOTO(out, rc = -ENODEV);
7127 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
7128 module_put(type->owner);
7130 if (IS_ERR(o->od_mnt)) {
7131 rc = PTR_ERR(o->od_mnt);
7133 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
7137 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) <<
7138 osd_sb(o)->s_blocksize_bits > 512ULL << 40 &&
7139 force_over_512tb == 0) {
7140 CERROR("%s: device %s LDISKFS does not support filesystems "
7141 "greater than 512TB and can cause data corruption. "
7142 "Use \"force_over_512tb\" mount option to override.\n",
7144 GOTO(out_mnt, rc = -EINVAL);
7147 if (lmd_flags & LMD_FLG_DEV_RDONLY) {
7148 if (priv_dev_set_rdonly) {
7149 priv_dev_set_rdonly(osd_sb(o)->s_bdev);
7150 o->od_dt_dev.dd_rdonly = 1;
7151 LCONSOLE_WARN("%s: set dev_rdonly on this device\n",
7154 LCONSOLE_WARN("%s: not support dev_rdonly on this device",
7157 GOTO(out_mnt, rc = -EOPNOTSUPP);
7159 } else if (priv_dev_check_rdonly &&
7160 priv_dev_check_rdonly(osd_sb(o)->s_bdev)) {
7161 CERROR("%s: underlying device %s is marked as "
7162 "read-only. Setup failed\n", name, dev);
7164 GOTO(out_mnt, rc = -EROFS);
7167 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
7168 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
7169 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
7170 GOTO(out_mnt, rc = -EINVAL);
7173 #ifdef LDISKFS_MOUNT_DIRDATA
7174 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
7175 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
7176 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
7177 else if (strstr(name, "MDT")) /* don't complain for MGT or OSTs */
7178 CWARN("%s: device %s was upgraded from Lustre-1.x without "
7179 "enabling the dirdata feature. If you do not want to "
7180 "downgrade to Lustre-1.x again, you can enable it via "
7181 "'tune2fs -O dirdata device'\n", name, dev);
7183 inode = osd_sb(o)->s_root->d_inode;
7184 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
7185 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
7187 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
7191 if (lmd_flags & LMD_FLG_NOSCRUB)
7192 o->od_auto_scrub_interval = AS_NEVER;
7202 __free_page(__page);
7207 static struct lu_device *osd_device_fini(const struct lu_env *env,
7208 struct lu_device *d)
7210 struct osd_device *o = osd_dev(d);
7213 osd_shutdown(env, o);
7215 osd_obj_map_fini(o);
7221 static int osd_device_init0(const struct lu_env *env,
7222 struct osd_device *o,
7223 struct lustre_cfg *cfg)
7225 struct lu_device *l = osd2lu_dev(o);
7226 struct osd_thread_info *info;
7230 /* if the module was re-loaded, env can loose its keys */
7231 rc = lu_env_refill((struct lu_env *) env);
7234 info = osd_oti_get(env);
7237 l->ld_ops = &osd_lu_ops;
7238 o->od_dt_dev.dd_ops = &osd_dt_ops;
7240 spin_lock_init(&o->od_osfs_lock);
7241 mutex_init(&o->od_otable_mutex);
7242 INIT_LIST_HEAD(&o->od_orphan_list);
7244 o->od_read_cache = 1;
7245 o->od_writethrough_cache = 1;
7246 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
7247 o->od_auto_scrub_interval = AS_DEFAULT;
7249 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
7250 sizeof(o->od_svname));
7251 if (cplen >= sizeof(o->od_svname)) {
7256 o->od_index = -1; /* -1 means index is invalid */
7257 rc = server_name2index(o->od_svname, &o->od_index, NULL);
7258 if (rc == LDD_F_SV_TYPE_OST)
7261 o->od_full_scrub_ratio = OFSR_DEFAULT;
7262 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
7263 rc = osd_mount(env, o, cfg);
7267 rc = osd_obj_map_init(env, o);
7271 rc = lu_site_init(&o->od_site, l);
7273 GOTO(out_compat, rc);
7274 o->od_site.ls_bottom_dev = l;
7276 rc = lu_site_init_finish(&o->od_site);
7280 INIT_LIST_HEAD(&o->od_ios_list);
7281 /* setup scrub, including OI files initialization */
7282 rc = osd_scrub_setup(env, o);
7286 rc = osd_procfs_init(o, o->od_svname);
7288 CERROR("%s: can't initialize procfs: rc = %d\n",
7290 GOTO(out_scrub, rc);
7293 LASSERT(l->ld_site->ls_linkage.next != NULL);
7294 LASSERT(l->ld_site->ls_linkage.prev != NULL);
7296 /* initialize quota slave instance */
7297 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
7299 if (IS_ERR(o->od_quota_slave)) {
7300 rc = PTR_ERR(o->od_quota_slave);
7301 o->od_quota_slave = NULL;
7302 GOTO(out_procfs, rc);
7310 osd_scrub_cleanup(env, o);
7312 lu_site_fini(&o->od_site);
7314 osd_obj_map_fini(o);
7321 static struct lu_device *osd_device_alloc(const struct lu_env *env,
7322 struct lu_device_type *t,
7323 struct lustre_cfg *cfg)
7325 struct osd_device *o;
7330 return ERR_PTR(-ENOMEM);
7332 rc = dt_device_init(&o->od_dt_dev, t);
7334 /* Because the ctx might be revived in dt_device_init,
7335 * refill the env here */
7336 lu_env_refill((struct lu_env *)env);
7337 rc = osd_device_init0(env, o, cfg);
7339 dt_device_fini(&o->od_dt_dev);
7342 if (unlikely(rc != 0))
7345 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
7348 static struct lu_device *osd_device_free(const struct lu_env *env,
7349 struct lu_device *d)
7351 struct osd_device *o = osd_dev(d);
7354 /* XXX: make osd top device in order to release reference */
7355 d->ld_site->ls_top_dev = d;
7356 lu_site_purge(env, d->ld_site, -1);
7357 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
7358 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
7359 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
7361 lu_site_fini(&o->od_site);
7362 dt_device_fini(&o->od_dt_dev);
7367 static int osd_process_config(const struct lu_env *env,
7368 struct lu_device *d, struct lustre_cfg *cfg)
7370 struct osd_device *o = osd_dev(d);
7374 switch (cfg->lcfg_command) {
7376 rc = osd_mount(env, o, cfg);
7379 lu_dev_del_linkage(d->ld_site, d);
7380 rc = osd_shutdown(env, o);
7383 LASSERT(&o->od_dt_dev);
7384 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
7385 cfg, &o->od_dt_dev);
7386 if (rc > 0 || rc == -ENOSYS) {
7387 rc = class_process_proc_param(PARAM_OST,
7388 lprocfs_osd_obd_vars,
7389 cfg, &o->od_dt_dev);
7401 static int osd_recovery_complete(const struct lu_env *env,
7402 struct lu_device *d)
7404 struct osd_device *osd = osd_dev(d);
7408 if (osd->od_quota_slave == NULL)
7411 /* start qsd instance on recovery completion, this notifies the quota
7412 * slave code that we are about to process new requests now */
7413 rc = qsd_start(env, osd->od_quota_slave);
7418 * we use exports to track all osd users
7420 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
7421 struct obd_device *obd, struct obd_uuid *cluuid,
7422 struct obd_connect_data *data, void *localdata)
7424 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
7425 struct lustre_handle conn;
7429 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
7431 rc = class_connect(&conn, obd, cluuid);
7435 *exp = class_conn2export(&conn);
7437 spin_lock(&osd->od_osfs_lock);
7439 spin_unlock(&osd->od_osfs_lock);
7445 * once last export (we don't count self-export) disappeared
7446 * osd can be released
7448 static int osd_obd_disconnect(struct obd_export *exp)
7450 struct obd_device *obd = exp->exp_obd;
7451 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
7452 int rc, release = 0;
7455 /* Only disconnect the underlying layers on the final disconnect. */
7456 spin_lock(&osd->od_osfs_lock);
7458 if (osd->od_connects == 0)
7460 spin_unlock(&osd->od_osfs_lock);
7462 rc = class_disconnect(exp); /* bz 9811 */
7464 if (rc == 0 && release)
7465 class_manual_cleanup(obd);
7469 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
7470 struct lu_device *dev)
7472 struct osd_device *osd = osd_dev(dev);
7473 struct lr_server_data *lsd =
7474 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
7478 if (osd->od_quota_slave != NULL) {
7479 /* set up quota slave objects */
7480 result = qsd_prepare(env, osd->od_quota_slave);
7485 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
7486 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
7487 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
7488 osd->od_index_in_idif = 1;
7490 osd->od_index_in_idif = 0;
7491 result = osd_register_proc_index_in_idif(osd);
7496 osd->od_index_in_idif = 1;
7500 result = osd_fid_init(env, osd);
7505 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
7506 struct lu_fid *fid, struct md_op_data *op_data)
7508 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
7510 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
7513 static const struct lu_object_operations osd_lu_obj_ops = {
7514 .loo_object_init = osd_object_init,
7515 .loo_object_delete = osd_object_delete,
7516 .loo_object_release = osd_object_release,
7517 .loo_object_free = osd_object_free,
7518 .loo_object_print = osd_object_print,
7519 .loo_object_invariant = osd_object_invariant
7522 const struct lu_device_operations osd_lu_ops = {
7523 .ldo_object_alloc = osd_object_alloc,
7524 .ldo_process_config = osd_process_config,
7525 .ldo_recovery_complete = osd_recovery_complete,
7526 .ldo_prepare = osd_prepare,
7529 static const struct lu_device_type_operations osd_device_type_ops = {
7530 .ldto_init = osd_type_init,
7531 .ldto_fini = osd_type_fini,
7533 .ldto_start = osd_type_start,
7534 .ldto_stop = osd_type_stop,
7536 .ldto_device_alloc = osd_device_alloc,
7537 .ldto_device_free = osd_device_free,
7539 .ldto_device_init = osd_device_init,
7540 .ldto_device_fini = osd_device_fini
7543 static struct lu_device_type osd_device_type = {
7544 .ldt_tags = LU_DEVICE_DT,
7545 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
7546 .ldt_ops = &osd_device_type_ops,
7547 .ldt_ctx_tags = LCT_LOCAL,
7550 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
7552 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
7553 struct super_block *sb = osd_sb(osd);
7555 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
7559 * lprocfs legacy support.
7561 static struct obd_ops osd_obd_device_ops = {
7562 .o_owner = THIS_MODULE,
7563 .o_connect = osd_obd_connect,
7564 .o_disconnect = osd_obd_disconnect,
7565 .o_fid_alloc = osd_fid_alloc,
7566 .o_health_check = osd_health_check,
7569 static int __init osd_init(void)
7573 CLASSERT(BH_DXLock < sizeof(((struct buffer_head *)0)->b_state) * 8);
7574 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
7575 /* please, try to keep osd_thread_info smaller than a page */
7576 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
7581 rc = lu_kmem_init(ldiskfs_caches);
7585 #ifdef CONFIG_KALLSYMS
7586 priv_dev_set_rdonly = (void *)kallsyms_lookup_name("dev_set_rdonly");
7587 priv_dev_check_rdonly = (void *)kallsyms_lookup_name("dev_check_rdonly");
7588 /* Clear readonly is unused at this time */
7589 /*priv_dev_clear_rdonly = (void *)kallsyms_lookup_name("dev_clear_rdonly");*/
7592 rc = class_register_type(&osd_obd_device_ops, NULL, true,
7593 lprocfs_osd_module_vars,
7594 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
7596 lu_kmem_fini(ldiskfs_caches);
7600 static void __exit osd_exit(void)
7602 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
7603 lu_kmem_fini(ldiskfs_caches);
7606 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
7607 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
7608 MODULE_VERSION(LUSTRE_VERSION_STRING);
7609 MODULE_LICENSE("GPL");
7611 module_init(osd_init);
7612 module_exit(osd_exit);