4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_handler.c
38 * Top-level entry points into osd module
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
44 #define DEBUG_SUBSYSTEM S_OSD
46 #include <linux/module.h>
47 #include <linux/user_namespace.h>
48 #ifdef HAVE_UIDGID_HEADER
49 # include <linux/uidgid.h>
52 /* LUSTRE_VERSION_CODE */
53 #include <lustre_ver.h>
54 /* prerequisite for linux/xattr.h */
55 #include <linux/types.h>
56 /* prerequisite for linux/xattr.h */
58 /* XATTR_{REPLACE,CREATE} */
59 #include <linux/xattr.h>
61 #include <ldiskfs/ldiskfs.h>
62 #include <ldiskfs/xattr.h>
65 * struct OBD_{ALLOC,FREE}*()
68 #include <obd_support.h>
69 /* struct ptlrpc_thread */
70 #include <lustre_net.h>
71 #include <lustre_fid.h>
73 #include <lustre_param.h>
75 #include "osd_internal.h"
76 #include "osd_dynlocks.h"
78 /* llo_* api support */
79 #include <md_object.h>
80 #include <lustre_quota.h>
82 #include <lustre_linkea.h>
85 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
86 "ldiskfs with parallel directory operations");
88 int ldiskfs_track_declares_assert;
89 CFS_MODULE_PARM(ldiskfs_track_declares_assert, "i", int, 0644,
90 "LBUG during tracking of declares");
92 /* Slab to allocate dynlocks */
93 struct kmem_cache *dynlock_cachep;
95 /* Slab to allocate osd_it_ea */
96 struct kmem_cache *osd_itea_cachep;
98 static struct lu_kmem_descr ldiskfs_caches[] = {
100 .ckd_cache = &dynlock_cachep,
101 .ckd_name = "dynlock_cache",
102 .ckd_size = sizeof(struct dynlock_handle)
105 .ckd_cache = &osd_itea_cachep,
106 .ckd_name = "osd_itea_cache",
107 .ckd_size = sizeof(struct osd_it_ea)
114 static const char dot[] = ".";
115 static const char dotdot[] = "..";
116 static const char remote_obj_dir[] = "REM_OBJ_DIR";
118 static const struct lu_object_operations osd_lu_obj_ops;
119 static const struct dt_object_operations osd_obj_ops;
120 static const struct dt_object_operations osd_obj_ea_ops;
121 static const struct dt_object_operations osd_obj_otable_it_ops;
122 static const struct dt_index_operations osd_index_iam_ops;
123 static const struct dt_index_operations osd_index_ea_ops;
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
154 * Concurrency: doesn't matter
156 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
158 struct osd_thread_info *oti = osd_oti_get(env);
159 return oti->oti_w_locks > 0 && o->oo_owner == env;
163 * Concurrency: doesn't access mutable data
165 static int osd_root_get(const struct lu_env *env,
166 struct dt_device *dev, struct lu_fid *f)
168 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
173 * OSD object methods.
177 * Concurrency: no concurrent access is possible that early in object
180 static struct lu_object *osd_object_alloc(const struct lu_env *env,
181 const struct lu_object_header *hdr,
184 struct osd_object *mo;
190 l = &mo->oo_dt.do_lu;
191 dt_object_init(&mo->oo_dt, NULL, d);
192 mo->oo_dt.do_ops = &osd_obj_ea_ops;
193 l->lo_ops = &osd_lu_obj_ops;
194 init_rwsem(&mo->oo_sem);
195 init_rwsem(&mo->oo_ext_idx_sem);
196 spin_lock_init(&mo->oo_guard);
203 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
204 struct dentry *dentry, struct lustre_mdt_attrs *lma)
208 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
209 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
210 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
212 if ((void *)lma != (void *)info->oti_mdt_attrs_old)
213 memcpy(lma, info->oti_mdt_attrs_old, sizeof(*lma));
215 lustre_lma_swab(lma);
216 /* Check LMA compatibility */
217 if (lma->lma_incompat & ~LMA_INCOMPAT_SUPP) {
218 CWARN("%.16s: unsupported incompat LMA feature(s) %#x "
219 "for fid = "DFID", ino = %lu\n",
220 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
221 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
222 PFID(&lma->lma_self_fid), inode->i_ino);
225 } else if (rc == 0) {
233 * retrieve object from backend ext fs.
235 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
236 struct osd_inode_id *id)
238 struct inode *inode = NULL;
240 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
242 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
243 id->oii_ino, PTR_ERR(inode));
244 } else if (id->oii_gen != OSD_OII_NOGEN &&
245 inode->i_generation != id->oii_gen) {
246 CDEBUG(D_INODE, "unmatched inode: ino = %u, oii_gen = %u, "
247 "i_generation = %u\n",
248 id->oii_ino, id->oii_gen, inode->i_generation);
250 inode = ERR_PTR(-ESTALE);
251 } else if (inode->i_nlink == 0) {
252 /* due to parallel readdir and unlink,
253 * we can have dead inode here. */
254 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
256 inode = ERR_PTR(-ESTALE);
257 } else if (is_bad_inode(inode)) {
258 CWARN("%.16s: bad inode: ino = %u\n",
259 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
261 inode = ERR_PTR(-ENOENT);
263 if (id->oii_gen == OSD_OII_NOGEN)
264 osd_id_gen(id, inode->i_ino, inode->i_generation);
266 /* Do not update file c/mtime in ldiskfs.
267 * NB: we don't have any lock to protect this because we don't
268 * have reference on osd_object now, but contention with
269 * another lookup + attr_set can't happen in the tiny window
270 * between if (...) and set S_NOCMTIME. */
271 if (!(inode->i_flags & S_NOCMTIME))
272 inode->i_flags |= S_NOCMTIME;
277 static struct inode *
278 osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
279 struct osd_inode_id *id, struct lu_fid *fid)
281 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
285 inode = osd_iget(info, dev, id);
289 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
291 *fid = lma->lma_self_fid;
292 } else if (rc == -ENODATA) {
293 if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
294 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
296 lu_igif_build(fid, inode->i_ino, inode->i_generation);
305 * \retval +v: new filter_fid, does not contain self-fid
306 * \retval 0: filter_fid_old, contains self-fid
307 * \retval -v: other failure cases
309 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
310 struct dentry *dentry, struct lu_fid *fid)
312 struct filter_fid_old *ff = &info->oti_ff;
313 struct ost_id *ostid = &info->oti_ostid;
316 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
317 if (rc == sizeof(*ff)) {
319 ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq));
320 ostid_set_id(ostid, le64_to_cpu(ff->ff_objid));
321 /* XXX: should use real OST index in the future. LU-3569 */
322 ostid_to_fid(fid, ostid, 0);
323 } else if (rc == sizeof(struct filter_fid)) {
325 } else if (rc >= 0) {
332 static int osd_lma_self_repair(struct osd_thread_info *info,
333 struct osd_device *osd, struct inode *inode,
334 const struct lu_fid *fid, __u32 compat)
339 LASSERT(current->journal_info == NULL);
341 jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
342 osd_dto_credits_noquota[DTO_XATTR_SET]);
345 CWARN("%s: cannot start journal for lma_self_repair: rc = %d\n",
350 rc = osd_ea_fid_set(info, inode, fid, compat, 0);
352 CWARN("%s: cannot self repair the LMA: rc = %d\n",
354 ldiskfs_journal_stop(jh);
358 static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
360 struct osd_thread_info *info = osd_oti_get(env);
361 struct osd_device *osd = osd_obj2dev(obj);
362 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
363 struct inode *inode = obj->oo_inode;
364 struct dentry *dentry = &info->oti_obj_dentry;
365 struct lu_fid *fid = NULL;
366 const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
370 CLASSERT(LMA_OLD_SIZE >= sizeof(*lma));
371 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMA,
372 info->oti_mdt_attrs_old, LMA_OLD_SIZE);
373 if (rc == -ENODATA && !fid_is_igif(rfid) && osd->od_check_ff) {
374 fid = &lma->lma_self_fid;
375 rc = osd_get_idif(info, inode, dentry, fid);
376 if ((rc > 0) || (rc == -ENODATA && osd->od_index_in_idif)) {
377 /* For the given OST-object, if it has neither LMA nor
378 * FID in XATTR_NAME_FID, then the given FID (which is
379 * contained in the @obj, from client RPC for locating
380 * the OST-object) is trusted. We use it to generate
382 osd_lma_self_repair(info, osd, inode, rfid,
388 if (unlikely(rc == -ENODATA))
396 lustre_lma_swab(lma);
397 if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
398 CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
399 CWARN("%s: unsupported incompat LMA feature(s) %#x for "
400 "fid = "DFID", ino = %lu\n", osd_name(osd),
401 lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
402 PFID(rfid), inode->i_ino);
405 fid = &lma->lma_self_fid;
409 if (fid != NULL && unlikely(!lu_fid_eq(rfid, fid))) {
410 if (fid_is_idif(rfid) && fid_is_idif(fid)) {
411 struct ost_id *oi = &info->oti_ostid;
412 struct lu_fid *fid1 = &info->oti_fid3;
413 __u32 idx = fid_idif_ost_idx(rfid);
415 /* For old IDIF, the OST index is not part of the IDIF,
416 * Means that different OSTs may have the same IDIFs.
417 * Under such case, we need to make some compatible
418 * check to make sure to trigger OI scrub properly. */
419 if (idx != 0 && fid_idif_ost_idx(fid) == 0) {
420 /* Given @rfid is new, LMA is old. */
421 fid_to_ostid(fid, oi);
422 ostid_to_fid(fid1, oi, idx);
423 if (lu_fid_eq(fid1, rfid)) {
424 if (osd->od_index_in_idif)
425 osd_lma_self_repair(info, osd,
439 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
440 const struct lu_fid *fid,
441 const struct lu_object_conf *conf)
443 struct osd_thread_info *info;
444 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
445 struct osd_device *dev;
446 struct osd_idmap_cache *oic;
447 struct osd_inode_id *id;
449 struct osd_scrub *scrub;
450 struct scrub_file *sf;
454 bool in_cache = false;
455 bool triggered = false;
458 LINVRNT(osd_invariant(obj));
459 LASSERT(obj->oo_inode == NULL);
460 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
463 scrub = &dev->od_scrub;
464 sf = &scrub->os_file;
465 info = osd_oti_get(env);
467 oic = &info->oti_cache;
469 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
472 /* For the object is created as locking anchor, or for the object to
473 * be created on disk. No need to osd_oi_lookup() at here because FID
474 * shouldn't never be re-used, if it's really a duplicate FID from
475 * unexpected reason, we should be able to detect it later by calling
476 * do_create->osd_oi_insert(). */
477 if (conf != NULL && conf->loc_flags & LOC_F_NEW)
478 GOTO(out, result = 0);
480 /* Search order: 1. per-thread cache. */
481 if (lu_fid_eq(fid, &oic->oic_fid) &&
482 likely(oic->oic_dev == dev)) {
489 if (!list_empty(&scrub->os_inconsistent_items)) {
490 /* Search order: 2. OI scrub pending list. */
491 result = osd_oii_lookup(dev, fid, id);
496 /* Search order: 3. OI files. */
497 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
498 if (result == -ENOENT) {
499 if (!(fid_is_norm(fid) || fid_is_igif(fid)) ||
500 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
502 GOTO(out, result = 0);
513 inode = osd_iget(info, dev, id);
515 result = PTR_ERR(inode);
516 if (result != -ENOENT && result != -ESTALE)
520 fid_zero(&oic->oic_fid);
522 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
524 GOTO(out, result = (result == -ENOENT ? 0 : result));
526 /* The OI mapping is there, but the inode is NOT there.
527 * Two possible cases for that:
529 * 1) Backup/restore caused the OI invalid.
530 * 2) Someone unlinked the object but NOT removed
531 * the OI mapping, such as mount target device
532 * as ldiskfs, and modify something directly.
534 * Generally, when the device is mounted, it will
535 * auto check whether the system is restored from
536 * file-level backup or not. We trust such detect
537 * to distinguish the 1st case from the 2nd case. */
538 if (!(scrub->os_file.sf_flags & SF_INCONSISTENT))
539 GOTO(out, result = 0);
542 if (unlikely(triggered))
543 GOTO(out, result = saved);
546 if (thread_is_running(&scrub->os_thread)) {
547 result = -EINPROGRESS;
548 } else if (!dev->od_noscrub) {
549 /* Since we do not know the right OI mapping, we have
550 * to trigger OI scrub to scan the whole device. */
551 result = osd_scrub_start(dev, SS_AUTO_FULL |
552 SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT);
553 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI "
554 "scrub by RPC for "DFID", rc = %d [1]\n",
555 osd_name(dev), PFID(fid), result);
556 if (result == 0 || result == -EALREADY)
557 result = -EINPROGRESS;
562 /* We still have chance to get the valid inode: for the
563 * object which is referenced by remote name entry, the
564 * object on the local MDT will be linked under the dir
565 * of "/REMOTE_PARENT_DIR" with its FID string as name.
567 * We do not know whether the object for the given FID
568 * is referenced by some remote name entry or not, and
569 * especially for DNE II, a multiple-linked object may
570 * have many name entries reside on many MDTs.
572 * To simplify the operation, OSD will not distinguish
573 * more, just lookup "/REMOTE_PARENT_DIR". Usually, it
574 * only happened for the RPC from other MDT during the
575 * OI scrub, or for the client side RPC with FID only,
576 * such as FID to path, or from old connected client. */
578 result = osd_lookup_in_remote_parent(info, dev, fid, id);
584 GOTO(out, result = saved);
587 obj->oo_inode = inode;
588 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
590 result = osd_check_lma(env, obj);
593 obj->oo_inode = NULL;
595 if (result != -EREMCHG)
599 fid_zero(&oic->oic_fid);
601 result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
605 if (result != -ENOENT)
608 if (!in_oi && (fid_is_norm(fid) || fid_is_igif(fid)) &&
609 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
613 GOTO(out, result = 0);
616 obj->oo_compat_dot_created = 1;
617 obj->oo_compat_dotdot_created = 1;
619 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
620 GOTO(out, result = 0);
622 LASSERT(obj->oo_hl_head == NULL);
623 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
624 if (obj->oo_hl_head == NULL) {
625 obj->oo_inode = NULL;
627 GOTO(out, result = -ENOMEM);
629 GOTO(out, result = 0);
632 LINVRNT(osd_invariant(obj));
637 * Concurrency: shouldn't matter.
639 static void osd_object_init0(struct osd_object *obj)
641 LASSERT(obj->oo_inode != NULL);
642 obj->oo_dt.do_body_ops = &osd_body_ops;
643 obj->oo_dt.do_lu.lo_header->loh_attr |=
644 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
648 * Concurrency: no concurrent access is possible that early in object
651 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
652 const struct lu_object_conf *conf)
654 struct osd_object *obj = osd_obj(l);
657 LINVRNT(osd_invariant(obj));
659 if (fid_is_otable_it(&l->lo_header->loh_fid)) {
660 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
661 l->lo_header->loh_attr |= LOHA_EXISTS;
665 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
666 obj->oo_dt.do_body_ops = &osd_body_ops_new;
667 if (result == 0 && obj->oo_inode != NULL)
668 osd_object_init0(obj);
670 LINVRNT(osd_invariant(obj));
675 * Concurrency: no concurrent access is possible that late in object
678 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
680 struct osd_object *obj = osd_obj(l);
682 LINVRNT(osd_invariant(obj));
684 dt_object_fini(&obj->oo_dt);
685 if (obj->oo_hl_head != NULL)
686 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
691 * Concurrency: no concurrent access is possible that late in object
694 static void osd_index_fini(struct osd_object *o)
696 struct iam_container *bag;
698 if (o->oo_dir != NULL) {
699 bag = &o->oo_dir->od_container;
700 if (o->oo_inode != NULL) {
701 if (bag->ic_object == o->oo_inode)
702 iam_container_fini(bag);
704 OBD_FREE_PTR(o->oo_dir);
710 * Concurrency: no concurrent access is possible that late in object
711 * life-cycle (for all existing callers, that is. New callers have to provide
712 * their own locking.)
714 static int osd_inode_unlinked(const struct inode *inode)
716 return inode->i_nlink == 0;
720 OSD_TXN_OI_DELETE_CREDITS = 20,
721 OSD_TXN_INODE_DELETE_CREDITS = 20
728 #if OSD_THANDLE_STATS
730 * Set time when the handle is allocated
732 static void osd_th_alloced(struct osd_thandle *oth)
734 oth->oth_alloced = cfs_time_current();
738 * Set time when the handle started
740 static void osd_th_started(struct osd_thandle *oth)
742 oth->oth_started = cfs_time_current();
746 * Helper function to convert time interval to microseconds packed in
749 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
753 cfs_duration_usec(cfs_time_sub(end, start), &val);
754 return val.tv_sec * 1000000 + val.tv_usec;
758 * Check whether the we deal with this handle for too long.
760 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
761 cfs_time_t alloced, cfs_time_t started,
764 cfs_time_t now = cfs_time_current();
766 LASSERT(dev != NULL);
768 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
769 interval_to_usec(alloced, started));
770 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
771 interval_to_usec(started, closed));
772 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
773 interval_to_usec(closed, now));
775 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
776 CWARN("transaction handle %p was open for too long: "
778 "alloced "CFS_TIME_T" ,"
779 "started "CFS_TIME_T" ,"
780 "closed "CFS_TIME_T"\n",
781 oth, now, alloced, started, closed);
782 libcfs_debug_dumpstack(NULL);
786 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
788 cfs_time_t __closed = cfs_time_current(); \
789 cfs_time_t __alloced = oth->oth_alloced; \
790 cfs_time_t __started = oth->oth_started; \
793 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
796 #else /* OSD_THANDLE_STATS */
798 #define osd_th_alloced(h) do {} while(0)
799 #define osd_th_started(h) do {} while(0)
800 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
802 #endif /* OSD_THANDLE_STATS */
805 * Concurrency: doesn't access mutable data.
807 static int osd_param_is_not_sane(const struct osd_device *dev,
808 const struct thandle *th)
810 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
812 return oh->ot_credits > osd_transaction_size(dev);
816 * Concurrency: shouldn't matter.
818 static void osd_trans_commit_cb(struct super_block *sb,
819 struct ldiskfs_journal_cb_entry *jcb, int error)
821 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
822 struct thandle *th = &oh->ot_super;
823 struct lu_device *lud = &th->th_dev->dd_lu_dev;
824 struct dt_txn_commit_cb *dcb, *tmp;
826 LASSERT(oh->ot_handle == NULL);
829 CERROR("transaction @0x%p commit error: %d\n", th, error);
831 dt_txn_hook_commit(th);
833 /* call per-transaction callbacks if any */
834 list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_dcb_list,
836 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
837 "commit callback entry: magic=%x name='%s'\n",
838 dcb->dcb_magic, dcb->dcb_name);
839 list_del_init(&dcb->dcb_linkage);
840 dcb->dcb_func(NULL, th, dcb, error);
843 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
847 lu_context_exit(&th->th_ctx);
848 lu_context_fini(&th->th_ctx);
852 static struct thandle *osd_trans_create(const struct lu_env *env,
855 struct osd_thread_info *oti = osd_oti_get(env);
856 struct osd_iobuf *iobuf = &oti->oti_iobuf;
857 struct osd_thandle *oh;
861 /* on pending IO in this thread should left from prev. request */
862 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
864 th = ERR_PTR(-ENOMEM);
865 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
867 oh->ot_quota_trans = &oti->oti_quota_trans;
868 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
872 th->th_tags = LCT_TX_HANDLE;
874 INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
875 INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
878 memset(oti->oti_declare_ops, 0,
879 sizeof(oti->oti_declare_ops));
880 memset(oti->oti_declare_ops_rb, 0,
881 sizeof(oti->oti_declare_ops_rb));
882 memset(oti->oti_declare_ops_cred, 0,
883 sizeof(oti->oti_declare_ops_cred));
884 oti->oti_rollback = false;
890 * Concurrency: shouldn't matter.
892 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
895 struct osd_thread_info *oti = osd_oti_get(env);
896 struct osd_device *dev = osd_dt_dev(d);
898 struct osd_thandle *oh;
903 LASSERT(current->journal_info == NULL);
905 oh = container_of0(th, struct osd_thandle, ot_super);
907 LASSERT(oh->ot_handle == NULL);
909 rc = dt_txn_hook_start(env, d, th);
913 if (unlikely(osd_param_is_not_sane(dev, th))) {
914 static unsigned long last_printed;
915 static int last_credits;
917 CWARN("%.16s: too many transaction credits (%d > %d)\n",
918 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
920 osd_journal(dev)->j_max_transaction_buffers);
921 CWARN(" create: %u/%u, destroy: %u/%u\n",
922 oti->oti_declare_ops[OSD_OT_CREATE],
923 oti->oti_declare_ops_cred[OSD_OT_CREATE],
924 oti->oti_declare_ops[OSD_OT_DESTROY],
925 oti->oti_declare_ops_cred[OSD_OT_DESTROY]);
926 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
927 oti->oti_declare_ops[OSD_OT_ATTR_SET],
928 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
929 oti->oti_declare_ops[OSD_OT_XATTR_SET],
930 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]);
931 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
932 oti->oti_declare_ops[OSD_OT_WRITE],
933 oti->oti_declare_ops_cred[OSD_OT_WRITE],
934 oti->oti_declare_ops[OSD_OT_PUNCH],
935 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
936 oti->oti_declare_ops[OSD_OT_QUOTA],
937 oti->oti_declare_ops_cred[OSD_OT_QUOTA]);
938 CWARN(" insert: %u/%u, delete: %u/%u\n",
939 oti->oti_declare_ops[OSD_OT_INSERT],
940 oti->oti_declare_ops_cred[OSD_OT_INSERT],
941 oti->oti_declare_ops[OSD_OT_DELETE],
942 oti->oti_declare_ops_cred[OSD_OT_DELETE]);
943 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
944 oti->oti_declare_ops[OSD_OT_REF_ADD],
945 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
946 oti->oti_declare_ops[OSD_OT_REF_DEL],
947 oti->oti_declare_ops_cred[OSD_OT_REF_DEL]);
949 if (last_credits != oh->ot_credits &&
950 time_after(jiffies, last_printed +
951 msecs_to_jiffies(60 * MSEC_PER_SEC))) {
952 libcfs_debug_dumpstack(NULL);
953 last_credits = oh->ot_credits;
954 last_printed = jiffies;
956 /* XXX Limit the credits to 'max_transaction_buffers', and
957 * let the underlying filesystem to catch the error if
958 * we really need so many credits.
960 * This should be removed when we can calculate the
961 * credits precisely. */
962 oh->ot_credits = osd_transaction_size(dev);
966 * XXX temporary stuff. Some abstraction layer should
969 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
973 LASSERT(oti->oti_txns == 0);
974 lu_context_init(&th->th_ctx, th->th_tags);
975 lu_context_enter(&th->th_ctx);
977 lu_device_get(&d->dd_lu_dev);
978 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
989 static int osd_seq_exists(const struct lu_env *env,
990 struct osd_device *osd, u64 seq)
992 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
993 struct seq_server_site *ss = osd_seq_site(osd);
998 LASSERT(ss->ss_server_fld != NULL);
1000 rc = osd_fld_lookup(env, osd, seq, range);
1003 CERROR("%s: can't lookup FLD sequence "LPX64
1004 ": rc = %d\n", osd_name(osd), seq, rc);
1008 RETURN(ss->ss_node_id == range->lsr_index);
1011 static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
1013 struct dt_txn_commit_cb *dcb;
1014 struct dt_txn_commit_cb *tmp;
1016 /* call per-transaction stop callbacks if any */
1017 list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
1019 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
1020 "commit callback entry: magic=%x name='%s'\n",
1021 dcb->dcb_magic, dcb->dcb_name);
1022 list_del_init(&dcb->dcb_linkage);
1023 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
1028 * Concurrency: shouldn't matter.
1030 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1034 struct osd_thandle *oh;
1035 struct osd_thread_info *oti = osd_oti_get(env);
1036 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1037 struct osd_device *osd = osd_dt_dev(th->th_dev);
1038 struct qsd_instance *qsd = osd->od_quota_slave;
1039 struct lquota_trans *qtrans;
1042 oh = container_of0(th, struct osd_thandle, ot_super);
1044 qtrans = oh->ot_quota_trans;
1045 oh->ot_quota_trans = NULL;
1047 if (oh->ot_handle != NULL) {
1048 handle_t *hdl = oh->ot_handle;
1051 * add commit callback
1052 * notice we don't do this in osd_trans_start()
1053 * as underlying transaction can change during truncate
1055 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1058 LASSERT(oti->oti_txns == 1);
1061 rc = dt_txn_hook_stop(env, th);
1063 CERROR("%s: failed in transaction hook: rc = %d\n",
1066 osd_trans_stop_cb(oh, rc);
1067 /* hook functions might modify th_sync */
1068 hdl->h_sync = th->th_sync;
1070 oh->ot_handle = NULL;
1071 OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl));
1073 CERROR("%s: failed to stop transaction: rc = %d\n",
1076 osd_trans_stop_cb(oh, th->th_result);
1080 /* inform the quota slave device that the transaction is stopping */
1081 qsd_op_end(env, qsd, qtrans);
1083 /* as we want IO to journal and data IO be concurrent, we don't block
1084 * awaiting data IO completion in osd_do_bio(), instead we wait here
1085 * once transaction is submitted to the journal. all reqular requests
1086 * don't do direct IO (except read/write), thus this wait_event becomes
1089 * IMPORTANT: we have to wait till any IO submited by the thread is
1090 * completed otherwise iobuf may be corrupted by different request
1092 wait_event(iobuf->dr_wait,
1093 atomic_read(&iobuf->dr_numreqs) == 0);
1094 osd_fini_iobuf(osd, iobuf);
1096 rc = iobuf->dr_error;
1101 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1103 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1106 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1107 LASSERT(&dcb->dcb_func != NULL);
1108 if (dcb->dcb_flags & DCB_TRANS_STOP)
1109 list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
1111 list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
1117 * Called just before object is freed. Releases all resources except for
1118 * object itself (that is released by osd_object_free()).
1120 * Concurrency: no concurrent access is possible that late in object
1123 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1125 struct osd_object *obj = osd_obj(l);
1126 struct inode *inode = obj->oo_inode;
1128 LINVRNT(osd_invariant(obj));
1131 * If object is unlinked remove fid->ino mapping from object index.
1134 osd_index_fini(obj);
1135 if (inode != NULL) {
1136 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1137 qid_t uid = i_uid_read(inode);
1138 qid_t gid = i_gid_read(inode);
1141 obj->oo_inode = NULL;
1144 struct osd_thread_info *info = osd_oti_get(env);
1145 struct lquota_id_info *qi = &info->oti_qi;
1147 /* Release granted quota to master if necessary */
1148 qi->lqi_id.qid_uid = uid;
1149 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1151 qi->lqi_id.qid_uid = gid;
1152 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
1158 * Concurrency: ->loo_object_release() is called under site spin-lock.
1160 static void osd_object_release(const struct lu_env *env,
1161 struct lu_object *l)
1166 * Concurrency: shouldn't matter.
1168 static int osd_object_print(const struct lu_env *env, void *cookie,
1169 lu_printer_t p, const struct lu_object *l)
1171 struct osd_object *o = osd_obj(l);
1172 struct iam_descr *d;
1174 if (o->oo_dir != NULL)
1175 d = o->oo_dir->od_container.ic_descr;
1178 return (*p)(env, cookie,
1179 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
1181 o->oo_inode ? o->oo_inode->i_ino : 0UL,
1182 o->oo_inode ? o->oo_inode->i_generation : 0,
1183 d ? d->id_ops->id_name : "plain");
1186 #define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */
1189 * Concurrency: shouldn't matter.
1191 int osd_statfs(const struct lu_env *env, struct dt_device *d,
1192 struct obd_statfs *sfs)
1194 struct osd_device *osd = osd_dt_dev(d);
1195 struct super_block *sb = osd_sb(osd);
1196 struct kstatfs *ksfs;
1199 if (unlikely(osd->od_mnt == NULL))
1200 return -EINPROGRESS;
1202 /* osd_lproc.c call this without env, allocate ksfs for that case */
1203 if (unlikely(env == NULL)) {
1204 OBD_ALLOC_PTR(ksfs);
1208 ksfs = &osd_oti_get(env)->oti_ksfs;
1211 spin_lock(&osd->od_osfs_lock);
1212 result = sb->s_op->statfs(sb->s_root, ksfs);
1213 if (likely(result == 0)) { /* N.B. statfs can't really fail */
1214 statfs_pack(sfs, ksfs);
1215 if (sb->s_flags & MS_RDONLY)
1216 sfs->os_state = OS_STATE_READONLY;
1219 spin_unlock(&osd->od_osfs_lock);
1221 if (unlikely(env == NULL))
1224 /* Reserve a small amount of space for local objects like last_rcvd,
1225 * llog, quota files, ... */
1226 if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) {
1229 sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS;
1230 /** Take out metadata overhead for indirect blocks */
1231 sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3);
1238 * Estimate space needed for file creations. We assume the largest filename
1239 * which is 2^64 - 1, hence a filename of 20 chars.
1240 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
1242 #ifdef __LDISKFS_DIR_REC_LEN
1243 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
1245 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
1249 * Concurrency: doesn't access mutable data.
1251 static void osd_conf_get(const struct lu_env *env,
1252 const struct dt_device *dev,
1253 struct dt_device_param *param)
1255 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1259 * XXX should be taken from not-yet-existing fs abstraction layer.
1261 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1262 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1263 param->ddp_block_shift = sb->s_blocksize_bits;
1264 param->ddp_mount_type = LDD_MT_LDISKFS;
1265 param->ddp_maxbytes = sb->s_maxbytes;
1266 /* Overhead estimate should be fairly accurate, so we really take a tiny
1267 * error margin which also avoids fragmenting the filesystem too much */
1268 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
1269 /* inode are statically allocated, so per-inode space consumption
1270 * is the space consumed by the directory entry */
1271 param->ddp_inodespace = PER_OBJ_USAGE;
1272 /* per-fragment overhead to be used by the client code */
1273 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
1274 param->ddp_mntopts = 0;
1275 if (test_opt(sb, XATTR_USER))
1276 param->ddp_mntopts |= MNTOPT_USERXATTR;
1277 if (test_opt(sb, POSIX_ACL))
1278 param->ddp_mntopts |= MNTOPT_ACL;
1280 /* LOD might calculate the max stripe count based on max_ea_size,
1281 * so we need take account in the overhead as well,
1282 * xattr_header + magic + xattr_entry_head */
1283 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
1284 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
1286 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1287 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1288 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
1292 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
1296 * Concurrency: shouldn't matter.
1298 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1302 CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1304 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1306 CDEBUG(D_CACHE, "synced OSD %s: rc = %d\n",
1307 LUSTRE_OSD_LDISKFS_NAME, rc);
1313 * Start commit for OSD device.
1315 * An implementation of dt_commit_async method for OSD device.
1316 * Asychronously starts underlayng fs sync and thereby a transaction
1319 * \param env environment
1320 * \param d dt device
1322 * \see dt_device_operations
1324 static int osd_commit_async(const struct lu_env *env,
1325 struct dt_device *d)
1327 struct super_block *s = osd_sb(osd_dt_dev(d));
1330 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1331 RETURN(s->s_op->sync_fs(s, 0));
1335 * Concurrency: shouldn't matter.
1338 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1340 struct super_block *sb = osd_sb(osd_dt_dev(d));
1341 struct block_device *dev = sb->s_bdev;
1342 #ifdef HAVE_DEV_SET_RDONLY
1343 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
1346 int rc = -EOPNOTSUPP;
1350 #ifdef HAVE_DEV_SET_RDONLY
1351 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1353 if (jdev && (jdev != dev)) {
1354 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
1356 dev_set_rdonly(jdev);
1358 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
1359 dev_set_rdonly(dev);
1361 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
1362 osd_dt_dev(d)->od_svname, (long)dev, rc);
1368 * Note: we do not count into QUOTA here.
1369 * If we mount with --data_journal we may need more.
1371 const int osd_dto_credits_noquota[DTO_NR] = {
1374 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1375 * SINGLEDATA_TRANS_BLOCKS(8)
1376 * XXX Note: maybe iam need more, since iam have more level than
1379 [DTO_INDEX_INSERT] = 16,
1382 * just modify a single entry, probably merge few within a block
1384 [DTO_INDEX_DELETE] = 1,
1388 [DTO_INDEX_UPDATE] = 16,
1390 * 4(inode, inode bits, groups, GDT)
1391 * notice: OI updates are counted separately with DTO_INDEX_INSERT
1393 [DTO_OBJECT_CREATE] = 4,
1395 * 4(inode, inode bits, groups, GDT)
1396 * notice: OI updates are counted separately with DTO_INDEX_DELETE
1398 [DTO_OBJECT_DELETE] = 4,
1400 * Attr set credits (inode)
1402 [DTO_ATTR_SET_BASE] = 1,
1404 * Xattr set. The same as xattr of EXT3.
1405 * DATA_TRANS_BLOCKS(14)
1406 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1407 * are also counted in. Do not know why?
1409 [DTO_XATTR_SET] = 14,
1411 * credits for inode change during write.
1413 [DTO_WRITE_BASE] = 3,
1415 * credits for single block write.
1417 [DTO_WRITE_BLOCK] = 14,
1419 * Attr set credits for chown.
1420 * This is extra credits for setattr, and it is null without quota
1422 [DTO_ATTR_SET_CHOWN] = 0
1425 static const struct dt_device_operations osd_dt_ops = {
1426 .dt_root_get = osd_root_get,
1427 .dt_statfs = osd_statfs,
1428 .dt_trans_create = osd_trans_create,
1429 .dt_trans_start = osd_trans_start,
1430 .dt_trans_stop = osd_trans_stop,
1431 .dt_trans_cb_add = osd_trans_cb_add,
1432 .dt_conf_get = osd_conf_get,
1433 .dt_sync = osd_sync,
1435 .dt_commit_async = osd_commit_async,
1438 static void osd_object_read_lock(const struct lu_env *env,
1439 struct dt_object *dt, unsigned role)
1441 struct osd_object *obj = osd_dt_obj(dt);
1442 struct osd_thread_info *oti = osd_oti_get(env);
1444 LINVRNT(osd_invariant(obj));
1446 LASSERT(obj->oo_owner != env);
1447 down_read_nested(&obj->oo_sem, role);
1449 LASSERT(obj->oo_owner == NULL);
1453 static void osd_object_write_lock(const struct lu_env *env,
1454 struct dt_object *dt, unsigned role)
1456 struct osd_object *obj = osd_dt_obj(dt);
1457 struct osd_thread_info *oti = osd_oti_get(env);
1459 LINVRNT(osd_invariant(obj));
1461 LASSERT(obj->oo_owner != env);
1462 down_write_nested(&obj->oo_sem, role);
1464 LASSERT(obj->oo_owner == NULL);
1465 obj->oo_owner = env;
1469 static void osd_object_read_unlock(const struct lu_env *env,
1470 struct dt_object *dt)
1472 struct osd_object *obj = osd_dt_obj(dt);
1473 struct osd_thread_info *oti = osd_oti_get(env);
1475 LINVRNT(osd_invariant(obj));
1477 LASSERT(oti->oti_r_locks > 0);
1479 up_read(&obj->oo_sem);
1482 static void osd_object_write_unlock(const struct lu_env *env,
1483 struct dt_object *dt)
1485 struct osd_object *obj = osd_dt_obj(dt);
1486 struct osd_thread_info *oti = osd_oti_get(env);
1488 LINVRNT(osd_invariant(obj));
1490 LASSERT(obj->oo_owner == env);
1491 LASSERT(oti->oti_w_locks > 0);
1493 obj->oo_owner = NULL;
1494 up_write(&obj->oo_sem);
1497 static int osd_object_write_locked(const struct lu_env *env,
1498 struct dt_object *dt)
1500 struct osd_object *obj = osd_dt_obj(dt);
1502 LINVRNT(osd_invariant(obj));
1504 return obj->oo_owner == env;
1507 static struct timespec *osd_inode_time(const struct lu_env *env,
1508 struct inode *inode, __u64 seconds)
1510 struct osd_thread_info *oti = osd_oti_get(env);
1511 struct timespec *t = &oti->oti_time;
1513 t->tv_sec = seconds;
1515 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1520 static void osd_inode_getattr(const struct lu_env *env,
1521 struct inode *inode, struct lu_attr *attr)
1523 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1524 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1525 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
1528 attr->la_atime = LTIME_S(inode->i_atime);
1529 attr->la_mtime = LTIME_S(inode->i_mtime);
1530 attr->la_ctime = LTIME_S(inode->i_ctime);
1531 attr->la_mode = inode->i_mode;
1532 attr->la_size = i_size_read(inode);
1533 attr->la_blocks = inode->i_blocks;
1534 attr->la_uid = i_uid_read(inode);
1535 attr->la_gid = i_gid_read(inode);
1536 attr->la_flags = LDISKFS_I(inode)->i_flags;
1537 attr->la_nlink = inode->i_nlink;
1538 attr->la_rdev = inode->i_rdev;
1539 attr->la_blksize = 1 << inode->i_blkbits;
1540 attr->la_blkbits = inode->i_blkbits;
1543 static int osd_attr_get(const struct lu_env *env,
1544 struct dt_object *dt,
1545 struct lu_attr *attr)
1547 struct osd_object *obj = osd_dt_obj(dt);
1549 if (!dt_object_exists(dt))
1552 LASSERT(!dt_object_remote(dt));
1553 LINVRNT(osd_invariant(obj));
1555 spin_lock(&obj->oo_guard);
1556 osd_inode_getattr(env, obj->oo_inode, attr);
1557 spin_unlock(&obj->oo_guard);
1561 static int osd_declare_attr_set(const struct lu_env *env,
1562 struct dt_object *dt,
1563 const struct lu_attr *attr,
1564 struct thandle *handle)
1566 struct osd_thandle *oh;
1567 struct osd_object *obj;
1568 struct osd_thread_info *info = osd_oti_get(env);
1569 struct lquota_id_info *qi = &info->oti_qi;
1577 LASSERT(dt != NULL);
1578 LASSERT(handle != NULL);
1580 obj = osd_dt_obj(dt);
1581 LASSERT(osd_invariant(obj));
1583 oh = container_of0(handle, struct osd_thandle, ot_super);
1584 LASSERT(oh->ot_handle == NULL);
1586 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
1587 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1589 if (attr == NULL || obj->oo_inode == NULL)
1592 bspace = obj->oo_inode->i_blocks;
1593 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1594 bspace = toqb(bspace);
1596 /* Changing ownership is always preformed by super user, it should not
1599 * We still need to call the osd_declare_qid() to calculate the journal
1600 * credits for updating quota accounting files and to trigger quota
1601 * space adjustment once the operation is completed.*/
1602 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
1604 uid = i_uid_read(obj->oo_inode);
1605 qi->lqi_type = USRQUOTA;
1606 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
1607 /* inode accounting */
1608 qi->lqi_is_blk = false;
1610 /* one more inode for the new uid ... */
1611 qi->lqi_id.qid_uid = attr->la_uid;
1613 /* Reserve credits for the new uid */
1614 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1615 if (rc == -EDQUOT || rc == -EINPROGRESS)
1620 /* and one less inode for the current uid */
1621 qi->lqi_id.qid_uid = uid;
1623 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1624 if (rc == -EDQUOT || rc == -EINPROGRESS)
1629 /* block accounting */
1630 qi->lqi_is_blk = true;
1632 /* more blocks for the new uid ... */
1633 qi->lqi_id.qid_uid = attr->la_uid;
1634 qi->lqi_space = bspace;
1636 * Credits for the new uid has been reserved, re-use "obj"
1637 * to save credit reservation.
1639 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1640 if (rc == -EDQUOT || rc == -EINPROGRESS)
1645 /* and finally less blocks for the current uid */
1646 qi->lqi_id.qid_uid = uid;
1647 qi->lqi_space = -bspace;
1648 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1649 if (rc == -EDQUOT || rc == -EINPROGRESS)
1655 gid = i_gid_read(obj->oo_inode);
1656 qi->lqi_type = GRPQUOTA;
1657 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
1659 /* inode accounting */
1660 qi->lqi_is_blk = false;
1662 /* one more inode for the new gid ... */
1663 qi->lqi_id.qid_gid = attr->la_gid;
1665 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1666 if (rc == -EDQUOT || rc == -EINPROGRESS)
1671 /* and one less inode for the current gid */
1672 qi->lqi_id.qid_gid = gid;
1674 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1675 if (rc == -EDQUOT || rc == -EINPROGRESS)
1680 /* block accounting */
1681 qi->lqi_is_blk = true;
1683 /* more blocks for the new gid ... */
1684 qi->lqi_id.qid_gid = attr->la_gid;
1685 qi->lqi_space = bspace;
1686 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1687 if (rc == -EDQUOT || rc == -EINPROGRESS)
1692 /* and finally less blocks for the current gid */
1693 qi->lqi_id.qid_gid = gid;
1694 qi->lqi_space = -bspace;
1695 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1696 if (rc == -EDQUOT || rc == -EINPROGRESS)
1705 static int osd_inode_setattr(const struct lu_env *env,
1706 struct inode *inode, const struct lu_attr *attr)
1708 __u64 bits = attr->la_valid;
1710 /* Only allow set size for regular file */
1711 if (!S_ISREG(inode->i_mode))
1712 bits &= ~(LA_SIZE | LA_BLOCKS);
1717 if (bits & LA_ATIME)
1718 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1719 if (bits & LA_CTIME)
1720 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1721 if (bits & LA_MTIME)
1722 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1723 if (bits & LA_SIZE) {
1724 LDISKFS_I(inode)->i_disksize = attr->la_size;
1725 i_size_write(inode, attr->la_size);
1729 /* OSD should not change "i_blocks" which is used by quota.
1730 * "i_blocks" should be changed by ldiskfs only. */
1731 if (bits & LA_BLOCKS)
1732 inode->i_blocks = attr->la_blocks;
1735 inode->i_mode = (inode->i_mode & S_IFMT) |
1736 (attr->la_mode & ~S_IFMT);
1738 i_uid_write(inode, attr->la_uid);
1740 i_gid_write(inode, attr->la_gid);
1741 if (bits & LA_NLINK)
1742 set_nlink(inode, attr->la_nlink);
1744 inode->i_rdev = attr->la_rdev;
1746 if (bits & LA_FLAGS) {
1747 /* always keep S_NOCMTIME */
1748 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1754 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1756 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
1757 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
1761 ll_vfs_dq_init(inode);
1763 if (attr->la_valid & LA_UID)
1764 iattr.ia_valid |= ATTR_UID;
1765 if (attr->la_valid & LA_GID)
1766 iattr.ia_valid |= ATTR_GID;
1767 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
1768 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
1770 rc = ll_vfs_dq_transfer(inode, &iattr);
1772 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1773 "enforcement enabled on the ldiskfs "
1774 "filesystem?\n", inode->i_sb->s_id, rc);
1781 static int osd_attr_set(const struct lu_env *env,
1782 struct dt_object *dt,
1783 const struct lu_attr *attr,
1784 struct thandle *handle)
1786 struct osd_object *obj = osd_dt_obj(dt);
1787 struct inode *inode;
1790 if (!dt_object_exists(dt))
1793 LASSERT(handle != NULL);
1794 LASSERT(!dt_object_remote(dt));
1795 LASSERT(osd_invariant(obj));
1797 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
1799 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING)) {
1800 struct osd_thread_info *oti = osd_oti_get(env);
1801 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
1802 struct lu_fid *fid1 = &oti->oti_fid;
1803 struct osd_inode_id *id = &oti->oti_id;
1804 struct iam_path_descr *ipd;
1805 struct iam_container *bag;
1806 struct osd_thandle *oh;
1809 fid_cpu_to_be(fid1, fid0);
1810 memset(id, 1, sizeof(*id));
1811 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
1812 fid0)->oi_dir.od_container;
1813 ipd = osd_idx_ipd_get(env, bag);
1814 if (unlikely(ipd == NULL))
1817 oh = container_of0(handle, struct osd_thandle, ot_super);
1818 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
1819 (const struct iam_rec *)id, ipd);
1820 osd_ipd_put(env, bag, ipd);
1821 return(rc > 0 ? 0 : rc);
1824 inode = obj->oo_inode;
1826 rc = osd_quota_transfer(inode, attr);
1830 spin_lock(&obj->oo_guard);
1831 rc = osd_inode_setattr(env, inode, attr);
1832 spin_unlock(&obj->oo_guard);
1835 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
1839 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
1840 struct osd_object *obj,
1841 const char *name, const int namelen)
1843 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1846 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1847 umode_t mode, struct dt_allocation_hint *hint,
1851 struct osd_device *osd = osd_obj2dev(obj);
1852 struct osd_thandle *oth;
1853 struct dt_object *parent = NULL;
1854 struct inode *inode;
1856 LINVRNT(osd_invariant(obj));
1857 LASSERT(obj->oo_inode == NULL);
1858 LASSERT(obj->oo_hl_head == NULL);
1860 if (S_ISDIR(mode) && ldiskfs_pdo) {
1861 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1862 if (obj->oo_hl_head == NULL)
1866 oth = container_of(th, struct osd_thandle, ot_super);
1867 LASSERT(oth->ot_handle->h_transaction != NULL);
1869 if (hint && hint->dah_parent)
1870 parent = hint->dah_parent;
1872 inode = ldiskfs_create_inode(oth->ot_handle,
1873 parent ? osd_dt_obj(parent)->oo_inode :
1874 osd_sb(osd)->s_root->d_inode,
1876 if (!IS_ERR(inode)) {
1877 /* Do not update file c/mtime in ldiskfs. */
1878 inode->i_flags |= S_NOCMTIME;
1880 /* For new created object, it must be consistent,
1881 * and it is unnecessary to scrub against it. */
1882 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
1884 obj->oo_inode = inode;
1887 if (obj->oo_hl_head != NULL) {
1888 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1889 obj->oo_hl_head = NULL;
1891 result = PTR_ERR(inode);
1893 LINVRNT(osd_invariant(obj));
1901 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1902 struct lu_attr *attr,
1903 struct dt_allocation_hint *hint,
1904 struct dt_object_format *dof,
1908 struct osd_thandle *oth;
1909 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1911 LASSERT(S_ISDIR(attr->la_mode));
1913 oth = container_of(th, struct osd_thandle, ot_super);
1914 LASSERT(oth->ot_handle->h_transaction != NULL);
1915 result = osd_mkfile(info, obj, mode, hint, th);
1920 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1921 struct lu_attr *attr,
1922 struct dt_allocation_hint *hint,
1923 struct dt_object_format *dof,
1927 struct osd_thandle *oth;
1928 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1930 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1932 LASSERT(S_ISREG(attr->la_mode));
1934 oth = container_of(th, struct osd_thandle, ot_super);
1935 LASSERT(oth->ot_handle->h_transaction != NULL);
1937 result = osd_mkfile(info, obj, mode, hint, th);
1939 LASSERT(obj->oo_inode != NULL);
1940 if (feat->dif_flags & DT_IND_VARKEY)
1941 result = iam_lvar_create(obj->oo_inode,
1942 feat->dif_keysize_max,
1944 feat->dif_recsize_max,
1947 result = iam_lfix_create(obj->oo_inode,
1948 feat->dif_keysize_max,
1950 feat->dif_recsize_max,
1957 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1958 struct lu_attr *attr,
1959 struct dt_allocation_hint *hint,
1960 struct dt_object_format *dof,
1963 LASSERT(S_ISREG(attr->la_mode));
1964 return osd_mkfile(info, obj, (attr->la_mode &
1965 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1968 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1969 struct lu_attr *attr,
1970 struct dt_allocation_hint *hint,
1971 struct dt_object_format *dof,
1974 LASSERT(S_ISLNK(attr->la_mode));
1975 return osd_mkfile(info, obj, (attr->la_mode &
1976 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1979 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1980 struct lu_attr *attr,
1981 struct dt_allocation_hint *hint,
1982 struct dt_object_format *dof,
1985 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1988 LINVRNT(osd_invariant(obj));
1989 LASSERT(obj->oo_inode == NULL);
1990 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1991 S_ISFIFO(mode) || S_ISSOCK(mode));
1993 result = osd_mkfile(info, obj, mode, hint, th);
1995 LASSERT(obj->oo_inode != NULL);
1997 * This inode should be marked dirty for i_rdev. Currently
1998 * that is done in the osd_attr_init().
2000 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
2003 LINVRNT(osd_invariant(obj));
2007 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
2009 struct dt_allocation_hint *hint,
2010 struct dt_object_format *dof,
2013 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
2015 osd_obj_type_f result;
2031 result = osd_mk_index;
2042 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2043 struct dt_object *parent, struct dt_object *child,
2048 ah->dah_parent = parent;
2049 ah->dah_mode = child_mode;
2052 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
2053 struct lu_attr *attr, struct dt_object_format *dof)
2055 struct inode *inode = obj->oo_inode;
2056 __u64 valid = attr->la_valid;
2059 attr->la_valid &= ~(LA_TYPE | LA_MODE);
2061 if (dof->dof_type != DFT_NODE)
2062 attr->la_valid &= ~LA_RDEV;
2063 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
2064 attr->la_valid &= ~LA_ATIME;
2065 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
2066 attr->la_valid &= ~LA_CTIME;
2067 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
2068 attr->la_valid &= ~LA_MTIME;
2070 result = osd_quota_transfer(inode, attr);
2074 if (attr->la_valid != 0) {
2075 result = osd_inode_setattr(info->oti_env, inode, attr);
2077 * The osd_inode_setattr() should always succeed here. The
2078 * only error that could be returned is EDQUOT when we are
2079 * trying to change the UID or GID of the inode. However, this
2080 * should not happen since quota enforcement is no longer
2081 * enabled on ldiskfs (lquota takes care of it).
2083 LASSERTF(result == 0, "%d\n", result);
2084 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2087 attr->la_valid = valid;
2091 * Helper function for osd_object_create()
2093 * \retval 0, on success
2095 static int __osd_object_create(struct osd_thread_info *info,
2096 struct osd_object *obj, struct lu_attr *attr,
2097 struct dt_allocation_hint *hint,
2098 struct dt_object_format *dof,
2104 /* we drop umask so that permissions we pass are not affected */
2105 umask = current->fs->umask;
2106 current->fs->umask = 0;
2108 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
2110 if (likely(obj->oo_inode != NULL)) {
2111 LASSERT(obj->oo_inode->i_state & I_NEW);
2113 /* Unlock the inode before attr initialization to avoid
2114 * unnecessary dqget operations. LU-6378 */
2115 unlock_new_inode(obj->oo_inode);
2118 if (likely(result == 0)) {
2119 osd_attr_init(info, obj, attr, dof);
2120 osd_object_init0(obj);
2123 /* restore previous umask value */
2124 current->fs->umask = umask;
2130 * Helper function for osd_object_create()
2132 * \retval 0, on success
2134 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
2135 const struct lu_fid *fid, struct thandle *th)
2137 struct osd_thread_info *info = osd_oti_get(env);
2138 struct osd_inode_id *id = &info->oti_id;
2139 struct osd_device *osd = osd_obj2dev(obj);
2140 struct osd_thandle *oh;
2142 LASSERT(obj->oo_inode != NULL);
2144 oh = container_of0(th, struct osd_thandle, ot_super);
2145 LASSERT(oh->ot_handle);
2147 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2148 return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
2151 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
2152 u64 seq, struct lu_seq_range *range)
2154 struct seq_server_site *ss = osd_seq_site(osd);
2156 if (fid_seq_is_idif(seq)) {
2157 fld_range_set_ost(range);
2158 range->lsr_index = idif_ost_idx(seq);
2162 if (!fid_seq_in_fldb(seq)) {
2163 fld_range_set_mdt(range);
2165 /* FIXME: If ss is NULL, it suppose not get lsr_index
2167 range->lsr_index = ss->ss_node_id;
2171 LASSERT(ss != NULL);
2172 fld_range_set_any(range);
2173 /* OSD will only do local fld lookup */
2174 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
2178 * Concurrency: no external locking is necessary.
2180 static int osd_declare_object_create(const struct lu_env *env,
2181 struct dt_object *dt,
2182 struct lu_attr *attr,
2183 struct dt_allocation_hint *hint,
2184 struct dt_object_format *dof,
2185 struct thandle *handle)
2187 struct osd_thandle *oh;
2191 LASSERT(handle != NULL);
2193 oh = container_of0(handle, struct osd_thandle, ot_super);
2194 LASSERT(oh->ot_handle == NULL);
2196 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
2197 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
2198 /* Reuse idle OI block may cause additional one OI block
2200 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2201 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
2203 /* If this is directory, then we expect . and .. to be inserted as
2204 * well. The one directory block always needs to be created for the
2205 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2206 * block), there is no danger of needing a tree for the first block.
2208 if (attr && S_ISDIR(attr->la_mode)) {
2209 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2210 osd_dto_credits_noquota[DTO_WRITE_BASE]);
2211 osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0);
2217 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2218 osd_dt_obj(dt), false, NULL, false);
2225 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2226 struct lu_attr *attr,
2227 struct dt_allocation_hint *hint,
2228 struct dt_object_format *dof, struct thandle *th)
2230 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2231 struct osd_object *obj = osd_dt_obj(dt);
2232 struct osd_thread_info *info = osd_oti_get(env);
2236 if (dt_object_exists(dt))
2239 LINVRNT(osd_invariant(obj));
2240 LASSERT(!dt_object_remote(dt));
2241 LASSERT(osd_write_locked(env, obj));
2242 LASSERT(th != NULL);
2244 if (unlikely(fid_is_acct(fid)))
2245 /* Quota files can't be created from the kernel any more,
2246 * 'tune2fs -O quota' will take care of creating them */
2249 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2250 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2252 result = __osd_object_create(info, obj, attr, hint, dof, th);
2254 result = __osd_oi_insert(env, obj, fid, th);
2256 LASSERT(ergo(result == 0,
2257 dt_object_exists(dt) && !dt_object_remote(dt)));
2259 LASSERT(osd_invariant(obj));
2264 * Called to destroy on-disk representation of the object
2266 * Concurrency: must be locked
2268 static int osd_declare_object_destroy(const struct lu_env *env,
2269 struct dt_object *dt,
2272 struct osd_object *obj = osd_dt_obj(dt);
2273 struct inode *inode = obj->oo_inode;
2274 struct osd_thandle *oh;
2278 oh = container_of0(th, struct osd_thandle, ot_super);
2279 LASSERT(oh->ot_handle == NULL);
2282 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
2283 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2284 /* Recycle idle OI leaf may cause additional three OI blocks
2286 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
2287 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
2288 /* one less inode */
2289 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2290 -1, oh, obj, false, NULL, false);
2293 /* data to be truncated */
2294 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2295 0, oh, obj, true, NULL, false);
2299 static int osd_object_destroy(const struct lu_env *env,
2300 struct dt_object *dt,
2303 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2304 struct osd_object *obj = osd_dt_obj(dt);
2305 struct inode *inode = obj->oo_inode;
2306 struct osd_device *osd = osd_obj2dev(obj);
2307 struct osd_thandle *oh;
2311 oh = container_of0(th, struct osd_thandle, ot_super);
2312 LASSERT(oh->ot_handle);
2314 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2316 if (unlikely(fid_is_acct(fid)))
2319 if (S_ISDIR(inode->i_mode)) {
2320 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
2321 inode->i_nlink == 2);
2322 /* it will check/delete the inode from remote parent,
2323 * how to optimize it? unlink performance impaction XXX */
2324 result = osd_delete_from_remote_parent(env, osd, obj, oh);
2325 if (result != 0 && result != -ENOENT) {
2326 CERROR("%s: delete inode "DFID": rc = %d\n",
2327 osd_name(osd), PFID(fid), result);
2329 spin_lock(&obj->oo_guard);
2331 spin_unlock(&obj->oo_guard);
2332 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2335 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
2337 result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
2340 /* XXX: add to ext3 orphan list */
2341 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2343 /* not needed in the cache anymore */
2344 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2350 * Put the fid into lustre_mdt_attrs, and then place the structure
2351 * inode's ea. This fid should not be altered during the life time
2354 * \retval +ve, on success
2355 * \retval -ve, on error
2357 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2359 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
2360 const struct lu_fid *fid, __u32 compat, __u32 incompat)
2362 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2366 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
2369 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
2372 lustre_lma_init(lma, fid, compat, incompat);
2373 lustre_lma_swab(lma);
2375 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma, sizeof(*lma),
2377 /* LMA may already exist, but we need to check that all the
2378 * desired compat/incompat flags have been added. */
2379 if (unlikely(rc == -EEXIST)) {
2380 if (compat == 0 && incompat == 0)
2383 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
2384 XATTR_NAME_LMA, info->oti_mdt_attrs_old,
2389 lustre_lma_swab(lma);
2390 if (!(~lma->lma_compat & compat) &&
2391 !(~lma->lma_incompat & incompat))
2394 lma->lma_compat |= compat;
2395 lma->lma_incompat |= incompat;
2396 lustre_lma_swab(lma);
2397 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2398 sizeof(*lma), XATTR_REPLACE);
2405 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2406 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2407 * To have compatilibility with 1.8 ldiskfs driver we need to have
2408 * magic number at start of fid data.
2409 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2412 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2413 const struct lu_fid *fid)
2415 if (!fid_is_namespace_visible(fid) ||
2416 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
2417 param->edp_magic = 0;
2421 param->edp_magic = LDISKFS_LUFID_MAGIC;
2422 param->edp_len = sizeof(struct lu_fid) + 1;
2423 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
2427 * Try to read the fid from inode ea into dt_rec.
2429 * \param fid object fid.
2431 * \retval 0 on success
2433 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2434 __u32 ino, struct lu_fid *fid,
2435 struct osd_inode_id *id)
2437 struct osd_thread_info *info = osd_oti_get(env);
2438 struct inode *inode;
2441 osd_id_gen(id, ino, OSD_OII_NOGEN);
2442 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2444 RETURN(PTR_ERR(inode));
2450 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
2452 struct inode *parent_dir,
2453 const struct lu_fid *dot_fid,
2454 const struct lu_fid *dot_dot_fid,
2455 struct osd_thandle *oth)
2457 struct ldiskfs_dentry_param *dot_ldp;
2458 struct ldiskfs_dentry_param *dot_dot_ldp;
2460 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
2461 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
2463 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
2464 dot_ldp->edp_magic = 0;
2465 return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
2466 dir, dot_ldp, dot_dot_ldp);
2470 * Create an local agent inode for remote entry
2472 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
2473 struct osd_device *osd,
2474 struct osd_object *pobj,
2475 const struct lu_fid *fid,
2479 struct osd_thread_info *info = osd_oti_get(env);
2480 struct inode *local;
2481 struct osd_thandle *oh;
2486 oh = container_of(th, struct osd_thandle, ot_super);
2487 LASSERT(oh->ot_handle->h_transaction != NULL);
2489 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
2490 if (IS_ERR(local)) {
2491 CERROR("%s: create local error %d\n", osd_name(osd),
2492 (int)PTR_ERR(local));
2496 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
2497 unlock_new_inode(local);
2499 /* Set special LMA flag for local agent inode */
2500 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
2502 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
2503 osd_name(osd), PFID(fid), rc);
2504 RETURN(ERR_PTR(rc));
2510 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
2511 lu_object_fid(&pobj->oo_dt.do_lu),
2514 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
2515 osd_name(osd), PFID(fid), rc);
2516 RETURN(ERR_PTR(rc));
2523 * Delete local agent inode for remote entry
2525 static int osd_delete_local_agent_inode(const struct lu_env *env,
2526 struct osd_device *osd,
2527 const struct lu_fid *fid,
2528 __u32 ino, struct osd_thandle *oh)
2530 struct osd_thread_info *oti = osd_oti_get(env);
2531 struct osd_inode_id *id = &oti->oti_id;
2532 struct inode *inode;
2535 id->oii_ino = le32_to_cpu(ino);
2536 id->oii_gen = OSD_OII_NOGEN;
2537 inode = osd_iget(oti, osd, id);
2538 if (IS_ERR(inode)) {
2539 CERROR("%s: iget error "DFID" id %u:%u\n", osd_name(osd),
2540 PFID(fid), id->oii_ino, id->oii_gen);
2541 RETURN(PTR_ERR(inode));
2545 mark_inode_dirty(inode);
2546 CDEBUG(D_INODE, "%s: delete remote inode "DFID" %lu\n",
2547 osd_name(osd), PFID(fid), inode->i_ino);
2553 * OSD layer object create function for interoperability mode (b11826).
2554 * This is mostly similar to osd_object_create(). Only difference being, fid is
2555 * inserted into inode ea here.
2557 * \retval 0, on success
2558 * \retval -ve, on error
2560 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2561 struct lu_attr *attr,
2562 struct dt_allocation_hint *hint,
2563 struct dt_object_format *dof,
2566 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2567 struct osd_object *obj = osd_dt_obj(dt);
2568 struct osd_thread_info *info = osd_oti_get(env);
2573 if (dt_object_exists(dt))
2576 LASSERT(osd_invariant(obj));
2577 LASSERT(!dt_object_remote(dt));
2578 LASSERT(osd_write_locked(env, obj));
2579 LASSERT(th != NULL);
2581 if (unlikely(fid_is_acct(fid)))
2582 /* Quota files can't be created from the kernel any more,
2583 * 'tune2fs -O quota' will take care of creating them */
2586 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2587 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2589 result = __osd_object_create(info, obj, attr, hint, dof, th);
2591 if (fid_is_idif(fid) &&
2592 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
2593 struct lu_fid *tfid = &info->oti_fid;
2594 struct ost_id *oi = &info->oti_ostid;
2596 fid_to_ostid(fid, oi);
2597 ostid_to_fid(tfid, oi, 0);
2598 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
2599 LMAC_FID_ON_OST, 0);
2601 result = osd_ea_fid_set(info, obj->oo_inode, fid,
2602 fid_is_on_ost(info, osd_obj2dev(obj),
2603 fid, OI_CHECK_FLD) ?
2604 LMAC_FID_ON_OST : 0, 0);
2609 result = __osd_oi_insert(env, obj, fid, th);
2611 LASSERT(ergo(result == 0,
2612 dt_object_exists(dt) && !dt_object_remote(dt)));
2613 LINVRNT(osd_invariant(obj));
2617 static int osd_declare_object_ref_add(const struct lu_env *env,
2618 struct dt_object *dt,
2619 struct thandle *handle)
2621 struct osd_thandle *oh;
2623 /* it's possible that object doesn't exist yet */
2624 LASSERT(handle != NULL);
2626 oh = container_of0(handle, struct osd_thandle, ot_super);
2627 LASSERT(oh->ot_handle == NULL);
2629 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
2630 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2636 * Concurrency: @dt is write locked.
2638 static int osd_object_ref_add(const struct lu_env *env,
2639 struct dt_object *dt, struct thandle *th)
2641 struct osd_object *obj = osd_dt_obj(dt);
2642 struct inode *inode = obj->oo_inode;
2643 struct osd_thandle *oh;
2646 if (!dt_object_exists(dt))
2649 LINVRNT(osd_invariant(obj));
2650 LASSERT(!dt_object_remote(dt));
2651 LASSERT(osd_write_locked(env, obj));
2652 LASSERT(th != NULL);
2654 oh = container_of0(th, struct osd_thandle, ot_super);
2655 LASSERT(oh->ot_handle != NULL);
2657 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
2659 CDEBUG(D_INODE, DFID" increase nlink %d\n",
2660 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2662 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
2663 * (65000) subdirectories by storing "1" in i_nlink if the link count
2664 * would otherwise overflow. Directory tranversal tools understand
2665 * that (st_nlink == 1) indicates that the filesystem dose not track
2666 * hard links count on the directory, and will not abort subdirectory
2667 * scanning early once (st_nlink - 2) subdirs have been found.
2669 * This also has to properly handle the case of inodes with nlink == 0
2670 * in case they are being linked into the PENDING directory
2672 spin_lock(&obj->oo_guard);
2673 if (unlikely(inode->i_nlink == 0))
2674 /* inc_nlink from 0 may cause WARN_ON */
2675 set_nlink(inode, 1);
2677 ldiskfs_inc_count(oh->ot_handle, inode);
2678 if (!S_ISDIR(inode->i_mode))
2679 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2681 spin_unlock(&obj->oo_guard);
2683 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2684 LINVRNT(osd_invariant(obj));
2689 static int osd_declare_object_ref_del(const struct lu_env *env,
2690 struct dt_object *dt,
2691 struct thandle *handle)
2693 struct osd_thandle *oh;
2695 LASSERT(!dt_object_remote(dt));
2696 LASSERT(handle != NULL);
2698 oh = container_of0(handle, struct osd_thandle, ot_super);
2699 LASSERT(oh->ot_handle == NULL);
2701 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
2702 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2708 * Concurrency: @dt is write locked.
2710 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2713 struct osd_object *obj = osd_dt_obj(dt);
2714 struct inode *inode = obj->oo_inode;
2715 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
2716 struct osd_thandle *oh;
2718 if (!dt_object_exists(dt))
2721 LINVRNT(osd_invariant(obj));
2722 LASSERT(!dt_object_remote(dt));
2723 LASSERT(osd_write_locked(env, obj));
2724 LASSERT(th != NULL);
2726 oh = container_of0(th, struct osd_thandle, ot_super);
2727 LASSERT(oh->ot_handle != NULL);
2729 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
2731 spin_lock(&obj->oo_guard);
2732 /* That can be result of upgrade from old Lustre version and
2733 * applied only to local files. Just skip this ref_del call.
2734 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
2735 if (inode->i_nlink == 0) {
2736 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2737 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
2738 ", maybe an upgraded file? (LU-3915)\n",
2739 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
2740 spin_unlock(&obj->oo_guard);
2744 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
2745 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2747 ldiskfs_dec_count(oh->ot_handle, inode);
2748 spin_unlock(&obj->oo_guard);
2750 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2751 LINVRNT(osd_invariant(obj));
2757 * Get the 64-bit version for an inode.
2759 static int osd_object_version_get(const struct lu_env *env,
2760 struct dt_object *dt, dt_obj_version_t *ver)
2762 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2764 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2765 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2766 *ver = LDISKFS_I(inode)->i_fs_version;
2771 * Concurrency: @dt is read locked.
2773 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2774 struct lu_buf *buf, const char *name)
2776 struct osd_object *obj = osd_dt_obj(dt);
2777 struct inode *inode = obj->oo_inode;
2778 struct osd_thread_info *info = osd_oti_get(env);
2779 struct dentry *dentry = &info->oti_obj_dentry;
2781 /* version get is not real XATTR but uses xattr API */
2782 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2783 /* for version we are just using xattr API but change inode
2785 if (buf->lb_len == 0)
2786 return sizeof(dt_obj_version_t);
2788 if (buf->lb_len < sizeof(dt_obj_version_t))
2791 osd_object_version_get(env, dt, buf->lb_buf);
2793 return sizeof(dt_obj_version_t);
2796 if (!dt_object_exists(dt))
2799 LASSERT(!dt_object_remote(dt));
2800 LASSERT(inode->i_op != NULL);
2801 LASSERT(inode->i_op->getxattr != NULL);
2803 return __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len);
2807 static int osd_declare_xattr_set(const struct lu_env *env,
2808 struct dt_object *dt,
2809 const struct lu_buf *buf, const char *name,
2810 int fl, struct thandle *handle)
2812 struct osd_thandle *oh;
2814 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2816 LASSERT(handle != NULL);
2818 oh = container_of0(handle, struct osd_thandle, ot_super);
2819 LASSERT(oh->ot_handle == NULL);
2821 /* optimistic optimization: LMA is set first and usually fit inode */
2822 if (strcmp(name, XATTR_NAME_LMA) == 0) {
2823 if (dt_object_exists(dt))
2827 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2830 credits = osd_dto_credits_noquota[DTO_XATTR_SET];
2831 if (buf && buf->lb_len > sb->s_blocksize) {
2832 credits *= (buf->lb_len + sb->s_blocksize - 1) >>
2833 sb->s_blocksize_bits;
2836 * xattr set may involve inode quota change, reserve credits for
2837 * dquot_initialize()
2839 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2842 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
2848 * Set the 64-bit version for object
2850 static void osd_object_version_set(const struct lu_env *env,
2851 struct dt_object *dt,
2852 dt_obj_version_t *new_version)
2854 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2856 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2857 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2859 LDISKFS_I(inode)->i_fs_version = *new_version;
2860 /** Version is set after all inode operations are finished,
2861 * so we should mark it dirty here */
2862 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2866 * Concurrency: @dt is write locked.
2868 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2869 const struct lu_buf *buf, const char *name, int fl,
2870 struct thandle *handle)
2872 struct osd_object *obj = osd_dt_obj(dt);
2873 struct inode *inode = obj->oo_inode;
2874 struct osd_thread_info *info = osd_oti_get(env);
2878 LASSERT(handle != NULL);
2880 /* version set is not real XATTR */
2881 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2882 /* for version we are just using xattr API but change inode
2884 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2885 osd_object_version_set(env, dt, buf->lb_buf);
2886 return sizeof(dt_obj_version_t);
2889 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
2890 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
2892 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2893 if (fl & LU_XATTR_REPLACE)
2894 fs_flags |= XATTR_REPLACE;
2896 if (fl & LU_XATTR_CREATE)
2897 fs_flags |= XATTR_CREATE;
2899 if (strcmp(name, XATTR_NAME_LMV) == 0) {
2900 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2903 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
2907 lma->lma_incompat |= LMAI_STRIPED;
2908 lustre_lma_swab(lma);
2909 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2910 sizeof(*lma), XATTR_REPLACE);
2915 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
2916 strcmp(name, XATTR_NAME_LINK) == 0)
2919 return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
2924 * Concurrency: @dt is read locked.
2926 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2927 const struct lu_buf *buf)
2929 struct osd_object *obj = osd_dt_obj(dt);
2930 struct inode *inode = obj->oo_inode;
2931 struct osd_thread_info *info = osd_oti_get(env);
2932 struct dentry *dentry = &info->oti_obj_dentry;
2934 if (!dt_object_exists(dt))
2937 LASSERT(!dt_object_remote(dt));
2938 LASSERT(inode->i_op != NULL);
2939 LASSERT(inode->i_op->listxattr != NULL);
2941 dentry->d_inode = inode;
2942 dentry->d_sb = inode->i_sb;
2943 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2946 static int osd_declare_xattr_del(const struct lu_env *env,
2947 struct dt_object *dt, const char *name,
2948 struct thandle *handle)
2950 struct osd_thandle *oh;
2951 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2953 LASSERT(!dt_object_remote(dt));
2954 LASSERT(handle != NULL);
2956 oh = container_of0(handle, struct osd_thandle, ot_super);
2957 LASSERT(oh->ot_handle == NULL);
2959 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2960 osd_dto_credits_noquota[DTO_XATTR_SET]);
2962 * xattr del may involve inode quota change, reserve credits for
2963 * dquot_initialize()
2965 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2971 * Concurrency: @dt is write locked.
2973 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2974 const char *name, struct thandle *handle)
2976 struct osd_object *obj = osd_dt_obj(dt);
2977 struct inode *inode = obj->oo_inode;
2978 struct osd_thread_info *info = osd_oti_get(env);
2979 struct dentry *dentry = &info->oti_obj_dentry;
2982 if (!dt_object_exists(dt))
2985 LASSERT(!dt_object_remote(dt));
2986 LASSERT(inode->i_op != NULL);
2987 LASSERT(inode->i_op->removexattr != NULL);
2988 LASSERT(handle != NULL);
2990 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2992 ll_vfs_dq_init(inode);
2993 dentry->d_inode = inode;
2994 dentry->d_sb = inode->i_sb;
2995 rc = inode->i_op->removexattr(dentry, name);
2999 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
3000 __u64 start, __u64 end)
3002 struct osd_object *obj = osd_dt_obj(dt);
3003 struct inode *inode = obj->oo_inode;
3004 struct osd_thread_info *info = osd_oti_get(env);
3005 struct dentry *dentry = &info->oti_obj_dentry;
3006 struct file *file = &info->oti_file;
3011 dentry->d_inode = inode;
3012 dentry->d_sb = inode->i_sb;
3013 file->f_path.dentry = dentry;
3014 file->f_mapping = inode->i_mapping;
3015 file->f_op = inode->i_fop;
3016 set_file_inode(file, inode);
3018 rc = ll_vfs_fsync_range(file, start, end, 0);
3027 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
3028 const struct dt_index_features *feat)
3030 struct iam_descr *descr;
3032 if (osd_object_is_root(o))
3033 return feat == &dt_directory_features;
3035 LASSERT(o->oo_dir != NULL);
3037 descr = o->oo_dir->od_container.ic_descr;
3038 if (feat == &dt_directory_features) {
3039 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
3045 feat->dif_keysize_min <= descr->id_key_size &&
3046 descr->id_key_size <= feat->dif_keysize_max &&
3047 feat->dif_recsize_min <= descr->id_rec_size &&
3048 descr->id_rec_size <= feat->dif_recsize_max &&
3049 !(feat->dif_flags & (DT_IND_VARKEY |
3050 DT_IND_VARREC | DT_IND_NONUNQ)) &&
3051 ergo(feat->dif_flags & DT_IND_UPDATE,
3052 1 /* XXX check that object (and file system) is
3057 static int osd_iam_container_init(const struct lu_env *env,
3058 struct osd_object *obj,
3059 struct osd_directory *dir)
3061 struct iam_container *bag = &dir->od_container;
3064 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
3068 result = iam_container_setup(bag);
3070 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
3072 iam_container_fini(bag);
3079 * Concurrency: no external locking is necessary.
3081 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
3082 const struct dt_index_features *feat)
3086 struct osd_object *obj = osd_dt_obj(dt);
3088 LINVRNT(osd_invariant(obj));
3090 if (osd_object_is_root(obj)) {
3091 dt->do_index_ops = &osd_index_ea_ops;
3093 } else if (feat == &dt_directory_features) {
3094 dt->do_index_ops = &osd_index_ea_ops;
3095 if (obj->oo_inode != NULL && S_ISDIR(obj->oo_inode->i_mode))
3100 } else if (unlikely(feat == &dt_otable_features)) {
3101 dt->do_index_ops = &osd_otable_ops;
3103 } else if (unlikely(feat == &dt_acct_features)) {
3104 dt->do_index_ops = &osd_acct_index_ops;
3107 } else if (!osd_has_index(obj)) {
3108 struct osd_directory *dir;
3113 spin_lock(&obj->oo_guard);
3114 if (obj->oo_dir == NULL)
3118 * Concurrent thread allocated container data.
3121 spin_unlock(&obj->oo_guard);
3123 * Now, that we have container data, serialize its
3126 down_write(&obj->oo_ext_idx_sem);
3128 * recheck under lock.
3130 if (!osd_has_index(obj))
3131 result = osd_iam_container_init(env, obj,
3135 up_write(&obj->oo_ext_idx_sem);
3143 if (result == 0 && skip_iam == 0) {
3144 if (!osd_iam_index_probe(env, obj, feat))
3147 LINVRNT(osd_invariant(obj));
3149 if (result == 0 && feat == &dt_quota_glb_features &&
3150 fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
3151 result = osd_quota_migration(env, dt);
3156 static int osd_otable_it_attr_get(const struct lu_env *env,
3157 struct dt_object *dt,
3158 struct lu_attr *attr)
3164 static const struct dt_object_operations osd_obj_ops = {
3165 .do_read_lock = osd_object_read_lock,
3166 .do_write_lock = osd_object_write_lock,
3167 .do_read_unlock = osd_object_read_unlock,
3168 .do_write_unlock = osd_object_write_unlock,
3169 .do_write_locked = osd_object_write_locked,
3170 .do_attr_get = osd_attr_get,
3171 .do_declare_attr_set = osd_declare_attr_set,
3172 .do_attr_set = osd_attr_set,
3173 .do_ah_init = osd_ah_init,
3174 .do_declare_create = osd_declare_object_create,
3175 .do_create = osd_object_create,
3176 .do_declare_destroy = osd_declare_object_destroy,
3177 .do_destroy = osd_object_destroy,
3178 .do_index_try = osd_index_try,
3179 .do_declare_ref_add = osd_declare_object_ref_add,
3180 .do_ref_add = osd_object_ref_add,
3181 .do_declare_ref_del = osd_declare_object_ref_del,
3182 .do_ref_del = osd_object_ref_del,
3183 .do_xattr_get = osd_xattr_get,
3184 .do_declare_xattr_set = osd_declare_xattr_set,
3185 .do_xattr_set = osd_xattr_set,
3186 .do_declare_xattr_del = osd_declare_xattr_del,
3187 .do_xattr_del = osd_xattr_del,
3188 .do_xattr_list = osd_xattr_list,
3189 .do_object_sync = osd_object_sync,
3193 * dt_object_operations for interoperability mode
3194 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
3196 static const struct dt_object_operations osd_obj_ea_ops = {
3197 .do_read_lock = osd_object_read_lock,
3198 .do_write_lock = osd_object_write_lock,
3199 .do_read_unlock = osd_object_read_unlock,
3200 .do_write_unlock = osd_object_write_unlock,
3201 .do_write_locked = osd_object_write_locked,
3202 .do_attr_get = osd_attr_get,
3203 .do_declare_attr_set = osd_declare_attr_set,
3204 .do_attr_set = osd_attr_set,
3205 .do_ah_init = osd_ah_init,
3206 .do_declare_create = osd_declare_object_create,
3207 .do_create = osd_object_ea_create,
3208 .do_declare_destroy = osd_declare_object_destroy,
3209 .do_destroy = osd_object_destroy,
3210 .do_index_try = osd_index_try,
3211 .do_declare_ref_add = osd_declare_object_ref_add,
3212 .do_ref_add = osd_object_ref_add,
3213 .do_declare_ref_del = osd_declare_object_ref_del,
3214 .do_ref_del = osd_object_ref_del,
3215 .do_xattr_get = osd_xattr_get,
3216 .do_declare_xattr_set = osd_declare_xattr_set,
3217 .do_xattr_set = osd_xattr_set,
3218 .do_declare_xattr_del = osd_declare_xattr_del,
3219 .do_xattr_del = osd_xattr_del,
3220 .do_xattr_list = osd_xattr_list,
3221 .do_object_sync = osd_object_sync,
3224 static const struct dt_object_operations osd_obj_otable_it_ops = {
3225 .do_attr_get = osd_otable_it_attr_get,
3226 .do_index_try = osd_index_try,
3229 static int osd_index_declare_iam_delete(const struct lu_env *env,
3230 struct dt_object *dt,
3231 const struct dt_key *key,
3232 struct thandle *handle)
3234 struct osd_thandle *oh;
3236 oh = container_of0(handle, struct osd_thandle, ot_super);
3237 LASSERT(oh->ot_handle == NULL);
3239 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3240 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3246 * delete a (key, value) pair from index \a dt specified by \a key
3248 * \param dt osd index object
3249 * \param key key for index
3250 * \param rec record reference
3251 * \param handle transaction handler
3254 * \retval -ve failure
3256 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
3257 const struct dt_key *key,
3258 struct thandle *handle)
3260 struct osd_thread_info *oti = osd_oti_get(env);
3261 struct osd_object *obj = osd_dt_obj(dt);
3262 struct osd_thandle *oh;
3263 struct iam_path_descr *ipd;
3264 struct iam_container *bag = &obj->oo_dir->od_container;
3268 if (!dt_object_exists(dt))
3271 LINVRNT(osd_invariant(obj));
3272 LASSERT(!dt_object_remote(dt));
3273 LASSERT(bag->ic_object == obj->oo_inode);
3274 LASSERT(handle != NULL);
3276 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3278 ipd = osd_idx_ipd_get(env, bag);
3279 if (unlikely(ipd == NULL))
3282 oh = container_of0(handle, struct osd_thandle, ot_super);
3283 LASSERT(oh->ot_handle != NULL);
3284 LASSERT(oh->ot_handle->h_transaction != NULL);
3286 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3287 /* swab quota uid/gid provided by caller */
3288 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3289 key = (const struct dt_key *)&oti->oti_quota_id;
3292 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
3293 osd_ipd_put(env, bag, ipd);
3294 LINVRNT(osd_invariant(obj));
3298 static int osd_index_declare_ea_delete(const struct lu_env *env,
3299 struct dt_object *dt,
3300 const struct dt_key *key,
3301 struct thandle *handle)
3303 struct osd_thandle *oh;
3304 struct inode *inode;
3308 LASSERT(!dt_object_remote(dt));
3309 LASSERT(handle != NULL);
3311 oh = container_of0(handle, struct osd_thandle, ot_super);
3312 LASSERT(oh->ot_handle == NULL);
3314 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3315 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3317 inode = osd_dt_obj(dt)->oo_inode;
3320 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3321 0, oh, osd_dt_obj(dt), true, NULL, false);
3325 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3328 struct osd_fid_pack *rec;
3331 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3332 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3333 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3334 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
3340 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
3341 const struct lu_fid *fid)
3343 struct seq_server_site *ss = osd_seq_site(osd);
3346 /* FID seqs not in FLDB, must be local seq */
3347 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
3350 /* If FLD is not being initialized yet, it only happens during the
3351 * initialization, likely during mgs initialization, and we assume
3352 * this is local FID. */
3353 if (ss == NULL || ss->ss_server_fld == NULL)
3356 /* Only check the local FLDB here */
3357 if (osd_seq_exists(env, osd, fid_seq(fid)))
3364 * Index delete function for interoperability mode (b11826).
3365 * It will remove the directory entry added by osd_index_ea_insert().
3366 * This entry is needed to maintain name->fid mapping.
3368 * \param key, key i.e. file entry to be deleted
3370 * \retval 0, on success
3371 * \retval -ve, on error
3373 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3374 const struct dt_key *key, struct thandle *handle)
3376 struct osd_object *obj = osd_dt_obj(dt);
3377 struct inode *dir = obj->oo_inode;
3378 struct dentry *dentry;
3379 struct osd_thandle *oh;
3380 struct ldiskfs_dir_entry_2 *de = NULL;
3381 struct buffer_head *bh;
3382 struct htree_lock *hlock = NULL;
3383 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
3384 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3388 if (!dt_object_exists(dt))
3391 LINVRNT(osd_invariant(obj));
3392 LASSERT(!dt_object_remote(dt));
3393 LASSERT(handle != NULL);
3395 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3397 oh = container_of(handle, struct osd_thandle, ot_super);
3398 LASSERT(oh->ot_handle != NULL);
3399 LASSERT(oh->ot_handle->h_transaction != NULL);
3401 ll_vfs_dq_init(dir);
3402 dentry = osd_child_dentry_get(env, obj,
3403 (char *)key, strlen((char *)key));
3405 if (obj->oo_hl_head != NULL) {
3406 hlock = osd_oti_get(env)->oti_hlock;
3407 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3408 dir, LDISKFS_HLOCK_DEL);
3410 down_write(&obj->oo_ext_idx_sem);
3413 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
3417 /* If this is not the ".." entry, it might be a remote DNE
3418 * entry and we need to check if the FID is for a remote
3419 * MDT. If the FID is not in the directory entry (e.g.
3420 * upgraded 1.8 filesystem without dirdata enabled) then
3421 * we need to get the FID from the LMA. For a remote directory
3422 * there HAS to be an LMA, it cannot be an IGIF inode in this
3425 * Delete the entry before the agent inode in order to
3426 * simplify error handling. At worst an error after deleting
3427 * the entry first might leak the agent inode afterward. The
3428 * reverse would need filesystem abort in case of error deleting
3429 * the entry after the agent had been removed, or leave a
3430 * dangling entry pointing at a random inode. */
3431 if (strcmp((char *)key, dotdot) != 0) {
3432 LASSERT(de != NULL);
3433 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
3434 /* If Fid is not in dentry, try to get it from LMA */
3435 if (rc == -ENODATA) {
3436 struct osd_inode_id *id;
3437 struct inode *inode;
3439 /* Before trying to get fid from the inode,
3440 * check whether the inode is valid.
3442 * If the inode has been deleted, do not go
3443 * ahead to do osd_ea_fid_get, which will set
3444 * the inode to bad inode, which might cause
3445 * the inode to be deleted uncorrectly */
3446 inode = ldiskfs_iget(osd_sb(osd),
3447 le32_to_cpu(de->inode));
3448 if (IS_ERR(inode)) {
3449 CDEBUG(D_INODE, "%s: "DFID"get inode"
3450 "error.\n", osd_name(osd),
3452 rc = PTR_ERR(inode);
3454 if (likely(inode->i_nlink != 0)) {
3455 id = &osd_oti_get(env)->oti_id;
3456 rc = osd_ea_fid_get(env, obj,
3457 le32_to_cpu(de->inode),
3460 CDEBUG(D_INFO, "%s: %u "DFID
3463 le32_to_cpu(de->inode),
3471 unlikely(osd_remote_fid(env, osd, fid)))
3472 /* Need to delete agent inode */
3473 ino = le32_to_cpu(de->inode);
3475 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
3477 if (rc == 0 && unlikely(ino != 0)) {
3478 rc = osd_delete_local_agent_inode(env, osd, fid, ino,
3481 CERROR("%s: del local inode "DFID": rc = %d\n",
3482 osd_name(osd), PFID(fid), rc);
3488 ldiskfs_htree_unlock(hlock);
3490 up_write(&obj->oo_ext_idx_sem);
3495 /* For inode on the remote MDT, .. will point to
3496 * /Agent directory, Check whether it needs to delete
3497 * from agent directory */
3498 if (unlikely(strcmp((char *)key, dotdot) == 0)) {
3499 rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj,
3501 if (rc != 0 && rc != -ENOENT) {
3502 CERROR("%s: delete agent inode "DFID": rc = %d\n",
3503 osd_name(osd), PFID(fid), rc);
3513 LASSERT(osd_invariant(obj));
3518 * Lookup index for \a key and copy record to \a rec.
3520 * \param dt osd index object
3521 * \param key key for index
3522 * \param rec record reference
3524 * \retval +ve success : exact mach
3525 * \retval 0 return record with key not greater than \a key
3526 * \retval -ve failure
3528 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3529 struct dt_rec *rec, const struct dt_key *key)
3531 struct osd_object *obj = osd_dt_obj(dt);
3532 struct iam_path_descr *ipd;
3533 struct iam_container *bag = &obj->oo_dir->od_container;
3534 struct osd_thread_info *oti = osd_oti_get(env);
3535 struct iam_iterator *it = &oti->oti_idx_it;
3536 struct iam_rec *iam_rec;
3540 if (!dt_object_exists(dt))
3543 LASSERT(osd_invariant(obj));
3544 LASSERT(!dt_object_remote(dt));
3545 LASSERT(bag->ic_object == obj->oo_inode);
3547 ipd = osd_idx_ipd_get(env, bag);
3551 /* got ipd now we can start iterator. */
3552 iam_it_init(it, bag, 0, ipd);
3554 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3555 /* swab quota uid/gid provided by caller */
3556 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3557 key = (const struct dt_key *)&oti->oti_quota_id;
3560 rc = iam_it_get(it, (struct iam_key *)key);
3562 if (S_ISDIR(obj->oo_inode->i_mode))
3563 iam_rec = (struct iam_rec *)oti->oti_ldp;
3565 iam_rec = (struct iam_rec *) rec;
3567 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3569 if (S_ISDIR(obj->oo_inode->i_mode))
3570 osd_fid_unpack((struct lu_fid *) rec,
3571 (struct osd_fid_pack *)iam_rec);
3572 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3573 osd_quota_unpack(obj, rec);
3578 osd_ipd_put(env, bag, ipd);
3580 LINVRNT(osd_invariant(obj));
3585 static int osd_index_declare_iam_insert(const struct lu_env *env,
3586 struct dt_object *dt,
3587 const struct dt_rec *rec,
3588 const struct dt_key *key,
3589 struct thandle *handle)
3591 struct osd_thandle *oh;
3593 LASSERT(handle != NULL);
3595 oh = container_of0(handle, struct osd_thandle, ot_super);
3596 LASSERT(oh->ot_handle == NULL);
3598 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3599 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3605 * Inserts (key, value) pair in \a dt index object.
3607 * \param dt osd index object
3608 * \param key key for index
3609 * \param rec record reference
3610 * \param th transaction handler
3613 * \retval -ve failure
3615 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3616 const struct dt_rec *rec,
3617 const struct dt_key *key, struct thandle *th,
3620 struct osd_object *obj = osd_dt_obj(dt);
3621 struct iam_path_descr *ipd;
3622 struct osd_thandle *oh;
3623 struct iam_container *bag;
3624 struct osd_thread_info *oti = osd_oti_get(env);
3625 struct iam_rec *iam_rec;
3629 if (!dt_object_exists(dt))
3632 LINVRNT(osd_invariant(obj));
3633 LASSERT(!dt_object_remote(dt));
3635 bag = &obj->oo_dir->od_container;
3636 LASSERT(bag->ic_object == obj->oo_inode);
3637 LASSERT(th != NULL);
3639 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3641 ipd = osd_idx_ipd_get(env, bag);
3642 if (unlikely(ipd == NULL))
3645 oh = container_of0(th, struct osd_thandle, ot_super);
3646 LASSERT(oh->ot_handle != NULL);
3647 LASSERT(oh->ot_handle->h_transaction != NULL);
3648 if (S_ISDIR(obj->oo_inode->i_mode)) {
3649 iam_rec = (struct iam_rec *)oti->oti_ldp;
3650 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3651 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3652 /* pack quota uid/gid */
3653 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3654 key = (const struct dt_key *)&oti->oti_quota_id;
3655 /* pack quota record */
3656 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3657 iam_rec = (struct iam_rec *)rec;
3659 iam_rec = (struct iam_rec *)rec;
3662 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3664 osd_ipd_put(env, bag, ipd);
3665 LINVRNT(osd_invariant(obj));
3670 * Calls ldiskfs_add_entry() to add directory entry
3671 * into the directory. This is required for
3672 * interoperability mode (b11826)
3674 * \retval 0, on success
3675 * \retval -ve, on error
3677 static int __osd_ea_add_rec(struct osd_thread_info *info,
3678 struct osd_object *pobj, struct inode *cinode,
3679 const char *name, const struct lu_fid *fid,
3680 struct htree_lock *hlock, struct thandle *th)
3682 struct ldiskfs_dentry_param *ldp;
3683 struct dentry *child;
3684 struct osd_thandle *oth;
3687 oth = container_of(th, struct osd_thandle, ot_super);
3688 LASSERT(oth->ot_handle != NULL);
3689 LASSERT(oth->ot_handle->h_transaction != NULL);
3690 LASSERT(pobj->oo_inode);
3692 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3693 if (unlikely(pobj->oo_inode ==
3694 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
3697 osd_get_ldiskfs_dirent_param(ldp, fid);
3698 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3699 child->d_fsdata = (void *)ldp;
3700 ll_vfs_dq_init(pobj->oo_inode);
3701 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3702 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
3703 struct ldiskfs_dir_entry_2 *de;
3704 struct buffer_head *bh;
3707 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
3710 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
3713 if (S_ISDIR(cinode->i_mode))
3714 de->file_type = LDISKFS_DIRENT_LUFID |
3715 LDISKFS_FT_REG_FILE;
3717 de->file_type = LDISKFS_DIRENT_LUFID |
3719 ldiskfs_handle_dirty_metadata(oth->ot_handle,
3730 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3731 * into the directory.Also sets flags into osd object to
3732 * indicate dot and dotdot are created. This is required for
3733 * interoperability mode (b11826)
3735 * \param dir directory for dot and dotdot fixup.
3736 * \param obj child object for linking
3738 * \retval 0, on success
3739 * \retval -ve, on error
3741 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3742 struct osd_object *dir,
3743 struct inode *parent_dir, const char *name,
3744 const struct lu_fid *dot_fid,
3745 const struct lu_fid *dot_dot_fid,
3748 struct inode *inode = dir->oo_inode;
3749 struct osd_thandle *oth;
3752 oth = container_of(th, struct osd_thandle, ot_super);
3753 LASSERT(oth->ot_handle->h_transaction != NULL);
3754 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3756 if (strcmp(name, dot) == 0) {
3757 if (dir->oo_compat_dot_created) {
3760 LASSERT(inode == parent_dir);
3761 dir->oo_compat_dot_created = 1;
3764 } else if (strcmp(name, dotdot) == 0) {
3765 if (!dir->oo_compat_dot_created)
3767 /* in case of rename, dotdot is already created */
3768 if (dir->oo_compat_dotdot_created) {
3769 return __osd_ea_add_rec(info, dir, parent_dir, name,
3770 dot_dot_fid, NULL, th);
3773 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
3774 struct lu_fid tfid = *dot_dot_fid;
3777 result = osd_add_dot_dotdot_internal(info,
3778 dir->oo_inode, parent_dir, dot_fid,
3781 result = osd_add_dot_dotdot_internal(info,
3782 dir->oo_inode, parent_dir, dot_fid,
3787 dir->oo_compat_dotdot_created = 1;
3790 /* ldiskfs_init_new_dir() doesn't call ldiskfs_mark_inode_dirty()
3791 * this seem as an optimization as usually it's called
3792 * later to refresh mtime of the parent. Lustre does not
3793 * update mtime in few cases (e.g. PENDING, .lustre)
3794 * we still need to transfer i_size/etc to the buffer cache */
3795 ldiskfs_mark_inode_dirty(oth->ot_handle, dir->oo_inode);
3802 * It will call the appropriate osd_add* function and return the
3803 * value, return by respective functions.
3805 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3806 struct inode *cinode, const char *name,
3807 const struct lu_fid *fid, struct thandle *th)
3809 struct osd_thread_info *info = osd_oti_get(env);
3810 struct htree_lock *hlock;
3813 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3815 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3817 if (hlock != NULL) {
3818 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3821 down_write(&pobj->oo_ext_idx_sem);
3824 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3825 lu_object_fid(&pobj->oo_dt.do_lu),
3828 if (hlock != NULL) {
3829 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3830 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3832 down_write(&pobj->oo_ext_idx_sem);
3835 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
3836 struct lu_fid *tfid = &info->oti_fid;
3840 rc = __osd_ea_add_rec(info, pobj, cinode, name,
3843 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3848 ldiskfs_htree_unlock(hlock);
3850 up_write(&pobj->oo_ext_idx_sem);
3856 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3857 struct osd_idmap_cache *oic)
3859 struct osd_scrub *scrub = &dev->od_scrub;
3860 struct lu_fid *fid = &oic->oic_fid;
3861 struct osd_inode_id *id = &oti->oti_id;
3866 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3869 if (scrub->os_pos_current > id->oii_ino)
3873 rc = osd_oi_lookup(oti, dev, fid, id, OI_CHECK_FLD);
3874 if (rc != 0 && rc != -ENOENT)
3877 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3880 if (thread_is_running(&scrub->os_thread)) {
3881 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3882 /* There is race condition between osd_oi_lookup and OI scrub.
3883 * The OI scrub finished just after osd_oi_lookup() failure.
3884 * Under such case, it is unnecessary to trigger OI scrub again,
3885 * but try to call osd_oi_lookup() again. */
3886 if (unlikely(rc == -EAGAIN))
3892 if (!dev->od_noscrub && ++once == 1) {
3893 rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN |
3895 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC "
3896 "for "DFID", rc = %d [2]\n",
3897 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3899 if (rc == 0 || rc == -EALREADY)
3906 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
3907 struct osd_device *dev,
3908 struct osd_idmap_cache *oic,
3909 struct lu_fid *fid, __u32 ino)
3911 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
3912 struct inode *inode;
3915 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3916 inode = osd_iget(oti, dev, &oic->oic_lid);
3917 if (IS_ERR(inode)) {
3918 fid_zero(&oic->oic_fid);
3919 return PTR_ERR(inode);
3922 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, lma);
3925 fid_zero(&oic->oic_fid);
3927 *fid = oic->oic_fid = lma->lma_self_fid;
3931 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
3932 struct osd_inode_id *id, const struct lu_fid *fid)
3934 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
3935 id->oii_ino, id->oii_gen, info);
3936 info->oti_cache.oic_lid = *id;
3937 info->oti_cache.oic_fid = *fid;
3938 info->oti_cache.oic_dev = osd;
3942 * Get parent FID from the linkEA.
3944 * For a directory which parent resides on remote MDT, to satisfy the
3945 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
3946 * the other hand, to make the lookup(..) on the directory can return
3947 * the real parent FID, we append the real parent FID after its ".."
3948 * name entry in the /REMOTE_PARENT_DIR.
3950 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
3951 * backup. So after the restore, we cannot get the right parent FID from
3952 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
3953 * we have stored the real parent FID in the directory object's linkEA,
3954 * we can parse the linkEA for the real parent FID.
3956 * \param[in] env pointer to the thread context
3957 * \param[in] obj pointer to the object to be handled
3958 * \param[out]fid pointer to the buffer to hold the parent FID
3960 * \retval 0 for getting the real parent FID successfully
3961 * \retval negative error number on failure
3963 static int osd_get_pfid_from_linkea(const struct lu_env *env,
3964 struct osd_object *obj,
3967 struct osd_thread_info *oti = osd_oti_get(env);
3968 struct lu_buf *buf = &oti->oti_big_buf;
3969 struct dentry *dentry = &oti->oti_obj_dentry;
3970 struct inode *inode = obj->oo_inode;
3971 struct linkea_data ldata = { NULL };
3976 if (!S_ISDIR(inode->i_mode))
3980 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
3981 buf->lb_buf, buf->lb_len);
3982 if (rc == -ERANGE) {
3983 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
3986 lu_buf_realloc(buf, rc);
3987 if (buf->lb_buf == NULL)
3994 if (unlikely(rc == 0))
4000 if (unlikely(buf->lb_buf == NULL)) {
4001 lu_buf_realloc(buf, rc);
4002 if (buf->lb_buf == NULL)
4009 rc = linkea_init(&ldata);
4011 linkea_first_entry(&ldata);
4012 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
4019 * Calls ->lookup() to find dentry. From dentry get inode and
4020 * read inode's ea to get fid. This is required for interoperability
4023 * \retval 0, on success
4024 * \retval -ve, on error
4026 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
4027 struct dt_rec *rec, const struct dt_key *key)
4029 struct inode *dir = obj->oo_inode;
4030 struct dentry *dentry;
4031 struct ldiskfs_dir_entry_2 *de;
4032 struct buffer_head *bh;
4033 struct lu_fid *fid = (struct lu_fid *) rec;
4034 struct htree_lock *hlock = NULL;
4039 LASSERT(dir->i_op != NULL);
4040 LASSERT(dir->i_op->lookup != NULL);
4042 dentry = osd_child_dentry_get(env, obj,
4043 (char *)key, strlen((char *)key));
4045 if (obj->oo_hl_head != NULL) {
4046 hlock = osd_oti_get(env)->oti_hlock;
4047 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4048 dir, LDISKFS_HLOCK_LOOKUP);
4050 down_read(&obj->oo_ext_idx_sem);
4053 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4055 struct osd_thread_info *oti = osd_oti_get(env);
4056 struct osd_inode_id *id = &oti->oti_id;
4057 struct osd_idmap_cache *oic = &oti->oti_cache;
4058 struct osd_device *dev = osd_obj2dev(obj);
4060 ino = le32_to_cpu(de->inode);
4061 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
4063 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
4067 rc = osd_get_fid_from_dentry(de, rec);
4069 /* done with de, release bh */
4072 if (unlikely(ino == osd_remote_parent_ino(dev))) {
4073 const char *name = (const char *)key;
4075 /* If the parent is on remote MDT, and there
4076 * is no FID-in-dirent, then we have to get
4077 * the parent FID from the linkEA. */
4078 if (likely(strlen(name) == 2 &&
4079 name[0] == '.' && name[1] == '.'))
4080 rc = osd_get_pfid_from_linkea(env, obj,
4083 rc = osd_ea_fid_get(env, obj, ino, fid, id);
4086 osd_id_gen(id, ino, OSD_OII_NOGEN);
4090 fid_zero(&oic->oic_fid);
4094 if (osd_remote_fid(env, dev, fid))
4097 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
4098 osd_consistency_check(oti, dev, oic);
4107 ldiskfs_htree_unlock(hlock);
4109 up_read(&obj->oo_ext_idx_sem);
4114 * Find the osd object for given fid.
4116 * \param fid need to find the osd object having this fid
4118 * \retval osd_object on success
4119 * \retval -ve on error
4121 static struct osd_object *osd_object_find(const struct lu_env *env,
4122 struct dt_object *dt,
4123 const struct lu_fid *fid)
4125 struct lu_device *ludev = dt->do_lu.lo_dev;
4126 struct osd_object *child = NULL;
4127 struct lu_object *luch;
4128 struct lu_object *lo;
4131 * at this point topdev might not exist yet
4132 * (i.e. MGS is preparing profiles). so we can
4133 * not rely on topdev and instead lookup with
4134 * our device passed as topdev. this can't work
4135 * if the object isn't cached yet (as osd doesn't
4136 * allocate lu_header). IOW, the object must be
4137 * in the cache, otherwise lu_object_alloc() crashes
4140 luch = lu_object_find_at(env, ludev->ld_site->ls_top_dev == NULL ?
4141 ludev : ludev->ld_site->ls_top_dev,
4143 if (!IS_ERR(luch)) {
4144 if (lu_object_exists(luch)) {
4145 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
4147 child = osd_obj(lo);
4149 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4150 "lu_object can't be located"
4151 DFID"\n", PFID(fid));
4153 if (child == NULL) {
4154 lu_object_put(env, luch);
4155 CERROR("Unable to get osd_object\n");
4156 child = ERR_PTR(-ENOENT);
4159 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4160 "lu_object does not exists "DFID"\n",
4162 lu_object_put(env, luch);
4163 child = ERR_PTR(-ENOENT);
4166 child = ERR_CAST(luch);
4173 * Put the osd object once done with it.
4175 * \param obj osd object that needs to be put
4177 static inline void osd_object_put(const struct lu_env *env,
4178 struct osd_object *obj)
4180 lu_object_put(env, &obj->oo_dt.do_lu);
4183 static int osd_index_declare_ea_insert(const struct lu_env *env,
4184 struct dt_object *dt,
4185 const struct dt_rec *rec,
4186 const struct dt_key *key,
4187 struct thandle *handle)
4189 struct osd_thandle *oh;
4190 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4191 struct lu_fid *fid = (struct lu_fid *)rec;
4195 LASSERT(!dt_object_remote(dt));
4196 LASSERT(handle != NULL);
4198 oh = container_of0(handle, struct osd_thandle, ot_super);
4199 LASSERT(oh->ot_handle == NULL);
4201 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4202 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4204 if (osd_dt_obj(dt)->oo_inode != NULL) {
4205 struct inode *inode = osd_dt_obj(dt)->oo_inode;
4207 /* We ignore block quota on meta pool (MDTs), so needn't
4208 * calculate how many blocks will be consumed by this index
4210 rc = osd_declare_inode_qid(env, i_uid_read(inode),
4211 i_gid_read(inode), 0, oh,
4212 osd_dt_obj(dt), true, NULL, false);
4218 rc = osd_remote_fid(env, osd, fid);
4224 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
4225 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
4226 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4227 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4228 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4229 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4235 * Index add function for interoperability mode (b11826).
4236 * It will add the directory entry.This entry is needed to
4237 * maintain name->fid mapping.
4239 * \param key it is key i.e. file entry to be inserted
4240 * \param rec it is value of given key i.e. fid
4242 * \retval 0, on success
4243 * \retval -ve, on error
4245 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
4246 const struct dt_rec *rec,
4247 const struct dt_key *key, struct thandle *th,
4250 struct osd_object *obj = osd_dt_obj(dt);
4251 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4252 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4253 const struct lu_fid *fid = rec1->rec_fid;
4254 const char *name = (const char *)key;
4255 struct osd_thread_info *oti = osd_oti_get(env);
4256 struct osd_inode_id *id = &oti->oti_id;
4257 struct inode *child_inode = NULL;
4258 struct osd_object *child = NULL;
4262 if (!dt_object_exists(dt))
4265 LASSERT(osd_invariant(obj));
4266 LASSERT(!dt_object_remote(dt));
4267 LASSERT(th != NULL);
4269 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4271 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
4273 rc = osd_remote_fid(env, osd, fid);
4275 CERROR("%s: Can not find object "DFID" rc %d\n",
4276 osd_name(osd), PFID(fid), rc);
4281 /* Insert remote entry */
4282 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
4283 struct osd_mdobj_map *omm = osd->od_mdt_map;
4284 struct osd_thandle *oh;
4286 /* If parent on remote MDT, we need put this object
4288 oh = container_of(th, typeof(*oh), ot_super);
4289 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4291 CERROR("%s: add "DFID" error: rc = %d\n",
4293 PFID(lu_object_fid(&dt->do_lu)), rc);
4297 child_inode = igrab(omm->omm_remote_parent->d_inode);
4299 child_inode = osd_create_local_agent_inode(env, osd,
4300 obj, fid, rec1->rec_type & S_IFMT, th);
4301 if (IS_ERR(child_inode))
4302 RETURN(PTR_ERR(child_inode));
4305 /* Insert local entry */
4306 child = osd_object_find(env, dt, fid);
4307 if (IS_ERR(child)) {
4308 CERROR("%s: Can not find object "DFID"%u:%u: rc = %d\n",
4309 osd_name(osd), PFID(fid),
4310 id->oii_ino, id->oii_gen,
4311 (int)PTR_ERR(child));
4312 RETURN(PTR_ERR(child));
4314 child_inode = igrab(child->oo_inode);
4317 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
4319 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
4320 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
4324 osd_object_put(env, child);
4325 LASSERT(osd_invariant(obj));
4330 * Initialize osd Iterator for given osd index object.
4332 * \param dt osd index object
4335 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
4336 struct dt_object *dt,
4339 struct osd_it_iam *it;
4340 struct osd_object *obj = osd_dt_obj(dt);
4341 struct lu_object *lo = &dt->do_lu;
4342 struct iam_path_descr *ipd;
4343 struct iam_container *bag = &obj->oo_dir->od_container;
4345 if (!dt_object_exists(dt))
4346 return ERR_PTR(-ENOENT);
4350 return ERR_PTR(-ENOMEM);
4352 ipd = osd_it_ipd_get(env, bag);
4353 if (likely(ipd != NULL)) {
4357 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
4358 return (struct dt_it *)it;
4361 return ERR_PTR(-ENOMEM);
4366 * free given Iterator.
4369 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
4371 struct osd_it_iam *it = (struct osd_it_iam *)di;
4372 struct osd_object *obj = it->oi_obj;
4374 iam_it_fini(&it->oi_it);
4375 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
4376 lu_object_put(env, &obj->oo_dt.do_lu);
4381 * Move Iterator to record specified by \a key
4383 * \param di osd iterator
4384 * \param key key for index
4386 * \retval +ve di points to record with least key not larger than key
4387 * \retval 0 di points to exact matched key
4388 * \retval -ve failure
4391 static int osd_it_iam_get(const struct lu_env *env,
4392 struct dt_it *di, const struct dt_key *key)
4394 struct osd_thread_info *oti = osd_oti_get(env);
4395 struct osd_it_iam *it = (struct osd_it_iam *)di;
4397 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4398 /* swab quota uid/gid */
4399 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4400 key = (struct dt_key *)&oti->oti_quota_id;
4403 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
4409 * \param di osd iterator
4411 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
4413 struct osd_it_iam *it = (struct osd_it_iam *)di;
4415 iam_it_put(&it->oi_it);
4419 * Move iterator by one record
4421 * \param di osd iterator
4423 * \retval +1 end of container reached
4425 * \retval -ve failure
4428 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
4430 struct osd_it_iam *it = (struct osd_it_iam *)di;
4432 return iam_it_next(&it->oi_it);
4436 * Return pointer to the key under iterator.
4439 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
4440 const struct dt_it *di)
4442 struct osd_thread_info *oti = osd_oti_get(env);
4443 struct osd_it_iam *it = (struct osd_it_iam *)di;
4444 struct osd_object *obj = it->oi_obj;
4447 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
4449 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
4450 /* swab quota uid/gid */
4451 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
4452 key = (struct dt_key *)&oti->oti_quota_id;
4459 * Return size of key under iterator (in bytes)
4462 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
4464 struct osd_it_iam *it = (struct osd_it_iam *)di;
4466 return iam_it_key_size(&it->oi_it);
4470 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
4472 /* check if file type is required */
4473 if (ent->lde_attrs & LUDA_TYPE) {
4474 struct luda_type *lt;
4475 int align = sizeof(*lt) - 1;
4477 len = (len + align) & ~align;
4478 lt = (struct luda_type *)(ent->lde_name + len);
4479 lt->lt_type = cpu_to_le16(DTTOIF(type));
4482 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
4486 * build lu direct from backend fs dirent.
4490 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
4491 char *name, __u16 namelen, __u16 type, __u32 attr)
4493 ent->lde_attrs = attr | LUDA_FID;
4494 fid_cpu_to_le(&ent->lde_fid, fid);
4496 ent->lde_hash = cpu_to_le64(offset);
4497 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
4499 strncpy(ent->lde_name, name, namelen);
4500 ent->lde_name[namelen] = '\0';
4501 ent->lde_namelen = cpu_to_le16(namelen);
4503 /* append lustre attributes */
4504 osd_it_append_attrs(ent, namelen, type);
4508 * Return pointer to the record under iterator.
4510 static int osd_it_iam_rec(const struct lu_env *env,
4511 const struct dt_it *di,
4512 struct dt_rec *dtrec, __u32 attr)
4514 struct osd_it_iam *it = (struct osd_it_iam *)di;
4515 struct osd_thread_info *info = osd_oti_get(env);
4518 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
4519 const struct osd_fid_pack *rec;
4520 struct lu_fid *fid = &info->oti_fid;
4521 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4527 name = (char *)iam_it_key_get(&it->oi_it);
4529 RETURN(PTR_ERR(name));
4531 namelen = iam_it_key_size(&it->oi_it);
4533 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
4535 RETURN(PTR_ERR(rec));
4537 rc = osd_fid_unpack(fid, rec);
4541 hash = iam_it_store(&it->oi_it);
4543 /* IAM does not store object type in IAM index (dir) */
4544 osd_it_pack_dirent(lde, fid, hash, name, namelen,
4546 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4547 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4548 (struct iam_rec *)dtrec);
4549 osd_quota_unpack(it->oi_obj, dtrec);
4551 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4552 (struct iam_rec *)dtrec);
4559 * Returns cookie for current Iterator position.
4561 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
4563 struct osd_it_iam *it = (struct osd_it_iam *)di;
4565 return iam_it_store(&it->oi_it);
4569 * Restore iterator from cookie.
4571 * \param di osd iterator
4572 * \param hash Iterator location cookie
4574 * \retval +ve di points to record with least key not larger than key.
4575 * \retval 0 di points to exact matched key
4576 * \retval -ve failure
4579 static int osd_it_iam_load(const struct lu_env *env,
4580 const struct dt_it *di, __u64 hash)
4582 struct osd_it_iam *it = (struct osd_it_iam *)di;
4584 return iam_it_load(&it->oi_it, hash);
4587 static const struct dt_index_operations osd_index_iam_ops = {
4588 .dio_lookup = osd_index_iam_lookup,
4589 .dio_declare_insert = osd_index_declare_iam_insert,
4590 .dio_insert = osd_index_iam_insert,
4591 .dio_declare_delete = osd_index_declare_iam_delete,
4592 .dio_delete = osd_index_iam_delete,
4594 .init = osd_it_iam_init,
4595 .fini = osd_it_iam_fini,
4596 .get = osd_it_iam_get,
4597 .put = osd_it_iam_put,
4598 .next = osd_it_iam_next,
4599 .key = osd_it_iam_key,
4600 .key_size = osd_it_iam_key_size,
4601 .rec = osd_it_iam_rec,
4602 .store = osd_it_iam_store,
4603 .load = osd_it_iam_load
4609 * Creates or initializes iterator context.
4611 * \retval struct osd_it_ea, iterator structure on success
4614 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
4615 struct dt_object *dt,
4618 struct osd_object *obj = osd_dt_obj(dt);
4619 struct osd_thread_info *info = osd_oti_get(env);
4620 struct osd_it_ea *oie;
4622 struct lu_object *lo = &dt->do_lu;
4623 struct dentry *obj_dentry;
4626 if (!dt_object_exists(dt))
4627 RETURN(ERR_PTR(-ENOENT));
4629 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
4631 RETURN(ERR_PTR(-ENOMEM));
4632 obj_dentry = &oie->oie_dentry;
4634 obj_dentry->d_inode = obj->oo_inode;
4635 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
4636 obj_dentry->d_name.hash = 0;
4638 oie->oie_rd_dirent = 0;
4639 oie->oie_it_dirent = 0;
4640 oie->oie_dirent = NULL;
4641 if (unlikely(!info->oti_it_ea_buf_used)) {
4642 oie->oie_buf = info->oti_it_ea_buf;
4643 info->oti_it_ea_buf_used = 1;
4645 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4646 if (oie->oie_buf == NULL)
4647 RETURN(ERR_PTR(-ENOMEM));
4651 file = &oie->oie_file;
4653 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
4654 if (attr & LUDA_64BITHASH)
4655 file->f_mode = FMODE_64BITHASH;
4657 file->f_mode = FMODE_32BITHASH;
4658 file->f_path.dentry = obj_dentry;
4659 file->f_mapping = obj->oo_inode->i_mapping;
4660 file->f_op = obj->oo_inode->i_fop;
4661 set_file_inode(file, obj->oo_inode);
4664 RETURN((struct dt_it *) oie);
4668 * Destroy or finishes iterator context.
4670 * \param di iterator structure to be destroyed
4672 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
4674 struct osd_thread_info *info = osd_oti_get(env);
4675 struct osd_it_ea *oie = (struct osd_it_ea *)di;
4676 struct osd_object *obj = oie->oie_obj;
4677 struct inode *inode = obj->oo_inode;
4680 oie->oie_file.f_op->release(inode, &oie->oie_file);
4681 lu_object_put(env, &obj->oo_dt.do_lu);
4682 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
4683 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4685 info->oti_it_ea_buf_used = 0;
4686 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
4691 * It position the iterator at given key, so that next lookup continues from
4692 * that key Or it is similar to dio_it->load() but based on a key,
4693 * rather than file position.
4695 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4698 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4700 static int osd_it_ea_get(const struct lu_env *env,
4701 struct dt_it *di, const struct dt_key *key)
4703 struct osd_it_ea *it = (struct osd_it_ea *)di;
4706 LASSERT(((const char *)key)[0] == '\0');
4707 it->oie_file.f_pos = 0;
4708 it->oie_rd_dirent = 0;
4709 it->oie_it_dirent = 0;
4710 it->oie_dirent = NULL;
4718 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4722 struct osd_filldir_cbs {
4723 #ifdef HAVE_DIR_CONTEXT
4724 struct dir_context ctx;
4726 struct osd_it_ea *it;
4729 * It is called internally by ->readdir(). It fills the
4730 * iterator's in-memory data structure with required
4731 * information i.e. name, namelen, rec_size etc.
4733 * \param buf in which information to be filled in.
4734 * \param name name of the file in given dir
4736 * \retval 0 on success
4737 * \retval 1 on buffer full
4739 static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen,
4740 loff_t offset, __u64 ino,
4743 struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it;
4744 struct osd_object *obj = it->oie_obj;
4745 struct osd_it_ea_dirent *ent = it->oie_dirent;
4746 struct lu_fid *fid = &ent->oied_fid;
4747 struct osd_fid_pack *rec;
4750 /* this should never happen */
4751 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4752 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4756 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4760 /* "." is just the object itself. */
4761 if (namelen == 1 && name[0] == '.') {
4762 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4763 } else if (d_type & LDISKFS_DIRENT_LUFID) {
4764 rec = (struct osd_fid_pack*) (name + namelen + 1);
4765 if (osd_fid_unpack(fid, rec) != 0)
4770 d_type &= ~LDISKFS_DIRENT_LUFID;
4772 /* NOT export local root. */
4773 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
4774 ino = obj->oo_inode->i_ino;
4775 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4778 ent->oied_ino = ino;
4779 ent->oied_off = offset;
4780 ent->oied_namelen = namelen;
4781 ent->oied_type = d_type;
4783 memcpy(ent->oied_name, name, namelen);
4785 it->oie_rd_dirent++;
4786 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4791 * Calls ->readdir() to load a directory entry at a time
4792 * and stored it in iterator's in-memory data structure.
4794 * \param di iterator's in memory structure
4796 * \retval 0 on success
4797 * \retval -ve on error
4798 * \retval +1 reach the end of entry
4800 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4801 const struct dt_it *di)
4803 struct osd_it_ea *it = (struct osd_it_ea *)di;
4804 struct osd_object *obj = it->oie_obj;
4805 struct inode *inode = obj->oo_inode;
4806 struct htree_lock *hlock = NULL;
4807 struct file *filp = &it->oie_file;
4809 struct osd_filldir_cbs buf = {
4810 #ifdef HAVE_DIR_CONTEXT
4811 .ctx.actor = osd_ldiskfs_filldir,
4817 it->oie_dirent = it->oie_buf;
4818 it->oie_rd_dirent = 0;
4820 if (obj->oo_hl_head != NULL) {
4821 hlock = osd_oti_get(env)->oti_hlock;
4822 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4823 inode, LDISKFS_HLOCK_READDIR);
4825 down_read(&obj->oo_ext_idx_sem);
4828 #ifdef HAVE_DIR_CONTEXT
4829 buf.ctx.pos = filp->f_pos;
4830 rc = inode->i_fop->iterate(filp, &buf.ctx);
4831 filp->f_pos = buf.ctx.pos;
4833 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
4837 ldiskfs_htree_unlock(hlock);
4839 up_read(&obj->oo_ext_idx_sem);
4841 if (it->oie_rd_dirent == 0) {
4842 /*If it does not get any dirent, it means it has been reached
4843 *to the end of the dir */
4844 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
4848 it->oie_dirent = it->oie_buf;
4849 it->oie_it_dirent = 1;
4856 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4857 * to load a directory entry at a time and stored it in
4858 * iterator's in-memory data structure.
4860 * \param di iterator's in memory structure
4862 * \retval +ve iterator reached to end
4863 * \retval 0 iterator not reached to end
4864 * \retval -ve on error
4866 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4868 struct osd_it_ea *it = (struct osd_it_ea *)di;
4873 if (it->oie_it_dirent < it->oie_rd_dirent) {
4875 (void *) it->oie_dirent +
4876 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4877 it->oie_dirent->oied_namelen);
4878 it->oie_it_dirent++;
4881 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4884 rc = osd_ldiskfs_it_fill(env, di);
4891 * Returns the key at current position from iterator's in memory structure.
4893 * \param di iterator's in memory structure
4895 * \retval key i.e. struct dt_key on success
4897 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4898 const struct dt_it *di)
4900 struct osd_it_ea *it = (struct osd_it_ea *)di;
4902 return (struct dt_key *)it->oie_dirent->oied_name;
4906 * Returns the key's size at current position from iterator's in memory structure.
4908 * \param di iterator's in memory structure
4910 * \retval key_size i.e. struct dt_key on success
4912 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4914 struct osd_it_ea *it = (struct osd_it_ea *)di;
4916 return it->oie_dirent->oied_namelen;
4920 osd_dirent_update(handle_t *jh, struct super_block *sb,
4921 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
4922 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de)
4924 struct osd_fid_pack *rec;
4928 LASSERT(de->file_type & LDISKFS_DIRENT_LUFID);
4929 LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack));
4931 rc = ldiskfs_journal_get_write_access(jh, bh);
4935 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
4936 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
4937 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
4943 osd_dirent_has_space(__u16 reclen, __u16 namelen, unsigned blocksize)
4945 if (ldiskfs_rec_len_from_disk(reclen, blocksize) >=
4946 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
4953 osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot)
4955 LASSERTF(dot_dotdot == 1 || dot_dotdot == 2,
4956 "dot_dotdot = %d\n", dot_dotdot);
4958 if (LDISKFS_DIR_REC_LEN(de) >=
4959 __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack)))
4966 osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
4967 struct inode *dir, struct inode *inode,
4968 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
4969 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de,
4970 struct htree_lock *hlock)
4972 struct dentry *dentry;
4973 struct osd_fid_pack *rec;
4974 struct ldiskfs_dentry_param *ldp;
4978 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
4979 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
4982 /* There is enough space to hold the FID-in-dirent. */
4983 if (osd_dirent_has_space(de->rec_len, ent->oied_namelen,
4984 dir->i_sb->s_blocksize)) {
4985 rc = ldiskfs_journal_get_write_access(jh, bh);
4989 de->name[de->name_len] = 0;
4990 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
4991 rec->fp_len = sizeof(struct lu_fid) + 1;
4992 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
4993 de->file_type |= LDISKFS_DIRENT_LUFID;
4995 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
5000 rc = ldiskfs_delete_entry(jh, dir, de, bh);
5004 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
5006 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
5007 osd_get_ldiskfs_dirent_param(ldp, fid);
5008 dentry->d_fsdata = (void *)ldp;
5009 ll_vfs_dq_init(dir);
5010 rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock);
5011 /* It is too bad, we cannot reinsert the name entry back.
5012 * That means we lose it! */
5014 CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
5015 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
5016 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
5017 dir->i_ino, dir->i_generation,
5018 ent->oied_namelen, ent->oied_name, PFID(fid), rc);
5024 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
5025 struct osd_it_ea *it, struct lu_fid *fid,
5026 struct osd_inode_id *id, __u32 *attr)
5028 struct osd_thread_info *info = osd_oti_get(env);
5029 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
5030 struct osd_device *dev = osd_obj2dev(obj);
5031 struct super_block *sb = osd_sb(dev);
5032 const char *devname =
5033 LDISKFS_SB(sb)->s_es->s_volume_name;
5034 struct osd_it_ea_dirent *ent = it->oie_dirent;
5035 struct inode *dir = obj->oo_inode;
5036 struct htree_lock *hlock = NULL;
5037 struct buffer_head *bh = NULL;
5038 handle_t *jh = NULL;
5039 struct ldiskfs_dir_entry_2 *de;
5040 struct dentry *dentry;
5041 struct inode *inode;
5048 if (ent->oied_name[0] == '.') {
5049 if (ent->oied_namelen == 1)
5051 else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
5055 dentry = osd_child_dentry_get(env, obj, ent->oied_name,
5058 /* We need to ensure that the name entry is still valid.
5059 * Because it may be removed or renamed by other already.
5061 * The unlink or rename operation will start journal before PDO lock,
5062 * so to avoid deadlock, here we need to start journal handle before
5063 * related PDO lock also. But because we do not know whether there
5064 * will be something to be repaired before PDO lock, we just start
5065 * journal without conditions.
5067 * We may need to remove the name entry firstly, then insert back.
5068 * One credit is for user quota file update.
5069 * One credit is for group quota file update.
5070 * Two credits are for dirty inode. */
5071 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
5072 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
5075 if (dev->od_dirent_journal != 0) {
5076 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
5079 CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
5080 "check_repair, dir = %lu/%u, credits = %d, "
5081 "name = %.*s: rc = %d\n",
5082 devname, dir->i_ino, dir->i_generation, credits,
5083 ent->oied_namelen, ent->oied_name, rc);
5087 if (obj->oo_hl_head != NULL) {
5088 hlock = osd_oti_get(env)->oti_hlock;
5089 /* "0" means exclusive lock for the whole directory.
5090 * We need to prevent others access such name entry
5091 * during the delete + insert. Neither HLOCK_ADD nor
5092 * HLOCK_DEL cannot guarantee the atomicity. */
5093 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
5095 down_write(&obj->oo_ext_idx_sem);
5098 if (obj->oo_hl_head != NULL) {
5099 hlock = osd_oti_get(env)->oti_hlock;
5100 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
5101 LDISKFS_HLOCK_LOOKUP);
5103 down_read(&obj->oo_ext_idx_sem);
5107 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5108 /* For dot/dotdot entry, if there is not enough space to hold the
5109 * FID-in-dirent, just keep them there. It only happens when the
5110 * device upgraded from 1.8 or restored from MDT file-level backup.
5111 * For the whole directory, only dot/dotdot entry have no FID-in-dirent
5112 * and needs to get FID from LMA when readdir, it will not affect the
5113 * performance much. */
5114 if ((bh == NULL) || (le32_to_cpu(de->inode) != ent->oied_ino) ||
5115 (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
5116 *attr |= LUDA_IGNORE;
5117 GOTO(out_journal, rc = 0);
5120 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
5121 inode = osd_iget(info, dev, id);
5122 if (IS_ERR(inode)) {
5123 rc = PTR_ERR(inode);
5124 if (rc == -ENOENT || rc == -ESTALE)
5127 CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
5128 "check_repair, dir = %lu/%u, name = %.*s: "
5130 devname, dir->i_ino, dir->i_generation,
5131 ent->oied_namelen, ent->oied_name, rc);
5133 GOTO(out_journal, rc);
5136 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
5138 LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI));
5140 if (fid_is_sane(fid)) {
5141 /* FID-in-dirent is valid. */
5142 if (lu_fid_eq(fid, &lma->lma_self_fid))
5143 GOTO(out_inode, rc = 0);
5145 /* Do not repair under dryrun mode. */
5146 if (*attr & LUDA_VERIFY_DRYRUN) {
5147 *attr |= LUDA_REPAIR;
5148 GOTO(out_inode, rc = 0);
5151 if (dev->od_dirent_journal == 0) {
5155 ldiskfs_htree_unlock(hlock);
5157 up_read(&obj->oo_ext_idx_sem);
5158 dev->od_dirent_journal = 1;
5162 *fid = lma->lma_self_fid;
5164 /* Update the FID-in-dirent. */
5165 rc = osd_dirent_update(jh, sb, ent, fid, bh, de);
5167 *attr |= LUDA_REPAIR;
5169 CDEBUG(D_LFSCK, "%.16s: fail to update FID "
5170 "in the dirent, dir = %lu/%u, "
5171 "name = %.*s, "DFID": rc = %d\n",
5172 devname, dir->i_ino, dir->i_generation,
5173 ent->oied_namelen, ent->oied_name,
5176 /* Do not repair under dryrun mode. */
5177 if (*attr & LUDA_VERIFY_DRYRUN) {
5178 *fid = lma->lma_self_fid;
5179 *attr |= LUDA_REPAIR;
5180 GOTO(out_inode, rc = 0);
5183 if (dev->od_dirent_journal == 0) {
5187 ldiskfs_htree_unlock(hlock);
5189 up_read(&obj->oo_ext_idx_sem);
5190 dev->od_dirent_journal = 1;
5194 *fid = lma->lma_self_fid;
5196 /* Append the FID-in-dirent. */
5197 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5198 fid, bh, de, hlock);
5200 *attr |= LUDA_REPAIR;
5202 CDEBUG(D_LFSCK, "%.16s: fail to append FID "
5203 "after the dirent, dir = %lu/%u, "
5204 "name = %.*s, "DFID": rc = %d\n",
5205 devname, dir->i_ino, dir->i_generation,
5206 ent->oied_namelen, ent->oied_name,
5209 } else if (rc == -ENODATA) {
5210 /* Do not repair under dryrun mode. */
5211 if (*attr & LUDA_VERIFY_DRYRUN) {
5212 if (fid_is_sane(fid)) {
5213 *attr |= LUDA_REPAIR;
5215 lu_igif_build(fid, inode->i_ino,
5216 inode->i_generation);
5217 *attr |= LUDA_UPGRADE;
5219 GOTO(out_inode, rc = 0);
5222 if (dev->od_dirent_journal == 0) {
5226 ldiskfs_htree_unlock(hlock);
5228 up_read(&obj->oo_ext_idx_sem);
5229 dev->od_dirent_journal = 1;
5234 if (unlikely(fid_is_sane(fid))) {
5235 /* FID-in-dirent exists, but FID-in-LMA is lost.
5236 * Trust the FID-in-dirent, and add FID-in-LMA. */
5237 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
5239 *attr |= LUDA_REPAIR;
5241 CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
5242 "update dirent, dir = %lu/%u, "
5243 "name = %.*s, "DFID": rc = %d\n",
5244 devname, dir->i_ino, dir->i_generation,
5245 ent->oied_namelen, ent->oied_name,
5248 lu_igif_build(fid, inode->i_ino, inode->i_generation);
5249 /* It is probably IGIF object. Only aappend the
5250 * FID-in-dirent. OI scrub will process FID-in-LMA. */
5251 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5252 fid, bh, de, hlock);
5254 *attr |= LUDA_UPGRADE;
5256 CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
5257 "after the dirent, dir = %lu/%u, "
5258 "name = %.*s, "DFID": rc = %d\n",
5259 devname, dir->i_ino, dir->i_generation,
5260 ent->oied_namelen, ent->oied_name,
5265 GOTO(out_inode, rc);
5272 if (hlock != NULL) {
5273 ldiskfs_htree_unlock(hlock);
5275 if (dev->od_dirent_journal != 0)
5276 up_write(&obj->oo_ext_idx_sem);
5278 up_read(&obj->oo_ext_idx_sem);
5281 ldiskfs_journal_stop(jh);
5282 if (rc >= 0 && !dirty)
5283 dev->od_dirent_journal = 0;
5288 * Returns the value at current position from iterator's in memory structure.
5290 * \param di struct osd_it_ea, iterator's in memory structure
5291 * \param attr attr requested for dirent.
5292 * \param lde lustre dirent
5294 * \retval 0 no error and \param lde has correct lustre dirent.
5295 * \retval -ve on error
5297 static inline int osd_it_ea_rec(const struct lu_env *env,
5298 const struct dt_it *di,
5299 struct dt_rec *dtrec, __u32 attr)
5301 struct osd_it_ea *it = (struct osd_it_ea *)di;
5302 struct osd_object *obj = it->oie_obj;
5303 struct osd_device *dev = osd_obj2dev(obj);
5304 struct osd_thread_info *oti = osd_oti_get(env);
5305 struct osd_inode_id *id = &oti->oti_id;
5306 struct lu_fid *fid = &it->oie_dirent->oied_fid;
5307 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5308 __u32 ino = it->oie_dirent->oied_ino;
5312 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
5314 if (attr & LUDA_VERIFY) {
5315 if (unlikely(ino == osd_remote_parent_ino(dev))) {
5316 attr |= LUDA_IGNORE;
5317 /* If the parent is on remote MDT, and there
5318 * is no FID-in-dirent, then we have to get
5319 * the parent FID from the linkEA. */
5320 if (!fid_is_sane(fid) &&
5321 it->oie_dirent->oied_namelen == 2 &&
5322 it->oie_dirent->oied_name[0] == '.' &&
5323 it->oie_dirent->oied_name[1] == '.')
5324 osd_get_pfid_from_linkea(env, obj, fid);
5326 rc = osd_dirent_check_repair(env, obj, it, fid, id,
5330 attr &= ~LU_DIRENT_ATTRS_MASK;
5331 if (!fid_is_sane(fid)) {
5332 if (it->oie_dirent->oied_namelen == 2 &&
5333 it->oie_dirent->oied_name[0] == '.' &&
5334 it->oie_dirent->oied_name[1] == '.') {
5335 /* If the parent is on remote MDT, and there
5336 * is no FID-in-dirent, then we have to get
5337 * the parent FID from the linkEA. */
5338 if (ino == osd_remote_parent_ino(dev))
5339 rc = osd_get_pfid_from_linkea(env, obj,
5342 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
5345 rc = osd_ea_fid_get(env, obj, ino, fid, id);
5348 osd_id_gen(id, ino, OSD_OII_NOGEN);
5352 /* Pack the entry anyway, at least the offset is right. */
5353 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
5354 it->oie_dirent->oied_name,
5355 it->oie_dirent->oied_namelen,
5356 it->oie_dirent->oied_type, attr);
5361 if (osd_remote_fid(env, dev, fid))
5364 if (likely(!(attr & LUDA_IGNORE) && rc == 0))
5365 osd_add_oi_cache(oti, dev, id, fid);
5367 RETURN(rc > 0 ? 0 : rc);
5371 * Returns the record size size at current position.
5373 * This function will return record(lu_dirent) size in bytes.
5375 * \param[in] env execution environment
5376 * \param[in] di iterator's in memory structure
5377 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
5378 * calculate the lu_dirent size.
5380 * \retval record size(in bytes & in memory) of the current lu_dirent
5383 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
5386 struct osd_it_ea *it = (struct osd_it_ea *)di;
5388 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
5392 * Returns a cookie for current position of the iterator head, so that
5393 * user can use this cookie to load/start the iterator next time.
5395 * \param di iterator's in memory structure
5397 * \retval cookie for current position, on success
5399 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
5401 struct osd_it_ea *it = (struct osd_it_ea *)di;
5403 return it->oie_dirent->oied_off;
5407 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
5408 * to load a directory entry at a time and stored it i inn,
5409 * in iterator's in-memory data structure.
5411 * \param di struct osd_it_ea, iterator's in memory structure
5413 * \retval +ve on success
5414 * \retval -ve on error
5416 static int osd_it_ea_load(const struct lu_env *env,
5417 const struct dt_it *di, __u64 hash)
5419 struct osd_it_ea *it = (struct osd_it_ea *)di;
5423 it->oie_file.f_pos = hash;
5425 rc = osd_ldiskfs_it_fill(env, di);
5436 * Index lookup function for interoperability mode (b11826).
5438 * \param key, key i.e. file name to be searched
5440 * \retval +ve, on success
5441 * \retval -ve, on error
5443 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
5444 struct dt_rec *rec, const struct dt_key *key)
5446 struct osd_object *obj = osd_dt_obj(dt);
5451 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
5452 LINVRNT(osd_invariant(obj));
5454 rc = osd_ea_lookup_rec(env, obj, rec, key);
5461 * Index and Iterator operations for interoperability
5462 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
5464 static const struct dt_index_operations osd_index_ea_ops = {
5465 .dio_lookup = osd_index_ea_lookup,
5466 .dio_declare_insert = osd_index_declare_ea_insert,
5467 .dio_insert = osd_index_ea_insert,
5468 .dio_declare_delete = osd_index_declare_ea_delete,
5469 .dio_delete = osd_index_ea_delete,
5471 .init = osd_it_ea_init,
5472 .fini = osd_it_ea_fini,
5473 .get = osd_it_ea_get,
5474 .put = osd_it_ea_put,
5475 .next = osd_it_ea_next,
5476 .key = osd_it_ea_key,
5477 .key_size = osd_it_ea_key_size,
5478 .rec = osd_it_ea_rec,
5479 .rec_size = osd_it_ea_rec_size,
5480 .store = osd_it_ea_store,
5481 .load = osd_it_ea_load
5485 static void *osd_key_init(const struct lu_context *ctx,
5486 struct lu_context_key *key)
5488 struct osd_thread_info *info;
5490 OBD_ALLOC_PTR(info);
5492 return ERR_PTR(-ENOMEM);
5494 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5495 if (info->oti_it_ea_buf == NULL)
5498 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
5500 info->oti_hlock = ldiskfs_htree_lock_alloc();
5501 if (info->oti_hlock == NULL)
5507 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5510 return ERR_PTR(-ENOMEM);
5513 static void osd_key_fini(const struct lu_context *ctx,
5514 struct lu_context_key *key, void* data)
5516 struct osd_thread_info *info = data;
5518 if (info->oti_inode != NULL)
5519 OBD_FREE_PTR(info->oti_inode);
5520 if (info->oti_hlock != NULL)
5521 ldiskfs_htree_lock_free(info->oti_hlock);
5522 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5523 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
5524 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
5525 lu_buf_free(&info->oti_big_buf);
5529 static void osd_key_exit(const struct lu_context *ctx,
5530 struct lu_context_key *key, void *data)
5532 struct osd_thread_info *info = data;
5534 LASSERT(info->oti_r_locks == 0);
5535 LASSERT(info->oti_w_locks == 0);
5536 LASSERT(info->oti_txns == 0);
5539 /* type constructor/destructor: osd_type_init, osd_type_fini */
5540 LU_TYPE_INIT_FINI(osd, &osd_key);
5542 struct lu_context_key osd_key = {
5543 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
5544 .lct_init = osd_key_init,
5545 .lct_fini = osd_key_fini,
5546 .lct_exit = osd_key_exit
5550 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
5551 const char *name, struct lu_device *next)
5553 struct osd_device *osd = osd_dev(d);
5555 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
5556 >= sizeof(osd->od_svname))
5558 return osd_procfs_init(osd, name);
5561 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
5563 struct seq_server_site *ss = osd_seq_site(osd);
5567 if (osd->od_is_ost || osd->od_cl_seq != NULL)
5570 if (unlikely(ss == NULL))
5573 OBD_ALLOC_PTR(osd->od_cl_seq);
5574 if (osd->od_cl_seq == NULL)
5577 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
5578 osd->od_svname, ss->ss_server_seq);
5580 OBD_FREE_PTR(osd->od_cl_seq);
5581 osd->od_cl_seq = NULL;
5585 if (ss->ss_node_id == 0) {
5586 /* If the OSD on the sequence controller(MDT0), then allocate
5587 * sequence here, otherwise allocate sequence after connected
5588 * to MDT0 (see mdt_register_lwp_callback()). */
5589 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
5590 &osd->od_cl_seq->lcs_space, env);
5596 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
5598 if (osd->od_cl_seq == NULL)
5601 seq_client_fini(osd->od_cl_seq);
5602 OBD_FREE_PTR(osd->od_cl_seq);
5603 osd->od_cl_seq = NULL;
5606 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
5610 /* shutdown quota slave instance associated with the device */
5611 if (o->od_quota_slave != NULL) {
5612 qsd_fini(env, o->od_quota_slave);
5613 o->od_quota_slave = NULL;
5616 osd_fid_fini(env, o);
5621 static void osd_umount(const struct lu_env *env, struct osd_device *o)
5625 if (o->od_mnt != NULL) {
5626 shrink_dcache_sb(osd_sb(o));
5627 osd_sync(env, &o->od_dt_dev);
5636 static int osd_mount(const struct lu_env *env,
5637 struct osd_device *o, struct lustre_cfg *cfg)
5639 const char *name = lustre_cfg_string(cfg, 0);
5640 const char *dev = lustre_cfg_string(cfg, 1);
5642 unsigned long page, s_flags, lmd_flags = 0;
5643 struct page *__page;
5644 struct file_system_type *type;
5645 char *options = NULL;
5647 struct osd_thread_info *info = osd_oti_get(env);
5648 struct lu_fid *fid = &info->oti_fid;
5649 struct inode *inode;
5650 int rc = 0, force_over_128tb = 0;
5653 if (o->od_mnt != NULL)
5656 if (strlen(dev) >= sizeof(o->od_mntdev))
5658 strcpy(o->od_mntdev, dev);
5660 str = lustre_cfg_string(cfg, 2);
5661 s_flags = simple_strtoul(str, NULL, 0);
5662 str = strstr(str, ":");
5664 lmd_flags = simple_strtoul(str + 1, NULL, 0);
5665 opts = lustre_cfg_string(cfg, 3);
5667 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
5668 CERROR("%s: device %s extents feature is not guaranteed to "
5669 "work on big-endian systems. Use \"bigendian_extents\" "
5670 "mount option to override.\n", name, dev);
5674 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
5675 force_over_128tb = 1;
5677 OBD_PAGE_ALLOC(__page, GFP_IOFS);
5679 GOTO(out, rc = -ENOMEM);
5680 page = (unsigned long)page_address(__page);
5681 options = (char *)page;
5684 /* strip out the options for back compatiblity */
5685 static char *sout[] = {
5692 /* strip out option we processed in osd */
5693 "bigendian_extents",
5697 strcat(options, opts);
5698 for (rc = 0, str = options; sout[rc]; ) {
5699 char *op = strstr(str, sout[rc]);
5705 if (op == options || *(op - 1) == ',') {
5706 str = op + strlen(sout[rc]);
5707 if (*str == ',' || *str == '\0') {
5708 *str == ',' ? str++ : str;
5709 memmove(op, str, strlen(str) + 1);
5712 for (str = op; *str != ',' && *str != '\0'; str++)
5716 strncat(options, "user_xattr,acl", 14);
5719 /* Glom up mount options */
5720 if (*options != '\0')
5721 strcat(options, ",");
5722 strlcat(options, "no_mbcache", PAGE_CACHE_SIZE);
5724 type = get_fs_type("ldiskfs");
5726 CERROR("%s: cannot find ldiskfs module\n", name);
5727 GOTO(out, rc = -ENODEV);
5730 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
5731 module_put(type->owner);
5733 if (IS_ERR(o->od_mnt)) {
5734 rc = PTR_ERR(o->od_mnt);
5736 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
5740 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (8ULL << 32) &&
5741 force_over_128tb == 0) {
5742 CERROR("%s: device %s LDISKFS does not support filesystems "
5743 "greater than 128TB and can cause data corruption. "
5744 "Use \"force_over_128tb\" mount option to override.\n",
5746 GOTO(out, rc = -EINVAL);
5749 #ifdef HAVE_DEV_SET_RDONLY
5750 if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
5751 CERROR("%s: underlying device %s is marked as read-only. "
5752 "Setup failed\n", name, dev);
5753 GOTO(out_mnt, rc = -EROFS);
5757 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
5758 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
5759 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
5760 GOTO(out_mnt, rc = -EINVAL);
5763 #ifdef LDISKFS_MOUNT_DIRDATA
5764 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
5765 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5766 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
5767 else if (!o->od_is_ost)
5768 CWARN("%s: device %s was upgraded from Lustre-1.x without "
5769 "enabling the dirdata feature. If you do not want to "
5770 "downgrade to Lustre-1.x again, you can enable it via "
5771 "'tune2fs -O dirdata device'\n", name, dev);
5773 inode = osd_sb(o)->s_root->d_inode;
5774 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
5775 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
5777 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
5781 if (lmd_flags & LMD_FLG_NOSCRUB)
5792 OBD_PAGE_FREE(__page);
5797 static struct lu_device *osd_device_fini(const struct lu_env *env,
5798 struct lu_device *d)
5800 struct osd_device *o = osd_dev(d);
5803 osd_shutdown(env, o);
5805 osd_scrub_cleanup(env, o);
5806 osd_obj_map_fini(o);
5812 static int osd_device_init0(const struct lu_env *env,
5813 struct osd_device *o,
5814 struct lustre_cfg *cfg)
5816 struct lu_device *l = osd2lu_dev(o);
5817 struct osd_thread_info *info;
5821 /* if the module was re-loaded, env can loose its keys */
5822 rc = lu_env_refill((struct lu_env *) env);
5825 info = osd_oti_get(env);
5828 l->ld_ops = &osd_lu_ops;
5829 o->od_dt_dev.dd_ops = &osd_dt_ops;
5831 spin_lock_init(&o->od_osfs_lock);
5832 mutex_init(&o->od_otable_mutex);
5834 o->od_read_cache = 1;
5835 o->od_writethrough_cache = 1;
5836 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
5838 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
5839 sizeof(o->od_svname));
5840 if (cplen >= sizeof(o->od_svname)) {
5845 if (server_name_is_ost(o->od_svname))
5848 o->od_full_scrub_ratio = OFSR_DEFAULT;
5849 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
5850 rc = osd_mount(env, o, cfg);
5854 rc = osd_obj_map_init(env, o);
5858 rc = lu_site_init(&o->od_site, l);
5860 GOTO(out_compat, rc);
5861 o->od_site.ls_bottom_dev = l;
5863 rc = lu_site_init_finish(&o->od_site);
5867 INIT_LIST_HEAD(&o->od_ios_list);
5868 /* setup scrub, including OI files initialization */
5869 rc = osd_scrub_setup(env, o);
5873 rc = osd_procfs_init(o, o->od_svname);
5875 CERROR("%s: can't initialize procfs: rc = %d\n",
5877 GOTO(out_scrub, rc);
5880 LASSERT(l->ld_site->ls_linkage.next != NULL);
5881 LASSERT(l->ld_site->ls_linkage.prev != NULL);
5883 /* initialize quota slave instance */
5884 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
5886 if (IS_ERR(o->od_quota_slave)) {
5887 rc = PTR_ERR(o->od_quota_slave);
5888 o->od_quota_slave = NULL;
5889 GOTO(out_procfs, rc);
5897 osd_scrub_cleanup(env, o);
5899 lu_site_fini(&o->od_site);
5901 osd_obj_map_fini(o);
5908 static struct lu_device *osd_device_alloc(const struct lu_env *env,
5909 struct lu_device_type *t,
5910 struct lustre_cfg *cfg)
5912 struct osd_device *o;
5917 return ERR_PTR(-ENOMEM);
5919 rc = dt_device_init(&o->od_dt_dev, t);
5921 /* Because the ctx might be revived in dt_device_init,
5922 * refill the env here */
5923 lu_env_refill((struct lu_env *)env);
5924 rc = osd_device_init0(env, o, cfg);
5926 dt_device_fini(&o->od_dt_dev);
5929 if (unlikely(rc != 0))
5932 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
5935 static struct lu_device *osd_device_free(const struct lu_env *env,
5936 struct lu_device *d)
5938 struct osd_device *o = osd_dev(d);
5941 /* XXX: make osd top device in order to release reference */
5942 d->ld_site->ls_top_dev = d;
5943 lu_site_purge(env, d->ld_site, -1);
5944 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
5945 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
5946 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
5948 lu_site_fini(&o->od_site);
5949 dt_device_fini(&o->od_dt_dev);
5954 static int osd_process_config(const struct lu_env *env,
5955 struct lu_device *d, struct lustre_cfg *cfg)
5957 struct osd_device *o = osd_dev(d);
5961 switch (cfg->lcfg_command) {
5963 rc = osd_mount(env, o, cfg);
5966 lu_dev_del_linkage(d->ld_site, d);
5967 rc = osd_shutdown(env, o);
5970 LASSERT(&o->od_dt_dev);
5971 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
5972 cfg, &o->od_dt_dev);
5973 if (rc > 0 || rc == -ENOSYS)
5974 rc = class_process_proc_param(PARAM_OST,
5975 lprocfs_osd_obd_vars,
5976 cfg, &o->od_dt_dev);
5985 static int osd_recovery_complete(const struct lu_env *env,
5986 struct lu_device *d)
5988 struct osd_device *osd = osd_dev(d);
5992 if (osd->od_quota_slave == NULL)
5995 /* start qsd instance on recovery completion, this notifies the quota
5996 * slave code that we are about to process new requests now */
5997 rc = qsd_start(env, osd->od_quota_slave);
6002 * we use exports to track all osd users
6004 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
6005 struct obd_device *obd, struct obd_uuid *cluuid,
6006 struct obd_connect_data *data, void *localdata)
6008 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6009 struct lustre_handle conn;
6013 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
6015 rc = class_connect(&conn, obd, cluuid);
6019 *exp = class_conn2export(&conn);
6021 spin_lock(&osd->od_osfs_lock);
6023 spin_unlock(&osd->od_osfs_lock);
6029 * once last export (we don't count self-export) disappeared
6030 * osd can be released
6032 static int osd_obd_disconnect(struct obd_export *exp)
6034 struct obd_device *obd = exp->exp_obd;
6035 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6036 int rc, release = 0;
6039 /* Only disconnect the underlying layers on the final disconnect. */
6040 spin_lock(&osd->od_osfs_lock);
6042 if (osd->od_connects == 0)
6044 spin_unlock(&osd->od_osfs_lock);
6046 rc = class_disconnect(exp); /* bz 9811 */
6048 if (rc == 0 && release)
6049 class_manual_cleanup(obd);
6053 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
6054 struct lu_device *dev)
6056 struct osd_device *osd = osd_dev(dev);
6057 struct lr_server_data *lsd =
6058 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
6062 if (osd->od_quota_slave != NULL) {
6063 /* set up quota slave objects */
6064 result = qsd_prepare(env, osd->od_quota_slave);
6069 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
6070 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
6071 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
6072 osd->od_index_in_idif = 1;
6074 osd->od_index_in_idif = 0;
6075 result = osd_register_proc_index_in_idif(osd);
6080 osd->od_index_in_idif = 1;
6084 result = osd_fid_init(env, osd);
6089 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
6090 struct lu_fid *fid, struct md_op_data *op_data)
6092 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
6094 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
6097 static const struct lu_object_operations osd_lu_obj_ops = {
6098 .loo_object_init = osd_object_init,
6099 .loo_object_delete = osd_object_delete,
6100 .loo_object_release = osd_object_release,
6101 .loo_object_free = osd_object_free,
6102 .loo_object_print = osd_object_print,
6103 .loo_object_invariant = osd_object_invariant
6106 const struct lu_device_operations osd_lu_ops = {
6107 .ldo_object_alloc = osd_object_alloc,
6108 .ldo_process_config = osd_process_config,
6109 .ldo_recovery_complete = osd_recovery_complete,
6110 .ldo_prepare = osd_prepare,
6113 static const struct lu_device_type_operations osd_device_type_ops = {
6114 .ldto_init = osd_type_init,
6115 .ldto_fini = osd_type_fini,
6117 .ldto_start = osd_type_start,
6118 .ldto_stop = osd_type_stop,
6120 .ldto_device_alloc = osd_device_alloc,
6121 .ldto_device_free = osd_device_free,
6123 .ldto_device_init = osd_device_init,
6124 .ldto_device_fini = osd_device_fini
6127 static struct lu_device_type osd_device_type = {
6128 .ldt_tags = LU_DEVICE_DT,
6129 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
6130 .ldt_ops = &osd_device_type_ops,
6131 .ldt_ctx_tags = LCT_LOCAL,
6134 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
6136 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6137 struct super_block *sb = osd_sb(osd);
6139 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
6143 * lprocfs legacy support.
6145 static struct obd_ops osd_obd_device_ops = {
6146 .o_owner = THIS_MODULE,
6147 .o_connect = osd_obd_connect,
6148 .o_disconnect = osd_obd_disconnect,
6149 .o_fid_alloc = osd_fid_alloc,
6150 .o_health_check = osd_health_check,
6153 static int __init osd_mod_init(void)
6157 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
6158 /* please, try to keep osd_thread_info smaller than a page */
6159 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
6164 rc = lu_kmem_init(ldiskfs_caches);
6168 rc = class_register_type(&osd_obd_device_ops, NULL, true,
6169 lprocfs_osd_module_vars,
6170 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
6172 lu_kmem_fini(ldiskfs_caches);
6176 static void __exit osd_mod_exit(void)
6178 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
6179 lu_kmem_fini(ldiskfs_caches);
6182 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6183 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
6184 MODULE_VERSION(LUSTRE_VERSION_STRING);
6185 MODULE_LICENSE("GPL");
6187 module_init(osd_mod_init);
6188 module_exit(osd_mod_exit);