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/kallsyms.h>
43 #include <linux/module.h>
44 #include <linux/user_namespace.h>
45 #include <linux/uidgid.h>
47 /* prerequisite for linux/xattr.h */
48 #include <linux/types.h>
49 /* prerequisite for linux/xattr.h */
51 /* XATTR_{REPLACE,CREATE} */
52 #include <linux/xattr.h>
54 #include <ldiskfs/ldiskfs.h>
55 #include <ldiskfs/xattr.h>
56 #include <ldiskfs/ldiskfs_extents.h>
59 * struct OBD_{ALLOC,FREE}*()
62 #include <obd_support.h>
63 /* struct ptlrpc_thread */
64 #include <lustre_net.h>
65 #include <lustre_fid.h>
67 #include <uapi/linux/lustre/lustre_param.h>
69 #include "osd_internal.h"
70 #include "osd_dynlocks.h"
72 /* llo_* api support */
73 #include <md_object.h>
74 #include <lustre_quota.h>
76 #include <lustre_linkea.h>
78 /* Maximum EA size is limited by LNET_MTU for remote objects */
79 #define OSD_MAX_EA_SIZE 1048364
82 module_param(ldiskfs_pdo, int, 0644);
83 MODULE_PARM_DESC(ldiskfs_pdo, "ldiskfs with parallel directory operations");
85 int ldiskfs_track_declares_assert;
86 module_param(ldiskfs_track_declares_assert, int, 0644);
87 MODULE_PARM_DESC(ldiskfs_track_declares_assert, "LBUG during tracking of declares");
89 /* Slab to allocate dynlocks */
90 struct kmem_cache *dynlock_cachep;
92 /* Slab to allocate osd_it_ea */
93 struct kmem_cache *osd_itea_cachep;
95 static struct lu_kmem_descr ldiskfs_caches[] = {
97 .ckd_cache = &dynlock_cachep,
98 .ckd_name = "dynlock_cache",
99 .ckd_size = sizeof(struct dynlock_handle)
102 .ckd_cache = &osd_itea_cachep,
103 .ckd_name = "osd_itea_cache",
104 .ckd_size = sizeof(struct osd_it_ea)
111 static const char dot[] = ".";
112 static const char dotdot[] = "..";
114 static const struct lu_object_operations osd_lu_obj_ops;
115 static const struct dt_object_operations osd_obj_ops;
116 static const struct dt_object_operations osd_obj_otable_it_ops;
117 static const struct dt_index_operations osd_index_iam_ops;
118 static const struct dt_index_operations osd_index_ea_ops;
120 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
121 const struct lu_fid *fid);
122 static int osd_process_scheduled_agent_removals(const struct lu_env *env,
123 struct osd_device *osd);
125 int osd_trans_declare_op2rb[] = {
126 [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET,
127 [OSD_OT_PUNCH] = OSD_OT_MAX,
128 [OSD_OT_XATTR_SET] = OSD_OT_XATTR_SET,
129 [OSD_OT_CREATE] = OSD_OT_DESTROY,
130 [OSD_OT_DESTROY] = OSD_OT_CREATE,
131 [OSD_OT_REF_ADD] = OSD_OT_REF_DEL,
132 [OSD_OT_REF_DEL] = OSD_OT_REF_ADD,
133 [OSD_OT_WRITE] = OSD_OT_WRITE,
134 [OSD_OT_INSERT] = OSD_OT_DELETE,
135 [OSD_OT_DELETE] = OSD_OT_INSERT,
136 [OSD_OT_QUOTA] = OSD_OT_MAX,
139 static int osd_has_index(const struct osd_object *obj)
141 return obj->oo_dt.do_index_ops != NULL;
144 static int osd_object_invariant(const struct lu_object *l)
146 return osd_invariant(osd_obj(l));
150 * Concurrency: doesn't matter
152 static int osd_is_write_locked(const struct lu_env *env, struct osd_object *o)
154 struct osd_thread_info *oti = osd_oti_get(env);
156 return oti->oti_w_locks > 0 && o->oo_owner == env;
160 * Concurrency: doesn't access mutable data
162 static int osd_root_get(const struct lu_env *env,
163 struct dt_device *dev, struct lu_fid *f)
165 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
170 * the following set of functions are used to maintain per-thread
171 * cache of FID->ino mapping. this mechanism is needed to resolve
172 * FID to inode at dt_insert() which in turn stores ino in the
173 * directory entries to keep ldiskfs compatible with ext[34].
174 * due to locking-originated restrictions we can't lookup ino
175 * using LU cache (deadlock is possible). lookup using OI is quite
176 * expensive. so instead we maintain this cache and methods like
177 * dt_create() fill it. so in the majority of cases dt_insert() is
178 * able to find needed mapping in lockless manner.
180 static struct osd_idmap_cache *
181 osd_idc_find(const struct lu_env *env, struct osd_device *osd,
182 const struct lu_fid *fid)
184 struct osd_thread_info *oti = osd_oti_get(env);
185 struct osd_idmap_cache *idc = oti->oti_ins_cache;
188 for (i = 0; i < oti->oti_ins_cache_used; i++) {
189 if (!lu_fid_eq(&idc[i].oic_fid, fid))
191 if (idc[i].oic_dev != osd)
200 static struct osd_idmap_cache *
201 osd_idc_add(const struct lu_env *env, struct osd_device *osd,
202 const struct lu_fid *fid)
204 struct osd_thread_info *oti = osd_oti_get(env);
205 struct osd_idmap_cache *idc;
208 if (unlikely(oti->oti_ins_cache_used >= oti->oti_ins_cache_size)) {
209 i = oti->oti_ins_cache_size * 2;
211 i = OSD_INS_CACHE_SIZE;
212 OBD_ALLOC_PTR_ARRAY(idc, i);
214 return ERR_PTR(-ENOMEM);
215 if (oti->oti_ins_cache != NULL) {
216 memcpy(idc, oti->oti_ins_cache,
217 oti->oti_ins_cache_used * sizeof(*idc));
218 OBD_FREE_PTR_ARRAY(oti->oti_ins_cache,
219 oti->oti_ins_cache_used);
221 oti->oti_ins_cache = idc;
222 oti->oti_ins_cache_size = i;
225 idc = oti->oti_ins_cache + oti->oti_ins_cache_used++;
228 idc->oic_lid.oii_ino = 0;
229 idc->oic_lid.oii_gen = 0;
236 * lookup mapping for the given fid in the cache, initialize a
237 * new one if not found. the initialization checks whether the
238 * object is local or remote. for local objects, OI is used to
239 * learn ino/generation. the function is used when the caller
240 * has no information about the object, e.g. at dt_insert().
242 static struct osd_idmap_cache *
243 osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd,
244 const struct lu_fid *fid)
246 struct osd_idmap_cache *idc;
249 idc = osd_idc_find(env, osd, fid);
250 LASSERT(!IS_ERR(idc));
254 CDEBUG(D_INODE, "%s: FID "DFID" not in the id map cache\n",
255 osd->od_svname, PFID(fid));
257 /* new mapping is needed */
258 idc = osd_idc_add(env, osd, fid);
260 CERROR("%s: FID "DFID" add id map cache failed: %ld\n",
261 osd->od_svname, PFID(fid), PTR_ERR(idc));
266 rc = osd_remote_fid(env, osd, fid);
267 if (unlikely(rc < 0))
271 /* the object is local, lookup in OI */
272 /* XXX: probably cheaper to lookup in LU first? */
273 rc = osd_oi_lookup(osd_oti_get(env), osd, fid,
275 if (unlikely(rc < 0)) {
276 CERROR("can't lookup: rc = %d\n", rc);
280 /* the object is remote */
287 static void osd_idc_dump_lma(const struct lu_env *env,
288 struct osd_device *osd,
292 struct osd_thread_info *info = osd_oti_get(env);
293 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
294 const struct lu_fid *fid;
295 struct osd_inode_id lid;
299 inode = osd_ldiskfs_iget(osd_sb(osd), ino);
301 CERROR("%s: can't get inode %lu: rc = %d\n",
302 osd->od_svname, ino, (int)PTR_ERR(inode));
305 if (is_bad_inode(inode)) {
306 CERROR("%s: bad inode %lu\n", osd->od_svname, ino);
309 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
311 CERROR("%s: can't get LMA for %lu: rc = %d\n",
312 osd->od_svname, ino, rc);
315 fid = &loa->loa_lma.lma_self_fid;
316 LCONSOLE(D_INFO, "%s: "DFID" in inode %lu/%u\n", osd->od_svname,
317 PFID(fid), ino, (unsigned)inode->i_generation);
320 rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0);
322 CERROR("%s: can't lookup "DFID": rc = %d\n",
323 osd->od_svname, PFID(fid), rc);
326 LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n", osd->od_svname,
327 PFID(fid), lid.oii_ino, lid.oii_gen);
332 static void osd_idc_dump_debug(const struct lu_env *env,
333 struct osd_device *osd,
334 const struct lu_fid *fid,
338 struct osd_inode_id lid;
342 rc = osd_oi_lookup(osd_oti_get(env), osd, fid, &lid, 0);
344 LCONSOLE(D_INFO, "%s: "DFID" maps to %u/%u\n",
345 osd->od_svname, PFID(fid), lid.oii_ino, lid.oii_gen);
346 osd_idc_dump_lma(env, osd, lid.oii_ino, false);
348 CERROR("%s: can't lookup "DFID": rc = %d\n",
349 osd->od_svname, PFID(fid), rc);
352 osd_idc_dump_lma(env, osd, ino1, true);
354 osd_idc_dump_lma(env, osd, ino2, true);
358 * lookup mapping for given FID and fill it from the given object.
359 * the object is lolcal by definition.
361 static int osd_idc_find_and_init(const struct lu_env *env,
362 struct osd_device *osd,
363 struct osd_object *obj)
365 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
366 struct osd_idmap_cache *idc;
368 idc = osd_idc_find(env, osd, fid);
369 LASSERT(!IS_ERR(idc));
371 if (obj->oo_inode == NULL)
373 if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) {
374 if (idc->oic_lid.oii_ino) {
375 osd_idc_dump_debug(env, osd, fid,
376 idc->oic_lid.oii_ino,
377 obj->oo_inode->i_ino);
380 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
381 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
386 CDEBUG(D_INODE, "%s: FID "DFID" not in the id map cache\n",
387 osd->od_svname, PFID(fid));
389 /* new mapping is needed */
390 idc = osd_idc_add(env, osd, fid);
392 CERROR("%s: FID "DFID" add id map cache failed: %ld\n",
393 osd->od_svname, PFID(fid), PTR_ERR(idc));
397 if (obj->oo_inode != NULL) {
398 idc->oic_lid.oii_ino = obj->oo_inode->i_ino;
399 idc->oic_lid.oii_gen = obj->oo_inode->i_generation;
405 * OSD object methods.
409 * Concurrency: no concurrent access is possible that early in object
412 static struct lu_object *osd_object_alloc(const struct lu_env *env,
413 const struct lu_object_header *hdr,
416 struct osd_object *mo;
421 struct lu_object_header *h;
422 struct osd_device *o = osd_dev(d);
424 l = &mo->oo_dt.do_lu;
425 if (unlikely(o->od_in_init)) {
432 lu_object_header_init(h);
433 lu_object_init(l, h, d);
434 lu_object_add_top(h, l);
437 dt_object_init(&mo->oo_dt, NULL, d);
438 mo->oo_header = NULL;
441 mo->oo_dt.do_ops = &osd_obj_ops;
442 l->lo_ops = &osd_lu_obj_ops;
443 init_rwsem(&mo->oo_sem);
444 init_rwsem(&mo->oo_ext_idx_sem);
445 spin_lock_init(&mo->oo_guard);
446 INIT_LIST_HEAD(&mo->oo_xattr_list);
452 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
453 struct dentry *dentry, struct lustre_ost_attrs *loa)
457 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
458 (void *)loa, sizeof(*loa));
460 struct lustre_mdt_attrs *lma = &loa->loa_lma;
462 if (rc < sizeof(*lma))
466 lustre_loa_swab(loa, true);
467 /* Check LMA compatibility */
468 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
470 CWARN("%s: unsupported incompat LMA feature(s) %#x for fid = "DFID", ino = %lu: rc = %d\n",
472 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
473 PFID(&lma->lma_self_fid), inode->i_ino, rc);
475 } else if (rc == 0) {
483 * retrieve object from backend ext fs.
485 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
486 struct osd_inode_id *id)
489 struct inode *inode = NULL;
492 * if we look for an inode withing a running
493 * transaction, then we risk to deadlock
494 * osd_dirent_check_repair() breaks this
496 /* LASSERT(current->journal_info == NULL); */
498 inode = osd_ldiskfs_iget(osd_sb(dev), id->oii_ino);
500 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
501 id->oii_ino, PTR_ERR(inode));
502 } else if (id->oii_gen != OSD_OII_NOGEN &&
503 inode->i_generation != id->oii_gen) {
504 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
505 "i_generation = %u\n",
506 id->oii_ino, id->oii_gen, inode->i_generation);
508 inode = ERR_PTR(-ESTALE);
509 } else if (inode->i_nlink == 0) {
511 * due to parallel readdir and unlink,
512 * we can have dead inode here.
514 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
516 inode = ERR_PTR(-ESTALE);
517 } else if (is_bad_inode(inode)) {
519 CWARN("%s: bad inode: ino = %u: rc = %d\n",
520 osd_dev2name(dev), id->oii_ino, rc);
523 } else if ((rc = osd_attach_jinode(inode))) {
527 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
528 if (id->oii_gen == OSD_OII_NOGEN)
529 osd_id_gen(id, inode->i_ino, inode->i_generation);
532 * Do not update file c/mtime in ldiskfs.
533 * NB: we don't have any lock to protect this because we don't
534 * have reference on osd_object now, but contention with
535 * another lookup + attr_set can't happen in the tiny window
536 * between if (...) and set S_NOCMTIME.
538 if (!(inode->i_flags & S_NOCMTIME))
539 inode->i_flags |= S_NOCMTIME;
544 int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd,
545 handle_t *handle, struct dentry *child,
546 struct inode *inode, struct htree_lock *hlock)
550 rc = __ldiskfs_add_entry(handle, child, inode, hlock);
551 if (rc == -ENOBUFS || rc == -ENOSPC) {
552 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
553 struct inode *parent = child->d_parent->d_inode;
554 struct lu_fid *fid = NULL;
555 char fidstr[FID_LEN + 1] = "unknown";
557 rc2 = osd_get_lma(info, parent, child->d_parent, loa);
559 fid = &loa->loa_lma.lma_self_fid;
560 } else if (rc2 == -ENODATA) {
561 if (unlikely(is_root_inode(parent))) {
562 fid = &info->oti_fid3;
563 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
564 } else if (!osd->od_is_ost && osd->od_index == 0) {
565 fid = &info->oti_fid3;
566 lu_igif_build(fid, parent->i_ino,
567 parent->i_generation);
572 snprintf(fidstr, sizeof(fidstr), DFID, PFID(fid));
574 /* below message is checked in sanity.sh test_129 */
576 CWARN("%s: directory (inode: %lu, FID: %s) has reached max size limit\n",
577 osd_name(osd), parent->i_ino, fidstr);
579 rc = 0; /* ignore such error now */
580 CWARN("%s: directory (inode: %lu, FID: %s) is approaching max size limit\n",
581 osd_name(osd), parent->i_ino, fidstr);
591 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
592 struct osd_inode_id *id, struct lu_fid *fid)
594 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
598 inode = osd_iget(info, dev, id);
602 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
604 *fid = loa->loa_lma.lma_self_fid;
605 } else if (rc == -ENODATA) {
606 if (unlikely(is_root_inode(inode)))
607 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
609 lu_igif_build(fid, inode->i_ino, inode->i_generation);
617 static struct inode *osd_iget_check(struct osd_thread_info *info,
618 struct osd_device *dev,
619 const struct lu_fid *fid,
620 struct osd_inode_id *id,
629 * The cached OI mapping is trustable. If we cannot locate the inode
630 * via the cached OI mapping, then return the failure to the caller
631 * directly without further OI checking.
635 inode = osd_ldiskfs_iget(osd_sb(dev), id->oii_ino);
638 if (!trusted && (rc == -ENOENT || rc == -ESTALE))
641 CDEBUG(D_INODE, "no inode for FID: "DFID", ino = %u, rc = %d\n",
642 PFID(fid), id->oii_ino, rc);
646 if (is_bad_inode(inode)) {
651 CDEBUG(D_INODE, "bad inode for FID: "DFID", ino = %u\n",
652 PFID(fid), id->oii_ino);
656 if (id->oii_gen != OSD_OII_NOGEN &&
657 inode->i_generation != id->oii_gen) {
662 CDEBUG(D_INODE, "unmatched inode for FID: "DFID", ino = %u, "
663 "oii_gen = %u, i_generation = %u\n", PFID(fid),
664 id->oii_ino, id->oii_gen, inode->i_generation);
668 if (inode->i_nlink == 0) {
673 CDEBUG(D_INODE, "stale inode for FID: "DFID", ino = %u\n",
674 PFID(fid), id->oii_ino);
678 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY);
682 __u32 saved_ino = id->oii_ino;
683 __u32 saved_gen = id->oii_gen;
686 LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
688 rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
690 * XXX: There are four possible cases:
692 * Backup/restore caused the OI invalid.
694 * Someone unlinked the object but NOT removed
695 * the OI mapping, such as mount target device
696 * as ldiskfs, and modify something directly.
698 * Someone just removed the object between the
699 * former oi_lookup and the iget. It is normal.
700 * 4. Other failure cases.
702 * Generally, when the device is mounted, it will
703 * auto check whether the system is restored from
704 * file-level backup or not. We trust such detect
705 * to distinguish the 1st case from the 2nd case:
706 * if the OI files are consistent but may contain
707 * stale OI mappings because of case 2, if iget()
708 * returns -ENOENT or -ESTALE, then it should be
713 * If the OI mapping was in OI file before the
714 * osd_iget_check(), but now, it is disappear,
715 * then it must be removed by race. That is a
721 * It is the OI scrub updated the OI mapping by race.
722 * The new OI mapping must be valid.
724 if (saved_ino != id->oii_ino ||
725 (saved_gen != id->oii_gen && saved_gen != OSD_OII_NOGEN)) {
734 if (dev->od_scrub.os_scrub.os_file.sf_flags &
737 * It still can be the case 2, but we cannot
738 * distinguish it from the case 1. So return
739 * -EREMCHG to block current operation until
740 * OI scrub rebuilt the OI mappings.
749 if (inode->i_generation == id->oii_gen)
754 if (id->oii_gen == OSD_OII_NOGEN)
755 osd_id_gen(id, inode->i_ino, inode->i_generation);
758 * Do not update file c/mtime in ldiskfs.
759 * NB: we don't have any lock to protect this because we don't
760 * have reference on osd_object now, but contention with
761 * another lookup + attr_set can't happen in the tiny window
762 * between if (...) and set S_NOCMTIME.
764 if (!(inode->i_flags & S_NOCMTIME))
765 inode->i_flags |= S_NOCMTIME;
782 * \retval +v: new filter_fid does not contain self-fid
783 * \retval 0: filter_fid_18_23, contains self-fid
784 * \retval -v: other failure cases
786 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
787 struct dentry *dentry, struct lu_fid *fid)
789 struct filter_fid *ff = &info->oti_ff;
790 struct ost_id *ostid = &info->oti_ostid;
793 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
794 if (rc == sizeof(struct filter_fid_18_23)) {
795 struct filter_fid_18_23 *ff_old = (void *)ff;
797 ostid_set_seq(ostid, le64_to_cpu(ff_old->ff_seq));
798 rc = ostid_set_id(ostid, le64_to_cpu(ff_old->ff_objid));
800 * XXX: use 0 as the index for compatibility, the caller will
801 * handle index related issues when necessary.
804 ostid_to_fid(fid, ostid, 0);
805 } else if (rc >= (int)sizeof(struct filter_fid_24_29)) {
807 } else if (rc >= 0) {
814 static int osd_lma_self_repair(struct osd_thread_info *info,
815 struct osd_device *osd, struct inode *inode,
816 const struct lu_fid *fid, __u32 compat)
821 LASSERT(current->journal_info == NULL);
823 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
824 osd_dto_credits_noquota[DTO_XATTR_SET]);
827 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
832 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
834 CWARN("%s: cannot self repair the LMA: rc = %d\n",
836 ldiskfs_journal_stop(jh);
840 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
842 struct osd_thread_info *info = osd_oti_get(env);
843 struct osd_device *osd = osd_obj2dev(obj);
844 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
845 struct lustre_mdt_attrs *lma = &loa->loa_lma;
846 struct inode *inode = obj->oo_inode;
847 struct dentry *dentry = &info->oti_obj_dentry;
848 struct lu_fid *fid = NULL;
849 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
854 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
855 (void *)loa, sizeof(*loa));
856 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
857 fid = &lma->lma_self_fid;
858 rc = osd_get_idif(info, inode, dentry, fid);
859 if (rc > 0 || (rc == -ENODATA && osd->od_index_in_idif)) {
861 * For the given OST-object, if it has neither LMA nor
862 * FID in XATTR_NAME_FID, then the given FID (which is
863 * contained in the @obj, from client RPC for locating
864 * the OST-object) is trusted. We use it to generate
867 osd_lma_self_repair(info, osd, inode, rfid,
878 lustre_lma_swab(lma);
879 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
880 (CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT) &&
881 S_ISREG(inode->i_mode)))) {
882 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
883 "fid = "DFID", ino = %lu\n", osd_name(osd),
884 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
885 PFID(rfid), inode->i_ino);
888 fid = &lma->lma_self_fid;
889 if (lma->lma_compat & LMAC_STRIPE_INFO &&
891 obj->oo_pfid_in_lma = 1;
892 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
894 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
898 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
899 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
900 struct ost_id *oi = &info->oti_ostid;
901 struct lu_fid *fid1 = &info->oti_fid3;
902 __u32 idx = fid_idif_ost_idx(rfid);
905 * For old IDIF, the OST index is not part of the IDIF,
906 * Means that different OSTs may have the same IDIFs.
907 * Under such case, we need to make some compatible
908 * check to make sure to trigger OI scrub properly.
910 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
911 /* Given @rfid is new, LMA is old. */
912 fid_to_ostid(fid, oi);
913 ostid_to_fid(fid1, oi, idx);
914 if (lu_fid_eq(fid1, rfid)) {
915 if (osd->od_index_in_idif)
916 osd_lma_self_repair(info, osd,
930 struct osd_check_lmv_buf {
931 /* please keep it as first member */
932 struct dir_context ctx;
933 struct osd_thread_info *oclb_info;
934 struct osd_device *oclb_dev;
940 * It is called internally by ->iterate*() to filter out the
941 * local slave object's FID of the striped directory.
943 * \retval 1 found the local slave's FID
944 * \retval 0 continue to check next item
945 * \retval -ve for failure
947 #ifdef HAVE_FILLDIR_USE_CTX
948 static int osd_stripe_dir_filldir(struct dir_context *buf,
950 static int osd_stripe_dir_filldir(void *buf,
952 const char *name, int namelen,
953 loff_t offset, __u64 ino, unsigned int d_type)
955 struct osd_check_lmv_buf *oclb = (struct osd_check_lmv_buf *)buf;
956 struct osd_thread_info *oti = oclb->oclb_info;
957 struct lu_fid *fid = &oti->oti_fid3;
958 struct osd_inode_id *id = &oti->oti_id3;
959 struct osd_device *dev = oclb->oclb_dev;
968 sscanf(name + 1, SFID, RFID(fid));
969 if (!fid_is_sane(fid))
972 if (osd_remote_fid(oti->oti_env, dev, fid))
975 osd_id_gen(id, ino, OSD_OII_NOGEN);
976 inode = osd_iget(oti, dev, id);
978 return PTR_ERR(inode);
981 osd_add_oi_cache(oti, dev, id, fid);
982 osd_oii_insert(dev, fid, id, true);
983 oclb->oclb_found = true;
989 * When lookup item under striped directory, we need to locate the master
990 * MDT-object of the striped directory firstly, then the client will send
991 * lookup (getattr_by_name) RPC to the MDT with some slave MDT-object's FID
992 * and the item's name. If the system is restored from MDT file level backup,
993 * then before the OI scrub completely built the OI files, the OI mappings of
994 * the master MDT-object and slave MDT-object may be invalid. Usually, it is
995 * not a problem for the master MDT-object. Because when locate the master
996 * MDT-object, we will do name based lookup (for the striped directory itself)
997 * firstly, during such process we can setup the correct OI mapping for the
998 * master MDT-object. But it will be trouble for the slave MDT-object. Because
999 * the client will not trigger name based lookup on the MDT to locate the slave
1000 * MDT-object before locating item under the striped directory, then when
1001 * osd_fid_lookup(), it will find that the OI mapping for the slave MDT-object
1002 * is invalid and does not know what the right OI mapping is, then the MDT has
1003 * to return -EINPROGRESS to the client to notify that the OI scrub is rebuiding
1004 * the OI file, related OI mapping is unknown yet, please try again later. And
1005 * then client will re-try the RPC again and again until related OI mapping has
1006 * been updated. That is quite inefficient.
1008 * To resolve above trouble, we will handle it as the following two cases:
1010 * 1) The slave MDT-object and the master MDT-object are on different MDTs.
1011 * It is relative easy. Be as one of remote MDT-objects, the slave MDT-object
1012 * is linked under /REMOTE_PARENT_DIR with the name of its FID string.
1013 * We can locate the slave MDT-object via lookup the /REMOTE_PARENT_DIR
1014 * directly. Please check osd_fid_lookup().
1016 * 2) The slave MDT-object and the master MDT-object reside on the same MDT.
1017 * Under such case, during lookup the master MDT-object, we will lookup the
1018 * slave MDT-object via readdir against the master MDT-object, because the
1019 * slave MDT-objects information are stored as sub-directories with the name
1020 * "${FID}:${index}". Then when find the local slave MDT-object, its OI
1021 * mapping will be recorded. Then subsequent osd_fid_lookup() will know
1022 * the correct OI mapping for the slave MDT-object.
1024 static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev,
1025 struct inode *inode)
1027 struct lu_buf *buf = &oti->oti_big_buf;
1028 struct dentry *dentry = &oti->oti_obj_dentry;
1030 struct lmv_mds_md_v1 *lmv1;
1031 struct osd_check_lmv_buf oclb = {
1032 .ctx.actor = osd_stripe_dir_filldir,
1035 .oclb_found = false,
1042 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, buf->lb_buf,
1044 if (rc == -ERANGE) {
1045 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, NULL, 0);
1047 lu_buf_realloc(buf, rc);
1048 if (buf->lb_buf == NULL)
1049 GOTO(out, rc = -ENOMEM);
1055 if (unlikely(rc == 0 || rc == -ENODATA))
1061 if (unlikely(buf->lb_buf == NULL)) {
1062 lu_buf_realloc(buf, rc);
1063 if (buf->lb_buf == NULL)
1064 GOTO(out, rc = -ENOMEM);
1070 if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
1073 filp = osd_quasi_file(oti->oti_env, inode);
1074 rc = osd_security_file_alloc(filp);
1079 oclb.oclb_items = 0;
1080 rc = iterate_dir(filp, &oclb.ctx);
1081 } while (rc >= 0 && oclb.oclb_items > 0 && !oclb.oclb_found &&
1082 filp->f_pos != LDISKFS_HTREE_EOF_64BIT);
1083 inode->i_fop->release(inode, filp);
1088 "%s: cannot check LMV, ino = %lu/%u: rc = %d\n",
1089 osd_ino2name(inode), inode->i_ino, inode->i_generation,
1097 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
1098 const struct lu_fid *fid,
1099 const struct lu_object_conf *conf)
1101 struct osd_thread_info *info;
1102 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
1103 struct osd_device *dev;
1104 struct osd_idmap_cache *oic;
1105 struct osd_inode_id *id;
1106 struct inode *inode = NULL;
1107 struct lustre_scrub *scrub;
1108 struct scrub_file *sf;
1109 __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT | SS_AUTO_FULL;
1114 bool remote = false;
1115 bool trusted = true;
1116 bool updated = false;
1117 bool checked = false;
1121 LINVRNT(osd_invariant(obj));
1122 LASSERT(obj->oo_inode == NULL);
1124 if (fid_is_sane(fid) == 0) {
1125 CERROR("%s: invalid FID "DFID"\n", ldev->ld_obd->obd_name,
1131 dev = osd_dev(ldev);
1132 scrub = &dev->od_scrub.os_scrub;
1133 sf = &scrub->os_file;
1134 info = osd_oti_get(env);
1136 oic = &info->oti_cache;
1138 if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
1142 * For the object is created as locking anchor, or for the object to
1143 * be created on disk. No need to osd_oi_lookup() at here because FID
1144 * shouldn't never be re-used, if it's really a duplicate FID from
1145 * unexpected reason, we should be able to detect it later by calling
1146 * do_create->osd_oi_insert().
1148 if (conf && conf->loc_flags & LOC_F_NEW)
1149 GOTO(out, result = 0);
1151 /* Search order: 1. per-thread cache. */
1152 if (lu_fid_eq(fid, &oic->oic_fid) && likely(oic->oic_dev == dev)) {
1158 if (!list_empty(&scrub->os_inconsistent_items)) {
1159 /* Search order: 2. OI scrub pending list. */
1160 result = osd_oii_lookup(dev, fid, id);
1166 * The OI mapping in the OI file can be updated by the OI scrub
1167 * when we locate the inode via FID. So it may be not trustable.
1171 /* Search order: 3. OI files. */
1172 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1173 if (result == -ENOENT) {
1174 if (!(fid_is_norm(fid) || fid_is_igif(fid)) ||
1175 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) ||
1176 !ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
1178 GOTO(out, result = 0);
1183 /* -ESTALE is returned if inode of OST object doesn't exist */
1184 if (result == -ESTALE &&
1185 fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) {
1186 GOTO(out, result = 0);
1193 obj->oo_inode = NULL;
1194 /* for later passes through checks, not true on first pass */
1195 if (!IS_ERR_OR_NULL(inode))
1198 inode = osd_iget_check(info, dev, fid, id, trusted);
1199 if (!IS_ERR(inode)) {
1200 obj->oo_inode = inode;
1208 result = PTR_ERR(inode);
1209 if (result == -ENOENT || result == -ESTALE)
1210 GOTO(out, result = 0);
1212 if (result != -EREMCHG)
1217 * We still have chance to get the valid inode: for the
1218 * object which is referenced by remote name entry, the
1219 * object on the local MDT will be linked under the dir
1220 * of "/REMOTE_PARENT_DIR" with its FID string as name.
1222 * We do not know whether the object for the given FID
1223 * is referenced by some remote name entry or not, and
1224 * especially for DNE II, a multiple-linked object may
1225 * have many name entries reside on many MDTs.
1227 * To simplify the operation, OSD will not distinguish
1228 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
1229 * only happened for the RPC from other MDT during the
1230 * OI scrub, or for the client side RPC with FID only,
1231 * such as FID to path, or from old connected client.
1234 rc1 = osd_lookup_in_remote_parent(info, dev, fid, id);
1238 flags |= SS_AUTO_PARTIAL;
1239 flags &= ~SS_AUTO_FULL;
1244 if (scrub->os_running) {
1245 if (scrub->os_partial_scan && !scrub->os_in_join)
1248 if (IS_ERR_OR_NULL(inode) || result) {
1249 osd_oii_insert(dev, fid, id, result == -ENOENT);
1250 GOTO(out, result = -EINPROGRESS);
1254 LASSERT(obj->oo_inode == inode);
1256 osd_oii_insert(dev, fid, id, true);
1260 if (dev->od_auto_scrub_interval == AS_NEVER) {
1262 GOTO(out, result = -EREMCHG);
1265 LASSERT(obj->oo_inode == inode);
1267 osd_add_oi_cache(info, dev, id, fid);
1272 rc1 = osd_scrub_start(env, dev, flags);
1273 CDEBUG_LIMIT(D_LFSCK | D_CONSOLE | D_WARNING,
1274 "%s: trigger OI scrub by RPC for "DFID"/%u with flags %#x: rc = %d\n",
1275 osd_name(dev), PFID(fid), id->oii_ino, flags, rc1);
1276 if (rc1 && rc1 != -EALREADY)
1277 GOTO(out, result = -EREMCHG);
1279 if (IS_ERR_OR_NULL(inode) || result) {
1280 osd_oii_insert(dev, fid, id, result == -ENOENT);
1281 GOTO(out, result = -EINPROGRESS);
1285 LASSERT(obj->oo_inode == inode);
1287 osd_oii_insert(dev, fid, id, true);
1292 if (unlikely(obj->oo_header))
1295 result = osd_check_lma(env, obj);
1299 LASSERTF(id->oii_ino == inode->i_ino &&
1300 id->oii_gen == inode->i_generation,
1301 "locate wrong inode for FID: "DFID", %u/%u => %ld/%u\n",
1302 PFID(fid), id->oii_ino, id->oii_gen,
1303 inode->i_ino, inode->i_generation);
1305 saved_ino = inode->i_ino;
1306 saved_gen = inode->i_generation;
1308 if (unlikely(result == -ENODATA)) {
1310 * If the OI scrub updated the OI mapping by race, it
1311 * must be valid. Trust the inode that has no LMA EA.
1316 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1319 * The OI mapping is still there, the inode is still
1320 * valid. It is just becaues the inode has no LMA EA.
1322 if (saved_ino == id->oii_ino &&
1323 saved_gen == id->oii_gen)
1327 * It is the OI scrub updated the OI mapping by race.
1328 * The new OI mapping must be valid.
1336 * "result == -ENOENT" means that the OI mappinghas been
1337 * removed by race, so the inode belongs to other object.
1339 * Others error can be returned directly.
1341 if (result == -ENOENT) {
1344 obj->oo_inode = NULL;
1349 if (result != -EREMCHG)
1355 * if two OST objects map to the same inode, and inode mode is
1356 * (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666), which means it's
1357 * reserved by precreate, and not written yet, in this case, don't
1358 * set inode for the object whose FID mismatch, so that it can create
1359 * inode and not block precreate.
1361 if (fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) &&
1362 inode->i_mode == (S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666)) {
1363 obj->oo_inode = NULL;
1364 GOTO(out, result = 0);
1367 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
1369 * "result == -ENOENT" means the cached OI mapping has been removed
1370 * from the OI file by race, above inode belongs to other object.
1372 if (result == -ENOENT) {
1375 obj->oo_inode = NULL;
1376 GOTO(out, result = 0);
1382 if (saved_ino == id->oii_ino && saved_gen == id->oii_gen) {
1384 osd_scrub_refresh_mapping(info, dev, fid, id, DTO_INDEX_DELETE,
1390 * It is the OI scrub updated the OI mapping by race.
1391 * The new OI mapping must be valid.
1399 struct lustre_ost_attrs *loa = &info->oti_ost_attrs;
1400 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
1402 result = osd_get_lma(info, inode, &info->oti_obj_dentry, loa);
1404 if (lma->lma_compat & LMAC_STRIPE_INFO &&
1406 obj->oo_pfid_in_lma = 1;
1407 if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
1409 lu_object_set_agent_entry(&obj->oo_dt.do_lu);
1410 } else if (result != -ENODATA) {
1415 obj->oo_compat_dot_created = 1;
1416 obj->oo_compat_dotdot_created = 1;
1418 if (S_ISDIR(inode->i_mode) &&
1419 (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING))
1420 osd_check_lmv(info, dev, inode);
1422 result = osd_attach_jinode(inode);
1427 GOTO(out, result = 0);
1429 LASSERT(!obj->oo_hl_head);
1430 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1432 GOTO(out, result = (!obj->oo_hl_head ? -ENOMEM : 0));
1435 if (result || !obj->oo_inode) {
1436 if (!IS_ERR_OR_NULL(inode))
1439 obj->oo_inode = NULL;
1441 fid_zero(&oic->oic_fid);
1444 LINVRNT(osd_invariant(obj));
1449 * Concurrency: shouldn't matter.
1451 static void osd_object_init0(struct osd_object *obj)
1453 LASSERT(obj->oo_inode != NULL);
1454 obj->oo_dt.do_body_ops = &osd_body_ops;
1455 obj->oo_dt.do_lu.lo_header->loh_attr |=
1456 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
1460 * Concurrency: no concurrent access is possible that early in object
1463 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
1464 const struct lu_object_conf *conf)
1466 struct osd_object *obj = osd_obj(l);
1469 LINVRNT(osd_invariant(obj));
1471 if (OBD_FAIL_PRECHECK(OBD_FAIL_MDS_LLOG_UMOUNT_RACE) &&
1472 cfs_fail_val == 2) {
1473 struct osd_thread_info *info = osd_oti_get(env);
1474 struct osd_idmap_cache *oic = &info->oti_cache;
1475 /* invalidate thread cache */
1476 memset(&oic->oic_fid, 0, sizeof(oic->oic_fid));
1478 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
1479 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
1480 l->lo_header->loh_attr |= LOHA_EXISTS;
1484 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
1485 obj->oo_dt.do_body_ops = &osd_body_ops_new;
1486 if (result == 0 && obj->oo_inode != NULL) {
1487 struct osd_thread_info *oti = osd_oti_get(env);
1488 struct lustre_ost_attrs *loa = &oti->oti_ost_attrs;
1490 osd_object_init0(obj);
1491 if (unlikely(obj->oo_header))
1494 result = osd_get_lma(oti, obj->oo_inode,
1495 &oti->oti_obj_dentry, loa);
1498 * Convert LMAI flags to lustre LMA flags
1499 * and cache it to oo_lma_flags
1502 lma_to_lustre_flags(loa->loa_lma.lma_incompat);
1503 } else if (result == -ENODATA) {
1507 obj->oo_dirent_count = LU_DIRENT_COUNT_UNSET;
1509 LINVRNT(osd_invariant(obj));
1514 * The first part of oxe_buf is xattr name, and is '\0' terminated.
1515 * The left part is for value, binary mode.
1517 struct osd_xattr_entry {
1518 struct list_head oxe_list;
1522 struct rcu_head oxe_rcu;
1526 static int osd_oxc_get(struct osd_object *obj, const char *name,
1529 struct osd_xattr_entry *tmp;
1530 struct osd_xattr_entry *oxe = NULL;
1531 size_t namelen = strlen(name);
1535 list_for_each_entry_rcu(tmp, &obj->oo_xattr_list, oxe_list) {
1536 if (namelen == tmp->oxe_namelen &&
1537 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1544 GOTO(out, rc = -ENOENT);
1546 if (!oxe->oxe_exist)
1547 GOTO(out, rc = -ENODATA);
1550 rc = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1;
1553 if (buf->lb_buf == NULL)
1556 if (buf->lb_len < rc)
1557 GOTO(out, rc = -ERANGE);
1559 memcpy(buf->lb_buf, &oxe->oxe_buf[namelen + 1], rc);
1566 static void osd_oxc_free(struct rcu_head *head)
1568 struct osd_xattr_entry *oxe;
1570 oxe = container_of(head, struct osd_xattr_entry, oxe_rcu);
1571 OBD_FREE(oxe, oxe->oxe_len);
1574 static void osd_oxc_add(struct osd_object *obj, const char *name,
1575 const char *buf, int buflen)
1577 struct osd_xattr_entry *oxe;
1578 struct osd_xattr_entry *old = NULL;
1579 struct osd_xattr_entry *tmp;
1580 size_t namelen = strlen(name);
1581 size_t len = sizeof(*oxe) + namelen + 1 + buflen;
1583 OBD_ALLOC(oxe, len);
1587 INIT_LIST_HEAD(&oxe->oxe_list);
1589 oxe->oxe_namelen = namelen;
1590 memcpy(oxe->oxe_buf, name, namelen);
1592 LASSERT(buf != NULL);
1593 memcpy(oxe->oxe_buf + namelen + 1, buf, buflen);
1594 oxe->oxe_exist = true;
1596 oxe->oxe_exist = false;
1599 /* this should be rarely called, just remove old and add new */
1600 spin_lock(&obj->oo_guard);
1601 list_for_each_entry(tmp, &obj->oo_xattr_list, oxe_list) {
1602 if (namelen == tmp->oxe_namelen &&
1603 strncmp(name, tmp->oxe_buf, namelen) == 0) {
1609 list_replace_rcu(&old->oxe_list, &oxe->oxe_list);
1610 call_rcu(&old->oxe_rcu, osd_oxc_free);
1612 list_add_tail_rcu(&oxe->oxe_list, &obj->oo_xattr_list);
1614 spin_unlock(&obj->oo_guard);
1617 static void osd_oxc_del(struct osd_object *obj, const char *name)
1619 struct osd_xattr_entry *oxe;
1620 size_t namelen = strlen(name);
1622 spin_lock(&obj->oo_guard);
1623 list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) {
1624 if (namelen == oxe->oxe_namelen &&
1625 strncmp(name, oxe->oxe_buf, namelen) == 0) {
1626 list_del_rcu(&oxe->oxe_list);
1627 call_rcu(&oxe->oxe_rcu, osd_oxc_free);
1631 spin_unlock(&obj->oo_guard);
1634 static void osd_oxc_fini(struct osd_object *obj)
1636 struct osd_xattr_entry *oxe, *next;
1638 list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) {
1639 list_del(&oxe->oxe_list);
1640 OBD_FREE(oxe, oxe->oxe_len);
1645 * Concurrency: no concurrent access is possible that late in object
1648 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
1650 struct osd_object *obj = osd_obj(l);
1651 struct lu_object_header *h = obj->oo_header;
1653 LINVRNT(osd_invariant(obj));
1656 dt_object_fini(&obj->oo_dt);
1657 if (obj->oo_hl_head != NULL)
1658 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1659 /* obj doesn't contain an lu_object_header, so we don't need call_rcu */
1662 lu_object_header_free(h);
1666 * Concurrency: no concurrent access is possible that late in object
1669 static void osd_index_fini(struct osd_object *o)
1671 struct iam_container *bag;
1673 if (o->oo_dir != NULL) {
1674 bag = &o->oo_dir->od_container;
1675 if (o->oo_inode != NULL) {
1676 if (bag->ic_object == o->oo_inode)
1677 iam_container_fini(bag);
1679 OBD_FREE_PTR(o->oo_dir);
1685 OSD_TXN_OI_DELETE_CREDITS = 20,
1686 OSD_TXN_INODE_DELETE_CREDITS = 20
1693 #if OSD_THANDLE_STATS
1695 * Set time when the handle is allocated
1697 static void osd_th_alloced(struct osd_thandle *oth)
1699 oth->oth_alloced = ktime_get();
1703 * Set time when the handle started
1705 static void osd_th_started(struct osd_thandle *oth)
1707 oth->oth_started = ktime_get();
1711 * Check whether the we deal with this handle for too long.
1713 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
1714 ktime_t alloced, ktime_t started,
1717 ktime_t now = ktime_get();
1719 LASSERT(dev != NULL);
1721 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
1722 ktime_us_delta(started, alloced));
1723 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
1724 ktime_us_delta(closed, started));
1725 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
1726 ktime_us_delta(now, closed));
1728 if (ktime_before(ktime_add_ns(alloced, 30 * NSEC_PER_SEC), now)) {
1729 CWARN("transaction handle %p was open for too long: now %lld, alloced %lld, started %lld, closed %lld\n",
1730 oth, now, alloced, started, closed);
1731 libcfs_debug_dumpstack(NULL);
1735 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
1737 ktime_t __closed = ktime_get(); \
1738 ktime_t __alloced = oth->oth_alloced; \
1739 ktime_t __started = oth->oth_started; \
1742 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
1745 #else /* OSD_THANDLE_STATS */
1747 #define osd_th_alloced(h) do {} while(0)
1748 #define osd_th_started(h) do {} while(0)
1749 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
1751 #endif /* OSD_THANDLE_STATS */
1754 * Concurrency: doesn't access mutable data.
1756 static int osd_param_is_not_sane(const struct osd_device *dev,
1757 const struct thandle *th)
1759 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
1761 return oh->ot_credits > osd_transaction_size(dev);
1765 * Concurrency: shouldn't matter.
1767 static void osd_trans_commit_cb(struct super_block *sb,
1768 struct ldiskfs_journal_cb_entry *jcb, int error)
1770 struct osd_thandle *oh = container_of(jcb, struct osd_thandle, ot_jcb);
1771 struct thandle *th = &oh->ot_super;
1772 struct lu_device *lud = &th->th_dev->dd_lu_dev;
1773 struct osd_device *osd = osd_dev(lud);
1774 struct dt_txn_commit_cb *dcb, *tmp;
1776 LASSERT(oh->ot_handle == NULL);
1779 CERROR("transaction @0x%p commit error: %d\n", th, error);
1781 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_DELAY_TRANS, 40);
1782 /* call per-transaction callbacks if any */
1783 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
1785 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1786 "commit callback entry: magic=%x name='%s'\n",
1787 dcb->dcb_magic, dcb->dcb_name);
1788 list_del_init(&dcb->dcb_linkage);
1789 dcb->dcb_func(NULL, th, dcb, error);
1792 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
1793 if (atomic_dec_and_test(&osd->od_commit_cb_in_flight))
1794 wake_up(&osd->od_commit_cb_done);
1800 static struct thandle *osd_trans_create(const struct lu_env *env,
1801 struct dt_device *d)
1803 struct osd_thread_info *oti = osd_oti_get(env);
1804 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1805 struct osd_thandle *oh;
1811 CERROR("%s: someone try to start transaction under "
1812 "readonly mode, should be disabled.\n",
1813 osd_name(osd_dt_dev(d)));
1815 RETURN(ERR_PTR(-EROFS));
1818 /* on pending IO in this thread should left from prev. request */
1819 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
1821 sb_start_write(osd_sb(osd_dt_dev(d)));
1823 OBD_ALLOC_GFP(oh, sizeof(*oh), GFP_NOFS);
1825 sb_end_write(osd_sb(osd_dt_dev(d)));
1826 RETURN(ERR_PTR(-ENOMEM));
1829 oh->ot_quota_trans = &oti->oti_quota_trans;
1830 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
1835 oh->oh_declared_ext = 0;
1836 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
1837 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
1838 INIT_LIST_HEAD(&oh->ot_trunc_locks);
1841 memset(oti->oti_declare_ops, 0,
1842 sizeof(oti->oti_declare_ops));
1843 memset(oti->oti_declare_ops_cred, 0,
1844 sizeof(oti->oti_declare_ops_cred));
1845 memset(oti->oti_declare_ops_used, 0,
1846 sizeof(oti->oti_declare_ops_used));
1848 oti->oti_ins_cache_depth++;
1853 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
1855 struct osd_thread_info *oti = osd_oti_get(env);
1856 struct osd_thandle *oh;
1858 oh = container_of(th, struct osd_thandle, ot_super);
1859 LASSERT(oh != NULL);
1861 CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n",
1862 oti->oti_declare_ops[OSD_OT_CREATE],
1863 oti->oti_declare_ops_cred[OSD_OT_CREATE],
1864 oti->oti_declare_ops_used[OSD_OT_CREATE],
1865 oti->oti_declare_ops[OSD_OT_DESTROY],
1866 oti->oti_declare_ops_cred[OSD_OT_DESTROY],
1867 oti->oti_declare_ops_used[OSD_OT_DESTROY]);
1868 CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
1869 oti->oti_declare_ops[OSD_OT_ATTR_SET],
1870 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
1871 oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
1872 oti->oti_declare_ops[OSD_OT_XATTR_SET],
1873 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
1874 oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
1875 CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
1876 oti->oti_declare_ops[OSD_OT_WRITE],
1877 oti->oti_declare_ops_cred[OSD_OT_WRITE],
1878 oti->oti_declare_ops_used[OSD_OT_WRITE],
1879 oti->oti_declare_ops[OSD_OT_PUNCH],
1880 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
1881 oti->oti_declare_ops_used[OSD_OT_PUNCH],
1882 oti->oti_declare_ops[OSD_OT_QUOTA],
1883 oti->oti_declare_ops_cred[OSD_OT_QUOTA],
1884 oti->oti_declare_ops_used[OSD_OT_QUOTA]);
1885 CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n",
1886 oti->oti_declare_ops[OSD_OT_INSERT],
1887 oti->oti_declare_ops_cred[OSD_OT_INSERT],
1888 oti->oti_declare_ops_used[OSD_OT_INSERT],
1889 oti->oti_declare_ops[OSD_OT_DELETE],
1890 oti->oti_declare_ops_cred[OSD_OT_DELETE],
1891 oti->oti_declare_ops_used[OSD_OT_DELETE]);
1892 CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
1893 oti->oti_declare_ops[OSD_OT_REF_ADD],
1894 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
1895 oti->oti_declare_ops_used[OSD_OT_REF_ADD],
1896 oti->oti_declare_ops[OSD_OT_REF_DEL],
1897 oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
1898 oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
1902 * Concurrency: shouldn't matter.
1904 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
1907 struct osd_thread_info *oti = osd_oti_get(env);
1908 struct osd_device *dev = osd_dt_dev(d);
1910 struct osd_thandle *oh;
1915 LASSERT(current->journal_info == NULL);
1917 oh = container_of(th, struct osd_thandle, ot_super);
1918 LASSERT(oh != NULL);
1919 LASSERT(oh->ot_handle == NULL);
1921 rc = dt_txn_hook_start(env, d, th);
1925 if (unlikely(osd_param_is_not_sane(dev, th))) {
1926 static unsigned long last_printed;
1927 static int last_credits;
1930 * don't make noise on a tiny testing systems
1931 * actual credits misuse will be caught anyway
1933 if (last_credits != oh->ot_credits &&
1934 time_after(jiffies, last_printed +
1935 cfs_time_seconds(60)) &&
1936 osd_transaction_size(dev) > 512) {
1937 CWARN("%s: credits %u > trans_max %u\n", osd_name(dev),
1938 oh->ot_credits, osd_transaction_size(dev));
1939 osd_trans_dump_creds(env, th);
1940 libcfs_debug_dumpstack(NULL);
1941 last_credits = oh->ot_credits;
1942 last_printed = jiffies;
1945 * XXX Limit the credits to 'max_transaction_buffers', and
1946 * let the underlying filesystem to catch the error if
1947 * we really need so many credits.
1949 * This should be removed when we can calculate the
1950 * credits precisely.
1952 oh->ot_credits = osd_transaction_size(dev);
1953 } else if (ldiskfs_track_declares_assert != 0) {
1955 * reserve few credits to prevent an assertion in JBD
1956 * our debugging mechanism will be able to detected
1957 * overuse. this can help to debug single-update
1960 oh->ot_credits += 10;
1961 if (unlikely(osd_param_is_not_sane(dev, th)))
1962 oh->ot_credits = osd_transaction_size(dev);
1965 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_TXN_START))
1966 GOTO(out, rc = -EIO);
1969 * XXX temporary stuff. Some abstraction layer should
1972 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
1976 LASSERT(oti->oti_txns == 0);
1978 atomic_inc(&dev->od_commit_cb_in_flight);
1979 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
1990 static int osd_seq_exists(const struct lu_env *env,
1991 struct osd_device *osd, u64 seq)
1993 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1994 struct seq_server_site *ss = osd_seq_site(osd);
1999 LASSERT(ss != NULL);
2000 LASSERT(ss->ss_server_fld != NULL);
2002 rc = osd_fld_lookup(env, osd, seq, range);
2005 CERROR("%s: can't lookup FLD sequence %#llx: rc = %d\n",
2006 osd_name(osd), seq, rc);
2010 RETURN(ss->ss_node_id == range->lsr_index);
2013 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
2015 struct dt_txn_commit_cb *dcb;
2016 struct dt_txn_commit_cb *tmp;
2018 /* call per-transaction stop callbacks if any */
2019 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
2021 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
2022 "commit callback entry: magic=%x name='%s'\n",
2023 dcb->dcb_magic, dcb->dcb_name);
2024 list_del_init(&dcb->dcb_linkage);
2025 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
2030 * Concurrency: shouldn't matter.
2032 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
2035 struct osd_thread_info *oti = osd_oti_get(env);
2036 struct osd_thandle *oh;
2037 struct osd_iobuf *iobuf = &oti->oti_iobuf;
2038 struct osd_device *osd = osd_dt_dev(th->th_dev);
2039 struct qsd_instance *qsd = osd_def_qsd(osd);
2040 struct lquota_trans *qtrans;
2041 LIST_HEAD(truncates);
2042 int rc = 0, remove_agents = 0;
2046 oh = container_of(th, struct osd_thandle, ot_super);
2048 remove_agents = oh->ot_remove_agents;
2050 qtrans = oh->ot_quota_trans;
2051 oh->ot_quota_trans = NULL;
2053 /* move locks to local list, stop tx, execute truncates */
2054 list_splice(&oh->ot_trunc_locks, &truncates);
2056 if (oh->ot_handle != NULL) {
2059 handle_t *hdl = oh->ot_handle;
2062 * add commit callback
2063 * notice we don't do this in osd_trans_start()
2064 * as underlying transaction can change during truncate
2066 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
2069 LASSERT(oti->oti_txns == 1);
2072 rc = dt_txn_hook_stop(env, th);
2074 CERROR("%s: failed in transaction hook: rc = %d\n",
2077 osd_trans_stop_cb(oh, rc);
2078 /* hook functions might modify th_sync */
2079 hdl->h_sync = th->th_sync;
2081 oh->ot_handle = NULL;
2082 OSD_CHECK_SLOW_TH(oh, osd, rc2 = ldiskfs_journal_stop(hdl));
2084 CERROR("%s: failed to stop transaction: rc = %d\n",
2085 osd_name(osd), rc2);
2089 osd_process_truncates(env, &truncates);
2091 osd_trans_stop_cb(oh, th->th_result);
2095 osd_trunc_unlock_all(env, &truncates);
2097 /* inform the quota slave device that the transaction is stopping */
2098 qsd_op_end(env, qsd, qtrans);
2101 * as we want IO to journal and data IO be concurrent, we don't block
2102 * awaiting data IO completion in osd_do_bio(), instead we wait here
2103 * once transaction is submitted to the journal. all reqular requests
2104 * don't do direct IO (except read/write), thus this wait_event becomes
2107 * IMPORTANT: we have to wait till any IO submited by the thread is
2108 * completed otherwise iobuf may be corrupted by different request
2110 wait_event(iobuf->dr_wait,
2111 atomic_read(&iobuf->dr_numreqs) == 0);
2112 osd_fini_iobuf(osd, iobuf);
2114 rc = iobuf->dr_error;
2116 if (unlikely(remove_agents != 0))
2117 osd_process_scheduled_agent_removals(env, osd);
2119 LASSERT(oti->oti_ins_cache_depth > 0);
2120 oti->oti_ins_cache_depth--;
2121 /* reset OI cache for safety */
2122 if (oti->oti_ins_cache_depth == 0)
2123 oti->oti_ins_cache_used = 0;
2125 sb_end_write(osd_sb(osd));
2130 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
2132 struct osd_thandle *oh = container_of(th, struct osd_thandle,
2135 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
2136 LASSERT(&dcb->dcb_func != NULL);
2137 if (dcb->dcb_flags & DCB_TRANS_STOP)
2138 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
2140 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
2146 * Called just before object is freed. Releases all resources except for
2147 * object itself (that is released by osd_object_free()).
2149 * Concurrency: no concurrent access is possible that late in object
2152 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
2154 struct osd_object *obj = osd_obj(l);
2155 struct qsd_instance *qsd = osd_def_qsd(osd_obj2dev(obj));
2156 struct inode *inode = obj->oo_inode;
2161 LINVRNT(osd_invariant(obj));
2164 * If object is unlinked remove fid->ino mapping from object index.
2167 osd_index_fini(obj);
2172 if (osd_has_index(obj) && obj->oo_dt.do_index_ops == &osd_index_iam_ops)
2173 ldiskfs_set_inode_flag(inode, LDISKFS_INODE_JOURNAL_DATA);
2175 uid = i_uid_read(inode);
2176 gid = i_gid_read(inode);
2177 projid = i_projid_read(inode);
2179 obj->oo_inode = NULL;
2182 /* do not rebalance quota if the caller needs to release memory
2183 * otherwise qsd_refresh_usage() may went into a new ldiskfs
2184 * transaction and risk to deadlock - LU-12178 */
2185 if (current->flags & (PF_MEMALLOC | PF_KSWAPD))
2188 if (!obj->oo_header && qsd) {
2189 struct osd_thread_info *info = osd_oti_get(env);
2190 struct lquota_id_info *qi = &info->oti_qi;
2192 /* Release granted quota to master if necessary */
2193 qi->lqi_id.qid_uid = uid;
2194 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
2196 qi->lqi_id.qid_uid = gid;
2197 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
2199 qi->lqi_id.qid_uid = projid;
2200 qsd_op_adjust(env, qsd, &qi->lqi_id, PRJQUOTA);
2205 * Concurrency: ->loo_object_release() is called under site spin-lock.
2207 static void osd_object_release(const struct lu_env *env,
2208 struct lu_object *l)
2210 struct osd_object *o = osd_obj(l);
2213 * nobody should be releasing a non-destroyed object with nlink=0
2214 * the API allows this, but ldiskfs doesn't like and then report
2215 * this inode as deleted
2217 LASSERT(!(o->oo_destroyed == 0 && o->oo_inode &&
2218 o->oo_inode->i_nlink == 0));
2222 * Concurrency: shouldn't matter.
2224 static int osd_object_print(const struct lu_env *env, void *cookie,
2225 lu_printer_t p, const struct lu_object *l)
2227 struct osd_object *o = osd_obj(l);
2228 struct iam_descr *d;
2230 if (o->oo_dir != NULL)
2231 d = o->oo_dir->od_container.ic_descr;
2234 return (*p)(env, cookie,
2235 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
2237 o->oo_inode ? o->oo_inode->i_ino : 0UL,
2238 o->oo_inode ? o->oo_inode->i_generation : 0,
2239 d ? d->id_ops->id_name : "plain");
2243 * Concurrency: shouldn't matter.
2245 int osd_statfs(const struct lu_env *env, struct dt_device *d,
2246 struct obd_statfs *sfs, struct obd_statfs_info *info)
2248 struct osd_device *osd = osd_dt_dev(d);
2249 struct super_block *sb = osd_sb(osd);
2250 struct kstatfs *ksfs;
2254 if (unlikely(osd->od_mnt == NULL))
2255 return -EINPROGRESS;
2257 /* osd_lproc.c call this without env, allocate ksfs for that case */
2258 if (unlikely(env == NULL)) {
2259 OBD_ALLOC_PTR(ksfs);
2263 ksfs = &osd_oti_get(env)->oti_ksfs;
2266 result = sb->s_op->statfs(sb->s_root, ksfs);
2270 statfs_pack(sfs, ksfs);
2271 if (unlikely(sb->s_flags & SB_RDONLY))
2272 sfs->os_state |= OS_STATFS_READONLY;
2274 sfs->os_state |= osd->od_nonrotational ? OS_STATFS_NONROT : 0;
2276 if (ldiskfs_has_feature_extents(sb))
2277 sfs->os_maxbytes = sb->s_maxbytes;
2279 sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2282 * Reserve some space so to avoid fragmenting the filesystem too much.
2283 * Fragmentation not only impacts performance, but can also increase
2284 * metadata overhead significantly, causing grant calculation to be
2287 * Reserve 0.78% of total space, at least 8MB for small filesystems.
2289 BUILD_BUG_ON(OSD_STATFS_RESERVED <= LDISKFS_MAX_BLOCK_SIZE);
2290 reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits;
2291 if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT))
2292 reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT;
2294 sfs->os_blocks -= reserved;
2295 sfs->os_bfree -= min(reserved, sfs->os_bfree);
2296 sfs->os_bavail -= min(reserved, sfs->os_bavail);
2299 if (unlikely(env == NULL))
2305 * Estimate space needed for file creations. We assume the largest filename
2306 * which is 2^64 - 1, hence a filename of 20 chars.
2307 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
2309 #ifdef __LDISKFS_DIR_REC_LEN
2310 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
2312 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
2316 * Concurrency: doesn't access mutable data.
2318 static void osd_conf_get(const struct lu_env *env,
2319 const struct dt_device *dev,
2320 struct dt_device_param *param)
2322 struct osd_device *d = osd_dt_dev(dev);
2323 struct super_block *sb = osd_sb(d);
2324 struct blk_integrity *bi = bdev_get_integrity(sb->s_bdev);
2329 * XXX should be taken from not-yet-existing fs abstraction layer.
2331 param->ddp_max_name_len = LDISKFS_NAME_LEN;
2332 param->ddp_max_nlink = LDISKFS_LINK_MAX;
2333 param->ddp_symlink_max = sb->s_blocksize;
2334 param->ddp_mount_type = LDD_MT_LDISKFS;
2335 if (ldiskfs_has_feature_extents(sb))
2336 param->ddp_maxbytes = sb->s_maxbytes;
2338 param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
2340 * inode are statically allocated, so per-inode space consumption
2341 * is the space consumed by the directory entry
2343 param->ddp_inodespace = PER_OBJ_USAGE;
2345 * EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks
2346 * is 128MB) which is unlikely to be hit in real life. Report a smaller
2347 * maximum length to not under-count the actual number of extents
2348 * needed for writing a file if there are sub-optimal block allocations.
2350 param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 1;
2351 /* worst-case extent insertion metadata overhead */
2352 param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb);
2353 param->ddp_mntopts = 0;
2354 if (test_opt(sb, XATTR_USER))
2355 param->ddp_mntopts |= MNTOPT_USERXATTR;
2356 if (test_opt(sb, POSIX_ACL))
2357 param->ddp_mntopts |= MNTOPT_ACL;
2360 * LOD might calculate the max stripe count based on max_ea_size,
2361 * so we need take account in the overhead as well,
2362 * xattr_header + magic + xattr_entry_head
2364 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
2365 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
2367 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
2368 if (ldiskfs_has_feature_ea_inode(sb))
2369 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
2373 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
2375 if (param->ddp_max_ea_size > OBD_MAX_EA_SIZE)
2376 param->ddp_max_ea_size = OBD_MAX_EA_SIZE;
2379 * Preferred RPC size for efficient disk IO. 4MB shows good
2380 * all-around performance for ldiskfs, but use bigalloc chunk size
2381 * by default if larger.
2383 #if defined(LDISKFS_CLUSTER_SIZE)
2384 if (LDISKFS_CLUSTER_SIZE(sb) > DT_DEF_BRW_SIZE)
2385 param->ddp_brw_size = LDISKFS_CLUSTER_SIZE(sb);
2388 param->ddp_brw_size = DT_DEF_BRW_SIZE;
2390 param->ddp_t10_cksum_type = 0;
2392 unsigned short interval = blk_integrity_interval(bi);
2393 name = blk_integrity_name(bi);
2401 if (strncmp(name, "T10-DIF-TYPE",
2402 sizeof("T10-DIF-TYPE") - 1) == 0) {
2403 /* also skip "1/3-" at end */
2404 const int type_off = sizeof("T10-DIF-TYPE.");
2405 char type_number = name[type_off - 2];
2407 if (interval != 512 && interval != 4096) {
2408 CERROR("%s: unsupported T10PI sector size %u\n",
2409 d->od_svname, interval);
2410 } else if (type_number != '1' && type_number != '3') {
2411 CERROR("%s: unsupported T10PI type %s\n",
2412 d->od_svname, name);
2413 } else if (strcmp(name + type_off, "CRC") == 0) {
2414 d->od_t10_type = type_number == '1' ?
2415 OSD_T10_TYPE1_CRC : OSD_T10_TYPE3_CRC;
2416 param->ddp_t10_cksum_type = interval == 512 ?
2417 OBD_CKSUM_T10CRC512 :
2419 } else if (strcmp(name + type_off, "IP") == 0) {
2420 d->od_t10_type = type_number == '1' ?
2421 OSD_T10_TYPE1_IP : OSD_T10_TYPE3_IP;
2422 param->ddp_t10_cksum_type = interval == 512 ?
2423 OBD_CKSUM_T10IP512 :
2426 CERROR("%s: unsupported checksum type of T10PI type '%s'\n",
2427 d->od_svname, name);
2431 CERROR("%s: unsupported T10PI type '%s'\n",
2432 d->od_svname, name);
2436 param->ddp_has_lseek_data_hole = true;
2439 static struct super_block *osd_mnt_sb_get(const struct dt_device *d)
2441 return osd_sb(osd_dt_dev(d));
2445 * Concurrency: shouldn't matter.
2447 static int osd_sync(const struct lu_env *env, struct dt_device *d)
2450 struct super_block *s = osd_sb(osd_dt_dev(d));
2453 down_read(&s->s_umount);
2454 rc = s->s_op->sync_fs(s, 1);
2455 up_read(&s->s_umount);
2457 CDEBUG(D_CACHE, "%s: synced OSD: rc = %d\n", osd_dt_dev(d)->od_svname,
2464 * Start commit for OSD device.
2466 * An implementation of dt_commit_async method for OSD device.
2467 * Asychronously starts underlayng fs sync and thereby a transaction
2470 * \param env environment
2471 * \param d dt device
2473 * \see dt_device_operations
2475 static int osd_commit_async(const struct lu_env *env,
2476 struct dt_device *d)
2478 struct super_block *s = osd_sb(osd_dt_dev(d));
2483 CDEBUG(D_HA, "%s: async commit OSD\n", osd_dt_dev(d)->od_svname);
2484 down_read(&s->s_umount);
2485 rc = s->s_op->sync_fs(s, 0);
2486 up_read(&s->s_umount);
2491 static int (*priv_security_file_alloc)(struct file *file);
2493 int osd_security_file_alloc(struct file *file)
2495 if (priv_security_file_alloc)
2496 return priv_security_file_alloc(file);
2501 * Concurrency: shouldn't matter.
2503 static int osd_ro(const struct lu_env *env, struct dt_device *d)
2505 struct super_block *sb = osd_sb(osd_dt_dev(d));
2506 struct block_device *dev = sb->s_bdev;
2507 int rc = -EOPNOTSUPP;
2511 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
2512 osd_dt_dev(d)->od_svname, (long)dev, rc);
2518 * Note: we do not count into QUOTA here.
2519 * If we mount with --data_journal we may need more.
2521 const int osd_dto_credits_noquota[DTO_NR] = {
2524 * INDEX_EXTRA_TRANS_BLOCKS(8) +
2525 * SINGLEDATA_TRANS_BLOCKS(8)
2526 * XXX Note: maybe iam need more, since iam have more level than
2529 [DTO_INDEX_INSERT] = 16,
2532 * just modify a single entry, probably merge few within a block
2534 [DTO_INDEX_DELETE] = 1,
2538 [DTO_INDEX_UPDATE] = 16,
2540 * 4(inode, inode bits, groups, GDT)
2541 * notice: OI updates are counted separately with DTO_INDEX_INSERT
2543 [DTO_OBJECT_CREATE] = 4,
2545 * 4(inode, inode bits, groups, GDT)
2546 * notice: OI updates are counted separately with DTO_INDEX_DELETE
2548 [DTO_OBJECT_DELETE] = 4,
2550 * Attr set credits (inode)
2552 [DTO_ATTR_SET_BASE] = 1,
2554 * Xattr set. The same as xattr of EXT3.
2555 * DATA_TRANS_BLOCKS(14)
2556 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
2557 * are also counted in. Do not know why?
2559 [DTO_XATTR_SET] = 14,
2561 * credits for inode change during write.
2563 [DTO_WRITE_BASE] = 3,
2565 * credits for single block write.
2567 [DTO_WRITE_BLOCK] = 14,
2569 * Attr set credits for chown.
2570 * This is extra credits for setattr, and it is null without quota
2572 [DTO_ATTR_SET_CHOWN] = 0
2575 static const struct dt_device_operations osd_dt_ops = {
2576 .dt_root_get = osd_root_get,
2577 .dt_statfs = osd_statfs,
2578 .dt_trans_create = osd_trans_create,
2579 .dt_trans_start = osd_trans_start,
2580 .dt_trans_stop = osd_trans_stop,
2581 .dt_trans_cb_add = osd_trans_cb_add,
2582 .dt_conf_get = osd_conf_get,
2583 .dt_mnt_sb_get = osd_mnt_sb_get,
2584 .dt_sync = osd_sync,
2586 .dt_commit_async = osd_commit_async,
2589 static void osd_read_lock(const struct lu_env *env, struct dt_object *dt,
2592 struct osd_object *obj = osd_dt_obj(dt);
2593 struct osd_thread_info *oti = osd_oti_get(env);
2595 LINVRNT(osd_invariant(obj));
2597 LASSERT(obj->oo_owner != env);
2598 down_read_nested(&obj->oo_sem, role);
2600 LASSERT(obj->oo_owner == NULL);
2604 static void osd_write_lock(const struct lu_env *env, struct dt_object *dt,
2607 struct osd_object *obj = osd_dt_obj(dt);
2608 struct osd_thread_info *oti = osd_oti_get(env);
2610 LINVRNT(osd_invariant(obj));
2612 LASSERT(obj->oo_owner != env);
2613 down_write_nested(&obj->oo_sem, role);
2615 LASSERT(obj->oo_owner == NULL);
2616 obj->oo_owner = env;
2620 static void osd_read_unlock(const struct lu_env *env, struct dt_object *dt)
2622 struct osd_object *obj = osd_dt_obj(dt);
2623 struct osd_thread_info *oti = osd_oti_get(env);
2625 LINVRNT(osd_invariant(obj));
2627 LASSERT(oti->oti_r_locks > 0);
2629 up_read(&obj->oo_sem);
2632 static void osd_write_unlock(const struct lu_env *env, struct dt_object *dt)
2634 struct osd_object *obj = osd_dt_obj(dt);
2635 struct osd_thread_info *oti = osd_oti_get(env);
2637 LINVRNT(osd_invariant(obj));
2639 LASSERT(obj->oo_owner == env);
2640 LASSERT(oti->oti_w_locks > 0);
2642 obj->oo_owner = NULL;
2643 up_write(&obj->oo_sem);
2646 static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
2648 struct osd_object *obj = osd_dt_obj(dt);
2650 LINVRNT(osd_invariant(obj));
2652 return obj->oo_owner == env;
2655 static void osd_inode_getattr(const struct lu_env *env,
2656 struct inode *inode, struct lu_attr *attr)
2658 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2659 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2660 LA_PROJID | LA_FLAGS | LA_NLINK | LA_RDEV |
2661 LA_BLKSIZE | LA_TYPE | LA_BTIME;
2663 attr->la_atime = inode->i_atime.tv_sec;
2664 attr->la_mtime = inode->i_mtime.tv_sec;
2665 attr->la_ctime = inode->i_ctime.tv_sec;
2666 attr->la_btime = LDISKFS_I(inode)->i_crtime.tv_sec;
2667 attr->la_mode = inode->i_mode;
2668 attr->la_size = i_size_read(inode);
2669 attr->la_blocks = inode->i_blocks;
2670 attr->la_uid = i_uid_read(inode);
2671 attr->la_gid = i_gid_read(inode);
2672 attr->la_projid = i_projid_read(inode);
2673 attr->la_flags = ll_inode_to_ext_flags(inode->i_flags);
2674 attr->la_nlink = inode->i_nlink;
2675 attr->la_rdev = inode->i_rdev;
2676 attr->la_blksize = 1 << inode->i_blkbits;
2677 attr->la_blkbits = inode->i_blkbits;
2679 * Ext4 did not transfer inherit flags from raw inode
2680 * to inode flags, and ext4 internally test raw inode
2681 * @i_flags directly. Instead of patching ext4, we do it here.
2683 if (LDISKFS_I(inode)->i_flags & LUSTRE_PROJINHERIT_FL)
2684 attr->la_flags |= LUSTRE_PROJINHERIT_FL;
2687 static int osd_dirent_count(const struct lu_env *env, struct dt_object *dt,
2690 struct osd_object *obj = osd_dt_obj(dt);
2691 const struct dt_it_ops *iops;
2697 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2698 LASSERT(fid_is_namespace_visible(lu_object_fid(&obj->oo_dt.do_lu)));
2700 if (obj->oo_dirent_count != LU_DIRENT_COUNT_UNSET) {
2701 *count = obj->oo_dirent_count;
2705 /* directory not initialized yet */
2706 if (!dt->do_index_ops) {
2711 iops = &dt->do_index_ops->dio_it;
2712 it = iops->init(env, dt, LUDA_64BITHASH);
2714 RETURN(PTR_ERR(it));
2716 rc = iops->load(env, it, 0);
2718 if (rc == -ENODATA) {
2725 rc = iops->next(env, it);
2727 for (*count = 0; rc == 0 || rc == -ESTALE; rc = iops->next(env, it)) {
2731 if (iops->key_size(env, it) == 0)
2737 obj->oo_dirent_count = *count;
2742 iops->fini(env, it);
2747 static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
2748 struct lu_attr *attr)
2750 struct osd_object *obj = osd_dt_obj(dt);
2753 if (unlikely(!dt_object_exists(dt)))
2755 if (unlikely(obj->oo_destroyed))
2758 LASSERT(!dt_object_remote(dt));
2759 LINVRNT(osd_invariant(obj));
2761 spin_lock(&obj->oo_guard);
2762 osd_inode_getattr(env, obj->oo_inode, attr);
2763 if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) {
2764 attr->la_valid |= LA_FLAGS;
2765 attr->la_flags |= LUSTRE_ORPHAN_FL;
2767 if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL) {
2768 attr->la_valid |= LA_FLAGS;
2769 attr->la_flags |= LUSTRE_ENCRYPT_FL;
2771 spin_unlock(&obj->oo_guard);
2773 if (S_ISDIR(obj->oo_inode->i_mode) &&
2774 fid_is_namespace_visible(lu_object_fid(&dt->do_lu)))
2775 rc = osd_dirent_count(env, dt, &attr->la_dirent_count);
2780 static int osd_declare_attr_qid(const struct lu_env *env,
2781 struct osd_object *obj,
2782 struct osd_thandle *oh, long long bspace,
2783 qid_t old_id, qid_t new_id, bool enforce,
2784 unsigned int type, bool ignore_edquot)
2787 struct osd_thread_info *info = osd_oti_get(env);
2788 struct lquota_id_info *qi = &info->oti_qi;
2790 qi->lqi_type = type;
2791 /* inode accounting */
2792 qi->lqi_is_blk = false;
2794 /* one more inode for the new id ... */
2795 qi->lqi_id.qid_uid = new_id;
2797 /* Reserve credits for the new id */
2798 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
2799 if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
2804 /* and one less inode for the current id */
2805 qi->lqi_id.qid_uid = old_id;
2807 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2808 if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
2813 /* block accounting */
2814 qi->lqi_is_blk = true;
2816 /* more blocks for the new id ... */
2817 qi->lqi_id.qid_uid = new_id;
2818 qi->lqi_space = bspace;
2820 * Credits for the new uid has been reserved, re-use "obj"
2821 * to save credit reservation.
2823 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2824 if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
2829 /* and finally less blocks for the current uid */
2830 qi->lqi_id.qid_uid = old_id;
2831 qi->lqi_space = -bspace;
2832 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
2833 if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
2839 static int osd_declare_attr_set(const struct lu_env *env,
2840 struct dt_object *dt,
2841 const struct lu_attr *attr,
2842 struct thandle *handle)
2844 struct osd_thandle *oh;
2845 struct osd_object *obj;
2854 LASSERT(dt != NULL);
2855 LASSERT(handle != NULL);
2857 obj = osd_dt_obj(dt);
2858 LASSERT(osd_invariant(obj));
2860 oh = container_of(handle, struct osd_thandle, ot_super);
2861 LASSERT(oh->ot_handle == NULL);
2863 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
2864 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2866 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2867 osd_dto_credits_noquota[DTO_XATTR_SET]);
2869 if (attr == NULL || obj->oo_inode == NULL)
2872 bspace = obj->oo_inode->i_blocks << 9;
2873 bspace = toqb(bspace);
2876 * Changing ownership is always preformed by super user, it should not
2877 * fail with EDQUOT unless required explicitly.
2879 * We still need to call the osd_declare_qid() to calculate the journal
2880 * credits for updating quota accounting files and to trigger quota
2881 * space adjustment once the operation is completed.
2883 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
2884 bool ignore_edquot = !(attr->la_flags & LUSTRE_SET_SYNC_FL);
2888 "%s: enforce quota on UID %u, GID %u (quota space is %lld)\n",
2889 osd_ino2name(obj->oo_inode), attr->la_uid,
2890 attr->la_gid, bspace);
2893 uid = i_uid_read(obj->oo_inode);
2894 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
2895 rc = osd_declare_attr_qid(env, obj, oh, bspace, uid,
2896 attr->la_uid, enforce, USRQUOTA,
2901 gid = i_gid_read(obj->oo_inode);
2902 CDEBUG(D_QUOTA, "declare uid %d -> %d gid %d -> %d\n", uid,
2903 attr->la_uid, gid, attr->la_gid);
2904 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
2905 rc = osd_declare_attr_qid(env, obj, oh, bspace, gid,
2906 attr->la_gid, enforce, GRPQUOTA,
2912 #ifdef HAVE_PROJECT_QUOTA
2913 if (attr->la_valid & LA_PROJID) {
2914 __u32 projid = i_projid_read(obj->oo_inode);
2916 enforce = (attr->la_valid & LA_PROJID) &&
2917 (attr->la_projid != projid);
2918 rc = osd_declare_attr_qid(env, obj, oh, bspace,
2919 (qid_t)projid, (qid_t)attr->la_projid,
2920 enforce, PRJQUOTA, true);
2928 static int osd_inode_setattr(const struct lu_env *env,
2929 struct inode *inode, const struct lu_attr *attr)
2931 __u64 bits = attr->la_valid;
2933 /* Only allow set size for regular file */
2934 if (!S_ISREG(inode->i_mode))
2935 bits &= ~(LA_SIZE | LA_BLOCKS);
2940 if (bits & LA_ATIME)
2941 inode->i_atime = osd_inode_time(inode, attr->la_atime);
2942 if (bits & LA_CTIME)
2943 inode->i_ctime = osd_inode_time(inode, attr->la_ctime);
2944 if (bits & LA_MTIME)
2945 inode->i_mtime = osd_inode_time(inode, attr->la_mtime);
2946 if (bits & LA_SIZE) {
2947 spin_lock(&inode->i_lock);
2948 LDISKFS_I(inode)->i_disksize = attr->la_size;
2949 i_size_write(inode, attr->la_size);
2950 spin_unlock(&inode->i_lock);
2954 * OSD should not change "i_blocks" which is used by quota.
2955 * "i_blocks" should be changed by ldiskfs only.
2958 inode->i_mode = (inode->i_mode & S_IFMT) |
2959 (attr->la_mode & ~S_IFMT);
2961 i_uid_write(inode, attr->la_uid);
2963 i_gid_write(inode, attr->la_gid);
2964 if (bits & LA_PROJID)
2965 i_projid_write(inode, attr->la_projid);
2966 if (bits & LA_NLINK)
2967 set_nlink(inode, attr->la_nlink);
2969 inode->i_rdev = attr->la_rdev;
2971 if (bits & LA_FLAGS) {
2972 /* always keep S_NOCMTIME */
2973 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
2975 #if defined(S_ENCRYPTED)
2976 /* Always remove S_ENCRYPTED, because ldiskfs must not be
2977 * aware of encryption status. It is just stored into LMA
2978 * so that it can be forwared to client side.
2980 inode->i_flags &= ~S_ENCRYPTED;
2983 * Ext4 did not transfer inherit flags from
2984 * @inode->i_flags to raw inode i_flags when writing
2985 * flags, we do it explictly here.
2987 if (attr->la_flags & LUSTRE_PROJINHERIT_FL)
2988 LDISKFS_I(inode)->i_flags |= LUSTRE_PROJINHERIT_FL;
2990 LDISKFS_I(inode)->i_flags &= ~LUSTRE_PROJINHERIT_FL;
2995 #ifdef HAVE_PROJECT_QUOTA
2996 static int osd_transfer_project(struct inode *inode, __u32 projid,
2997 struct thandle *handle)
2999 struct super_block *sb = inode->i_sb;
3000 struct ldiskfs_inode_info *ei = LDISKFS_I(inode);
3003 struct ldiskfs_iloc iloc;
3004 struct ldiskfs_inode *raw_inode;
3005 struct dquot *transfer_to[LDISKFS_MAXQUOTAS] = { };
3007 if (!ldiskfs_has_feature_project(sb)) {
3008 LASSERT(__kprojid_val(LDISKFS_I(inode)->i_projid)
3009 == LDISKFS_DEF_PROJID);
3010 if (projid != LDISKFS_DEF_PROJID)
3016 if (LDISKFS_INODE_SIZE(sb) <= LDISKFS_GOOD_OLD_INODE_SIZE)
3019 kprojid = make_kprojid(&init_user_ns, (projid_t)projid);
3020 if (projid_eq(kprojid, LDISKFS_I(inode)->i_projid))
3023 err = ldiskfs_get_inode_loc(inode, &iloc);
3027 raw_inode = ldiskfs_raw_inode(&iloc);
3028 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3029 struct osd_thandle *oh = container_of(handle,
3033 * try to expand inode size automatically.
3035 ldiskfs_mark_inode_dirty(oh->ot_handle, inode);
3036 if (!LDISKFS_FITS_IN_INODE(raw_inode, ei, i_projid)) {
3044 dquot_initialize(inode);
3045 transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
3046 if (transfer_to[PRJQUOTA]) {
3047 err = __dquot_transfer(inode, transfer_to);
3048 dqput(transfer_to[PRJQUOTA]);
3057 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr,
3058 struct thandle *handle)
3062 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
3063 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
3067 "executing dquot_transfer inode %ld uid %d -> %d gid %d -> %d\n",
3068 inode->i_ino, i_uid_read(inode), attr->la_uid,
3069 i_gid_read(inode), attr->la_gid);
3071 dquot_initialize(inode);
3073 if (attr->la_valid & LA_UID)
3074 iattr.ia_valid |= ATTR_UID;
3075 if (attr->la_valid & LA_GID)
3076 iattr.ia_valid |= ATTR_GID;
3077 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
3078 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
3080 rc = dquot_transfer(inode, &iattr);
3082 CERROR("%s: quota transfer failed. Is quota enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3083 osd_ino2name(inode), rc);
3088 /* Handle project id transfer here properly */
3089 if (attr->la_valid & LA_PROJID &&
3090 attr->la_projid != i_projid_read(inode)) {
3091 #ifdef HAVE_PROJECT_QUOTA
3092 rc = osd_transfer_project(inode, attr->la_projid, handle);
3097 CERROR("%s: quota transfer failed. Is project enforcement enabled on the ldiskfs filesystem? rc = %d\n",
3098 osd_ino2name(inode), rc);
3105 static int osd_attr_set(const struct lu_env *env,
3106 struct dt_object *dt,
3107 const struct lu_attr *attr,
3108 struct thandle *handle)
3110 struct osd_object *obj = osd_dt_obj(dt);
3111 struct inode *inode;
3114 if (!dt_object_exists(dt))
3117 LASSERT(handle != NULL);
3118 LASSERT(!dt_object_remote(dt));
3119 LASSERT(osd_invariant(obj));
3121 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
3123 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING) &&
3124 !osd_obj2dev(obj)->od_is_ost) {
3125 struct osd_thread_info *oti = osd_oti_get(env);
3126 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
3127 struct lu_fid *fid1 = &oti->oti_fid;
3128 struct osd_inode_id *id = &oti->oti_id;
3129 struct iam_path_descr *ipd;
3130 struct iam_container *bag;
3131 struct osd_thandle *oh;
3134 fid_cpu_to_be(fid1, fid0);
3135 memset(id, 1, sizeof(*id));
3136 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
3137 fid0)->oi_dir.od_container;
3138 ipd = osd_idx_ipd_get(env, bag);
3139 if (unlikely(ipd == NULL))
3142 oh = container_of(handle, struct osd_thandle, ot_super);
3143 rc = iam_update(oh->ot_handle, bag,
3144 (const struct iam_key *)fid1,
3145 (const struct iam_rec *)id, ipd);
3146 osd_ipd_put(env, bag, ipd);
3147 return(rc > 0 ? 0 : rc);
3150 inode = obj->oo_inode;
3152 rc = osd_quota_transfer(inode, attr, handle);
3156 spin_lock(&obj->oo_guard);
3157 rc = osd_inode_setattr(env, inode, attr);
3158 spin_unlock(&obj->oo_guard);
3162 osd_dirty_inode(inode, I_DIRTY_DATASYNC);
3164 osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
3166 if (!(attr->la_valid & LA_FLAGS))
3169 /* Let's check if there are extra flags need to be set into LMA */
3170 if (attr->la_flags & LUSTRE_LMA_FL_MASKS) {
3171 struct osd_thread_info *info = osd_oti_get(env);
3172 struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
3174 LASSERT(!obj->oo_pfid_in_lma);
3176 rc = osd_get_lma(info, inode, &info->oti_obj_dentry,
3177 &info->oti_ost_attrs);
3181 lma->lma_incompat |=