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)) {
520 CWARN("%s: bad inode: ino = %u: rc = %d\n",
521 osd_dev2name(dev), id->oii_ino, -ENOENT);
523 inode = ERR_PTR(-ENOENT);
524 } else if (osd_is_ea_inode(inode)) {
526 * EA inode is internal ldiskfs object, should don't visible
529 CDEBUG(D_INODE, "EA inode: ino = %u\n", id->oii_ino);
531 inode = ERR_PTR(-ENOENT);
532 } else if ((rc = osd_attach_jinode(inode))) {
536 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
537 if (id->oii_gen == OSD_OII_NOGEN)
538 osd_id_gen(id, inode->i_ino, inode->i_generation);
541 * Do not update file c/mtime in ldiskfs.
542 * NB: we don't have any lock to protect this because we don't
543 * have reference on osd_object now, but contention with
544 * another lookup + attr_set can't happen in the tiny window
545 * between if (...) and set S_NOCMTIME.
547 if (!(inode->i_flags & S_NOCMTIME))
548 inode->i_flags |= S_NOCMTIME;
553 int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd,
554 handle_t *handle, struct dentry *child,
555 struct inode *inode, struct htree_lock *hlock)
559 rc = __ldiskfs_add_entry(handle, child, inode, hlock);
560 if (rc == -ENOBUFS || rc == -ENOSPC) {
561 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
562 struct inode *parent = child->d_parent->d_inode;
563 struct lu_fid *fid = NULL;
564 char fidstr[FID_LEN + 1] = "unknown";
566 rc2 = osd_get_lma(info, parent, child->d_parent, loa);
568 fid = &loa->loa_lma.lma_self_fid;
569 } else if (rc2 == -ENODATA) {
570 if (unlikely(is_root_inode(parent))) {
571 fid = &info->oti_fid3;
572 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
573 } else if (!osd->od_is_ost && osd->od_index == 0) {
574 fid = &info->oti_fid3;
575 lu_igif_build(fid, parent->i_ino,
576 parent->i_generation);
581 snprintf(fidstr, sizeof(fidstr), DFID, PFID(fid));
583 /* below message is checked in sanity.sh test_129 */
585 CWARN("%s: directory (inode: %lu, FID: %s) has reached max size limit\n",
586 osd_name(osd), parent->i_ino, fidstr);
588 rc = 0; /* ignore such error now */
589 CWARN("%s: directory (inode: %lu, FID: %s) is approaching max size limit\n",
590 osd_name(osd), parent->i_ino, fidstr);
600 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
601 struct osd_inode_id *id, struct lu_fid *fid)
603 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
607 inode = osd_iget(info, dev, id);
611 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
613 *fid = loa->loa_lma.lma_self_fid;
614 } else if (rc == -ENODATA) {
615 if (unlikely(is_root_inode(inode)))
616 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
618 lu_igif_build(fid, inode->i_ino, inode->i_generation);
626 static struct inode *osd_iget_check(struct osd_thread_info *info,
627 struct osd_device *dev,
628 const struct lu_fid *fid,
629 struct osd_inode_id *id,
638 * The cached OI mapping is trustable. If we cannot locate the inode
639 * via the cached OI mapping, then return the failure to the caller
640 * directly without further OI checking.
644 inode = osd_iget(info, dev, id);
647 if (!trusted && (rc == -ENOENT || rc == -ESTALE))
650 CDEBUG(D_INODE, "no inode for FID: "DFID", ino = %u, rc = %d\n",
651 PFID(fid), id->oii_ino, rc);
657 __u32 saved_ino = id->oii_ino;
658 __u32 saved_gen = id->oii_gen;
661 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
663 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
665 * XXX: There are four possible cases:
667 * Backup/restore caused the OI invalid.
669 * Someone unlinked the object but NOT removed
670 * the OI mapping, such as mount target device
671 * as ldiskfs, and modify something directly.
673 * Someone just removed the object between the
674 * former oi_lookup and the iget. It is normal.
675 * 4. Other failure cases.
677 * Generally, when the device is mounted, it will
678 * auto check whether the system is restored from
679 * file-level backup or not. We trust such detect
680 * to distinguish the 1st case from the 2nd case:
681 * if the OI files are consistent but may contain
682 * stale OI mappings because of case 2, if iget()
683 * returns -ENOENT or -ESTALE, then it should be
688 * If the OI mapping was in OI file before the
689 * osd_iget_check(), but now, it is disappear,
690 * then it must be removed by race. That is a
696 * It is the OI scrub updated the OI mapping by race.
697 * The new OI mapping must be valid.
699 if (saved_ino != id->oii_ino ||
700 (saved_gen != id->oii_gen && saved_gen != OSD_OII_NOGEN)) {
709 if (dev->od_scrub.os_scrub.os_file.sf_flags &
712 * It still can be the case 2, but we cannot
713 * distinguish it from the case 1. So return
714 * -EREMCHG to block current operation until
715 * OI scrub rebuilt the OI mappings.
724 if (inode->i_generation == id->oii_gen)
744 * \retval +v: new filter_fid does not contain self-fid
745 * \retval 0: filter_fid_18_23, contains self-fid
746 * \retval -v: other failure cases
748 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
749 struct dentry *dentry, struct lu_fid *fid)
751 struct filter_fid *ff = &info->oti_ff;
752 struct ost_id *ostid = &info->oti_ostid;
755 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
756 if (rc == sizeof(struct filter_fid_18_23)) {
757 struct filter_fid_18_23 *ff_old = (void *)ff;
759 ostid_set_seq(ostid, le64_to_cpu(ff_old->ff_seq));
760 rc = ostid_set_id(ostid, le64_to_cpu(ff_old->ff_objid));
762 * XXX: use 0 as the index for compatibility, the caller will
763 * handle index related issues when necessary.
766 ostid_to_fid(fid, ostid, 0);
767 } else if (rc >= (int)sizeof(struct filter_fid_24_29)) {
769 } else if (rc >= 0) {
776 static int osd_lma_self_repair(struct osd_thread_info *info,
777 struct osd_device *osd, struct inode *inode,
778 const struct lu_fid *fid, __u32 compat)
783 LASSERT(current->journal_info == NULL);
785 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
786 osd_dto_credits_noquota[DTO_XATTR_SET]);
789 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
794 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
796 CWARN("%s: cannot self repair the LMA: rc = %d\n",
798 ldiskfs_journal_stop(jh);
802 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
804 struct osd_thread_info *info = osd_oti_get(env);
805 struct osd_device *osd = osd_obj2dev(obj);
806 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
807 struct lustre_mdt_attrs *lma = &loa->loa_lma;
808 struct inode *inode = obj->oo_inode;
809 struct dentry *dentry = &info->oti_obj_dentry;
810 struct lu_fid *fid = NULL;
811 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
816 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
817 (void *)loa, sizeof(*loa));
818 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
819 fid = &lma->lma_self_fid;
820 rc = osd_get_idif(info, inode, dentry, fid);
821 if (rc > 0 || (rc == -ENODATA && osd->od_index_in_idif)) {
823 * For the given OST-object, if it has neither LMA nor
824 * FID in XATTR_NAME_FID, then the given FID (which is
825 * contained in the @obj, from client RPC for locating
826 * the OST-object) is trusted. We use it to generate
829 osd_lma_self_repair(info, osd, inode, rfid,
840 lustre_lma_swab(lma);
841 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
842 (CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT) &&
843 S_ISREG(inode->i_mode)))) {
844 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
845 "fid = "DFID", ino = %lu\n", osd_name(osd),
846 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
847 PFID(rfid), inode->i_ino);
850 fid = &lma->lma_self_fid;
851 if (lma->lma_compat & LMAC_STRIPE_INFO &&
853 obj->oo_pfid_in_lma = 1;
854 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
856 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
860 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
861 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
862 struct ost_id *oi = &info->oti_ostid;
863 struct lu_fid *fid1 = &info->oti_fid3;
864 __u32 idx = fid_idif_ost_idx(rfid);
867 * For old IDIF, the OST index is not part of the IDIF,
868 * Means that different OSTs may have the same IDIFs.
869 * Under such case, we need to make some compatible
870 * check to make sure to trigger OI scrub properly.
872 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
873 /* Given @rfid is new, LMA is old. */
874 fid_to_ostid(fid, oi);
875 ostid_to_fid(fid1, oi, idx);
876 if (lu_fid_eq(fid1, rfid)) {
877 if (osd->od_index_in_idif)
878 osd_lma_self_repair(info, osd,
892 struct osd_check_lmv_buf {
893 /* please keep it as first member */
894 struct dir_context ctx;
895 struct osd_thread_info *oclb_info;
896 struct osd_device *oclb_dev;
902 * It is called internally by ->iterate*() to filter out the
903 * local slave object's FID of the striped directory.
905 * \retval 1 found the local slave's FID
906 * \retval 0 continue to check next item
907 * \retval -ve for failure
909 #ifdef HAVE_FILLDIR_USE_CTX
910 static int osd_stripe_dir_filldir(struct dir_context *buf,
912 static int osd_stripe_dir_filldir(void *buf,
914 const char *name, int namelen,
915 loff_t offset, __u64 ino, unsigned int d_type)
917 struct osd_check_lmv_buf *oclb = (struct osd_check_lmv_buf *)buf;
918 struct osd_thread_info *oti = oclb->oclb_info;
919 struct lu_fid *fid = &oti->oti_fid3;
920 struct osd_inode_id *id = &oti->oti_id3;
921 struct osd_device *dev = oclb->oclb_dev;
930 sscanf(name + 1, SFID, RFID(fid));
931 if (!fid_is_sane(fid))
934 if (osd_remote_fid(oti->oti_env, dev, fid))
937 osd_id_gen(id, ino, OSD_OII_NOGEN);
938 inode = osd_iget(oti, dev, id);
940 return PTR_ERR(inode);
943 osd_add_oi_cache(oti, dev, id, fid);
944 osd_oii_insert(dev, fid, id, true);
945 oclb->oclb_found = true;
951 * When lookup item under striped directory, we need to locate the master
952 * MDT-object of the striped directory firstly, then the client will send
953 * lookup (getattr_by_name) RPC to the MDT with some slave MDT-object's FID
954 * and the item's name. If the system is restored from MDT file level backup,
955 * then before the OI scrub completely built the OI files, the OI mappings of
956 * the master MDT-object and slave MDT-object may be invalid. Usually, it is
957 * not a problem for the master MDT-object. Because when locate the master
958 * MDT-object, we will do name based lookup (for the striped directory itself)
959 * firstly, during such process we can setup the correct OI mapping for the
960 * master MDT-object. But it will be trouble for the slave MDT-object. Because
961 * the client will not trigger name based lookup on the MDT to locate the slave
962 * MDT-object before locating item under the striped directory, then when
963 * osd_fid_lookup(), it will find that the OI mapping for the slave MDT-object
964 * is invalid and does not know what the right OI mapping is, then the MDT has
965 * to return -EINPROGRESS to the client to notify that the OI scrub is rebuiding
966 * the OI file, related OI mapping is unknown yet, please try again later. And
967 * then client will re-try the RPC again and again until related OI mapping has
968 * been updated. That is quite inefficient.
970 * To resolve above trouble, we will handle it as the following two cases:
972 * 1) The slave MDT-object and the master MDT-object are on different MDTs.
973 * It is relative easy. Be as one of remote MDT-objects, the slave MDT-object
974 * is linked under /REMOTE_PARENT_DIR with the name of its FID string.
975 * We can locate the slave MDT-object via lookup the /REMOTE_PARENT_DIR
976 * directly. Please check osd_fid_lookup().
978 * 2) The slave MDT-object and the master MDT-object reside on the same MDT.
979 * Under such case, during lookup the master MDT-object, we will lookup the
980 * slave MDT-object via readdir against the master MDT-object, because the
981 * slave MDT-objects information are stored as sub-directories with the name
982 * "${FID}:${index}". Then when find the local slave MDT-object, its OI
983 * mapping will be recorded. Then subsequent osd_fid_lookup() will know
984 * the correct OI mapping for the slave MDT-object.
986 static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev,
989 struct lu_buf *buf = &oti->oti_big_buf;
991 struct lmv_mds_md_v1 *lmv1;
992 struct osd_check_lmv_buf oclb = {
993 .ctx.actor = osd_stripe_dir_filldir,
1001 /* We should use the VFS layer to create a real dentry. */
1002 oti->oti_obj_dentry.d_inode = inode;
1003 oti->oti_obj_dentry.d_sb = inode->i_sb;
1005 filp = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
1010 filp->f_mode |= FMODE_64BITHASH;
1014 rc = __osd_xattr_get(inode, filp->f_path.dentry, XATTR_NAME_LMV,
1015 buf->lb_buf, buf->lb_len);
1016 if (rc == -ERANGE) {
1017 rc = __osd_xattr_get(inode, filp->f_path.dentry,
1018 XATTR_NAME_LMV, NULL, 0);
1020 lu_buf_realloc(buf, rc);
1021 if (buf->lb_buf == NULL)
1022 GOTO(out, rc = -ENOMEM);
1028 if (unlikely(rc == 0 || rc == -ENODATA))
1034 if (unlikely(buf->lb_buf == NULL)) {
1035 lu_buf_realloc(buf, rc);
1036 if (buf->lb_buf == NULL)
1037 GOTO(out, rc = -ENOMEM);
1043 if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
1047 oclb.oclb_items = 0;
1048 rc = iterate_dir(filp, &oclb.ctx);
1049 } while (rc >= 0 && oclb.oclb_items > 0 && !oclb.oclb_found &&
1050 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
1055 "%s: cannot check LMV, ino = %lu/%u: rc = %d\n",
1056 osd_ino2name(inode), inode->i_ino, inode->i_generation,
1064 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
1065 const struct lu_fid *fid,
1066 const struct lu_object_conf *conf)
1068 struct osd_thread_info *info;
1069 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
1070 struct osd_device *dev;
1071 struct osd_idmap_cache *oic;
1072 struct osd_inode_id *id;
1073 struct inode *inode = NULL;
1074 struct lustre_scrub *scrub;
1075 struct scrub_file *sf;
1076 __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT | SS_AUTO_FULL;
1081 bool remote = false;
1082 bool trusted = true;
1083 bool updated = false;
1084 bool checked = false;
1088 LINVRNT(osd_invariant(obj));
1089 LASSERT(obj->oo_inode == NULL);
1091 if (fid_is_sane(fid) == 0) {
1092 CERROR("%s: invalid FID "DFID"\n", ldev->ld_obd->obd_name,
1098 dev = osd_dev(ldev);
1099 scrub = &dev->od_scrub.os_scrub;
1100 sf = &scrub->os_file;
1101 info = osd_oti_get(env);
1103 oic = &info->oti_cache;
1105 if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
1109 * For the object is created as locking anchor, or for the object to
1110 * be created on disk. No need to osd_oi_lookup() at here because FID
1111 * shouldn't never be re-used, if it's really a duplicate FID from
1112 * unexpected reason, we should be able to detect it later by calling
1113 * do_create->osd_oi_insert().
1115 if (conf && conf->loc_flags & LOC_F_NEW)
1116 GOTO(out, result = 0);
1118 /* Search order: 1. per-thread cache. */
1119 if (lu_fid_eq(fid, &oic->oic_fid) && likely(oic->oic_dev == dev)) {
1125 memset(id, 0, sizeof(struct osd_inode_id));
1126 if (!list_empty(&scrub->os_inconsistent_items)) {
1127 /* Search order: 2. OI scrub pending list. */
1128 result = osd_oii_lookup(dev, fid, id);
1134 * The OI mapping in the OI file can be updated by the OI scrub
1135 * when we locate the inode via FID. So it may be not trustable.
1139 /* Search order: 3. OI files. */
1140 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1141 if (result == -ENOENT) {
1142 if (!fid_is_norm(fid) ||
1143 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
1144 !ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
1146 GOTO(out, result = 0);
1151 /* -ESTALE is returned if inode of OST object doesn't exist */
1152 if (result == -ESTALE &&
1153 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) {
1154 GOTO(out, result = 0);
1161 obj->oo_inode = NULL;
1162 /* for later passes through checks, not true on first pass */
1163 if (!IS_ERR_OR_NULL(inode))
1166 inode = osd_iget_check(info, dev, fid, id, trusted);
1167 if (!IS_ERR(inode)) {
1168 obj->oo_inode = inode;
1176 result = PTR_ERR(inode);
1177 if (result == -ENOENT || result == -ESTALE)
1178 GOTO(out, result = 0);
1180 if (result != -EREMCHG)
1185 * We still have chance to get the valid inode: for the
1186 * object which is referenced by remote name entry, the
1187 * object on the local MDT will be linked under the dir
1188 * of "/REMOTE_PARENT_DIR" with its FID string as name.
1190 * We do not know whether the object for the given FID
1191 * is referenced by some remote name entry or not, and
1192 * especially for DNE II, a multiple-linked object may
1193 * have many name entries reside on many MDTs.
1195 * To simplify the operation, OSD will not distinguish
1196 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
1197 * only happened for the RPC from other MDT during the
1198 * OI scrub, or for the client side RPC with FID only,
1199 * such as FID to path, or from old connected client.
1202 rc1 = osd_lookup_in_remote_parent(info, dev, fid, id);
1206 flags |= SS_AUTO_PARTIAL;
1207 flags &= ~SS_AUTO_FULL;
1212 if (scrub->os_running) {
1213 if (scrub->os_partial_scan && !scrub->os_in_join)
1216 if (IS_ERR_OR_NULL(inode) || result) {
1217 osd_oii_insert(dev, fid, id, result == -ENOENT);
1218 GOTO(out, result = -EINPROGRESS);
1222 LASSERT(obj->oo_inode == inode);
1224 osd_oii_insert(dev, fid, id, true);
1228 if (dev->od_scrub.os_scrub.os_auto_scrub_interval == AS_NEVER) {
1230 GOTO(out, result = -EREMCHG);
1233 LASSERT(obj->oo_inode == inode);
1235 osd_add_oi_cache(info, dev, id, fid);
1240 rc1 = osd_scrub_start(env, dev, flags);
1241 CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
1242 "%s: trigger OI scrub by RPC for "DFID"/%u with flags %#x: rc = %d\n",
1243 osd_name(dev), PFID(fid), id->oii_ino, flags, rc1);
1244 if (rc1 && rc1 != -EALREADY)
1245 GOTO(out, result = -EREMCHG);
1247 if (IS_ERR_OR_NULL(inode) || result) {
1248 osd_oii_insert(dev, fid, id, result == -ENOENT);
1249 GOTO(out, result = -EINPROGRESS);
1253 LASSERT(obj->oo_inode == inode);
1255 osd_oii_insert(dev, fid, id, true);
1260 if (unlikely(obj->oo_header))
1263 result = osd_check_lma(env, obj);
1267 LASSERTF(id->oii_ino == inode->i_ino &&
1268 id->oii_gen == inode->i_generation,
1269 "locate wrong inode for FID: "DFID", %u/%u => %ld/%u\n",
1270 PFID(fid), id->oii_ino, id->oii_gen,
1271 inode->i_ino, inode->i_generation);
1273 saved_ino = inode->i_ino;
1274 saved_gen = inode->i_generation;
1276 if (unlikely(result == -ENODATA)) {
1278 * If the OI scrub updated the OI mapping by race, it
1279 * must be valid. Trust the inode that has no LMA EA.
1284 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1287 * The OI mapping is still there, the inode is still
1288 * valid. It is just becaues the inode has no LMA EA.
1290 if (saved_ino == id->oii_ino &&
1291 saved_gen == id->oii_gen)
1295 * It is the OI scrub updated the OI mapping by race.
1296 * The new OI mapping must be valid.
1304 * "result == -ENOENT" means that the OI mappinghas been
1305 * removed by race, so the inode belongs to other object.
1307 * Others error can be returned directly.
1309 if (result == -ENOENT) {
1312 obj->oo_inode = NULL;
1317 if (result != -EREMCHG)
1323 * if two OST objects map to the same inode, and inode mode is
1324 * (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666), which means it's
1325 * reserved by precreate, and not written yet, in this case, don't
1326 * set inode for the object whose FID mismatch, so that it can create
1327 * inode and not block precreate.
1329 if (fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) &&
1330 inode->i_mode == (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666)) {
1331 obj->oo_inode = NULL;
1332 GOTO(out, result = 0);
1335 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1337 * "result == -ENOENT" means the cached OI mapping has been removed
1338 * from the OI file by race, above inode belongs to other object.
1340 if (result == -ENOENT) {
1343 obj->oo_inode = NULL;
1344 GOTO(out, result = 0);
1350 if (saved_ino == id->oii_ino && saved_gen == id->oii_gen) {
1352 osd_scrub_refresh_mapping(info, dev, fid, id, DTO_INDEX_DELETE,
1358 * It is the OI scrub updated the OI mapping by race.
1359 * The new OI mapping must be valid.
1367 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
1368 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1370 result = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
1372 if (lma->lma_compat & LMAC_STRIPE_INFO &&
1374 obj->oo_pfid_in_lma = 1;
1375 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
1377 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
1378 } else if (result != -ENODATA) {
1383 obj->oo_compat_dot_created = 1;
1384 obj->oo_compat_dotdot_created = 1;
1386 if (S_ISDIR(inode->i_mode) &&
1387 (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING))
1388 osd_check_lmv(info, dev, inode);
1390 result = osd_attach_jinode(inode);
1395 GOTO(out, result = 0);
1397 LASSERT(!obj->oo_hl_head);
1398 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1400 GOTO(out, result = (!obj->oo_hl_head ? -ENOMEM : 0));
1403 if (result || !obj->oo_inode) {
1404 if (!IS_ERR_OR_NULL(inode))
1407 obj->oo_inode = NULL;
1409 fid_zero(&oic->oic_fid);
1412 LINVRNT(osd_invariant(obj));
1417 * Concurrency: shouldn't matter.
1419 static void osd_object_init0(struct osd_object *obj)
1421 LASSERT(obj->oo_inode != NULL);
1422 obj->oo_dt.do_body_ops = &osd_body_ops;
1423 obj->oo_dt.do_lu.lo_header->loh_attr |=
1424 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
1428 * Concurrency: no concurrent access is possible that early in object
1431 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
1432 const struct lu_object_conf *conf)
1434 struct osd_object *obj = osd_obj(l);
1437 LINVRNT(osd_invariant(obj));
1439 if (OBD_FAIL_PRECHECK(OBD_FAIL_MDS_LLOG_UMOUNT_RACE) &&
1440 cfs_fail_val == 2) {
1441 struct osd_thread_info *info = osd_oti_get(env);
1442 struct osd_idmap_cache *oic = &info->oti_cache;
1443 /* invalidate thread cache */
1444 memset(&oic->oic_fid, 0, sizeof(oic->oic_fid));
1446 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
1447 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
1448 l->lo_header->loh_attr |= LOHA_EXISTS;
1452 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
1453 obj->oo_dt.do_body_ops = &osd_body_ops_new;
1454 if (result == 0 && obj->oo_inode != NULL) {
1455 struct osd_thread_info *oti = osd_oti_get(env);
1456 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
1458 osd_object_init0(obj);
1459 if (unlikely(obj->oo_header))
1462 result = osd_get_lma(oti, obj->oo_inode,
1463 &oti->oti_obj_dentry, loa);
1466 * Convert LMAI flags to lustre LMA flags
1467 * and cache it to oo_lma_flags
1470 lma_to_lustre_flags(loa->loa_lma.lma_incompat);
1471 } else if (result == -ENODATA) {
1475 obj->oo_dirent_count = LU_DIRENT_COUNT_UNSET;
1477 LINVRNT(osd_invariant(obj));
1482 * The first part of oxe_buf is xattr name, and is '\0' terminated.
1483 * The left part is for value, binary mode.
1485 struct osd_xattr_entry {
1486 struct list_head oxe_list;
1490 struct rcu_head oxe_rcu;
1494 static int osd_oxc_get(struct osd_object *obj, const char *name,
1497 struct osd_xattr_entry *tmp;
1498 struct osd_xattr_entry *oxe = NULL;
1499 size_t namelen = strlen(name);
1503 list_for_each_entry_rcu(tmp, &obj->oo_xattr_list, oxe_list) {
1504 if (namelen == tmp->oxe_namelen &&
1505 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1512 GOTO(out, rc = -ENOENT);
1514 if (!oxe->oxe_exist)
1515 GOTO(out, rc = -ENODATA);
1518 rc = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1;
1521 if (buf->lb_buf == NULL)
1524 if (buf->lb_len < rc)
1525 GOTO(out, rc = -ERANGE);
1527 memcpy(buf->lb_buf, &oxe->oxe_buf[namelen + 1], rc);
1534 static void osd_oxc_free(struct rcu_head *head)
1536 struct osd_xattr_entry *oxe;
1538 oxe = container_of(head, struct osd_xattr_entry, oxe_rcu);
1539 OBD_FREE(oxe, oxe->oxe_len);
1542 static void osd_oxc_add(struct osd_object *obj, const char *name,
1543 const char *buf, int buflen)
1545 struct osd_xattr_entry *oxe;
1546 struct osd_xattr_entry *old = NULL;
1547 struct osd_xattr_entry *tmp;
1548 size_t namelen = strlen(name);
1549 size_t len = sizeof(*oxe) + namelen + 1 + buflen;
1551 OBD_ALLOC(oxe, len);
1555 INIT_LIST_HEAD(&oxe->oxe_list);
1557 oxe->oxe_namelen = namelen;
1558 memcpy(oxe->oxe_buf, name, namelen);
1560 LASSERT(buf != NULL);
1561 memcpy(oxe->oxe_buf + namelen + 1, buf, buflen);
1562 oxe->oxe_exist = true;
1564 oxe->oxe_exist = false;
1567 /* this should be rarely called, just remove old and add new */
1568 spin_lock(&obj->oo_guard);
1569 list_for_each_entry(tmp, &obj->oo_xattr_list, oxe_list) {
1570 if (namelen == tmp->oxe_namelen &&
1571 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1577 list_replace_rcu(&old->oxe_list, &oxe->oxe_list);
1578 call_rcu(&old->oxe_rcu, osd_oxc_free);
1580 list_add_tail_rcu(&oxe->oxe_list, &obj->oo_xattr_list);
1582 spin_unlock(&obj->oo_guard);
1585 static void osd_oxc_del(struct osd_object *obj, const char *name)
1587 struct osd_xattr_entry *oxe;
1588 size_t namelen = strlen(name);
1590 spin_lock(&obj->oo_guard);
1591 list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) {
1592 if (namelen == oxe->oxe_namelen &&
1593 strncmp(name, oxe->oxe_buf, namelen) == 0) {
1594 list_del_rcu(&oxe->oxe_list);
1595 call_rcu(&oxe->oxe_rcu, osd_oxc_free);
1599 spin_unlock(&obj->oo_guard);
1602 static void osd_oxc_fini(struct osd_object *obj)
1604 struct osd_xattr_entry *oxe, *next;
1606 list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) {
1607 list_del(&oxe->oxe_list);
1608 OBD_FREE(oxe, oxe->oxe_len);
1613 * Concurrency: no concurrent access is possible that late in object
1616 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
1618 struct osd_object *obj = osd_obj(l);
1619 struct lu_object_header *h = obj->oo_header;
1621 LINVRNT(osd_invariant(obj));
1624 dt_object_fini(&obj->oo_dt);
1625 if (obj->oo_hl_head != NULL)
1626 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1627 /* obj doesn't contain an lu_object_header, so we don't need call_rcu */
1630 lu_object_header_free(h);
1634 * Concurrency: no concurrent access is possible that late in object
1637 static void osd_index_fini(struct osd_object *o)
1639 struct iam_container *bag;
1641 if (o->oo_dir != NULL) {
1642 bag = &o->oo_dir->od_container;
1643 if (o->oo_inode != NULL) {
1644 if (bag->ic_object == o->oo_inode)
1645 iam_container_fini(bag);
1647 OBD_FREE_PTR(o->oo_dir);
1653 OSD_TXN_OI_DELETE_CREDITS = 20,
1654 OSD_TXN_INODE_DELETE_CREDITS = 20
1661 #if OSD_THANDLE_STATS
1663 * Set time when the handle is allocated
1665 static void osd_th_alloced(struct osd_thandle *oth)
1667 oth->oth_alloced = ktime_get();
1671 * Set time when the handle started
1673 static void osd_th_started(struct osd_thandle *oth)
1675 oth->oth_started = ktime_get();
1679 * Check whether the we deal with this handle for too long.
1681 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
1682 ktime_t alloced, ktime_t started,
1685 ktime_t now = ktime_get();
1687 LASSERT(dev != NULL);
1689 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
1690 ktime_us_delta(started, alloced));
1691 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
1692 ktime_us_delta(closed, started));
1693 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
1694 ktime_us_delta(now, closed));
1696 if (ktime_before(ktime_add_ns(alloced, 30 * NSEC_PER_SEC), now)) {
1697 CWARN("transaction handle %p was open for too long: now %lld, alloced %lld, started %lld, closed %lld\n",
1698 oth, now, alloced, started, closed);
1699 libcfs_debug_dumpstack(NULL);
1703 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
1705 ktime_t __closed = ktime_get(); \
1706 ktime_t __alloced = oth->oth_alloced; \
1707 ktime_t __started = oth->oth_started; \
1710 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
1713 #else /* OSD_THANDLE_STATS */
1715 #define osd_th_alloced(h) do {} while(0)
1716 #define osd_th_started(h) do {} while(0)
1717 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
1719 #endif /* OSD_THANDLE_STATS */
1722 * Concurrency: doesn't access mutable data.
1724 static int osd_param_is_not_sane(const struct osd_device *dev,
1725 const struct thandle *th)
1727 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
1729 return oh->ot_credits > osd_transaction_size(dev);
1733 * Concurrency: shouldn't matter.
1735 static void osd_trans_commit_cb(struct super_block *sb,
1736 struct ldiskfs_journal_cb_entry *jcb, int error)
1738 struct osd_thandle *oh = container_of(jcb, struct osd_thandle, ot_jcb);
1739 struct thandle *th = &oh->ot_super;
1740 struct lu_device *lud = &th->th_dev->dd_lu_dev;
1741 struct osd_device *osd = osd_dev(lud);
1742 struct dt_txn_commit_cb *dcb, *tmp;
1744 LASSERT(oh->ot_handle == NULL);
1747 CERROR("transaction @0x%p commit error: %d\n", th, error);
1749 /* call per-transaction callbacks if any */
1750 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
1752 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1753 "commit callback entry: magic=%x name='%s'\n",
1754 dcb->dcb_magic, dcb->dcb_name);
1755 list_del_init(&dcb->dcb_linkage);
1756 dcb->dcb_func(NULL, th, dcb, error);
1759 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
1760 if (atomic_dec_and_test(&osd->od_commit_cb_in_flight))
1761 wake_up(&osd->od_commit_cb_done);
1767 static struct thandle *osd_trans_create(const struct lu_env *env,
1768 struct dt_device *d)
1770 struct osd_thread_info *oti = osd_oti_get(env);
1771 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1772 struct osd_thandle *oh;
1778 CERROR("%s: someone try to start transaction under "
1779 "readonly mode, should be disabled.\n",
1780 osd_name(osd_dt_dev(d)));
1782 RETURN(ERR_PTR(-EROFS));
1785 /* on pending IO in this thread should left from prev. request */
1786 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
1788 sb_start_write(osd_sb(osd_dt_dev(d)));
1790 OBD_ALLOC_GFP(oh, sizeof(*oh), GFP_NOFS);
1792 sb_end_write(osd_sb(osd_dt_dev(d)));
1793 RETURN(ERR_PTR(-ENOMEM));
1796 oh->ot_quota_trans = &oti->oti_quota_trans;
1797 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
1802 oh->oh_declared_ext = 0;
1803 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
1804 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
1805 INIT_LIST_HEAD(&oh->ot_trunc_locks);
1808 memset(oti->oti_declare_ops, 0,
1809 sizeof(oti->oti_declare_ops));
1810 memset(oti->oti_declare_ops_cred, 0,
1811 sizeof(oti->oti_declare_ops_cred));
1812 memset(oti->oti_declare_ops_used, 0,
1813 sizeof(oti->oti_declare_ops_used));
1815 oti->oti_ins_cache_depth++;
1820 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
1822 struct osd_thread_info *oti = osd_oti_get(env);
1823 struct osd_thandle *oh;
1825 oh = container_of(th, struct osd_thandle, ot_super);
1826 LASSERT(oh != NULL);
1828 CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n",
1829 oti->oti_declare_ops[OSD_OT_CREATE],
1830 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1831 oti->oti_declare_ops_used[OSD_OT_CREATE],
1832 oti->oti_declare_ops[OSD_OT_DESTROY],
1833 oti->oti_declare_ops_cred[OSD_OT_DESTROY],
1834 oti->oti_declare_ops_used[OSD_OT_DESTROY]);
1835 CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
1836 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1837 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1838 oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
1839 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1840 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
1841 oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
1842 CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
1843 oti->oti_declare_ops[OSD_OT_WRITE],
1844 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1845 oti->oti_declare_ops_used[OSD_OT_WRITE],
1846 oti->oti_declare_ops[OSD_OT_PUNCH],
1847 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1848 oti->oti_declare_ops_used[OSD_OT_PUNCH],
1849 oti->oti_declare_ops[OSD_OT_QUOTA],
1850 oti->oti_declare_ops_cred[OSD_OT_QUOTA],
1851 oti->oti_declare_ops_used[OSD_OT_QUOTA]);
1852 CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n",
1853 oti->oti_declare_ops[OSD_OT_INSERT],
1854 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1855 oti->oti_declare_ops_used[OSD_OT_INSERT],
1856 oti->oti_declare_ops[OSD_OT_DELETE],
1857 oti->oti_declare_ops_cred[OSD_OT_DELETE],
1858 oti->oti_declare_ops_used[OSD_OT_DELETE]);
1859 CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
1860 oti->oti_declare_ops[OSD_OT_REF_ADD],
1861 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1862 oti->oti_declare_ops_used[OSD_OT_REF_ADD],
1863 oti->oti_declare_ops[OSD_OT_REF_DEL],
1864 oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
1865 oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
1869 * Concurrency: shouldn't matter.
1871 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1874 struct osd_thread_info *oti = osd_oti_get(env);
1875 struct osd_device *dev = osd_dt_dev(d);
1877 struct osd_thandle *oh;
1882 LASSERT(current->journal_info == NULL);
1884 oh = container_of(th, struct osd_thandle, ot_super);
1885 LASSERT(oh != NULL);
1886 LASSERT(oh->ot_handle == NULL);
1888 rc = dt_txn_hook_start(env, d, th);
1892 if (unlikely(osd_param_is_not_sane(dev, th))) {
1893 static unsigned long last_printed;
1894 static int last_credits;
1897 * don't make noise on a tiny testing systems
1898 * actual credits misuse will be caught anyway
1900 if (last_credits != oh->ot_credits &&
1901 time_after(jiffies, last_printed +
1902 cfs_time_seconds(60)) &&
1903 osd_transaction_size(dev) > 512) {
1904 CWARN("%s: credits %u > trans_max %u\n", osd_name(dev),
1905 oh->ot_credits, osd_transaction_size(dev));
1906 osd_trans_dump_creds(env, th);
1907 libcfs_debug_dumpstack(NULL);
1908 last_credits = oh->ot_credits;
1909 last_printed = jiffies;
1912 * XXX Limit the credits to 'max_transaction_buffers', and
1913 * let the underlying filesystem to catch the error if
1914 * we really need so many credits.
1916 * This should be removed when we can calculate the
1917 * credits precisely.
1919 oh->ot_credits = osd_transaction_size(dev);
1920 } else if (ldiskfs_track_declares_assert != 0) {
1922 * reserve few credits to prevent an assertion in JBD
1923 * our debugging mechanism will be able to detected
1924 * overuse. this can help to debug single-update
1927 oh->ot_credits += 10;
1928 if (unlikely(osd_param_is_not_sane(dev, th)))
1929 oh->ot_credits = osd_transaction_size(dev);
1932 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_TXN_START))
1933 GOTO(out, rc = -EIO);
1936 * XXX temporary stuff. Some abstraction layer should
1939 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1943 LASSERT(oti->oti_txns == 0);
1945 atomic_inc(&dev->od_commit_cb_in_flight);
1946 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1957 static int osd_seq_exists(const struct lu_env *env,
1958 struct osd_device *osd, u64 seq)
1960 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1961 struct seq_server_site *ss = osd_seq_site(osd);
1966 LASSERT(ss != NULL);
1967 LASSERT(ss->ss_server_fld != NULL);
1969 rc = osd_fld_lookup(env, osd, seq, range);
1972 CERROR("%s: can't lookup FLD sequence %#llx: rc = %d\n",
1973 osd_name(osd), seq, rc);
1977 RETURN(ss->ss_node_id == range->lsr_index);
1980 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
1982 struct dt_txn_commit_cb *dcb;
1983 struct dt_txn_commit_cb *tmp;
1985 /* call per-transaction stop callbacks if any */
1986 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
1988 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1989 "commit callback entry: magic=%x name='%s'\n",
1990 dcb->dcb_magic, dcb->dcb_name);
1991 list_del_init(&dcb->dcb_linkage);
1992 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
1997 * Concurrency: shouldn't matter.
1999 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
2002 struct osd_thread_info *oti = osd_oti_get(env);
2003 struct osd_thandle *oh;
2004 struct osd_iobuf *iobuf = &oti->oti_iobuf;
2005 struct osd_device *osd = osd_dt_dev(th->th_dev);
2006 struct qsd_instance *qsd = osd_def_qsd(osd);
2007 struct lquota_trans *qtrans;
2008 LIST_HEAD(truncates);
2009 int rc = 0, remove_agents = 0;
2013 oh = container_of(th, struct osd_thandle, ot_super);
2015 remove_agents = oh->ot_remove_agents;
2017 qtrans = oh->ot_quota_trans;
2018 oh->ot_quota_trans = NULL;
2020 /* move locks to local list, stop tx, execute truncates */
2021 list_splice(&oh->ot_trunc_locks, &truncates);
2023 if (oh->ot_handle != NULL) {
2026 handle_t *hdl = oh->ot_handle;
2029 * add commit callback
2030 * notice we don't do this in osd_trans_start()
2031 * as underlying transaction can change during truncate
2033 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
2036 LASSERT(oti->oti_txns == 1);
2039 rc = dt_txn_hook_stop(env, th);
2041 CERROR("%s: failed in transaction hook: rc = %d\n",
2044 osd_trans_stop_cb(oh, rc);
2045 /* hook functions might modify th_sync */
2046 hdl->h_sync = th->th_sync;
2048 oh->ot_handle = NULL;
2049 OSD_CHECK_SLOW_TH(oh, osd, rc2 = ldiskfs_journal_stop(hdl));
2051 CERROR("%s: failed to stop transaction: rc = %d\n",
2052 osd_name(osd), rc2);
2056 /* We preserve the origin behavior of ignoring any
2057 * failures with the underlying punch / truncate
2058 * operation. We do record for debugging if an error
2059 * does occur in the lctl dk logs.
2061 rc2 = osd_process_truncates(env, &truncates);
2063 CERROR("%s: failed truncate process: rc = %d\n",
2064 osd_name(osd), rc2);
2066 osd_trans_stop_cb(oh, th->th_result);
2070 osd_trunc_unlock_all(env, &truncates);
2072 /* inform the quota slave device that the transaction is stopping */
2073 qsd_op_end(env, qsd, qtrans);
2076 * as we want IO to journal and data IO be concurrent, we don't block
2077 * awaiting data IO completion in osd_do_bio(), instead we wait here
2078 * once transaction is submitted to the journal. all reqular requests
2079 * don't do direct IO (except read/write), thus this wait_event becomes
2082 * IMPORTANT: we have to wait till any IO submited by the thread is
2083 * completed otherwise iobuf may be corrupted by different request
2085 wait_event(iobuf->dr_wait,
2086 atomic_read(&iobuf->dr_numreqs) == 0);
2087 osd_fini_iobuf(osd, iobuf);
2089 rc = iobuf->dr_error;
2091 if (unlikely(remove_agents != 0))
2092 osd_process_scheduled_agent_removals(env, osd);
2094 LASSERT(oti->oti_ins_cache_depth > 0);
2095 oti->oti_ins_cache_depth--;
2096 /* reset OI cache for safety */
2097 if (oti->oti_ins_cache_depth == 0)
2098 oti->oti_ins_cache_used = 0;
2100 sb_end_write(osd_sb(osd));
2105 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
2107 struct osd_thandle *oh = container_of(th, struct osd_thandle,
2110 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
2111 LASSERT(&dcb->dcb_func != NULL);
2112 if (dcb->dcb_flags & DCB_TRANS_STOP)
2113 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
2115 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
2121 * Called just before object is freed. Releases all resources except for
2122 * object itself (that is released by osd_object_free()).
2124 * Concurrency: no concurrent access is possible that late in object
2127 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
2129 struct osd_object *obj = osd_obj(l);
2130 struct qsd_instance *qsd = osd_def_qsd(osd_obj2dev(obj));
2131 struct inode *inode = obj->oo_inode;
2136 LINVRNT(osd_invariant(obj));
2139 * If object is unlinked remove fid->ino mapping from object index.
2142 osd_index_fini(obj);
2147 if (osd_has_index(obj) && obj->oo_dt.do_index_ops == &osd_index_iam_ops)
2148 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2150 uid = i_uid_read(inode);
2151 gid = i_gid_read(inode);
2152 projid = i_projid_read(inode);
2154 obj->oo_inode = NULL;
2157 /* do not rebalance quota if the caller needs to release memory
2158 * otherwise qsd_refresh_usage() may went into a new ldiskfs
2159 * transaction and risk to deadlock - LU-12178 */
2160 if (current->flags & (PF_MEMALLOC | PF_KSWAPD))
2163 if (!obj->oo_header && qsd) {
2164 struct osd_thread_info *info = osd_oti_get(env);
2165 struct lquota_id_info *qi = &info->oti_qi;
2167 /* Release granted quota to master if necessary */
2168 qi->lqi_id.qid_uid = uid;
2169 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
2171 qi->lqi_id.qid_uid = gid;
2172 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
2174 qi->lqi_id.qid_uid = projid;
2175 qsd_op_adjust(env, qsd, &qi->lqi_id, PRJQUOTA);
2180 * Concurrency: ->loo_object_release() is called under site spin-lock.
2182 static void osd_object_release(const struct lu_env *env,
2183 struct lu_object *l)
2185 struct osd_object *o = osd_obj(l);
2188 * nobody should be releasing a non-destroyed object with nlink=0
2189 * the API allows this, but ldiskfs doesn't like and then report
2190 * this inode as deleted
2192 LASSERT(!(o->oo_destroyed == 0 && o->oo_inode &&
2193 o->oo_inode->i_nlink == 0));
2197 * Concurrency: shouldn't matter.
2199 static int osd_object_print(const struct lu_env *env, void *cookie,
2200 lu_printer_t p, const struct lu_object *l)
2202 struct osd_object *o = osd_obj(l);
2203 struct iam_descr *d;
2205 if (o->oo_dir != NULL)
2206 d = o->oo_dir->od_container.ic_descr;
2209 return (*p)(env, cookie,
2210 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
2212 o->oo_inode ? o->oo_inode->i_ino : 0UL,
2213 o->oo_inode ? o->oo_inode->i_generation : 0,
2214 d ? d->id_ops->id_name : "plain");
2218 * Concurrency: shouldn't matter.
2220 int osd_statfs(const struct lu_env *env, struct dt_device *d,
2221 struct obd_statfs *sfs, struct obd_statfs_info *info)
2223 struct osd_device *osd = osd_dt_dev(d);
2224 struct super_block *sb = osd_sb(osd);
2225 struct kstatfs *ksfs;
2229 if (unlikely(osd->od_mnt == NULL))
2230 return -EINPROGRESS;
2232 /* osd_lproc.c call this without env, allocate ksfs for that case */
2233 if (unlikely(env == NULL)) {
2234 OBD_ALLOC_PTR(ksfs);
2238 ksfs = &osd_oti_get(env)->oti_ksfs;
2241 result = sb->s_op->statfs(sb->s_root, ksfs);
2245 statfs_pack(sfs, ksfs);
2246 if (unlikely(sb->s_flags & SB_RDONLY))
2247 sfs->os_state |= OS_STATFS_READONLY;
2249 sfs->os_state |= osd->od_nonrotational ? OS_STATFS_NONROT : 0;
2251 if (ldiskfs_has_feature_extents(sb))
2252 sfs->os_maxbytes = sb->s_maxbytes;
2254 sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2257 * Reserve some space so to avoid fragmenting the filesystem too much.
2258 * Fragmentation not only impacts performance, but can also increase
2259 * metadata overhead significantly, causing grant calculation to be
2262 * Reserve 0.78% of total space, at least 8MB for small filesystems.
2264 BUILD_BUG_ON(OSD_STATFS_RESERVED <= LDISKFS_MAX_BLOCK_SIZE);
2265 reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits;
2266 if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT))
2267 reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT;
2269 sfs->os_blocks -= reserved;
2270 sfs->os_bfree -= min(reserved, sfs->os_bfree);
2271 sfs->os_bavail -= min(reserved, sfs->os_bavail);
2274 if (unlikely(env == NULL))
2280 * Estimate space needed for file creations. We assume the largest filename
2281 * which is 2^64 - 1, hence a filename of 20 chars.
2282 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
2284 #ifdef __LDISKFS_DIR_REC_LEN
2285 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
2287 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
2291 * Concurrency: doesn't access mutable data.
2293 static void osd_conf_get(const struct lu_env *env,
2294 const struct dt_device *dev,
2295 struct dt_device_param *param)
2297 struct osd_device *d = osd_dt_dev(dev);
2298 struct super_block *sb = osd_sb(d);
2299 struct blk_integrity *bi = bdev_get_integrity(sb->s_bdev);
2304 * XXX should be taken from not-yet-existing fs abstraction layer.
2306 param->ddp_max_name_len = LDISKFS_NAME_LEN;
2307 param->ddp_max_nlink = LDISKFS_LINK_MAX;
2308 param->ddp_symlink_max = sb->s_blocksize;
2309 param->ddp_mount_type = LDD_MT_LDISKFS;
2310 if (ldiskfs_has_feature_extents(sb))
2311 param->ddp_maxbytes = sb->s_maxbytes;
2313 param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2315 * inode are statically allocated, so per-inode space consumption
2316 * is the space consumed by the directory entry
2318 param->ddp_inodespace = PER_OBJ_USAGE;
2320 * EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks
2321 * is 128MB) which is unlikely to be hit in real life. Report a smaller
2322 * maximum length to not under-count the actual number of extents
2323 * needed for writing a file if there are sub-optimal block allocations.
2325 param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 1;
2326 /* worst-case extent insertion metadata overhead */
2327 param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb);
2328 param->ddp_mntopts = 0;
2329 if (test_opt(sb, XATTR_USER))
2330 param->ddp_mntopts |= MNTOPT_USERXATTR;
2331 if (test_opt(sb, POSIX_ACL))
2332 param->ddp_mntopts |= MNTOPT_ACL;
2335 * LOD might calculate the max stripe count based on max_ea_size,
2336 * so we need take account in the overhead as well,
2337 * xattr_header + magic + xattr_entry_head
2339 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
2340 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
2342 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
2343 if (ldiskfs_has_feature_ea_inode(sb))
2344 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
2348 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
2350 if (param->ddp_max_ea_size > OBD_MAX_EA_SIZE)
2351 param->ddp_max_ea_size = OBD_MAX_EA_SIZE;
2354 * Preferred RPC size for efficient disk IO. 4MB shows good
2355 * all-around performance for ldiskfs, but use bigalloc chunk size
2356 * by default if larger.
2358 #if defined(LDISKFS_CLUSTER_SIZE)
2359 if (LDISKFS_CLUSTER_SIZE(sb) > DT_DEF_BRW_SIZE)
2360 param->ddp_brw_size = LDISKFS_CLUSTER_SIZE(sb);
2363 param->ddp_brw_size = DT_DEF_BRW_SIZE;
2365 param->ddp_t10_cksum_type = 0;
2367 unsigned short interval = blk_integrity_interval(bi);
2368 name = blk_integrity_name(bi);
2376 if (strncmp(name, "T10-DIF-TYPE",
2377 sizeof("T10-DIF-TYPE") - 1) == 0) {
2378 /* also skip "1/3-" at end */
2379 const int type_off = sizeof("T10-DIF-TYPE.");
2380 char type_number = name[type_off - 2];
2382 if (interval != 512 && interval != 4096) {
2383 CERROR("%s: unsupported T10PI sector size %u\n",
2384 d->od_svname, interval);
2385 } else if (type_number != '1' && type_number != '3') {
2386 CERROR("%s: unsupported T10PI type %s\n",
2387 d->od_svname, name);
2388 } else if (strcmp(name + type_off, "CRC") == 0) {
2389 d->od_t10_type = type_number == '1' ?
2390 OSD_T10_TYPE1_CRC : OSD_T10_TYPE3_CRC;
2391 param->ddp_t10_cksum_type = interval == 512 ?
2392 OBD_CKSUM_T10CRC512 :
2394 } else if (strcmp(name + type_off, "IP") == 0) {
2395 d->od_t10_type = type_number == '1' ?
2396 OSD_T10_TYPE1_IP : OSD_T10_TYPE3_IP;
2397 param->ddp_t10_cksum_type = interval == 512 ?
2398 OBD_CKSUM_T10IP512 :
2401 CERROR("%s: unsupported checksum type of T10PI type '%s'\n",
2402 d->od_svname, name);
2406 CERROR("%s: unsupported T10PI type '%s'\n",
2407 d->od_svname, name);
2411 param->ddp_has_lseek_data_hole = true;
2414 static struct super_block *osd_mnt_sb_get(const struct dt_device *d)
2416 return osd_sb(osd_dt_dev(d));
2420 * Concurrency: shouldn't matter.
2422 static int osd_sync(const struct lu_env *env, struct dt_device *d)
2425 struct super_block *s = osd_sb(osd_dt_dev(d));
2428 down_read(&s->s_umount);
2429 rc = s->s_op->sync_fs(s, 1);
2430 up_read(&s->s_umount);
2432 CDEBUG(D_CACHE, "%s: synced OSD: rc = %d\n", osd_dt_dev(d)->od_svname,
2439 * Start commit for OSD device.
2441 * An implementation of dt_commit_async method for OSD device.
2442 * Asychronously starts underlayng fs sync and thereby a transaction
2445 * \param env environment
2446 * \param d dt device
2448 * \see dt_device_operations
2450 static int osd_commit_async(const struct lu_env *env,
2451 struct dt_device *d)
2453 struct super_block *s = osd_sb(osd_dt_dev(d));
2458 CDEBUG(D_HA, "%s: async commit OSD\n", osd_dt_dev(d)->od_svname);
2459 down_read(&s->s_umount);
2460 rc = s->s_op->sync_fs(s, 0);
2461 up_read(&s->s_umount);
2467 * Concurrency: shouldn't matter.
2469 static int osd_ro(const struct lu_env *env, struct dt_device *d)
2471 struct super_block *sb = osd_sb(osd_dt_dev(d));
2472 struct block_device *dev = sb->s_bdev;
2473 int rc = -EOPNOTSUPP;
2477 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
2478 osd_dt_dev(d)->od_svname, (long)dev, rc);
2484 * Note: we do not count into QUOTA here.
2485 * If we mount with --data_journal we may need more.
2487 const int osd_dto_credits_noquota[DTO_NR] = {
2490 * INDEX_EXTRA_TRANS_BLOCKS(8) +
2491 * SINGLEDATA_TRANS_BLOCKS(8)
2492 * XXX Note: maybe iam need more, since iam have more level than
2495 [DTO_INDEX_INSERT] = 16,
2498 * just modify a single entry, probably merge few within a block
2500 [DTO_INDEX_DELETE] = 1,
2504 [DTO_INDEX_UPDATE] = 16,
2506 * 4(inode, inode bits, groups, GDT)
2507 * notice: OI updates are counted separately with DTO_INDEX_INSERT
2509 [DTO_OBJECT_CREATE] = 4,
2511 * 4(inode, inode bits, groups, GDT)
2512 * notice: OI updates are counted separately with DTO_INDEX_DELETE
2514 [DTO_OBJECT_DELETE] = 4,
2516 * Attr set credits (inode)
2518 [DTO_ATTR_SET_BASE] = 1,
2520 * Xattr set. The same as xattr of EXT3.
2521 * DATA_TRANS_BLOCKS(14)
2522 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
2523 * are also counted in. Do not know why?
2525 [DTO_XATTR_SET] = 14,
2527 * credits for inode change during write.
2529 [DTO_WRITE_BASE] = 3,
2531 * credits for single block write.
2533 [DTO_WRITE_BLOCK] = 14,
2535 * Attr set credits for chown.
2536 * This is extra credits for setattr, and it is null without quota
2538 [DTO_ATTR_SET_CHOWN] = 0
2541 /* reserve or free quota for some operation */
2542 static int osd_reserve_or_free_quota(const struct lu_env *env,
2543 struct dt_device *dev,
2544 struct lquota_id_info *qi)
2546 struct osd_device *osd = osd_dt_dev(dev);
2547 struct qsd_instance *qsd = NULL;
2553 qsd = osd->od_quota_slave_dt;
2555 qsd = osd->od_quota_slave_md;
2557 rc = qsd_reserve_or_free_quota(env, qsd, qi);
2561 static const struct dt_device_operations osd_dt_ops = {
2562 .dt_root_get = osd_root_get,
2563 .dt_statfs = osd_statfs,
2564 .dt_trans_create = osd_trans_create,
2565 .dt_trans_start = osd_trans_start,
2566 .dt_trans_stop = osd_trans_stop,
2567 .dt_trans_cb_add = osd_trans_cb_add,
2568 .dt_conf_get = osd_conf_get,
2569 .dt_mnt_sb_get = osd_mnt_sb_get,
2570 .dt_sync = osd_sync,
2572 .dt_commit_async = osd_commit_async,
2573 .dt_reserve_or_free_quota = osd_reserve_or_free_quota,
2576 static void osd_read_lock(const struct lu_env *env, struct dt_object *dt,
2579 struct osd_object *obj = osd_dt_obj(dt);
2580 struct osd_thread_info *oti = osd_oti_get(env);
2582 LINVRNT(osd_invariant(obj));
2584 LASSERT(obj->oo_owner != env);
2585 down_read_nested(&obj->oo_sem, role);
2587 LASSERT(obj->oo_owner == NULL);
2591 static void osd_write_lock(const struct lu_env *env, struct dt_object *dt,
2594 struct osd_object *obj = osd_dt_obj(dt);
2595 struct osd_thread_info *oti = osd_oti_get(env);
2597 LINVRNT(osd_invariant(obj));
2599 LASSERT(obj->oo_owner != env);
2600 down_write_nested(&obj->oo_sem, role);
2602 LASSERT(obj->oo_owner == NULL);
2603 obj->oo_owner = env;
2607 static void osd_read_unlock(const struct lu_env *env, struct dt_object *dt)
2609 struct osd_object *obj = osd_dt_obj(dt);
2610 struct osd_thread_info *oti = osd_oti_get(env);
2612 LINVRNT(osd_invariant(obj));
2614 LASSERT(oti->oti_r_locks > 0);
2616 up_read(&obj->oo_sem);
2619 static void osd_write_unlock(const struct lu_env *env, struct dt_object *dt)
2621 struct osd_object *obj = osd_dt_obj(dt);
2622 struct osd_thread_info *oti = osd_oti_get(env);
2624 LINVRNT(osd_invariant(obj));
2626 LASSERT(obj->oo_owner == env);
2627 LASSERT(oti->oti_w_locks > 0);
2629 obj->oo_owner = NULL;
2630 up_write(&obj->oo_sem);
2633 static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
2635 struct osd_object *obj = osd_dt_obj(dt);
2637 LINVRNT(osd_invariant(obj));
2639 return obj->oo_owner == env;
2642 static void osd_inode_getattr(const struct lu_env *env,
2643 struct inode *inode, struct lu_attr *attr)
2645 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2646 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2647 LA_PROJID | LA_FLAGS | LA_NLINK | LA_RDEV |
2648 LA_BLKSIZE | LA_TYPE | LA_BTIME;
2650 attr->la_atime = inode->i_atime.tv_sec;
2651 attr->la_mtime = inode->i_mtime.tv_sec;
2652 attr->la_ctime = inode->i_ctime.tv_sec;
2653 attr->la_btime = LDISKFS_I(inode)->i_crtime.tv_sec;
2654 attr->la_mode = inode->i_mode;
2655 attr->la_size = i_size_read(inode);
2656 attr->la_blocks = inode->i_blocks;
2657 attr->la_uid = i_uid_read(inode);
2658 attr->la_gid = i_gid_read(inode);
2659 attr->la_projid = i_projid_read(inode);
2660 attr->la_flags = ll_inode_to_ext_flags(inode->i_flags);
2661 attr->la_nlink = inode->i_nlink;
2662 attr->la_rdev = inode->i_rdev;
2663 attr->la_blksize = 1 << inode->i_blkbits;
2664 attr->la_blkbits = inode->i_blkbits;
2666 * Ext4 did not transfer inherit flags from raw inode
2667 * to inode flags, and ext4 internally test raw inode
2668 * @i_flags directly. Instead of patching ext4, we do it here.
2670 if (LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL)
2671 attr->la_flags |= LUSTRE_PROJINHERIT_FL;
2674 static int osd_dirent_count(const struct lu_env *env, struct dt_object *dt,
2677 struct osd_object *obj = osd_dt_obj(dt);
2678 const struct dt_it_ops *iops;
2684 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2685 LASSERT(fid_is_namespace_visible(lu_object_fid(&obj->oo_dt.do_lu)));
2687 if (obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
2688 *count = obj->oo_dirent_count;
2692 /* directory not initialized yet */
2693 if (!dt->do_index_ops) {
2698 iops = &dt->do_index_ops->dio_it;
2699 it = iops->init(env, dt, LUDA_64BITHASH);
2701 RETURN(PTR_ERR(it));
2703 rc = iops->load(env, it, 0);
2705 if (rc == -ENODATA) {
2712 rc = iops->next(env, it);
2714 for (*count = 0; rc == 0 || rc == -ESTALE; rc = iops->next(env, it)) {
2718 if (iops->key_size(env, it) == 0)
2724 obj->oo_dirent_count = *count;
2729 iops->fini(env, it);
2734 static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
2735 struct lu_attr *attr)
2737 struct osd_object *obj = osd_dt_obj(dt);
2740 if (unlikely(!dt_object_exists(dt)))
2742 if (unlikely(obj->oo_destroyed))
2745 LASSERT(!dt_object_remote(dt));
2746 LINVRNT(osd_invariant(obj));
2748 spin_lock(&obj->oo_guard);
2749 osd_inode_getattr(env, obj->oo_inode, attr);
2750 if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) {
2751 attr->la_valid |= LA_FLAGS;
2752 attr->la_flags |= LUSTRE_ORPHAN_FL;
2754 if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL) {
2755 attr->la_valid |= LA_FLAGS;
2756 attr->la_flags |= LUSTRE_ENCRYPT_FL;
2758 spin_unlock(&obj->oo_guard);
2760 if (S_ISDIR(obj->oo_inode->i_mode) &&
2761 fid_is_namespace_visible(lu_object_fid(&dt->do_lu)))
2762 rc = osd_dirent_count(env, dt, &attr->la_dirent_count);
2767 static int osd_declare_attr_qid(const struct lu_env *env,
2768 struct osd_object *obj,
2769 struct osd_thandle *oh, long long bspace,
2770 qid_t old_id, qid_t new_id, bool enforce,
2774 struct osd_thread_info *info = osd_oti_get(env);
2775 struct lquota_id_info *qi = &info->oti_qi;
2777 qi->lqi_type = type;
2778 /* inode accounting */
2779 qi->lqi_is_blk = false;
2781 /* one more inode for the new id ... */
2782 qi->lqi_id.qid_uid = new_id;
2784 /* Reserve credits for the new id */
2785 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2786 if (rc == -EDQUOT || rc == -EINPROGRESS)
2791 /* and one less inode for the current id */
2792 qi->lqi_id.qid_uid = old_id;
2794 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2795 if (rc == -EDQUOT || rc == -EINPROGRESS)
2800 /* block accounting */
2801 qi->lqi_is_blk = true;
2803 /* more blocks for the new id ... */
2804 qi->lqi_id.qid_uid = new_id;
2805 qi->lqi_space = bspace;
2807 * Credits for the new uid has been reserved, re-use "obj"
2808 * to save credit reservation.
2810 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2811 if (rc == -EDQUOT || rc == -EINPROGRESS)
2816 /* and finally less blocks for the current uid */
2817 qi->lqi_id.qid_uid = old_id;
2818 qi->lqi_space = -bspace;
2819 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2820 if (rc == -EDQUOT || rc == -EINPROGRESS)
2826 static int osd_declare_attr_set(const struct lu_env *env,
2827 struct dt_object *dt,
2828 const struct lu_attr *attr,
2829 struct thandle *handle)
2831 struct osd_thandle *oh;
2832 struct osd_object *obj;
2841 LASSERT(dt != NULL);
2842 LASSERT(handle != NULL);
2844 obj = osd_dt_obj(dt);
2845 LASSERT(osd_invariant(obj));
2847 oh = container_of(handle, struct osd_thandle, ot_super);
2848 LASSERT(oh->ot_handle == NULL);
2850 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
2851 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2853 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2854 osd_dto_credits_noquota[DTO_XATTR_SET]);
2856 if (attr == NULL || obj->oo_inode == NULL)
2859 bspace = obj->oo_inode->i_blocks << 9;
2860 bspace = toqb(bspace);
2863 * Changing ownership is always preformed by super user, it should not
2864 * fail with EDQUOT unless required explicitly.
2866 * We still need to call the osd_declare_qid() to calculate the journal
2867 * credits for updating quota accounting files and to trigger quota
2868 * space adjustment once the operation is completed.
2870 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
2872 uid = i_uid_read(obj->oo_inode);
2873 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
2874 rc = osd_declare_attr_qid(env, obj, oh, bspace, uid,
2875 attr->la_uid, enforce, USRQUOTA);
2879 gid = i_gid_read(obj->oo_inode);
2880 CDEBUG(D_QUOTA, "declare uid %d -> %d gid %d -> %d\n", uid,
2881 attr->la_uid, gid, attr->la_gid);
2882 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
2883 rc = osd_declare_attr_qid(env, obj, oh, bspace, gid,
2884 attr->la_gid, enforce, GRPQUOTA);
2889 #ifdef HAVE_PROJECT_QUOTA
2890 if (attr->la_valid & LA_PROJID) {
2891 __u32 projid = i_projid_read(obj->oo_inode);
2893 enforce = (attr->la_valid & LA_PROJID) &&
2894 (attr->la_projid != projid);
2895 rc = osd_declare_attr_qid(env, obj, oh, bspace,
2896 (qid_t)projid, (qid_t)attr->la_projid,
2905 static int osd_inode_setattr(const struct lu_env *env,
2906 struct inode *inode, const struct lu_attr *attr)
2908 __u64 bits = attr->la_valid;
2910 /* Only allow set size for regular file */
2911 if (!S_ISREG(inode->i_mode))
2912 bits &= ~(LA_SIZE | LA_BLOCKS);
2917 if (bits & LA_ATIME)
2918 inode->i_atime = osd_inode_time(inode, attr->la_atime);
2919 if (bits & LA_CTIME)
2920 inode->i_ctime = osd_inode_time(inode, attr->la_ctime);
2921 if (bits & LA_MTIME)
2922 inode->i_mtime = osd_inode_time(inode, attr->la_mtime);
2923 if (bits & LA_SIZE) {
2924 spin_lock(&inode->i_lock);
2925 LDISKFS_I(inode)->i_disksize = attr->la_size;
2926 i_size_write(inode, attr->la_size);
2927 spin_unlock(&inode->i_lock);
2931 * OSD should not change "i_blocks" which is used by quota.
2932 * "i_blocks" should be changed by ldiskfs only.
2935 inode->i_mode = (inode->i_mode & S_IFMT) |
2936 (attr->la_mode & ~S_IFMT);
2938 i_uid_write(inode, attr->la_uid);
2940 i_gid_write(inode, attr->la_gid);
2941 if (bits & LA_PROJID)
2942 i_projid_write(inode, attr->la_projid);
2943 if (bits & LA_NLINK)
2944 set_nlink(inode, attr->la_nlink);
2946 inode->i_rdev = attr->la_rdev;
2948 if (bits & LA_FLAGS) {
2949 /* always keep S_NOCMTIME */
2950 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
2952 #if defined(S_ENCRYPTED)
2953 /* Always remove S_ENCRYPTED, because ldiskfs must not be
2954 * aware of encryption status. It is just stored into LMA
2955 * so that it can be forwared to client side.
2957 inode->i_flags &= ~S_ENCRYPTED;
2960 * Ext4 did not transfer inherit flags from
2961 * @inode->i_flags to raw inode i_flags when writing
2962 * flags, we do it explictly here.
2964 if (attr->la_flags & LUSTRE_PROJINHERIT_FL)
2965 LDISKFS_I(inode)->i_flags |= LUSTRE_PROJINHERIT_FL;
2967 LDISKFS_I(inode)->i_flags &= ~LUSTRE_PROJINHERIT_FL;
2972 #ifdef HAVE_PROJECT_QUOTA
2973 static int osd_transfer_project(struct inode *inode, __u32 projid,
2974 struct thandle *handle)
2976 struct super_block *sb = inode->i_sb;
2977 struct ldiskfs_inode_info *ei = LDISKFS_I(inode);
2980 struct ldiskfs_iloc iloc;
2981 struct ldiskfs_inode *raw_inode;
2982 struct dquot *transfer_to[LDISKFS_MAXQUOTAS] = { };
2984 if (!ldiskfs_has_feature_project(sb)) {
2985 LASSERT(__kprojid_val(LDISKFS_I(inode)->i_projid)
2986 == LDISKFS_DEF_PROJID);
2987 if (projid != LDISKFS_DEF_PROJID)
2993 if (LDISKFS_INODE_SIZE(sb) <= LDISKFS_GOOD_OLD_INODE_SIZE)
2996 kprojid = make_kprojid(&init_user_ns, (projid_t)projid);
2997 if (projid_eq(kprojid, LDISKFS_I(inode)->i_projid))
3000 err = ldiskfs_get_inode_loc(inode, &iloc);
3004 raw_inode = ldiskfs_raw_inode(&iloc);
3005 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3006 struct osd_thandle *oh = container_of(handle,
3010 * try to expand inode size automatically.
3012 ldiskfs_mark_inode_dirty(oh->ot_handle, inode);
3013 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3021 dquot_initialize(inode);
3022 transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
3023 if (transfer_to[PRJQUOTA]) {
3024 lock_dquot_transfer(inode);
3025 err = __dquot_transfer(inode, transfer_to);
3026 unlock_dquot_transfer(inode);
3027 dqput(transfer_to[PRJQUOTA]);
3036 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr,
3037 struct thandle *handle)
3041 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
3042 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
3046 "executing dquot_transfer inode %ld uid %d -> %d gid %d -> %d\n",
3047 inode->i_ino, i_uid_read(inode), attr->la_uid,
3048 i_gid_read(inode), attr->la_gid);
3050 dquot_initialize(inode);
3052 if (attr->la_valid & LA_UID)
3053 iattr.ia_valid |= ATTR_UID;
3054 if (attr->la_valid & LA_GID)
3055 iattr.ia_valid |= ATTR_GID;
3056 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
3057 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
3059 lock_dquot_transfer(inode);
3060 rc = dquot_transfer(inode, &iattr);
3061 unlock_dquot_transfer(inode);
3063 CERROR("%s: quota transfer failed. Is quota enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3064 osd_ino2name(inode), rc);
3069 /* Handle project id transfer here properly */
3070 if (attr->la_valid & LA_PROJID &&
3071 attr->la_projid != i_projid_read(inode)) {
3072 if (!projid_valid(make_kprojid(&init_user_ns, attr->la_projid)))
3074 #ifdef HAVE_PROJECT_QUOTA
3075 rc = osd_transfer_project(inode, attr->la_projid, handle);
3080 CERROR("%s: quota transfer failed. Is project enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3081 osd_ino2name(inode), rc);
3088 static int osd_attr_set(const struct lu_env *env,
3089 struct dt_object *dt,
3090 const struct lu_attr *attr,
3091 struct thandle *handle)
3093 struct osd_object *obj = osd_dt_obj(dt);
3094 struct inode *inode;
3097 if (!dt_object_exists(dt))
3100 LASSERT(handle != NULL);
3101 LASSERT(!dt_object_remote(dt));
3102 LASSERT(osd_invariant(obj));
3104 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
3106 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING) &&
3107 !osd_obj2dev(obj)->od_is_ost) {
3108 struct osd_thread_info *oti = osd_oti_get(env);
3109 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
3110 struct lu_fid *fid1 = &oti->oti_fid;
3111 struct osd_inode_id *id = &oti->oti_id;
3112 struct iam_path_descr *ipd;
3113 struct iam_container *bag;
3114 struct osd_thandle *oh;
3117 fid_cpu_to_be(fid1, fid0);
3118 memset(id, 1, sizeof(*id));
3119 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
3120 fid0)->oi_dir.od_container;
3121 ipd = osd_idx_ipd_get(env, bag);
3122 if (unlikely(ipd == NULL))
3125 oh = container_of(handle, struct osd_thandle, ot_super);
3126 rc = iam_update(oh->ot_handle, bag,
3127 (const struct iam_key *)fid1,
3128 (const struct iam_rec *)id, ipd);
3129 osd_ipd_put(env, bag, ipd);
3130 return(rc > 0 ? 0 : rc);
3133 inode = obj->oo_inode;
3135 rc = osd_quota_transfer(inode, attr, handle);
3139 spin_lock(&obj->oo_guard);
3140 rc = osd_inode_setattr(env, inode, attr);
3141 spin_unlock(&obj->oo_guard);
3145 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3147 osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
3149 if (!(attr->la_valid & LA_FLAGS))
3152 /* Let's check if there are extra flags need to be set into LMA */
3153 if (attr->la_flags & LUSTRE_LMA_FL_MASKS) {
3154 struct osd_thread_info *info = osd_oti_get(env);
3155 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
3157 LASSERT(!obj->oo_pfid_in_lma);
3159 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
3160 &info->oti_ost_attrs);
3164 lma->lma_incompat |=
3165 lustre_to_lma_flags(attr->la_flags);
3166 lustre_lma_swab(lma);
3168 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
3170 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA,
3171 lma, sizeof(*lma), XATTR_REPLACE);
3173 struct osd_device *osd = osd_obj2dev(obj);
3175 CWARN("%s: set "DFID" lma flags %u failed: rc = %d\n",
3176 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)),
3177 lma->lma_incompat, rc);
3180 attr->la_flags & LUSTRE_LMA_FL_MASKS;
3182 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
3189 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
3190 struct osd_object *obj,
3191 const char *name, const int namelen)
3193 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
3196 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
3197 umode_t mode, struct dt_allocation_hint *hint,
3198 struct thandle *th, struct lu_attr *attr)
3201 struct osd_device *osd = osd_obj2dev(obj);
3202 struct osd_thandle *oth;
3203 struct dt_object *parent = NULL;
3204 struct inode *inode;
3205 struct iattr iattr = {
3206 .ia_valid = ATTR_UID | ATTR_GID |
3207 ATTR_CTIME | ATTR_MTIME | ATTR_ATIME,
3208 .ia_ctime.tv_sec = attr->la_ctime,
3209 .ia_mtime.tv_sec = attr->la_mtime,
3210 .ia_atime.tv_sec = attr->la_atime,
3211 .ia_uid = GLOBAL_ROOT_UID,
3212 .ia_gid = GLOBAL_ROOT_GID,
3214 const struct osd_timespec omit = { .tv_nsec = UTIME_OMIT };
3216 if (attr->la_valid & LA_UID)
3217 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
3218 if (attr->la_valid & LA_GID)
3219 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
3221 LINVRNT(osd_invariant(obj));
3222 LASSERT(obj->oo_inode == NULL);
3223 LASSERT(obj->oo_hl_head == NULL);
3225 if (S_ISDIR(mode) && ldiskfs_pdo) {
3227 ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
3228 if (obj->oo_hl_head == NULL)
3232 oth = container_of(th, struct osd_thandle, ot_super);
3233 LASSERT(oth->ot_handle->h_transaction != NULL);
3235 if (hint != NULL && hint->dah_parent != NULL &&
3236 !dt_object_remote(hint->dah_parent))
3237 parent = hint->dah_parent;
3239 /* if a time component is not valid set it to UTIME_OMIT */
3240 if (!(attr->la_valid & LA_CTIME))
3241 iattr.ia_ctime = omit;
3242 if (!(attr->la_valid & LA_MTIME))
3243 iattr.ia_mtime = omit;
3244 if (!(attr->la_valid & LA_ATIME))
3245 iattr.ia_atime = omit;
3247 inode = ldiskfs_create_inode(oth->ot_handle,
3248 parent ? osd_dt_obj(parent)->oo_inode :
3249 osd_sb(osd)->s_root->d_inode,
3251 if (!IS_ERR(inode)) {
3252 /* Do not update file c/mtime in ldiskfs. */
3253 inode->i_flags |= S_NOCMTIME;
3256 * For new created object, it must be consistent,
3257 * and it is unnecessary to scrub against it.
3259 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
3261 obj->oo_inode = inode;
3264 if (obj->oo_hl_head != NULL) {
3265 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
3266 obj->oo_hl_head = NULL;
3268 result = PTR_ERR(inode);
3270 LINVRNT(osd_invariant(obj));
3278 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
3279 struct lu_attr *attr,
3280 struct dt_allocation_hint *hint,
3281 struct dt_object_format *dof,
3285 struct osd_thandle *oth;
3286 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX | S_ISGID));
3288 LASSERT(S_ISDIR(attr->la_mode));
3290 oth = container_of(th, struct osd_thandle, ot_super);
3291 LASSERT(oth->ot_handle->h_transaction != NULL);
3292 if (fid_is_namespace_visible(lu_object_fid(&obj->oo_dt.do_lu)))
3293 obj->oo_dirent_count = 0;
3294 result = osd_mkfile(info, obj, mode, hint, th, attr);
3299 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
3300 struct lu_attr *attr,
3301 struct dt_allocation_hint *hint,
3302 struct dt_object_format *dof,
3306 struct osd_thandle *oth;
3307 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
3309 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
3311 LASSERT(S_ISREG(attr->la_mode));
3313 oth = container_of(th, struct osd_thandle, ot_super);
3314 LASSERT(oth->ot_handle->h_transaction != NULL);
3316 result = osd_mkfile(info, obj, mode, hint, th, attr);
3318 LASSERT(obj->oo_inode != NULL);
3319 if (feat->dif_flags & DT_IND_VARKEY)
3320 result = iam_lvar_create(obj->oo_inode,
3321 feat->dif_keysize_max,
3323 feat->dif_recsize_max,
3326 result = iam_lfix_create(obj->oo_inode,
3327 feat->dif_keysize_max,
3329 feat->dif_recsize_max,
3335 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
3336 struct lu_attr *attr,
3337 struct dt_allocation_hint *hint,
3338 struct dt_object_format *dof,
3341 LASSERT(S_ISREG(attr->la_mode));
3342 return osd_mkfile(info, obj, (attr->la_mode &
3343 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th,
3347 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
3348 struct lu_attr *attr,
3349 struct dt_allocation_hint *hint,
3350 struct dt_object_format *dof,
3353 LASSERT(S_ISLNK(attr->la_mode));
3354 return osd_mkfile(info, obj, (attr->la_mode &
3355 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th,
3359 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
3360 struct lu_attr *attr,
3361 struct dt_allocation_hint *hint,
3362 struct dt_object_format *dof,
3365 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
3368 LINVRNT(osd_invariant(obj));
3369 LASSERT(obj->oo_inode == NULL);
3370 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
3371 S_ISFIFO(mode) || S_ISSOCK(mode));
3373 result = osd_mkfile(info, obj, mode, hint, th, attr);
3375 LASSERT(obj->oo_inode != NULL);
3377 * This inode should be marked dirty for i_rdev. Currently
3378 * that is done in the osd_attr_init().
3380 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
3383 LINVRNT(osd_invariant(obj));
3387 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
3389 struct dt_allocation_hint *hint,
3390 struct dt_object_format *dof,
3393 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
3395 osd_obj_type_f result;
3411 result = osd_mk_index;
3421 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
3422 struct dt_object *parent, struct dt_object *child,
3427 ah->dah_parent = parent;
3429 if (parent != NULL && !dt_object_remote(parent)) {
3430 /* will help to find FID->ino at dt_insert("..") */
3431 struct osd_object *pobj = osd_dt_obj(parent);
3433 osd_idc_find_and_init(env, osd_obj2dev(pobj), pobj);
3437 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
3438 struct lu_attr *attr, struct dt_object_format *dof,
3439 struct thandle *handle)
3441 struct inode *inode = obj->oo_inode;
3442 __u64 valid = attr->la_valid;
3445 attr->la_valid &= ~(LA_TYPE | LA_MODE);
3447 if (dof->dof_type != DFT_NODE)
3448 attr->la_valid &= ~LA_RDEV;
3449 if ((valid & LA_ATIME) && (attr->la_atime == inode->i_atime.tv_sec))
3450 attr->la_valid &= ~LA_ATIME;
3451 if ((valid & LA_CTIME) && (attr->la_ctime == inode->i_ctime.tv_sec))
3452 attr->la_valid &= ~LA_CTIME;
3453 if ((valid & LA_MTIME) && (attr->la_mtime == inode->i_mtime.tv_sec))
3454 attr->la_valid &= ~LA_MTIME;
3456 result = osd_quota_transfer(inode, attr, handle);
3460 if (attr->la_valid != 0) {
3461 result = osd_inode_setattr(info->oti_env, inode, attr);
3463 * The osd_inode_setattr() should always succeed here. The
3464 * only error that could be returned is EDQUOT when we are
3465 * trying to change the UID or GID of the inode. However, this
3466 * should not happen since quota enforcement is no longer
3467 * enabled on ldiskfs (lquota takes care of it).
3469 LASSERTF(result == 0, "%d\n", result);
3470 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3473 attr->la_valid = valid;
3477 * Helper function for osd_create()
3479 * \retval 0, on success
3481 static int __osd_create(struct osd_thread_info *info, struct osd_object *obj,
3482 struct lu_attr *attr, struct dt_allocation_hint *hint,
3483 struct dt_object_format *dof, struct thandle *th)
3488 osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE);
3490 /* we drop umask so that permissions we pass are not affected */
3491 umask = current->fs->umask;
3492 current->fs->umask = 0;
3494 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
3496 if (likely(obj->oo_inode != NULL)) {
3497 LASSERT(obj->oo_inode->i_state & I_NEW);
3500 * Unlock the inode before attr initialization to avoid
3501 * unnecessary dqget operations. LU-6378
3503 unlock_new_inode(obj->oo_inode);
3506 if (likely(result == 0)) {
3507 osd_attr_init(info, obj, attr, dof, th);
3508 osd_object_init0(obj);
3511 /* restore previous umask value */
3512 current->fs->umask = umask;
3514 osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE);
3520 * Helper function for osd_create()
3522 * \retval 0, on success
3524 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
3525 const struct lu_fid *fid, struct thandle *th)
3527 struct osd_thread_info *info = osd_oti_get(env);
3528 struct osd_inode_id *id = &info->oti_id;
3529 struct osd_device *osd = osd_obj2dev(obj);
3530 struct osd_thandle *oh;
3533 LASSERT(obj->oo_inode != NULL);
3535 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_OI_ENOSPC))
3538 oh = container_of(th, struct osd_thandle, ot_super);
3539 LASSERT(oh->ot_handle);
3540 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3542 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
3543 rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle,
3544 OI_CHECK_FLD, NULL);
3545 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_DUPLICATE_MAP) && osd->od_is_ost) {
3546 struct lu_fid next_fid = *fid;
3548 /* insert next object in advance, and map to the same inode */
3550 if (next_fid.f_oid != 0) {
3551 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3552 osd_oi_insert(info, osd, &next_fid, id, oh->ot_handle,
3553 OI_CHECK_FLD, NULL);
3554 osd_trans_exec_check(env, th, OSD_OT_INSERT);
3558 osd_trans_exec_check(env, th, OSD_OT_INSERT);
3563 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
3564 u64 seq, struct lu_seq_range *range)
3566 struct seq_server_site *ss = osd_seq_site(osd);
3568 if (fid_seq_is_idif(seq)) {
3569 fld_range_set_ost(range);
3570 range->lsr_index = idif_ost_idx(seq);
3574 if (!fid_seq_in_fldb(seq)) {
3575 fld_range_set_mdt(range);
3578 * FIXME: If ss is NULL, it suppose not get lsr_index
3581 range->lsr_index = ss->ss_node_id;
3585 LASSERT(ss != NULL);
3586 fld_range_set_any(range);
3587 /* OSD will only do local fld lookup */
3588 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
3591 static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
3592 struct lu_attr *attr,
3593 struct dt_allocation_hint *hint,
3594 struct dt_object_format *dof,
3595 struct thandle *handle)
3597 struct osd_thandle *oh;
3598 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
3604 LASSERT(handle != NULL);
3606 oh = container_of(handle, struct osd_thandle, ot_super);
3607 LASSERT(oh->ot_handle == NULL);
3610 * EA object consumes more credits than regular object: osd_mk_index
3611 * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and
3612 * leaf_node, could involves the block, block bitmap, groups, GDT
3613 * change for each block, so add 4 * 2 credits in that case.
3615 * The default ACL initialization may consume an additional 16 blocks
3617 credits = osd_dto_credits_noquota[DTO_OBJECT_CREATE] +
3618 ((dof->dof_type == DFT_INDEX) ? 4 * 2 : 0);
3621 * While ldiskfs_new_inode() calls ldiskfs_init_acl() we have to add
3622 * credits for possible default ACL creation in new inode
3624 if (hint && hint->dah_acl_len)
3625 credits += osd_calc_bkmap_credits(sb, NULL, 0, -1,
3626 (hint->dah_acl_len + sb->s_blocksize - 1) >>
3627 sb->s_blocksize_bits);
3629 osd_trans_declare_op(env, oh, OSD_OT_CREATE, credits);
3632 * Reuse idle OI block may cause additional one OI block
3635 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3636 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
3637 if (CFS_FAIL_CHECK(OBD_FAIL_OSD_DUPLICATE_MAP))
3638 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3639 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
3641 /* will help to find FID->ino mapping at dt_insert() */
3642 rc = osd_idc_find_and_init(env, osd_obj2dev(osd_dt_obj(dt)),
3650 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid,
3651 attr->la_projid, 1, oh, osd_dt_obj(dt),
3652 NULL, OSD_QID_INODE);
3660 * Called to destroy on-disk representation of the object
3662 * Concurrency: must be locked
3664 static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
3667 struct osd_object *obj = osd_dt_obj(dt);
3668 struct inode *inode = obj->oo_inode;
3669 struct osd_thandle *oh;
3677 oh = container_of(th, struct osd_thandle, ot_super);
3678 LASSERT(oh->ot_handle == NULL);
3680 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
3681 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
3683 /* For removing agent entry */
3684 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu))
3685 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
3688 * Recycle idle OI leaf may cause additional three OI blocks
3691 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3692 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3693 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
3694 /* one less inode */
3695 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3696 i_projid_read(inode), -1, oh, obj, NULL,
3700 /* data to be truncated */
3701 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3702 i_projid_read(inode), 0, oh, obj, NULL,
3708 * will help to find FID->ino when this object is being
3711 rc = osd_idc_find_and_init(env, osd_obj2dev(obj), obj);
3716 static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
3719 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
3720 struct osd_object *obj = osd_dt_obj(dt);
3721 struct inode *inode = obj->oo_inode;
3722 struct osd_device *osd = osd_obj2dev(obj);
3723 struct osd_thandle *oh;
3728 oh = container_of(th, struct osd_thandle, ot_super);
3729 LASSERT(oh->ot_handle);
3731 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
3733 if (unlikely(fid_is_acct(fid)))
3736 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu)) {
3737 result = osd_delete_from_remote_parent(env, osd, obj, oh, true);
3739 CERROR("%s: remove agent entry "DFID": rc = %d\n",
3740 osd_name(osd), PFID(fid), result);
3743 if (S_ISDIR(inode->i_mode)) {
3744 if (inode->i_nlink > 2)
3745 CERROR("%s: directory "DFID" ino %lu link count is %u at unlink. run e2fsck to repair\n",
3746 osd_name(osd), PFID(fid), inode->i_ino,
3749 spin_lock(&obj->oo_guard);
3751 spin_unlock(&obj->oo_guard);
3752 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3755 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
3757 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
3759 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2))
3760 result = osd_oi_delete(osd_oti_get(env), osd, fid,
3761 oh->ot_handle, OI_CHECK_FLD);
3763 osd_trans_exec_check(env, th, OSD_OT_DESTROY);
3764 /* XXX: add to ext3 orphan list */
3765 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
3767 /* not needed in the cache anymore */
3768 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
3769 obj->oo_destroyed = 1;
3775 * Put the fid into lustre_mdt_attrs, and then place the structure
3776 * inode's ea. This fid should not be altered during the life time
3779 * \retval +ve, on success
3780 * \retval -ve, on error
3782 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
3784 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
3785 const struct lu_fid *fid, __u32 compat, __u32 incompat)
3787 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
3788 struct lustre_mdt_attrs *lma = &loa->loa_lma;
3793 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
3796 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
3799 lustre_loa_init(loa, fid, compat, incompat);
3800 lustre_loa_swab(loa, false);
3803 * For the OST device with 256 bytes inode size by default,
3804 * the PFID EA will be stored together with LMA EA to avoid
3805 * performance trouble. Otherwise the PFID EA can be stored
3806 * independently. LU-8998
3808 if ((compat & LMAC_FID_ON_OST) &&
3809 LDISKFS_INODE_SIZE(inode->i_sb) <= 256)
3810 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3811 sizeof(*loa), XATTR_CREATE);
3813 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3814 sizeof(*lma), XATTR_CREATE);
3816 * LMA may already exist, but we need to check that all the
3817 * desired compat/incompat flags have been added.
3819 if (unlikely(rc == -EEXIST)) {
3820 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
3821 XATTR_NAME_LMA, (void *)loa, sizeof(*loa));
3825 if (rc < sizeof(*lma))
3828 lustre_loa_swab(loa, true);
3829 if (lu_fid_eq(fid, &lma->lma_self_fid) &&
3830 ((compat == 0 && incompat == 0) ||
3831 (!(~lma->lma_compat & compat) &&
3832 !(~lma->lma_incompat & incompat))))
3835 lma->lma_self_fid = *fid;
3836 lma->lma_compat |= compat;
3837 lma->lma_incompat |= incompat;
3838 if (rc == sizeof(*lma)) {
3839 lustre_lma_swab(lma);
3840 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
3841 sizeof(*lma), XATTR_REPLACE);
3843 lustre_loa_swab(loa, false);
3844 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa,
3845 sizeof(*loa), XATTR_REPLACE);
3853 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
3854 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
3855 * To have compatilibility with 1.8 ldiskfs driver we need to have
3856 * magic number at start of fid data.
3857 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
3860 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
3861 const struct lu_fid *fid)
3863 if (!fid_is_namespace_visible(fid) ||
3864 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
3865 param->edp_magic = 0;
3869 param->edp_magic = LDISKFS_LUFID_MAGIC;
3870 param->edp_len = sizeof(struct lu_fid) + 1;
3871 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
3875 * Try to read the fid from inode ea into dt_rec.
3877 * \param fid object fid.
3879 * \retval 0 on success
3881 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
3882 __u32 ino, struct lu_fid *fid,
3883 struct osd_inode_id *id)
3885 struct osd_thread_info *info = osd_oti_get(env);
3886 struct inode *inode;
3890 osd_id_gen(id, ino, OSD_OII_NOGEN);
3891 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
3893 RETURN(PTR_ERR(inode));
3899 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
3901 struct inode *parent_dir,
3902 const struct lu_fid *dot_fid,
3903 const struct lu_fid *dot_dot_fid,
3904 struct osd_thandle *oth)
3906 struct ldiskfs_dentry_param *dot_ldp;
3907 struct ldiskfs_dentry_param *dot_dot_ldp;
3908 __u32 saved_nlink = dir->i_nlink;
3911 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_DOTDOT_ENOSPC))
3914 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3915 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3917 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3918 dot_ldp->edp_magic = 0;
3920 rc = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3921 dir, dot_ldp, dot_dot_ldp);
3923 * The ldiskfs_add_dot_dotdot() may dir->i_nlink as 2, then
3924 * the subseqent ref_add() will increase the dir->i_nlink
3925 * as 3. That is incorrect for new created directory.
3927 * It looks like hack, because we want to make the OSD API
3928 * to be order-independent for new created directory object
3929 * between dt_insert(..) and ref_add() operations.
3931 * Here, we only restore the in-RAM dir-inode's nlink attr,
3932 * becuase if the nlink attr is not 2, then there will be
3933 * ref_add() called following the dt_insert(..), such call
3934 * will make both the in-RAM and on-disk dir-inode's nlink
3935 * attr to be set as 2. LU-7447
3937 set_nlink(dir, saved_nlink);
3942 * Create an local agent inode for remote entry
3944 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
3945 struct osd_device *osd,
3946 struct osd_object *pobj,
3947 const struct lu_fid *fid,
3951 struct osd_thread_info *info = osd_oti_get(env);
3952 struct inode *local;
3953 struct osd_thandle *oh;
3954 struct iattr iattr = {
3955 .ia_valid = ATTR_UID | ATTR_GID |
3956 ATTR_CTIME | ATTR_MTIME | ATTR_ATIME,
3957 .ia_ctime.tv_nsec = UTIME_OMIT,
3958 .ia_mtime.tv_nsec = UTIME_OMIT,
3959 .ia_atime.tv_nsec = UTIME_OMIT,
3960 .ia_uid = GLOBAL_ROOT_UID,
3961 .ia_gid = GLOBAL_ROOT_GID,
3968 oh = container_of(th, struct osd_thandle, ot_super);
3969 LASSERT(oh->ot_handle->h_transaction != NULL);
3971 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode,
3973 if (IS_ERR(local)) {
3974 CERROR("%s: create local error %d\n", osd_name(osd),
3975 (int)PTR_ERR(local));
3980 * restore i_gid in case S_ISGID is set, we will inherit S_ISGID and set
3981 * correct gid on remote file, not agent here
3983 local->i_gid = current_fsgid();
3984 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
3986 /* e2fsck doesn't like empty symlinks. Store remote FID as symlink.
3987 * That gives e2fsck something to look at and be happy, and allows
3988 * debugging if we need to determine where this symlink came from.
3990 if (S_ISLNK(type)) {
3991 BUILD_BUG_ON(LDISKFS_N_BLOCKS * 4 < FID_LEN + 1);
3992 rc = scnprintf((char *)LDISKFS_I(local)->i_data,
3993 LDISKFS_N_BLOCKS * 4, DFID, PFID(fid));
3995 i_size_write(local, rc);
3996 LDISKFS_I(local)->i_disksize = rc;
3998 unlock_new_inode(local);
4000 /* Agent inode should not have project ID */
4001 #ifdef HAVE_PROJECT_QUOTA
4002 if (LDISKFS_I(pobj->oo_inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
4003 i_projid_read(pobj->oo_inode) != 0) {
4004 rc = osd_transfer_project(local, 0, th);
4006 CERROR("%s: quota transfer failed:. Is project quota enforcement enabled on the ldiskfs filesystem? rc = %d\n",
4007 osd_ino2name(local), rc);
4008 RETURN(ERR_PTR(rc));
4012 /* Set special LMA flag for local agent inode */
4013 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
4015 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
4016 osd_name(osd), PFID(fid), rc);
4017 RETURN(ERR_PTR(rc));
4023 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
4024 lu_object_fid(&pobj->oo_dt.do_lu),
4027 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
4028 osd_name(osd), PFID(fid), rc);
4029 RETURN(ERR_PTR(rc));
4036 * when direntry is deleted, we have to take care of possible agent inode
4037 * referenced by that. unfortunately we can't do this at that point:
4038 * iget() within a running transaction leads to deadlock and we better do
4039 * not call that every delete declaration to save performance. so we put
4040 * a potention agent inode on a list and process that once the transaction
4041 * is over. Notice it's not any worse in terms of real orphans as regular
4042 * object destroy doesn't put inodes on the on-disk orphan list. this should
4043 * be addressed separately
4045 static int osd_schedule_agent_inode_removal(const struct lu_env *env,
4046 struct osd_thandle *oh,
4049 struct osd_device *osd = osd_dt_dev(oh->ot_super.th_dev);
4050 struct osd_obj_orphan *oor;
4057 oor->oor_env = (struct lu_env *)env;
4058 spin_lock(&osd->od_osfs_lock);
4059 list_add(&oor->oor_list, &osd->od_orphan_list);
4060 spin_unlock(&osd->od_osfs_lock);
4062 oh->ot_remove_agents = 1;
4068 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
4069 struct osd_device *osd)
4071 struct osd_thread_info *info = osd_oti_get(env);
4072 struct osd_obj_orphan *oor, *tmp;
4073 struct osd_inode_id id;
4075 struct inode *inode;
4080 spin_lock(&osd->od_osfs_lock);
4081 list_for_each_entry_safe(oor, tmp, &osd->od_orphan_list, oor_list) {
4082 if (oor->oor_env == env)
4083 list_move(&oor->oor_list, &list);
4085 spin_unlock(&osd->od_osfs_lock);
4087 list_for_each_entry_safe(oor, tmp, &list, oor_list) {
4091 list_del(&oor->oor_list);
4094 osd_id_gen(&id, ino, OSD_OII_NOGEN);
4095 inode = osd_iget_fid(info, osd, &id, &fid);
4099 if (!osd_remote_fid(env, osd, &fid)) {
4104 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC, 1);
4106 mark_inode_dirty(inode);
4107 ldiskfs_journal_stop(jh);
4115 * OSD layer object create function for OST objects (b=11826).
4117 * The FID is inserted into inode xattr here.
4119 * \retval 0, on success
4120 * \retval -ve, on error
4122 static int osd_create(const struct lu_env *env, struct dt_object *dt,
4123 struct lu_attr *attr, struct dt_allocation_hint *hint,
4124 struct dt_object_format *dof, struct thandle *th)
4126 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
4127 struct osd_object *obj = osd_dt_obj(dt);
4128 struct osd_thread_info *info = osd_oti_get(env);
4129 int result, on_ost = 0;
4133 if (dt_object_exists(dt))
4136 LINVRNT(osd_invariant(obj));
4137 LASSERT(!dt_object_remote(dt));
4138 LASSERT(osd_is_write_locked(env, obj));
4139 LASSERT(th != NULL);
4141 if (unlikely(fid_is_acct(fid)))
4143 * Quota files can't be created from the kernel any more,
4144 * 'tune2fs -O quota' will take care of creating them
4148 result = __osd_create(info, obj, attr, hint, dof, th);
4150 if (fid_is_idif(fid) &&
4151 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
4152 struct lu_fid *tfid = &info->oti_fid;
4153 struct ost_id *oi = &info->oti_ostid;
4155 fid_to_ostid(fid, oi);
4156 ostid_to_fid(tfid, oi, 0);
4158 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
4159 LMAC_FID_ON_OST, 0);
4161 on_ost = fid_is_on_ost(info, osd_obj2dev(obj),
4163 result = osd_ea_fid_set(info, obj->oo_inode, fid,
4164 on_ost ? LMAC_FID_ON_OST : 0,
4167 if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
4168 obj->oo_dt.do_body_ops = &osd_body_ops;
4171 if (!result && !CFS_FAIL_CHECK(OBD_FAIL_OSD_NO_OI_ENTRY)) {
4172 struct inode *inode = obj->oo_inode;
4174 result = __osd_oi_insert(env, obj, fid, th);
4175 if (result && inode) {
4176 spin_lock(&obj->oo_guard);
4178 spin_unlock(&obj->oo_guard);
4179 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4180 ldiskfs_set_inode_state(inode,
4181 LDISKFS_STATE_LUSTRE_DESTROY);
4183 obj->oo_inode = NULL;
4188 * a small optimization - dt_insert() isn't usually applied
4189 * to OST objects, so we don't need to cache OI mapping for
4192 if (result == 0 && on_ost == 0) {
4193 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4195 result = osd_idc_find_and_init(env, osd, obj);
4196 LASSERT(result == 0);
4199 LASSERT(ergo(result == 0,
4200 dt_object_exists(dt) && !dt_object_remote(dt)));
4201 LINVRNT(osd_invariant(obj));
4205 static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
4206 struct thandle *handle)
4208 struct osd_thandle *oh;
4211 /* it's possible that object doesn't exist yet */
4212 LASSERT(handle != NULL);
4214 oh = container_of(handle, struct osd_thandle, ot_super);
4215 LASSERT(oh->ot_handle == NULL);
4217 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
4218 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
4220 rc = osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev),
4227 * Concurrency: @dt is write locked.
4229 static int osd_ref_add(const struct lu_env *env, struct dt_object *dt,
4232 struct osd_object *obj = osd_dt_obj(dt);
4233 struct inode *inode = obj->oo_inode;
4234 struct osd_thandle *oh;
4237 if (!dt_object_exists(dt) || obj->oo_destroyed)
4240 LINVRNT(osd_invariant(obj));
4241 LASSERT(!dt_object_remote(dt));
4242 LASSERT(osd_is_write_locked(env, obj));
4243 LASSERT(th != NULL);
4245 oh = container_of(th, struct osd_thandle, ot_super);
4246 LASSERT(oh->ot_handle != NULL);
4248 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
4250 CDEBUG(D_INODE, DFID" increase nlink %d\n",
4251 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
4253 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
4254 * (65000) subdirectories by storing "1" in i_nlink if the link count
4255 * would otherwise overflow. Directory tranversal tools understand
4256 * that (st_nlink == 1) indicates that the filesystem dose not track
4257 * hard links count on the directory, and will not abort subdirectory
4258 * scanning early once (st_nlink - 2) subdirs have been found.
4260 * This also has to properly handle the case of inodes with nlink == 0
4261 * in case they are being linked into the PENDING directory
4263 spin_lock(&obj->oo_guard);
4264 if (unlikely(inode->i_nlink == 0))
4265 /* inc_nlink from 0 may cause WARN_ON */
4266 set_nlink(inode, 1);
4268 osd_ldiskfs_inc_count(oh->ot_handle, inode);
4269 if (!S_ISDIR(inode->i_mode))
4270 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
4272 spin_unlock(&obj->oo_guard);
4274 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4275 LINVRNT(osd_invariant(obj));
4277 osd_trans_exec_check(env, th, OSD_OT_REF_ADD);
4282 static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
4283 struct thandle *handle)
4285 struct osd_thandle *oh;
4287 if (!dt_object_exists(dt))
4290 LASSERT(!dt_object_remote(dt));
4291 LASSERT(handle != NULL);
4293 oh = container_of(handle, struct osd_thandle, ot_super);
4294 LASSERT(oh->ot_handle == NULL);
4296 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
4297 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
4303 * Concurrency: @dt is write locked.
4305 static int osd_ref_del(const struct lu_env *env, struct dt_object *dt,
4308 struct osd_object *obj = osd_dt_obj(dt);
4309 struct inode *inode = obj->oo_inode;
4310 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4311 struct osd_thandle *oh;
4313 if (!dt_object_exists(dt))
4316 LINVRNT(osd_invariant(obj));
4317 LASSERT(!dt_object_remote(dt));
4318 LASSERT(osd_is_write_locked(env, obj));
4319 LASSERT(th != NULL);
4321 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_REF_DEL))
4324 oh = container_of(th, struct osd_thandle, ot_super);
4325 LASSERT(oh->ot_handle != NULL);
4327 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
4329 spin_lock(&obj->oo_guard);
4331 * That can be result of upgrade from old Lustre version and
4332 * applied only to local files. Just skip this ref_del call.
4333 * ext4_unlink() only treats this as a warning, don't LASSERT here.
4335 if (inode->i_nlink == 0) {
4336 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
4337 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
4338 ", maybe an upgraded file? (LU-3915)\n",
4339 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
4340 spin_unlock(&obj->oo_guard);
4344 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
4345 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
4347 osd_ldiskfs_dec_count(oh->ot_handle, inode);
4348 spin_unlock(&obj->oo_guard);
4350 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4351 LINVRNT(osd_invariant(obj));
4353 osd_trans_exec_check(env, th, OSD_OT_REF_DEL);
4359 * Concurrency: @dt is read locked.
4361 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
4362 struct lu_buf *buf, const char *name)
4364 struct osd_object *obj = osd_dt_obj(dt);
4365 struct inode *inode = obj->oo_inode;
4366 struct osd_thread_info *info = osd_oti_get(env);
4367 struct dentry *dentry = &info->oti_obj_dentry;
4368 bool cache_xattr = false;
4373 /* version get is not real XATTR but uses xattr API */
4374 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4375 dt_obj_version_t *ver = buf->lb_buf;
4378 * for version we are just using xattr API but change inode
4381 if (buf->lb_len == 0)
4382 return sizeof(dt_obj_version_t);
4384 if (buf->lb_len < sizeof(dt_obj_version_t))
4387 CDEBUG(D_INODE, "Get version %#llx for inode %lu\n",
4388 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
4390 *ver = LDISKFS_I(inode)->i_fs_version;
4392 return sizeof(dt_obj_version_t);
4395 if (!dt_object_exists(dt))
4398 LASSERT(!dt_object_remote(dt));
4399 LASSERT(inode->i_op != NULL);
4400 #ifdef HAVE_IOP_XATTR
4401 LASSERT(inode->i_op->getxattr != NULL);
4404 if (strcmp(name, XATTR_NAME_LOV) == 0 ||
4405 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
4409 rc = osd_oxc_get(obj, name, buf);
4414 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
4415 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4416 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4417 struct filter_fid *ff;
4418 struct ost_layout *ol;
4420 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
4424 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
4427 if (buf->lb_len == 0 || !buf->lb_buf)
4430 if (buf->lb_len < rc)
4434 ol = &ff->ff_layout;
4435 ol->ol_stripe_count = cpu_to_le32(loa->loa_parent_fid.f_ver >>
4436 PFID_STRIPE_IDX_BITS);
4437 ol->ol_stripe_size = cpu_to_le32(loa->loa_stripe_size);
4438 loa->loa_parent_fid.f_ver &= PFID_STRIPE_COUNT_MASK;
4439 fid_cpu_to_le(&ff->ff_parent, &loa->loa_parent_fid);
4440 if (lma->lma_compat & LMAC_COMP_INFO) {
4441 ol->ol_comp_start = cpu_to_le64(loa->loa_comp_start);
4442 ol->ol_comp_end = cpu_to_le64(loa->loa_comp_end);
4443 ol->ol_comp_id = cpu_to_le32(loa->loa_comp_id);
4445 ol->ol_comp_start = 0;
4446 ol->ol_comp_end = 0;
4450 /* Get enc context xattr directly from ldiskfs instead of going
4451 * through the VFS, as there is no xattr handler for
4454 if (strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
4455 rc = ldiskfs_xattr_get(inode,
4456 LDISKFS_XATTR_INDEX_ENCRYPTION,
4457 LDISKFS_XATTR_NAME_ENCRYPTION_CONTEXT,
4458 buf->lb_buf, buf->lb_len);
4460 rc = __osd_xattr_get(inode, dentry, name,
4461 buf->lb_buf, buf->lb_len);
4465 if (rc == -ENOENT || rc == -ENODATA)
4466 osd_oxc_add(obj, name, NULL, 0);
4467 else if (rc > 0 && buf->lb_buf != NULL)
4468 osd_oxc_add(obj, name, buf->lb_buf, rc);
4474 static int osd_declare_xattr_set(const struct lu_env *env,
4475 struct dt_object *dt,
4476 const struct lu_buf *buf, const char *name,
4477 int fl, struct thandle *handle)
4479 struct osd_thandle *oh;
4481 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
4483 LASSERT(handle != NULL);
4485 oh = container_of(handle, struct osd_thandle, ot_super);
4486 LASSERT(oh->ot_handle == NULL);
4488 if (strcmp(name, XATTR_NAME_LMA) == 0) {
4490 * For non-upgrading case, the LMA is set first and
4491 * usually fit inode. But for upgrade case, the LMA
4492 * may be in another separated EA block.
4494 if (dt_object_exists(dt)) {
4495 if (fl == LU_XATTR_REPLACE)
4500 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4502 } else if (strcmp(name, XATTR_NAME_FID) == 0) {
4503 /* We may need to delete the old PFID EA. */
4504 credits = LDISKFS_MAXQUOTAS_DEL_BLOCKS(sb);
4505 if (fl == LU_XATTR_REPLACE)
4511 * If some name entry resides on remote MDT, then will create
4512 * agent entry under remote parent. On the other hand, if the
4513 * remote entry will be removed, then related agent entry may
4514 * need to be removed from the remote parent. So there may be
4515 * kinds of cases, let's declare enough credits. The credits
4516 * for create agent entry is enough for remove case.
4518 if (strcmp(name, XATTR_NAME_LINK) == 0) {
4519 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
4520 if (dt_object_exists(dt))
4521 credits += 1; /* For updating LMA */
4525 credits += osd_dto_credits_noquota[DTO_XATTR_SET];
4530 if (buf->lb_buf == NULL && dt_object_exists(dt)) {
4532 * learn xattr size from osd_xattr_get if
4533 * attribute has not been read yet
4535 buflen = __osd_xattr_get(
4536 osd_dt_obj(dt)->oo_inode,
4537 &osd_oti_get(env)->oti_obj_dentry,
4542 buflen = buf->lb_len;
4545 if (buflen > sb->s_blocksize) {
4546 credits += osd_calc_bkmap_credits(
4548 (buflen + sb->s_blocksize - 1) >>
4549 sb->s_blocksize_bits);
4553 * xattr set may involve inode quota change, reserve credits for
4554 * dquot_initialize()
4556 credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
4559 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
4564 static int osd_xattr_set_pfid(const struct lu_env *env, struct osd_object *obj,
4565 const struct lu_buf *buf, int fl,
4566 struct thandle *handle)
4568 struct osd_thread_info *info = osd_oti_get(env);
4569 struct dentry *dentry = &info->oti_obj_dentry;
4570 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4571 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4572 struct inode *inode = obj->oo_inode;
4573 struct filter_fid *ff = buf->lb_buf;
4574 struct ost_layout *ol = &ff->ff_layout;
4575 int flags = XATTR_REPLACE;
4580 if (buf->lb_len != sizeof(*ff) && buf->lb_len != sizeof(struct lu_fid))
4583 rc = osd_get_lma(info, inode, dentry, loa);
4584 if (rc == -ENODATA) {
4585 /* Usually for upgarding from old device */
4586 lustre_loa_init(loa, lu_object_fid(&obj->oo_dt.do_lu),
4587 LMAC_FID_ON_OST, 0);
4588 flags = XATTR_CREATE;
4593 if (!rc && lma->lma_compat & LMAC_STRIPE_INFO) {
4594 if ((fl & LU_XATTR_CREATE) && !(fl & LU_XATTR_REPLACE))
4597 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256) {
4598 /* Separate PFID EA from LMA */
4599 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4600 lustre_lma_swab(lma);
4601 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4602 sizeof(*lma), XATTR_REPLACE);
4604 obj->oo_pfid_in_lma = 0;
4605 rc = LU_XATTR_CREATE;
4611 if (LDISKFS_INODE_SIZE(inode->i_sb) > 256)
4615 * Old client does not send stripe information,
4616 * then store the PFID EA on disk separatedly.
4618 if (unlikely(buf->lb_len == sizeof(struct lu_fid) ||
4619 ol->ol_stripe_size == 0))
4622 /* Remove old PFID EA entry firstly. */
4623 dquot_initialize(inode);
4624 rc = ll_vfs_removexattr(dentry, inode, XATTR_NAME_FID);
4625 if (rc == -ENODATA) {
4626 /* XATTR_NAME_FID is already absent */
4633 fid_le_to_cpu(&loa->loa_parent_fid, &ff->ff_parent);
4634 if (likely(ol->ol_stripe_size != 0)) {
4635 loa->loa_parent_fid.f_ver |= le32_to_cpu(ol->ol_stripe_count) <<
4636 PFID_STRIPE_IDX_BITS;
4637 loa->loa_stripe_size = le32_to_cpu(ol->ol_stripe_size);
4638 lma->lma_compat |= LMAC_STRIPE_INFO;
4639 if (ol->ol_comp_id != 0) {
4640 loa->loa_comp_id = le32_to_cpu(ol->ol_comp_id);
4641 loa->loa_comp_start = le64_to_cpu(ol->ol_comp_start);
4642 loa->loa_comp_end = le64_to_cpu(ol->ol_comp_end);
4643 lma->lma_compat |= LMAC_COMP_INFO;
4647 lustre_loa_swab(loa, false);
4649 /* Store the PFID EA inside LMA. */
4650 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, loa, sizeof(*loa),
4653 obj->oo_pfid_in_lma = 1;
4659 * In DNE environment, the object (in spite of regular file or directory)
4660 * and its name entry may reside on different MDTs. Under such case, we will
4661 * create an agent entry on the MDT where the object resides. The agent entry
4662 * references the object locally, that makes the object to be visible to the
4663 * userspace when mounted as 'ldiskfs' directly. Then the userspace tools,
4664 * such as 'tar' can handle the object properly.
4666 * We handle the agent entry during set linkEA that is the common interface
4667 * for both regular file and directroy, can handle kinds of cases, such as
4668 * create/link/unlink/rename, and so on.
4670 * NOTE: we can NOT do that when ea_{insert,delete} that is only for directory.
4672 * XXX: There are two known issues:
4673 * 1. For one object, we will create at most one agent entry even if there
4674 * may be more than one cross-MDTs hard links on the object. So the local
4675 * e2fsck may claim that the object's nlink is larger than the name entries
4676 * that reference such inode. And in further, the e2fsck will fix the nlink
4677 * attribute to match the local references. Then it will cause the object's
4678 * nlink attribute to be inconsistent with the global references. it is bad
4679 * but not fatal. The ref_del() can handle the zero-referenced case. On the
4680 * other hand, the global namespace LFSCK can repair the object's attribute
4681 * according to the linkEA.
4682 * 2. There may be too many hard links on the object as to its linkEA overflow,
4683 * then the linkEA entry for cross-MDTs reference may be discarded. If such
4684 * case happened, then at this point, we do not know whether there are some
4685 * cross-MDTs reference. But there are local references, it guarantees that
4686 * object is visible to userspace when mounted as 'ldiskfs'. That is enough.
4688 static int osd_xattr_handle_linkea(const struct lu_env *env,
4689 struct osd_device *osd,
4690 struct osd_object *obj,
4691 const struct lu_buf *buf,
4692 struct thandle *handle)
4694 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
4695 struct lu_fid *tfid = &osd_oti_get(env)->oti_fid3;
4696 struct linkea_data ldata = { .ld_buf = (struct lu_buf *)buf };
4697 struct lu_name tmpname;
4698 struct osd_thandle *oh;
4700 bool remote = false;
4704 oh = container_of(handle, struct osd_thandle, ot_super);
4705 LASSERT(oh->ot_handle != NULL);
4707 rc = linkea_init_with_rec(&ldata);
4709 linkea_first_entry(&ldata);
4710 while (ldata.ld_lee != NULL && !remote) {
4711 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
4713 if (osd_remote_fid(env, osd, tfid) > 0)
4716 linkea_next_entry(&ldata);
4718 } else if (rc == -ENODATA) {
4724 if (lu_object_has_agent_entry(&obj->oo_dt.do_lu) && !remote) {
4725 rc = osd_delete_from_remote_parent(env, osd, obj, oh, false);
4727 CERROR("%s: failed to remove agent entry for "DFID
4728 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4729 } else if (!lu_object_has_agent_entry(&obj->oo_dt.do_lu) && remote) {
4730 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4732 CERROR("%s: failed to create agent entry for "DFID
4733 ": rc = %d\n", osd_name(osd), PFID(fid), rc);
4740 * Concurrency: @dt is write locked.
4742 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
4743 const struct lu_buf *buf, const char *name, int fl,
4744 struct thandle *handle)
4746 struct osd_object *obj = osd_dt_obj(dt);
4747 struct osd_device *osd = osd_obj2dev(obj);
4748 struct inode *inode = obj->oo_inode;
4749 struct osd_thread_info *info = osd_oti_get(env);
4759 /* version set is not real XATTR */
4760 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
4761 dt_obj_version_t *version = buf->lb_buf;
4764 * for version we are just using xattr API but change inode
4767 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
4769 CDEBUG(D_INODE, "Set version %#llx (old %#llx) for inode %lu\n",
4770 *version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
4772 LDISKFS_I(inode)->i_fs_version = *version;
4774 * Version is set after all inode operations are finished,
4775 * so we should mark it dirty here
4777 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
4782 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
4783 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
4786 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4789 * For the OST device with 256 bytes inode size by default,
4790 * the PFID EA will be stored together with LMA EA to avoid
4791 * performance trouble. Otherwise the PFID EA can be stored
4792 * independently. LU-8998
4794 if (strcmp(name, XATTR_NAME_FID) == 0 && osd->od_is_ost &&
4795 (LDISKFS_INODE_SIZE(inode->i_sb) <= 256 || obj->oo_pfid_in_lma)) {
4796 LASSERT(buf->lb_buf);
4798 fl = osd_xattr_set_pfid(env, obj, buf, fl, handle);
4801 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
4802 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
4803 struct lustre_mdt_attrs *lma = &loa->loa_lma;
4805 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
4809 lma->lma_incompat |= LMAI_STRIPED;
4810 lustre_lma_swab(lma);
4811 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4812 sizeof(*lma), XATTR_REPLACE);
4815 } else if (strcmp(name, XATTR_NAME_LINK) == 0) {
4816 LASSERT(!osd->od_is_ost);
4818 rc = osd_xattr_handle_linkea(env, osd, obj, buf, handle);
4823 if (fl & LU_XATTR_REPLACE)
4824 fs_flags |= XATTR_REPLACE;
4826 if (fl & LU_XATTR_CREATE)
4827 fs_flags |= XATTR_CREATE;
4829 if (strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
4830 /* Set enc context xattr directly in ldiskfs instead of going
4831 * through the VFS, as there is no xattr handler for
4834 struct osd_thandle *oth = container_of(handle,
4838 if (!oth->ot_handle)
4839 /* this should be already part of a transaction */
4842 rc = ldiskfs_xattr_set_handle(oth->ot_handle, inode,
4843 LDISKFS_XATTR_INDEX_ENCRYPTION,
4844 LDISKFS_XATTR_NAME_ENCRYPTION_CONTEXT,
4845 buf->lb_buf, len, fs_flags);
4847 rc = __osd_xattr_set(info, inode, name,
4848 buf->lb_buf, len, fs_flags);
4850 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4853 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4854 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4855 osd_oxc_add(obj, name, buf->lb_buf, buf->lb_len);
4861 * Concurrency: @dt is read locked.
4863 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
4864 const struct lu_buf *buf)
4866 struct osd_object *obj = osd_dt_obj(dt);
4867 struct osd_device *dev = osd_obj2dev(obj);
4868 struct inode *inode = obj->oo_inode;
4869 struct osd_thread_info *info = osd_oti_get(env);
4870 struct dentry *dentry = &info->oti_obj_dentry;
4873 if (!dt_object_exists(dt))
4876 LASSERT(!dt_object_remote(dt));
4877 LASSERT(inode->i_op != NULL);
4878 LASSERT(inode->i_op->listxattr != NULL);
4880 dentry->d_inode = inode;
4881 dentry->d_sb = inode->i_sb;
4882 rc = inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
4884 if (rc < 0 || buf->lb_buf == NULL)
4887 /* Hide virtual project ID xattr from list if disabled */
4888 if (!dev->od_enable_projid_xattr) {
4889 char *end = (char *)buf->lb_buf + rc;
4890 char *p = buf->lb_buf;
4893 char *next = p + strlen(p) + 1;
4895 if (strcmp(p, XATTR_NAME_PROJID) == 0) {
4897 memmove(p, next, end - next);
4909 static int osd_declare_xattr_del(const struct lu_env *env,
4910 struct dt_object *dt, const char *name,
4911 struct thandle *handle)
4913 struct osd_thandle *oh;
4914 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
4916 LASSERT(!dt_object_remote(dt));
4917 LASSERT(handle != NULL);
4919 oh = container_of(handle, struct osd_thandle, ot_super);
4920 LASSERT(oh->ot_handle == NULL);
4922 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
4923 osd_dto_credits_noquota[DTO_XATTR_SET]);
4925 * xattr del may involve inode quota change, reserve credits for
4926 * dquot_initialize()
4928 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
4934 * Concurrency: @dt is write locked.
4936 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
4937 const char *name, struct thandle *handle)
4939 struct osd_object *obj = osd_dt_obj(dt);
4940 struct inode *inode = obj->oo_inode;
4941 struct osd_thread_info *info = osd_oti_get(env);
4942 struct dentry *dentry = &info->oti_obj_dentry;
4945 if (!dt_object_exists(dt))
4948 LASSERT(!dt_object_remote(dt));
4949 LASSERT(inode->i_op != NULL);
4950 LASSERT(handle != NULL);
4951 #ifdef HAVE_IOP_XATTR
4952 LASSERT(inode->i_op->removexattr != NULL);
4955 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
4957 if (strcmp(name, XATTR_NAME_FID) == 0 && obj->oo_pfid_in_lma) {
4958 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
4960 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
4961 &info->oti_ost_attrs);
4963 LASSERT(lma->lma_compat & LMAC_STRIPE_INFO);
4965 lma->lma_compat &= ~(LMAC_STRIPE_INFO | LMAC_COMP_INFO);
4966 lustre_lma_swab(lma);
4967 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
4968 sizeof(*lma), XATTR_REPLACE);
4970 obj->oo_pfid_in_lma = 0;
4973 dquot_initialize(inode);
4974 dentry->d_inode = inode;
4975 dentry->d_sb = inode->i_sb;
4976 rc = ll_vfs_removexattr(dentry, inode, name);
4979 osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
4982 (strcmp(name, XATTR_NAME_LOV) == 0 ||
4983 strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0))
4984 osd_oxc_del(obj, name);
4989 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
4990 __u64 start, __u64 end)
4992 struct osd_object *obj = osd_dt_obj(dt);
4993 struct osd_device *dev = osd_obj2dev(obj);
4994 struct inode *inode = obj->oo_inode;
4999 file = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
5002 RETURN(PTR_ERR(file));
5004 file->f_mode |= FMODE_64BITHASH;
5005 rc = vfs_fsync_range(file, start, end, 0);
5012 static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
5017 static bool osd_check_stale(struct dt_object *dt)
5025 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
5026 const struct dt_index_features *feat)
5028 struct iam_descr *descr;
5030 if (osd_object_is_root(o))
5031 return feat == &dt_directory_features;
5033 LASSERT(o->oo_dir != NULL);
5035 descr = o->oo_dir->od_container.ic_descr;
5036 if (feat == &dt_directory_features) {
5037 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
5042 return feat->dif_keysize_min <= descr->id_key_size &&
5043 descr->id_key_size <= feat->dif_keysize_max &&
5044 feat->dif_recsize_min <= descr->id_rec_size &&
5045 descr->id_rec_size <= feat->dif_recsize_max &&
5046 !(feat->dif_flags & (DT_IND_VARKEY |
5047 DT_IND_VARREC | DT_IND_NONUNQ)) &&
5048 ergo(feat->dif_flags & DT_IND_UPDATE,
5049 1 /* XXX check that object (and fs) is writable */);
5053 static int osd_iam_container_init(const struct lu_env *env,
5054 struct osd_object *obj,
5055 struct osd_directory *dir)
5057 struct iam_container *bag = &dir->od_container;
5060 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
5064 result = iam_container_setup(bag);
5066 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
5068 iam_container_fini(bag);
5075 * Concurrency: no external locking is necessary.
5077 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
5078 const struct dt_index_features *feat)
5082 struct osd_object *obj = osd_dt_obj(dt);
5084 LINVRNT(osd_invariant(obj));
5086 if (osd_object_is_root(obj)) {
5087 dt->do_index_ops = &osd_index_ea_ops;
5089 } else if (feat == &dt_directory_features) {
5090 dt->do_index_ops = &osd_index_ea_ops;
5091 if (obj->oo_inode == NULL || S_ISDIR(obj->oo_inode->i_mode))
5096 } else if (unlikely(feat == &dt_otable_features)) {
5097 dt->do_index_ops = &osd_otable_ops;
5099 } else if (unlikely(feat == &dt_acct_features)) {
5100 dt->do_index_ops = &osd_acct_index_ops;
5103 } else if (!osd_has_index(obj)) {
5104 struct osd_directory *dir;
5105 struct osd_device *osd = osd_obj2dev(obj);
5106 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
5111 spin_lock(&obj->oo_guard);
5112 if (obj->oo_dir == NULL)
5116 * Concurrent thread allocated container data.
5119 spin_unlock(&obj->oo_guard);
5121 * Now, that we have container data, serialize its
5124 down_write(&obj->oo_ext_idx_sem);
5126 * recheck under lock.
5129 if (osd_has_index(obj)) {
5134 result = osd_iam_container_init(env, obj, obj->oo_dir);
5135 if (result || feat == &dt_lfsck_namespace_features ||
5136 feat == &dt_lfsck_layout_orphan_features ||
5137 feat == &dt_lfsck_layout_dangling_features)
5140 result = osd_index_register(osd, fid,
5141 feat->dif_keysize_max,
5142 feat->dif_recsize_max);
5144 CWARN("%s: failed to register index "
5146 osd_name(osd), PFID(fid), result);
5147 else if (result > 0)
5150 CDEBUG(D_LFSCK, "%s: index object "DFID
5151 " (%d/%d) registered\n",
5152 osd_name(osd), PFID(fid),
5153 (int)feat->dif_keysize_max,
5154 (int)feat->dif_recsize_max);
5157 up_write(&obj->oo_ext_idx_sem);
5165 if (result == 0 && skip_iam == 0) {
5166 if (!osd_iam_index_probe(env, obj, feat))
5169 LINVRNT(osd_invariant(obj));
5174 static int osd_otable_it_attr_get(const struct lu_env *env,
5175 struct dt_object *dt,
5176 struct lu_attr *attr)
5182 static const struct dt_object_operations osd_obj_ops = {
5183 .do_read_lock = osd_read_lock,
5184 .do_write_lock = osd_write_lock,
5185 .do_read_unlock = osd_read_unlock,
5186 .do_write_unlock = osd_write_unlock,
5187 .do_write_locked = osd_write_locked,
5188 .do_attr_get = osd_attr_get,
5189 .do_declare_attr_set = osd_declare_attr_set,
5190 .do_attr_set = osd_attr_set,
5191 .do_ah_init = osd_ah_init,
5192 .do_declare_create = osd_declare_create,
5193 .do_create = osd_create,
5194 .do_declare_destroy = osd_declare_destroy,
5195 .do_destroy = osd_destroy,
5196 .do_index_try = osd_index_try,
5197 .do_declare_ref_add = osd_declare_ref_add,
5198 .do_ref_add = osd_ref_add,
5199 .do_declare_ref_del = osd_declare_ref_del,
5200 .do_ref_del = osd_ref_del,
5201 .do_xattr_get = osd_xattr_get,
5202 .do_declare_xattr_set = osd_declare_xattr_set,
5203 .do_xattr_set = osd_xattr_set,
5204 .do_declare_xattr_del = osd_declare_xattr_del,
5205 .do_xattr_del = osd_xattr_del,
5206 .do_xattr_list = osd_xattr_list,
5207 .do_object_sync = osd_object_sync,
5208 .do_invalidate = osd_invalidate,
5209 .do_check_stale = osd_check_stale,
5212 static const struct dt_object_operations osd_obj_otable_it_ops = {
5213 .do_attr_get = osd_otable_it_attr_get,
5214 .do_index_try = osd_index_try,
5217 static int osd_index_declare_iam_delete(const struct lu_env *env,
5218 struct dt_object *dt,
5219 const struct dt_key *key,
5220 struct thandle *handle)
5222 struct osd_thandle *oh;
5224 oh = container_of(handle, struct osd_thandle, ot_super);
5225 LASSERT(oh->ot_handle == NULL);
5227 /* Recycle may cause additional three blocks to be changed. */
5228 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
5229 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
5235 * delete a (key, value) pair from index \a dt specified by \a key
5237 * \param dt osd index object
5238 * \param key key for index
5239 * \param rec record reference
5240 * \param handle transaction handler
5243 * \retval -ve failure
5245 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
5246 const struct dt_key *key,
5247 struct thandle *handle)
5249 struct osd_thread_info *oti = osd_oti_get(env);
5250 struct osd_object *obj = osd_dt_obj(dt);
5251 struct osd_thandle *oh;
5252 struct iam_path_descr *ipd;
5253 struct iam_container *bag = &obj->oo_dir->od_container;
5258 if (!dt_object_exists(dt))
5261 LINVRNT(osd_invariant(obj));
5262 LASSERT(!dt_object_remote(dt));
5263 LASSERT(bag->ic_object == obj->oo_inode);
5264 LASSERT(handle != NULL);
5266 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
5268 ipd = osd_idx_ipd_get(env, bag);
5269 if (unlikely(ipd == NULL))
5272 oh = container_of(handle, struct osd_thandle, ot_super);
5273 LASSERT(oh->ot_handle != NULL);
5274 LASSERT(oh->ot_handle->h_transaction != NULL);
5276 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5277 /* swab quota uid/gid provided by caller */
5278 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5279 key = (const struct dt_key *)&oti->oti_quota_id;
5282 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
5283 osd_ipd_put(env, bag, ipd);
5284 LINVRNT(osd_invariant(obj));
5285 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
5289 static int osd_index_declare_ea_delete(const struct lu_env *env,
5290 struct dt_object *dt,
5291 const struct dt_key *key,
5292 struct thandle *handle)
5294 struct osd_thandle *oh;
5295 struct inode *inode;
5300 LASSERT(!dt_object_remote(dt));
5301 LASSERT(handle != NULL);
5303 oh = container_of(handle, struct osd_thandle, ot_super);
5304 LASSERT(oh->ot_handle == NULL);
5306 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE];
5307 osd_trans_declare_op(env, oh, OSD_OT_DELETE, credits);
5309 inode = osd_dt_obj(dt)->oo_inode;
5313 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
5314 i_projid_read(inode), 0, oh, osd_dt_obj(dt),
5319 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
5322 struct osd_fid_pack *rec;
5325 if (de->file_type & LDISKFS_DIRENT_LUFID) {
5326 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
5327 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
5328 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
5334 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
5335 const struct lu_fid *fid)
5337 struct seq_server_site *ss = osd_seq_site(osd);
5341 /* FID seqs not in FLDB, must be local seq */
5342 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
5346 * If FLD is not being initialized yet, it only happens during the
5347 * initialization, likely during mgs initialization, and we assume
5348 * this is local FID.
5350 if (ss == NULL || ss->ss_server_fld == NULL)
5353 /* Only check the local FLDB here */
5354 if (osd_seq_exists(env, osd, fid_seq(fid)))
5360 static void osd_take_care_of_agent(const struct lu_env *env,
5361 struct osd_device *osd,
5362 struct osd_thandle *oh,
5363 struct ldiskfs_dir_entry_2 *de)
5365 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
5366 struct osd_idmap_cache *idc;
5367 int rc, schedule = 0;
5369 LASSERT(de != NULL);
5371 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
5372 if (likely(rc == 0)) {
5373 idc = osd_idc_find_or_init(env, osd, fid);
5374 if (IS_ERR(idc) || idc->oic_remote)
5376 } else if (rc == -ENODATA) {
5378 * can't get FID, postpone to the end of the
5379 * transaction when iget() is safe
5383 CERROR("%s: can't get FID: rc = %d\n", osd_name(osd), rc);
5386 osd_schedule_agent_inode_removal(env, oh,
5387 le32_to_cpu(de->inode));
5391 * Utility function to get real name from object name
5393 * \param[in] obj pointer to the object to be handled
5394 * \param[in] name object name
5395 * \param[in] len object name len
5396 * \param[out]ln pointer to the struct lu_name to hold the real name
5398 * If file is not encrypted, real name is just the object name.
5399 * If file is encrypted, object name needs to be decoded. In
5400 * this case a new buffer is allocated, and ln->ln_name needs to be freed by
5403 * \retval 0, on success
5404 * \retval -ve, on error
5406 static int obj_name2lu_name(struct osd_object *obj, const char *name,
5407 int len, struct lu_name *ln)
5409 if (!(obj->oo_lma_flags & LUSTRE_ENCRYPT_FL)) {
5411 ln->ln_namelen = len;
5413 char *buf = kmalloc(len, GFP_NOFS);
5418 len = critical_decode(name, len, buf);
5420 ln->ln_namelen = len;
5427 * Index delete function for interoperability mode (b11826).
5428 * It will remove the directory entry added by osd_index_ea_insert().
5429 * This entry is needed to maintain name->fid mapping.
5431 * \param key, key i.e. file entry to be deleted
5433 * \retval 0, on success
5434 * \retval -ve, on error
5436 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
5437 const struct dt_key *key, struct thandle *handle)
5439 struct osd_object *obj = osd_dt_obj(dt);
5440 struct inode *dir = obj->oo_inode;
5441 struct dentry *dentry;
5442 struct osd_thandle *oh;
5443 struct ldiskfs_dir_entry_2 *de = NULL;
5444 struct buffer_head *bh;
5445 struct htree_lock *hlock = NULL;
5446 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
5452 if (!dt_object_exists(dt))
5455 LINVRNT(osd_invariant(obj));
5456 LASSERT(!dt_object_remote(dt));
5457 LASSERT(handle != NULL);
5459 rc = obj_name2lu_name(obj, (char *)key, strlen((char *)key), &ln);
5463 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
5465 oh = container_of(handle, struct osd_thandle, ot_super);
5466 LASSERT(oh->ot_handle != NULL);
5467 LASSERT(oh->ot_handle->h_transaction != NULL);
5469 dquot_initialize(dir);
5470 dentry = osd_child_dentry_get(env, obj, ln.ln_name, ln.ln_namelen);
5472 if (obj->oo_hl_head != NULL) {
5473 hlock = osd_oti_get(env)->oti_hlock;
5474 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
5475 dir, LDISKFS_HLOCK_DEL);
5477 down_write(&obj->oo_ext_idx_sem);
5480 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5483 * If this is not the ".." entry, it might be a remote DNE
5484 * entry and we need to check if the FID is for a remote
5485 * MDT. If the FID is not in the directory entry (e.g.
5486 * upgraded 1.8 filesystem without dirdata enabled) then
5487 * we need to get the FID from the LMA. For a remote directory
5488 * there HAS to be an LMA, it cannot be an IGIF inode in this
5491 * Delete the entry before the agent inode in order to
5492 * simplify error handling. At worst an error after deleting
5493 * the entry first might leak the agent inode afterward. The
5494 * reverse would need filesystem abort in case of error deleting
5495 * the entry after the agent had been removed, or leave a
5496 * dangling entry pointing at a random inode.
5498 if (strcmp((char *)key, dotdot) != 0)
5499 osd_take_care_of_agent(env, osd, oh, de);
5500 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
5506 if (!rc && fid_is_namespace_visible(lu_object_fid(&dt->do_lu)) &&
5507 obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
5508 /* NB, dirent count may not be accurate, because it's counted
5511 if (obj->oo_dirent_count)
5512 obj->oo_dirent_count--;
5514 obj->oo_dirent_count = LU_DIRENT_COUNT_UNSET;
5517 ldiskfs_htree_unlock(hlock);
5519 up_write(&obj->oo_ext_idx_sem);
5522 LASSERT(osd_invariant(obj));
5523 osd_trans_exec_check(env, handle, OSD_OT_DELETE);
5524 if (ln.ln_name != (char *)key)
5530 * Lookup index for \a key and copy record to \a rec.
5532 * \param dt osd index object
5533 * \param key key for index
5534 * \param rec record reference
5536 * \retval +ve success : exact mach
5537 * \retval 0 return record with key not greater than \a key
5538 * \retval -ve failure
5540 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
5541 struct dt_rec *rec, const struct dt_key *key)
5543 struct osd_object *obj = osd_dt_obj(dt);
5544 struct iam_path_descr *ipd;
5545 struct iam_container *bag = &obj->oo_dir->od_container;
5546 struct osd_thread_info *oti = osd_oti_get(env);
5547 struct iam_iterator *it = &oti->oti_idx_it;
5548 struct iam_rec *iam_rec;
5553 if (!dt_object_exists(dt))
5556 LASSERT(osd_invariant(obj));
5557 LASSERT(!dt_object_remote(dt));
5558 LASSERT(bag->ic_object == obj->oo_inode);
5560 ipd = osd_idx_ipd_get(env, bag);
5564 /* got ipd now we can start iterator. */
5565 iam_it_init(it, bag, 0, ipd);
5567 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5568 /* swab quota uid/gid provided by caller */
5569 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5570 key = (const struct dt_key *)&oti->oti_quota_id;
5573 rc = iam_it_get(it, (struct iam_key *)key);
5575 if (S_ISDIR(obj->oo_inode->i_mode))
5576 iam_rec = (struct iam_rec *)oti->oti_ldp;
5578 iam_rec = (struct iam_rec *)rec;
5580 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
5582 if (S_ISDIR(obj->oo_inode->i_mode))
5583 osd_fid_unpack((struct lu_fid *)rec,
5584 (struct osd_fid_pack *)iam_rec);
5585 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
5586 osd_quota_unpack(obj, rec);
5591 osd_ipd_put(env, bag, ipd);
5593 LINVRNT(osd_invariant(obj));
5598 static int osd_index_declare_iam_insert(const struct lu_env *env,
5599 struct dt_object *dt,
5600 const struct dt_rec *rec,
5601 const struct dt_key *key,
5602 struct thandle *handle)
5604 struct osd_thandle *oh;
5606 LASSERT(handle != NULL);
5608 oh = container_of(handle, struct osd_thandle, ot_super);
5609 LASSERT(oh->ot_handle == NULL);
5611 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
5612 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
5618 * Inserts (key, value) pair in \a dt index object.
5620 * \param dt osd index object
5621 * \param key key for index
5622 * \param rec record reference
5623 * \param th transaction handler
5626 * \retval -ve failure
5628 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
5629 const struct dt_rec *rec,
5630 const struct dt_key *key, struct thandle *th)
5632 struct osd_object *obj = osd_dt_obj(dt);
5633 struct iam_path_descr *ipd;
5634 struct osd_thandle *oh;
5635 struct iam_container *bag;
5636 struct osd_thread_info *oti = osd_oti_get(env);
5637 struct iam_rec *iam_rec;
5642 if (!dt_object_exists(dt))
5645 LINVRNT(osd_invariant(obj));
5646 LASSERT(!dt_object_remote(dt));
5648 bag = &obj->oo_dir->od_container;
5649 LASSERT(bag->ic_object == obj->oo_inode);
5650 LASSERT(th != NULL);
5652 osd_trans_exec_op(env, th, OSD_OT_INSERT);
5654 ipd = osd_idx_ipd_get(env, bag);
5655 if (unlikely(ipd == NULL))
5658 oh = container_of(th, struct osd_thandle, ot_super);
5659 LASSERT(oh->ot_handle != NULL);
5660 LASSERT(oh->ot_handle->h_transaction != NULL);
5661 if (S_ISDIR(obj->oo_inode->i_mode)) {
5662 iam_rec = (struct iam_rec *)oti->oti_ldp;
5663 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec,
5665 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
5666 /* pack quota uid/gid */
5667 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
5668 key = (const struct dt_key *)&oti->oti_quota_id;
5669 /* pack quota record */
5670 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
5671 iam_rec = (struct iam_rec *)rec;
5673 iam_rec = (struct iam_rec *)rec;
5676 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
5678 osd_ipd_put(env, bag, ipd);
5679 LINVRNT(osd_invariant(obj));
5680 osd_trans_exec_check(env, th, OSD_OT_INSERT);
5685 * Calls ldiskfs_add_entry() to add directory entry
5686 * into the directory. This is required for
5687 * interoperability mode (b11826)
5689 * \retval 0, on success
5690 * \retval -ve, on error
5692 static int __osd_ea_add_rec(struct osd_thread_info *info,
5693 struct osd_object *pobj, struct inode *cinode,
5694 const char *name, const struct lu_fid *fid,
5695 struct htree_lock *hlock, struct thandle *th)
5697 struct ldiskfs_dentry_param *ldp;
5698 struct dentry *child;
5699 struct osd_thandle *oth;
5703 oth = container_of(th, struct osd_thandle, ot_super);
5704 LASSERT(oth->ot_handle != NULL);
5705 LASSERT(oth->ot_handle->h_transaction != NULL);
5706 LASSERT(pobj->oo_inode);
5708 rc = obj_name2lu_name(pobj, name, strlen(name), &ln);
5712 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
5713 if (unlikely(osd_object_is_root(pobj)))
5716 osd_get_ldiskfs_dirent_param(ldp, fid);
5717 child = osd_child_dentry_get(info->oti_env, pobj,
5718 ln.ln_name, ln.ln_namelen);
5719 child->d_fsdata = (void *)ldp;
5720 dquot_initialize(pobj->oo_inode);
5721 rc = osd_ldiskfs_add_entry(info, osd_obj2dev(pobj), oth->ot_handle,
5722 child, cinode, hlock);
5723 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
5724 struct ldiskfs_dir_entry_2 *de;
5725 struct buffer_head *bh;
5728 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
5731 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
5734 if (S_ISDIR(cinode->i_mode))
5735 de->file_type = LDISKFS_DIRENT_LUFID |
5736 LDISKFS_FT_REG_FILE;
5738 de->file_type = LDISKFS_DIRENT_LUFID |
5740 ldiskfs_handle_dirty_metadata(oth->ot_handle,
5747 if (ln.ln_name != name)
5753 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
5754 * into the directory.Also sets flags into osd object to
5755 * indicate dot and dotdot are created. This is required for
5756 * interoperability mode (b11826)
5758 * \param dir directory for dot and dotdot fixup.
5759 * \param obj child object for linking
5761 * \retval 0, on success
5762 * \retval -ve, on error
5764 static int osd_add_dot_dotdot(struct osd_thread_info *info,
5765 struct osd_object *dir,
5766 struct inode *parent_dir, const char *name,
5767 const struct lu_fid *dot_fid,
5768 const struct lu_fid *dot_dot_fid,
5771 struct inode *inode = dir->oo_inode;
5772 struct osd_thandle *oth;
5775 oth = container_of(th, struct osd_thandle, ot_super);
5776 LASSERT(oth->ot_handle->h_transaction != NULL);
5777 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
5779 if (strcmp(name, dot) == 0) {
5780 if (dir->oo_compat_dot_created) {
5783 LASSERT(inode->i_ino == parent_dir->i_ino);
5784 dir->oo_compat_dot_created = 1;
5787 } else if (strcmp(name, dotdot) == 0) {
5788 if (!dir->oo_compat_dot_created)
5790 /* in case of rename, dotdot is already created */
5791 if (dir->oo_compat_dotdot_created) {
5792 return __osd_ea_add_rec(info, dir, parent_dir, name,
5793 dot_dot_fid, NULL, th);
5796 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
5797 struct lu_fid tfid = *dot_dot_fid;
5800 result = osd_add_dot_dotdot_internal(info,
5801 dir->oo_inode, parent_dir, dot_fid,
5804 result = osd_add_dot_dotdot_internal(info,
5805 dir->oo_inode, parent_dir, dot_fid,
5810 dir->oo_compat_dotdot_created = 1;
5818 * It will call the appropriate osd_add* function and return the
5819 * value, return by respective functions.
5821 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
5822 struct inode *cinode, const char *name,
5823 const struct lu_fid *fid, struct thandle *th)
5825 struct osd_thread_info *info = osd_oti_get(env);
5826 struct htree_lock *hlock;
5829 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
5831 if (name[0] == '.' && (name[1] == '\0' ||
5832 (name[1] == '.' && name[2] == '\0'))) {
5833 if (hlock != NULL) {
5834 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5837 down_write(&pobj->oo_ext_idx_sem);
5840 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
5841 lu_object_fid(&pobj->oo_dt.do_lu),
5844 if (hlock != NULL) {
5845 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
5846 pobj->oo_inode, LDISKFS_HLOCK_ADD);
5848 down_write(&pobj->oo_ext_idx_sem);
5851 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
5852 struct lu_fid *tfid = &info->oti_fid;
5856 rc = __osd_ea_add_rec(info, pobj, cinode, name,
5859 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
5863 if (!rc && fid_is_namespace_visible(lu_object_fid(&pobj->oo_dt.do_lu))
5864 && pobj->oo_dirent_count != LU_DIRENT_COUNT_UNSET)
5865 pobj->oo_dirent_count++;
5868 ldiskfs_htree_unlock(hlock);
5870 up_write(&pobj->oo_ext_idx_sem);
5876 osd_ldiskfs_consistency_check(struct osd_thread_info *oti,
5877 struct osd_device *dev,
5878 const struct lu_fid *fid,
5879 struct osd_inode_id *id)
5881 struct lustre_scrub *scrub = &dev->od_scrub.os_scrub;
5882 struct inode *inode = NULL;
5888 if (!scrub_needs_check(scrub, fid, id->oii_ino))
5891 rc = osd_oi_lookup(oti, dev, fid, &oti->oti_id, 0);
5892 if (rc == -ENOENT) {
5893 __u32 gen = id->oii_gen;
5899 inode = osd_iget(oti, dev, id);
5900 /* The inode has been removed (by race maybe). */
5901 if (IS_ERR(inode)) {
5902 rc = PTR_ERR(inode);
5904 RETURN(rc == -ESTALE ? -ENOENT : rc);
5907 /* The OI mapping is lost. */
5908 if (gen != OSD_OII_NOGEN)
5912 * The inode may has been reused by others, we do not know,
5913 * leave it to be handled by subsequent osd_fid_lookup().
5916 } else if (rc || osd_id_eq(id, &oti->oti_id)) {
5923 if (scrub->os_running) {
5924 if (inode == NULL) {
5925 inode = osd_iget(oti, dev, id);
5926 /* The inode has been removed (by race maybe). */
5927 if (IS_ERR(inode)) {
5928 rc = PTR_ERR(inode);
5930 RETURN(rc == -ESTALE ? -ENOENT : rc);
5934 rc = osd_oii_insert(dev, fid, id, insert);
5936 * There is race condition between osd_oi_lookup and OI scrub.
5937 * The OI scrub finished just after osd_oi_lookup() failure.
5938 * Under such case, it is unnecessary to trigger OI scrub again,
5939 * but try to call osd_oi_lookup() again.
5941 if (unlikely(rc == -EAGAIN))
5944 if (!S_ISDIR(inode->i_mode))
5947 rc = osd_check_lmv(oti, dev, inode);
5952 if (dev->od_scrub.os_scrub.os_auto_scrub_interval != AS_NEVER &&
5954 rc = osd_scrub_start(oti->oti_env, dev, SS_AUTO_PARTIAL |
5955 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
5956 CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
5957 "%s: trigger partial OI scrub for RPC inconsistency, checking FID "DFID"/%u: rc = %d\n",
5958 osd_dev2name(dev), PFID(fid), id->oii_ino, rc);
5959 if (rc == 0 || rc == -EALREADY)
5971 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
5972 struct osd_device *dev,
5973 struct lu_fid *fid, __u32 ino)
5975 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
5976 struct osd_idmap_cache *oic = &oti->oti_cache;
5977 struct inode *inode;
5980 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
5981 inode = osd_iget(oti, dev, &oic->oic_lid);
5982 if (IS_ERR(inode)) {
5983 fid_zero(&oic->oic_fid);
5984 return PTR_ERR(inode);
5987 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, loa);
5990 fid_zero(&oic->oic_fid);
5992 *fid = oic->oic_fid = loa->loa_lma.lma_self_fid;
5996 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
5997 struct osd_inode_id *id, const struct lu_fid *fid)
5999 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
6000 id->oii_ino, id->oii_gen, info);
6001 info->oti_cache.oic_lid = *id;
6002 info->oti_cache.oic_fid = *fid;
6003 info->oti_cache.oic_dev = osd;
6007 * Get parent FID from the linkEA.
6009 * For a directory which parent resides on remote MDT, to satisfy the
6010 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
6011 * the other hand, to make the lookup(..) on the directory can return
6012 * the real parent FID, we append the real parent FID after its ".."
6013 * name entry in the /REMOTE_PARENT_DIR.
6015 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
6016 * backup. So after the restore, we cannot get the right parent FID from
6017 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
6018 * we have stored the real parent FID in the directory object's linkEA,
6019 * we can parse the linkEA for the real parent FID.
6021 * \param[in] env pointer to the thread context
6022 * \param[in] obj pointer to the object to be handled
6023 * \param[out]fid pointer to the buffer to hold the parent FID
6025 * \retval 0 for getting the real parent FID successfully
6026 * \retval negative error number on failure
6028 static int osd_get_pfid_from_linkea(const struct lu_env *env,
6029 struct osd_object *obj,
6032 struct osd_thread_info *oti = osd_oti_get(env);
6033 struct lu_buf *buf = &oti->oti_big_buf;
6034 struct dentry *dentry = &oti->oti_obj_dentry;
6035 struct inode *inode = obj->oo_inode;
6036 struct linkea_data ldata = { NULL };
6042 if (!S_ISDIR(inode->i_mode))
6046 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6047 buf->lb_buf, buf->lb_len);
6048 if (rc == -ERANGE) {
6049 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6052 lu_buf_realloc(buf, rc);
6053 if (buf->lb_buf == NULL)
6060 if (unlikely(rc == 0))
6066 if (unlikely(buf->lb_buf == NULL)) {
6067 lu_buf_realloc(buf, rc);
6068 if (buf->lb_buf == NULL)
6075 rc = linkea_init_with_rec(&ldata);
6077 linkea_first_entry(&ldata);
6078 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
6084 static int osd_verify_ent_by_linkea(const struct lu_env *env,
6085 struct inode *inode,
6086 const struct lu_fid *pfid,
6087 const char *name, const int namelen)
6089 struct osd_thread_info *oti = osd_oti_get(env);
6090 struct lu_buf *buf = &oti->oti_big_buf;
6091 struct dentry *dentry = &oti->oti_obj_dentry;
6092 struct linkea_data ldata = { NULL };
6093 struct lu_name cname = { .ln_name = name,
6094 .ln_namelen = namelen };
6100 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
6101 buf->lb_buf, buf->lb_len);
6103 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK, NULL, 0);
6108 if (unlikely(rc == 0))
6111 if (buf->lb_len < rc) {
6112 lu_buf_realloc(buf, rc);
6113 if (buf->lb_buf == NULL)
6120 rc = linkea_init_with_rec(&ldata);
6122 rc = linkea_links_find(&ldata, &cname, pfid);
6128 * Calls ->lookup() to find dentry. From dentry get inode and
6129 * read inode's ea to get fid. This is required for interoperability
6132 * \retval 0, on success
6133 * \retval -ve, on error
6135 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
6136 struct dt_rec *rec, const struct dt_key *key)
6138 struct inode *dir = obj->oo_inode;
6139 struct dentry *dentry;
6140 struct ldiskfs_dir_entry_2 *de;
6141 struct buffer_head *bh;
6142 struct lu_fid *fid = (struct lu_fid *)rec;
6143 struct htree_lock *hlock = NULL;
6150 LASSERT(dir->i_op != NULL);
6151 LASSERT(dir->i_op->lookup != NULL);
6153 rc = obj_name2lu_name(obj, (char *)key, strlen((char *)key), &ln);
6157 dentry = osd_child_dentry_get(env, obj, ln.ln_name, ln.ln_namelen);
6159 if (obj->oo_hl_head != NULL) {
6160 hlock = osd_oti_get(env)->oti_hlock;
6161 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
6162 dir, LDISKFS_HLOCK_LOOKUP);
6164 down_read(&obj->oo_ext_idx_sem);
6167 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
6169 struct osd_thread_info *oti = osd_oti_get(env);
6170 struct osd_inode_id *id = &oti->oti_id;
6171 struct osd_device *dev = osd_obj2dev(obj);
6173 ino = le32_to_cpu(de->inode);
6174 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
6176 rc = osd_fail_fid_lookup(oti, dev, fid, ino);
6180 rc = osd_get_fid_from_dentry(de, rec);
6182 /* done with de, release bh */
6185 if (unlikely(is_remote_parent_ino(dev, ino))) {
6186 const char *name = (const char *)key;
6189 * If the parent is on remote MDT, and there
6190 * is no FID-in-dirent, then we have to get
6191 * the parent FID from the linkEA.
6193 if (likely(strlen(name) == 2 &&
6194 name[0] == '.' && name[1] == '.'))
6195 rc = osd_get_pfid_from_linkea(env, obj,
6198 rc = osd_ea_fid_get(env, obj, ino, fid, id);
6201 osd_id_gen(id, ino, OSD_OII_NOGEN);
6204 if (rc != 0 || osd_remote_fid(env, dev, fid))
6207 rc = osd_ldiskfs_consistency_check(oti, dev, fid, id);
6208 if (rc != -ENOENT) {
6209 /* Other error should not affect lookup result. */
6212 /* Normal file mapping should be added into OI cache
6213 * after FID in LMA check, but for local files like
6214 * hsm_actions, their FIDs are not stored in OI files,
6215 * see osd_initial_OI_scrub(), and here is the only
6216 * place to load mapping into OI cache.
6218 if (!fid_is_namespace_visible(fid))
6219 osd_add_oi_cache(osd_oti_get(env),
6220 osd_obj2dev(obj), id, fid);
6230 ldiskfs_htree_unlock(hlock);
6232 up_read(&obj->oo_ext_idx_sem);
6233 if (ln.ln_name != (char *)key)
6238 static int osd_index_declare_ea_insert(const struct lu_env *env,
6239 struct dt_object *dt,
6240 const struct dt_rec *rec,
6241 const struct dt_key *key,
6242 struct thandle *handle)
6244 struct osd_thandle *oh;
6245 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
6246 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
6247 const struct lu_fid *fid = rec1->rec_fid;
6248 int credits, rc = 0;
6249 struct osd_idmap_cache *idc;
6253 LASSERT(!dt_object_remote(dt));
6254 LASSERT(handle != NULL);
6255 LASSERT(fid != NULL);
6256 LASSERT(rec1->rec_type != 0);
6258 oh = container_of(handle, struct osd_thandle, ot_super);
6259 LASSERT(oh->ot_handle == NULL);
6261 credits = osd_dto_credits_noquota[DTO_INDEX_INSERT];
6264 * we can't call iget() while a transactions is running
6265 * (this can lead to a deadlock), but we need to know
6266 * inum and object type. so we find this information at
6267 * declaration and cache in per-thread info
6269 idc = osd_idc_find_or_init(env, osd, fid);
6271 RETURN(PTR_ERR(idc));
6272 if (idc->oic_remote) {
6274 * a reference to remote inode is represented by an
6275 * agent inode which we have to create
6277 credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
6278 credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
6281 osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits);
6283 if (osd_dt_obj(dt)->oo_inode != NULL) {
6284 struct inode *inode = osd_dt_obj(dt)->oo_inode;
6287 * We ignore block quota on meta pool (MDTs), so needn't
6288 * calculate how many blocks will be consumed by this index
6291 rc = osd_declare_inode_qid(env, i_uid_read(inode),
6293 i_projid_read(inode), 0,
6294 oh, osd_dt_obj(dt), NULL,
6299 #ifdef HAVE_PROJECT_QUOTA
6301 * Reserve credits for local agent inode to transfer
6302 * to 0, quota enforcement is ignored in this case.
6304 if (idc->oic_remote &&
6305 LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL &&
6306 i_projid_read(inode) != 0)
6307 rc = osd_declare_attr_qid(env, osd_dt_obj(dt), oh,
6308 0, i_projid_read(inode),
6309 0, false, PRJQUOTA);
6317 * Index add function for interoperability mode (b11826).
6318 * It will add the directory entry.This entry is needed to
6319 * maintain name->fid mapping.
6321 * \param key it is key i.e. file entry to be inserted
6322 * \param rec it is value of given key i.e. fid
6324 * \retval 0, on success
6325 * \retval -ve, on error
6327 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
6328 const struct dt_rec *rec,
6329 const struct dt_key *key, struct thandle *th)
6331 struct osd_object *obj = osd_dt_obj(dt);
6332 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
6333 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
6334 const struct lu_fid *fid = rec1->rec_fid;
6335 const char *name = (const char *)key;
6336 struct osd_thread_info *oti = osd_oti_get(env);
6337 struct inode *child_inode = NULL;
6338 struct osd_idmap_cache *idc;
6343 if (!dt_object_exists(dt))
6346 LASSERT(osd_invariant(obj));
6347 LASSERT(!dt_object_remote(dt));
6348 LASSERT(th != NULL);
6350 osd_trans_exec_op(env, th, OSD_OT_INSERT);
6352 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
6354 idc = osd_idc_find(env, osd, fid);
6355 if (unlikely(idc == NULL)) {
6356 idc = osd_idc_find_or_init(env, osd, fid);
6359 * this dt_insert() wasn't declared properly, so
6360 * FID is missing in OI cache. we better do not
6361 * lookup FID in FLDB/OI and don't risk to deadlock,
6362 * but in some special cases (lfsck testing, etc)
6363 * it's much simpler than fixing a caller.
6365 * normally this error should be placed after the first
6366 * find, but migrate may attach source stripes to
6367 * target, which doesn't create stripes.
6369 CERROR("%s: "DFID" wasn't declared for insert\n",
6370 osd_name(osd), PFID(fid));
6372 RETURN(PTR_ERR(idc));
6376 if (idc->oic_remote) {
6377 /* Insert remote entry */
6378 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
6380 igrab(osd->od_mdt_map->omm_remote_parent->d_inode);
6382 child_inode = osd_create_local_agent_inode(env, osd,
6383 obj, fid, rec1->rec_type & S_IFMT, th);
6384 if (IS_ERR(child_inode))
6385 RETURN(PTR_ERR(child_inode));
6388 /* Insert local entry */
6389 if (unlikely(idc->oic_lid.oii_ino == 0)) {
6390 /* for a reason OI cache wasn't filled properly */
6391 CERROR("%s: OIC for "DFID" isn't filled\n",
6392 osd_name(osd), PFID(fid));
6395 child_inode = oti->oti_inode;
6396 if (unlikely(child_inode == NULL)) {
6397 struct ldiskfs_inode_info *lii;
6402 child_inode = oti->oti_inode = &lii->vfs_inode;
6404 child_inode->i_sb = osd_sb(osd);
6405 child_inode->i_ino = idc->oic_lid.oii_ino;
6406 child_inode->i_mode = rec1->rec_type & S_IFMT;
6409 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
6411 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
6412 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
6414 if (child_inode && child_inode != oti->oti_inode)
6416 LASSERT(osd_invariant(obj));
6417 osd_trans_exec_check(env, th, OSD_OT_INSERT);
6423 * Initialize osd Iterator for given osd index object.
6425 * \param dt osd index object
6428 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
6429 struct dt_object *dt,
6432 struct osd_it_iam *it;
6433 struct osd_object *obj = osd_dt_obj(dt);
6434 struct lu_object *lo = &dt->do_lu;
6435 struct iam_path_descr *ipd;
6436 struct iam_container *bag = &obj->oo_dir->od_container;
6438 if (!dt_object_exists(dt))
6439 return ERR_PTR(-ENOENT);
6443 return ERR_PTR(-ENOMEM);
6445 ipd = osd_it_ipd_get(env, bag);
6446 if (likely(ipd != NULL)) {
6450 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
6451 return (struct dt_it *)it;
6454 return ERR_PTR(-ENOMEM);
6459 * free given Iterator.
6461 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
6463 struct osd_it_iam *it = (struct osd_it_iam *)di;
6464 struct osd_object *obj = it->oi_obj;
6466 iam_it_fini(&it->oi_it);
6467 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
6468 osd_object_put(env, obj);
6473 * Move Iterator to record specified by \a key
6475 * \param di osd iterator
6476 * \param key key for index
6478 * \retval +ve di points to record with least key not larger than key
6479 * \retval 0 di points to exact matched key
6480 * \retval -ve failure
6483 static int osd_it_iam_get(const struct lu_env *env,
6484 struct dt_it *di, const struct dt_key *key)
6486 struct osd_thread_info *oti = osd_oti_get(env);
6487 struct osd_it_iam *it = (struct osd_it_iam *)di;
6489 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
6490 /* swab quota uid/gid */
6491 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
6492 key = (struct dt_key *)&oti->oti_quota_id;
6495 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
6501 * \param di osd iterator
6503 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
6505 struct osd_it_iam *it = (struct osd_it_iam *)di;
6507 iam_it_put(&it->oi_it);
6511 * Move iterator by one record
6513 * \param di osd iterator
6515 * \retval +1 end of container reached
6517 * \retval -ve failure
6520 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
6522 struct osd_it_iam *it = (struct osd_it_iam *)di;
6524 return iam_it_next(&it->oi_it);
6528 * Return pointer to the key under iterator.
6531 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
6532 const struct dt_it *di)
6534 struct osd_thread_info *oti = osd_oti_get(env);
6535 struct osd_it_iam *it = (struct osd_it_iam *)di;
6536 struct osd_object *obj = it->oi_obj;
6539 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
6541 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
6542 /* swab quota uid/gid */
6543 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
6544 key = (struct dt_key *)&oti->oti_quota_id;
6551 * Return size of key under iterator (in bytes)
6554 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
6556 struct osd_it_iam *it = (struct osd_it_iam *)di;
6558 return iam_it_key_size(&it->oi_it);
6562 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
6564 /* check if file type is required */
6565 if (ent->lde_attrs & LUDA_TYPE) {
6566 struct luda_type *lt;
6567 int align = sizeof(*lt) - 1;
6569 len = (len + align) & ~align;
6570 lt = (struct luda_type *)(ent->lde_name + len);
6571 lt->lt_type = cpu_to_le16(DTTOIF(type));
6574 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
6578 * build lu direct from backend fs dirent.
6582 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
6583 char *name, __u16 namelen, __u16 type, __u32 attr)
6585 ent->lde_attrs = attr | LUDA_FID;
6586 fid_cpu_to_le(&ent->lde_fid, fid);
6588 ent->lde_hash = cpu_to_le64(offset);
6589 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
6591 strncpy(ent->lde_name, name, namelen);
6592 ent->lde_name[namelen] = '\0';
6593 ent->lde_namelen = cpu_to_le16(namelen);
6595 /* append lustre attributes */
6596 osd_it_append_attrs(ent, namelen, type);
6600 * Return pointer to the record under iterator.
6602 static int osd_it_iam_rec(const struct lu_env *env,
6603 const struct dt_it *di,
6604 struct dt_rec *dtrec, __u32 attr)
6606 struct osd_it_iam *it = (struct osd_it_iam *)di;
6607 struct osd_thread_info *info = osd_oti_get(env);
6611 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
6612 const struct osd_fid_pack *rec;
6613 struct lu_fid *fid = &info->oti_fid;
6614 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
6620 name = (char *)iam_it_key_get(&it->oi_it);
6622 RETURN(PTR_ERR(name));
6624 namelen = iam_it_key_size(&it->oi_it);
6626 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
6628 RETURN(PTR_ERR(rec));
6630 rc = osd_fid_unpack(fid, rec);
6634 hash = iam_it_store(&it->oi_it);
6636 /* IAM does not store object type in IAM index (dir) */
6637 osd_it_pack_dirent(lde, fid, hash, name, namelen,
6639 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
6640 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
6641 (struct iam_rec *)dtrec);
6642 osd_quota_unpack(it->oi_obj, dtrec);
6644 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
6645 (struct iam_rec *)dtrec);
6652 * Returns cookie for current Iterator position.
6654 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
6656 struct osd_it_iam *it = (struct osd_it_iam *)di;
6658 return iam_it_store(&it->oi_it);
6662 * Restore iterator from cookie.
6664 * \param di osd iterator
6665 * \param hash Iterator location cookie
6667 * \retval +ve di points to record with least key not larger than key.
6668 * \retval 0 di points to exact matched key
6669 * \retval -ve failure
6672 static int osd_it_iam_load(const struct lu_env *env,
6673 const struct dt_it *di, __u64 hash)
6675 struct osd_it_iam *it = (struct osd_it_iam *)di;
6677 return iam_it_load(&it->oi_it, hash);
6680 static const struct dt_index_operations osd_index_iam_ops = {
6681 .dio_lookup = osd_index_iam_lookup,
6682 .dio_declare_insert = osd_index_declare_iam_insert,
6683 .dio_insert = osd_index_iam_insert,
6684 .dio_declare_delete = osd_index_declare_iam_delete,
6685 .dio_delete = osd_index_iam_delete,
6687 .init = osd_it_iam_init,
6688 .fini = osd_it_iam_fini,
6689 .get = osd_it_iam_get,
6690 .put = osd_it_iam_put,
6691 .next = osd_it_iam_next,
6692 .key = osd_it_iam_key,
6693 .key_size = osd_it_iam_key_size,
6694 .rec = osd_it_iam_rec,
6695 .store = osd_it_iam_store,
6696 .load = osd_it_iam_load
6700 struct osd_it_ea *osd_it_dir_init(const struct lu_env *env,
6701 struct osd_device *dev,
6702 struct inode *inode, u32 attr)
6704 struct osd_thread_info *info = osd_oti_get(env);
6705 struct osd_it_ea *oie;
6709 file = alloc_file_pseudo(inode, dev->od_mnt, "/", O_NOATIME,
6712 RETURN(ERR_CAST(file));
6714 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
6715 if (attr & LUDA_64BITHASH)
6716 file->f_mode |= FMODE_64BITHASH;
6718 file->f_mode |= FMODE_32BITHASH;
6721 OBD_SLAB_ALLOC_PTR(oie, osd_itea_cachep);
6725 oie->oie_rd_dirent = 0;
6726 oie->oie_it_dirent = 0;
6727 oie->oie_dirent = NULL;
6728 if (unlikely(!info->oti_it_ea_buf_used)) {
6729 oie->oie_buf = info->oti_it_ea_buf;
6730 info->oti_it_ea_buf_used = 1;
6732 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
6736 oie->oie_obj = NULL;
6737 oie->oie_file = file;
6742 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
6746 return ERR_PTR(-ENOMEM);
6750 * Creates or initializes iterator context.
6752 * \retval struct osd_it_ea, iterator structure on success
6755 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
6756 struct dt_object *dt,
6759 struct osd_object *obj = osd_dt_obj(dt);
6760 struct osd_device *dev = osd_obj2dev(obj);
6761 struct lu_object *lo = &dt->do_lu;
6762 struct osd_it_ea *oie;
6766 if (!dt_object_exists(dt) || obj->oo_destroyed)
6767 RETURN(ERR_PTR(-ENOENT));
6769 oie = osd_it_dir_init(env, dev, obj->oo_inode, attr);
6771 RETURN(ERR_CAST(oie));
6775 RETURN((struct dt_it *)oie);
6778 void osd_it_dir_fini(const struct lu_env *env, struct osd_it_ea *oie,
6779 struct inode *inode)
6781 struct osd_thread_info *info = osd_oti_get(env);
6784 fput(oie->oie_file);
6785 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
6786 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
6788 info->oti_it_ea_buf_used = 0;
6789 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
6794 * Destroy or finishes iterator context.
6796 * \param di iterator structure to be destroyed
6798 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
6800 struct osd_it_ea *oie = (struct osd_it_ea *)di;
6801 struct osd_object *obj = oie->oie_obj;
6802 struct inode *inode = obj->oo_inode;
6805 osd_it_dir_fini(env, (struct osd_it_ea *)di, inode);
6806 osd_object_put(env, obj);
6811 * It position the iterator at given key, so that next lookup continues from
6812 * that key Or it is similar to dio_it->load() but based on a key,
6813 * rather than file position.
6815 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
6818 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
6820 static int osd_it_ea_get(const struct lu_env *env,
6821 struct dt_it *di, const struct dt_key *key)
6823 struct osd_it_ea *it = (struct osd_it_ea *)di;
6826 LASSERT(((const char *)key)[0] == '\0');
6827 it->oie_file->f_pos = 0;
6828 it->oie_rd_dirent = 0;
6829 it->oie_it_dirent = 0;
6830 it->oie_dirent = NULL;
6838 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
6842 struct osd_filldir_cbs {
6843 struct dir_context ctx;
6844 struct osd_it_ea *it;
6847 * It is called internally by ->iterate*(). It fills the
6848 * iterator's in-memory data structure with required
6849 * information i.e. name, namelen, rec_size etc.
6851 * \param buf in which information to be filled in.
6852 * \param name name of the file in given dir
6854 * \retval 0 on success
6855 * \retval 1 on buffer full
6857 #ifdef HAVE_FILLDIR_USE_CTX
6858 static int osd_ldiskfs_filldir(struct dir_context *ctx,
6860 static int osd_ldiskfs_filldir(void *ctx,
6862 const char *name, int namelen,
6863 loff_t offset, __u64 ino, unsigned int d_type)
6865 struct osd_it_ea *it = ((struct osd_filldir_cbs *)ctx)->it;
6866 struct osd_object *obj = it->oie_obj;
6867 struct osd_it_ea_dirent *ent = it->oie_dirent;
6868 struct lu_fid *fid = &ent->oied_fid;
6869 char *buf = it->oie_buf;
6870 struct osd_fid_pack *rec;
6873 /* this should never happen */
6874 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
6875 CERROR("ldiskfs return invalid namelen %d\n", namelen);
6879 /* Check for enough space. Note oied_name is not NUL terminated. */
6880 if (&ent->oied_name[namelen] > buf + OSD_IT_EA_BUFSIZE)
6883 /* "." is just the object itself. */
6884 if (namelen == 1 && name[0] == '.') {
6886 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6887 } else if (d_type & LDISKFS_DIRENT_LUFID) {
6888 rec = (struct osd_fid_pack *)(name + namelen + 1);
6889 if (osd_fid_unpack(fid, rec) != 0)
6894 d_type &= ~LDISKFS_DIRENT_LUFID;
6896 /* NOT export local root. */
6898 unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
6899 ino = obj->oo_inode->i_ino;
6900 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
6903 if (obj == NULL || !(obj->oo_lma_flags & LUSTRE_ENCRYPT_FL)) {
6904 ent->oied_namelen = namelen;
6905 memcpy(ent->oied_name, name, namelen);
6907 int encoded_namelen = critical_chars(name, namelen);
6909 /* Check again for enough space. */
6910 if (&ent->oied_name[encoded_namelen] > buf + OSD_IT_EA_BUFSIZE)
6913 ent->oied_namelen = encoded_namelen;
6915 if (encoded_namelen == namelen)
6916 memcpy(ent->oied_name, name, namelen);
6918 critical_encode(name, namelen, ent->oied_name);
6921 ent->oied_ino = ino;
6922 ent->oied_off = offset;
6923 ent->oied_type = d_type;
6925 it->oie_rd_dirent++;
6926 it->oie_dirent = (void *)ent + cfs_size_round(sizeof(*ent) + ent->oied_namelen);
6931 * Calls ->iterate*() to load a directory entry at a time
6932 * and stored it in iterator's in-memory data structure.
6934 * \param di iterator's in memory structure
6936 * \retval 0 on success
6937 * \retval -ve on error
6938 * \retval +1 reach the end of entry
6940 int osd_ldiskfs_it_fill(const struct lu_env *env, const struct dt_it *di)
6942 struct osd_it_ea *it = (struct osd_it_ea *)di;
6943 struct osd_object *obj = it->oie_obj;
6944 struct htree_lock *hlock = NULL;
6945 struct file *filp = it->oie_file;
6947 struct osd_filldir_cbs buf = {
6948 .ctx.actor = osd_ldiskfs_filldir,
6953 it->oie_dirent = it->oie_buf;
6954 it->oie_rd_dirent = 0;
6957 if (obj->oo_hl_head != NULL) {
6958 hlock = osd_oti_get(env)->oti_hlock;
6959 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
6961 LDISKFS_HLOCK_READDIR);
6963 down_read(&obj->oo_ext_idx_sem);
6967 rc = iterate_dir(filp, &buf.ctx);
6971 if (it->oie_rd_dirent == 0) {
6973 * If it does not get any dirent, it means it has been reached
6974 * to the end of the dir
6976 it->oie_file->f_pos = ldiskfs_get_htree_eof(it->oie_file);
6980 it->oie_dirent = it->oie_buf;
6981 it->oie_it_dirent = 1;
6986 ldiskfs_htree_unlock(hlock);
6988 up_read(&obj->oo_ext_idx_sem);
6995 * It calls osd_ldiskfs_it_fill() which will use ->iterate*()
6996 * to load a directory entry at a time and stored it in
6997 * iterator's in-memory data structure.
6999 * \param di iterator's in memory structure
7001 * \retval +ve iterator reached to end
7002 * \retval 0 iterator not reached to end
7003 * \retval -ve on error
7005 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
7007 struct osd_it_ea *it = (struct osd_it_ea *)di;
7012 if (it->oie_it_dirent < it->oie_rd_dirent) {
7014 (void *)it->oie_dirent +
7015 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
7016 it->oie_dirent->oied_namelen);
7017 it->oie_it_dirent++;
7020 if (it->oie_file->f_pos == ldiskfs_get_htree_eof(it->oie_file))
7023 rc = osd_ldiskfs_it_fill(env, di);
7030 * Returns the key at current position from iterator's in memory structure.
7032 * \param di iterator's in memory structure
7034 * \retval key i.e. struct dt_key on success
7036 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
7037 const struct dt_it *di)
7039 struct osd_it_ea *it = (struct osd_it_ea *)di;
7041 return (struct dt_key *)it->oie_dirent->oied_name;
7045 * Returns key's size at current position from iterator's in memory structure.
7047 * \param di iterator's in memory structure
7049 * \retval key_size i.e. struct dt_key on success
7051 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
7053 struct osd_it_ea *it = (struct osd_it_ea *)di;
7055 return it->oie_dirent->oied_namelen;
7058 #if defined LDISKFS_DIR_ENTRY_LEN && defined LDISKFS_DIR_ENTRY_LEN_
7059 #undef LDISKFS_DIR_REC_LEN
7060 #define LDISKFS_DIR_REC_LEN(de) LDISKFS_DIR_ENTRY_LEN_((de))
7063 static inline bool osd_dotdot_has_space(struct ldiskfs_dir_entry_2 *de)
7065 if (LDISKFS_DIR_REC_LEN(de) >=
7066 __LDISKFS_DIR_REC_LEN(2 + 1 + sizeof(struct osd_fid_pack)))
7073 osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen,
7074 unsigned int blocksize, bool dotdot)
7077 return osd_dotdot_has_space(de);
7079 if (ldiskfs_rec_len_from_disk(de->rec_len, blocksize) >=
7080 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
7087 osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev,
7088 handle_t *jh, struct dentry *dentry,
7089 const struct lu_fid *fid, struct buffer_head *bh,
7090 struct ldiskfs_dir_entry_2 *de, struct htree_lock *hlock,
7093 struct inode *dir = dentry->d_parent->d_inode;
7094 struct inode *inode = dentry->d_inode;
7095 struct osd_fid_pack *rec;
7096 struct ldiskfs_dentry_param *ldp;
7097 int namelen = dentry->d_name.len;
7099 struct osd_thread_info *info = osd_oti_get(env);
7103 if (!ldiskfs_has_feature_dirdata(inode->i_sb))
7106 /* There is enough space to hold the FID-in-dirent. */
7107 if (osd_dirent_has_space(de, namelen, dir->i_sb->s_blocksize, dotdot)) {
7108 rc = ldiskfs_journal_get_write_access(jh, bh);
7112 de->name[namelen] = 0;
7113 rec = (struct osd_fid_pack *)(de->name + namelen + 1);
7114 rec->fp_len = sizeof(struct lu_fid) + 1;
7115 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
7116 de->file_type |= LDISKFS_DIRENT_LUFID;
7117 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
7124 rc = ldiskfs_delete_entry(jh, dir, de, bh);
7128 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
7129 osd_get_ldiskfs_dirent_param(ldp, fid);
7130 dentry->d_fsdata = (void *)ldp;
7131 dquot_initialize(dir);
7132 rc = osd_ldiskfs_add_entry(info, dev, jh, dentry, inode, hlock);
7134 * It is too bad, we cannot reinsert the name entry back.
7135 * That means we lose it!
7139 "%s: fail to reinsert the dirent, dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
7140 osd_ino2name(inode), dir->i_ino, dir->i_generation,
7141 namelen, dentry->d_name.name, PFID(fid), rc);
7147 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
7148 struct osd_it_ea *it, struct lu_fid *fid,
7149 struct osd_inode_id *id, __u32 *attr)
7151 struct osd_thread_info *info = osd_oti_get(env);
7152 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
7153 struct osd_device *dev = osd_obj2dev(obj);
7154 struct super_block *sb = osd_sb(dev);
7155 const char *devname = osd_name(dev);
7156 struct osd_it_ea_dirent *ent = it->oie_dirent;
7157 struct inode *dir = obj->oo_inode;
7158 struct htree_lock *hlock = NULL;
7159 struct buffer_head *bh = NULL;
7160 handle_t *jh = NULL;
7161 struct ldiskfs_dir_entry_2 *de;
7162 struct dentry *dentry;
7163 struct inode *inode;
7164 const struct lu_fid *pfid = lu_object_fid(&obj->oo_dt.do_lu);
7167 bool dotdot = false;
7173 if (ent->oied_name[0] == '.') {
7174 if (ent->oied_namelen == 1)
7177 if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
7181 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
7182 inode = osd_iget(info, dev, id);
7183 if (IS_ERR(inode)) {
7184 rc = PTR_ERR(inode);
7185 if (rc == -ENOENT || rc == -ESTALE) {
7187 * Maybe dangling name entry, or
7188 * corrupted directory entry.
7190 *attr |= LUDA_UNKNOWN;
7193 CDEBUG(D_LFSCK, "%s: fail to iget() for dirent "
7194 "check_repair, dir = %lu/%u, name = %.*s, "
7195 "ino = %llu, rc = %d\n",
7196 devname, dir->i_ino, dir->i_generation,
7197 ent->oied_namelen, ent->oied_name,
7204 rc = obj_name2lu_name(obj, ent->oied_name, ent->oied_namelen, &ln);
7208 dentry = osd_child_dentry_by_inode(env, dir, ln.ln_name, ln.ln_namelen);
7209 rc = osd_get_lma(info, inode, dentry, &info->oti_ost_attrs);
7210 if (rc == -ENODATA || !fid_is_sane(&lma->lma_self_fid))
7216 * We need to ensure that the name entry is still valid.
7217 * Because it may be removed or renamed by other already.
7219 * The unlink or rename operation will start journal before PDO lock,
7220 * so to avoid deadlock, here we need to start journal handle before
7221 * related PDO lock also. But because we do not know whether there
7222 * will be something to be repaired before PDO lock, we just start
7223 * journal without conditions.
7225 * We may need to remove the name entry firstly, then insert back.
7226 * One credit is for user quota file update.
7227 * One credit is for group quota file update.
7228 * Two credits are for dirty inode.
7230 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
7231 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
7233 if (dev->od_dirent_journal != 0) {
7236 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
7239 CDEBUG(D_LFSCK, "%s: fail to start trans for dirent "
7240 "check_repair, dir = %lu/%u, credits = %d, "
7241 "name = %.*s, ino = %llu: rc = %d\n",
7242 devname, dir->i_ino, dir->i_generation, credits,
7243 ent->oied_namelen, ent->oied_name,
7246 GOTO(out_inode, rc);
7249 if (obj->oo_hl_head != NULL) {
7250 hlock = osd_oti_get(env)->oti_hlock;
7252 * "0" means exclusive lock for the whole directory.
7253 * We need to prevent others access such name entry
7254 * during the delete + insert. Neither HLOCK_ADD nor
7255 * HLOCK_DEL cannot guarantee the atomicity.
7257 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
7259 down_write(&obj->oo_ext_idx_sem);
7262 if (obj->oo_hl_head != NULL) {
7263 hlock = osd_oti_get(env)->oti_hlock;
7264 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
7265 LDISKFS_HLOCK_LOOKUP);
7267 down_read(&obj->oo_ext_idx_sem);
7271 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
7272 if (IS_ERR(bh) || le32_to_cpu(de->inode) != inode->i_ino) {
7273 *attr |= LUDA_IGNORE;
7279 * For dotdot entry, if there is not enough space to hold the
7280 * FID-in-dirent, just keep them there. It only happens when the
7281 * device upgraded from 1.8 or restored from MDT file-level backup.
7282 * For the whole directory, only dotdot entry have no FID-in-dirent
7283 * and needs to get FID from LMA when readdir, it will not affect the
7286 if (dotdot && !osd_dotdot_has_space(de)) {
7287 *attr |= LUDA_UNKNOWN;
7293 if (lu_fid_eq(fid, &lma->lma_self_fid))
7296 if (unlikely(lma->lma_compat & LMAC_NOT_IN_OI)) {
7297 struct lu_fid *tfid = &lma->lma_self_fid;
7299 if (likely(dotdot &&
7300 fid_seq(tfid) == FID_SEQ_LOCAL_FILE &&
7301 fid_oid(tfid) == REMOTE_PARENT_DIR_OID)) {
7303 * It must be REMOTE_PARENT_DIR and as the
7304 * 'dotdot' entry of remote directory
7306 *attr |= LUDA_IGNORE;
7308 CDEBUG(D_LFSCK, "%s: expect remote agent "
7309 "parent directory, but got %.*s under "
7310 "dir = %lu/%u with the FID "DFID"\n",
7311 devname, ent->oied_namelen,
7312 ent->oied_name, dir->i_ino,
7313 dir->i_generation, PFID(tfid));
7315 *attr |= LUDA_UNKNOWN;
7322 if (!fid_is_zero(fid)) {
7323 rc = osd_verify_ent_by_linkea(env, inode, pfid, ent->oied_name,
7325 if (rc == -ENOENT ||
7327 !(dev->od_scrub.os_scrub.os_file.sf_flags & SF_UPGRADE))) {
7329 * linkEA does not recognize the dirent entry,
7330 * it may because the dirent entry corruption
7331 * and points to other's inode.
7333 CDEBUG(D_LFSCK, "%s: the target inode does not "
7334 "recognize the dirent, dir = %lu/%u, "
7335 " name = %.*s, ino = %llu, "
7336 DFID": rc = %d\n", devname, dir->i_ino,
7337 dir->i_generation, ent->oied_namelen,
7338 ent->oied_name, ent->oied_ino, PFID(fid), rc);
7339 *attr |= LUDA_UNKNOWN;
7344 if (rc && rc != -ENODATA) {
7345 CDEBUG(D_LFSCK, "%s: fail to verify FID in the dirent, "
7346 "dir = %lu/%u, name = %.*s, ino = %llu, "
7347 DFID": rc = %d\n", devname, dir->i_ino,
7348 dir->i_generation, ent->oied_namelen,
7349 ent->oied_name, ent->oied_ino, PFID(fid), rc);
7350 *attr |= LUDA_UNKNOWN;
7358 * linkEA recognizes the dirent entry, the FID-in-LMA is
7359 * valid, trusted, in spite of fid_is_sane(fid) or not.
7361 if (*attr & LUDA_VERIFY_DRYRUN) {
7362 *fid = lma->lma_self_fid;
7363 *attr |= LUDA_REPAIR;
7370 dev->od_dirent_journal = 1;
7371 if (hlock != NULL) {
7372 ldiskfs_htree_unlock(hlock);
7375 up_read(&obj->oo_ext_idx_sem);
7381 *fid = lma->lma_self_fid;
7383 /* Update or append the FID-in-dirent. */
7384 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
7385 bh, de, hlock, dotdot);
7387 *attr |= LUDA_REPAIR;
7389 CDEBUG(D_LFSCK, "%s: fail to re-insert FID after "
7390 "the dirent, dir = %lu/%u, name = %.*s, "
7391 "ino = %llu, "DFID": rc = %d\n",
7392 devname, dir->i_ino, dir->i_generation,
7393 ent->oied_namelen, ent->oied_name,
7394 ent->oied_ino, PFID(fid), rc);
7396 /* lma is NULL, trust the FID-in-dirent if it is valid. */
7397 if (*attr & LUDA_VERIFY_DRYRUN) {
7398 if (fid_is_sane(fid)) {
7399 *attr |= LUDA_REPAIR;
7400 } else if (dev->od_index == 0) {
7401 lu_igif_build(fid, inode->i_ino,
7402 inode->i_generation);
7403 *attr |= LUDA_UPGRADE;
7411 dev->od_dirent_journal = 1;
7412 if (hlock != NULL) {
7413 ldiskfs_htree_unlock(hlock);
7416 up_read(&obj->oo_ext_idx_sem);
7423 if (unlikely(fid_is_sane(fid))) {
7425 * FID-in-dirent exists, but FID-in-LMA is lost.
7426 * Trust the FID-in-dirent, and add FID-in-LMA.
7428 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
7430 *attr |= LUDA_REPAIR;
7432 CDEBUG(D_LFSCK, "%s: fail to set LMA for "
7433 "update dirent, dir = %lu/%u, "
7434 "name = %.*s, ino = %llu, "
7436 devname, dir->i_ino, dir->i_generation,
7437 ent->oied_namelen, ent->oied_name,
7438 ent->oied_ino, PFID(fid), rc);
7439 } else if (dev->od_index == 0) {
7440 lu_igif_build(fid, inode->i_ino, inode->i_generation);
7442 * It is probably IGIF object. Only aappend the
7443 * FID-in-dirent. OI scrub will process FID-in-LMA.
7445 rc = osd_dirent_reinsert(env, dev, jh, dentry, fid,
7446 bh, de, hlock, dotdot);
7448 *attr |= LUDA_UPGRADE;
7450 CDEBUG(D_LFSCK, "%s: fail to append IGIF "
7451 "after the dirent, dir = %lu/%u, "
7452 "name = %.*s, ino = %llu, "
7454 devname, dir->i_ino, dir->i_generation,
7455 ent->oied_namelen, ent->oied_name,
7456 ent->oied_ino, PFID(fid), rc);
7465 if (hlock != NULL) {
7466 ldiskfs_htree_unlock(hlock);
7468 if (dev->od_dirent_journal != 0)
7469 up_write(&obj->oo_ext_idx_sem);
7471 up_read(&obj->oo_ext_idx_sem);
7475 ldiskfs_journal_stop(jh);
7479 if (rc >= 0 && !dirty)
7480 dev->od_dirent_journal = 0;
7481 if (ln.ln_name != ent->oied_name)
7488 * Returns the value at current position from iterator's in memory structure.
7490 * \param di struct osd_it_ea, iterator's in memory structure
7491 * \param attr attr requested for dirent.
7492 * \param lde lustre dirent
7494 * \retval 0 no error and \param lde has correct lustre dirent.
7495 * \retval -ve on error
7497 static inline int osd_it_ea_rec(const struct lu_env *env,
7498 const struct dt_it *di,
7499 struct dt_rec *dtrec, __u32 attr)
7501 struct osd_it_ea *it = (struct osd_it_ea *)di;
7502 struct osd_object *obj = it->oie_obj;
7503 struct osd_device *dev = osd_obj2dev(obj);
7504 struct osd_thread_info *oti = osd_oti_get(env);
7505 struct osd_inode_id *id = &oti->oti_id;
7506 struct lu_fid *fid = &it->oie_dirent->oied_fid;
7507 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
7508 __u32 ino = it->oie_dirent->oied_ino;
7513 LASSERT(!is_remote_parent_ino(dev, obj->oo_inode->i_ino));
7515 if (attr & LUDA_VERIFY) {
7516 if (unlikely(is_remote_parent_ino(dev, ino))) {
7517 attr |= LUDA_IGNORE;
7519 * If the parent is on remote MDT, and there
7520 * is no FID-in-dirent, then we have to get
7521 * the parent FID from the linkEA.
7523 if (!fid_is_sane(fid) &&
7524 it->oie_dirent->oied_namelen == 2 &&
7525 it->oie_dirent->oied_name[0] == '.' &&
7526 it->oie_dirent->oied_name[1] == '.')
7527 osd_get_pfid_from_linkea(env, obj, fid);
7529 rc = osd_dirent_check_repair(env, obj, it, fid, id,
7533 if (!fid_is_sane(fid))
7534 attr |= LUDA_UNKNOWN;
7536 attr &= ~LU_DIRENT_ATTRS_MASK;
7537 if (!fid_is_sane(fid)) {
7538 bool is_dotdot = false;
7540 if (it->oie_dirent->oied_namelen == 2 &&
7541 it->oie_dirent->oied_name[0] == '.' &&
7542 it->oie_dirent->oied_name[1] == '.')
7545 * If the parent is on remote MDT, and there
7546 * is no FID-in-dirent, then we have to get
7547 * the parent FID from the linkEA.
7549 if (is_remote_parent_ino(dev, ino) && is_dotdot) {
7550 rc = osd_get_pfid_from_linkea(env, obj, fid);
7552 if (is_dotdot == false &&
7553 OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
7556 rc = osd_ea_fid_get(env, obj, ino, fid, id);
7561 /* Pack the entry anyway, at least the offset is right. */
7562 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
7563 it->oie_dirent->oied_name,
7564 it->oie_dirent->oied_namelen,
7565 it->oie_dirent->oied_type, attr);
7567 RETURN(rc > 0 ? 0 : rc);
7571 * Returns the record size size at current position.
7573 * This function will return record(lu_dirent) size in bytes.
7575 * \param[in] env execution environment
7576 * \param[in] di iterator's in memory structure
7577 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
7578 * calculate the lu_dirent size.
7580 * \retval record size(in bytes & in memory) of the current lu_dirent
7583 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
7586 struct osd_it_ea *it = (struct osd_it_ea *)di;
7588 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
7592 * Returns a cookie for current position of the iterator head, so that
7593 * user can use this cookie to load/start the iterator next time.
7595 * \param di iterator's in memory structure
7597 * \retval cookie for current position, on success
7599 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
7601 struct osd_it_ea *it = (struct osd_it_ea *)di;
7603 return it->oie_dirent->oied_off;
7607 * It calls osd_ldiskfs_it_fill() which will use ->iterate*()
7608 * to load a directory entry at a time and stored it i inn,
7609 * in iterator's in-memory data structure.
7611 * \param di struct osd_it_ea, iterator's in memory structure
7613 * \retval +ve on success
7614 * \retval -ve on error
7616 static int osd_it_ea_load(const struct lu_env *env,
7617 const struct dt_it *di, __u64 hash)
7619 struct osd_it_ea *it = (struct osd_it_ea *)di;
7623 it->oie_file->f_pos = hash;
7625 rc = osd_ldiskfs_it_fill(env, di);
7636 * Index lookup function for interoperability mode (b11826).
7638 * \param key, key i.e. file name to be searched
7640 * \retval +ve, on success
7641 * \retval -ve, on error
7643 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
7644 struct dt_rec *rec, const struct dt_key *key)
7646 struct osd_object *obj = osd_dt_obj(dt);
7651 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
7652 LINVRNT(osd_invariant(obj));
7654 rc = osd_ea_lookup_rec(env, obj, rec, key);
7661 * Index and Iterator operations for interoperability
7662 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
7664 static const struct dt_index_operations osd_index_ea_ops = {
7665 .dio_lookup = osd_index_ea_lookup,
7666 .dio_declare_insert = osd_index_declare_ea_insert,
7667 .dio_insert = osd_index_ea_insert,
7668 .dio_declare_delete = osd_index_declare_ea_delete,
7669 .dio_delete = osd_index_ea_delete,
7671 .init = osd_it_ea_init,
7672 .fini = osd_it_ea_fini,
7673 .get = osd_it_ea_get,
7674 .put = osd_it_ea_put,
7675 .next = osd_it_ea_next,
7676 .key = osd_it_ea_key,
7677 .key_size = osd_it_ea_key_size,
7678 .rec = osd_it_ea_rec,
7679 .rec_size = osd_it_ea_rec_size,
7680 .store = osd_it_ea_store,
7681 .load = osd_it_ea_load
7685 static void *osd_key_init(const struct lu_context *ctx,
7686 struct lu_context_key *key)
7688 struct osd_thread_info *info;
7690 OBD_ALLOC_PTR(info);
7692 return ERR_PTR(-ENOMEM);
7694 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7695 if (info->oti_it_ea_buf == NULL)
7698 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
7700 info->oti_hlock = ldiskfs_htree_lock_alloc();
7701 if (info->oti_hlock == NULL)
7707 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7710 return ERR_PTR(-ENOMEM);
7713 static void osd_key_fini(const struct lu_context *ctx,
7714 struct lu_context_key *key, void *data)
7716 struct osd_thread_info *info = data;
7717 struct ldiskfs_inode_info *lli = LDISKFS_I(info->oti_inode);
7718 struct osd_idmap_cache *idc = info->oti_ins_cache;
7720 if (info->oti_dio_pages) {
7722 for (i = 0; i < PTLRPC_MAX_BRW_PAGES; i++) {
7723 struct page *page = info->oti_dio_pages[i];
7725 LASSERT(PagePrivate2(page));
7726 LASSERT(PageLocked(page));
7727 ClearPagePrivate2(page);
7732 OBD_FREE_PTR_ARRAY_LARGE(info->oti_dio_pages,
7733 PTLRPC_MAX_BRW_PAGES);
7736 if (info->oti_inode != NULL)
7738 if (info->oti_hlock != NULL)
7739 ldiskfs_htree_lock_free(info->oti_hlock);
7740 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
7741 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
7742 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
7743 lu_buf_free(&info->oti_iobuf.dr_lnb_buf);
7744 lu_buf_free(&info->oti_big_buf);
7746 LASSERT(info->oti_ins_cache_size > 0);
7747 OBD_FREE_PTR_ARRAY_LARGE(idc, info->oti_ins_cache_size);
7748 info->oti_ins_cache = NULL;
7749 info->oti_ins_cache_size = 0;
7754 static void osd_key_exit(const struct lu_context *ctx,
7755 struct lu_context_key *key, void *data)
7757 struct osd_thread_info *info = data;
7759 LASSERT(info->oti_r_locks == 0);
7760 LASSERT(info->oti_w_locks == 0);
7761 LASSERT(info->oti_txns == 0);
7762 LASSERTF(info->oti_dio_pages_used == 0, "%d\n",
7763 info->oti_dio_pages_used);
7766 /* type constructor/destructor: osd_type_init, osd_type_fini */
7767 LU_TYPE_INIT_FINI(osd, &osd_key);
7769 struct lu_context_key osd_key = {
7770 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
7771 .lct_init = osd_key_init,
7772 .lct_fini = osd_key_fini,
7773 .lct_exit = osd_key_exit
7777 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
7778 const char *name, struct lu_device *next)
7780 struct osd_device *osd = osd_dev(d);
7782 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname)) >=
7783 sizeof(osd->od_svname))
7785 return osd_procfs_init(osd, name);
7788 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
7790 struct seq_server_site *ss = osd_seq_site(osd);
7795 if (osd->od_is_ost || osd->od_cl_seq != NULL)
7798 if (unlikely(ss == NULL))
7801 OBD_ALLOC_PTR(osd->od_cl_seq);
7802 if (osd->od_cl_seq == NULL)
7805 seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
7806 osd->od_svname, ss->ss_server_seq);
7808 if (ss->ss_node_id == 0) {
7810 * If the OSD on the sequence controller(MDT0), then allocate
7811 * sequence here, otherwise allocate sequence after connected
7812 * to MDT0 (see mdt_register_lwp_callback()).
7814 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
7815 &osd->od_cl_seq->lcs_space, env);
7821 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
7823 if (osd->od_cl_seq == NULL)
7826 seq_client_fini(osd->od_cl_seq);
7827 OBD_FREE_PTR(osd->od_cl_seq);
7828 osd->od_cl_seq = NULL;
7831 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
7835 /* shutdown quota slave instance associated with the device */
7836 if (o->od_quota_slave_md != NULL) {
7837 struct qsd_instance *qsd = o->od_quota_slave_md;
7839 o->od_quota_slave_md = NULL;
7843 if (o->od_quota_slave_dt != NULL) {
7844 struct qsd_instance *qsd = o->od_quota_slave_dt;
7846 o->od_quota_slave_dt = NULL;
7850 osd_fid_fini(env, o);
7851 osd_scrub_cleanup(env, o);
7856 static void osd_umount(const struct lu_env *env, struct osd_device *o)
7860 if (o->od_mnt != NULL) {
7861 shrink_dcache_sb(osd_sb(o));
7862 osd_sync(env, &o->od_dt_dev);
7863 wait_event(o->od_commit_cb_done,
7864 !atomic_read(&o->od_commit_cb_in_flight));
7873 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
7874 # ifndef LDISKFS_HAS_INCOMPAT_FEATURE
7875 /* Newer kernels provide the ldiskfs_set_feature_largedir() wrapper already,
7876 * which calls ldiskfs_update_dynamic_rev() to update ancient filesystems.
7877 * All ldiskfs filesystems are already v2, so it is a no-op and unnecessary.
7878 * This avoids maintaining patches to export this otherwise-useless function.
7880 void ldiskfs_update_dynamic_rev(struct super_block *sb)
7887 static int osd_mount(const struct lu_env *env,
7888 struct osd_device *o, struct lustre_cfg *cfg)
7890 const char *name = lustre_cfg_string(cfg, 0);
7891 const char *dev = lustre_cfg_string(cfg, 1);
7893 unsigned long page, s_flags = 0, lmd_flags = 0;
7894 struct page *__page;
7895 struct file_system_type *type;
7896 char *options = NULL;
7898 struct osd_thread_info *info = osd_oti_get(env);
7899 struct lu_fid *fid = &info->oti_fid;
7900 struct inode *inode;
7901 int rc = 0, force_over_1024tb = 0;
7905 if (o->od_mnt != NULL)
7908 if (strlen(dev) >= sizeof(o->od_mntdev))
7910 strcpy(o->od_mntdev, dev);
7912 str = lustre_cfg_buf(cfg, 2);
7913 sscanf(str, "%lu:%lu", &s_flags, &lmd_flags);
7915 opts = lustre_cfg_string(cfg, 3);
7917 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
7918 CERROR("%s: device %s extents feature is not guaranteed to "
7919 "work on big-endian systems. Use \"bigendian_extents\" "
7920 "mount option to override.\n", name, dev);
7924 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
7925 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) {
7926 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");
7929 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 1, 53, 0)
7930 if (opts != NULL && strstr(opts, "force_over_256tb") != NULL) {
7931 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");
7934 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
7935 if (opts != NULL && strstr(opts, "force_over_512tb") != NULL) {
7936 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");
7940 if (opts != NULL && strstr(opts, "force_over_1024tb") != NULL)
7941 force_over_1024tb = 1;
7943 __page = alloc_page(GFP_KERNEL);
7945 GOTO(out, rc = -ENOMEM);
7946 page = (unsigned long)page_address(__page);
7947 options = (char *)page;
7950 /* strip out the options for back compatiblity */
7951 static const char * const sout[] = {
7958 /* strip out option we processed in osd */
7959 "bigendian_extents",
7963 "force_over_1024tb",
7967 strncat(options, opts, PAGE_SIZE);
7968 for (rc = 0, str = options; sout[rc]; ) {
7969 char *op = strstr(str, sout[rc]);
7976 if (op == options || *(op - 1) == ',') {
7977 str = op + strlen(sout[rc]);
7978 if (*str == ',' || *str == '\0') {
7979 *str == ',' ? str++ : str;
7980 memmove(op, str, strlen(str) + 1);
7983 for (str = op; *str != ',' && *str != '\0'; str++)
7987 strncat(options, "user_xattr,acl", PAGE_SIZE);
7990 /* Glom up mount options */
7991 if (*options != '\0')
7992 strncat(options, ",", PAGE_SIZE);
7993 strncat(options, "no_mbcache,nodelalloc", PAGE_SIZE);
7995 type = get_fs_type("ldiskfs");
7997 CERROR("%s: cannot find ldiskfs module\n", name);
7998 GOTO(out, rc = -ENODEV);
8001 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
8002 module_put(type->owner);
8004 if (IS_ERR(o->od_mnt)) {
8005 rc = PTR_ERR(o->od_mnt);
8007 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
8011 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) <<
8012 osd_sb(o)->s_blocksize_bits > 1024ULL << 40 &&
8013 force_over_1024tb == 0) {
8014 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",
8016 GOTO(out_mnt, rc = -EINVAL);
8019 if (lmd_flags & LMD_FLG_DEV_RDONLY) {
8020 LCONSOLE_WARN("%s: not support dev_rdonly on this device\n",
8023 GOTO(out_mnt, rc = -EOPNOTSUPP);
8026 if (!ldiskfs_has_feature_journal(o->od_mnt->mnt_sb)) {
8027 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
8028 GOTO(out_mnt, rc = -EINVAL);
8031 if (ldiskfs_has_feature_fast_commit(o->od_mnt->mnt_sb)) {
8032 CERROR("%s: device %s is mounted with fast_commit that breaks recovery\n",
8034 GOTO(out_mnt, rc = -EOPNOTSUPP);
8037 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 53, 0)
8038 #ifdef LDISKFS_MOUNT_DIRDATA
8039 if (ldiskfs_has_feature_dirdata(o->od_mnt->mnt_sb))
8040 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
8041 else if (strstr(name, "MDT")) /* don't complain for MGT or OSTs */
8042 CWARN("%s: device %s was upgraded from Lustre-1.x without "
8043 "enabling the dirdata feature. If you do not want to "
8044 "downgrade to Lustre-1.x again, you can enable it via "
8045 "'tune2fs -O dirdata device'\n", name, dev);
8047 /* enable large_dir on MDTs to avoid REMOTE_PARENT_DIR overflow,
8048 * and on very large OSTs to avoid object directory overflow */
8049 if (unlikely(!ldiskfs_has_feature_largedir(o->od_mnt->mnt_sb) &&
8050 !strstr(name, "MGS"))) {
8051 ldiskfs_set_feature_largedir(o->od_mnt->mnt_sb);
8052 LCONSOLE_INFO("%s: enabled 'large_dir' feature on device %s\n",
8056 inode = osd_sb(o)->s_root->d_inode;
8057 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
8058 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
8060 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
8064 if (lmd_flags & LMD_FLG_NOSCRUB)
8065 o->od_scrub.os_scrub.os_auto_scrub_interval = AS_NEVER;
8067 if (blk_queue_nonrot(bdev_get_queue(osd_sb(o)->s_bdev))) {
8068 /* do not use pagecache with flash-backed storage */
8069 o->od_writethrough_cache = 0;
8070 o->od_read_cache = 0;
8081 __free_page(__page);
8086 static struct lu_device *osd_device_fini(const struct lu_env *env,
8087 struct lu_device *d)
8089 struct osd_device *o = osd_dev(d);
8093 osd_index_backup(env, o, false);
8094 osd_shutdown(env, o);
8096 if (o->od_oi_table != NULL)
8097 osd_oi_fini(osd_oti_get(env), o);
8098 if (o->od_extent_bytes_percpu)
8099 free_percpu(o->od_extent_bytes_percpu);
8100 osd_obj_map_fini(o);
8106 static int osd_device_init0(const struct lu_env *env,
8107 struct osd_device *o,
8108 struct lustre_cfg *cfg)
8110 struct lu_device *l = osd2lu_dev(o);
8111 struct osd_thread_info *info;
8114 bool restored = false;
8117 /* if the module was re-loaded, env can loose its keys */
8118 rc = lu_env_refill((struct lu_env *)env);
8121 info = osd_oti_get(env);
8124 l->ld_ops = &osd_lu_ops;
8125 o->od_dt_dev.dd_ops = &osd_dt_ops;
8127 spin_lock_init(&o->od_osfs_lock);
8128 mutex_init(&o->od_otable_mutex);
8129 INIT_LIST_HEAD(&o->od_orphan_list);
8130 INIT_LIST_HEAD(&o->od_index_backup_list);
8131 INIT_LIST_HEAD(&o->od_index_restore_list);
8132 spin_lock_init(&o->od_lock);
8133 o->od_index_backup_policy = LIBP_NONE;
8135 init_waitqueue_head(&o->od_commit_cb_done);
8137 o->od_read_cache = 1;
8138 o->od_writethrough_cache = 1;
8139 o->od_enable_projid_xattr = 0;
8140 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
8141 o->od_readcache_max_iosize = OSD_READCACHE_MAX_IO_MB << 20;
8142 o->od_writethrough_max_iosize = OSD_WRITECACHE_MAX_IO_MB << 20;
8143 o->od_scrub.os_scrub.os_auto_scrub_interval = AS_DEFAULT;
8144 /* default fallocate to unwritten extents: LU-14326/LU-14333 */
8145 o->od_fallocate_zero_blocks = 0;
8147 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
8148 sizeof(o->od_svname));
8149 if (cplen >= sizeof(o->od_svname)) {
8154 o->od_index_backup_stop = 0;
8155 o->od_index = -1; /* -1 means index is invalid */
8156 rc = server_name2index(o->od_svname, &o->od_index, NULL);
8157 if (rc == LDD_F_SV_TYPE_OST)
8160 o->od_full_scrub_ratio = OFSR_DEFAULT;
8161 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
8162 rc = osd_mount(env, o, cfg);
8166 /* Can only check block device after mount */
8167 o->od_nonrotational =
8168 blk_queue_nonrot(bdev_get_queue(osd_sb(o)->s_bdev));
8170 rc = osd_obj_map_init(env, o);
8174 rc = lu_site_init(&o->od_site, l);
8176 GOTO(out_compat, rc);
8177 o->od_site.ls_bottom_dev = l;
8179 rc = lu_site_init_finish(&o->od_site);
8183 opts = lustre_cfg_string(cfg, 3);
8184 if (opts && strstr(opts, "resetoi"))
8187 INIT_LIST_HEAD(&o->od_ios_list);
8189 rc = lprocfs_init_brw_stats(&o->od_brw_stats);
8191 GOTO(out_brw_stats, rc);
8193 /* setup scrub, including OI files initialization */
8195 rc = osd_scrub_setup(env, o, restored);
8198 GOTO(out_brw_stats, rc);
8200 rc = osd_procfs_init(o, o->od_svname);
8202 CERROR("%s: can't initialize procfs: rc = %d\n",
8204 GOTO(out_scrub, rc);
8207 LASSERT(l->ld_site->ls_linkage.next != NULL);
8208 LASSERT(l->ld_site->ls_linkage.prev != NULL);
8210 /* initialize quota slave instance */
8211 /* currently it's no need to prepare qsd_instance_md for OST */
8212 if (!o->od_is_ost) {
8213 o->od_quota_slave_md = qsd_init(env, o->od_svname,
8214 &o->od_dt_dev, o->od_proc_entry,
8216 if (IS_ERR(o->od_quota_slave_md)) {
8217 rc = PTR_ERR(o->od_quota_slave_md);
8218 o->od_quota_slave_md = NULL;
8219 GOTO(out_procfs, rc);
8223 o->od_quota_slave_dt = qsd_init(env, o->od_svname, &o->od_dt_dev,
8224 o->od_proc_entry, false, true);
8226 if (IS_ERR(o->od_quota_slave_dt)) {
8227 if (o->od_quota_slave_md != NULL) {
8228 qsd_fini(env, o->od_quota_slave_md);
8229 o->od_quota_slave_md = NULL;
8232 rc = PTR_ERR(o->od_quota_slave_dt);
8233 o->od_quota_slave_dt = NULL;
8234 GOTO(out_procfs, rc);
8237 o->od_extent_bytes_percpu = alloc_percpu(unsigned int);
8238 if (!o->od_extent_bytes_percpu) {
8240 GOTO(out_procfs, rc);
8248 osd_scrub_cleanup(env, o);
8250 lprocfs_fini_brw_stats(&o->od_brw_stats);
8252 lu_site_fini(&o->od_site);
8254 osd_obj_map_fini(o);
8261 static struct lu_device *osd_device_alloc(const struct lu_env *env,
8262 struct lu_device_type *t,
8263 struct lustre_cfg *cfg)
8265 struct osd_device *o;
8270 return ERR_PTR(-ENOMEM);
8272 rc = dt_device_init(&o->od_dt_dev, t);
8275 * Because the ctx might be revived in dt_device_init,
8276 * refill the env here
8278 lu_env_refill((struct lu_env *)env);
8279 rc = osd_device_init0(env, o, cfg);
8281 dt_device_fini(&o->od_dt_dev);
8284 if (unlikely(rc != 0))
8287 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
8290 static struct lu_device *osd_device_free(const struct lu_env *env,
8291 struct lu_device *d)
8293 struct osd_device *o = osd_dev(d);
8297 /* XXX: make osd top device in order to release reference */
8298 d->ld_site->ls_top_dev = d;
8299 lu_site_purge(env, d->ld_site, -1);
8300 lu_site_print(env, d->ld_site, &d->ld_site->ls_obj_hash.nelems,
8301 D_ERROR, lu_cdebug_printer);
8302 lu_site_fini(&o->od_site);
8303 dt_device_fini(&o->od_dt_dev);
8308 static int osd_process_config(const struct lu_env *env,
8309 struct lu_device *d, struct lustre_cfg *cfg)
8311 struct osd_device *o = osd_dev(d);
8317 switch (cfg->lcfg_command) {
8319 rc = osd_mount(env, o, cfg);
8323 * For the case LCFG_PRE_CLEANUP is not called in advance,
8324 * that may happend if hit failure during mount process.
8326 osd_index_backup(env, o, false);
8327 lu_dev_del_linkage(d->ld_site, d);
8328 rc = osd_shutdown(env, o);
8331 LASSERT(&o->od_dt_dev);
8332 count = class_modify_config(cfg, PARAM_OSD,
8333 &o->od_dt_dev.dd_kobj);
8335 count = class_modify_config(cfg, PARAM_OST,
8336 &o->od_dt_dev.dd_kobj);
8337 rc = count > 0 ? 0 : count;
8339 case LCFG_PRE_CLEANUP:
8341 osd_index_backup(env, o,
8342 o->od_index_backup_policy != LIBP_NONE);
8352 static int osd_recovery_complete(const struct lu_env *env,
8353 struct lu_device *d)
8355 struct osd_device *osd = osd_dev(d);
8360 if (osd->od_quota_slave_md == NULL && osd->od_quota_slave_dt == NULL)
8364 * start qsd instance on recovery completion, this notifies the quota
8365 * slave code that we are about to process new requests now
8367 rc = qsd_start(env, osd->od_quota_slave_dt);
8368 if (rc == 0 && osd->od_quota_slave_md != NULL)
8369 rc = qsd_start(env, osd->od_quota_slave_md);
8375 * we use exports to track all osd users
8377 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
8378 struct obd_device *obd, struct obd_uuid *cluuid,
8379 struct obd_connect_data *data, void *localdata)
8381 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8382 struct lustre_handle conn;
8387 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
8389 rc = class_connect(&conn, obd, cluuid);
8393 *exp = class_conn2export(&conn);
8395 spin_lock(&osd->od_osfs_lock);
8397 spin_unlock(&osd->od_osfs_lock);
8403 * once last export (we don't count self-export) disappeared
8404 * osd can be released
8406 static int osd_obd_disconnect(struct obd_export *exp)
8408 struct obd_device *obd = exp->exp_obd;
8409 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8410 int rc, release = 0;
8414 /* Only disconnect the underlying layers on the final disconnect. */
8415 spin_lock(&osd->od_osfs_lock);
8417 if (osd->od_connects == 0)
8419 spin_unlock(&osd->od_osfs_lock);
8421 rc = class_disconnect(exp); /* bz 9811 */
8423 if (rc == 0 && release)
8424 class_manual_cleanup(obd);
8428 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
8429 struct lu_device *dev)
8431 struct osd_device *osd = osd_dev(dev);
8432 struct lr_server_data *lsd =
8433 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
8438 if (osd->od_quota_slave_md != NULL) {
8439 /* set up quota slave objects for inode */
8440 result = qsd_prepare(env, osd->od_quota_slave_md);
8445 if (osd->od_quota_slave_dt != NULL) {
8446 /* set up quota slave objects for block */
8447 result = qsd_prepare(env, osd->od_quota_slave_dt);
8453 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
8454 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
8455 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
8456 osd->od_index_in_idif = 1;
8458 osd->od_index_in_idif = 0;
8459 result = osd_register_proc_index_in_idif(osd);
8464 osd->od_index_in_idif = 1;
8468 result = osd_fid_init(env, osd);
8474 * Implementation of lu_device_operations::ldo_fid_alloc() for OSD
8478 * see include/lu_object.h for the details.
8480 static int osd_fid_alloc(const struct lu_env *env, struct lu_device *d,
8481 struct lu_fid *fid, struct lu_object *parent,
8482 const struct lu_name *name)
8484 struct osd_device *osd = osd_dev(d);
8486 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
8489 static const struct lu_object_operations osd_lu_obj_ops = {
8490 .loo_object_init = osd_object_init,
8491 .loo_object_delete = osd_object_delete,
8492 .loo_object_release = osd_object_release,
8493 .loo_object_free = osd_object_free,
8494 .loo_object_print = osd_object_print,
8495 .loo_object_invariant = osd_object_invariant
8498 const struct lu_device_operations osd_lu_ops = {
8499 .ldo_object_alloc = osd_object_alloc,
8500 .ldo_process_config = osd_process_config,
8501 .ldo_recovery_complete = osd_recovery_complete,
8502 .ldo_prepare = osd_prepare,
8503 .ldo_fid_alloc = osd_fid_alloc,
8506 static const struct lu_device_type_operations osd_device_type_ops = {
8507 .ldto_init = osd_type_init,
8508 .ldto_fini = osd_type_fini,
8510 .ldto_start = osd_type_start,
8511 .ldto_stop = osd_type_stop,
8513 .ldto_device_alloc = osd_device_alloc,
8514 .ldto_device_free = osd_device_free,
8516 .ldto_device_init = osd_device_init,
8517 .ldto_device_fini = osd_device_fini
8520 static struct lu_device_type osd_device_type = {
8521 .ldt_tags = LU_DEVICE_DT,
8522 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
8523 .ldt_ops = &osd_device_type_ops,
8524 .ldt_ctx_tags = LCT_LOCAL,
8527 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
8529 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
8530 struct super_block *sb = osd_sb(osd);
8532 return (osd->od_mnt == NULL || sb->s_flags & SB_RDONLY);
8536 * lprocfs legacy support.
8538 static const struct obd_ops osd_obd_device_ops = {
8539 .o_owner = THIS_MODULE,
8540 .o_connect = osd_obd_connect,
8541 .o_disconnect = osd_obd_disconnect,
8542 .o_health_check = osd_health_check,
8545 static ssize_t track_declares_assert_show(struct kobject *kobj,
8546 struct attribute *attr,
8549 return sprintf(buf, "%d\n", ldiskfs_track_declares_assert);
8552 static ssize_t track_declares_assert_store(struct kobject *kobj,
8553 struct attribute *attr,
8554 const char *buffer, size_t count)
8556 bool track_declares_assert;
8559 rc = kstrtobool(buffer, &track_declares_assert);
8563 ldiskfs_track_declares_assert = track_declares_assert;
8567 LUSTRE_RW_ATTR(track_declares_assert);
8569 static int __init osd_init(void)
8571 struct kobject *kobj;
8574 BUILD_BUG_ON(BH_DXLock >=
8575 sizeof(((struct buffer_head *)0)->b_state) * 8);
8576 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
8577 /* please, try to keep osd_thread_info smaller than a page */
8578 BUILD_BUG_ON(sizeof(struct osd_thread_info) > PAGE_SIZE);
8583 rc = lu_kmem_init(ldiskfs_caches);
8587 rc = class_register_type(&osd_obd_device_ops, NULL, true,
8588 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
8590 lu_kmem_fini(ldiskfs_caches);
8594 kobj = kset_find_obj(lustre_kset, LUSTRE_OSD_LDISKFS_NAME);
8596 rc = sysfs_create_file(kobj,
8597 &lustre_attr_track_declares_assert.attr);
8600 CWARN("osd-ldiskfs: track_declares_assert failed to register with sysfs\n");
8608 static void __exit osd_exit(void)
8610 struct kobject *kobj;
8612 kobj = kset_find_obj(lustre_kset, LUSTRE_OSD_LDISKFS_NAME);
8614 sysfs_remove_file(kobj,
8615 &lustre_attr_track_declares_assert.attr);
8618 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
8619 lu_kmem_fini(ldiskfs_caches);
8622 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
8623 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
8624 MODULE_VERSION(LUSTRE_VERSION_STRING);
8625 MODULE_LICENSE("GPL");
8627 module_init(osd_init);
8628 module_exit(osd_exit);