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/
31 * lustre/osd/osd_handler.c
33 * Top-level entry points into osd module
35 * Author: Nikita Danilov <nikita@clusterfs.com>
36 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
39 #define DEBUG_SUBSYSTEM S_OSD
41 #include <linux/fs_struct.h>
42 #include <linux/module.h>
43 #include <linux/user_namespace.h>
44 #include <linux/uidgid.h>
46 /* prerequisite for linux/xattr.h */
47 #include <linux/types.h>
48 /* prerequisite for linux/xattr.h */
50 /* XATTR_{REPLACE,CREATE} */
51 #include <linux/xattr.h>
53 #include <ldiskfs/ldiskfs.h>
54 #include <ldiskfs/xattr.h>
55 #include <ldiskfs/ldiskfs_extents.h>
58 * struct OBD_{ALLOC,FREE}*()
61 #include <obd_support.h>
62 /* struct ptlrpc_thread */
63 #include <lustre_net.h>
64 #include <lustre_fid.h>
66 #include <uapi/linux/lustre/lustre_param.h>
68 #include "osd_internal.h"
69 #include "osd_dynlocks.h"
71 /* llo_* api support */
72 #include <md_object.h>
73 #include <lustre_quota.h>
75 #include <lustre_linkea.h>
77 /* encoding routines */
78 #include <lustre_crypto.h>
80 /* Maximum EA size is limited by LNET_MTU for remote objects */
81 #define OSD_MAX_EA_SIZE 1048364
84 module_param(ldiskfs_pdo, int, 0644);
85 MODULE_PARM_DESC(ldiskfs_pdo, "ldiskfs with parallel directory operations");
87 int ldiskfs_track_declares_assert;
88 module_param(ldiskfs_track_declares_assert, int, 0644);
89 MODULE_PARM_DESC(ldiskfs_track_declares_assert, "LBUG during tracking of declares");
91 /* Slab to allocate dynlocks */
92 struct kmem_cache *dynlock_cachep;
94 /* Slab to allocate osd_it_ea */
95 struct kmem_cache *osd_itea_cachep;
97 static struct lu_kmem_descr ldiskfs_caches[] = {
99 .ckd_cache = &dynlock_cachep,
100 .ckd_name = "dynlock_cache",
101 .ckd_size = sizeof(struct dynlock_handle)
104 .ckd_cache = &osd_itea_cachep,
105 .ckd_name = "osd_itea_cache",
106 .ckd_size = sizeof(struct osd_it_ea)
113 static const char dot[] = ".";
114 static const char dotdot[] = "..";
116 static const struct lu_object_operations osd_lu_obj_ops;
117 static const struct dt_object_operations osd_obj_ops;
118 static const struct dt_object_operations osd_obj_otable_it_ops;
119 static const struct dt_index_operations osd_index_iam_ops;
120 static const struct dt_index_operations osd_index_ea_ops;
122 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
123 const struct lu_fid *fid);
124 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
125 struct osd_device *osd);
127 int osd_trans_declare_op2rb[] = {
128 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
129 [OSD_OT_PUNCH] = OSD_OT_MAX,
130 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
131 [OSD_OT_CREATE] = OSD_OT_DESTROY,
132 [OSD_OT_DESTROY] = OSD_OT_CREATE,
133 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
134 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
135 [OSD_OT_WRITE] = OSD_OT_WRITE,
136 [OSD_OT_INSERT] = OSD_OT_DELETE,
137 [OSD_OT_DELETE] = OSD_OT_INSERT,
138 [OSD_OT_QUOTA] = OSD_OT_MAX,
141 static int osd_has_index(const struct osd_object *obj)
143 return obj->oo_dt.do_index_ops != NULL;
146 static int osd_object_invariant(const struct lu_object *l)
148 return osd_invariant(osd_obj(l));
152 * Concurrency: doesn't matter
154 static int osd_is_write_locked(const struct lu_env *env, struct osd_object *o)
156 struct osd_thread_info *oti = osd_oti_get(env);
158 return oti->oti_w_locks > 0 && o->oo_owner == env;
162 * Concurrency: doesn't access mutable data
164 static int osd_root_get(const struct lu_env *env,
165 struct dt_device *dev, struct lu_fid *f)
167 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
172 * the following set of functions are used to maintain per-thread
173 * cache of FID->ino mapping. this mechanism is needed to resolve
174 * FID to inode at dt_insert() which in turn stores ino in the
175 * directory entries to keep ldiskfs compatible with ext[34].
176 * due to locking-originated restrictions we can't lookup ino
177 * using LU cache (deadlock is possible). lookup using OI is quite
178 * expensive. so instead we maintain this cache and methods like
179 * dt_create() fill it. so in the majority of cases dt_insert() is
180 * able to find needed mapping in lockless manner.
182 static struct osd_idmap_cache *
183 osd_idc_find(const struct lu_env *env, struct osd_device *osd,
184 const struct lu_fid *fid)
186 struct osd_thread_info *oti = osd_oti_get(env);
187 struct osd_idmap_cache *idc = oti->oti_ins_cache;
190 for (i = 0; i < oti->oti_ins_cache_used; i++) {
191 if (!lu_fid_eq(&idc[i].oic_fid, fid))
193 if (idc[i].oic_dev != osd)
202 static struct osd_idmap_cache *
203 osd_idc_add(const struct lu_env *env, struct osd_device *osd,
204 const struct lu_fid *fid)
206 struct osd_thread_info *oti = osd_oti_get(env);
207 struct osd_idmap_cache *idc;
210 if (unlikely(oti->oti_ins_cache_used >= oti->oti_ins_cache_size)) {
211 i = oti->oti_ins_cache_size * 2;
213 i = OSD_INS_CACHE_SIZE;
214 OBD_ALLOC_PTR_ARRAY_LARGE(idc, i);
216 return ERR_PTR(-ENOMEM);
217 if (oti->oti_ins_cache != NULL) {
218 memcpy(idc, oti->oti_ins_cache,
219 oti->oti_ins_cache_used * sizeof(*idc));
220 OBD_FREE_PTR_ARRAY_LARGE(oti->oti_ins_cache,
221 oti->oti_ins_cache_used);
223 oti->oti_ins_cache = idc;
224 oti->oti_ins_cache_size = i;
227 idc = oti->oti_ins_cache + oti->oti_ins_cache_used++;
230 idc->oic_lid.oii_ino = 0;
231 idc->oic_lid.oii_gen = 0;
238 * lookup mapping for the given fid in the cache, initialize a
239 * new one if not found. the initialization checks whether the
240 * object is local or remote. for local objects, OI is used to
241 * learn ino/generation. the function is used when the caller
242 * has no information about the object, e.g. at dt_insert().
244 static struct osd_idmap_cache *
245 osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd,
246 const struct lu_fid *fid)
248 struct osd_idmap_cache *idc;
251 idc = osd_idc_find(env, osd, fid);
252 LASSERT(!IS_ERR(idc));
256 CDEBUG(D_INODE, "%s: FID "DFID" not in the id map cache\n",
257 osd->od_svname, PFID(fid));
259 /* new mapping is needed */
260 idc = osd_idc_add(env, osd, fid);
262 CERROR("%s: FID "DFID" add id map cache failed: %ld\n",
263 osd->od_svname, PFID(fid), PTR_ERR(idc));
268 rc = osd_remote_fid(env, osd, fid);
269 if (unlikely(rc < 0))
273 /* the object is local, lookup in OI */
274 /* XXX: probably cheaper to lookup in LU first? */
275 rc = osd_oi_lookup(osd_oti_get(env), osd, fid,
277 if (unlikely(rc < 0)) {
278 CERROR("can't lookup: rc = %d\n", rc);
282 /* the object is remote */
289 static void osd_idc_dump_lma(const struct lu_env *env,
290 struct osd_device *osd,
294 struct osd_thread_info *info = osd_oti_get(env);
295 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
296 const struct lu_fid *fid;
297 struct osd_inode_id lid;
301 inode = osd_ldiskfs_iget(osd_sb(osd), ino);
303 CERROR("%s: can't get inode %lu: rc = %d\n",
304 osd->od_svname, ino, (int)PTR_ERR(inode));
307 if (is_bad_inode(inode)) {
308 CERROR("%s: bad inode %lu\n", osd->od_svname, ino);
311 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
313 CERROR("%s: can't get LMA for %lu: rc = %d\n",
314 osd->od_svname, ino, rc);
317 fid = &loa->loa_lma.lma_self_fid;
318 LCONSOLE(D_INFO, "%s: "DFID" in inode %lu/%u\n", osd->od_svname,
319 PFID(fid), ino, (unsigned)inode->i_generation);
322 rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0);
324 CERROR("%s: can't lookup "DFID": rc = %d\n",
325 osd->od_svname, PFID(fid), rc);
328 LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n", osd->od_svname,
329 PFID(fid), lid.oii_ino, lid.oii_gen);
334 static void osd_idc_dump_debug(const struct lu_env *env,
335 struct osd_device *osd,
336 const struct lu_fid *fid,
340 struct osd_inode_id lid;
344 rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0);
346 LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n",
347 osd->od_svname, PFID(fid), lid.oii_ino, lid.oii_gen);
348 osd_idc_dump_lma(env, osd, lid.oii_ino, false);
350 CERROR("%s: can't lookup "DFID": rc = %d\n",
351 osd->od_svname, PFID(fid), rc);
354 osd_idc_dump_lma(env, osd, ino1, true);
356 osd_idc_dump_lma(env, osd, ino2, true);
360 * lookup mapping for given FID and fill it from the given object.
361 * the object is lolcal by definition.
363 static int osd_idc_find_and_init(const struct lu_env *env,
364 struct osd_device *osd,
365 struct osd_object *obj)
367 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
368 struct osd_idmap_cache *idc;
370 idc = osd_idc_find(env, osd, fid);
371 LASSERT(!IS_ERR(idc));
373 if (obj->oo_inode == NULL)
375 if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) {
376 if (idc->oic_lid.oii_ino) {
377 osd_idc_dump_debug(env, osd, fid,
378 idc->oic_lid.oii_ino,
379 obj->oo_inode->i_ino);
382 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
383 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
388 CDEBUG(D_INODE, "%s: FID "DFID" not in the id map cache\n",
389 osd->od_svname, PFID(fid));
391 /* new mapping is needed */
392 idc = osd_idc_add(env, osd, fid);
394 CERROR("%s: FID "DFID" add id map cache failed: %ld\n",
395 osd->od_svname, PFID(fid), PTR_ERR(idc));
399 if (obj->oo_inode != NULL) {
400 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
401 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
407 * OSD object methods.
411 * Concurrency: no concurrent access is possible that early in object
414 static struct lu_object *osd_object_alloc(const struct lu_env *env,
415 const struct lu_object_header *hdr,
418 struct osd_object *mo;
423 struct lu_object_header *h;
424 struct osd_device *o = osd_dev(d);
426 l = &mo->oo_dt.do_lu;
427 if (unlikely(o->od_in_init)) {
434 lu_object_header_init(h);
435 lu_object_init(l, h, d);
436 lu_object_add_top(h, l);
439 dt_object_init(&mo->oo_dt, NULL, d);
440 mo->oo_header = NULL;
443 mo->oo_dt.do_ops = &osd_obj_ops;
444 l->lo_ops = &osd_lu_obj_ops;
445 init_rwsem(&mo->oo_sem);
446 init_rwsem(&mo->oo_ext_idx_sem);
447 spin_lock_init(&mo->oo_guard);
448 INIT_LIST_HEAD(&mo->oo_xattr_list);
454 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
455 struct dentry *dentry, struct lustre_ost_attrs *loa)
459 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
460 (void *)loa, sizeof(*loa));
462 struct lustre_mdt_attrs *lma = &loa->loa_lma;
464 if (rc < sizeof(*lma))
468 lustre_loa_swab(loa, true);
469 /* Check LMA compatibility */
470 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
472 CWARN("%s: unsupported incompat LMA feature(s) %#x for fid = "DFID", ino = %lu: rc = %d\n",
474 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
475 PFID(&lma->lma_self_fid), inode->i_ino, rc);
477 } else if (rc == 0) {
485 * retrieve object from backend ext fs.
487 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
488 struct osd_inode_id *id)
491 struct inode *inode = NULL;
494 * if we look for an inode withing a running
495 * transaction, then we risk to deadlock
496 * osd_dirent_check_repair() breaks this
498 /* LASSERT(current->journal_info == NULL); */
500 inode = osd_ldiskfs_iget(osd_sb(dev), id->oii_ino);
502 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
503 id->oii_ino, PTR_ERR(inode));
504 } else if (id->oii_gen != OSD_OII_NOGEN &&
505 inode->i_generation != id->oii_gen) {
506 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
507 "i_generation = %u\n",
508 id->oii_ino, id->oii_gen, inode->i_generation);
510 inode = ERR_PTR(-ESTALE);
511 } else if (inode->i_nlink == 0) {
513 * due to parallel readdir and unlink,
514 * we can have dead inode here.
516 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
518 inode = ERR_PTR(-ESTALE);
519 } else if (is_bad_inode(inode)) {
521 CWARN("%s: bad inode: ino = %u: rc = %d\n",
522 osd_dev2name(dev), id->oii_ino, rc);
525 } else if ((rc = osd_attach_jinode(inode))) {
529 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
530 if (id->oii_gen == OSD_OII_NOGEN)
531 osd_id_gen(id, inode->i_ino, inode->i_generation);
534 * Do not update file c/mtime in ldiskfs.
535 * NB: we don't have any lock to protect this because we don't
536 * have reference on osd_object now, but contention with
537 * another lookup + attr_set can't happen in the tiny window
538 * between if (...) and set S_NOCMTIME.
540 if (!(inode->i_flags & S_NOCMTIME))
541 inode->i_flags |= S_NOCMTIME;
546 int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd,
547 handle_t *handle, struct dentry *child,
548 struct inode *inode, struct htree_lock *hlock)
552 rc = __ldiskfs_add_entry(handle, child, inode, hlock);
553 if (rc == -ENOBUFS || rc == -ENOSPC) {
554 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
555 struct inode *parent = child->d_parent->d_inode;
556 struct lu_fid *fid = NULL;
557 char fidstr[FID_LEN + 1] = "unknown";
559 rc2 = osd_get_lma(info, parent, child->d_parent, loa);
561 fid = &loa->loa_lma.lma_self_fid;
562 } else if (rc2 == -ENODATA) {
563 if (unlikely(is_root_inode(parent))) {
564 fid = &info->oti_fid3;
565 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
566 } else if (!osd->od_is_ost && osd->od_index == 0) {
567 fid = &info->oti_fid3;
568 lu_igif_build(fid, parent->i_ino,
569 parent->i_generation);
574 snprintf(fidstr, sizeof(fidstr), DFID, PFID(fid));
576 /* below message is checked in sanity.sh test_129 */
578 CWARN("%s: directory (inode: %lu, FID: %s) has reached max size limit\n",
579 osd_name(osd), parent->i_ino, fidstr);
581 rc = 0; /* ignore such error now */
582 CWARN("%s: directory (inode: %lu, FID: %s) is approaching max size limit\n",
583 osd_name(osd), parent->i_ino, fidstr);
593 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
594 struct osd_inode_id *id, struct lu_fid *fid)
596 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
600 inode = osd_iget(info, dev, id);
604 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
606 *fid = loa->loa_lma.lma_self_fid;
607 } else if (rc == -ENODATA) {
608 if (unlikely(is_root_inode(inode)))
609 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
611 lu_igif_build(fid, inode->i_ino, inode->i_generation);
619 static struct inode *osd_iget_check(struct osd_thread_info *info,
620 struct osd_device *dev,
621 const struct lu_fid *fid,
622 struct osd_inode_id *id,
631 * The cached OI mapping is trustable. If we cannot locate the inode
632 * via the cached OI mapping, then return the failure to the caller
633 * directly without further OI checking.
637 inode = osd_ldiskfs_iget(osd_sb(dev), id->oii_ino);
640 if (!trusted && (rc == -ENOENT || rc == -ESTALE))
643 CDEBUG(D_INODE, "no inode for FID: "DFID", ino = %u, rc = %d\n",
644 PFID(fid), id->oii_ino, rc);
648 if (is_bad_inode(inode)) {
653 CDEBUG(D_INODE, "bad inode for FID: "DFID", ino = %u\n",
654 PFID(fid), id->oii_ino);
658 if (id->oii_gen != OSD_OII_NOGEN &&
659 inode->i_generation != id->oii_gen) {
664 CDEBUG(D_INODE, "unmatched inode for FID: "DFID", ino = %u, "
665 "oii_gen = %u, i_generation = %u\n", PFID(fid),
666 id->oii_ino, id->oii_gen, inode->i_generation);
670 if (inode->i_nlink == 0) {
675 CDEBUG(D_INODE, "stale inode for FID: "DFID", ino = %u\n",
676 PFID(fid), id->oii_ino);
680 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
684 __u32 saved_ino = id->oii_ino;
685 __u32 saved_gen = id->oii_gen;
688 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
690 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
692 * XXX: There are four possible cases:
694 * Backup/restore caused the OI invalid.
696 * Someone unlinked the object but NOT removed
697 * the OI mapping, such as mount target device
698 * as ldiskfs, and modify something directly.
700 * Someone just removed the object between the
701 * former oi_lookup and the iget. It is normal.
702 * 4. Other failure cases.
704 * Generally, when the device is mounted, it will
705 * auto check whether the system is restored from
706 * file-level backup or not. We trust such detect
707 * to distinguish the 1st case from the 2nd case:
708 * if the OI files are consistent but may contain
709 * stale OI mappings because of case 2, if iget()
710 * returns -ENOENT or -ESTALE, then it should be
715 * If the OI mapping was in OI file before the
716 * osd_iget_check(), but now, it is disappear,
717 * then it must be removed by race. That is a
723 * It is the OI scrub updated the OI mapping by race.
724 * The new OI mapping must be valid.
726 if (saved_ino != id->oii_ino ||
727 (saved_gen != id->oii_gen && saved_gen != OSD_OII_NOGEN)) {
736 if (dev->od_scrub.os_scrub.os_file.sf_flags &
739 * It still can be the case 2, but we cannot
740 * distinguish it from the case 1. So return
741 * -EREMCHG to block current operation until
742 * OI scrub rebuilt the OI mappings.
751 if (inode->i_generation == id->oii_gen)
756 if (id->oii_gen == OSD_OII_NOGEN)
757 osd_id_gen(id, inode->i_ino, inode->i_generation);
760 * Do not update file c/mtime in ldiskfs.
761 * NB: we don't have any lock to protect this because we don't
762 * have reference on osd_object now, but contention with
763 * another lookup + attr_set can't happen in the tiny window
764 * between if (...) and set S_NOCMTIME.
766 if (!(inode->i_flags & S_NOCMTIME))
767 inode->i_flags |= S_NOCMTIME;
784 * \retval +v: new filter_fid does not contain self-fid
785 * \retval 0: filter_fid_18_23, contains self-fid
786 * \retval -v: other failure cases
788 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
789 struct dentry *dentry, struct lu_fid *fid)
791 struct filter_fid *ff = &info->oti_ff;
792 struct ost_id *ostid = &info->oti_ostid;
795 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
796 if (rc == sizeof(struct filter_fid_18_23)) {
797 struct filter_fid_18_23 *ff_old = (void *)ff;
799 ostid_set_seq(ostid, le64_to_cpu(ff_old->ff_seq));
800 rc = ostid_set_id(ostid, le64_to_cpu(ff_old->ff_objid));
802 * XXX: use 0 as the index for compatibility, the caller will
803 * handle index related issues when necessary.
806 ostid_to_fid(fid, ostid, 0);
807 } else if (rc >= (int)sizeof(struct filter_fid_24_29)) {
809 } else if (rc >= 0) {
816 static int osd_lma_self_repair(struct osd_thread_info *info,
817 struct osd_device *osd, struct inode *inode,
818 const struct lu_fid *fid, __u32 compat)
823 LASSERT(current->journal_info == NULL);
825 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
826 osd_dto_credits_noquota[DTO_XATTR_SET]);
829 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
834 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
836 CWARN("%s: cannot self repair the LMA: rc = %d\n",
838 ldiskfs_journal_stop(jh);
842 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
844 struct osd_thread_info *info = osd_oti_get(env);
845 struct osd_device *osd = osd_obj2dev(obj);
846 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
847 struct lustre_mdt_attrs *lma = &loa->loa_lma;
848 struct inode *inode = obj->oo_inode;
849 struct dentry *dentry = &info->oti_obj_dentry;
850 struct lu_fid *fid = NULL;
851 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
856 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
857 (void *)loa, sizeof(*loa));
858 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
859 fid = &lma->lma_self_fid;
860 rc = osd_get_idif(info, inode, dentry, fid);
861 if (rc > 0 || (rc == -ENODATA && osd->od_index_in_idif)) {
863 * For the given OST-object, if it has neither LMA nor
864 * FID in XATTR_NAME_FID, then the given FID (which is
865 * contained in the @obj, from client RPC for locating
866 * the OST-object) is trusted. We use it to generate
869 osd_lma_self_repair(info, osd, inode, rfid,
880 lustre_lma_swab(lma);
881 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
882 (CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT) &&
883 S_ISREG(inode->i_mode)))) {
884 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
885 "fid = "DFID", ino = %lu\n", osd_name(osd),
886 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
887 PFID(rfid), inode->i_ino);
890 fid = &lma->lma_self_fid;
891 if (lma->lma_compat & LMAC_STRIPE_INFO &&
893 obj->oo_pfid_in_lma = 1;
894 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
896 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
900 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
901 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
902 struct ost_id *oi = &info->oti_ostid;
903 struct lu_fid *fid1 = &info->oti_fid3;
904 __u32 idx = fid_idif_ost_idx(rfid);
907 * For old IDIF, the OST index is not part of the IDIF,
908 * Means that different OSTs may have the same IDIFs.
909 * Under such case, we need to make some compatible
910 * check to make sure to trigger OI scrub properly.
912 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
913 /* Given @rfid is new, LMA is old. */
914 fid_to_ostid(fid, oi);
915 ostid_to_fid(fid1, oi, idx);
916 if (lu_fid_eq(fid1, rfid)) {
917 if (osd->od_index_in_idif)
918 osd_lma_self_repair(info, osd,
932 struct osd_check_lmv_buf {
933 /* please keep it as first member */
934 struct dir_context ctx;
935 struct osd_thread_info *oclb_info;
936 struct osd_device *oclb_dev;
942 * It is called internally by ->iterate*() to filter out the
943 * local slave object's FID of the striped directory.
945 * \retval 1 found the local slave's FID
946 * \retval 0 continue to check next item
947 * \retval -ve for failure
949 #ifdef HAVE_FILLDIR_USE_CTX
950 static int osd_stripe_dir_filldir(struct dir_context *buf,
952 static int osd_stripe_dir_filldir(void *buf,
954 const char *name, int namelen,
955 loff_t offset, __u64 ino, unsigned int d_type)
957 struct osd_check_lmv_buf *oclb = (struct osd_check_lmv_buf *)buf;
958 struct osd_thread_info *oti = oclb->oclb_info;
959 struct lu_fid *fid = &oti->oti_fid3;
960 struct osd_inode_id *id = &oti->oti_id3;
961 struct osd_device *dev = oclb->oclb_dev;
970 sscanf(name + 1, SFID, RFID(fid));
971 if (!fid_is_sane(fid))
974 if (osd_remote_fid(oti->oti_env, dev, fid))
977 osd_id_gen(id, ino, OSD_OII_NOGEN);
978 inode = osd_iget(oti, dev, id);
980 return PTR_ERR(inode);
983 osd_add_oi_cache(oti, dev, id, fid);
984 osd_oii_insert(dev, fid, id, true);
985 oclb->oclb_found = true;
991 * When lookup item under striped directory, we need to locate the master
992 * MDT-object of the striped directory firstly, then the client will send
993 * lookup (getattr_by_name) RPC to the MDT with some slave MDT-object's FID
994 * and the item's name. If the system is restored from MDT file level backup,
995 * then before the OI scrub completely built the OI files, the OI mappings of
996 * the master MDT-object and slave MDT-object may be invalid. Usually, it is
997 * not a problem for the master MDT-object. Because when locate the master
998 * MDT-object, we will do name based lookup (for the striped directory itself)
999 * firstly, during such process we can setup the correct OI mapping for the
1000 * master MDT-object. But it will be trouble for the slave MDT-object. Because
1001 * the client will not trigger name based lookup on the MDT to locate the slave
1002 * MDT-object before locating item under the striped directory, then when
1003 * osd_fid_lookup(), it will find that the OI mapping for the slave MDT-object
1004 * is invalid and does not know what the right OI mapping is, then the MDT has
1005 * to return -EINPROGRESS to the client to notify that the OI scrub is rebuiding
1006 * the OI file, related OI mapping is unknown yet, please try again later. And
1007 * then client will re-try the RPC again and again until related OI mapping has
1008 * been updated. That is quite inefficient.
1010 * To resolve above trouble, we will handle it as the following two cases:
1012 * 1) The slave MDT-object and the master MDT-object are on different MDTs.
1013 * It is relative easy. Be as one of remote MDT-objects, the slave MDT-object
1014 * is linked under /REMOTE_PARENT_DIR with the name of its FID string.
1015 * We can locate the slave MDT-object via lookup the /REMOTE_PARENT_DIR
1016 * directly. Please check osd_fid_lookup().
1018 * 2) The slave MDT-object and the master MDT-object reside on the same MDT.
1019 * Under such case, during lookup the master MDT-object, we will lookup the
1020 * slave MDT-object via readdir against the master MDT-object, because the
1021 * slave MDT-objects information are stored as sub-directories with the name
1022 * "${FID}:${index}". Then when find the local slave MDT-object, its OI
1023 * mapping will be recorded. Then subsequent osd_fid_lookup() will know
1024 * the correct OI mapping for the slave MDT-object.
1026 static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev,
1027 struct inode *inode)
1029 struct lu_buf *buf = &oti->oti_big_buf;
1031 struct lmv_mds_md_v1 *lmv1;
1032 struct osd_check_lmv_buf oclb = {
1033 .ctx.actor = osd_stripe_dir_filldir,
1036 .oclb_found = false,
1041 /* We should use the VFS layer to create a real dentry. */
1042 oti->oti_obj_dentry.d_inode = inode;
1043 oti->oti_obj_dentry.d_sb = inode->i_sb;
1045 filp = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
1050 filp->f_mode |= FMODE_64BITHASH;
1054 rc = __osd_xattr_get(inode, filp->f_path.dentry, XATTR_NAME_LMV,
1055 buf->lb_buf, buf->lb_len);
1056 if (rc == -ERANGE) {
1057 rc = __osd_xattr_get(inode, filp->f_path.dentry,
1058 XATTR_NAME_LMV, NULL, 0);
1060 lu_buf_realloc(buf, rc);
1061 if (buf->lb_buf == NULL)
1062 GOTO(out, rc = -ENOMEM);
1068 if (unlikely(rc == 0 || rc == -ENODATA))
1074 if (unlikely(buf->lb_buf == NULL)) {
1075 lu_buf_realloc(buf, rc);
1076 if (buf->lb_buf == NULL)
1077 GOTO(out, rc = -ENOMEM);
1083 if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
1087 oclb.oclb_items = 0;
1088 rc = iterate_dir(filp, &oclb.ctx);
1089 } while (rc >= 0 && oclb.oclb_items > 0 && !oclb.oclb_found &&
1090 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
1095 "%s: cannot check LMV, ino = %lu/%u: rc = %d\n",
1096 osd_ino2name(inode), inode->i_ino, inode->i_generation,
1104 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
1105 const struct lu_fid *fid,
1106 const struct lu_object_conf *conf)
1108 struct osd_thread_info *info;
1109 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
1110 struct osd_device *dev;
1111 struct osd_idmap_cache *oic;
1112 struct osd_inode_id *id;
1113 struct inode *inode = NULL;
1114 struct lustre_scrub *scrub;
1115 struct scrub_file *sf;
1116 __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT | SS_AUTO_FULL;
1121 bool remote = false;
1122 bool trusted = true;
1123 bool updated = false;
1124 bool checked = false;
1128 LINVRNT(osd_invariant(obj));
1129 LASSERT(obj->oo_inode == NULL);
1131 if (fid_is_sane(fid) == 0) {
1132 CERROR("%s: invalid FID "DFID"\n", ldev->ld_obd->obd_name,
1138 dev = osd_dev(ldev);
1139 scrub = &dev->od_scrub.os_scrub;
1140 sf = &scrub->os_file;
1141 info = osd_oti_get(env);
1143 oic = &info->oti_cache;
1145 if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
1149 * For the object is created as locking anchor, or for the object to
1150 * be created on disk. No need to osd_oi_lookup() at here because FID
1151 * shouldn't never be re-used, if it's really a duplicate FID from
1152 * unexpected reason, we should be able to detect it later by calling
1153 * do_create->osd_oi_insert().
1155 if (conf && conf->loc_flags & LOC_F_NEW)
1156 GOTO(out, result = 0);
1158 /* Search order: 1. per-thread cache. */
1159 if (lu_fid_eq(fid, &oic->oic_fid) && likely(oic->oic_dev == dev)) {
1165 memset(id, 0, sizeof(struct osd_inode_id));
1166 if (!list_empty(&scrub->os_inconsistent_items)) {
1167 /* Search order: 2. OI scrub pending list. */
1168 result = osd_oii_lookup(dev, fid, id);
1174 * The OI mapping in the OI file can be updated by the OI scrub
1175 * when we locate the inode via FID. So it may be not trustable.
1179 /* Search order: 3. OI files. */
1180 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1181 if (result == -ENOENT) {
1182 if (!(fid_is_norm(fid) || fid_is_igif(fid)) ||
1183 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
1184 !ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
1186 GOTO(out, result = 0);
1191 /* -ESTALE is returned if inode of OST object doesn't exist */
1192 if (result == -ESTALE &&
1193 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) {
1194 GOTO(out, result = 0);
1201 obj->oo_inode = NULL;
1202 /* for later passes through checks, not true on first pass */
1203 if (!IS_ERR_OR_NULL(inode))
1206 inode = osd_iget_check(info, dev, fid, id, trusted);
1207 if (!IS_ERR(inode)) {
1208 obj->oo_inode = inode;
1216 result = PTR_ERR(inode);
1217 if (result == -ENOENT || result == -ESTALE)
1218 GOTO(out, result = 0);
1220 if (result != -EREMCHG)
1225 * We still have chance to get the valid inode: for the
1226 * object which is referenced by remote name entry, the
1227 * object on the local MDT will be linked under the dir
1228 * of "/REMOTE_PARENT_DIR" with its FID string as name.
1230 * We do not know whether the object for the given FID
1231 * is referenced by some remote name entry or not, and
1232 * especially for DNE II, a multiple-linked object may
1233 * have many name entries reside on many MDTs.
1235 * To simplify the operation, OSD will not distinguish
1236 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
1237 * only happened for the RPC from other MDT during the
1238 * OI scrub, or for the client side RPC with FID only,
1239 * such as FID to path, or from old connected client.
1242 rc1 = osd_lookup_in_remote_parent(info, dev, fid, id);
1246 flags |= SS_AUTO_PARTIAL;
1247 flags &= ~SS_AUTO_FULL;
1252 if (scrub->os_running) {
1253 if (scrub->os_partial_scan && !scrub->os_in_join)
1256 if (IS_ERR_OR_NULL(inode) || result) {
1257 osd_oii_insert(dev, fid, id, result == -ENOENT);
1258 GOTO(out, result = -EINPROGRESS);
1262 LASSERT(obj->oo_inode == inode);
1264 osd_oii_insert(dev, fid, id, true);
1268 if (dev->od_scrub.os_scrub.os_auto_scrub_interval == AS_NEVER) {
1270 GOTO(out, result = -EREMCHG);
1273 LASSERT(obj->oo_inode == inode);
1275 osd_add_oi_cache(info, dev, id, fid);
1280 rc1 = osd_scrub_start(env, dev, flags);
1281 CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
1282 "%s: trigger OI scrub by RPC for "DFID"/%u with flags %#x: rc = %d\n",
1283 osd_name(dev), PFID(fid), id->oii_ino, flags, rc1);
1284 if (rc1 && rc1 != -EALREADY)
1285 GOTO(out, result = -EREMCHG);
1287 if (IS_ERR_OR_NULL(inode) || result) {
1288 osd_oii_insert(dev, fid, id, result == -ENOENT);
1289 GOTO(out, result = -EINPROGRESS);
1293 LASSERT(obj->oo_inode == inode);
1295 osd_oii_insert(dev, fid, id, true);
1300 if (unlikely(obj->oo_header))
1303 result = osd_check_lma(env, obj);
1307 LASSERTF(id->oii_ino == inode->i_ino &&
1308 id->oii_gen == inode->i_generation,
1309 "locate wrong inode for FID: "DFID", %u/%u => %ld/%u\n",
1310 PFID(fid), id->oii_ino, id->oii_gen,
1311 inode->i_ino, inode->i_generation);
1313 saved_ino = inode->i_ino;
1314 saved_gen = inode->i_generation;
1316 if (unlikely(result == -ENODATA)) {
1318 * If the OI scrub updated the OI mapping by race, it
1319 * must be valid. Trust the inode that has no LMA EA.
1324 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1327 * The OI mapping is still there, the inode is still
1328 * valid. It is just becaues the inode has no LMA EA.
1330 if (saved_ino == id->oii_ino &&
1331 saved_gen == id->oii_gen)
1335 * It is the OI scrub updated the OI mapping by race.
1336 * The new OI mapping must be valid.
1344 * "result == -ENOENT" means that the OI mappinghas been
1345 * removed by race, so the inode belongs to other object.
1347 * Others error can be returned directly.
1349 if (result == -ENOENT) {
1352 obj->oo_inode = NULL;
1357 if (result != -EREMCHG)
1363 * if two OST objects map to the same inode, and inode mode is
1364 * (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666), which means it's
1365 * reserved by precreate, and not written yet, in this case, don't
1366 * set inode for the object whose FID mismatch, so that it can create
1367 * inode and not block precreate.
1369 if (fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) &&
1370 inode->i_mode == (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666)) {
1371 obj->oo_inode = NULL;
1372 GOTO(out, result = 0);
1375 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1377 * "result == -ENOENT" means the cached OI mapping has been removed
1378 * from the OI file by race, above inode belongs to other object.
1380 if (result == -ENOENT) {
1383 obj->oo_inode = NULL;
1384 GOTO(out, result = 0);
1390 if (saved_ino == id->oii_ino && saved_gen == id->oii_gen) {
1392 osd_scrub_refresh_mapping(info, dev, fid, id, DTO_INDEX_DELETE,
1398 * It is the OI scrub updated the OI mapping by race.
1399 * The new OI mapping must be valid.
1407 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
1408 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1410 result = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
1412 if (lma->lma_compat & LMAC_STRIPE_INFO &&
1414 obj->oo_pfid_in_lma = 1;
1415 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
1417 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
1418 } else if (result != -ENODATA) {
1423 obj->oo_compat_dot_created = 1;
1424 obj->oo_compat_dotdot_created = 1;
1426 if (S_ISDIR(inode->i_mode) &&
1427 (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING))
1428 osd_check_lmv(info, dev, inode);
1430 result = osd_attach_jinode(inode);
1435 GOTO(out, result = 0);
1437 LASSERT(!obj->oo_hl_head);
1438 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1440 GOTO(out, result = (!obj->oo_hl_head ? -ENOMEM : 0));
1443 if (result || !obj->oo_inode) {
1444 if (!IS_ERR_OR_NULL(inode))
1447 obj->oo_inode = NULL;
1449 fid_zero(&oic->oic_fid);
1452 LINVRNT(osd_invariant(obj));
1457 * Concurrency: shouldn't matter.
1459 static void osd_object_init0(struct osd_object *obj)
1461 LASSERT(obj->oo_inode != NULL);
1462 obj->oo_dt.do_body_ops = &osd_body_ops;
1463 obj->oo_dt.do_lu.lo_header->loh_attr |=
1464 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
1468 * Concurrency: no concurrent access is possible that early in object
1471 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
1472 const struct lu_object_conf *conf)
1474 struct osd_object *obj = osd_obj(l);
1477 LINVRNT(osd_invariant(obj));
1479 if (OBD_FAIL_PRECHECK(OBD_FAIL_MDS_LLOG_UMOUNT_RACE) &&
1480 cfs_fail_val == 2) {
1481 struct osd_thread_info *info = osd_oti_get(env);
1482 struct osd_idmap_cache *oic = &info->oti_cache;
1483 /* invalidate thread cache */
1484 memset(&oic->oic_fid, 0, sizeof(oic->oic_fid));
1486 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
1487 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
1488 l->lo_header->loh_attr |= LOHA_EXISTS;
1492 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
1493 obj->oo_dt.do_body_ops = &osd_body_ops_new;
1494 if (result == 0 && obj->oo_inode != NULL) {
1495 struct osd_thread_info *oti = osd_oti_get(env);
1496 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
1498 osd_object_init0(obj);
1499 if (unlikely(obj->oo_header))
1502 result = osd_get_lma(oti, obj->oo_inode,
1503 &oti->oti_obj_dentry, loa);
1506 * Convert LMAI flags to lustre LMA flags
1507 * and cache it to oo_lma_flags
1510 lma_to_lustre_flags(loa->loa_lma.lma_incompat);
1511 } else if (result == -ENODATA) {
1515 obj->oo_dirent_count = LU_DIRENT_COUNT_UNSET;
1517 LINVRNT(osd_invariant(obj));
1522 * The first part of oxe_buf is xattr name, and is '\0' terminated.
1523 * The left part is for value, binary mode.
1525 struct osd_xattr_entry {
1526 struct list_head oxe_list;
1530 struct rcu_head oxe_rcu;
1534 static int osd_oxc_get(struct osd_object *obj, const char *name,
1537 struct osd_xattr_entry *tmp;
1538 struct osd_xattr_entry *oxe = NULL;
1539 size_t namelen = strlen(name);
1543 list_for_each_entry_rcu(tmp, &obj->oo_xattr_list, oxe_list) {
1544 if (namelen == tmp->oxe_namelen &&
1545 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1552 GOTO(out, rc = -ENOENT);
1554 if (!oxe->oxe_exist)
1555 GOTO(out, rc = -ENODATA);
1558 rc = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1;
1561 if (buf->lb_buf == NULL)
1564 if (buf->lb_len < rc)
1565 GOTO(out, rc = -ERANGE);
1567 memcpy(buf->lb_buf, &oxe->oxe_buf[namelen + 1], rc);
1574 static void osd_oxc_free(struct rcu_head *head)
1576 struct osd_xattr_entry *oxe;
1578 oxe = container_of(head, struct osd_xattr_entry, oxe_rcu);
1579 OBD_FREE(oxe, oxe->oxe_len);
1582 static void osd_oxc_add(struct osd_object *obj, const char *name,
1583 const char *buf, int buflen)
1585 struct osd_xattr_entry *oxe;
1586 struct osd_xattr_entry *old = NULL;
1587 struct osd_xattr_entry *tmp;
1588 size_t namelen = strlen(name);
1589 size_t len = sizeof(*oxe) + namelen + 1 + buflen;
1591 OBD_ALLOC(oxe, len);
1595 INIT_LIST_HEAD(&oxe->oxe_list);
1597 oxe->oxe_namelen = namelen;
1598 memcpy(oxe->oxe_buf, name, namelen);
1600 LASSERT(buf != NULL);
1601 memcpy(oxe->oxe_buf + namelen + 1, buf, buflen);
1602 oxe->oxe_exist = true;
1604 oxe->oxe_exist = false;
1607 /* this should be rarely called, just remove old and add new */
1608 spin_lock(&obj->oo_guard);
1609 list_for_each_entry(tmp, &obj->oo_xattr_list, oxe_list) {
1610 if (namelen == tmp->oxe_namelen &&
1611 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1617 list_replace_rcu(&old->oxe_list, &oxe->oxe_list);
1618 call_rcu(&old->oxe_rcu, osd_oxc_free);
1620 list_add_tail_rcu(&oxe->oxe_list, &obj->oo_xattr_list);
1622 spin_unlock(&obj->oo_guard);
1625 static void osd_oxc_del(struct osd_object *obj, const char *name)
1627 struct osd_xattr_entry *oxe;
1628 size_t namelen = strlen(name);
1630 spin_lock(&obj->oo_guard);
1631 list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) {
1632 if (namelen == oxe->oxe_namelen &&
1633 strncmp(name, oxe->oxe_buf, namelen) == 0) {
1634 list_del_rcu(&oxe->oxe_list);
1635 call_rcu(&oxe->oxe_rcu, osd_oxc_free);
1639 spin_unlock(&obj->oo_guard);
1642 static void osd_oxc_fini(struct osd_object *obj)
1644 struct osd_xattr_entry *oxe, *next;
1646 list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) {
1647 list_del(&oxe->oxe_list);
1648 OBD_FREE(oxe, oxe->oxe_len);
1653 * Concurrency: no concurrent access is possible that late in object
1656 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
1658 struct osd_object *obj = osd_obj(l);
1659 struct lu_object_header *h = obj->oo_header;
1661 LINVRNT(osd_invariant(obj));
1664 dt_object_fini(&obj->oo_dt);
1665 if (obj->oo_hl_head != NULL)
1666 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1667 /* obj doesn't contain an lu_object_header, so we don't need call_rcu */
1670 lu_object_header_free(h);
1674 * Concurrency: no concurrent access is possible that late in object
1677 static void osd_index_fini(struct osd_object *o)
1679 struct iam_container *bag;
1681 if (o->oo_dir != NULL) {
1682 bag = &o->oo_dir->od_container;
1683 if (o->oo_inode != NULL) {
1684 if (bag->ic_object == o->oo_inode)
1685 iam_container_fini(bag);
1687 OBD_FREE_PTR(o->oo_dir);
1693 OSD_TXN_OI_DELETE_CREDITS = 20,
1694 OSD_TXN_INODE_DELETE_CREDITS = 20
1701 #if OSD_THANDLE_STATS
1703 * Set time when the handle is allocated
1705 static void osd_th_alloced(struct osd_thandle *oth)
1707 oth->oth_alloced = ktime_get();
1711 * Set time when the handle started
1713 static void osd_th_started(struct osd_thandle *oth)
1715 oth->oth_started = ktime_get();
1719 * Check whether the we deal with this handle for too long.
1721 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
1722 ktime_t alloced, ktime_t started,
1725 ktime_t now = ktime_get();
1727 LASSERT(dev != NULL);
1729 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
1730 ktime_us_delta(started, alloced));
1731 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
1732 ktime_us_delta(closed, started));
1733 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
1734 ktime_us_delta(now, closed));
1736 if (ktime_before(ktime_add_ns(alloced, 30 * NSEC_PER_SEC), now)) {
1737 CWARN("transaction handle %p was open for too long: now %lld, alloced %lld, started %lld, closed %lld\n",
1738 oth, now, alloced, started, closed);
1739 libcfs_debug_dumpstack(NULL);
1743 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
1745 ktime_t __closed = ktime_get(); \
1746 ktime_t __alloced = oth->oth_alloced; \
1747 ktime_t __started = oth->oth_started; \
1750 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
1753 #else /* OSD_THANDLE_STATS */
1755 #define osd_th_alloced(h) do {} while(0)
1756 #define osd_th_started(h) do {} while(0)
1757 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
1759 #endif /* OSD_THANDLE_STATS */
1762 * Concurrency: doesn't access mutable data.
1764 static int osd_param_is_not_sane(const struct osd_device *dev,
1765 const struct thandle *th)
1767 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
1769 return oh->ot_credits > osd_transaction_size(dev);
1773 * Concurrency: shouldn't matter.
1775 static void osd_trans_commit_cb(struct super_block *sb,
1776 struct ldiskfs_journal_cb_entry *jcb, int error)
1778 struct osd_thandle *oh = container_of(jcb, struct osd_thandle, ot_jcb);
1779 struct thandle *th = &oh->ot_super;
1780 struct lu_device *lud = &th->th_dev->dd_lu_dev;
1781 struct osd_device *osd = osd_dev(lud);
1782 struct dt_txn_commit_cb *dcb, *tmp;
1784 LASSERT(oh->ot_handle == NULL);
1787 CERROR("transaction @0x%p commit error: %d\n", th, error);
1789 /* call per-transaction callbacks if any */
1790 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
1792 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1793 "commit callback entry: magic=%x name='%s'\n",
1794 dcb->dcb_magic, dcb->dcb_name);
1795 list_del_init(&dcb->dcb_linkage);
1796 dcb->dcb_func(NULL, th, dcb, error);
1799 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
1800 if (atomic_dec_and_test(&osd->od_commit_cb_in_flight))
1801 wake_up(&osd->od_commit_cb_done);
1807 static struct thandle *osd_trans_create(const struct lu_env *env,
1808 struct dt_device *d)
1810 struct osd_thread_info *oti = osd_oti_get(env);
1811 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1812 struct osd_thandle *oh;
1818 CERROR("%s: someone try to start transaction under "
1819 "readonly mode, should be disabled.\n",
1820 osd_name(osd_dt_dev(d)));
1822 RETURN(ERR_PTR(-EROFS));
1825 /* on pending IO in this thread should left from prev. request */
1826 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
1828 sb_start_write(osd_sb(osd_dt_dev(d)));
1830 OBD_ALLOC_GFP(oh, sizeof(*oh), GFP_NOFS);
1832 sb_end_write(osd_sb(osd_dt_dev(d)));
1833 RETURN(ERR_PTR(-ENOMEM));
1836 oh->ot_quota_trans = &oti->oti_quota_trans;
1837 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
1842 oh->oh_declared_ext = 0;
1843 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
1844 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
1845 INIT_LIST_HEAD(&oh->ot_trunc_locks);
1848 memset(oti->oti_declare_ops, 0,
1849 sizeof(oti->oti_declare_ops));
1850 memset(oti->oti_declare_ops_cred, 0,
1851 sizeof(oti->oti_declare_ops_cred));
1852 memset(oti->oti_declare_ops_used, 0,
1853 sizeof(oti->oti_declare_ops_used));
1855 oti->oti_ins_cache_depth++;
1860 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
1862 struct osd_thread_info *oti = osd_oti_get(env);
1863 struct osd_thandle *oh;
1865 oh = container_of(th, struct osd_thandle, ot_super);
1866 LASSERT(oh != NULL);
1868 CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n",
1869 oti->oti_declare_ops[OSD_OT_CREATE],
1870 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1871 oti->oti_declare_ops_used[OSD_OT_CREATE],
1872 oti->oti_declare_ops[OSD_OT_DESTROY],
1873 oti->oti_declare_ops_cred[OSD_OT_DESTROY],
1874 oti->oti_declare_ops_used[OSD_OT_DESTROY]);
1875 CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
1876 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1877 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1878 oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
1879 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1880 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
1881 oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
1882 CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
1883 oti->oti_declare_ops[OSD_OT_WRITE],
1884 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1885 oti->oti_declare_ops_used[OSD_OT_WRITE],
1886 oti->oti_declare_ops[OSD_OT_PUNCH],
1887 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1888 oti->oti_declare_ops_used[OSD_OT_PUNCH],
1889 oti->oti_declare_ops[OSD_OT_QUOTA],
1890 oti->oti_declare_ops_cred[OSD_OT_QUOTA],
1891 oti->oti_declare_ops_used[OSD_OT_QUOTA]);
1892 CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n",
1893 oti->oti_declare_ops[OSD_OT_INSERT],
1894 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1895 oti->oti_declare_ops_used[OSD_OT_INSERT],
1896 oti->oti_declare_ops[OSD_OT_DELETE],
1897 oti->oti_declare_ops_cred[OSD_OT_DELETE],
1898 oti->oti_declare_ops_used[OSD_OT_DELETE]);
1899 CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
1900 oti->oti_declare_ops[OSD_OT_REF_ADD],
1901 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1902 oti->oti_declare_ops_used[OSD_OT_REF_ADD],
1903 oti->oti_declare_ops[OSD_OT_REF_DEL],
1904 oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
1905 oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
1909 * Concurrency: shouldn't matter.
1911 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1914 struct osd_thread_info *oti = osd_oti_get(env);
1915 struct osd_device *dev = osd_dt_dev(d);
1917 struct osd_thandle *oh;
1922 LASSERT(current->journal_info == NULL);
1924 oh = container_of(th, struct osd_thandle, ot_super);
1925 LASSERT(oh != NULL);
1926 LASSERT(oh->ot_handle == NULL);
1928 rc = dt_txn_hook_start(env, d, th);
1932 if (unlikely(osd_param_is_not_sane(dev, th))) {
1933 static unsigned long last_printed;
1934 static int last_credits;
1937 * don't make noise on a tiny testing systems
1938 * actual credits misuse will be caught anyway
1940 if (last_credits != oh->ot_credits &&
1941 time_after(jiffies, last_printed +
1942 cfs_time_seconds(60)) &&
1943 osd_transaction_size(dev) > 512) {
1944 CWARN("%s: credits %u > trans_max %u\n", osd_name(dev),
1945 oh->ot_credits, osd_transaction_size(dev));
1946 osd_trans_dump_creds(env, th);
1947 libcfs_debug_dumpstack(NULL);
1948 last_credits = oh->ot_credits;
1949 last_printed = jiffies;
1952 * XXX Limit the credits to 'max_transaction_buffers', and
1953 * let the underlying filesystem to catch the error if
1954 * we really need so many credits.
1956 * This should be removed when we can calculate the
1957 * credits precisely.
1959 oh->ot_credits = osd_transaction_size(dev);
1960 } else if (ldiskfs_track_declares_assert != 0) {
1962 * reserve few credits to prevent an assertion in JBD
1963 * our debugging mechanism will be able to detected
1964 * overuse. this can help to debug single-update
1967 oh->ot_credits += 10;
1968 if (unlikely(osd_param_is_not_sane(dev, th)))
1969 oh->ot_credits = osd_transaction_size(dev);
1972 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_TXN_START))
1973 GOTO(out, rc = -EIO);
1976 * XXX temporary stuff. Some abstraction layer should
1979 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1983 LASSERT(oti->oti_txns == 0);
1985 atomic_inc(&dev->od_commit_cb_in_flight);
1986 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1997 static int osd_seq_exists(const struct lu_env *env,
1998 struct osd_device *osd, u64 seq)
2000 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
2001 struct seq_server_site *ss = osd_seq_site(osd);
2006 LASSERT(ss != NULL);
2007 LASSERT(ss->ss_server_fld != NULL);
2009 rc = osd_fld_lookup(env, osd, seq, range);
2012 CERROR("%s: can't lookup FLD sequence %#llx: rc = %d\n",
2013 osd_name(osd), seq, rc);
2017 RETURN(ss->ss_node_id == range->lsr_index);
2020 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
2022 struct dt_txn_commit_cb *dcb;
2023 struct dt_txn_commit_cb *tmp;
2025 /* call per-transaction stop callbacks if any */
2026 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
2028 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
2029 "commit callback entry: magic=%x name='%s'\n",
2030 dcb->dcb_magic, dcb->dcb_name);
2031 list_del_init(&dcb->dcb_linkage);
2032 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
2037 * Concurrency: shouldn't matter.
2039 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
2042 struct osd_thread_info *oti = osd_oti_get(env);
2043 struct osd_thandle *oh;
2044 struct osd_iobuf *iobuf = &oti->oti_iobuf;
2045 struct osd_device *osd = osd_dt_dev(th->th_dev);
2046 struct qsd_instance *qsd = osd_def_qsd(osd);
2047 struct lquota_trans *qtrans;
2048 LIST_HEAD(truncates);
2049 int rc = 0, remove_agents = 0;
2053 oh = container_of(th, struct osd_thandle, ot_super);
2055 remove_agents = oh->ot_remove_agents;
2057 qtrans = oh->ot_quota_trans;
2058 oh->ot_quota_trans = NULL;
2060 /* move locks to local list, stop tx, execute truncates */
2061 list_splice(&oh->ot_trunc_locks, &truncates);
2063 if (oh->ot_handle != NULL) {
2066 handle_t *hdl = oh->ot_handle;
2069 * add commit callback
2070 * notice we don't do this in osd_trans_start()
2071 * as underlying transaction can change during truncate
2073 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
2076 LASSERT(oti->oti_txns == 1);
2079 rc = dt_txn_hook_stop(env, th);
2081 CERROR("%s: failed in transaction hook: rc = %d\n",
2084 osd_trans_stop_cb(oh, rc);
2085 /* hook functions might modify th_sync */
2086 hdl->h_sync = th->th_sync;
2088 oh->ot_handle = NULL;
2089 OSD_CHECK_SLOW_TH(oh, osd, rc2 = ldiskfs_journal_stop(hdl));
2091 CERROR("%s: failed to stop transaction: rc = %d\n",
2092 osd_name(osd), rc2);
2096 /* We preserve the origin behavior of ignoring any
2097 * failures with the underlying punch / truncate
2098 * operation. We do record for debugging if an error
2099 * does occur in the lctl dk logs.
2101 rc2 = osd_process_truncates(env, &truncates);
2103 CERROR("%s: failed truncate process: rc = %d\n",
2104 osd_name(osd), rc2);
2106 osd_trans_stop_cb(oh, th->th_result);
2110 osd_trunc_unlock_all(env, &truncates);
2112 /* inform the quota slave device that the transaction is stopping */
2113 qsd_op_end(env, qsd, qtrans);
2116 * as we want IO to journal and data IO be concurrent, we don't block
2117 * awaiting data IO completion in osd_do_bio(), instead we wait here
2118 * once transaction is submitted to the journal. all reqular requests
2119 * don't do direct IO (except read/write), thus this wait_event becomes
2122 * IMPORTANT: we have to wait till any IO submited by the thread is
2123 * completed otherwise iobuf may be corrupted by different request
2125 wait_event(iobuf->dr_wait,
2126 atomic_read(&iobuf->dr_numreqs) == 0);
2127 osd_fini_iobuf(osd, iobuf);
2129 rc = iobuf->dr_error;
2131 if (unlikely(remove_agents != 0))
2132 osd_process_scheduled_agent_removals(env, osd);
2134 LASSERT(oti->oti_ins_cache_depth > 0);
2135 oti->oti_ins_cache_depth--;
2136 /* reset OI cache for safety */
2137 if (oti->oti_ins_cache_depth == 0)
2138 oti->oti_ins_cache_used = 0;
2140 sb_end_write(osd_sb(osd));
2145 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
2147 struct osd_thandle *oh = container_of(th, struct osd_thandle,
2150 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
2151 LASSERT(&dcb->dcb_func != NULL);
2152 if (dcb->dcb_flags & DCB_TRANS_STOP)
2153 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
2155 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
2161 * Called just before object is freed. Releases all resources except for
2162 * object itself (that is released by osd_object_free()).
2164 * Concurrency: no concurrent access is possible that late in object
2167 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
2169 struct osd_object *obj = osd_obj(l);
2170 struct qsd_instance *qsd = osd_def_qsd(osd_obj2dev(obj));
2171 struct inode *inode = obj->oo_inode;
2176 LINVRNT(osd_invariant(obj));
2179 * If object is unlinked remove fid->ino mapping from object index.
2182 osd_index_fini(obj);
2187 if (osd_has_index(obj) && obj->oo_dt.do_index_ops == &osd_index_iam_ops)
2188 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2190 uid = i_uid_read(inode);
2191 gid = i_gid_read(inode);
2192 projid = i_projid_read(inode);
2194 obj->oo_inode = NULL;
2197 /* do not rebalance quota if the caller needs to release memory
2198 * otherwise qsd_refresh_usage() may went into a new ldiskfs
2199 * transaction and risk to deadlock - LU-12178 */
2200 if (current->flags & (PF_MEMALLOC | PF_KSWAPD))
2203 if (!obj->oo_header && qsd) {
2204 struct osd_thread_info *info = osd_oti_get(env);
2205 struct lquota_id_info *qi = &info->oti_qi;
2207 /* Release granted quota to master if necessary */
2208 qi->lqi_id.qid_uid = uid;
2209 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
2211 qi->lqi_id.qid_uid = gid;
2212 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
2214 qi->lqi_id.qid_uid = projid;
2215 qsd_op_adjust(env, qsd, &qi->lqi_id, PRJQUOTA);
2220 * Concurrency: ->loo_object_release() is called under site spin-lock.
2222 static void osd_object_release(const struct lu_env *env,
2223 struct lu_object *l)
2225 struct osd_object *o = osd_obj(l);
2228 * nobody should be releasing a non-destroyed object with nlink=0
2229 * the API allows this, but ldiskfs doesn't like and then report
2230 * this inode as deleted
2232 LASSERT(!(o->oo_destroyed == 0 && o->oo_inode &&
2233 o->oo_inode->i_nlink == 0));
2237 * Concurrency: shouldn't matter.
2239 static int osd_object_print(const struct lu_env *env, void *cookie,
2240 lu_printer_t p, const struct lu_object *l)
2242 struct osd_object *o = osd_obj(l);
2243 struct iam_descr *d;
2245 if (o->oo_dir != NULL)
2246 d = o->oo_dir->od_container.ic_descr;
2249 return (*p)(env, cookie,
2250 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
2252 o->oo_inode ? o->oo_inode->i_ino : 0UL,
2253 o->oo_inode ? o->oo_inode->i_generation : 0,
2254 d ? d->id_ops->id_name : "plain");
2258 * Concurrency: shouldn't matter.
2260 int osd_statfs(const struct lu_env *env, struct dt_device *d,
2261 struct obd_statfs *sfs, struct obd_statfs_info *info)
2263 struct osd_device *osd = osd_dt_dev(d);
2264 struct super_block *sb = osd_sb(osd);
2265 struct kstatfs *ksfs;
2269 if (unlikely(osd->od_mnt == NULL))
2270 return -EINPROGRESS;
2272 /* osd_lproc.c call this without env, allocate ksfs for that case */
2273 if (unlikely(env == NULL)) {
2274 OBD_ALLOC_PTR(ksfs);
2278 ksfs = &osd_oti_get(env)->oti_ksfs;
2281 result = sb->s_op->statfs(sb->s_root, ksfs);
2285 statfs_pack(sfs, ksfs);
2286 if (unlikely(sb->s_flags & SB_RDONLY))
2287 sfs->os_state |= OS_STATFS_READONLY;
2289 sfs->os_state |= osd->od_nonrotational ? OS_STATFS_NONROT : 0;
2291 if (ldiskfs_has_feature_extents(sb))
2292 sfs->os_maxbytes = sb->s_maxbytes;
2294 sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2297 * Reserve some space so to avoid fragmenting the filesystem too much.
2298 * Fragmentation not only impacts performance, but can also increase
2299 * metadata overhead significantly, causing grant calculation to be
2302 * Reserve 0.78% of total space, at least 8MB for small filesystems.
2304 BUILD_BUG_ON(OSD_STATFS_RESERVED <= LDISKFS_MAX_BLOCK_SIZE);
2305 reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits;
2306 if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT))
2307 reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT;
2309 sfs->os_blocks -= reserved;
2310 sfs->os_bfree -= min(reserved, sfs->os_bfree);
2311 sfs->os_bavail -= min(reserved, sfs->os_bavail);
2314 if (unlikely(env == NULL))
2320 * Estimate space needed for file creations. We assume the largest filename
2321 * which is 2^64 - 1, hence a filename of 20 chars.
2322 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
2324 #ifdef __LDISKFS_DIR_REC_LEN
2325 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
2327 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
2331 * Concurrency: doesn't access mutable data.
2333 static void osd_conf_get(const struct lu_env *env,
2334 const struct dt_device *dev,
2335 struct dt_device_param *param)
2337 struct osd_device *d = osd_dt_dev(dev);
2338 struct super_block *sb = osd_sb(d);
2339 struct blk_integrity *bi = bdev_get_integrity(sb->s_bdev);
2344 * XXX should be taken from not-yet-existing fs abstraction layer.
2346 param->ddp_max_name_len = LDISKFS_NAME_LEN;
2347 param->ddp_max_nlink = LDISKFS_LINK_MAX;
2348 param->ddp_symlink_max = sb->s_blocksize;
2349 param->ddp_mount_type = LDD_MT_LDISKFS;
2350 if (ldiskfs_has_feature_extents(sb))
2351 param->ddp_maxbytes = sb->s_maxbytes;
2353 param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2355 * inode are statically allocated, so per-inode space consumption
2356 * is the space consumed by the directory entry
2358 param->ddp_inodespace = PER_OBJ_USAGE;
2360 * EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks
2361 * is 128MB) which is unlikely to be hit in real life. Report a smaller
2362 * maximum length to not under-count the actual number of extents
2363 * needed for writing a file if there are sub-optimal block allocations.
2365 param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 1;
2366 /* worst-case extent insertion metadata overhead */
2367 param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb);
2368 param->ddp_mntopts = 0;
2369 if (test_opt(sb, XATTR_USER))
2370 param->ddp_mntopts |= MNTOPT_USERXATTR;
2371 if (test_opt(sb, POSIX_ACL))
2372 param->ddp_mntopts |= MNTOPT_ACL;
2375 * LOD might calculate the max stripe count based on max_ea_size,
2376 * so we need take account in the overhead as well,
2377 * xattr_header + magic + xattr_entry_head
2379 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
2380 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
2382 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
2383 if (ldiskfs_has_feature_ea_inode(sb))
2384 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
2388 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
2390 if (param->ddp_max_ea_size > OBD_MAX_EA_SIZE)
2391 param->ddp_max_ea_size = OBD_MAX_EA_SIZE;
2394 * Preferred RPC size for efficient disk IO. 4MB shows good
2395 * all-around performance for ldiskfs, but use bigalloc chunk size
2396 * by default if larger.
2398 #if defined(LDISKFS_CLUSTER_SIZE)
2399 if (LDISKFS_CLUSTER_SIZE(sb) > DT_DEF_BRW_SIZE)
2400 param->ddp_brw_size = LDISKFS_CLUSTER_SIZE(sb);
2403 param->ddp_brw_size = DT_DEF_BRW_SIZE;
2405 param->ddp_t10_cksum_type = 0;
2407 unsigned short interval = blk_integrity_interval(bi);
2408 name = blk_integrity_name(bi);
2416 if (strncmp(name, "T10-DIF-TYPE",
2417 sizeof("T10-DIF-TYPE") - 1) == 0) {
2418 /* also skip "1/3-" at end */
2419 const int type_off = sizeof("T10-DIF-TYPE.");
2420 char type_number = name[type_off - 2];
2422 if (interval != 512 && interval != 4096) {
2423 CERROR("%s: unsupported T10PI sector size %u\n",
2424 d->od_svname, interval);
2425 } else if (type_number != '1' && type_number != '3') {
2426 CERROR("%s: unsupported T10PI type %s\n",
2427 d->od_svname, name);
2428 } else if (strcmp(name + type_off, "CRC") == 0) {
2429 d->od_t10_type = type_number == '1' ?
2430 OSD_T10_TYPE1_CRC : OSD_T10_TYPE3_CRC;
2431 param->ddp_t10_cksum_type = interval == 512 ?
2432 OBD_CKSUM_T10CRC512 :
2434 } else if (strcmp(name + type_off, "IP") == 0) {
2435 d->od_t10_type = type_number == '1' ?
2436 OSD_T10_TYPE1_IP : OSD_T10_TYPE3_IP;
2437 param->ddp_t10_cksum_type = interval == 512 ?
2438 OBD_CKSUM_T10IP512 :
2441 CERROR("%s: unsupported checksum type of T10PI type '%s'\n",
2442 d->od_svname, name);
2446 CERROR("%s: unsupported T10PI type '%s'\n",
2447 d->od_svname, name);
2451 param->ddp_has_lseek_data_hole = true;
2454 static struct super_block *osd_mnt_sb_get(const struct dt_device *d)
2456 return osd_sb(osd_dt_dev(d));
2460 * Concurrency: shouldn't matter.
2462 static int osd_sync(const struct lu_env *env, struct dt_device *d)
2465 struct super_block *s = osd_sb(osd_dt_dev(d));
2468 down_read(&s->s_umount);
2469 rc = s->s_op->sync_fs(s, 1);
2470 up_read(&s->s_umount);
2472 CDEBUG(D_CACHE, "%s: synced OSD: rc = %d\n", osd_dt_dev(d)->od_svname,
2479 * Start commit for OSD device.
2481 * An implementation of dt_commit_async method for OSD device.
2482 * Asychronously starts underlayng fs sync and thereby a transaction
2485 * \param env environment
2486 * \param d dt device
2488 * \see dt_device_operations
2490 static int osd_commit_async(const struct lu_env *env,
2491 struct dt_device *d)
2493 struct super_block *s = osd_sb(osd_dt_dev(d));
2498 CDEBUG(D_HA, "%s: async commit OSD\n", osd_dt_dev(d)->od_svname);
2499 down_read(&s->s_umount);
2500 rc = s->s_op->sync_fs(s, 0);
2501 up_read(&s->s_umount);
2507 * Concurrency: shouldn't matter.
2509 static int osd_ro(const struct lu_env *env, struct dt_device *d)
2511 struct super_block *sb = osd_sb(osd_dt_dev(d));
2512 struct block_device *dev = sb->s_bdev;
2513 int rc = -EOPNOTSUPP;
2517 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
2518 osd_dt_dev(d)->od_svname, (long)dev, rc);
2524 * Note: we do not count into QUOTA here.
2525 * If we mount with --data_journal we may need more.
2527 const int osd_dto_credits_noquota[DTO_NR] = {
2530 * INDEX_EXTRA_TRANS_BLOCKS(8) +
2531 * SINGLEDATA_TRANS_BLOCKS(8)
2532 * XXX Note: maybe iam need more, since iam have more level than
2535 [DTO_INDEX_INSERT] = 16,
2538 * just modify a single entry, probably merge few within a block
2540 [DTO_INDEX_DELETE] = 1,
2544 [DTO_INDEX_UPDATE] = 16,
2546 * 4(inode, inode bits, groups, GDT)
2547 * notice: OI updates are counted separately with DTO_INDEX_INSERT
2549 [DTO_OBJECT_CREATE] = 4,
2551 * 4(inode, inode bits, groups, GDT)
2552 * notice: OI updates are counted separately with DTO_INDEX_DELETE
2554 [DTO_OBJECT_DELETE] = 4,
2556 * Attr set credits (inode)
2558 [DTO_ATTR_SET_BASE] = 1,
2560 * Xattr set. The same as xattr of EXT3.
2561 * DATA_TRANS_BLOCKS(14)
2562 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
2563 * are also counted in. Do not know why?
2565 [DTO_XATTR_SET] = 14,
2567 * credits for inode change during write.
2569 [DTO_WRITE_BASE] = 3,
2571 * credits for single block write.
2573 [DTO_WRITE_BLOCK] = 14,
2575 * Attr set credits for chown.
2576 * This is extra credits for setattr, and it is null without quota
2578 [DTO_ATTR_SET_CHOWN] = 0
2581 /* reserve or free quota for some operation */
2582 static int osd_reserve_or_free_quota(const struct lu_env *env,
2583 struct dt_device *dev,
2584 enum quota_type type, __u64 uid,
2585 __u64 gid, __s64 count, bool is_md)
2588 struct osd_device *osd = osd_dt_dev(dev);
2589 struct osd_thread_info *info = osd_oti_get(env);
2590 struct lquota_id_info *qi = &info->oti_qi;
2591 struct qsd_instance *qsd = NULL;
2596 qsd = osd->od_quota_slave_md;
2598 qsd = osd->od_quota_slave_dt;
2600 rc = quota_reserve_or_free(env, qsd, qi, type, uid, gid, count, is_md);
2604 static const struct dt_device_operations osd_dt_ops = {
2605 .dt_root_get = osd_root_get,
2606 .dt_statfs = osd_statfs,
2607 .dt_trans_create = osd_trans_create,
2608 .dt_trans_start = osd_trans_start,
2609 .dt_trans_stop = osd_trans_stop,
2610 .dt_trans_cb_add = osd_trans_cb_add,
2611 .dt_conf_get = osd_conf_get,
2612 .dt_mnt_sb_get = osd_mnt_sb_get,
2613 .dt_sync = osd_sync,
2615 .dt_commit_async = osd_commit_async,
2616 .dt_reserve_or_free_quota = osd_reserve_or_free_quota,
2619 static void osd_read_lock(const struct lu_env *env, struct dt_object *dt,
2622 struct osd_object *obj = osd_dt_obj(dt);
2623 struct osd_thread_info *oti = osd_oti_get(env);
2625 LINVRNT(osd_invariant(obj));
2627 LASSERT(obj->oo_owner != env);
2628 down_read_nested(&obj->oo_sem, role);
2630 LASSERT(obj->oo_owner == NULL);
2634 static void osd_write_lock(const struct lu_env *env, struct dt_object *dt,
2637 struct osd_object *obj = osd_dt_obj(dt);
2638 struct osd_thread_info *oti = osd_oti_get(env);
2640 LINVRNT(osd_invariant(obj));
2642 LASSERT(obj->oo_owner != env);
2643 down_write_nested(&obj->oo_sem, role);
2645 LASSERT(obj->oo_owner == NULL);
2646 obj->oo_owner = env;
2650 static void osd_read_unlock(const struct lu_env *env, struct dt_object *dt)
2652 struct osd_object *obj = osd_dt_obj(dt);
2653 struct osd_thread_info *oti = osd_oti_get(env);
2655 LINVRNT(osd_invariant(obj));
2657 LASSERT(oti->oti_r_locks > 0);
2659 up_read(&obj->oo_sem);
2662 static void osd_write_unlock(const struct lu_env *env, struct dt_object *dt)
2664 struct osd_object *obj = osd_dt_obj(dt);
2665 struct osd_thread_info *oti = osd_oti_get(env);
2667 LINVRNT(osd_invariant(obj));
2669 LASSERT(obj->oo_owner == env);
2670 LASSERT(oti->oti_w_locks > 0);
2672 obj->oo_owner = NULL;
2673 up_write(&obj->oo_sem);
2676 static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
2678 struct osd_object *obj = osd_dt_obj(dt);
2680 LINVRNT(osd_invariant(obj));
2682 return obj->oo_owner == env;
2685 static void osd_inode_getattr(const struct lu_env *env,
2686 struct inode *inode, struct lu_attr *attr)
2688 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2689 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2690 LA_PROJID | LA_FLAGS | LA_NLINK | LA_RDEV |
2691 LA_BLKSIZE | LA_TYPE | LA_BTIME;
2693 attr->la_atime = inode->i_atime.tv_sec;
2694 attr->la_mtime = inode->i_mtime.tv_sec;
2695 attr->la_ctime = inode->i_ctime.tv_sec;
2696 attr->la_btime = LDISKFS_I(inode)->i_crtime.tv_sec;
2697 attr->la_mode = inode->i_mode;
2698 attr->la_size = i_size_read(inode);
2699 attr->la_blocks = inode->i_blocks;
2700 attr->la_uid = i_uid_read(inode);
2701 attr->la_gid = i_gid_read(inode);
2702 attr->la_projid = i_projid_read(inode);
2703 attr->la_flags = ll_inode_to_ext_flags(inode->i_flags);
2704 attr->la_nlink = inode->i_nlink;
2705 attr->la_rdev = inode->i_rdev;
2706 attr->la_blksize = 1 << inode->i_blkbits;
2707 attr->la_blkbits = inode->i_blkbits;
2709 * Ext4 did not transfer inherit flags from raw inode
2710 * to inode flags, and ext4 internally test raw inode
2711 * @i_flags directly. Instead of patching ext4, we do it here.
2713 if (LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL)
2714 attr->la_flags |= LUSTRE_PROJINHERIT_FL;
2717 static int osd_dirent_count(const struct lu_env *env, struct dt_object *dt,
2720 struct osd_object *obj = osd_dt_obj(dt);
2721 const struct dt_it_ops *iops;
2727 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2728 LASSERT(fid_is_namespace_visible(lu_object_fid(&obj->oo_dt.do_lu)));
2730 if (obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
2731 *count = obj->oo_dirent_count;
2735 /* directory not initialized yet */
2736 if (!dt->do_index_ops) {
2741 iops = &dt->do_index_ops->dio_it;
2742 it = iops->init(env, dt, LUDA_64BITHASH);
2744 RETURN(PTR_ERR(it));
2746 rc = iops->load(env, it, 0);
2748 if (rc == -ENODATA) {
2755 rc = iops->next(env, it);
2757 for (*count = 0; rc == 0 || rc == -ESTALE; rc = iops->next(env, it)) {
2761 if (iops->key_size(env, it) == 0)
2767 obj->oo_dirent_count = *count;
2772 iops->fini(env, it);
2777 static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
2778 struct lu_attr *attr)
2780 struct osd_object *obj = osd_dt_obj(dt);
2783 if (unlikely(!dt_object_exists(dt)))
2785 if (unlikely(obj->oo_destroyed))
2788 LASSERT(!dt_object_remote(dt));
2789 LINVRNT(osd_invariant(obj));
2791 spin_lock(&obj->oo_guard);
2792 osd_inode_getattr(env, obj->oo_inode, attr);
2793 if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) {
2794 attr->la_valid |= LA_FLAGS;
2795 attr->la_flags |= LUSTRE_ORPHAN_FL;
2797 if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL) {
2798 attr->la_valid |= LA_FLAGS;
2799 attr->la_flags |= LUSTRE_ENCRYPT_FL;
2801 spin_unlock(&obj->oo_guard);
2803 if (S_ISDIR(obj->oo_inode->i_mode) &&
2804 fid_is_namespace_visible(lu_object_fid(&dt->do_lu)))
2805 rc = osd_dirent_count(env, dt, &attr->la_dirent_count);
2810 static int osd_declare_attr_qid(const struct lu_env *env,
2811 struct osd_object *obj,
2812 struct osd_thandle *oh, long long bspace,
2813 qid_t old_id, qid_t new_id, bool enforce,
2817 struct osd_thread_info *info = osd_oti_get(env);
2818 struct lquota_id_info *qi = &info->oti_qi;
2820 qi->lqi_type = type;
2821 /* inode accounting */
2822 qi->lqi_is_blk = false;
2824 /* one more inode for the new id ... */
2825 qi->lqi_id.qid_uid = new_id;
2827 /* Reserve credits for the new id */
2828 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2829 if (rc == -EDQUOT || rc == -EINPROGRESS)
2834 /* and one less inode for the current id */
2835 qi->lqi_id.qid_uid = old_id;
2837 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2838 if (rc == -EDQUOT || rc == -EINPROGRESS)
2843 /* block accounting */
2844 qi->lqi_is_blk = true;
2846 /* more blocks for the new id ... */
2847 qi->lqi_id.qid_uid = new_id;
2848 qi->lqi_space = bspace;
2850 * Credits for the new uid has been reserved, re-use "obj"
2851 * to save credit reservation.
2853 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2854 if (rc == -EDQUOT || rc == -EINPROGRESS)
2859 /* and finally less blocks for the current uid */
2860 qi->lqi_id.qid_uid = old_id;
2861 qi->lqi_space = -bspace;
2862 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2863 if (rc == -EDQUOT || rc == -EINPROGRESS)
2869 static int osd_declare_attr_set(const struct lu_env *env,
2870 struct dt_object *dt,
2871 const struct lu_attr *attr,
2872 struct thandle *handle)
2874 struct osd_thandle *oh;
2875 struct osd_object *obj;
2884 LASSERT(dt != NULL);
2885 LASSERT(handle != NULL);
2887 obj = osd_dt_obj(dt);
2888 LASSERT(osd_invariant(obj));
2890 oh = container_of(handle, struct osd_thandle, ot_super);
2891 LASSERT(oh->ot_handle == NULL);
2893 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
2894 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2896 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2897 osd_dto_credits_noquota[DTO_XATTR_SET]);
2899 if (attr == NULL || obj->oo_inode == NULL)
2902 bspace = obj->oo_inode->i_blocks << 9;
2903 bspace = toqb(bspace);
2906 * Changing ownership is always preformed by super user, it should not
2907 * fail with EDQUOT unless required explicitly.
2909 * We still need to call the osd_declare_qid() to calculate the journal
2910 * credits for updating quota accounting files and to trigger quota
2911 * space adjustment once the operation is completed.
2913 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
2915 uid = i_uid_read(obj->oo_inode);
2916 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
2917 rc = osd_declare_attr_qid(env, obj, oh, bspace, uid,
2918 attr->la_uid, enforce, USRQUOTA);
2922 gid = i_gid_read(obj->oo_inode);
2923 CDEBUG(D_QUOTA, "declare uid %d -> %d gid %d -> %d\n", uid,
2924 attr->la_uid, gid, attr->la_gid);
2925 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
2926 rc = osd_declare_attr_qid(env, obj, oh, bspace, gid,
2927 attr->la_gid, enforce, GRPQUOTA);
2932 #ifdef HAVE_PROJECT_QUOTA
2933 if (attr->la_valid & LA_PROJID) {
2934 __u32 projid = i_projid_read(obj->oo_inode);
2936 enforce = (attr->la_valid & LA_PROJID) &&
2937 (attr->la_projid != projid);
2938 rc = osd_declare_attr_qid(env, obj, oh, bspace,
2939 (qid_t)projid, (qid_t)attr->la_projid,
2948 static int osd_inode_setattr(const struct lu_env *env,
2949 struct inode *inode, const struct lu_attr *attr)
2951 __u64 bits = attr->la_valid;
2953 /* Only allow set size for regular file */
2954 if (!S_ISREG(inode->i_mode))
2955 bits &= ~(LA_SIZE | LA_BLOCKS);
2960 if (bits & LA_ATIME)
2961 inode->i_atime = osd_inode_time(inode, attr->la_atime);
2962 if (bits & LA_CTIME)
2963 inode->i_ctime = osd_inode_time(inode, attr->la_ctime);
2964 if (bits & LA_MTIME)
2965 inode->i_mtime = osd_inode_time(inode, attr->la_mtime);
2966 if (bits & LA_SIZE) {
2967 spin_lock(&inode->i_lock);
2968 LDISKFS_I(inode)->i_disksize = attr->la_size;
2969 i_size_write(inode, attr->la_size);
2970 spin_unlock(&inode->i_lock);
2974 * OSD should not change "i_blocks" which is used by quota.
2975 * "i_blocks" should be changed by ldiskfs only.
2978 inode->i_mode = (inode->i_mode & S_IFMT) |
2979 (attr->la_mode & ~S_IFMT);
2981 i_uid_write(inode, attr->la_uid);
2983 i_gid_write(inode, attr->la_gid);
2984 if (bits & LA_PROJID)
2985 i_projid_write(inode, attr->la_projid);
2986 if (bits & LA_NLINK)
2987 set_nlink(inode, attr->la_nlink);
2989 inode->i_rdev = attr->la_rdev;
2991 if (bits & LA_FLAGS) {
2992 /* always keep S_NOCMTIME */
2993 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
2995 #if defined(S_ENCRYPTED)
2996 /* Always remove S_ENCRYPTED, because ldiskfs must not be
2997 * aware of encryption status. It is just stored into LMA
2998 * so that it can be forwared to client side.
3000 inode->i_flags &= ~S_ENCRYPTED;
3003 * Ext4 did not transfer inherit flags from
3004 * @inode->i_flags to raw inode i_flags when writing
3005 * flags, we do it explictly here.
3007 if (attr->la_flags & LUSTRE_PROJINHERIT_FL)
3008 LDISKFS_I(inode)->i_flags |= LUSTRE_PROJINHERIT_FL;
3010 LDISKFS_I(inode)->i_flags &= ~LUSTRE_PROJINHERIT_FL;
3015 #ifdef HAVE_PROJECT_QUOTA
3016 static int osd_transfer_project(struct inode *inode, __u32 projid,
3017 struct thandle *handle)
3019 struct super_block *sb = inode->i_sb;
3020 struct ldiskfs_inode_info *ei = LDISKFS_I(inode);
3023 struct ldiskfs_iloc iloc;
3024 struct ldiskfs_inode *raw_inode;
3025 struct dquot *transfer_to[LDISKFS_MAXQUOTAS] = { };
3027 if (!ldiskfs_has_feature_project(sb)) {
3028 LASSERT(__kprojid_val(LDISKFS_I(inode)->i_projid)
3029 == LDISKFS_DEF_PROJID);
3030 if (projid != LDISKFS_DEF_PROJID)
3036 if (LDISKFS_INODE_SIZE(sb) <= LDISKFS_GOOD_OLD_INODE_SIZE)
3039 kprojid = make_kprojid(&init_user_ns, (projid_t)projid);
3040 if (projid_eq(kprojid, LDISKFS_I(inode)->i_projid))
3043 err = ldiskfs_get_inode_loc(inode, &iloc);
3047 raw_inode = ldiskfs_raw_inode(&iloc);
3048 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3049 struct osd_thandle *oh = container_of(handle,
3053 * try to expand inode size automatically.
3055 ldiskfs_mark_inode_dirty(oh->ot_handle, inode);
3056 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3064 dquot_initialize(inode);
3065 transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
3066 if (transfer_to[PRJQUOTA]) {
3067 lock_dquot_transfer(inode);
3068 err = __dquot_transfer(inode, transfer_to);
3069 unlock_dquot_transfer(inode);
3070 dqput(transfer_to[PRJQUOTA]);
3079 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr,
3080 struct thandle *handle)
3084 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
3085 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
3089 "executing dquot_transfer inode %ld uid %d -> %d gid %d -> %d\n",
3090 inode->i_ino, i_uid_read(inode), attr->la_uid,
3091 i_gid_read(inode), attr->la_gid);
3093 dquot_initialize(inode);
3095 if (attr->la_valid & LA_UID)
3096 iattr.ia_valid |= ATTR_UID;
3097 if (attr->la_valid & LA_GID)
3098 iattr.ia_valid |= ATTR_GID;
3099 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
3100 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
3102 lock_dquot_transfer(inode);
3103 rc = dquot_transfer(inode, &iattr);
3104 unlock_dquot_transfer(inode);
3106 CERROR("%s: quota transfer failed. Is quota enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3107 osd_ino2name(inode), rc);
3112 /* Handle project id transfer here properly */
3113 if (attr->la_valid & LA_PROJID &&
3114 attr->la_projid != i_projid_read(inode)) {
3115 if (!projid_valid(make_kprojid(&init_user_ns, attr->la_projid)))
3117 #ifdef HAVE_PROJECT_QUOTA
3118 rc = osd_transfer_project(inode, attr->la_projid, handle);
3123 CERROR("%s: quota transfer failed. Is project enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3124 osd_ino2name(inode), rc);
3131 static int osd_attr_set(const struct lu_env *env,
3132 struct dt_object *dt,
3133 const struct lu_attr *attr,
3134 struct thandle *handle)
3136 struct osd_object *obj = osd_dt_obj(dt);
3137 struct inode *inode;
3140 if (!dt_object_exists(dt))
3143 LASSERT(handle != NULL);
3144 LASSERT(!dt_object_remote(dt));
3145 LASSERT(osd_invariant(obj));
3147 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
3149 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING) &&
3150 !osd_obj2dev(obj)->od_is_ost) {
3151 struct osd_thread_info *oti = osd_oti_get(env);
3152 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
3153 struct lu_fid *fid1 = &oti->oti_fid;
3154 struct osd_inode_id *id = &oti->oti_id;
3155 struct iam_path_descr *ipd;
3156 struct iam_container *bag;
3157 struct osd_thandle *oh;
3160 fid_cpu_to_be(fid1, fid0);
3161 memset(id, 1, sizeof(*id));
3162 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
3163 fid0)->oi_dir.od_container;
3164 ipd = osd_idx_ipd_get(env, bag);
3165 if (unlikely(ipd == NULL))
3168 oh = container_of(handle, struct osd_thandle, ot_super);
3169 rc = iam_update(oh->ot_handle, bag,
3170 (const struct iam_key *)fid1,
3171 (const struct iam_rec *)id, ipd);
3172 osd_ipd_put(env, bag, ipd);
3173 return(rc > 0 ? 0 : rc);
3176 inode = obj->oo_inode;
3178 rc = osd_quota_transfer(inode, attr, handle);
3182 spin_lock(&obj->oo_guard);
3183 rc = osd_inode_setattr(env, inode, attr);
3184 spin_unlock(&obj->oo_guard);
3188 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3190 osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
3192 if (!(attr->la_valid & LA_FLAGS))
3195 /* Let's check if there are extra flags need to be set into LMA */
3196 if (attr->la_flags & LUSTRE_LMA_FL_MASKS) {
3197 struct osd_thread_info *info = osd_oti_get(env);
3198 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
3200 LASSERT(!obj->oo_pfid_in_lma);
3202 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
3203 &info->oti_ost_attrs);
3207 lma->lma_incompat |=
3208 lustre_to_lma_flags(attr->la_flags);
3209 lustre_lma_swab(lma);
3211 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3213 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA,
3214 lma, sizeof(*lma), XATTR_REPLACE);
3216 struct osd_device *osd = osd_obj2dev(obj);
3218 CWARN("%s: set "DFID" lma flags %u failed: rc = %d\n",
3219 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)),
3220 lma->lma_incompat, rc);
3223 attr->la_flags & LUSTRE_LMA_FL_MASKS;
3225 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
3232 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
3233 struct osd_object *obj,
3234 const char *name, const int namelen)
3236 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
3239 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
3240 umode_t mode, struct dt_allocation_hint *hint,
3241 struct thandle *th, struct lu_attr *attr)
3244 struct osd_device *osd = osd_obj2dev(obj);
3245 struct osd_thandle *oth;
3246 struct dt_object *parent = NULL;
3247 struct inode *inode;
3248 struct iattr iattr = {
3249 .ia_valid = ATTR_UID | ATTR_GID |
3250 ATTR_CTIME | ATTR_MTIME | ATTR_ATIME,
3251 .ia_ctime.tv_sec = attr->la_ctime,
3252 .ia_mtime.tv_sec = attr->la_mtime,
3253 .ia_atime.tv_sec = attr->la_atime,
3254 .ia_uid = GLOBAL_ROOT_UID,
3255 .ia_gid = GLOBAL_ROOT_GID,
3257 const struct osd_timespec omit = { .tv_nsec = UTIME_OMIT };
3259 if (attr->la_valid & LA_UID)
3260 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
3261 if (attr->la_valid & LA_GID)
3262 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
3264 LINVRNT(osd_invariant(obj));
3265 LASSERT(obj->oo_inode == NULL);
3266 LASSERT(obj->oo_hl_head == NULL);
3268 if (S_ISDIR(mode) && ldiskfs_pdo) {
3270 ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
3271 if (obj->oo_hl_head == NULL)
3275 oth = container_of(th, struct osd_thandle, ot_super);
3276 LASSERT(oth->ot_handle->h_transaction != NULL);
3278 if (hint != NULL && hint->dah_parent != NULL &&
3279 !dt_object_remote(hint->dah_parent))
3280 parent = hint->dah_parent;
3282 /* if a time component is not valid set it to UTIME_OMIT */
3283 if (!(attr->la_valid & LA_CTIME))
3284 iattr.ia_ctime = omit;
3285 if (!(attr->la_valid & LA_MTIME))
3286 iattr.ia_mtime = omit;
3287 if (!(attr->la_valid & LA_ATIME))
3288 iattr.ia_atime = omit;
3290 inode = ldiskfs_create_inode(oth->ot_handle,
3291 parent ? osd_dt_obj(parent)->oo_inode :
3292 osd_sb(osd)->s_root->d_inode,
3294 if (!IS_ERR(inode)) {
3295 /* Do not update file c/mtime in ldiskfs. */
3296 inode->i_flags |= S_NOCMTIME;
3299 * For new created object, it must be consistent,
3300 * and it is unnecessary to scrub against it.
3302 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
3304 obj->oo_inode = inode;
3307 if (obj->oo_hl_head != NULL) {
3308 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
3309 obj->oo_hl_head = NULL;
3311 result = PTR_ERR(inode);
3313 LINVRNT(osd_invariant(obj));
3321 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
3322 struct lu_attr *attr,
3323 struct dt_allocation_hint *hint,
3324 struct dt_object_format *dof,
3328 struct osd_thandle *oth;
3329 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX | S_ISGID));
3331 LASSERT(S_ISDIR(attr->la_mode));
3333 oth = container_of(th, struct osd_thandle, ot_super);
3334 LASSERT(oth->ot_handle->h_transaction != NULL);
3335 if (fid_is_namespace_visible(lu_object_fid(&obj->oo_dt.do_lu)))
3336 obj->oo_dirent_count = 0;
3337 result = osd_mkfile(info, obj, mode, hint, th, attr);
3342 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
3343 struct lu_attr *attr,
3344 struct dt_allocation_hint *hint,
3345 struct dt_object_format *dof,
3349 struct osd_thandle *oth;
3350 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
3352 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
3354 LASSERT(S_ISREG(attr->la_mode));
3356 oth = container_of(th, struct osd_thandle, ot_super);
3357 LASSERT(oth->ot_handle->h_transaction != NULL);
3359 result = osd_mkfile(info, obj, mode, hint, th, attr);
3361 LASSERT(obj->oo_inode != NULL);
3362 if (feat->dif_flags & DT_IND_VARKEY)
3363 result = iam_lvar_create(obj->oo_inode,
3364 feat->dif_keysize_max,
3366 feat->dif_recsize_max,
3369 result = iam_lfix_create(obj->oo_inode,
3370 feat->dif_keysize_max,
3372 feat->dif_recsize_max,
3378 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
3379 struct lu_attr *attr,
3380 struct dt_allocation_hint *hint,
3381 struct dt_object_format *dof,
3384 LASSERT(S_ISREG(attr->la_mode));
3385 return osd_mkfile(info, obj, (attr->la_mode &
3386 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th,
3390 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
3391 struct lu_attr *attr,
3392 struct dt_allocation_hint *hint,
3393 struct dt_object_format *dof,
3396 LASSERT(S_ISLNK(attr->la_mode));
3397 return osd_mkfile(info, obj, (attr->la_mode &
3398 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th,
3402 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
3403 struct lu_attr *attr,
3404 struct dt_allocation_hint *hint,
3405 struct dt_object_format *dof,
3408 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
3411 LINVRNT(osd_invariant(obj));
3412 LASSERT(obj->oo_inode == NULL);
3413 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
3414 S_ISFIFO(mode) || S_ISSOCK(mode));
3416 result = osd_mkfile(info, obj, mode, hint, th, attr);
3418 LASSERT(obj->oo_inode != NULL);
3420 * This inode should be marked dirty for i_rdev. Currently
3421 * that is done in the osd_attr_init().
3423 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
3426 LINVRNT(osd_invariant(obj));
3430 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
3432 struct dt_allocation_hint *hint,
3433 struct dt_object_format *dof,
3436 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
3438 osd_obj_type_f result;
3454 result = osd_mk_index;
3464 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
3465 struct dt_object *parent, struct dt_object *child,
3470 ah->dah_parent = parent;
3471 ah->dah_mode = child_mode;
3473 if (parent != NULL && !dt_object_remote(parent)) {
3474 /* will help to find FID->ino at dt_insert("..") */
3475 struct osd_object *pobj = osd_dt_obj(parent);
3477 osd_idc_find_and_init(env, osd_obj2dev(pobj), pobj);
3481 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
3482 struct lu_attr *attr, struct dt_object_format *dof,
3483 struct thandle *handle)
3485 struct inode *inode = obj->oo_inode;
3486 __u64 valid = attr->la_valid;
3489 attr->la_valid &= ~(LA_TYPE | LA_MODE);
3491 if (dof->dof_type != DFT_NODE)
3492 attr->la_valid &= ~LA_RDEV;
3493 if ((valid & LA_ATIME) && (attr->la_atime == inode->i_atime.tv_sec))
3494 attr->la_valid &= ~LA_ATIME;
3495 if ((valid & LA_CTIME) && (attr->la_ctime == inode->i_ctime.tv_sec))
3496 attr->la_valid &= ~LA_CTIME;
3497 if ((valid & LA_MTIME) && (attr->la_mtime == inode->i_mtime.tv_sec))
3498 attr->la_valid &= ~LA_MTIME;
3500 result = osd_quota_transfer(inode, attr, handle);
3504 if (attr->la_valid != 0) {
3505 result = osd_inode_setattr(info->oti_env, inode, attr);
3507 * The osd_inode_setattr() should always succeed here. The
3508 * only error that could be returned is EDQUOT when we are
3509 * trying to change the UID or GID of the inode. However, this
3510 * should not happen since quota enforcement is no longer
3511 * enabled on ldiskfs (lquota takes care of it).
3513 LASSERTF(result == 0, "%d\n", result);
3514 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3517 attr->la_valid = valid;
3521 * Helper function for osd_create()
3523 * \retval 0, on success
3525 static int __osd_create(struct osd_thread_info *info, struct osd_object *obj,
3526 struct lu_attr *attr, struct dt_allocation_hint *hint,
3527 struct dt_object_format *dof, struct thandle *th)
3532 osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE);
3534 /* we drop umask so that permissions we pass are not affected */
3535 umask = current->fs->umask;
3536 current->fs->umask = 0;
3538 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
3540 if (likely(obj->oo_inode != NULL)) {
3541 LASSERT(obj->oo_inode->i_state & I_NEW);
3544 * Unlock the inode before attr initialization to avoid
3545 * unnecessary dqget operations. LU-6378
3547 unlock_new_inode(obj->oo_inode);
3550 if (likely(result == 0)) {
3551 osd_attr_init(info, obj, attr, dof, th);
3552 osd_object_init0(obj);
3555 /* restore previous umask value */
3556 current->fs->umask = umask;
3558 osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE);
3564 * Helper function for osd_create()
3566 * \retval 0, on success
3568 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
3569 const struct lu_fid *fid, struct thandle *th)
3571 struct osd_thread_info *info = osd_oti_get(env);
3572 struct osd_inode_id *id = &info->oti_id;
3573 struct osd_device *osd = osd_obj2dev(obj);
3574 struct osd_thandle *oh;
3577 LASSERT(obj->oo_inode != NULL);
3579 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_OI_ENOSPC))
3582 oh = container_of(th, struct osd_thandle, ot_super);
3583 LASSERT(oh->ot_handle);
3584 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3586 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
3587 rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle,
3588 OI_CHECK_FLD, NULL);
3589 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_DUPLICATE_MAP) && osd->od_is_ost) {
3590 struct lu_fid next_fid = *fid;
3592 /* insert next object in advance, and map to the same inode */
3594 if (next_fid.f_oid != 0) {
3595 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3596 osd_oi_insert(info, osd, &next_fid, id, oh->ot_handle,
3597 OI_CHECK_FLD, NULL);
3598 osd_trans_exec_check(env, th, OSD_OT_INSERT);
3602 osd_trans_exec_check(env, th, OSD_OT_INSERT);
3607 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
3608 u64 seq, struct lu_seq_range *range)
3610 struct seq_server_site *ss = osd_seq_site(osd);
3612 if (fid_seq_is_idif(seq)) {
3613 fld_range_set_ost(range);
3614 range->lsr_index = idif_ost_idx(seq);
3618 if (!fid_seq_in_fldb(seq)) {
3619 fld_range_set_mdt(range);
3622 * FIXME: If ss is NULL, it suppose not get lsr_index
3625 range->lsr_index = ss->ss_node_id;
3629 LASSERT(ss != NULL);
3630 fld_range_set_any(range);
3631 /* OSD will only do local fld lookup */
3632 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
3635 static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
3636 struct lu_attr *attr,
3637 struct dt_allocation_hint *hint,
3638 struct dt_object_format *dof,
3639 struct thandle *handle)
3641 struct osd_thandle *oh;
3642 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3648 LASSERT(handle != NULL);
3650 oh = container_of(handle, struct osd_thandle, ot_super);
3651 LASSERT(oh->ot_handle == NULL);
3654 * EA object consumes more credits than regular object: osd_mk_index
3655 * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and
3656 * leaf_node, could involves the block, block bitmap, groups, GDT
3657 * change for each block, so add 4 * 2 credits in that case.
3659 * The default ACL initialization may consume an additional 16 blocks
3661 credits = osd_dto_credits_noquota[DTO_OBJECT_CREATE] +
3662 ((dof->dof_type == DFT_INDEX) ? 4 * 2 : 0);
3665 * While ldiskfs_new_inode() calls ldiskfs_init_acl() we have to add
3666 * credits for possible default ACL creation in new inode
3668 if (hint && hint->dah_acl_len)
3669 credits += osd_calc_bkmap_credits(sb, NULL, 0, -1,
3670 (hint->dah_acl_len + sb->s_blocksize - 1) >>
3671 sb->s_blocksize_bits);
3673 osd_trans_declare_op(env, oh, OSD_OT_CREATE, credits);
3676 * Reuse idle OI block may cause additional one OI block
3679 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3680 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
3681 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_DUPLICATE_MAP))
3682 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3683 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
3685 /* will help to find FID->ino mapping at dt_insert() */
3686 rc = osd_idc_find_and_init(env, osd_obj2dev(osd_dt_obj(dt)),
3694 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid,
3695 attr->la_projid, 1, oh, osd_dt_obj(dt),
3696 NULL, OSD_QID_INODE);
3704 * Called to destroy on-disk representation of the object
3706 * Concurrency: must be locked
3708 static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
3711 struct osd_object *obj = osd_dt_obj(dt);
3712 struct inode *inode = obj->oo_inode;
3713 struct osd_thandle *oh;
3721 oh = container_of(th, struct osd_thandle, ot_super);
3722 LASSERT(oh->ot_handle == NULL);
3724 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
3725 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
3727 /* For removing agent entry */
3728 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu))
3729 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
3732 * Recycle idle OI leaf may cause additional three OI blocks
3735 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3736 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3737 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
3738 /* one less inode */
3739 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3740 i_projid_read(inode), -1, oh, obj, NULL,
3744 /* data to be truncated */
3745 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3746 i_projid_read(inode), 0, oh, obj, NULL,
3752 * will help to find FID->ino when this object is being
3755 rc = osd_idc_find_and_init(env, osd_obj2dev(obj), obj);
3760 static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
3763 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
3764 struct osd_object *obj = osd_dt_obj(dt);
3765 struct inode *inode = obj->oo_inode;
3766 struct osd_device *osd = osd_obj2dev(obj);
3767 struct osd_thandle *oh;
3772 oh = container_of(th, struct osd_thandle, ot_super);
3773 LASSERT(oh->ot_handle);
3775 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
3777 if (unlikely(fid_is_acct(fid)))
3780 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu)) {
3781 result = osd_delete_from_remote_parent(env, osd, obj, oh, true);
3783 CERROR("%s: remove agent entry "DFID": rc = %d\n",
3784 osd_name(osd), PFID(fid), result);
3787 if (S_ISDIR(inode->i_mode)) {
3788 if (inode->i_nlink > 2)
3789 CERROR("%s: directory "DFID" ino %lu link count is %u at unlink. run e2fsck to repair\n",
3790 osd_name(osd), PFID(fid), inode->i_ino,
3793 spin_lock(&obj->oo_guard);
3795 spin_unlock(&obj->oo_guard);
3796 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3799 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
3801 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
3803 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3804 result = osd_oi_delete(osd_oti_get(env), osd, fid,
3805 oh->ot_handle, OI_CHECK_FLD);
3807 osd_trans_exec_check(env, th, OSD_OT_DESTROY);
3808 /* XXX: add to ext3 orphan list */
3809 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
3811 /* not needed in the cache anymore */
3812 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
3813 obj->oo_destroyed = 1;
3819 * Put the fid into lustre_mdt_attrs, and then place the structure
3820 * inode's ea. This fid should not be altered during the life time
3823 * \retval +ve, on success
3824 * \retval -ve, on error
3826 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
3828 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
3829 const struct lu_fid *fid, __u32 compat, __u32 incompat)
3831 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
3832 struct lustre_mdt_attrs *lma = &loa->loa_lma;
3837 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
3840 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
3843 lustre_loa_init(loa, fid, compat, incompat);
3844 lustre_loa_swab(loa, false);
3847 * For the OST device with 256 bytes inode size by default,
3848 * the PFID EA will be stored together with LMA EA to avoid
3849 * performance trouble. Otherwise the PFID EA can be stored
3850 * independently. LU-8998
3852 if ((compat & LMAC_FID_ON_OST) &&
3853 LDISKFS_INODE_SIZE(inode->i_sb) <= 256)
3854 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3855 sizeof(*loa), XATTR_CREATE);
3857 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3858 sizeof(*lma), XATTR_CREATE);
3860 * LMA may already exist, but we need to check that all the
3861 * desired compat/incompat flags have been added.
3863 if (unlikely(rc == -EEXIST)) {
3864 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
3865 XATTR_NAME_LMA, (void *)loa, sizeof(*loa));
3869 if (rc < sizeof(*lma))
3872 lustre_loa_swab(loa, true);
3873 if (lu_fid_eq(fid, &lma->lma_self_fid) &&
3874 ((compat == 0 && incompat == 0) ||
3875 (!(~lma->lma_compat & compat) &&
3876 !(~lma->lma_incompat & incompat))))
3879 lma->lma_self_fid = *fid;
3880 lma->lma_compat |= compat;
3881 lma->lma_incompat |= incompat;
3882 if (rc == sizeof(*lma)) {
3883 lustre_lma_swab(lma);
3884 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3885 sizeof(*lma), XATTR_REPLACE);
3887 lustre_loa_swab(loa, false);
3888 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3889 sizeof(*loa), XATTR_REPLACE);
3897 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
3898 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
3899 * To have compatilibility with 1.8 ldiskfs driver we need to have
3900 * magic number at start of fid data.
3901 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
3904 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
3905 const struct lu_fid *fid)
3907 if (!fid_is_namespace_visible(fid) ||
3908 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
3909 param->edp_magic = 0;
3913 param->edp_magic = LDISKFS_LUFID_MAGIC;
3914 param->edp_len = sizeof(struct lu_fid) + 1;
3915 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
3919 * Try to read the fid from inode ea into dt_rec.
3921 * \param fid object fid.
3923 * \retval 0 on success
3925 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
3926 __u32 ino, struct lu_fid *fid,
3927 struct osd_inode_id *id)
3929 struct osd_thread_info *info = osd_oti_get(env);
3930 struct inode *inode;
3934 osd_id_gen(id, ino, OSD_OII_NOGEN);
3935 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
3937 RETURN(PTR_ERR(inode));
3943 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
3945 struct inode *parent_dir,
3946 const struct lu_fid *dot_fid,
3947 const struct lu_fid *dot_dot_fid,
3948 struct osd_thandle *oth)
3950 struct ldiskfs_dentry_param *dot_ldp;
3951 struct ldiskfs_dentry_param *dot_dot_ldp;
3952 __u32 saved_nlink = dir->i_nlink;
3955 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_DOTDOT_ENOSPC))
3958 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3959 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3961 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3962 dot_ldp->edp_magic = 0;
3964 rc = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3965 dir, dot_ldp, dot_dot_ldp);
3967 * The ldiskfs_add_dot_dotdot() may dir->i_nlink as 2, then
3968 * the subseqent ref_add() will increase the dir->i_nlink
3969 * as 3. That is incorrect for new created directory.
3971 * It looks like hack, because we want to make the OSD API
3972 * to be order-independent for new created directory object
3973 * between dt_insert(..) and ref_add() operations.
3975 * Here, we only restore the in-RAM dir-inode's nlink attr,
3976 * becuase if the nlink attr is not 2, then there will be
3977 * ref_add() called following the dt_insert(..), such call
3978 * will make both the in-RAM and on-disk dir-inode's nlink
3979 * attr to be set as 2. LU-7447
3981 set_nlink(dir, saved_nlink);
3986 * Create an local agent inode for remote entry
3988 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
3989 struct osd_device *osd,
3990 struct osd_object *pobj,
3991 const struct lu_fid *fid,
3995 struct osd_thread_info *info = osd_oti_get(env);
3996 struct inode *local;
3997 struct osd_thandle *oh;
3998 struct iattr iattr = {
3999 .ia_valid = ATTR_UID | ATTR_GID |
4000 ATTR_CTIME | ATTR_MTIME | ATTR_ATIME,
4001 .ia_ctime.tv_nsec = UTIME_OMIT,
4002 .ia_mtime.tv_nsec = UTIME_OMIT,
4003 .ia_atime.tv_nsec = UTIME_OMIT,
4004 .ia_uid = GLOBAL_ROOT_UID,
4005 .ia_gid = GLOBAL_ROOT_GID,
4012 oh = container_of(th, struct osd_thandle, ot_super);
4013 LASSERT(oh->ot_handle->h_transaction != NULL);
4015 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode,
4017 if (IS_ERR(local)) {
4018 CERROR("%s: create local error %d\n", osd_name(osd),
4019 (int)PTR_ERR(local));
4024 * restore i_gid in case S_ISGID is set, we will inherit S_ISGID and set
4025 * correct gid on remote file, not agent here
4027 local->i_gid = current_fsgid();
4028 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
4030 /* e2fsck doesn't like empty symlinks. Store remote FID as symlink.
4031 * That gives e2fsck something to look at and be happy, and allows
4032 * debugging if we need to determine where this symlink came from.
4034 if (S_ISLNK(type)) {
4035 BUILD_BUG_ON(LDISKFS_N_BLOCKS * 4 < FID_LEN + 1);
4036 rc = scnprintf((char *)LDISKFS_I(local)->i_data,
4037 LDISKFS_N_BLOCKS * 4, DFID, PFID(fid));
4039 i_size_write(local, rc);
4040 LDISKFS_I(local)->i_disksize = rc;
4042 unlock_new_inode(local);
4044 /* Agent inode should not have project ID */
4045 #ifdef HAVE_PROJECT_QUOTA
4046 if (LDISKFS_I(pobj->oo_inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
4047 i_projid_read(pobj->oo_inode) != 0) {
4048 rc = osd_transfer_project(local, 0, th);
4050 CERROR("%s: quota transfer failed:. Is project quota enforcement enabled on the ldiskfs filesystem? rc = %d\n",
4051 osd_ino2name(local), rc);
4052 RETURN(ERR_PTR(rc));
4056 /* Set special LMA flag for local agent inode */
4057 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
4059 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
4060 osd_name(osd), PFID(fid), rc);
4061 RETURN(ERR_PTR(rc));
4067 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
4068 lu_object_fid(&pobj->oo_dt.do_lu),
4071 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
4072 osd_name(osd), PFID(fid), rc);
4073 RETURN(ERR_PTR(rc));
4080 * when direntry is deleted, we have to take care of possible agent inode
4081 * referenced by that. unfortunately we can't do this at that point:
4082 * iget() within a running transaction leads to deadlock and we better do
4083 * not call that every delete declaration to save performance. so we put
4084 * a potention agent inode on a list and process that once the transaction
4085 * is over. Notice it's not any worse in terms of real orphans as regular
4086 * object destroy doesn't put inodes on the on-disk orphan list. this should
4087 * be addressed separately
4089 static int osd_schedule_agent_inode_removal(const struct lu_env *env,
4090 struct osd_thandle *oh,
4093 struct osd_device *osd = osd_dt_dev(oh->ot_super.th_dev);
4094 struct osd_obj_orphan *oor;
4101 oor->oor_env = (struct lu_env *)env;
4102 spin_lock(&osd->od_osfs_lock);
4103 list_add(&oor->oor_list, &osd->od_orphan_list);
4104 spin_unlock(&osd->od_osfs_lock);
4106 oh->ot_remove_agents = 1;
4112 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
4113 struct osd_device *osd)
4115 struct osd_thread_info *info = osd_oti_get(env);
4116 struct osd_obj_orphan *oor, *tmp;
4117 struct osd_inode_id id;
4119 struct inode *inode;
4124 spin_lock(&osd->od_osfs_lock);
4125 list_for_each_entry_safe(oor, tmp, &osd->od_orphan_list, oor_list) {
4126 if (oor->oor_env == env)
4127 list_move(&oor->oor_list, &list);
4129 spin_unlock(&osd->od_osfs_lock);
4131 list_for_each_entry_safe(oor, tmp, &list, oor_list) {
4135 list_del(&oor->oor_list);
4138 osd_id_gen(&id, ino, OSD_OII_NOGEN);
4139 inode = osd_iget_fid(info, osd, &id, &fid);
4143 if (!osd_remote_fid(env, osd, &fid)) {
4148 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC, 1);
4150 mark_inode_dirty(inode);
4151 ldiskfs_journal_stop(jh);
4159 * OSD layer object create function for OST objects (b=11826).
4161 * The FID is inserted into inode xattr here.
4163 * \retval 0, on success
4164 * \retval -ve, on error
4166 static int osd_create(const struct lu_env *env, struct dt_object *dt,
4167 struct lu_attr *attr, struct dt_allocation_hint *hint,
4168 struct dt_object_format *dof, struct thandle *th)
4170 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
4171 struct osd_object *obj = osd_dt_obj(dt);
4172 struct osd_thread_info *info = osd_oti_get(env);
4173 int result, on_ost = 0;
4177 if (dt_object_exists(dt))
4180 LINVRNT(osd_invariant(obj));
4181 LASSERT(!dt_object_remote(dt));
4182 LASSERT(osd_is_write_locked(env, obj));
4183 LASSERT(th != NULL);
4185 if (unlikely(fid_is_acct(fid)))
4187 * Quota files can't be created from the kernel any more,
4188 * 'tune2fs -O quota' will take care of creating them
4192 result = __osd_create(info, obj, attr, hint, dof, th);
4194 if (fid_is_idif(fid) &&
4195 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
4196 struct lu_fid *tfid = &info->oti_fid;
4197 struct ost_id *oi = &info->oti_ostid;
4199 fid_to_ostid(fid, oi);
4200 ostid_to_fid(tfid, oi, 0);
4202 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
4203 LMAC_FID_ON_OST, 0);
4205 on_ost = fid_is_on_ost(info, osd_obj2dev(obj),
4207 result = osd_ea_fid_set(info, obj->oo_inode, fid,
4208 on_ost ? LMAC_FID_ON_OST : 0,
4211 if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
4212 obj->oo_dt.do_body_ops = &osd_body_ops;
4215 if (!result && !CFS_FAIL_CHECK(OBD_FAIL_OSD_NO_OI_ENTRY)) {
4216 struct inode *inode = obj->oo_inode;
4218 result = __osd_oi_insert(env, obj, fid, th);
4219 if (result && inode) {
4220 spin_lock(&obj->oo_guard);
4222 spin_unlock(&obj->oo_guard);
4223 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4224 ldiskfs_set_inode_state(inode,
4225 LDISKFS_STATE_LUSTRE_DESTROY);
4227 obj->oo_inode = NULL;
4232 * a small optimization - dt_insert() isn't usually applied
4233 * to OST objects, so we don't need to cache OI mapping for
4236 if (result == 0 && on_ost == 0) {
4237 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4239 result = osd_idc_find_and_init(env, osd, obj);
4240 LASSERT(result == 0);
4243 LASSERT(ergo(result == 0,
4244 dt_object_exists(dt) && !dt_object_remote(dt)));
4245 LINVRNT(osd_invariant(obj));
4249 static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
4250 struct thandle *handle)
4252 struct osd_thandle *oh;
4255 /* it's possible that object doesn't exist yet */
4256 LASSERT(handle != NULL);
4258 oh = container_of(handle, struct osd_thandle, ot_super);
4259 LASSERT(oh->ot_handle == NULL);
4261 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
4262 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
4264 rc = osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev),
4271 * Concurrency: @dt is write locked.
4273 static int osd_ref_add(const struct lu_env *env, struct dt_object *dt,
4276 struct osd_object *obj = osd_dt_obj(dt);
4277 struct inode *inode = obj->oo_inode;
4278 struct osd_thandle *oh;
4281 if (!dt_object_exists(dt) || obj->oo_destroyed)
4284 LINVRNT(osd_invariant(obj));
4285 LASSERT(!dt_object_remote(dt));
4286 LASSERT(osd_is_write_locked(env, obj));
4287 LASSERT(th != NULL);
4289 oh = container_of(th, struct osd_thandle, ot_super);
4290 LASSERT(oh->ot_handle != NULL);
4292 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
4294 CDEBUG(D_INODE, DFID" increase nlink %d\n",
4295 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
4297 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
4298 * (65000) subdirectories by storing "1" in i_nlink if the link count
4299 * would otherwise overflow. Directory tranversal tools understand
4300 * that (st_nlink == 1) indicates that the filesystem dose not track
4301 * hard links count on the directory, and will not abort subdirectory
4302 * scanning early once (st_nlink - 2) subdirs have been found.
4304 * This also has to properly handle the case of inodes with nlink == 0
4305 * in case they are being linked into the PENDING directory
4307 spin_lock(&obj->oo_guard);
4308 if (unlikely(inode->i_nlink == 0))
4309 /* inc_nlink from 0 may cause WARN_ON */
4310 set_nlink(inode, 1);
4312 ldiskfs_inc_count(oh->ot_handle, inode);
4313 if (!S_ISDIR(inode->i_mode))
4314 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
4316 spin_unlock(&obj->oo_guard);
4318 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4319 LINVRNT(osd_invariant(obj));
4321 osd_trans_exec_check(env, th, OSD_OT_REF_ADD);
4326 static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
4327 struct thandle *handle)
4329 struct osd_thandle *oh;
4331 if (!dt_object_exists(dt))
4334 LASSERT(!dt_object_remote(dt));
4335 LASSERT(handle != NULL);
4337 oh = container_of(handle, struct osd_thandle, ot_super);
4338 LASSERT(oh->ot_handle == NULL);
4340 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
4341 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
4347 * Concurrency: @dt is write locked.
4349 static int osd_ref_del(const struct lu_env *env, struct dt_object *dt,
4352 struct osd_object *obj = osd_dt_obj(dt);
4353 struct inode *inode = obj->oo_inode;
4354 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4355 struct osd_thandle *oh;
4357 if (!dt_object_exists(dt))
4360 LINVRNT(osd_invariant(obj));
4361 LASSERT(!dt_object_remote(dt));
4362 LASSERT(osd_is_write_locked(env, obj));
4363 LASSERT(th != NULL);
4365 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_REF_DEL))
4368 oh = container_of(th, struct osd_thandle, ot_super);
4369 LASSERT(oh->ot_handle != NULL);
4371 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
4373 spin_lock(&obj->oo_guard);
4375 * That can be result of upgrade from old Lustre version and
4376 * applied only to local files. Just skip this ref_del call.
4377 * ext4_unlink() only treats this as a warning, don't LASSERT here.
4379 if (inode->i_nlink == 0) {
4380 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
4381 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
4382 ", maybe an upgraded file? (LU-3915)\n",
4383 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
4384 spin_unlock(&obj->oo_guard);
4388 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
4389 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
4391 ldiskfs_dec_count(oh->ot_handle, inode);
4392 spin_unlock(&obj->oo_guard);
4394 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4395 LINVRNT(osd_invariant(obj));
4397 osd_trans_exec_check(env, th, OSD_OT_REF_DEL);
4403 * Concurrency: @dt is read locked.
4405 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
4406 struct lu_buf *buf, const char *name)
4408 struct osd_object *obj = osd_dt_obj(dt);
4409 struct inode *inode = obj->oo_inode;
4410 struct osd_thread_info *info = osd_oti_get(env);
4411 struct dentry *dentry = &info->oti_obj_dentry;
4412 bool cache_xattr = false;
4417 /* version get is not real XATTR but uses xattr API */
4418 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4419 dt_obj_version_t *ver = buf->lb_buf;
4422 * for version we are just using xattr API but change inode
4425 if (buf->lb_len == 0)
4426 return sizeof(dt_obj_version_t);
4428 if (buf->lb_len < sizeof(dt_obj_version_t))
4431 CDEBUG(D_INODE, "Get version %#llx for inode %lu\n",
4432 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
4434 *ver = LDISKFS_I(inode)->i_fs_version;
4436 return sizeof(dt_obj_version_t);
4439 if (!dt_object_exists(dt))
4442 LASSERT(!dt_object_remote(dt));
4443 LASSERT(inode->i_op != NULL);
4444 #ifdef HAVE_IOP_XATTR
4445 LASSERT(inode->i_op->getxattr != NULL);
4448 if (strcmp(name, XATTR_NAME_LOV) == 0 ||
4449 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
4453 rc = osd_oxc_get(obj, name, buf);
4458 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
4459 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4460 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4461 struct filter_fid *ff;
4462 struct ost_layout *ol;
4464 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
4468 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
4471 if (buf->lb_len == 0 || !buf->lb_buf)
4474 if (buf->lb_len < rc)
4478 ol = &ff->ff_layout;
4479 ol->ol_stripe_count = cpu_to_le32(loa->loa_parent_fid.f_ver >>
4480 PFID_STRIPE_IDX_BITS);
4481 ol->ol_stripe_size = cpu_to_le32(loa->loa_stripe_size);
4482 loa->loa_parent_fid.f_ver &= PFID_STRIPE_COUNT_MASK;
4483 fid_cpu_to_le(&ff->ff_parent, &loa->loa_parent_fid);
4484 if (lma->lma_compat & LMAC_COMP_INFO) {
4485 ol->ol_comp_start = cpu_to_le64(loa->loa_comp_start);
4486 ol->ol_comp_end = cpu_to_le64(loa->loa_comp_end);
4487 ol->ol_comp_id = cpu_to_le32(loa->loa_comp_id);
4489 ol->ol_comp_start = 0;
4490 ol->ol_comp_end = 0;
4494 rc = __osd_xattr_get(inode, dentry, name,
4495 buf->lb_buf, buf->lb_len);
4499 if (rc == -ENOENT || rc == -ENODATA)
4500 osd_oxc_add(obj, name, NULL, 0);
4501 else if (rc > 0 && buf->lb_buf != NULL)
4502 osd_oxc_add(obj, name, buf->lb_buf, rc);
4508 static int osd_declare_xattr_set(const struct lu_env *env,
4509 struct dt_object *dt,
4510 const struct lu_buf *buf, const char *name,
4511 int fl, struct thandle *handle)
4513 struct osd_thandle *oh;
4515 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
4517 LASSERT(handle != NULL);
4519 oh = container_of(handle, struct osd_thandle, ot_super);
4520 LASSERT(oh->ot_handle == NULL);
4522 if (strcmp(name, XATTR_NAME_LMA) == 0) {
4524 * For non-upgrading case, the LMA is set first and
4525 * usually fit inode. But for upgrade case, the LMA
4526 * may be in another separated EA block.
4528 if (dt_object_exists(dt)) {
4529 if (fl == LU_XATTR_REPLACE)
4534 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4536 } else if (strcmp(name, XATTR_NAME_FID) == 0) {
4537 /* We may need to delete the old PFID EA. */
4538 credits = LDISKFS_MAXQUOTAS_DEL_BLOCKS(sb);
4539 if (fl == LU_XATTR_REPLACE)
4545 * If some name entry resides on remote MDT, then will create
4546 * agent entry under remote parent. On the other hand, if the
4547 * remote entry will be removed, then related agent entry may
4548 * need to be removed from the remote parent. So there may be
4549 * kinds of cases, let's declare enough credits. The credits
4550 * for create agent entry is enough for remove case.
4552 if (strcmp(name, XATTR_NAME_LINK) == 0) {
4553 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
4554 if (dt_object_exists(dt))
4555 credits += 1; /* For updating LMA */
4559 credits += osd_dto_credits_noquota[DTO_XATTR_SET];
4564 if (buf->lb_buf == NULL && dt_object_exists(dt)) {
4566 * learn xattr size from osd_xattr_get if
4567 * attribute has not been read yet
4569 buflen = __osd_xattr_get(
4570 osd_dt_obj(dt)->oo_inode,
4571 &osd_oti_get(env)->oti_obj_dentry,
4576 buflen = buf->lb_len;
4579 if (buflen > sb->s_blocksize) {
4580 credits += osd_calc_bkmap_credits(
4582 (buflen + sb->s_blocksize - 1) >>
4583 sb->s_blocksize_bits);
4587 * xattr set may involve inode quota change, reserve credits for
4588 * dquot_initialize()
4590 credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
4593 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
4598 static int osd_xattr_set_pfid(const struct lu_env *env, struct osd_object *obj,
4599 const struct lu_buf *buf, int fl,
4600 struct thandle *handle)
4602 struct osd_thread_info *info = osd_oti_get(env);
4603 struct dentry *dentry = &info->oti_obj_dentry;
4604 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4605 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4606 struct inode *inode = obj->oo_inode;
4607 struct filter_fid *ff = buf->lb_buf;
4608 struct ost_layout *ol = &ff->ff_layout;
4609 int flags = XATTR_REPLACE;
4614 if (buf->lb_len != sizeof(*ff) && buf->lb_len != sizeof(struct lu_fid))
4617 rc = osd_get_lma(info, inode, dentry, loa);
4618 if (rc == -ENODATA) {
4619 /* Usually for upgarding from old device */
4620 lustre_loa_init(loa, lu_object_fid(&obj->oo_dt.do_lu),
4621 LMAC_FID_ON_OST, 0);
4622 flags = XATTR_CREATE;
4627 if (!rc && lma->lma_compat & LMAC_STRIPE_INFO) {
4628 if ((fl & LU_XATTR_CREATE) && !(fl & LU_XATTR_REPLACE))
4631 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256) {
4632 /* Separate PFID EA from LMA */
4633 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4634 lustre_lma_swab(lma);
4635 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4636 sizeof(*lma), XATTR_REPLACE);
4638 obj->oo_pfid_in_lma = 0;
4639 rc = LU_XATTR_CREATE;
4645 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256)
4649 * Old client does not send stripe information,
4650 * then store the PFID EA on disk separatedly.
4652 if (unlikely(buf->lb_len == sizeof(struct lu_fid) ||
4653 ol->ol_stripe_size == 0))
4656 /* Remove old PFID EA entry firstly. */
4657 dquot_initialize(inode);
4658 rc = ll_vfs_removexattr(dentry, inode, XATTR_NAME_FID);
4659 if (rc == -ENODATA) {
4660 /* XATTR_NAME_FID is already absent */
4667 fid_le_to_cpu(&loa->loa_parent_fid, &ff->ff_parent);
4668 if (likely(ol->ol_stripe_size != 0)) {
4669 loa->loa_parent_fid.f_ver |= le32_to_cpu(ol->ol_stripe_count) <<
4670 PFID_STRIPE_IDX_BITS;
4671 loa->loa_stripe_size = le32_to_cpu(ol->ol_stripe_size);
4672 lma->lma_compat |= LMAC_STRIPE_INFO;
4673 if (ol->ol_comp_id != 0) {
4674 loa->loa_comp_id = le32_to_cpu(ol->ol_comp_id);
4675 loa->loa_comp_start = le64_to_cpu(ol->ol_comp_start);
4676 loa->loa_comp_end = le64_to_cpu(ol->ol_comp_end);
4677 lma->lma_compat |= LMAC_COMP_INFO;
4681 lustre_loa_swab(loa, false);
4683 /* Store the PFID EA inside LMA. */
4684 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa, sizeof(*loa),
4687 obj->oo_pfid_in_lma = 1;
4693 * In DNE environment, the object (in spite of regular file or directory)
4694 * and its name entry may reside on different MDTs. Under such case, we will
4695 * create an agent entry on the MDT where the object resides. The agent entry
4696 * references the object locally, that makes the object to be visible to the
4697 * userspace when mounted as 'ldiskfs' directly. Then the userspace tools,
4698 * such as 'tar' can handle the object properly.
4700 * We handle the agent entry during set linkEA that is the common interface
4701 * for both regular file and directroy, can handle kinds of cases, such as
4702 * create/link/unlink/rename, and so on.
4704 * NOTE: we can NOT do that when ea_{insert,delete} that is only for directory.
4706 * XXX: There are two known issues:
4707 * 1. For one object, we will create at most one agent entry even if there
4708 * may be more than one cross-MDTs hard links on the object. So the local
4709 * e2fsck may claim that the object's nlink is larger than the name entries
4710 * that reference such inode. And in further, the e2fsck will fix the nlink
4711 * attribute to match the local references. Then it will cause the object's
4712 * nlink attribute to be inconsistent with the global references. it is bad
4713 * but not fatal. The ref_del() can handle the zero-referenced case. On the
4714 * other hand, the global namespace LFSCK can repair the object's attribute
4715 * according to the linkEA.
4716 * 2. There may be too many hard links on the object as to its linkEA overflow,
4717 * then the linkEA entry for cross-MDTs reference may be discarded. If such
4718 * case happened, then at this point, we do not know whether there are some
4719 * cross-MDTs reference. But there are local references, it guarantees that
4720 * object is visible to userspace when mounted as 'ldiskfs'. That is enough.
4722 static int osd_xattr_handle_linkea(const struct lu_env *env,
4723 struct osd_device *osd,
4724 struct osd_object *obj,
4725 const struct lu_buf *buf,
4726 struct thandle *handle)
4728 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
4729 struct lu_fid *tfid = &osd_oti_get(env)->oti_fid3;
4730 struct linkea_data ldata = { .ld_buf = (struct lu_buf *)buf };
4731 struct lu_name tmpname;
4732 struct osd_thandle *oh;
4734 bool remote = false;
4738 oh = container_of(handle, struct osd_thandle, ot_super);
4739 LASSERT(oh->ot_handle != NULL);
4741 rc = linkea_init_with_rec(&ldata);
4743 linkea_first_entry(&ldata);
4744 while (ldata.ld_lee != NULL && !remote) {
4745 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
4747 if (osd_remote_fid(env, osd, tfid) > 0)
4750 linkea_next_entry(&ldata);
4752 } else if (rc == -ENODATA) {
4758 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu) && !remote) {
4759 rc = osd_delete_from_remote_parent(env, osd, obj, oh, false);
4761 CERROR("%s: failed to remove agent entry for "DFID
4762 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4763 } else if (!lu_object_has_agent_entry(&obj->oo_dt.do_lu) && remote) {
4764 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4766 CERROR("%s: failed to create agent entry for "DFID
4767 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4774 * Concurrency: @dt is write locked.
4776 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
4777 const struct lu_buf *buf, const char *name, int fl,
4778 struct thandle *handle)
4780 struct osd_object *obj = osd_dt_obj(dt);
4781 struct osd_device *osd = osd_obj2dev(obj);
4782 struct inode *inode = obj->oo_inode;
4783 struct osd_thread_info *info = osd_oti_get(env);
4793 /* version set is not real XATTR */
4794 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4795 dt_obj_version_t *version = buf->lb_buf;
4798 * for version we are just using xattr API but change inode
4801 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
4803 CDEBUG(D_INODE, "Set version %#llx (old %#llx) for inode %lu\n",
4804 *version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
4806 LDISKFS_I(inode)->i_fs_version = *version;
4808 * Version is set after all inode operations are finished,
4809 * so we should mark it dirty here
4811 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4816 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
4817 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
4820 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4823 * For the OST device with 256 bytes inode size by default,
4824 * the PFID EA will be stored together with LMA EA to avoid
4825 * performance trouble. Otherwise the PFID EA can be stored
4826 * independently. LU-8998
4828 if (strcmp(name, XATTR_NAME_FID) == 0 && osd->od_is_ost &&
4829 (LDISKFS_INODE_SIZE(inode->i_sb) <= 256 || obj->oo_pfid_in_lma)) {
4830 LASSERT(buf->lb_buf);
4832 fl = osd_xattr_set_pfid(env, obj, buf, fl, handle);
4835 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
4836 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4837 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4839 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
4843 lma->lma_incompat |= LMAI_STRIPED;
4844 lustre_lma_swab(lma);
4845 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4846 sizeof(*lma), XATTR_REPLACE);
4849 } else if (strcmp(name, XATTR_NAME_LINK) == 0) {
4850 LASSERT(!osd->od_is_ost);
4852 rc = osd_xattr_handle_linkea(env, osd, obj, buf, handle);
4857 if (fl & LU_XATTR_REPLACE)
4858 fs_flags |= XATTR_REPLACE;
4860 if (fl & LU_XATTR_CREATE)
4861 fs_flags |= XATTR_CREATE;
4863 rc = __osd_xattr_set(info, inode, name, buf->lb_buf, len, fs_flags);
4864 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4867 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4868 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4869 osd_oxc_add(obj, name, buf->lb_buf, buf->lb_len);
4875 * Concurrency: @dt is read locked.
4877 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
4878 const struct lu_buf *buf)
4880 struct osd_object *obj = osd_dt_obj(dt);
4881 struct inode *inode = obj->oo_inode;
4882 struct osd_thread_info *info = osd_oti_get(env);
4883 struct dentry *dentry = &info->oti_obj_dentry;
4885 if (!dt_object_exists(dt))
4888 LASSERT(!dt_object_remote(dt));
4889 LASSERT(inode->i_op != NULL);
4890 LASSERT(inode->i_op->listxattr != NULL);
4892 dentry->d_inode = inode;
4893 dentry->d_sb = inode->i_sb;
4894 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
4897 static int osd_declare_xattr_del(const struct lu_env *env,
4898 struct dt_object *dt, const char *name,
4899 struct thandle *handle)
4901 struct osd_thandle *oh;
4902 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
4904 LASSERT(!dt_object_remote(dt));
4905 LASSERT(handle != NULL);
4907 oh = container_of(handle, struct osd_thandle, ot_super);
4908 LASSERT(oh->ot_handle == NULL);
4910 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
4911 osd_dto_credits_noquota[DTO_XATTR_SET]);
4913 * xattr del may involve inode quota change, reserve credits for
4914 * dquot_initialize()
4916 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
4922 * Concurrency: @dt is write locked.
4924 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
4925 const char *name, struct thandle *handle)
4927 struct osd_object *obj = osd_dt_obj(dt);
4928 struct inode *inode = obj->oo_inode;
4929 struct osd_thread_info *info = osd_oti_get(env);
4930 struct dentry *dentry = &info->oti_obj_dentry;
4933 if (!dt_object_exists(dt))
4936 LASSERT(!dt_object_remote(dt));
4937 LASSERT(inode->i_op != NULL);
4938 LASSERT(handle != NULL);
4939 #ifdef HAVE_IOP_XATTR
4940 LASSERT(inode->i_op->removexattr != NULL);
4943 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4945 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
4946 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
4948 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
4949 &info->oti_ost_attrs);
4951 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
4953 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4954 lustre_lma_swab(lma);
4955 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4956 sizeof(*lma), XATTR_REPLACE);
4958 obj->oo_pfid_in_lma = 0;
4961 dquot_initialize(inode);
4962 dentry->d_inode = inode;
4963 dentry->d_sb = inode->i_sb;
4964 rc = ll_vfs_removexattr(dentry, inode, name);
4967 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4970 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4971 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4972 osd_oxc_del(obj, name);
4977 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
4978 __u64 start, __u64 end)
4980 struct osd_object *obj = osd_dt_obj(dt);
4981 struct osd_device *dev = osd_obj2dev(obj);
4982 struct inode *inode = obj->oo_inode;
4987 file = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
4990 RETURN(PTR_ERR(file));
4992 file->f_mode |= FMODE_64BITHASH;
4993 rc = vfs_fsync_range(file, start, end, 0);
5000 static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
5005 static bool osd_check_stale(struct dt_object *dt)
5013 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
5014 const struct dt_index_features *feat)
5016 struct iam_descr *descr;
5018 if (osd_object_is_root(o))
5019 return feat == &dt_directory_features;
5021 LASSERT(o->oo_dir != NULL);
5023 descr = o->oo_dir->od_container.ic_descr;
5024 if (feat == &dt_directory_features) {
5025 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
5030 return feat->dif_keysize_min <= descr->id_key_size &&
5031 descr->id_key_size <= feat->dif_keysize_max &&
5032 feat->dif_recsize_min <= descr->id_rec_size &&
5033 descr->id_rec_size <= feat->dif_recsize_max &&
5034 !(feat->dif_flags & (DT_IND_VARKEY |
5035 DT_IND_VARREC | DT_IND_NONUNQ)) &&
5036 ergo(feat->dif_flags & DT_IND_UPDATE,
5037 1 /* XXX check that object (and fs) is writable */);
5041 static int osd_iam_container_init(const struct lu_env *env,
5042 struct osd_object *obj,
5043 struct osd_directory *dir)
5045 struct iam_container *bag = &dir->od_container;
5048 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
5052 result = iam_container_setup(bag);
5054 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
5056 iam_container_fini(bag);
5063 * Concurrency: no external locking is necessary.
5065 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
5066 const struct dt_index_features *feat)
5070 struct osd_object *obj = osd_dt_obj(dt);
5072 LINVRNT(osd_invariant(obj));
5074 if (osd_object_is_root(obj)) {
5075 dt->do_index_ops = &osd_index_ea_ops;
5077 } else if (feat == &dt_directory_features) {
5078 dt->do_index_ops = &osd_index_ea_ops;
5079 if (obj->oo_inode == NULL || S_ISDIR(obj->oo_inode->i_mode))
5084 } else if (unlikely(feat == &dt_otable_features)) {
5085 dt->do_index_ops = &osd_otable_ops;
5087 } else if (unlikely(feat == &dt_acct_features)) {
5088 dt->do_index_ops = &osd_acct_index_ops;
5091 } else if (!osd_has_index(obj)) {
5092 struct osd_directory *dir;
5093 struct osd_device *osd = osd_obj2dev(obj);
5094 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
5099 spin_lock(&obj->oo_guard);
5100 if (obj->oo_dir == NULL)
5104 * Concurrent thread allocated container data.
5107 spin_unlock(&obj->oo_guard);
5109 * Now, that we have container data, serialize its
5112 down_write(&obj->oo_ext_idx_sem);
5114 * recheck under lock.
5117 if (osd_has_index(obj)) {
5122 result = osd_iam_container_init(env, obj, obj->oo_dir);
5123 if (result || feat == &dt_lfsck_namespace_features ||
5124 feat == &dt_lfsck_layout_orphan_features ||
5125 feat == &dt_lfsck_layout_dangling_features)
5128 result = osd_index_register(osd, fid,
5129 feat->dif_keysize_max,
5130 feat->dif_recsize_max);
5132 CWARN("%s: failed to register index "
5134 osd_name(osd), PFID(fid), result);
5135 else if (result > 0)
5138 CDEBUG(D_LFSCK, "%s: index object "DFID
5139 " (%d/%d) registered\n",
5140 osd_name(osd), PFID(fid),
5141 (int)feat->dif_keysize_max,
5142 (int)feat->dif_recsize_max);
5145 up_write(&obj->oo_ext_idx_sem);
5153 if (result == 0 && skip_iam == 0) {
5154 if (!osd_iam_index_probe(env, obj, feat))
5157 LINVRNT(osd_invariant(obj));
5162 static int osd_otable_it_attr_get(const struct lu_env *env,
5163 struct dt_object *dt,
5164 struct lu_attr *attr)
5170 static const struct dt_object_operations osd_obj_ops = {
5171 .do_read_lock = osd_read_lock,
5172 .do_write_lock = osd_write_lock,
5173 .do_read_unlock = osd_read_unlock,
5174 .do_write_unlock = osd_write_unlock,
5175 .do_write_locked = osd_write_locked,
5176 .do_attr_get = osd_attr_get,
5177 .do_declare_attr_set = osd_declare_attr_set,
5178 .do_attr_set = osd_attr_set,
5179 .do_ah_init = osd_ah_init,
5180 .do_declare_create = osd_declare_create,
5181 .do_create = osd_create,
5182 .do_declare_destroy = osd_declare_destroy,
5183 .do_destroy = osd_destroy,
5184 .do_index_try = osd_index_try,
5185 .do_declare_ref_add = osd_declare_ref_add,
5186 .do_ref_add = osd_ref_add,
5187 .do_declare_ref_del = osd_declare_ref_del,
5188 .do_ref_del = osd_ref_del,
5189 .do_xattr_get = osd_xattr_get,
5190 .do_declare_xattr_set = osd_declare_xattr_set,
5191 .do_xattr_set = osd_xattr_set,
5192 .do_declare_xattr_del = osd_declare_xattr_del,
5193 .do_xattr_del = osd_xattr_del,
5194 .do_xattr_list = osd_xattr_list,
5195 .do_object_sync = osd_object_sync,
5196 .do_invalidate = osd_invalidate,
5197 .do_check_stale = osd_check_stale,
5200 static const struct dt_object_operations osd_obj_otable_it_ops = {
5201 .do_attr_get = osd_otable_it_attr_get,
5202 .do_index_try = osd_index_try,
5205 static int osd_index_declare_iam_delete(const struct lu_env *env,
5206 struct dt_object *dt,
5207 const struct dt_key *key,
5208 struct thandle *handle)
5210 struct osd_thandle *oh;
5212 oh = container_of(handle, struct osd_thandle, ot_super);
5213 LASSERT(oh->ot_handle == NULL);
5215 /* Recycle may cause additional three blocks to be changed. */
5216 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
5217 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
5223 * delete a (key, value) pair from index \a dt specified by \a key
5225 * \param dt osd index object
5226 * \param key key for index
5227 * \param rec record reference
5228 * \param handle transaction handler
5231 * \retval -ve failure
5233 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
5234 const struct dt_key *key,
5235 struct thandle *handle)
5237 struct osd_thread_info *oti = osd_oti_get(env);
5238 struct osd_object *obj = osd_dt_obj(dt);
5239 struct osd_thandle *oh;
5240 struct iam_path_descr *ipd;
5241 struct iam_container *bag = &obj->oo_dir->od_container;
5246 if (!dt_object_exists(dt))
5249 LINVRNT(osd_invariant(obj));
5250 LASSERT(!dt_object_remote(dt));
5251 LASSERT(bag->ic_object == obj->oo_inode);
5252 LASSERT(handle != NULL);
5254 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
5256 ipd = osd_idx_ipd_get(env, bag);
5257 if (unlikely(ipd == NULL))
5260 oh = container_of(handle, struct osd_thandle, ot_super);
5261 LASSERT(oh->ot_handle != NULL);
5262 LASSERT(oh->ot_handle->h_transaction != NULL);
5264 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5265 /* swab quota uid/gid provided by caller */
5266 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5267 key = (const struct dt_key *)&oti->oti_quota_id;
5270 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
5271 osd_ipd_put(env, bag, ipd);
5272 LINVRNT(osd_invariant(obj));
5273 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
5277 static int osd_index_declare_ea_delete(const struct lu_env *env,
5278 struct dt_object *dt,
5279 const struct dt_key *key,
5280 struct thandle *handle)
5282 struct osd_thandle *oh;
5283 struct inode *inode;
5288 LASSERT(!dt_object_remote(dt));
5289 LASSERT(handle != NULL);
5291 oh = container_of(handle, struct osd_thandle, ot_super);
5292 LASSERT(oh->ot_handle == NULL);
5294 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE];
5295 osd_trans_declare_op(env, oh, OSD_OT_DELETE, credits);
5297 inode = osd_dt_obj(dt)->oo_inode;
5301 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
5302 i_projid_read(inode), 0, oh, osd_dt_obj(dt),
5307 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
5310 struct osd_fid_pack *rec;
5313 if (de->file_type & LDISKFS_DIRENT_LUFID) {
5314 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5315 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
5316 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
5322 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
5323 const struct lu_fid *fid)
5325 struct seq_server_site *ss = osd_seq_site(osd);
5329 /* FID seqs not in FLDB, must be local seq */
5330 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
5334 * If FLD is not being initialized yet, it only happens during the
5335 * initialization, likely during mgs initialization, and we assume
5336 * this is local FID.
5338 if (ss == NULL || ss->ss_server_fld == NULL)
5341 /* Only check the local FLDB here */
5342 if (osd_seq_exists(env, osd, fid_seq(fid)))
5348 static void osd_take_care_of_agent(const struct lu_env *env,
5349 struct osd_device *osd,
5350 struct osd_thandle *oh,
5351 struct ldiskfs_dir_entry_2 *de)
5353 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
5354 struct osd_idmap_cache *idc;
5355 int rc, schedule = 0;
5357 LASSERT(de != NULL);
5359 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
5360 if (likely(rc == 0)) {
5361 idc = osd_idc_find_or_init(env, osd, fid);
5362 if (IS_ERR(idc) || idc->oic_remote)
5364 } else if (rc == -ENODATA) {
5366 * can't get FID, postpone to the end of the
5367 * transaction when iget() is safe
5371 CERROR("%s: can't get FID: rc = %d\n", osd_name(osd), rc);
5374 osd_schedule_agent_inode_removal(env, oh,
5375 le32_to_cpu(de->inode));
5379 * Utility function to get real name from object name
5381 * \param[in] obj pointer to the object to be handled
5382 * \param[in] name object name
5383 * \param[in] len object name len
5384 * \param[out]ln pointer to the struct lu_name to hold the real name
5386 * If file is not encrypted, real name is just the object name.
5387 * If file is encrypted, object name needs to be decoded. In
5388 * this case a new buffer is allocated, and ln->ln_name needs to be freed by
5391 * \retval 0, on success
5392 * \retval -ve, on error
5394 static int obj_name2lu_name(struct osd_object *obj, const char *name,
5395 int len, struct lu_name *ln)
5397 struct lu_fid namefid;
5402 sscanf(name + 1, SFID, RFID(&namefid));
5404 if (fid_is_sane(&namefid) || name_is_dot_or_dotdot(name, len) ||
5405 !(obj->oo_lma_flags & LUSTRE_ENCRYPT_FL)) {
5407 ln->ln_namelen = len;
5409 char *buf = kmalloc(len, GFP_NOFS);
5414 len = critical_decode(name, len, buf);
5416 ln->ln_namelen = len;
5423 * Index delete function for interoperability mode (b11826).
5424 * It will remove the directory entry added by osd_index_ea_insert().
5425 * This entry is needed to maintain name->fid mapping.
5427 * \param key, key i.e. file entry to be deleted
5429 * \retval 0, on success
5430 * \retval -ve, on error
5432 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
5433 const struct dt_key *key, struct thandle *handle)
5435 struct osd_object *obj = osd_dt_obj(dt);
5436 struct inode *dir = obj->oo_inode;
5437 struct dentry *dentry;
5438 struct osd_thandle *oh;
5439 struct ldiskfs_dir_entry_2 *de = NULL;
5440 struct buffer_head *bh;
5441 struct htree_lock *hlock = NULL;
5442 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
5448 if (!dt_object_exists(dt))
5451 LINVRNT(osd_invariant(obj));
5452 LASSERT(!dt_object_remote(dt));
5453 LASSERT(handle != NULL);
5455 rc = obj_name2lu_name(obj, (char *)key, strlen((char *)key), &ln);
5459 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
5461 oh = container_of(handle, struct osd_thandle, ot_super);
5462 LASSERT(oh->ot_handle != NULL);
5463 LASSERT(oh->ot_handle->h_transaction != NULL);
5465 dquot_initialize(dir);
5466 dentry = osd_child_dentry_get(env, obj, ln.ln_name, ln.ln_namelen);
5468 if (obj->oo_hl_head != NULL) {
5469 hlock = osd_oti_get(env)->oti_hlock;
5470 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
5471 dir, LDISKFS_HLOCK_DEL);
5473 down_write(&obj->oo_ext_idx_sem);
5476 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5479 * If this is not the ".." entry, it might be a remote DNE
5480 * entry and we need to check if the FID is for a remote
5481 * MDT. If the FID is not in the directory entry (e.g.
5482 * upgraded 1.8 filesystem without dirdata enabled) then
5483 * we need to get the FID from the LMA. For a remote directory
5484 * there HAS to be an LMA, it cannot be an IGIF inode in this
5487 * Delete the entry before the agent inode in order to
5488 * simplify error handling. At worst an error after deleting
5489 * the entry first might leak the agent inode afterward. The
5490 * reverse would need filesystem abort in case of error deleting
5491 * the entry after the agent had been removed, or leave a
5492 * dangling entry pointing at a random inode.
5494 if (strcmp((char *)key, dotdot) != 0)
5495 osd_take_care_of_agent(env, osd, oh, de);
5496 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
5502 if (!rc && fid_is_namespace_visible(lu_object_fid(&dt->do_lu)) &&
5503 obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
5504 /* NB, dirent count may not be accurate, because it's counted
5507 if (obj->oo_dirent_count)
5508 obj->oo_dirent_count--;
5510 obj->oo_dirent_count = LU_DIRENT_COUNT_UNSET;
5513 ldiskfs_htree_unlock(hlock);
5515 up_write(&obj->oo_ext_idx_sem);
5518 LASSERT(osd_invariant(obj));
5519 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
5520 if (ln.ln_name != (char *)key)
5526 * Lookup index for \a key and copy record to \a rec.
5528 * \param dt osd index object
5529 * \param key key for index
5530 * \param rec record reference
5532 * \retval +ve success : exact mach
5533 * \retval 0 return record with key not greater than \a key
5534 * \retval -ve failure
5536 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
5537 struct dt_rec *rec, const struct dt_key *key)
5539 struct osd_object *obj = osd_dt_obj(dt);
5540 struct iam_path_descr *ipd;
5541 struct iam_container *bag = &obj->oo_dir->od_container;
5542 struct osd_thread_info *oti = osd_oti_get(env);
5543 struct iam_iterator *it = &oti->oti_idx_it;
5544 struct iam_rec *iam_rec;
5549 if (!dt_object_exists(dt))
5552 LASSERT(osd_invariant(obj));
5553 LASSERT(!dt_object_remote(dt));
5554 LASSERT(bag->ic_object == obj->oo_inode);
5556 ipd = osd_idx_ipd_get(env, bag);
5560 /* got ipd now we can start iterator. */
5561 iam_it_init(it, bag, 0, ipd);
5563 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5564 /* swab quota uid/gid provided by caller */
5565 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5566 key = (const struct dt_key *)&oti->oti_quota_id;
5569 rc = iam_it_get(it, (struct iam_key *)key);
5571 if (S_ISDIR(obj->oo_inode->i_mode))
5572 iam_rec = (struct iam_rec *)oti->oti_ldp;
5574 iam_rec = (struct iam_rec *)rec;
5576 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
5578 if (S_ISDIR(obj->oo_inode->i_mode))
5579 osd_fid_unpack((struct lu_fid *)rec,
5580 (struct osd_fid_pack *)iam_rec);
5581 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
5582 osd_quota_unpack(obj, rec);
5587 osd_ipd_put(env, bag, ipd);
5589 LINVRNT(osd_invariant(obj));
5594 static int osd_index_declare_iam_insert(const struct lu_env *env,
5595 struct dt_object *dt,
5596 const struct dt_rec *rec,
5597 const struct dt_key *key,
5598 struct thandle *handle)
5600 struct osd_thandle *oh;
5602 LASSERT(handle != NULL);
5604 oh = container_of(handle, struct osd_thandle, ot_super);
5605 LASSERT(oh->ot_handle == NULL);
5607 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
5608 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
5614 * Inserts (key, value) pair in \a dt index object.
5616 * \param dt osd index object
5617 * \param key key for index
5618 * \param rec record reference
5619 * \param th transaction handler
5622 * \retval -ve failure
5624 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
5625 const struct dt_rec *rec,
5626 const struct dt_key *key, struct thandle *th)
5628 struct osd_object *obj = osd_dt_obj(dt);
5629 struct iam_path_descr *ipd;
5630 struct osd_thandle *oh;
5631 struct iam_container *bag;
5632 struct osd_thread_info *oti = osd_oti_get(env);
5633 struct iam_rec *iam_rec;
5638 if (!dt_object_exists(dt))
5641 LINVRNT(osd_invariant(obj));
5642 LASSERT(!dt_object_remote(dt));
5644 bag = &obj->oo_dir->od_container;
5645 LASSERT(bag->ic_object == obj->oo_inode);
5646 LASSERT(th != NULL);
5648 osd_trans_exec_op(env, th, OSD_OT_INSERT);
5650 ipd = osd_idx_ipd_get(env, bag);
5651 if (unlikely(ipd == NULL))
5654 oh = container_of(th, struct osd_thandle, ot_super);
5655 LASSERT(oh->ot_handle != NULL);
5656 LASSERT(oh->ot_handle->h_transaction != NULL);
5657 if (S_ISDIR(obj->oo_inode->i_mode)) {
5658 iam_rec = (struct iam_rec *)oti->oti_ldp;
5659 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec,
5661 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5662 /* pack quota uid/gid */
5663 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5664 key = (const struct dt_key *)&oti->oti_quota_id;
5665 /* pack quota record */
5666 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
5667 iam_rec = (struct iam_rec *)rec;
5669 iam_rec = (struct iam_rec *)rec;
5672 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
5674 osd_ipd_put(env, bag, ipd);
5675 LINVRNT(osd_invariant(obj));
5676 osd_trans_exec_check(env, th, OSD_OT_INSERT);
5681 * Calls ldiskfs_add_entry() to add directory entry
5682 * into the directory. This is required for
5683 * interoperability mode (b11826)
5685 * \retval 0, on success
5686 * \retval -ve, on error
5688 static int __osd_ea_add_rec(struct osd_thread_info *info,
5689 struct osd_object *pobj, struct inode *cinode,
5690 const char *name, const struct lu_fid *fid,
5691 struct htree_lock *hlock, struct thandle *th)
5693 struct ldiskfs_dentry_param *ldp;
5694 struct dentry *child;
5695 struct osd_thandle *oth;
5699 oth = container_of(th, struct osd_thandle, ot_super);
5700 LASSERT(oth->ot_handle != NULL);
5701 LASSERT(oth->ot_handle->h_transaction != NULL);
5702 LASSERT(pobj->oo_inode);
5704 rc = obj_name2lu_name(pobj, name, strlen(name), &ln);
5708 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
5709 if (unlikely(osd_object_is_root(pobj)))
5712 osd_get_ldiskfs_dirent_param(ldp, fid);
5713 child = osd_child_dentry_get(info->oti_env, pobj,
5714 ln.ln_name, ln.ln_namelen);
5715 child->d_fsdata = (void *)ldp;
5716 dquot_initialize(pobj->oo_inode);
5717 rc = osd_ldiskfs_add_entry(info, osd_obj2dev(pobj), oth->ot_handle,
5718 child, cinode, hlock);
5719 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
5720 struct ldiskfs_dir_entry_2 *de;
5721 struct buffer_head *bh;
5724 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
5727 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
5730 if (S_ISDIR(cinode->i_mode))
5731 de->file_type = LDISKFS_DIRENT_LUFID |
5732 LDISKFS_FT_REG_FILE;
5734 de->file_type = LDISKFS_DIRENT_LUFID |
5736 ldiskfs_handle_dirty_metadata(oth->ot_handle,
5743 if (ln.ln_name != name)
5749 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
5750 * into the directory.Also sets flags into osd object to
5751 * indicate dot and dotdot are created. This is required for
5752 * interoperability mode (b11826)
5754 * \param dir directory for dot and dotdot fixup.
5755 * \param obj child object for linking
5757 * \retval 0, on success
5758 * \retval -ve, on error
5760 static int osd_add_dot_dotdot(struct osd_thread_info *info,
5761 struct osd_object *dir,
5762 struct inode *parent_dir, const char *name,
5763 const struct lu_fid *dot_fid,
5764 const struct lu_fid *dot_dot_fid,
5767 struct inode *inode = dir->oo_inode;
5768 struct osd_thandle *oth;
5771 oth = container_of(th, struct osd_thandle, ot_super);
5772 LASSERT(oth->ot_handle->h_transaction != NULL);
5773 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
5775 if (strcmp(name, dot) == 0) {
5776 if (dir->oo_compat_dot_created) {
5779 LASSERT(inode->i_ino == parent_dir->i_ino);
5780 dir->oo_compat_dot_created = 1;
5783 } else if (strcmp(name, dotdot) == 0) {
5784 if (!dir->oo_compat_dot_created)
5786 /* in case of rename, dotdot is already created */
5787 if (dir->oo_compat_dotdot_created) {
5788 return __osd_ea_add_rec(info, dir, parent_dir, name,
5789 dot_dot_fid, NULL, th);
5792 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
5793 struct lu_fid tfid = *dot_dot_fid;
5796 result = osd_add_dot_dotdot_internal(info,
5797 dir->oo_inode, parent_dir, dot_fid,
5800 result = osd_add_dot_dotdot_internal(info,
5801 dir->oo_inode, parent_dir, dot_fid,
5806 dir->oo_compat_dotdot_created = 1;
5814 * It will call the appropriate osd_add* function and return the
5815 * value, return by respective functions.
5817 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
5818 struct inode *cinode, const char *name,
5819 const struct lu_fid *fid, struct thandle *th)
5821 struct osd_thread_info *info = osd_oti_get(env);
5822 struct htree_lock *hlock;
5825 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
5827 if (name[0] == '.' && (name[1] == '\0' ||
5828 (name[1] == '.' && name[2] == '\0'))) {
5829 if (hlock != NULL) {
5830 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5833 down_write(&pobj->oo_ext_idx_sem);
5836 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
5837 lu_object_fid(&pobj->oo_dt.do_lu),
5840 if (hlock != NULL) {
5841 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5842 pobj->oo_inode, LDISKFS_HLOCK_ADD);
5844 down_write(&pobj->oo_ext_idx_sem);
5847 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
5848 struct lu_fid *tfid = &info->oti_fid;
5852 rc = __osd_ea_add_rec(info, pobj, cinode, name,
5855 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
5859 if (!rc && fid_is_namespace_visible(lu_object_fid(&pobj->oo_dt.do_lu))
5860 && pobj->oo_dirent_count != LU_DIRENT_COUNT_UNSET)
5861 pobj->oo_dirent_count++;
5864 ldiskfs_htree_unlock(hlock);
5866 up_write(&pobj->oo_ext_idx_sem);
5872 osd_ldiskfs_consistency_check(struct osd_thread_info *oti,
5873 struct osd_device *dev,
5874 const struct lu_fid *fid,
5875 struct osd_inode_id *id)
5877 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
5878 struct inode *inode = NULL;
5884 if (!scrub_needs_check(scrub, fid, id->oii_ino))
5887 rc = osd_oi_lookup(oti, dev, fid, &oti->oti_id, 0);
5888 if (rc == -ENOENT) {
5889 __u32 gen = id->oii_gen;
5895 inode = osd_iget(oti, dev, id);
5896 /* The inode has been removed (by race maybe). */
5897 if (IS_ERR(inode)) {
5898 rc = PTR_ERR(inode);
5900 RETURN(rc == -ESTALE ? -ENOENT : rc);
5903 /* The OI mapping is lost. */
5904 if (gen != OSD_OII_NOGEN)
5908 * The inode may has been reused by others, we do not know,
5909 * leave it to be handled by subsequent osd_fid_lookup().
5912 } else if (rc || osd_id_eq(id, &oti->oti_id)) {
5919 if (scrub->os_running) {
5920 if (inode == NULL) {
5921 inode = osd_iget(oti, dev, id);
5922 /* The inode has been removed (by race maybe). */
5923 if (IS_ERR(inode)) {
5924 rc = PTR_ERR(inode);
5926 RETURN(rc == -ESTALE ? -ENOENT : rc);
5930 rc = osd_oii_insert(dev, fid, id, insert);
5932 * There is race condition between osd_oi_lookup and OI scrub.
5933 * The OI scrub finished just after osd_oi_lookup() failure.
5934 * Under such case, it is unnecessary to trigger OI scrub again,
5935 * but try to call osd_oi_lookup() again.
5937 if (unlikely(rc == -EAGAIN))
5940 if (!S_ISDIR(inode->i_mode))
5943 rc = osd_check_lmv(oti, dev, inode);
5948 if (dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
5950 rc = osd_scrub_start(oti->oti_env, dev, SS_AUTO_PARTIAL |
5951 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
5952 CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
5953 "%s: trigger partial OI scrub for RPC inconsistency, checking FID "DFID"/%u: rc = %d\n",
5954 osd_dev2name(dev), PFID(fid), id->oii_ino, rc);
5955 if (rc == 0 || rc == -EALREADY)
5967 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
5968 struct osd_device *dev,
5969 struct lu_fid *fid, __u32 ino)
5971 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
5972 struct osd_idmap_cache *oic = &oti->oti_cache;
5973 struct inode *inode;
5976 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
5977 inode = osd_iget(oti, dev, &oic->oic_lid);
5978 if (IS_ERR(inode)) {
5979 fid_zero(&oic->oic_fid);
5980 return PTR_ERR(inode);
5983 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, loa);
5986 fid_zero(&oic->oic_fid);
5988 *fid = oic->oic_fid = loa->loa_lma.lma_self_fid;
5992 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
5993 struct osd_inode_id *id, const struct lu_fid *fid)
5995 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
5996 id->oii_ino, id->oii_gen, info);
5997 info->oti_cache.oic_lid = *id;
5998 info->oti_cache.oic_fid = *fid;
5999 info->oti_cache.oic_dev = osd;
6003 * Get parent FID from the linkEA.
6005 * For a directory which parent resides on remote MDT, to satisfy the
6006 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
6007 * the other hand, to make the lookup(..) on the directory can return
6008 * the real parent FID, we append the real parent FID after its ".."
6009 * name entry in the /REMOTE_PARENT_DIR.
6011 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
6012 * backup. So after the restore, we cannot get the right parent FID from
6013 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
6014 * we have stored the real parent FID in the directory object's linkEA,
6015 * we can parse the linkEA for the real parent FID.
6017 * \param[in] env pointer to the thread context
6018 * \param[in] obj pointer to the object to be handled
6019 * \param[out]fid pointer to the buffer to hold the parent FID
6021 * \retval 0 for getting the real parent FID successfully
6022 * \retval negative error number on failure
6024 static int osd_get_pfid_from_linkea(const struct lu_env *env,
6025 struct osd_object *obj,
6028 struct osd_thread_info *oti = osd_oti_get(env);
6029 struct lu_buf *buf = &oti->oti_big_buf;
6030 struct dentry *dentry = &oti->oti_obj_dentry;
6031 struct inode *inode = obj->oo_inode;
6032 struct linkea_data ldata = { NULL };
6038 if (!S_ISDIR(inode->i_mode))
6042 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6043 buf->lb_buf, buf->lb_len);
6044 if (rc == -ERANGE) {
6045 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6048 lu_buf_realloc(buf, rc);
6049 if (buf->lb_buf == NULL)
6056 if (unlikely(rc == 0))
6062 if (unlikely(buf->lb_buf == NULL)) {
6063 lu_buf_realloc(buf, rc);
6064 if (buf->lb_buf == NULL)
6071 rc = linkea_init_with_rec(&ldata);
6073 linkea_first_entry(&ldata);
6074 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
6080 static int osd_verify_ent_by_linkea(const struct lu_env *env,
6081 struct inode *inode,
6082 const struct lu_fid *pfid,
6083 const char *name, const int namelen)
6085 struct osd_thread_info *oti = osd_oti_get(env);
6086 struct lu_buf *buf = &oti->oti_big_buf;
6087 struct dentry *dentry = &oti->oti_obj_dentry;
6088 struct linkea_data ldata = { NULL };
6089 struct lu_name cname = { .ln_name = name,
6090 .ln_namelen = namelen };
6096 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6097 buf->lb_buf, buf->lb_len);
6099 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK, NULL, 0);
6104 if (unlikely(rc == 0))
6107 if (buf->lb_len < rc) {
6108 lu_buf_realloc(buf, rc);
6109 if (buf->lb_buf == NULL)
6116 rc = linkea_init_with_rec(&ldata);
6118 rc = linkea_links_find(&ldata, &cname, pfid);
6124 * Calls ->lookup() to find dentry. From dentry get inode and
6125 * read inode's ea to get fid. This is required for interoperability
6128 * \retval 0, on success
6129 * \retval -ve, on error
6131 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
6132 struct dt_rec *rec, const struct dt_key *key)
6134 struct inode *dir = obj->oo_inode;
6135 struct dentry *dentry;
6136 struct ldiskfs_dir_entry_2 *de;
6137 struct buffer_head *bh;
6138 struct lu_fid *fid = (struct lu_fid *)rec;
6139 struct htree_lock *hlock = NULL;
6146 LASSERT(dir->i_op != NULL);
6147 LASSERT(dir->i_op->lookup != NULL);
6149 rc = obj_name2lu_name(obj, (char *)key, strlen((char *)key), &ln);
6153 dentry = osd_child_dentry_get(env, obj, ln.ln_name, ln.ln_namelen);
6155 if (obj->oo_hl_head != NULL) {
6156 hlock = osd_oti_get(env)->oti_hlock;
6157 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
6158 dir, LDISKFS_HLOCK_LOOKUP);
6160 down_read(&obj->oo_ext_idx_sem);
6163 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
6165 struct osd_thread_info *oti = osd_oti_get(env);
6166 struct osd_inode_id *id = &oti->oti_id;
6167 struct osd_device *dev = osd_obj2dev(obj);
6169 ino = le32_to_cpu(de->inode);
6170 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
6172 rc = osd_fail_fid_lookup(oti, dev, fid, ino);
6176 rc = osd_get_fid_from_dentry(de, rec);
6178 /* done with de, release bh */
6181 if (unlikely(is_remote_parent_ino(dev, ino))) {
6182 const char *name = (const char *)key;
6185 * If the parent is on remote MDT, and there
6186 * is no FID-in-dirent, then we have to get
6187 * the parent FID from the linkEA.
6189 if (likely(strlen(name) == 2 &&
6190 name[0] == '.' && name[1] == '.'))
6191 rc = osd_get_pfid_from_linkea(env, obj,
6194 rc = osd_ea_fid_get(env, obj, ino, fid, id);
6197 osd_id_gen(id, ino, OSD_OII_NOGEN);
6200 if (rc != 0 || osd_remote_fid(env, dev, fid))
6203 rc = osd_ldiskfs_consistency_check(oti, dev, fid, id);
6204 if (rc != -ENOENT) {
6205 /* Other error should not affect lookup result. */
6208 /* Normal file mapping should be added into OI cache
6209 * after FID in LMA check, but for local files like
6210 * hsm_actions, their FIDs are not stored in OI files,
6211 * see osd_initial_OI_scrub(), and here is the only
6212 * place to load mapping into OI cache.
6214 if (!fid_is_namespace_visible(fid))
6215 osd_add_oi_cache(osd_oti_get(env),
6216 osd_obj2dev(obj), id, fid);
6226 ldiskfs_htree_unlock(hlock);
6228 up_read(&obj->oo_ext_idx_sem);
6229 if (ln.ln_name != (char *)key)
6234 static int osd_index_declare_ea_insert(const struct lu_env *env,
6235 struct dt_object *dt,
6236 const struct dt_rec *rec,
6237 const struct dt_key *key,
6238 struct thandle *handle)
6240 struct osd_thandle *oh;
6241 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
6242 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
6243 const struct lu_fid *fid = rec1->rec_fid;
6244 int credits, rc = 0;
6245 struct osd_idmap_cache *idc;
6249 LASSERT(!dt_object_remote(dt));
6250 LASSERT(handle != NULL);
6251 LASSERT(fid != NULL);
6252 LASSERT(rec1->rec_type != 0);
6254 oh = container_of(handle, struct osd_thandle, ot_super);
6255 LASSERT(oh->ot_handle == NULL);
6257 credits = osd_dto_credits_noquota[DTO_INDEX_INSERT];
6260 * we can't call iget() while a transactions is running
6261 * (this can lead to a deadlock), but we need to know
6262 * inum and object type. so we find this information at
6263 * declaration and cache in per-thread info
6265 idc = osd_idc_find_or_init(env, osd, fid);
6267 RETURN(PTR_ERR(idc));
6268 if (idc->oic_remote) {
6270 * a reference to remote inode is represented by an
6271 * agent inode which we have to create
6273 credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
6274 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
6277 osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits);
6279 if (osd_dt_obj(dt)->oo_inode != NULL) {
6280 struct inode *inode = osd_dt_obj(dt)->oo_inode;
6283 * We ignore block quota on meta pool (MDTs), so needn't
6284 * calculate how many blocks will be consumed by this index
6287 rc = osd_declare_inode_qid(env, i_uid_read(inode),
6289 i_projid_read(inode), 0,
6290 oh, osd_dt_obj(dt), NULL,
6295 #ifdef HAVE_PROJECT_QUOTA
6297 * Reserve credits for local agent inode to transfer
6298 * to 0, quota enforcement is ignored in this case.
6300 if (idc->oic_remote &&
6301 LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
6302 i_projid_read(inode) != 0)
6303 rc = osd_declare_attr_qid(env, osd_dt_obj(dt), oh,
6304 0, i_projid_read(inode),
6305 0, false, PRJQUOTA);
6313 * Index add function for interoperability mode (b11826).
6314 * It will add the directory entry.This entry is needed to
6315 * maintain name->fid mapping.
6317 * \param key it is key i.e. file entry to be inserted
6318 * \param rec it is value of given key i.e. fid
6320 * \retval 0, on success
6321 * \retval -ve, on error
6323 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
6324 const struct dt_rec *rec,
6325 const struct dt_key *key, struct thandle *th)
6327 struct osd_object *obj = osd_dt_obj(dt);
6328 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
6329 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
6330 const struct lu_fid *fid = rec1->rec_fid;
6331 const char *name = (const char *)key;
6332 struct osd_thread_info *oti = osd_oti_get(env);
6333 struct inode *child_inode = NULL;
6334 struct osd_idmap_cache *idc;
6339 if (!dt_object_exists(dt))
6342 LASSERT(osd_invariant(obj));
6343 LASSERT(!dt_object_remote(dt));
6344 LASSERT(th != NULL);
6346 osd_trans_exec_op(env, th, OSD_OT_INSERT);
6348 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
6350 idc = osd_idc_find(env, osd, fid);
6351 if (unlikely(idc == NULL)) {
6352 idc = osd_idc_find_or_init(env, osd, fid);
6355 * this dt_insert() wasn't declared properly, so
6356 * FID is missing in OI cache. we better do not
6357 * lookup FID in FLDB/OI and don't risk to deadlock,
6358 * but in some special cases (lfsck testing, etc)
6359 * it's much simpler than fixing a caller.
6361 * normally this error should be placed after the first
6362 * find, but migrate may attach source stripes to
6363 * target, which doesn't create stripes.
6365 CERROR("%s: "DFID" wasn't declared for insert\n",
6366 osd_name(osd), PFID(fid));
6368 RETURN(PTR_ERR(idc));
6372 if (idc->oic_remote) {
6373 /* Insert remote entry */
6374 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
6376 igrab(osd->od_mdt_map->omm_remote_parent->d_inode);
6378 child_inode = osd_create_local_agent_inode(env, osd,
6379 obj, fid, rec1->rec_type & S_IFMT, th);
6380 if (IS_ERR(child_inode))
6381 RETURN(PTR_ERR(child_inode));
6384 /* Insert local entry */
6385 if (unlikely(idc->oic_lid.oii_ino == 0)) {
6386 /* for a reason OI cache wasn't filled properly */
6387 CERROR("%s: OIC for "DFID" isn't filled\n",
6388 osd_name(osd), PFID(fid));
6391 child_inode = oti->oti_inode;
6392 if (unlikely(child_inode == NULL)) {
6393 struct ldiskfs_inode_info *lii;
6398 child_inode = oti->oti_inode = &lii->vfs_inode;
6400 child_inode->i_sb = osd_sb(osd);
6401 child_inode->i_ino = idc->oic_lid.oii_ino;
6402 child_inode->i_mode = rec1->rec_type & S_IFMT;
6405 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
6407 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
6408 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
6410 if (child_inode && child_inode != oti->oti_inode)
6412 LASSERT(osd_invariant(obj));
6413 osd_trans_exec_check(env, th, OSD_OT_INSERT);
6419 * Initialize osd Iterator for given osd index object.
6421 * \param dt osd index object
6424 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
6425 struct dt_object *dt,
6428 struct osd_it_iam *it;
6429 struct osd_object *obj = osd_dt_obj(dt);
6430 struct lu_object *lo = &dt->do_lu;
6431 struct iam_path_descr *ipd;
6432 struct iam_container *bag = &obj->oo_dir->od_container;
6434 if (!dt_object_exists(dt))
6435 return ERR_PTR(-ENOENT);
6439 return ERR_PTR(-ENOMEM);
6441 ipd = osd_it_ipd_get(env, bag);
6442 if (likely(ipd != NULL)) {
6446 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
6447 return (struct dt_it *)it;
6450 return ERR_PTR(-ENOMEM);
6455 * free given Iterator.
6457 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
6459 struct osd_it_iam *it = (struct osd_it_iam *)di;
6460 struct osd_object *obj = it->oi_obj;
6462 iam_it_fini(&it->oi_it);
6463 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
6464 osd_object_put(env, obj);
6469 * Move Iterator to record specified by \a key
6471 * \param di osd iterator
6472 * \param key key for index
6474 * \retval +ve di points to record with least key not larger than key
6475 * \retval 0 di points to exact matched key
6476 * \retval -ve failure
6479 static int osd_it_iam_get(const struct lu_env *env,
6480 struct dt_it *di, const struct dt_key *key)
6482 struct osd_thread_info *oti = osd_oti_get(env);
6483 struct osd_it_iam *it = (struct osd_it_iam *)di;
6485 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
6486 /* swab quota uid/gid */
6487 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
6488 key = (struct dt_key *)&oti->oti_quota_id;
6491 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
6497 * \param di osd iterator
6499 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
6501 struct osd_it_iam *it = (struct osd_it_iam *)di;
6503 iam_it_put(&it->oi_it);
6507 * Move iterator by one record
6509 * \param di osd iterator
6511 * \retval +1 end of container reached
6513 * \retval -ve failure
6516 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
6518 struct osd_it_iam *it = (struct osd_it_iam *)di;
6520 return iam_it_next(&it->oi_it);
6524 * Return pointer to the key under iterator.
6527 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
6528 const struct dt_it *di)
6530 struct osd_thread_info *oti = osd_oti_get(env);
6531 struct osd_it_iam *it = (struct osd_it_iam *)di;
6532 struct osd_object *obj = it->oi_obj;
6535 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
6537 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
6538 /* swab quota uid/gid */
6539 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
6540 key = (struct dt_key *)&oti->oti_quota_id;
6547 * Return size of key under iterator (in bytes)
6550 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
6552 struct osd_it_iam *it = (struct osd_it_iam *)di;
6554 return iam_it_key_size(&it->oi_it);
6558 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
6560 /* check if file type is required */
6561 if (ent->lde_attrs & LUDA_TYPE) {
6562 struct luda_type *lt;
6563 int align = sizeof(*lt) - 1;
6565 len = (len + align) & ~align;
6566 lt = (struct luda_type *)(ent->lde_name + len);
6567 lt->lt_type = cpu_to_le16(DTTOIF(type));
6570 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
6574 * build lu direct from backend fs dirent.
6578 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
6579 char *name, __u16 namelen, __u16 type, __u32 attr)
6581 ent->lde_attrs = attr | LUDA_FID;
6582 fid_cpu_to_le(&ent->lde_fid, fid);
6584 ent->lde_hash = cpu_to_le64(offset);
6585 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
6587 strncpy(ent->lde_name, name, namelen);
6588 ent->lde_name[namelen] = '\0';
6589 ent->lde_namelen = cpu_to_le16(namelen);
6591 /* append lustre attributes */
6592 osd_it_append_attrs(ent, namelen, type);
6596 * Return pointer to the record under iterator.
6598 static int osd_it_iam_rec(const struct lu_env *env,
6599 const struct dt_it *di,
6600 struct dt_rec *dtrec, __u32 attr)
6602 struct osd_it_iam *it = (struct osd_it_iam *)di;
6603 struct osd_thread_info *info = osd_oti_get(env);
6607 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
6608 const struct osd_fid_pack *rec;
6609 struct lu_fid *fid = &info->oti_fid;
6610 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
6616 name = (char *)iam_it_key_get(&it->oi_it);
6618 RETURN(PTR_ERR(name));
6620 namelen = iam_it_key_size(&it->oi_it);
6622 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
6624 RETURN(PTR_ERR(rec));
6626 rc = osd_fid_unpack(fid, rec);
6630 hash = iam_it_store(&it->oi_it);
6632 /* IAM does not store object type in IAM index (dir) */
6633 osd_it_pack_dirent(lde, fid, hash, name, namelen,
6635 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
6636 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
6637 (struct iam_rec *)dtrec);
6638 osd_quota_unpack(it->oi_obj, dtrec);
6640 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
6641 (struct iam_rec *)dtrec);
6648 * Returns cookie for current Iterator position.
6650 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
6652 struct osd_it_iam *it = (struct osd_it_iam *)di;
6654 return iam_it_store(&it->oi_it);
6658 * Restore iterator from cookie.
6660 * \param di osd iterator
6661 * \param hash Iterator location cookie
6663 * \retval +ve di points to record with least key not larger than key.
6664 * \retval 0 di points to exact matched key
6665 * \retval -ve failure
6668 static int osd_it_iam_load(const struct lu_env *env,
6669 const struct dt_it *di, __u64 hash)
6671 struct osd_it_iam *it = (struct osd_it_iam *)di;
6673 return iam_it_load(&it->oi_it, hash);
6676 static const struct dt_index_operations osd_index_iam_ops = {
6677 .dio_lookup = osd_index_iam_lookup,
6678 .dio_declare_insert = osd_index_declare_iam_insert,
6679 .dio_insert = osd_index_iam_insert,
6680 .dio_declare_delete = osd_index_declare_iam_delete,
6681 .dio_delete = osd_index_iam_delete,
6683 .init = osd_it_iam_init,
6684 .fini = osd_it_iam_fini,
6685 .get = osd_it_iam_get,
6686 .put = osd_it_iam_put,
6687 .next = osd_it_iam_next,
6688 .key = osd_it_iam_key,
6689 .key_size = osd_it_iam_key_size,
6690 .rec = osd_it_iam_rec,
6691 .store = osd_it_iam_store,
6692 .load = osd_it_iam_load
6696 struct osd_it_ea *osd_it_dir_init(const struct lu_env *env,
6697 struct osd_device *dev,
6698 struct inode *inode, u32 attr)
6700 struct osd_thread_info *info = osd_oti_get(env);
6701 struct osd_it_ea *oie;
6705 file = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
6708 RETURN(ERR_CAST(file));
6710 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
6711 if (attr & LUDA_64BITHASH)
6712 file->f_mode |= FMODE_64BITHASH;
6714 file->f_mode |= FMODE_32BITHASH;
6717 OBD_SLAB_ALLOC_PTR(oie, osd_itea_cachep);
6721 oie->oie_rd_dirent = 0;
6722 oie->oie_it_dirent = 0;
6723 oie->oie_dirent = NULL;
6724 if (unlikely(!info->oti_it_ea_buf_used)) {
6725 oie->oie_buf = info->oti_it_ea_buf;
6726 info->oti_it_ea_buf_used = 1;
6728 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
6732 oie->oie_obj = NULL;
6733 oie->oie_file = file;
6738 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
6742 return ERR_PTR(-ENOMEM);
6746 * Creates or initializes iterator context.
6748 * \retval struct osd_it_ea, iterator structure on success
6751 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
6752 struct dt_object *dt,
6755 struct osd_object *obj = osd_dt_obj(dt);
6756 struct osd_device *dev = osd_obj2dev(obj);
6757 struct lu_object *lo = &dt->do_lu;
6758 struct osd_it_ea *oie;
6762 if (!dt_object_exists(dt) || obj->oo_destroyed)
6763 RETURN(ERR_PTR(-ENOENT));
6765 oie = osd_it_dir_init(env, dev, obj->oo_inode, attr);
6767 RETURN(ERR_CAST(oie));
6771 RETURN((struct dt_it *)oie);
6774 void osd_it_dir_fini(const struct lu_env *env, struct osd_it_ea *oie,
6775 struct inode *inode)
6777 struct osd_thread_info *info = osd_oti_get(env);
6780 fput(oie->oie_file);
6781 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
6782 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
6784 info->oti_it_ea_buf_used = 0;
6785 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
6790 * Destroy or finishes iterator context.
6792 * \param di iterator structure to be destroyed
6794 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
6796 struct osd_it_ea *oie = (struct osd_it_ea *)di;
6797 struct osd_object *obj = oie->oie_obj;
6798 struct inode *inode = obj->oo_inode;
6801 osd_it_dir_fini(env, (struct osd_it_ea *)di, inode);
6802 osd_object_put(env, obj);
6807 * It position the iterator at given key, so that next lookup continues from
6808 * that key Or it is similar to dio_it->load() but based on a key,
6809 * rather than file position.
6811 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
6814 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
6816 static int osd_it_ea_get(const struct lu_env *env,
6817 struct dt_it *di, const struct dt_key *key)
6819 struct osd_it_ea *it = (struct osd_it_ea *)di;
6822 LASSERT(((const char *)key)[0] == '\0');
6823 it->oie_file->f_pos = 0;
6824 it->oie_rd_dirent = 0;
6825 it->oie_it_dirent = 0;
6826 it->oie_dirent = NULL;
6834 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
6838 struct osd_filldir_cbs {
6839 struct dir_context ctx;
6840 struct osd_it_ea *it;
6843 * It is called internally by ->iterate*(). It fills the
6844 * iterator's in-memory data structure with required
6845 * information i.e. name, namelen, rec_size etc.
6847 * \param buf in which information to be filled in.
6848 * \param name name of the file in given dir
6850 * \retval 0 on success
6851 * \retval 1 on buffer full
6853 #ifdef HAVE_FILLDIR_USE_CTX
6854 static int osd_ldiskfs_filldir(struct dir_context *buf,
6856 static int osd_ldiskfs_filldir(void *buf,
6858 const char *name, int namelen,
6859 loff_t offset, __u64 ino, unsigned int d_type)
6861 struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it;
6862 struct osd_object *obj = it->oie_obj;
6863 struct osd_it_ea_dirent *ent = it->oie_dirent;
6864 struct lu_fid *fid = &ent->oied_fid;
6865 struct osd_fid_pack *rec;
6866 struct lu_fid namefid;
6870 /* this should never happen */
6871 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
6872 CERROR("ldiskfs return invalid namelen %d\n", namelen);
6876 if ((void *)ent - it->oie_buf + sizeof(*ent) + namelen >
6882 /* "." is just the object itself. */
6883 if (namelen == 1 && name[0] == '.') {
6885 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6886 } else if (d_type & LDISKFS_DIRENT_LUFID) {
6887 rec = (struct osd_fid_pack *)(name + namelen + 1);
6888 if (osd_fid_unpack(fid, rec) != 0)
6893 d_type &= ~LDISKFS_DIRENT_LUFID;
6895 /* NOT export local root. */
6897 unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
6898 ino = obj->oo_inode->i_ino;
6899 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6903 sscanf(name + 1, SFID, RFID(&namefid));
6904 if (fid_is_sane(&namefid) || name_is_dot_or_dotdot(name, namelen) ||
6905 !obj || !(obj->oo_lma_flags & LUSTRE_ENCRYPT_FL)) {
6906 memcpy(ent->oied_name, name, namelen);
6908 int presented_len = critical_chars(name, namelen);
6910 if (presented_len == namelen)
6911 memcpy(ent->oied_name, name, namelen);
6913 namelen = critical_encode(name, namelen,
6916 ent->oied_name[namelen] = '\0';
6919 ent->oied_ino = ino;
6920 ent->oied_off = offset;
6921 ent->oied_namelen = namelen;
6922 ent->oied_type = d_type;
6924 it->oie_rd_dirent++;
6925 it->oie_dirent = (void *)ent + cfs_size_round(sizeof(*ent) + namelen);
6930 * Calls ->iterate*() to load a directory entry at a time
6931 * and stored it in iterator's in-memory data structure.
6933 * \param di iterator's in memory structure
6935 * \retval 0 on success
6936 * \retval -ve on error
6937 * \retval +1 reach the end of entry
6939 int osd_ldiskfs_it_fill(const struct lu_env *env, const struct dt_it *di)
6941 struct osd_it_ea *it = (struct osd_it_ea *)di;
6942 struct osd_object *obj = it->oie_obj;
6943 struct htree_lock *hlock = NULL;
6944 struct file *filp = it->oie_file;
6946 struct osd_filldir_cbs buf = {
6947 .ctx.actor = osd_ldiskfs_filldir,
6952 it->oie_dirent = it->oie_buf;
6953 it->oie_rd_dirent = 0;
6956 if (obj->oo_hl_head != NULL) {
6957 hlock = osd_oti_get(env)->oti_hlock;
6958 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
6960 LDISKFS_HLOCK_READDIR);
6962 down_read(&obj->oo_ext_idx_sem);
6966 rc = iterate_dir(filp, &buf.ctx);
6970 if (it->oie_rd_dirent == 0) {
6972 * If it does not get any dirent, it means it has been reached
6973 * to the end of the dir
6975 it->oie_file->f_pos = ldiskfs_get_htree_eof(it->oie_file);
6979 it->oie_dirent = it->oie_buf;
6980 it->oie_it_dirent = 1;
6985 ldiskfs_htree_unlock(hlock);
6987 up_read(&obj->oo_ext_idx_sem);
6994 * It calls osd_ldiskfs_it_fill() which will use ->iterate*()
6995 * to load a directory entry at a time and stored it in
6996 * iterator's in-memory data structure.
6998 * \param di iterator's in memory structure
7000 * \retval +ve iterator reached to end
7001 * \retval 0 iterator not reached to end
7002 * \retval -ve on error
7004 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
7006 struct osd_it_ea *it = (struct osd_it_ea *)di;
7011 if (it->oie_it_dirent < it->oie_rd_dirent) {
7013 (void *)it->oie_dirent +
7014 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
7015 it->oie_dirent->oied_namelen);
7016 it->oie_it_dirent++;
7019 if (it->oie_file->f_pos == ldiskfs_get_htree_eof(it->oie_file))
7022 rc = osd_ldiskfs_it_fill(env, di);
7029 * Returns the key at current position from iterator's in memory structure.
7031 * \param di iterator's in memory structure
7033 * \retval key i.e. struct dt_key on success
7035 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
7036 const struct dt_it *di)
7038 struct osd_it_ea *it = (struct osd_it_ea *)di;
7040 return (struct dt_key *)it->oie_dirent->oied_name;
7044 * Returns key's size at current position from iterator's in memory structure.
7046 * \param di iterator's in memory structure
7048 * \retval key_size i.e. struct dt_key on success
7050 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
7052 struct osd_it_ea *it = (struct osd_it_ea *)di;
7054 return it->oie_dirent->oied_namelen;
7057 #if defined LDISKFS_DIR_ENTRY_LEN && defined LDISKFS_DIR_ENTRY_LEN_
7058 #undef LDISKFS_DIR_REC_LEN
7059 #define LDISKFS_DIR_REC_LEN(de) LDISKFS_DIR_ENTRY_LEN_((de))
7062 static inline bool osd_dotdot_has_space(struct ldiskfs_dir_entry_2 *de)
7064 if (LDISKFS_DIR_REC_LEN(de) >=
7065 __LDISKFS_DIR_REC_LEN(2 + 1 + sizeof(struct osd_fid_pack)))
7072 osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen,
7073 unsigned int blocksize, bool dotdot)
7076 return osd_dotdot_has_space(de);
7078 if (ldiskfs_rec_len_from_disk(de->rec_len, blocksize) >=
7079 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
7086 osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev,
7087 handle_t *jh, struct dentry *dentry,
7088 const struct lu_fid *fid, struct buffer_head *bh,
7089 struct ldiskfs_dir_entry_2 *de, struct htree_lock *hlock,
7092 struct inode *dir = dentry->d_parent->d_inode;
7093 struct inode *inode = dentry->d_inode;
7094 struct osd_fid_pack *rec;
7095 struct ldiskfs_dentry_param *ldp;
7096 int namelen = dentry->d_name.len;
7098 struct osd_thread_info *info = osd_oti_get(env);
7102 if (!ldiskfs_has_feature_dirdata(inode->i_sb))
7105 /* There is enough space to hold the FID-in-dirent. */
7106 if (osd_dirent_has_space(de, namelen, dir->i_sb->s_blocksize, dotdot)) {
7107 rc = ldiskfs_journal_get_write_access(jh, bh);
7111 de->name[namelen] = 0;
7112 rec = (struct osd_fid_pack *)(de->name + namelen + 1);
7113 rec->fp_len = sizeof(struct lu_fid) + 1;
7114 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
7115 de->file_type |= LDISKFS_DIRENT_LUFID;
7116 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
7123 rc = ldiskfs_delete_entry(jh, dir, de, bh);
7127 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
7128 osd_get_ldiskfs_dirent_param(ldp, fid);
7129 dentry->d_fsdata = (void *)ldp;
7130 dquot_initialize(dir);
7131 rc = osd_ldiskfs_add_entry(info, dev, jh, dentry, inode, hlock);
7133 * It is too bad, we cannot reinsert the name entry back.
7134 * That means we lose it!
7138 "%s: fail to reinsert the dirent, dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
7139 osd_ino2name(inode), dir->i_ino, dir->i_generation,
7140 namelen, dentry->d_name.name, PFID(fid), rc);
7146 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
7147 struct osd_it_ea *it, struct lu_fid *fid,
7148 struct osd_inode_id *id, __u32 *attr)
7150 struct osd_thread_info *info = osd_oti_get(env);
7151 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
7152 struct osd_device *dev = osd_obj2dev(obj);
7153 struct super_block *sb = osd_sb(dev);
7154 const char *devname = osd_name(dev);
7155 struct osd_it_ea_dirent *ent = it->oie_dirent;
7156 struct inode *dir = obj->oo_inode;
7157 struct htree_lock *hlock = NULL;
7158 struct buffer_head *bh = NULL;
7159 handle_t *jh = NULL;
7160 struct ldiskfs_dir_entry_2 *de;
7161 struct dentry *dentry;
7162 struct inode *inode;
7163 const struct lu_fid *pfid = lu_object_fid(&obj->oo_dt.do_lu);
7166 bool dotdot = false;
7172 if (ent->oied_name[0] == '.') {
7173 if (ent->oied_namelen == 1)
7176 if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
7180 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
7181 inode = osd_iget(info, dev, id);
7182 if (IS_ERR(inode)) {
7183 rc = PTR_ERR(inode);
7184 if (rc == -ENOENT || rc == -ESTALE) {
7186 * Maybe dangling name entry, or
7187 * corrupted directory entry.
7189 *attr |= LUDA_UNKNOWN;
7192 CDEBUG(D_LFSCK, "%s: fail to iget() for dirent "
7193 "check_repair, dir = %lu/%u, name = %.*s, "
7194 "ino = %llu, rc = %d\n",
7195 devname, dir->i_ino, dir->i_generation,
7196 ent->oied_namelen, ent->oied_name,
7203 rc = obj_name2lu_name(obj, ent->oied_name, ent->oied_namelen, &ln);
7207 dentry = osd_child_dentry_by_inode(env, dir, ln.ln_name, ln.ln_namelen);
7208 rc = osd_get_lma(info, inode, dentry, &info->oti_ost_attrs);
7209 if (rc == -ENODATA || !fid_is_sane(&lma->lma_self_fid))
7215 * We need to ensure that the name entry is still valid.
7216 * Because it may be removed or renamed by other already.
7218 * The unlink or rename operation will start journal before PDO lock,
7219 * so to avoid deadlock, here we need to start journal handle before
7220 * related PDO lock also. But because we do not know whether there
7221 * will be something to be repaired before PDO lock, we just start
7222 * journal without conditions.
7224 * We may need to remove the name entry firstly, then insert back.
7225 * One credit is for user quota file update.
7226 * One credit is for group quota file update.
7227 * Two credits are for dirty inode.
7229 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
7230 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
7232 if (dev->od_dirent_journal != 0) {
7235 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
7238 CDEBUG(D_LFSCK, "%s: fail to start trans for dirent "
7239 "check_repair, dir = %lu/%u, credits = %d, "
7240 "name = %.*s, ino = %llu: rc = %d\n",
7241 devname, dir->i_ino, dir->i_generation, credits,
7242 ent->oied_namelen, ent->oied_name,
7245 GOTO(out_inode, rc);
7248 if (obj->oo_hl_head != NULL) {
7249 hlock = osd_oti_get(env)->oti_hlock;
7251 * "0" means exclusive lock for the whole directory.
7252 * We need to prevent others access such name entry
7253 * during the delete + insert. Neither HLOCK_ADD nor
7254 * HLOCK_DEL cannot guarantee the atomicity.
7256 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
7258 down_write(&obj->oo_ext_idx_sem);
7261 if (obj->oo_hl_head != NULL) {
7262 hlock = osd_oti_get(env)->oti_hlock;
7263 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
7264 LDISKFS_HLOCK_LOOKUP);
7266 down_read(&obj->oo_ext_idx_sem);
7270 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
7271 if (IS_ERR(bh) || le32_to_cpu(de->inode) != inode->i_ino) {
7272 *attr |= LUDA_IGNORE;
7278 * For dotdot entry, if there is not enough space to hold the
7279 * FID-in-dirent, just keep them there. It only happens when the
7280 * device upgraded from 1.8 or restored from MDT file-level backup.
7281 * For the whole directory, only dotdot entry have no FID-in-dirent
7282 * and needs to get FID from LMA when readdir, it will not affect the
7285 if (dotdot && !osd_dotdot_has_space(de)) {
7286 *attr |= LUDA_UNKNOWN;
7292 if (lu_fid_eq(fid, &lma->lma_self_fid))
7295 if (unlikely(lma->lma_compat & LMAC_NOT_IN_OI)) {
7296 struct lu_fid *tfid = &lma->lma_self_fid;
7298 if (likely(dotdot &&
7299 fid_seq(tfid) == FID_SEQ_LOCAL_FILE &&
7300 fid_oid(tfid) == REMOTE_PARENT_DIR_OID)) {
7302 * It must be REMOTE_PARENT_DIR and as the
7303 * 'dotdot' entry of remote directory
7305 *attr |= LUDA_IGNORE;
7307 CDEBUG(D_LFSCK, "%s: expect remote agent "
7308 "parent directory, but got %.*s under "
7309 "dir = %lu/%u with the FID "DFID"\n",
7310 devname, ent->oied_namelen,
7311 ent->oied_name, dir->i_ino,
7312 dir->i_generation, PFID(tfid));
7314 *attr |= LUDA_UNKNOWN;
7321 if (!fid_is_zero(fid)) {
7322 rc = osd_verify_ent_by_linkea(env, inode, pfid, ent->oied_name,
7324 if (rc == -ENOENT ||
7326 !(dev->od_scrub.os_scrub.os_file.sf_flags & SF_UPGRADE))) {
7328 * linkEA does not recognize the dirent entry,
7329 * it may because the dirent entry corruption
7330 * and points to other's inode.
7332 CDEBUG(D_LFSCK, "%s: the target inode does not "
7333 "recognize the dirent, dir = %lu/%u, "
7334 " name = %.*s, ino = %llu, "
7335 DFID": rc = %d\n", devname, dir->i_ino,
7336 dir->i_generation, ent->oied_namelen,
7337 ent->oied_name, ent->oied_ino, PFID(fid), rc);
7338 *attr |= LUDA_UNKNOWN;
7343 if (rc && rc != -ENODATA) {
7344 CDEBUG(D_LFSCK, "%s: fail to verify FID in the dirent, "
7345 "dir = %lu/%u, name = %.*s, ino = %llu, "
7346 DFID": rc = %d\n", devname, dir->i_ino,
7347 dir->i_generation, ent->oied_namelen,
7348 ent->oied_name, ent->oied_ino, PFID(fid), rc);
7349 *attr |= LUDA_UNKNOWN;
7357 * linkEA recognizes the dirent entry, the FID-in-LMA is
7358 * valid, trusted, in spite of fid_is_sane(fid) or not.
7360 if (*attr & LUDA_VERIFY_DRYRUN) {
7361 *fid = lma->lma_self_fid;
7362 *attr |= LUDA_REPAIR;
7369 dev->od_dirent_journal = 1;
7370 if (hlock != NULL) {
7371 ldiskfs_htree_unlock(hlock);
7374 up_read(&obj->oo_ext_idx_sem);
7380 *fid = lma->lma_self_fid;
7382 /* Update or append the FID-in-dirent. */
7383 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
7384 bh, de, hlock, dotdot);
7386 *attr |= LUDA_REPAIR;
7388 CDEBUG(D_LFSCK, "%s: fail to re-insert FID after "
7389 "the dirent, dir = %lu/%u, name = %.*s, "
7390 "ino = %llu, "DFID": rc = %d\n",
7391 devname, dir->i_ino, dir->i_generation,
7392 ent->oied_namelen, ent->oied_name,
7393 ent->oied_ino, PFID(fid), rc);
7395 /* lma is NULL, trust the FID-in-dirent if it is valid. */
7396 if (*attr & LUDA_VERIFY_DRYRUN) {
7397 if (fid_is_sane(fid)) {
7398 *attr |= LUDA_REPAIR;
7399 } else if (dev->od_index == 0) {
7400 lu_igif_build(fid, inode->i_ino,
7401 inode->i_generation);
7402 *attr |= LUDA_UPGRADE;
7410 dev->od_dirent_journal = 1;
7411 if (hlock != NULL) {
7412 ldiskfs_htree_unlock(hlock);
7415 up_read(&obj->oo_ext_idx_sem);
7422 if (unlikely(fid_is_sane(fid))) {
7424 * FID-in-dirent exists, but FID-in-LMA is lost.
7425 * Trust the FID-in-dirent, and add FID-in-LMA.
7427 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
7429 *attr |= LUDA_REPAIR;
7431 CDEBUG(D_LFSCK, "%s: fail to set LMA for "
7432 "update dirent, dir = %lu/%u, "
7433 "name = %.*s, ino = %llu, "
7435 devname, dir->i_ino, dir->i_generation,
7436 ent->oied_namelen, ent->oied_name,
7437 ent->oied_ino, PFID(fid), rc);
7438 } else if (dev->od_index == 0) {
7439 lu_igif_build(fid, inode->i_ino, inode->i_generation);
7441 * It is probably IGIF object. Only aappend the
7442 * FID-in-dirent. OI scrub will process FID-in-LMA.
7444 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
7445 bh, de, hlock, dotdot);
7447 *attr |= LUDA_UPGRADE;
7449 CDEBUG(D_LFSCK, "%s: fail to append IGIF "
7450 "after the dirent, dir = %lu/%u, "
7451 "name = %.*s, ino = %llu, "
7453 devname, dir->i_ino, dir->i_generation,
7454 ent->oied_namelen, ent->oied_name,
7455 ent->oied_ino, PFID(fid), rc);
7464 if (hlock != NULL) {
7465 ldiskfs_htree_unlock(hlock);
7467 if (dev->od_dirent_journal != 0)
7468 up_write(&obj->oo_ext_idx_sem);
7470 up_read(&obj->oo_ext_idx_sem);
7474 ldiskfs_journal_stop(jh);
7478 if (rc >= 0 && !dirty)
7479 dev->od_dirent_journal = 0;
7480 if (ln.ln_name != ent->oied_name)
7487 * Returns the value at current position from iterator's in memory structure.
7489 * \param di struct osd_it_ea, iterator's in memory structure
7490 * \param attr attr requested for dirent.
7491 * \param lde lustre dirent
7493 * \retval 0 no error and \param lde has correct lustre dirent.
7494 * \retval -ve on error
7496 static inline int osd_it_ea_rec(const struct lu_env *env,
7497 const struct dt_it *di,
7498 struct dt_rec *dtrec, __u32 attr)
7500 struct osd_it_ea *it = (struct osd_it_ea *)di;
7501 struct osd_object *obj = it->oie_obj;
7502 struct osd_device *dev = osd_obj2dev(obj);
7503 struct osd_thread_info *oti = osd_oti_get(env);
7504 struct osd_inode_id *id = &oti->oti_id;
7505 struct lu_fid *fid = &it->oie_dirent->oied_fid;
7506 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
7507 __u32 ino = it->oie_dirent->oied_ino;
7512 LASSERT(!is_remote_parent_ino(dev, obj->oo_inode->i_ino));
7514 if (attr & LUDA_VERIFY) {
7515 if (unlikely(is_remote_parent_ino(dev, ino))) {
7516 attr |= LUDA_IGNORE;
7518 * If the parent is on remote MDT, and there
7519 * is no FID-in-dirent, then we have to get
7520 * the parent FID from the linkEA.
7522 if (!fid_is_sane(fid) &&
7523 it->oie_dirent->oied_namelen == 2 &&
7524 it->oie_dirent->oied_name[0] == '.' &&
7525 it->oie_dirent->oied_name[1] == '.')
7526 osd_get_pfid_from_linkea(env, obj, fid);
7528 rc = osd_dirent_check_repair(env, obj, it, fid, id,
7532 if (!fid_is_sane(fid))
7533 attr |= LUDA_UNKNOWN;
7535 attr &= ~LU_DIRENT_ATTRS_MASK;
7536 if (!fid_is_sane(fid)) {
7537 bool is_dotdot = false;
7539 if (it->oie_dirent->oied_namelen == 2 &&
7540 it->oie_dirent->oied_name[0] == '.' &&
7541 it->oie_dirent->oied_name[1] == '.')
7544 * If the parent is on remote MDT, and there
7545 * is no FID-in-dirent, then we have to get
7546 * the parent FID from the linkEA.
7548 if (is_remote_parent_ino(dev, ino) && is_dotdot) {
7549 rc = osd_get_pfid_from_linkea(env, obj, fid);
7551 if (is_dotdot == false &&
7552 OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
7555 rc = osd_ea_fid_get(env, obj, ino, fid, id);
7560 /* Pack the entry anyway, at least the offset is right. */
7561 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
7562 it->oie_dirent->oied_name,
7563 it->oie_dirent->oied_namelen,
7564 it->oie_dirent->oied_type, attr);
7566 RETURN(rc > 0 ? 0 : rc);
7570 * Returns the record size size at current position.
7572 * This function will return record(lu_dirent) size in bytes.
7574 * \param[in] env execution environment
7575 * \param[in] di iterator's in memory structure
7576 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
7577 * calculate the lu_dirent size.
7579 * \retval record size(in bytes & in memory) of the current lu_dirent
7582 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
7585 struct osd_it_ea *it = (struct osd_it_ea *)di;
7587 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
7591 * Returns a cookie for current position of the iterator head, so that
7592 * user can use this cookie to load/start the iterator next time.
7594 * \param di iterator's in memory structure
7596 * \retval cookie for current position, on success
7598 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
7600 struct osd_it_ea *it = (struct osd_it_ea *)di;
7602 return it->oie_dirent->oied_off;
7606 * It calls osd_ldiskfs_it_fill() which will use ->iterate*()
7607 * to load a directory entry at a time and stored it i inn,
7608 * in iterator's in-memory data structure.
7610 * \param di struct osd_it_ea, iterator's in memory structure
7612 * \retval +ve on success
7613 * \retval -ve on error
7615 static int osd_it_ea_load(const struct lu_env *env,
7616 const struct dt_it *di, __u64 hash)
7618 struct osd_it_ea *it = (struct osd_it_ea *)di;
7622 it->oie_file->f_pos = hash;
7624 rc = osd_ldiskfs_it_fill(env, di);
7635 * Index lookup function for interoperability mode (b11826).
7637 * \param key, key i.e. file name to be searched
7639 * \retval +ve, on success
7640 * \retval -ve, on error
7642 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
7643 struct dt_rec *rec, const struct dt_key *key)
7645 struct osd_object *obj = osd_dt_obj(dt);
7650 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
7651 LINVRNT(osd_invariant(obj));
7653 rc = osd_ea_lookup_rec(env, obj, rec, key);
7660 * Index and Iterator operations for interoperability
7661 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
7663 static const struct dt_index_operations osd_index_ea_ops = {
7664 .dio_lookup = osd_index_ea_lookup,
7665 .dio_declare_insert = osd_index_declare_ea_insert,
7666 .dio_insert = osd_index_ea_insert,
7667 .dio_declare_delete = osd_index_declare_ea_delete,
7668 .dio_delete = osd_index_ea_delete,
7670 .init = osd_it_ea_init,
7671 .fini = osd_it_ea_fini,
7672 .get = osd_it_ea_get,
7673 .put = osd_it_ea_put,
7674 .next = osd_it_ea_next,
7675 .key = osd_it_ea_key,
7676 .key_size = osd_it_ea_key_size,
7677 .rec = osd_it_ea_rec,
7678 .rec_size = osd_it_ea_rec_size,
7679 .store = osd_it_ea_store,
7680 .load = osd_it_ea_load
7684 static void *osd_key_init(const struct lu_context *ctx,
7685 struct lu_context_key *key)
7687 struct osd_thread_info *info;
7689 OBD_ALLOC_PTR(info);
7691 return ERR_PTR(-ENOMEM);
7693 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7694 if (info->oti_it_ea_buf == NULL)
7697 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
7699 info->oti_hlock = ldiskfs_htree_lock_alloc();
7700 if (info->oti_hlock == NULL)
7706 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7709 return ERR_PTR(-ENOMEM);
7712 static void osd_key_fini(const struct lu_context *ctx,
7713 struct lu_context_key *key, void *data)
7715 struct osd_thread_info *info = data;
7716 struct ldiskfs_inode_info *lli = LDISKFS_I(info->oti_inode);
7717 struct osd_idmap_cache *idc = info->oti_ins_cache;
7719 if (info->oti_dio_pages) {
7721 for (i = 0; i < PTLRPC_MAX_BRW_PAGES; i++) {
7722 struct page *page = info->oti_dio_pages[i];
7724 LASSERT(PagePrivate2(page));
7725 LASSERT(PageLocked(page));
7726 ClearPagePrivate2(page);
7731 OBD_FREE_PTR_ARRAY_LARGE(info->oti_dio_pages,
7732 PTLRPC_MAX_BRW_PAGES);
7735 if (info->oti_inode != NULL)
7737 if (info->oti_hlock != NULL)
7738 ldiskfs_htree_lock_free(info->oti_hlock);
7739 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7740 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
7741 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
7742 lu_buf_free(&info->oti_iobuf.dr_lnb_buf);
7743 lu_buf_free(&info->oti_big_buf);
7745 LASSERT(info->oti_ins_cache_size > 0);
7746 OBD_FREE_PTR_ARRAY_LARGE(idc, info->oti_ins_cache_size);
7747 info->oti_ins_cache = NULL;
7748 info->oti_ins_cache_size = 0;
7753 static void osd_key_exit(const struct lu_context *ctx,
7754 struct lu_context_key *key, void *data)
7756 struct osd_thread_info *info = data;
7758 LASSERT(info->oti_r_locks == 0);
7759 LASSERT(info->oti_w_locks == 0);
7760 LASSERT(info->oti_txns == 0);
7763 /* type constructor/destructor: osd_type_init, osd_type_fini */
7764 LU_TYPE_INIT_FINI(osd, &osd_key);
7766 struct lu_context_key osd_key = {
7767 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
7768 .lct_init = osd_key_init,
7769 .lct_fini = osd_key_fini,
7770 .lct_exit = osd_key_exit
7774 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
7775 const char *name, struct lu_device *next)
7777 struct osd_device *osd = osd_dev(d);
7779 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname)) >=
7780 sizeof(osd->od_svname))
7782 return osd_procfs_init(osd, name);
7785 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
7787 struct seq_server_site *ss = osd_seq_site(osd);
7792 if (osd->od_is_ost || osd->od_cl_seq != NULL)
7795 if (unlikely(ss == NULL))
7798 OBD_ALLOC_PTR(osd->od_cl_seq);
7799 if (osd->od_cl_seq == NULL)
7802 seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
7803 osd->od_svname, ss->ss_server_seq);
7805 if (ss->ss_node_id == 0) {
7807 * If the OSD on the sequence controller(MDT0), then allocate
7808 * sequence here, otherwise allocate sequence after connected
7809 * to MDT0 (see mdt_register_lwp_callback()).
7811 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
7812 &osd->od_cl_seq->lcs_space, env);
7818 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
7820 if (osd->od_cl_seq == NULL)
7823 seq_client_fini(osd->od_cl_seq);
7824 OBD_FREE_PTR(osd->od_cl_seq);
7825 osd->od_cl_seq = NULL;
7828 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
7832 /* shutdown quota slave instance associated with the device */
7833 if (o->od_quota_slave_md != NULL) {
7834 struct qsd_instance *qsd = o->od_quota_slave_md;
7836 o->od_quota_slave_md = NULL;
7840 if (o->od_quota_slave_dt != NULL) {
7841 struct qsd_instance *qsd = o->od_quota_slave_dt;
7843 o->od_quota_slave_dt = NULL;
7847 osd_fid_fini(env, o);
7848 osd_scrub_cleanup(env, o);
7853 static void osd_umount(const struct lu_env *env, struct osd_device *o)
7857 if (o->od_mnt != NULL) {
7858 shrink_dcache_sb(osd_sb(o));
7859 osd_sync(env, &o->od_dt_dev);
7860 wait_event(o->od_commit_cb_done,
7861 !atomic_read(&o->od_commit_cb_in_flight));
7870 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
7871 # ifndef LDISKFS_HAS_INCOMPAT_FEATURE
7872 /* Newer kernels provide the ldiskfs_set_feature_largedir() wrapper already,
7873 * which calls ldiskfs_update_dynamic_rev() to update ancient filesystems.
7874 * All ldiskfs filesystems are already v2, so it is a no-op and unnecessary.
7875 * This avoids maintaining patches to export this otherwise-useless function.
7877 void ldiskfs_update_dynamic_rev(struct super_block *sb)
7884 static int osd_mount(const struct lu_env *env,
7885 struct osd_device *o, struct lustre_cfg *cfg)
7887 const char *name = lustre_cfg_string(cfg, 0);
7888 const char *dev = lustre_cfg_string(cfg, 1);
7890 unsigned long page, s_flags = 0, lmd_flags = 0;
7891 struct page *__page;
7892 struct file_system_type *type;
7893 char *options = NULL;
7895 struct osd_thread_info *info = osd_oti_get(env);
7896 struct lu_fid *fid = &info->oti_fid;
7897 struct inode *inode;
7898 int rc = 0, force_over_1024tb = 0;
7902 if (o->od_mnt != NULL)
7905 if (strlen(dev) >= sizeof(o->od_mntdev))
7907 strcpy(o->od_mntdev, dev);
7909 str = lustre_cfg_buf(cfg, 2);
7910 sscanf(str, "%lu:%lu", &s_flags, &lmd_flags);
7912 opts = lustre_cfg_string(cfg, 3);
7914 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
7915 CERROR("%s: device %s extents feature is not guaranteed to "
7916 "work on big-endian systems. Use \"bigendian_extents\" "
7917 "mount option to override.\n", name, dev);
7921 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
7922 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) {
7923 CWARN("force_over_128tb option is deprecated. Filesystems smaller than 1024TB can be created without any force option. Use force_over_1024tb option for filesystems larger than 1024TB.\n");
7926 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 1, 53, 0)
7927 if (opts != NULL && strstr(opts, "force_over_256tb") != NULL) {
7928 CWARN("force_over_256tb option is deprecated. Filesystems smaller than 1024TB can be created without any force options. Use force_over_1024tb option for filesystems larger than 1024TB.\n");
7931 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
7932 if (opts != NULL && strstr(opts, "force_over_512tb") != NULL) {
7933 CWARN("force_over_512tb option is deprecated. Filesystems smaller than 1024TB can be created without any force options. Use force_over_1024tb option for filesystems larger than 1024TB.\n");
7937 if (opts != NULL && strstr(opts, "force_over_1024tb") != NULL)
7938 force_over_1024tb = 1;
7940 __page = alloc_page(GFP_KERNEL);
7942 GOTO(out, rc = -ENOMEM);
7943 page = (unsigned long)page_address(__page);
7944 options = (char *)page;
7947 /* strip out the options for back compatiblity */
7948 static const char * const sout[] = {
7955 /* strip out option we processed in osd */
7956 "bigendian_extents",
7960 "force_over_1024tb",
7964 strncat(options, opts, PAGE_SIZE);
7965 for (rc = 0, str = options; sout[rc]; ) {
7966 char *op = strstr(str, sout[rc]);
7973 if (op == options || *(op - 1) == ',') {
7974 str = op + strlen(sout[rc]);
7975 if (*str == ',' || *str == '\0') {
7976 *str == ',' ? str++ : str;
7977 memmove(op, str, strlen(str) + 1);
7980 for (str = op; *str != ',' && *str != '\0'; str++)
7984 strncat(options, "user_xattr,acl", PAGE_SIZE);
7987 /* Glom up mount options */
7988 if (*options != '\0')
7989 strncat(options, ",", PAGE_SIZE);
7990 strncat(options, "no_mbcache,nodelalloc", PAGE_SIZE);
7992 type = get_fs_type("ldiskfs");
7994 CERROR("%s: cannot find ldiskfs module\n", name);
7995 GOTO(out, rc = -ENODEV);
7998 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
7999 module_put(type->owner);
8001 if (IS_ERR(o->od_mnt)) {
8002 rc = PTR_ERR(o->od_mnt);
8004 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
8008 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) <<
8009 osd_sb(o)->s_blocksize_bits > 1024ULL << 40 &&
8010 force_over_1024tb == 0) {
8011 CERROR("%s: device %s LDISKFS has not been tested on filesystems larger than 1024TB and may cause data corruption. Use 'force_over_1024tb' mount option to override.\n",
8013 GOTO(out_mnt, rc = -EINVAL);
8016 if (lmd_flags & LMD_FLG_DEV_RDONLY) {
8017 LCONSOLE_WARN("%s: not support dev_rdonly on this device\n",
8020 GOTO(out_mnt, rc = -EOPNOTSUPP);
8023 if (!ldiskfs_has_feature_journal(o->od_mnt->mnt_sb)) {
8024 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
8025 GOTO(out_mnt, rc = -EINVAL);
8028 if (ldiskfs_has_feature_fast_commit(o->od_mnt->mnt_sb)) {
8029 CERROR("%s: device %s is mounted with fast_commit that breaks recovery\n",
8031 GOTO(out_mnt, rc = -EOPNOTSUPP);
8034 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
8035 #ifdef LDISKFS_MOUNT_DIRDATA
8036 if (ldiskfs_has_feature_dirdata(o->od_mnt->mnt_sb))
8037 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
8038 else if (strstr(name, "MDT")) /* don't complain for MGT or OSTs */
8039 CWARN("%s: device %s was upgraded from Lustre-1.x without "
8040 "enabling the dirdata feature. If you do not want to "
8041 "downgrade to Lustre-1.x again, you can enable it via "
8042 "'tune2fs -O dirdata device'\n", name, dev);
8044 /* enable large_dir on MDTs to avoid REMOTE_PARENT_DIR overflow,
8045 * and on very large OSTs to avoid object directory overflow */
8046 if (unlikely(!ldiskfs_has_feature_largedir(o->od_mnt->mnt_sb) &&
8047 !strstr(name, "MGS"))) {
8048 ldiskfs_set_feature_largedir(o->od_mnt->mnt_sb);
8049 LCONSOLE_INFO("%s: enabled 'large_dir' feature on device %s\n",
8053 inode = osd_sb(o)->s_root->d_inode;
8054 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
8055 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
8057 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
8061 if (lmd_flags & LMD_FLG_NOSCRUB)
8062 o->od_scrub.os_scrub.os_auto_scrub_interval = AS_NEVER;
8064 if (blk_queue_nonrot(bdev_get_queue(osd_sb(o)->s_bdev))) {
8065 /* do not use pagecache with flash-backed storage */
8066 o->od_writethrough_cache = 0;
8067 o->od_read_cache = 0;
8078 __free_page(__page);
8083 static struct lu_device *osd_device_fini(const struct lu_env *env,
8084 struct lu_device *d)
8086 struct osd_device *o = osd_dev(d);
8090 osd_index_backup(env, o, false);
8091 osd_shutdown(env, o);
8093 if (o->od_oi_table != NULL)
8094 osd_oi_fini(osd_oti_get(env), o);
8095 if (o->od_extent_bytes_percpu)
8096 free_percpu(o->od_extent_bytes_percpu);
8097 osd_obj_map_fini(o);
8103 static int osd_device_init0(const struct lu_env *env,
8104 struct osd_device *o,
8105 struct lustre_cfg *cfg)
8107 struct lu_device *l = osd2lu_dev(o);
8108 struct osd_thread_info *info;
8111 bool restored = false;
8114 /* if the module was re-loaded, env can loose its keys */
8115 rc = lu_env_refill((struct lu_env *)env);
8118 info = osd_oti_get(env);
8121 l->ld_ops = &osd_lu_ops;
8122 o->od_dt_dev.dd_ops = &osd_dt_ops;
8124 spin_lock_init(&o->od_osfs_lock);
8125 mutex_init(&o->od_otable_mutex);
8126 INIT_LIST_HEAD(&o->od_orphan_list);
8127 INIT_LIST_HEAD(&o->od_index_backup_list);
8128 INIT_LIST_HEAD(&o->od_index_restore_list);
8129 spin_lock_init(&o->od_lock);
8130 o->od_index_backup_policy = LIBP_NONE;
8132 init_waitqueue_head(&o->od_commit_cb_done);
8134 o->od_read_cache = 1;
8135 o->od_writethrough_cache = 1;
8136 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
8137 o->od_readcache_max_iosize = OSD_READCACHE_MAX_IO_MB << 20;
8138 o->od_writethrough_max_iosize = OSD_WRITECACHE_MAX_IO_MB << 20;
8139 o->od_scrub.os_scrub.os_auto_scrub_interval = AS_DEFAULT;
8140 /* default fallocate to unwritten extents: LU-14326/LU-14333 */
8141 o->od_fallocate_zero_blocks = 0;
8143 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
8144 sizeof(o->od_svname));
8145 if (cplen >= sizeof(o->od_svname)) {
8150 o->od_index_backup_stop = 0;
8151 o->od_index = -1; /* -1 means index is invalid */
8152 rc = server_name2index(o->od_svname, &o->od_index, NULL);
8153 if (rc == LDD_F_SV_TYPE_OST)
8156 o->od_full_scrub_ratio = OFSR_DEFAULT;
8157 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
8158 rc = osd_mount(env, o, cfg);
8162 /* Can only check block device after mount */
8163 o->od_nonrotational =
8164 blk_queue_nonrot(bdev_get_queue(osd_sb(o)->s_bdev));
8166 rc = osd_obj_map_init(env, o);
8170 rc = lu_site_init(&o->od_site, l);
8172 GOTO(out_compat, rc);
8173 o->od_site.ls_bottom_dev = l;
8175 rc = lu_site_init_finish(&o->od_site);
8179 opts = lustre_cfg_string(cfg, 3);
8180 if (opts && strstr(opts, "resetoi"))
8183 INIT_LIST_HEAD(&o->od_ios_list);
8185 rc = lprocfs_init_brw_stats(&o->od_brw_stats);
8187 GOTO(out_brw_stats, rc);
8189 /* setup scrub, including OI files initialization */
8191 rc = osd_scrub_setup(env, o, restored);
8194 GOTO(out_brw_stats, rc);
8196 rc = osd_procfs_init(o, o->od_svname);
8198 CERROR("%s: can't initialize procfs: rc = %d\n",
8200 GOTO(out_scrub, rc);
8203 LASSERT(l->ld_site->ls_linkage.next != NULL);
8204 LASSERT(l->ld_site->ls_linkage.prev != NULL);
8206 /* initialize quota slave instance */
8207 /* currently it's no need to prepare qsd_instance_md for OST */
8208 if (!o->od_is_ost) {
8209 o->od_quota_slave_md = qsd_init(env, o->od_svname,
8210 &o->od_dt_dev, o->od_proc_entry,
8212 if (IS_ERR(o->od_quota_slave_md)) {
8213 rc = PTR_ERR(o->od_quota_slave_md);
8214 o->od_quota_slave_md = NULL;
8215 GOTO(out_procfs, rc);
8219 o->od_quota_slave_dt = qsd_init(env, o->od_svname, &o->od_dt_dev,
8220 o->od_proc_entry, false, true);
8222 if (IS_ERR(o->od_quota_slave_dt)) {
8223 if (o->od_quota_slave_md != NULL) {
8224 qsd_fini(env, o->od_quota_slave_md);
8225 o->od_quota_slave_md = NULL;
8228 rc = PTR_ERR(o->od_quota_slave_dt);
8229 o->od_quota_slave_dt = NULL;
8230 GOTO(out_procfs, rc);
8233 o->od_extent_bytes_percpu = alloc_percpu(unsigned int);
8234 if (!o->od_extent_bytes_percpu) {
8236 GOTO(out_procfs, rc);
8244 osd_scrub_cleanup(env, o);
8246 lprocfs_fini_brw_stats(&o->od_brw_stats);
8248 lu_site_fini(&o->od_site);
8250 osd_obj_map_fini(o);
8257 static struct lu_device *osd_device_alloc(const struct lu_env *env,
8258 struct lu_device_type *t,
8259 struct lustre_cfg *cfg)
8261 struct osd_device *o;
8266 return ERR_PTR(-ENOMEM);
8268 rc = dt_device_init(&o->od_dt_dev, t);
8271 * Because the ctx might be revived in dt_device_init,
8272 * refill the env here
8274 lu_env_refill((struct lu_env *)env);
8275 rc = osd_device_init0(env, o, cfg);
8277 dt_device_fini(&o->od_dt_dev);
8280 if (unlikely(rc != 0))
8283 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
8286 static struct lu_device *osd_device_free(const struct lu_env *env,
8287 struct lu_device *d)
8289 struct osd_device *o = osd_dev(d);
8293 /* XXX: make osd top device in order to release reference */
8294 d->ld_site->ls_top_dev = d;
8295 lu_site_purge(env, d->ld_site, -1);
8296 lu_site_print(env, d->ld_site, &d->ld_site->ls_obj_hash.nelems,
8297 D_ERROR, lu_cdebug_printer);
8298 lu_site_fini(&o->od_site);
8299 dt_device_fini(&o->od_dt_dev);
8304 static int osd_process_config(const struct lu_env *env,
8305 struct lu_device *d, struct lustre_cfg *cfg)
8307 struct osd_device *o = osd_dev(d);
8313 switch (cfg->lcfg_command) {
8315 rc = osd_mount(env, o, cfg);
8319 * For the case LCFG_PRE_CLEANUP is not called in advance,
8320 * that may happend if hit failure during mount process.
8322 osd_index_backup(env, o, false);
8323 lu_dev_del_linkage(d->ld_site, d);
8324 rc = osd_shutdown(env, o);
8327 LASSERT(&o->od_dt_dev);
8328 count = class_modify_config(cfg, PARAM_OSD,
8329 &o->od_dt_dev.dd_kobj);
8331 count = class_modify_config(cfg, PARAM_OST,
8332 &o->od_dt_dev.dd_kobj);
8333 rc = count > 0 ? 0 : count;
8335 case LCFG_PRE_CLEANUP:
8337 osd_index_backup(env, o,
8338 o->od_index_backup_policy != LIBP_NONE);
8348 static int osd_recovery_complete(const struct lu_env *env,
8349 struct lu_device *d)
8351 struct osd_device *osd = osd_dev(d);
8356 if (osd->od_quota_slave_md == NULL && osd->od_quota_slave_dt == NULL)
8360 * start qsd instance on recovery completion, this notifies the quota
8361 * slave code that we are about to process new requests now
8363 rc = qsd_start(env, osd->od_quota_slave_dt);
8364 if (rc == 0 && osd->od_quota_slave_md != NULL)
8365 rc = qsd_start(env, osd->od_quota_slave_md);
8371 * we use exports to track all osd users
8373 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
8374 struct obd_device *obd, struct obd_uuid *cluuid,
8375 struct obd_connect_data *data, void *localdata)
8377 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8378 struct lustre_handle conn;
8383 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
8385 rc = class_connect(&conn, obd, cluuid);
8389 *exp = class_conn2export(&conn);
8391 spin_lock(&osd->od_osfs_lock);
8393 spin_unlock(&osd->od_osfs_lock);
8399 * once last export (we don't count self-export) disappeared
8400 * osd can be released
8402 static int osd_obd_disconnect(struct obd_export *exp)
8404 struct obd_device *obd = exp->exp_obd;
8405 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8406 int rc, release = 0;
8410 /* Only disconnect the underlying layers on the final disconnect. */
8411 spin_lock(&osd->od_osfs_lock);
8413 if (osd->od_connects == 0)
8415 spin_unlock(&osd->od_osfs_lock);
8417 rc = class_disconnect(exp); /* bz 9811 */
8419 if (rc == 0 && release)
8420 class_manual_cleanup(obd);
8424 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
8425 struct lu_device *dev)
8427 struct osd_device *osd = osd_dev(dev);
8428 struct lr_server_data *lsd =
8429 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
8434 if (osd->od_quota_slave_md != NULL) {
8435 /* set up quota slave objects for inode */
8436 result = qsd_prepare(env, osd->od_quota_slave_md);
8441 if (osd->od_quota_slave_dt != NULL) {
8442 /* set up quota slave objects for block */
8443 result = qsd_prepare(env, osd->od_quota_slave_dt);
8449 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
8450 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
8451 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
8452 osd->od_index_in_idif = 1;
8454 osd->od_index_in_idif = 0;
8455 result = osd_register_proc_index_in_idif(osd);
8460 osd->od_index_in_idif = 1;
8464 result = osd_fid_init(env, osd);
8470 * Implementation of lu_device_operations::ldo_fid_alloc() for OSD
8474 * see include/lu_object.h for the details.
8476 static int osd_fid_alloc(const struct lu_env *env, struct lu_device *d,
8477 struct lu_fid *fid, struct lu_object *parent,
8478 const struct lu_name *name)
8480 struct osd_device *osd = osd_dev(d);
8482 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
8485 static const struct lu_object_operations osd_lu_obj_ops = {
8486 .loo_object_init = osd_object_init,
8487 .loo_object_delete = osd_object_delete,
8488 .loo_object_release = osd_object_release,
8489 .loo_object_free = osd_object_free,
8490 .loo_object_print = osd_object_print,
8491 .loo_object_invariant = osd_object_invariant
8494 const struct lu_device_operations osd_lu_ops = {
8495 .ldo_object_alloc = osd_object_alloc,
8496 .ldo_process_config = osd_process_config,
8497 .ldo_recovery_complete = osd_recovery_complete,
8498 .ldo_prepare = osd_prepare,
8499 .ldo_fid_alloc = osd_fid_alloc,
8502 static const struct lu_device_type_operations osd_device_type_ops = {
8503 .ldto_init = osd_type_init,
8504 .ldto_fini = osd_type_fini,
8506 .ldto_start = osd_type_start,
8507 .ldto_stop = osd_type_stop,
8509 .ldto_device_alloc = osd_device_alloc,
8510 .ldto_device_free = osd_device_free,
8512 .ldto_device_init = osd_device_init,
8513 .ldto_device_fini = osd_device_fini
8516 static struct lu_device_type osd_device_type = {
8517 .ldt_tags = LU_DEVICE_DT,
8518 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
8519 .ldt_ops = &osd_device_type_ops,
8520 .ldt_ctx_tags = LCT_LOCAL,
8523 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
8525 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8526 struct super_block *sb = osd_sb(osd);
8528 return (osd->od_mnt == NULL || sb->s_flags & SB_RDONLY);
8532 * lprocfs legacy support.
8534 static const struct obd_ops osd_obd_device_ops = {
8535 .o_owner = THIS_MODULE,
8536 .o_connect = osd_obd_connect,
8537 .o_disconnect = osd_obd_disconnect,
8538 .o_health_check = osd_health_check,
8541 static ssize_t track_declares_assert_show(struct kobject *kobj,
8542 struct attribute *attr,
8545 return sprintf(buf, "%d\n", ldiskfs_track_declares_assert);
8548 static ssize_t track_declares_assert_store(struct kobject *kobj,
8549 struct attribute *attr,
8550 const char *buffer, size_t count)
8552 bool track_declares_assert;
8555 rc = kstrtobool(buffer, &track_declares_assert);
8559 ldiskfs_track_declares_assert = track_declares_assert;
8563 LUSTRE_RW_ATTR(track_declares_assert);
8565 static int __init osd_init(void)
8567 struct kobject *kobj;
8570 BUILD_BUG_ON(BH_DXLock >=
8571 sizeof(((struct buffer_head *)0)->b_state) * 8);
8572 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
8573 /* please, try to keep osd_thread_info smaller than a page */
8574 BUILD_BUG_ON(sizeof(struct osd_thread_info) > PAGE_SIZE);
8579 rc = lu_kmem_init(ldiskfs_caches);
8583 rc = class_register_type(&osd_obd_device_ops, NULL, true,
8584 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
8586 lu_kmem_fini(ldiskfs_caches);
8590 kobj = kset_find_obj(lustre_kset, LUSTRE_OSD_LDISKFS_NAME);
8592 rc = sysfs_create_file(kobj,
8593 &lustre_attr_track_declares_assert.attr);
8596 CWARN("osd-ldiskfs: track_declares_assert failed to register with sysfs\n");
8604 static void __exit osd_exit(void)
8606 struct kobject *kobj;
8608 kobj = kset_find_obj(lustre_kset, LUSTRE_OSD_LDISKFS_NAME);
8610 sysfs_remove_file(kobj,
8611 &lustre_attr_track_declares_assert.attr);
8614 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
8615 lu_kmem_fini(ldiskfs_caches);
8618 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
8619 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
8620 MODULE_VERSION(LUSTRE_VERSION_STRING);
8621 MODULE_LICENSE("GPL");
8623 module_init(osd_init);
8624 module_exit(osd_exit);