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_dcb_list, dcb_linkage) {
835 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
836 "commit callback entry: magic=%x name='%s'\n",
837 dcb->dcb_magic, dcb->dcb_name);
838 list_del_init(&dcb->dcb_linkage);
839 dcb->dcb_func(NULL, th, dcb, error);
842 lu_ref_del_at(&lud->ld_reference, &oh->ot_dev_link, "osd-tx", th);
846 lu_context_exit(&th->th_ctx);
847 lu_context_fini(&th->th_ctx);
851 static struct thandle *osd_trans_create(const struct lu_env *env,
854 struct osd_thread_info *oti = osd_oti_get(env);
855 struct osd_iobuf *iobuf = &oti->oti_iobuf;
856 struct osd_thandle *oh;
860 /* on pending IO in this thread should left from prev. request */
861 LASSERT(atomic_read(&iobuf->dr_numreqs) == 0);
863 th = ERR_PTR(-ENOMEM);
864 OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS);
866 oh->ot_quota_trans = &oti->oti_quota_trans;
867 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
871 th->th_tags = LCT_TX_HANDLE;
873 INIT_LIST_HEAD(&oh->ot_dcb_list);
876 memset(oti->oti_declare_ops, 0,
877 sizeof(oti->oti_declare_ops));
878 memset(oti->oti_declare_ops_rb, 0,
879 sizeof(oti->oti_declare_ops_rb));
880 memset(oti->oti_declare_ops_cred, 0,
881 sizeof(oti->oti_declare_ops_cred));
882 oti->oti_rollback = false;
888 * Concurrency: shouldn't matter.
890 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
893 struct osd_thread_info *oti = osd_oti_get(env);
894 struct osd_device *dev = osd_dt_dev(d);
896 struct osd_thandle *oh;
901 LASSERT(current->journal_info == NULL);
903 oh = container_of0(th, struct osd_thandle, ot_super);
905 LASSERT(oh->ot_handle == NULL);
907 rc = dt_txn_hook_start(env, d, th);
911 if (unlikely(osd_param_is_not_sane(dev, th))) {
912 static unsigned long last_printed;
913 static int last_credits;
915 CWARN("%.16s: too many transaction credits (%d > %d)\n",
916 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
918 osd_journal(dev)->j_max_transaction_buffers);
919 CWARN(" create: %u/%u, destroy: %u/%u\n",
920 oti->oti_declare_ops[OSD_OT_CREATE],
921 oti->oti_declare_ops_cred[OSD_OT_CREATE],
922 oti->oti_declare_ops[OSD_OT_DESTROY],
923 oti->oti_declare_ops_cred[OSD_OT_DESTROY]);
924 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
925 oti->oti_declare_ops[OSD_OT_ATTR_SET],
926 oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
927 oti->oti_declare_ops[OSD_OT_XATTR_SET],
928 oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]);
929 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
930 oti->oti_declare_ops[OSD_OT_WRITE],
931 oti->oti_declare_ops_cred[OSD_OT_WRITE],
932 oti->oti_declare_ops[OSD_OT_PUNCH],
933 oti->oti_declare_ops_cred[OSD_OT_PUNCH],
934 oti->oti_declare_ops[OSD_OT_QUOTA],
935 oti->oti_declare_ops_cred[OSD_OT_QUOTA]);
936 CWARN(" insert: %u/%u, delete: %u/%u\n",
937 oti->oti_declare_ops[OSD_OT_INSERT],
938 oti->oti_declare_ops_cred[OSD_OT_INSERT],
939 oti->oti_declare_ops[OSD_OT_DELETE],
940 oti->oti_declare_ops_cred[OSD_OT_DELETE]);
941 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
942 oti->oti_declare_ops[OSD_OT_REF_ADD],
943 oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
944 oti->oti_declare_ops[OSD_OT_REF_DEL],
945 oti->oti_declare_ops_cred[OSD_OT_REF_DEL]);
947 if (last_credits != oh->ot_credits &&
948 time_after(jiffies, last_printed +
949 msecs_to_jiffies(60 * MSEC_PER_SEC))) {
950 libcfs_debug_dumpstack(NULL);
951 last_credits = oh->ot_credits;
952 last_printed = jiffies;
954 /* XXX Limit the credits to 'max_transaction_buffers', and
955 * let the underlying filesystem to catch the error if
956 * we really need so many credits.
958 * This should be removed when we can calculate the
959 * credits precisely. */
960 oh->ot_credits = osd_transaction_size(dev);
964 * XXX temporary stuff. Some abstraction layer should
967 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, oh->ot_credits);
971 LASSERT(oti->oti_txns == 0);
972 lu_context_init(&th->th_ctx, th->th_tags);
973 lu_context_enter(&th->th_ctx);
975 lu_device_get(&d->dd_lu_dev);
976 lu_ref_add_at(&d->dd_lu_dev.ld_reference, &oh->ot_dev_link,
987 static int osd_seq_exists(const struct lu_env *env,
988 struct osd_device *osd, u64 seq)
990 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
991 struct seq_server_site *ss = osd_seq_site(osd);
996 LASSERT(ss->ss_server_fld != NULL);
998 rc = osd_fld_lookup(env, osd, seq, range);
1001 CERROR("%s: can't lookup FLD sequence "LPX64
1002 ": rc = %d\n", osd_name(osd), seq, rc);
1006 RETURN(ss->ss_node_id == range->lsr_index);
1010 * Concurrency: shouldn't matter.
1012 static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
1016 struct osd_thandle *oh;
1017 struct osd_thread_info *oti = osd_oti_get(env);
1018 struct osd_iobuf *iobuf = &oti->oti_iobuf;
1019 struct osd_device *osd = osd_dt_dev(th->th_dev);
1020 struct qsd_instance *qsd = osd->od_quota_slave;
1021 struct lquota_trans *qtrans;
1024 oh = container_of0(th, struct osd_thandle, ot_super);
1026 qtrans = oh->ot_quota_trans;
1027 oh->ot_quota_trans = NULL;
1029 if (oh->ot_handle != NULL) {
1030 handle_t *hdl = oh->ot_handle;
1033 * add commit callback
1034 * notice we don't do this in osd_trans_start()
1035 * as underlying transaction can change during truncate
1037 ldiskfs_journal_callback_add(hdl, osd_trans_commit_cb,
1040 LASSERT(oti->oti_txns == 1);
1043 rc = dt_txn_hook_stop(env, th);
1045 CERROR("%s: failed in transaction hook: rc = %d\n",
1048 /* hook functions might modify th_sync */
1049 hdl->h_sync = th->th_sync;
1051 oh->ot_handle = NULL;
1052 OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl));
1054 CERROR("%s: failed to stop transaction: rc = %d\n",
1060 /* inform the quota slave device that the transaction is stopping */
1061 qsd_op_end(env, qsd, qtrans);
1063 /* as we want IO to journal and data IO be concurrent, we don't block
1064 * awaiting data IO completion in osd_do_bio(), instead we wait here
1065 * once transaction is submitted to the journal. all reqular requests
1066 * don't do direct IO (except read/write), thus this wait_event becomes
1069 * IMPORTANT: we have to wait till any IO submited by the thread is
1070 * completed otherwise iobuf may be corrupted by different request
1072 wait_event(iobuf->dr_wait,
1073 atomic_read(&iobuf->dr_numreqs) == 0);
1074 osd_fini_iobuf(osd, iobuf);
1076 rc = iobuf->dr_error;
1081 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
1083 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
1086 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
1087 LASSERT(&dcb->dcb_func != NULL);
1088 list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
1094 * Called just before object is freed. Releases all resources except for
1095 * object itself (that is released by osd_object_free()).
1097 * Concurrency: no concurrent access is possible that late in object
1100 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
1102 struct osd_object *obj = osd_obj(l);
1103 struct inode *inode = obj->oo_inode;
1105 LINVRNT(osd_invariant(obj));
1108 * If object is unlinked remove fid->ino mapping from object index.
1111 osd_index_fini(obj);
1112 if (inode != NULL) {
1113 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
1114 qid_t uid = i_uid_read(inode);
1115 qid_t gid = i_gid_read(inode);
1118 obj->oo_inode = NULL;
1121 struct osd_thread_info *info = osd_oti_get(env);
1122 struct lquota_id_info *qi = &info->oti_qi;
1124 /* Release granted quota to master if necessary */
1125 qi->lqi_id.qid_uid = uid;
1126 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
1128 qi->lqi_id.qid_uid = gid;
1129 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
1135 * Concurrency: ->loo_object_release() is called under site spin-lock.
1137 static void osd_object_release(const struct lu_env *env,
1138 struct lu_object *l)
1143 * Concurrency: shouldn't matter.
1145 static int osd_object_print(const struct lu_env *env, void *cookie,
1146 lu_printer_t p, const struct lu_object *l)
1148 struct osd_object *o = osd_obj(l);
1149 struct iam_descr *d;
1151 if (o->oo_dir != NULL)
1152 d = o->oo_dir->od_container.ic_descr;
1155 return (*p)(env, cookie,
1156 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
1158 o->oo_inode ? o->oo_inode->i_ino : 0UL,
1159 o->oo_inode ? o->oo_inode->i_generation : 0,
1160 d ? d->id_ops->id_name : "plain");
1163 #define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */
1166 * Concurrency: shouldn't matter.
1168 int osd_statfs(const struct lu_env *env, struct dt_device *d,
1169 struct obd_statfs *sfs)
1171 struct osd_device *osd = osd_dt_dev(d);
1172 struct super_block *sb = osd_sb(osd);
1173 struct kstatfs *ksfs;
1176 if (unlikely(osd->od_mnt == NULL))
1177 return -EINPROGRESS;
1179 /* osd_lproc.c call this without env, allocate ksfs for that case */
1180 if (unlikely(env == NULL)) {
1181 OBD_ALLOC_PTR(ksfs);
1185 ksfs = &osd_oti_get(env)->oti_ksfs;
1188 spin_lock(&osd->od_osfs_lock);
1189 result = sb->s_op->statfs(sb->s_root, ksfs);
1190 if (likely(result == 0)) { /* N.B. statfs can't really fail */
1191 statfs_pack(sfs, ksfs);
1192 if (sb->s_flags & MS_RDONLY)
1193 sfs->os_state = OS_STATE_READONLY;
1196 spin_unlock(&osd->od_osfs_lock);
1198 if (unlikely(env == NULL))
1201 /* Reserve a small amount of space for local objects like last_rcvd,
1202 * llog, quota files, ... */
1203 if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) {
1206 sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS;
1207 /** Take out metadata overhead for indirect blocks */
1208 sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3);
1215 * Estimate space needed for file creations. We assume the largest filename
1216 * which is 2^64 - 1, hence a filename of 20 chars.
1217 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
1219 #ifdef __LDISKFS_DIR_REC_LEN
1220 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
1222 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
1226 * Concurrency: doesn't access mutable data.
1228 static void osd_conf_get(const struct lu_env *env,
1229 const struct dt_device *dev,
1230 struct dt_device_param *param)
1232 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1236 * XXX should be taken from not-yet-existing fs abstraction layer.
1238 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1239 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1240 param->ddp_block_shift = sb->s_blocksize_bits;
1241 param->ddp_mount_type = LDD_MT_LDISKFS;
1242 param->ddp_maxbytes = sb->s_maxbytes;
1243 /* Overhead estimate should be fairly accurate, so we really take a tiny
1244 * error margin which also avoids fragmenting the filesystem too much */
1245 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
1246 /* inode are statically allocated, so per-inode space consumption
1247 * is the space consumed by the directory entry */
1248 param->ddp_inodespace = PER_OBJ_USAGE;
1249 /* per-fragment overhead to be used by the client code */
1250 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
1251 param->ddp_mntopts = 0;
1252 if (test_opt(sb, XATTR_USER))
1253 param->ddp_mntopts |= MNTOPT_USERXATTR;
1254 if (test_opt(sb, POSIX_ACL))
1255 param->ddp_mntopts |= MNTOPT_ACL;
1257 /* LOD might calculate the max stripe count based on max_ea_size,
1258 * so we need take account in the overhead as well,
1259 * xattr_header + magic + xattr_entry_head */
1260 ea_overhead = sizeof(struct ldiskfs_xattr_header) + sizeof(__u32) +
1261 LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN);
1263 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1264 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1265 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE -
1269 param->ddp_max_ea_size = sb->s_blocksize - ea_overhead;
1273 * Concurrency: shouldn't matter.
1275 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1279 CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1281 rc = ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1283 CDEBUG(D_CACHE, "synced OSD %s: rc = %d\n",
1284 LUSTRE_OSD_LDISKFS_NAME, rc);
1290 * Start commit for OSD device.
1292 * An implementation of dt_commit_async method for OSD device.
1293 * Asychronously starts underlayng fs sync and thereby a transaction
1296 * \param env environment
1297 * \param d dt device
1299 * \see dt_device_operations
1301 static int osd_commit_async(const struct lu_env *env,
1302 struct dt_device *d)
1304 struct super_block *s = osd_sb(osd_dt_dev(d));
1307 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1308 RETURN(s->s_op->sync_fs(s, 0));
1312 * Concurrency: shouldn't matter.
1315 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1317 struct super_block *sb = osd_sb(osd_dt_dev(d));
1318 struct block_device *dev = sb->s_bdev;
1319 #ifdef HAVE_DEV_SET_RDONLY
1320 struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
1323 int rc = -EOPNOTSUPP;
1327 #ifdef HAVE_DEV_SET_RDONLY
1328 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1330 if (jdev && (jdev != dev)) {
1331 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
1333 dev_set_rdonly(jdev);
1335 CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
1336 dev_set_rdonly(dev);
1338 CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
1339 osd_dt_dev(d)->od_svname, (long)dev, rc);
1345 * Note: we do not count into QUOTA here.
1346 * If we mount with --data_journal we may need more.
1348 const int osd_dto_credits_noquota[DTO_NR] = {
1351 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1352 * SINGLEDATA_TRANS_BLOCKS(8)
1353 * XXX Note: maybe iam need more, since iam have more level than
1356 [DTO_INDEX_INSERT] = 16,
1359 * just modify a single entry, probably merge few within a block
1361 [DTO_INDEX_DELETE] = 1,
1365 [DTO_INDEX_UPDATE] = 16,
1367 * 4(inode, inode bits, groups, GDT)
1368 * notice: OI updates are counted separately with DTO_INDEX_INSERT
1370 [DTO_OBJECT_CREATE] = 4,
1372 * 4(inode, inode bits, groups, GDT)
1373 * notice: OI updates are counted separately with DTO_INDEX_DELETE
1375 [DTO_OBJECT_DELETE] = 4,
1377 * Attr set credits (inode)
1379 [DTO_ATTR_SET_BASE] = 1,
1381 * Xattr set. The same as xattr of EXT3.
1382 * DATA_TRANS_BLOCKS(14)
1383 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1384 * are also counted in. Do not know why?
1386 [DTO_XATTR_SET] = 14,
1388 * credits for inode change during write.
1390 [DTO_WRITE_BASE] = 3,
1392 * credits for single block write.
1394 [DTO_WRITE_BLOCK] = 14,
1396 * Attr set credits for chown.
1397 * This is extra credits for setattr, and it is null without quota
1399 [DTO_ATTR_SET_CHOWN] = 0
1402 static const struct dt_device_operations osd_dt_ops = {
1403 .dt_root_get = osd_root_get,
1404 .dt_statfs = osd_statfs,
1405 .dt_trans_create = osd_trans_create,
1406 .dt_trans_start = osd_trans_start,
1407 .dt_trans_stop = osd_trans_stop,
1408 .dt_trans_cb_add = osd_trans_cb_add,
1409 .dt_conf_get = osd_conf_get,
1410 .dt_sync = osd_sync,
1412 .dt_commit_async = osd_commit_async,
1415 static void osd_object_read_lock(const struct lu_env *env,
1416 struct dt_object *dt, unsigned role)
1418 struct osd_object *obj = osd_dt_obj(dt);
1419 struct osd_thread_info *oti = osd_oti_get(env);
1421 LINVRNT(osd_invariant(obj));
1423 LASSERT(obj->oo_owner != env);
1424 down_read_nested(&obj->oo_sem, role);
1426 LASSERT(obj->oo_owner == NULL);
1430 static void osd_object_write_lock(const struct lu_env *env,
1431 struct dt_object *dt, unsigned role)
1433 struct osd_object *obj = osd_dt_obj(dt);
1434 struct osd_thread_info *oti = osd_oti_get(env);
1436 LINVRNT(osd_invariant(obj));
1438 LASSERT(obj->oo_owner != env);
1439 down_write_nested(&obj->oo_sem, role);
1441 LASSERT(obj->oo_owner == NULL);
1442 obj->oo_owner = env;
1446 static void osd_object_read_unlock(const struct lu_env *env,
1447 struct dt_object *dt)
1449 struct osd_object *obj = osd_dt_obj(dt);
1450 struct osd_thread_info *oti = osd_oti_get(env);
1452 LINVRNT(osd_invariant(obj));
1454 LASSERT(oti->oti_r_locks > 0);
1456 up_read(&obj->oo_sem);
1459 static void osd_object_write_unlock(const struct lu_env *env,
1460 struct dt_object *dt)
1462 struct osd_object *obj = osd_dt_obj(dt);
1463 struct osd_thread_info *oti = osd_oti_get(env);
1465 LINVRNT(osd_invariant(obj));
1467 LASSERT(obj->oo_owner == env);
1468 LASSERT(oti->oti_w_locks > 0);
1470 obj->oo_owner = NULL;
1471 up_write(&obj->oo_sem);
1474 static int osd_object_write_locked(const struct lu_env *env,
1475 struct dt_object *dt)
1477 struct osd_object *obj = osd_dt_obj(dt);
1479 LINVRNT(osd_invariant(obj));
1481 return obj->oo_owner == env;
1484 static struct timespec *osd_inode_time(const struct lu_env *env,
1485 struct inode *inode, __u64 seconds)
1487 struct osd_thread_info *oti = osd_oti_get(env);
1488 struct timespec *t = &oti->oti_time;
1490 t->tv_sec = seconds;
1492 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1497 static void osd_inode_getattr(const struct lu_env *env,
1498 struct inode *inode, struct lu_attr *attr)
1500 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1501 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1502 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
1505 attr->la_atime = LTIME_S(inode->i_atime);
1506 attr->la_mtime = LTIME_S(inode->i_mtime);
1507 attr->la_ctime = LTIME_S(inode->i_ctime);
1508 attr->la_mode = inode->i_mode;
1509 attr->la_size = i_size_read(inode);
1510 attr->la_blocks = inode->i_blocks;
1511 attr->la_uid = i_uid_read(inode);
1512 attr->la_gid = i_gid_read(inode);
1513 attr->la_flags = LDISKFS_I(inode)->i_flags;
1514 attr->la_nlink = inode->i_nlink;
1515 attr->la_rdev = inode->i_rdev;
1516 attr->la_blksize = 1 << inode->i_blkbits;
1517 attr->la_blkbits = inode->i_blkbits;
1520 static int osd_attr_get(const struct lu_env *env,
1521 struct dt_object *dt,
1522 struct lu_attr *attr)
1524 struct osd_object *obj = osd_dt_obj(dt);
1526 if (!dt_object_exists(dt))
1529 LASSERT(!dt_object_remote(dt));
1530 LINVRNT(osd_invariant(obj));
1532 spin_lock(&obj->oo_guard);
1533 osd_inode_getattr(env, obj->oo_inode, attr);
1534 spin_unlock(&obj->oo_guard);
1538 static int osd_declare_attr_set(const struct lu_env *env,
1539 struct dt_object *dt,
1540 const struct lu_attr *attr,
1541 struct thandle *handle)
1543 struct osd_thandle *oh;
1544 struct osd_object *obj;
1545 struct osd_thread_info *info = osd_oti_get(env);
1546 struct lquota_id_info *qi = &info->oti_qi;
1554 LASSERT(dt != NULL);
1555 LASSERT(handle != NULL);
1557 obj = osd_dt_obj(dt);
1558 LASSERT(osd_invariant(obj));
1560 oh = container_of0(handle, struct osd_thandle, ot_super);
1561 LASSERT(oh->ot_handle == NULL);
1563 osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET,
1564 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1566 if (attr == NULL || obj->oo_inode == NULL)
1569 bspace = obj->oo_inode->i_blocks;
1570 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1571 bspace = toqb(bspace);
1573 /* Changing ownership is always preformed by super user, it should not
1576 * We still need to call the osd_declare_qid() to calculate the journal
1577 * credits for updating quota accounting files and to trigger quota
1578 * space adjustment once the operation is completed.*/
1579 if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
1581 uid = i_uid_read(obj->oo_inode);
1582 qi->lqi_type = USRQUOTA;
1583 enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
1584 /* inode accounting */
1585 qi->lqi_is_blk = false;
1587 /* one more inode for the new uid ... */
1588 qi->lqi_id.qid_uid = attr->la_uid;
1590 /* Reserve credits for the new uid */
1591 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1592 if (rc == -EDQUOT || rc == -EINPROGRESS)
1597 /* and one less inode for the current uid */
1598 qi->lqi_id.qid_uid = uid;
1600 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1601 if (rc == -EDQUOT || rc == -EINPROGRESS)
1606 /* block accounting */
1607 qi->lqi_is_blk = true;
1609 /* more blocks for the new uid ... */
1610 qi->lqi_id.qid_uid = attr->la_uid;
1611 qi->lqi_space = bspace;
1613 * Credits for the new uid has been reserved, re-use "obj"
1614 * to save credit reservation.
1616 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1617 if (rc == -EDQUOT || rc == -EINPROGRESS)
1622 /* and finally less blocks for the current uid */
1623 qi->lqi_id.qid_uid = uid;
1624 qi->lqi_space = -bspace;
1625 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1626 if (rc == -EDQUOT || rc == -EINPROGRESS)
1632 gid = i_gid_read(obj->oo_inode);
1633 qi->lqi_type = GRPQUOTA;
1634 enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
1636 /* inode accounting */
1637 qi->lqi_is_blk = false;
1639 /* one more inode for the new gid ... */
1640 qi->lqi_id.qid_gid = attr->la_gid;
1642 rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
1643 if (rc == -EDQUOT || rc == -EINPROGRESS)
1648 /* and one less inode for the current gid */
1649 qi->lqi_id.qid_gid = gid;
1651 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1652 if (rc == -EDQUOT || rc == -EINPROGRESS)
1657 /* block accounting */
1658 qi->lqi_is_blk = true;
1660 /* more blocks for the new gid ... */
1661 qi->lqi_id.qid_gid = attr->la_gid;
1662 qi->lqi_space = bspace;
1663 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1664 if (rc == -EDQUOT || rc == -EINPROGRESS)
1669 /* and finally less blocks for the current gid */
1670 qi->lqi_id.qid_gid = gid;
1671 qi->lqi_space = -bspace;
1672 rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
1673 if (rc == -EDQUOT || rc == -EINPROGRESS)
1682 static int osd_inode_setattr(const struct lu_env *env,
1683 struct inode *inode, const struct lu_attr *attr)
1685 __u64 bits = attr->la_valid;
1687 /* Only allow set size for regular file */
1688 if (!S_ISREG(inode->i_mode))
1689 bits &= ~(LA_SIZE | LA_BLOCKS);
1694 if (bits & LA_ATIME)
1695 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1696 if (bits & LA_CTIME)
1697 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1698 if (bits & LA_MTIME)
1699 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1700 if (bits & LA_SIZE) {
1701 LDISKFS_I(inode)->i_disksize = attr->la_size;
1702 i_size_write(inode, attr->la_size);
1706 /* OSD should not change "i_blocks" which is used by quota.
1707 * "i_blocks" should be changed by ldiskfs only. */
1708 if (bits & LA_BLOCKS)
1709 inode->i_blocks = attr->la_blocks;
1712 inode->i_mode = (inode->i_mode & S_IFMT) |
1713 (attr->la_mode & ~S_IFMT);
1715 i_uid_write(inode, attr->la_uid);
1717 i_gid_write(inode, attr->la_gid);
1718 if (bits & LA_NLINK)
1719 set_nlink(inode, attr->la_nlink);
1721 inode->i_rdev = attr->la_rdev;
1723 if (bits & LA_FLAGS) {
1724 /* always keep S_NOCMTIME */
1725 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1731 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1733 if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
1734 (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
1738 ll_vfs_dq_init(inode);
1740 if (attr->la_valid & LA_UID)
1741 iattr.ia_valid |= ATTR_UID;
1742 if (attr->la_valid & LA_GID)
1743 iattr.ia_valid |= ATTR_GID;
1744 iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
1745 iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
1747 rc = ll_vfs_dq_transfer(inode, &iattr);
1749 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1750 "enforcement enabled on the ldiskfs "
1751 "filesystem?\n", inode->i_sb->s_id, rc);
1758 static int osd_attr_set(const struct lu_env *env,
1759 struct dt_object *dt,
1760 const struct lu_attr *attr,
1761 struct thandle *handle)
1763 struct osd_object *obj = osd_dt_obj(dt);
1764 struct inode *inode;
1767 if (!dt_object_exists(dt))
1770 LASSERT(handle != NULL);
1771 LASSERT(!dt_object_remote(dt));
1772 LASSERT(osd_invariant(obj));
1774 osd_trans_exec_op(env, handle, OSD_OT_ATTR_SET);
1776 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING)) {
1777 struct osd_thread_info *oti = osd_oti_get(env);
1778 const struct lu_fid *fid0 = lu_object_fid(&dt->do_lu);
1779 struct lu_fid *fid1 = &oti->oti_fid;
1780 struct osd_inode_id *id = &oti->oti_id;
1781 struct iam_path_descr *ipd;
1782 struct iam_container *bag;
1783 struct osd_thandle *oh;
1786 fid_cpu_to_be(fid1, fid0);
1787 memset(id, 1, sizeof(*id));
1788 bag = &osd_fid2oi(osd_dev(dt->do_lu.lo_dev),
1789 fid0)->oi_dir.od_container;
1790 ipd = osd_idx_ipd_get(env, bag);
1791 if (unlikely(ipd == NULL))
1794 oh = container_of0(handle, struct osd_thandle, ot_super);
1795 rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1,
1796 (const struct iam_rec *)id, ipd);
1797 osd_ipd_put(env, bag, ipd);
1798 return(rc > 0 ? 0 : rc);
1801 inode = obj->oo_inode;
1803 rc = osd_quota_transfer(inode, attr);
1807 spin_lock(&obj->oo_guard);
1808 rc = osd_inode_setattr(env, inode, attr);
1809 spin_unlock(&obj->oo_guard);
1812 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
1816 static struct dentry *osd_child_dentry_get(const struct lu_env *env,
1817 struct osd_object *obj,
1818 const char *name, const int namelen)
1820 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1823 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1824 umode_t mode, struct dt_allocation_hint *hint,
1828 struct osd_device *osd = osd_obj2dev(obj);
1829 struct osd_thandle *oth;
1830 struct dt_object *parent = NULL;
1831 struct inode *inode;
1833 LINVRNT(osd_invariant(obj));
1834 LASSERT(obj->oo_inode == NULL);
1835 LASSERT(obj->oo_hl_head == NULL);
1837 if (S_ISDIR(mode) && ldiskfs_pdo) {
1838 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1839 if (obj->oo_hl_head == NULL)
1843 oth = container_of(th, struct osd_thandle, ot_super);
1844 LASSERT(oth->ot_handle->h_transaction != NULL);
1846 if (hint && hint->dah_parent)
1847 parent = hint->dah_parent;
1849 inode = ldiskfs_create_inode(oth->ot_handle,
1850 parent ? osd_dt_obj(parent)->oo_inode :
1851 osd_sb(osd)->s_root->d_inode,
1853 if (!IS_ERR(inode)) {
1854 /* Do not update file c/mtime in ldiskfs. */
1855 inode->i_flags |= S_NOCMTIME;
1857 /* For new created object, it must be consistent,
1858 * and it is unnecessary to scrub against it. */
1859 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
1861 obj->oo_inode = inode;
1864 if (obj->oo_hl_head != NULL) {
1865 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1866 obj->oo_hl_head = NULL;
1868 result = PTR_ERR(inode);
1870 LINVRNT(osd_invariant(obj));
1878 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1879 struct lu_attr *attr,
1880 struct dt_allocation_hint *hint,
1881 struct dt_object_format *dof,
1885 struct osd_thandle *oth;
1886 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1888 LASSERT(S_ISDIR(attr->la_mode));
1890 oth = container_of(th, struct osd_thandle, ot_super);
1891 LASSERT(oth->ot_handle->h_transaction != NULL);
1892 result = osd_mkfile(info, obj, mode, hint, th);
1897 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1898 struct lu_attr *attr,
1899 struct dt_allocation_hint *hint,
1900 struct dt_object_format *dof,
1904 struct osd_thandle *oth;
1905 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1907 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1909 LASSERT(S_ISREG(attr->la_mode));
1911 oth = container_of(th, struct osd_thandle, ot_super);
1912 LASSERT(oth->ot_handle->h_transaction != NULL);
1914 result = osd_mkfile(info, obj, mode, hint, th);
1916 LASSERT(obj->oo_inode != NULL);
1917 if (feat->dif_flags & DT_IND_VARKEY)
1918 result = iam_lvar_create(obj->oo_inode,
1919 feat->dif_keysize_max,
1921 feat->dif_recsize_max,
1924 result = iam_lfix_create(obj->oo_inode,
1925 feat->dif_keysize_max,
1927 feat->dif_recsize_max,
1934 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1935 struct lu_attr *attr,
1936 struct dt_allocation_hint *hint,
1937 struct dt_object_format *dof,
1940 LASSERT(S_ISREG(attr->la_mode));
1941 return osd_mkfile(info, obj, (attr->la_mode &
1942 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1945 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1946 struct lu_attr *attr,
1947 struct dt_allocation_hint *hint,
1948 struct dt_object_format *dof,
1951 LASSERT(S_ISLNK(attr->la_mode));
1952 return osd_mkfile(info, obj, (attr->la_mode &
1953 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1956 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1957 struct lu_attr *attr,
1958 struct dt_allocation_hint *hint,
1959 struct dt_object_format *dof,
1962 umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1965 LINVRNT(osd_invariant(obj));
1966 LASSERT(obj->oo_inode == NULL);
1967 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1968 S_ISFIFO(mode) || S_ISSOCK(mode));
1970 result = osd_mkfile(info, obj, mode, hint, th);
1972 LASSERT(obj->oo_inode != NULL);
1974 * This inode should be marked dirty for i_rdev. Currently
1975 * that is done in the osd_attr_init().
1977 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
1980 LINVRNT(osd_invariant(obj));
1984 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1986 struct dt_allocation_hint *hint,
1987 struct dt_object_format *dof,
1990 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1992 osd_obj_type_f result;
2008 result = osd_mk_index;
2019 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
2020 struct dt_object *parent, struct dt_object *child,
2025 ah->dah_parent = parent;
2026 ah->dah_mode = child_mode;
2029 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
2030 struct lu_attr *attr, struct dt_object_format *dof)
2032 struct inode *inode = obj->oo_inode;
2033 __u64 valid = attr->la_valid;
2036 attr->la_valid &= ~(LA_TYPE | LA_MODE);
2038 if (dof->dof_type != DFT_NODE)
2039 attr->la_valid &= ~LA_RDEV;
2040 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
2041 attr->la_valid &= ~LA_ATIME;
2042 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
2043 attr->la_valid &= ~LA_CTIME;
2044 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
2045 attr->la_valid &= ~LA_MTIME;
2047 result = osd_quota_transfer(inode, attr);
2051 if (attr->la_valid != 0) {
2052 result = osd_inode_setattr(info->oti_env, inode, attr);
2054 * The osd_inode_setattr() should always succeed here. The
2055 * only error that could be returned is EDQUOT when we are
2056 * trying to change the UID or GID of the inode. However, this
2057 * should not happen since quota enforcement is no longer
2058 * enabled on ldiskfs (lquota takes care of it).
2060 LASSERTF(result == 0, "%d\n", result);
2061 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2064 attr->la_valid = valid;
2068 * Helper function for osd_object_create()
2070 * \retval 0, on success
2072 static int __osd_object_create(struct osd_thread_info *info,
2073 struct osd_object *obj, struct lu_attr *attr,
2074 struct dt_allocation_hint *hint,
2075 struct dt_object_format *dof,
2081 /* we drop umask so that permissions we pass are not affected */
2082 umask = current->fs->umask;
2083 current->fs->umask = 0;
2085 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
2087 if (likely(obj->oo_inode != NULL)) {
2088 LASSERT(obj->oo_inode->i_state & I_NEW);
2090 /* Unlock the inode before attr initialization to avoid
2091 * unnecessary dqget operations. LU-6378 */
2092 unlock_new_inode(obj->oo_inode);
2095 if (likely(result == 0)) {
2096 osd_attr_init(info, obj, attr, dof);
2097 osd_object_init0(obj);
2100 /* restore previous umask value */
2101 current->fs->umask = umask;
2107 * Helper function for osd_object_create()
2109 * \retval 0, on success
2111 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
2112 const struct lu_fid *fid, struct thandle *th)
2114 struct osd_thread_info *info = osd_oti_get(env);
2115 struct osd_inode_id *id = &info->oti_id;
2116 struct osd_device *osd = osd_obj2dev(obj);
2117 struct osd_thandle *oh;
2119 LASSERT(obj->oo_inode != NULL);
2121 oh = container_of0(th, struct osd_thandle, ot_super);
2122 LASSERT(oh->ot_handle);
2124 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2125 return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
2128 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
2129 u64 seq, struct lu_seq_range *range)
2131 struct seq_server_site *ss = osd_seq_site(osd);
2133 if (fid_seq_is_idif(seq)) {
2134 fld_range_set_ost(range);
2135 range->lsr_index = idif_ost_idx(seq);
2139 if (!fid_seq_in_fldb(seq)) {
2140 fld_range_set_mdt(range);
2142 /* FIXME: If ss is NULL, it suppose not get lsr_index
2144 range->lsr_index = ss->ss_node_id;
2148 LASSERT(ss != NULL);
2149 fld_range_set_any(range);
2150 /* OSD will only do local fld lookup */
2151 return fld_local_lookup(env, ss->ss_server_fld, seq, range);
2155 * Concurrency: no external locking is necessary.
2157 static int osd_declare_object_create(const struct lu_env *env,
2158 struct dt_object *dt,
2159 struct lu_attr *attr,
2160 struct dt_allocation_hint *hint,
2161 struct dt_object_format *dof,
2162 struct thandle *handle)
2164 struct osd_thandle *oh;
2168 LASSERT(handle != NULL);
2170 oh = container_of0(handle, struct osd_thandle, ot_super);
2171 LASSERT(oh->ot_handle == NULL);
2173 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
2174 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
2175 /* Reuse idle OI block may cause additional one OI block
2177 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2178 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
2180 /* If this is directory, then we expect . and .. to be inserted as
2181 * well. The one directory block always needs to be created for the
2182 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2183 * block), there is no danger of needing a tree for the first block.
2185 if (attr && S_ISDIR(attr->la_mode)) {
2186 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
2187 osd_dto_credits_noquota[DTO_WRITE_BASE]);
2188 osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0);
2194 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2195 osd_dt_obj(dt), false, NULL, false);
2202 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2203 struct lu_attr *attr,
2204 struct dt_allocation_hint *hint,
2205 struct dt_object_format *dof, struct thandle *th)
2207 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2208 struct osd_object *obj = osd_dt_obj(dt);
2209 struct osd_thread_info *info = osd_oti_get(env);
2213 if (dt_object_exists(dt))
2216 LINVRNT(osd_invariant(obj));
2217 LASSERT(!dt_object_remote(dt));
2218 LASSERT(osd_write_locked(env, obj));
2219 LASSERT(th != NULL);
2221 if (unlikely(fid_is_acct(fid)))
2222 /* Quota files can't be created from the kernel any more,
2223 * 'tune2fs -O quota' will take care of creating them */
2226 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2227 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2229 result = __osd_object_create(info, obj, attr, hint, dof, th);
2231 result = __osd_oi_insert(env, obj, fid, th);
2233 LASSERT(ergo(result == 0,
2234 dt_object_exists(dt) && !dt_object_remote(dt)));
2236 LASSERT(osd_invariant(obj));
2241 * Called to destroy on-disk representation of the object
2243 * Concurrency: must be locked
2245 static int osd_declare_object_destroy(const struct lu_env *env,
2246 struct dt_object *dt,
2249 struct osd_object *obj = osd_dt_obj(dt);
2250 struct inode *inode = obj->oo_inode;
2251 struct osd_thandle *oh;
2255 oh = container_of0(th, struct osd_thandle, ot_super);
2256 LASSERT(oh->ot_handle == NULL);
2259 osd_trans_declare_op(env, oh, OSD_OT_DESTROY,
2260 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2261 /* Recycle idle OI leaf may cause additional three OI blocks
2263 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
2264 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
2265 /* one less inode */
2266 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2267 -1, oh, obj, false, NULL, false);
2270 /* data to be truncated */
2271 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
2272 0, oh, obj, true, NULL, false);
2276 static int osd_object_destroy(const struct lu_env *env,
2277 struct dt_object *dt,
2280 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2281 struct osd_object *obj = osd_dt_obj(dt);
2282 struct inode *inode = obj->oo_inode;
2283 struct osd_device *osd = osd_obj2dev(obj);
2284 struct osd_thandle *oh;
2288 oh = container_of0(th, struct osd_thandle, ot_super);
2289 LASSERT(oh->ot_handle);
2291 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2293 if (unlikely(fid_is_acct(fid)))
2296 if (S_ISDIR(inode->i_mode)) {
2297 LASSERT(osd_inode_unlinked(inode) || inode->i_nlink == 1 ||
2298 inode->i_nlink == 2);
2299 /* it will check/delete the inode from remote parent,
2300 * how to optimize it? unlink performance impaction XXX */
2301 result = osd_delete_from_remote_parent(env, osd, obj, oh);
2302 if (result != 0 && result != -ENOENT) {
2303 CERROR("%s: delete inode "DFID": rc = %d\n",
2304 osd_name(osd), PFID(fid), result);
2306 spin_lock(&obj->oo_guard);
2308 spin_unlock(&obj->oo_guard);
2309 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2312 osd_trans_exec_op(env, th, OSD_OT_DESTROY);
2314 result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
2317 /* XXX: add to ext3 orphan list */
2318 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2320 /* not needed in the cache anymore */
2321 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2327 * Put the fid into lustre_mdt_attrs, and then place the structure
2328 * inode's ea. This fid should not be altered during the life time
2331 * \retval +ve, on success
2332 * \retval -ve, on error
2334 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2336 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
2337 const struct lu_fid *fid, __u32 compat, __u32 incompat)
2339 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2343 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
2346 lustre_lma_init(lma, fid, compat, incompat);
2347 lustre_lma_swab(lma);
2349 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma, sizeof(*lma),
2351 /* LMA may already exist, but we need to check that all the
2352 * desired compat/incompat flags have been added. */
2353 if (unlikely(rc == -EEXIST)) {
2354 if (compat == 0 && incompat == 0)
2357 rc = __osd_xattr_get(inode, &info->oti_obj_dentry,
2358 XATTR_NAME_LMA, info->oti_mdt_attrs_old,
2363 lustre_lma_swab(lma);
2364 if (!(~lma->lma_compat & compat) &&
2365 !(~lma->lma_incompat & incompat))
2368 lma->lma_compat |= compat;
2369 lma->lma_incompat |= incompat;
2370 lustre_lma_swab(lma);
2371 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2372 sizeof(*lma), XATTR_REPLACE);
2379 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2380 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2381 * To have compatilibility with 1.8 ldiskfs driver we need to have
2382 * magic number at start of fid data.
2383 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2386 static void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2387 const struct lu_fid *fid)
2389 if (!fid_is_namespace_visible(fid) ||
2390 OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
2391 param->edp_magic = 0;
2395 param->edp_magic = LDISKFS_LUFID_MAGIC;
2396 param->edp_len = sizeof(struct lu_fid) + 1;
2397 fid_cpu_to_be((struct lu_fid *)param->edp_data, (struct lu_fid *)fid);
2401 * Try to read the fid from inode ea into dt_rec.
2403 * \param fid object fid.
2405 * \retval 0 on success
2407 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2408 __u32 ino, struct lu_fid *fid,
2409 struct osd_inode_id *id)
2411 struct osd_thread_info *info = osd_oti_get(env);
2412 struct inode *inode;
2415 osd_id_gen(id, ino, OSD_OII_NOGEN);
2416 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2418 RETURN(PTR_ERR(inode));
2424 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
2426 struct inode *parent_dir,
2427 const struct lu_fid *dot_fid,
2428 const struct lu_fid *dot_dot_fid,
2429 struct osd_thandle *oth)
2431 struct ldiskfs_dentry_param *dot_ldp;
2432 struct ldiskfs_dentry_param *dot_dot_ldp;
2434 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
2435 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
2437 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
2438 dot_ldp->edp_magic = 0;
2439 return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
2440 dir, dot_ldp, dot_dot_ldp);
2444 * Create an local agent inode for remote entry
2446 static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
2447 struct osd_device *osd,
2448 struct osd_object *pobj,
2449 const struct lu_fid *fid,
2453 struct osd_thread_info *info = osd_oti_get(env);
2454 struct inode *local;
2455 struct osd_thandle *oh;
2460 oh = container_of(th, struct osd_thandle, ot_super);
2461 LASSERT(oh->ot_handle->h_transaction != NULL);
2463 local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
2464 if (IS_ERR(local)) {
2465 CERROR("%s: create local error %d\n", osd_name(osd),
2466 (int)PTR_ERR(local));
2470 ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB);
2471 unlock_new_inode(local);
2473 /* Set special LMA flag for local agent inode */
2474 rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
2476 CERROR("%s: set LMA for "DFID" remote inode failed: rc = %d\n",
2477 osd_name(osd), PFID(fid), rc);
2478 RETURN(ERR_PTR(rc));
2484 rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
2485 lu_object_fid(&pobj->oo_dt.do_lu),
2488 CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
2489 osd_name(osd), PFID(fid), rc);
2490 RETURN(ERR_PTR(rc));
2497 * Delete local agent inode for remote entry
2499 static int osd_delete_local_agent_inode(const struct lu_env *env,
2500 struct osd_device *osd,
2501 const struct lu_fid *fid,
2502 __u32 ino, struct osd_thandle *oh)
2504 struct osd_thread_info *oti = osd_oti_get(env);
2505 struct osd_inode_id *id = &oti->oti_id;
2506 struct inode *inode;
2509 id->oii_ino = le32_to_cpu(ino);
2510 id->oii_gen = OSD_OII_NOGEN;
2511 inode = osd_iget(oti, osd, id);
2512 if (IS_ERR(inode)) {
2513 CERROR("%s: iget error "DFID" id %u:%u\n", osd_name(osd),
2514 PFID(fid), id->oii_ino, id->oii_gen);
2515 RETURN(PTR_ERR(inode));
2519 mark_inode_dirty(inode);
2520 CDEBUG(D_INODE, "%s: delete remote inode "DFID" %lu\n",
2521 osd_name(osd), PFID(fid), inode->i_ino);
2527 * OSD layer object create function for interoperability mode (b11826).
2528 * This is mostly similar to osd_object_create(). Only difference being, fid is
2529 * inserted into inode ea here.
2531 * \retval 0, on success
2532 * \retval -ve, on error
2534 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2535 struct lu_attr *attr,
2536 struct dt_allocation_hint *hint,
2537 struct dt_object_format *dof,
2540 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2541 struct osd_object *obj = osd_dt_obj(dt);
2542 struct osd_thread_info *info = osd_oti_get(env);
2547 if (dt_object_exists(dt))
2550 LASSERT(osd_invariant(obj));
2551 LASSERT(!dt_object_remote(dt));
2552 LASSERT(osd_write_locked(env, obj));
2553 LASSERT(th != NULL);
2555 if (unlikely(fid_is_acct(fid)))
2556 /* Quota files can't be created from the kernel any more,
2557 * 'tune2fs -O quota' will take care of creating them */
2560 osd_trans_exec_op(env, th, OSD_OT_CREATE);
2561 osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
2563 result = __osd_object_create(info, obj, attr, hint, dof, th);
2565 if (fid_is_idif(fid) &&
2566 !osd_dev(dt->do_lu.lo_dev)->od_index_in_idif) {
2567 struct lu_fid *tfid = &info->oti_fid;
2568 struct ost_id *oi = &info->oti_ostid;
2570 fid_to_ostid(fid, oi);
2571 ostid_to_fid(tfid, oi, 0);
2572 result = osd_ea_fid_set(info, obj->oo_inode, tfid,
2573 LMAC_FID_ON_OST, 0);
2575 result = osd_ea_fid_set(info, obj->oo_inode, fid,
2576 fid_is_on_ost(info, osd_obj2dev(obj),
2577 fid, OI_CHECK_FLD) ?
2578 LMAC_FID_ON_OST : 0, 0);
2583 result = __osd_oi_insert(env, obj, fid, th);
2585 LASSERT(ergo(result == 0,
2586 dt_object_exists(dt) && !dt_object_remote(dt)));
2587 LINVRNT(osd_invariant(obj));
2591 static int osd_declare_object_ref_add(const struct lu_env *env,
2592 struct dt_object *dt,
2593 struct thandle *handle)
2595 struct osd_thandle *oh;
2597 /* it's possible that object doesn't exist yet */
2598 LASSERT(handle != NULL);
2600 oh = container_of0(handle, struct osd_thandle, ot_super);
2601 LASSERT(oh->ot_handle == NULL);
2603 osd_trans_declare_op(env, oh, OSD_OT_REF_ADD,
2604 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2610 * Concurrency: @dt is write locked.
2612 static int osd_object_ref_add(const struct lu_env *env,
2613 struct dt_object *dt, struct thandle *th)
2615 struct osd_object *obj = osd_dt_obj(dt);
2616 struct inode *inode = obj->oo_inode;
2617 struct osd_thandle *oh;
2620 if (!dt_object_exists(dt))
2623 LINVRNT(osd_invariant(obj));
2624 LASSERT(!dt_object_remote(dt));
2625 LASSERT(osd_write_locked(env, obj));
2626 LASSERT(th != NULL);
2628 oh = container_of0(th, struct osd_thandle, ot_super);
2629 LASSERT(oh->ot_handle != NULL);
2631 osd_trans_exec_op(env, th, OSD_OT_REF_ADD);
2633 CDEBUG(D_INODE, DFID" increase nlink %d\n",
2634 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2636 * The DIR_NLINK feature allows directories to exceed LDISKFS_LINK_MAX
2637 * (65000) subdirectories by storing "1" in i_nlink if the link count
2638 * would otherwise overflow. Directory tranversal tools understand
2639 * that (st_nlink == 1) indicates that the filesystem dose not track
2640 * hard links count on the directory, and will not abort subdirectory
2641 * scanning early once (st_nlink - 2) subdirs have been found.
2643 * This also has to properly handle the case of inodes with nlink == 0
2644 * in case they are being linked into the PENDING directory
2646 spin_lock(&obj->oo_guard);
2647 if (unlikely(inode->i_nlink == 0))
2648 /* inc_nlink from 0 may cause WARN_ON */
2649 set_nlink(inode, 1);
2651 ldiskfs_inc_count(oh->ot_handle, inode);
2652 if (!S_ISDIR(inode->i_mode))
2653 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2655 spin_unlock(&obj->oo_guard);
2657 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2658 LINVRNT(osd_invariant(obj));
2663 static int osd_declare_object_ref_del(const struct lu_env *env,
2664 struct dt_object *dt,
2665 struct thandle *handle)
2667 struct osd_thandle *oh;
2669 LASSERT(!dt_object_remote(dt));
2670 LASSERT(handle != NULL);
2672 oh = container_of0(handle, struct osd_thandle, ot_super);
2673 LASSERT(oh->ot_handle == NULL);
2675 osd_trans_declare_op(env, oh, OSD_OT_REF_DEL,
2676 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2682 * Concurrency: @dt is write locked.
2684 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2687 struct osd_object *obj = osd_dt_obj(dt);
2688 struct inode *inode = obj->oo_inode;
2689 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
2690 struct osd_thandle *oh;
2692 if (!dt_object_exists(dt))
2695 LINVRNT(osd_invariant(obj));
2696 LASSERT(!dt_object_remote(dt));
2697 LASSERT(osd_write_locked(env, obj));
2698 LASSERT(th != NULL);
2700 oh = container_of0(th, struct osd_thandle, ot_super);
2701 LASSERT(oh->ot_handle != NULL);
2703 osd_trans_exec_op(env, th, OSD_OT_REF_DEL);
2705 spin_lock(&obj->oo_guard);
2706 /* That can be result of upgrade from old Lustre version and
2707 * applied only to local files. Just skip this ref_del call.
2708 * ext4_unlink() only treats this as a warning, don't LASSERT here.*/
2709 if (inode->i_nlink == 0) {
2710 CDEBUG_LIMIT(fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2711 D_ERROR : D_INODE, "%s: nlink == 0 on "DFID
2712 ", maybe an upgraded file? (LU-3915)\n",
2713 osd_name(osd), PFID(lu_object_fid(&dt->do_lu)));
2714 spin_unlock(&obj->oo_guard);
2718 CDEBUG(D_INODE, DFID" decrease nlink %d\n",
2719 PFID(lu_object_fid(&dt->do_lu)), inode->i_nlink);
2721 ldiskfs_dec_count(oh->ot_handle, inode);
2722 spin_unlock(&obj->oo_guard);
2724 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2725 LINVRNT(osd_invariant(obj));
2731 * Get the 64-bit version for an inode.
2733 static int osd_object_version_get(const struct lu_env *env,
2734 struct dt_object *dt, dt_obj_version_t *ver)
2736 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2738 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2739 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2740 *ver = LDISKFS_I(inode)->i_fs_version;
2745 * Concurrency: @dt is read locked.
2747 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2748 struct lu_buf *buf, const char *name)
2750 struct osd_object *obj = osd_dt_obj(dt);
2751 struct inode *inode = obj->oo_inode;
2752 struct osd_thread_info *info = osd_oti_get(env);
2753 struct dentry *dentry = &info->oti_obj_dentry;
2755 /* version get is not real XATTR but uses xattr API */
2756 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2757 /* for version we are just using xattr API but change inode
2759 if (buf->lb_len == 0)
2760 return sizeof(dt_obj_version_t);
2762 if (buf->lb_len < sizeof(dt_obj_version_t))
2765 osd_object_version_get(env, dt, buf->lb_buf);
2767 return sizeof(dt_obj_version_t);
2770 if (!dt_object_exists(dt))
2773 LASSERT(!dt_object_remote(dt));
2774 LASSERT(inode->i_op != NULL);
2775 LASSERT(inode->i_op->getxattr != NULL);
2777 return __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len);
2781 static int osd_declare_xattr_set(const struct lu_env *env,
2782 struct dt_object *dt,
2783 const struct lu_buf *buf, const char *name,
2784 int fl, struct thandle *handle)
2786 struct osd_thandle *oh;
2788 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2790 LASSERT(handle != NULL);
2792 oh = container_of0(handle, struct osd_thandle, ot_super);
2793 LASSERT(oh->ot_handle == NULL);
2795 /* optimistic optimization: LMA is set first and usually fit inode */
2796 if (strcmp(name, XATTR_NAME_LMA) == 0) {
2797 if (dt_object_exists(dt))
2801 } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2804 credits = osd_dto_credits_noquota[DTO_XATTR_SET];
2805 if (buf && buf->lb_len > sb->s_blocksize) {
2806 credits *= (buf->lb_len + sb->s_blocksize - 1) >>
2807 sb->s_blocksize_bits;
2810 * xattr set may involve inode quota change, reserve credits for
2811 * dquot_initialize()
2813 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2816 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
2822 * Set the 64-bit version for object
2824 static void osd_object_version_set(const struct lu_env *env,
2825 struct dt_object *dt,
2826 dt_obj_version_t *new_version)
2828 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2830 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2831 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2833 LDISKFS_I(inode)->i_fs_version = *new_version;
2834 /** Version is set after all inode operations are finished,
2835 * so we should mark it dirty here */
2836 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
2840 * Concurrency: @dt is write locked.
2842 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2843 const struct lu_buf *buf, const char *name, int fl,
2844 struct thandle *handle)
2846 struct osd_object *obj = osd_dt_obj(dt);
2847 struct inode *inode = obj->oo_inode;
2848 struct osd_thread_info *info = osd_oti_get(env);
2852 LASSERT(handle != NULL);
2854 /* version set is not real XATTR */
2855 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2856 /* for version we are just using xattr API but change inode
2858 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2859 osd_object_version_set(env, dt, buf->lb_buf);
2860 return sizeof(dt_obj_version_t);
2863 CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n",
2864 PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
2866 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2867 if (fl & LU_XATTR_REPLACE)
2868 fs_flags |= XATTR_REPLACE;
2870 if (fl & LU_XATTR_CREATE)
2871 fs_flags |= XATTR_CREATE;
2873 if (strcmp(name, XATTR_NAME_LMV) == 0) {
2874 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
2877 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
2881 lma->lma_incompat |= LMAI_STRIPED;
2882 lustre_lma_swab(lma);
2883 rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
2884 sizeof(*lma), XATTR_REPLACE);
2889 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) &&
2890 strcmp(name, XATTR_NAME_LINK) == 0)
2893 return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
2898 * Concurrency: @dt is read locked.
2900 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2901 const struct lu_buf *buf)
2903 struct osd_object *obj = osd_dt_obj(dt);
2904 struct inode *inode = obj->oo_inode;
2905 struct osd_thread_info *info = osd_oti_get(env);
2906 struct dentry *dentry = &info->oti_obj_dentry;
2908 if (!dt_object_exists(dt))
2911 LASSERT(!dt_object_remote(dt));
2912 LASSERT(inode->i_op != NULL);
2913 LASSERT(inode->i_op->listxattr != NULL);
2915 dentry->d_inode = inode;
2916 dentry->d_sb = inode->i_sb;
2917 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2920 static int osd_declare_xattr_del(const struct lu_env *env,
2921 struct dt_object *dt, const char *name,
2922 struct thandle *handle)
2924 struct osd_thandle *oh;
2925 struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
2927 LASSERT(!dt_object_remote(dt));
2928 LASSERT(handle != NULL);
2930 oh = container_of0(handle, struct osd_thandle, ot_super);
2931 LASSERT(oh->ot_handle == NULL);
2933 osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
2934 osd_dto_credits_noquota[DTO_XATTR_SET]);
2936 * xattr del may involve inode quota change, reserve credits for
2937 * dquot_initialize()
2939 oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
2945 * Concurrency: @dt is write locked.
2947 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2948 const char *name, struct thandle *handle)
2950 struct osd_object *obj = osd_dt_obj(dt);
2951 struct inode *inode = obj->oo_inode;
2952 struct osd_thread_info *info = osd_oti_get(env);
2953 struct dentry *dentry = &info->oti_obj_dentry;
2956 if (!dt_object_exists(dt))
2959 LASSERT(!dt_object_remote(dt));
2960 LASSERT(inode->i_op != NULL);
2961 LASSERT(inode->i_op->removexattr != NULL);
2962 LASSERT(handle != NULL);
2964 osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
2966 ll_vfs_dq_init(inode);
2967 dentry->d_inode = inode;
2968 dentry->d_sb = inode->i_sb;
2969 rc = inode->i_op->removexattr(dentry, name);
2973 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
2974 __u64 start, __u64 end)
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;
2980 struct file *file = &info->oti_file;
2985 dentry->d_inode = inode;
2986 dentry->d_sb = inode->i_sb;
2987 file->f_path.dentry = dentry;
2988 file->f_mapping = inode->i_mapping;
2989 file->f_op = inode->i_fop;
2990 set_file_inode(file, inode);
2992 rc = ll_vfs_fsync_range(file, start, end, 0);
3001 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
3002 const struct dt_index_features *feat)
3004 struct iam_descr *descr;
3006 if (osd_object_is_root(o))
3007 return feat == &dt_directory_features;
3009 LASSERT(o->oo_dir != NULL);
3011 descr = o->oo_dir->od_container.ic_descr;
3012 if (feat == &dt_directory_features) {
3013 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
3019 feat->dif_keysize_min <= descr->id_key_size &&
3020 descr->id_key_size <= feat->dif_keysize_max &&
3021 feat->dif_recsize_min <= descr->id_rec_size &&
3022 descr->id_rec_size <= feat->dif_recsize_max &&
3023 !(feat->dif_flags & (DT_IND_VARKEY |
3024 DT_IND_VARREC | DT_IND_NONUNQ)) &&
3025 ergo(feat->dif_flags & DT_IND_UPDATE,
3026 1 /* XXX check that object (and file system) is
3031 static int osd_iam_container_init(const struct lu_env *env,
3032 struct osd_object *obj,
3033 struct osd_directory *dir)
3035 struct iam_container *bag = &dir->od_container;
3038 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
3042 result = iam_container_setup(bag);
3044 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
3046 iam_container_fini(bag);
3053 * Concurrency: no external locking is necessary.
3055 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
3056 const struct dt_index_features *feat)
3060 struct osd_object *obj = osd_dt_obj(dt);
3062 LINVRNT(osd_invariant(obj));
3064 if (osd_object_is_root(obj)) {
3065 dt->do_index_ops = &osd_index_ea_ops;
3067 } else if (feat == &dt_directory_features) {
3068 dt->do_index_ops = &osd_index_ea_ops;
3069 if (obj->oo_inode != NULL && S_ISDIR(obj->oo_inode->i_mode))
3074 } else if (unlikely(feat == &dt_otable_features)) {
3075 dt->do_index_ops = &osd_otable_ops;
3077 } else if (unlikely(feat == &dt_acct_features)) {
3078 dt->do_index_ops = &osd_acct_index_ops;
3081 } else if (!osd_has_index(obj)) {
3082 struct osd_directory *dir;
3087 spin_lock(&obj->oo_guard);
3088 if (obj->oo_dir == NULL)
3092 * Concurrent thread allocated container data.
3095 spin_unlock(&obj->oo_guard);
3097 * Now, that we have container data, serialize its
3100 down_write(&obj->oo_ext_idx_sem);
3102 * recheck under lock.
3104 if (!osd_has_index(obj))
3105 result = osd_iam_container_init(env, obj,
3109 up_write(&obj->oo_ext_idx_sem);
3117 if (result == 0 && skip_iam == 0) {
3118 if (!osd_iam_index_probe(env, obj, feat))
3121 LINVRNT(osd_invariant(obj));
3123 if (result == 0 && is_quota_glb_feat(feat) &&
3124 fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
3125 result = osd_quota_migration(env, dt, feat);
3130 static int osd_otable_it_attr_get(const struct lu_env *env,
3131 struct dt_object *dt,
3132 struct lu_attr *attr)
3138 static const struct dt_object_operations osd_obj_ops = {
3139 .do_read_lock = osd_object_read_lock,
3140 .do_write_lock = osd_object_write_lock,
3141 .do_read_unlock = osd_object_read_unlock,
3142 .do_write_unlock = osd_object_write_unlock,
3143 .do_write_locked = osd_object_write_locked,
3144 .do_attr_get = osd_attr_get,
3145 .do_declare_attr_set = osd_declare_attr_set,
3146 .do_attr_set = osd_attr_set,
3147 .do_ah_init = osd_ah_init,
3148 .do_declare_create = osd_declare_object_create,
3149 .do_create = osd_object_create,
3150 .do_declare_destroy = osd_declare_object_destroy,
3151 .do_destroy = osd_object_destroy,
3152 .do_index_try = osd_index_try,
3153 .do_declare_ref_add = osd_declare_object_ref_add,
3154 .do_ref_add = osd_object_ref_add,
3155 .do_declare_ref_del = osd_declare_object_ref_del,
3156 .do_ref_del = osd_object_ref_del,
3157 .do_xattr_get = osd_xattr_get,
3158 .do_declare_xattr_set = osd_declare_xattr_set,
3159 .do_xattr_set = osd_xattr_set,
3160 .do_declare_xattr_del = osd_declare_xattr_del,
3161 .do_xattr_del = osd_xattr_del,
3162 .do_xattr_list = osd_xattr_list,
3163 .do_object_sync = osd_object_sync,
3167 * dt_object_operations for interoperability mode
3168 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
3170 static const struct dt_object_operations osd_obj_ea_ops = {
3171 .do_read_lock = osd_object_read_lock,
3172 .do_write_lock = osd_object_write_lock,
3173 .do_read_unlock = osd_object_read_unlock,
3174 .do_write_unlock = osd_object_write_unlock,
3175 .do_write_locked = osd_object_write_locked,
3176 .do_attr_get = osd_attr_get,
3177 .do_declare_attr_set = osd_declare_attr_set,
3178 .do_attr_set = osd_attr_set,
3179 .do_ah_init = osd_ah_init,
3180 .do_declare_create = osd_declare_object_create,
3181 .do_create = osd_object_ea_create,
3182 .do_declare_destroy = osd_declare_object_destroy,
3183 .do_destroy = osd_object_destroy,
3184 .do_index_try = osd_index_try,
3185 .do_declare_ref_add = osd_declare_object_ref_add,
3186 .do_ref_add = osd_object_ref_add,
3187 .do_declare_ref_del = osd_declare_object_ref_del,
3188 .do_ref_del = osd_object_ref_del,
3189 .do_xattr_get = osd_xattr_get,
3190 .do_declare_xattr_set = osd_declare_xattr_set,
3191 .do_xattr_set = osd_xattr_set,
3192 .do_declare_xattr_del = osd_declare_xattr_del,
3193 .do_xattr_del = osd_xattr_del,
3194 .do_xattr_list = osd_xattr_list,
3195 .do_object_sync = osd_object_sync,
3198 static const struct dt_object_operations osd_obj_otable_it_ops = {
3199 .do_attr_get = osd_otable_it_attr_get,
3200 .do_index_try = osd_index_try,
3203 static int osd_index_declare_iam_delete(const struct lu_env *env,
3204 struct dt_object *dt,
3205 const struct dt_key *key,
3206 struct thandle *handle)
3208 struct osd_thandle *oh;
3210 oh = container_of0(handle, struct osd_thandle, ot_super);
3211 LASSERT(oh->ot_handle == NULL);
3213 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3214 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3220 * delete a (key, value) pair from index \a dt specified by \a key
3222 * \param dt osd index object
3223 * \param key key for index
3224 * \param rec record reference
3225 * \param handle transaction handler
3228 * \retval -ve failure
3230 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
3231 const struct dt_key *key,
3232 struct thandle *handle)
3234 struct osd_thread_info *oti = osd_oti_get(env);
3235 struct osd_object *obj = osd_dt_obj(dt);
3236 struct osd_thandle *oh;
3237 struct iam_path_descr *ipd;
3238 struct iam_container *bag = &obj->oo_dir->od_container;
3242 if (!dt_object_exists(dt))
3245 LINVRNT(osd_invariant(obj));
3246 LASSERT(!dt_object_remote(dt));
3247 LASSERT(bag->ic_object == obj->oo_inode);
3248 LASSERT(handle != NULL);
3250 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3252 ipd = osd_idx_ipd_get(env, bag);
3253 if (unlikely(ipd == NULL))
3256 oh = container_of0(handle, struct osd_thandle, ot_super);
3257 LASSERT(oh->ot_handle != NULL);
3258 LASSERT(oh->ot_handle->h_transaction != NULL);
3260 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3261 /* swab quota uid/gid provided by caller */
3262 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3263 key = (const struct dt_key *)&oti->oti_quota_id;
3266 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
3267 osd_ipd_put(env, bag, ipd);
3268 LINVRNT(osd_invariant(obj));
3272 static int osd_index_declare_ea_delete(const struct lu_env *env,
3273 struct dt_object *dt,
3274 const struct dt_key *key,
3275 struct thandle *handle)
3277 struct osd_thandle *oh;
3278 struct inode *inode;
3282 LASSERT(!dt_object_remote(dt));
3283 LASSERT(handle != NULL);
3285 oh = container_of0(handle, struct osd_thandle, ot_super);
3286 LASSERT(oh->ot_handle == NULL);
3288 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
3289 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
3291 inode = osd_dt_obj(dt)->oo_inode;
3294 rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
3295 0, oh, osd_dt_obj(dt), true, NULL, false);
3299 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3302 struct osd_fid_pack *rec;
3305 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3306 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3307 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3308 if (rc == 0 && unlikely(!fid_is_sane((struct lu_fid *)fid)))
3314 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
3315 const struct lu_fid *fid)
3317 struct seq_server_site *ss = osd_seq_site(osd);
3320 /* FID seqs not in FLDB, must be local seq */
3321 if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
3324 /* If FLD is not being initialized yet, it only happens during the
3325 * initialization, likely during mgs initialization, and we assume
3326 * this is local FID. */
3327 if (ss == NULL || ss->ss_server_fld == NULL)
3330 /* Only check the local FLDB here */
3331 if (osd_seq_exists(env, osd, fid_seq(fid)))
3338 * Index delete function for interoperability mode (b11826).
3339 * It will remove the directory entry added by osd_index_ea_insert().
3340 * This entry is needed to maintain name->fid mapping.
3342 * \param key, key i.e. file entry to be deleted
3344 * \retval 0, on success
3345 * \retval -ve, on error
3347 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3348 const struct dt_key *key, struct thandle *handle)
3350 struct osd_object *obj = osd_dt_obj(dt);
3351 struct inode *dir = obj->oo_inode;
3352 struct dentry *dentry;
3353 struct osd_thandle *oh;
3354 struct ldiskfs_dir_entry_2 *de = NULL;
3355 struct buffer_head *bh;
3356 struct htree_lock *hlock = NULL;
3357 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
3358 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
3362 if (!dt_object_exists(dt))
3365 LINVRNT(osd_invariant(obj));
3366 LASSERT(!dt_object_remote(dt));
3367 LASSERT(handle != NULL);
3369 osd_trans_exec_op(env, handle, OSD_OT_DELETE);
3371 oh = container_of(handle, struct osd_thandle, ot_super);
3372 LASSERT(oh->ot_handle != NULL);
3373 LASSERT(oh->ot_handle->h_transaction != NULL);
3375 ll_vfs_dq_init(dir);
3376 dentry = osd_child_dentry_get(env, obj,
3377 (char *)key, strlen((char *)key));
3379 if (obj->oo_hl_head != NULL) {
3380 hlock = osd_oti_get(env)->oti_hlock;
3381 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3382 dir, LDISKFS_HLOCK_DEL);
3384 down_write(&obj->oo_ext_idx_sem);
3387 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
3391 /* If this is not the ".." entry, it might be a remote DNE
3392 * entry and we need to check if the FID is for a remote
3393 * MDT. If the FID is not in the directory entry (e.g.
3394 * upgraded 1.8 filesystem without dirdata enabled) then
3395 * we need to get the FID from the LMA. For a remote directory
3396 * there HAS to be an LMA, it cannot be an IGIF inode in this
3399 * Delete the entry before the agent inode in order to
3400 * simplify error handling. At worst an error after deleting
3401 * the entry first might leak the agent inode afterward. The
3402 * reverse would need filesystem abort in case of error deleting
3403 * the entry after the agent had been removed, or leave a
3404 * dangling entry pointing at a random inode. */
3405 if (strcmp((char *)key, dotdot) != 0) {
3406 LASSERT(de != NULL);
3407 rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid);
3408 /* If Fid is not in dentry, try to get it from LMA */
3409 if (rc == -ENODATA) {
3410 struct osd_inode_id *id;
3411 struct inode *inode;
3413 /* Before trying to get fid from the inode,
3414 * check whether the inode is valid.
3416 * If the inode has been deleted, do not go
3417 * ahead to do osd_ea_fid_get, which will set
3418 * the inode to bad inode, which might cause
3419 * the inode to be deleted uncorrectly */
3420 inode = ldiskfs_iget(osd_sb(osd),
3421 le32_to_cpu(de->inode));
3422 if (IS_ERR(inode)) {
3423 CDEBUG(D_INODE, "%s: "DFID"get inode"
3424 "error.\n", osd_name(osd),
3426 rc = PTR_ERR(inode);
3428 if (likely(inode->i_nlink != 0)) {
3429 id = &osd_oti_get(env)->oti_id;
3430 rc = osd_ea_fid_get(env, obj,
3431 le32_to_cpu(de->inode),
3434 CDEBUG(D_INFO, "%s: %u "DFID
3437 le32_to_cpu(de->inode),
3445 unlikely(osd_remote_fid(env, osd, fid)))
3446 /* Need to delete agent inode */
3447 ino = le32_to_cpu(de->inode);
3449 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
3451 if (rc == 0 && unlikely(ino != 0)) {
3452 rc = osd_delete_local_agent_inode(env, osd, fid, ino,
3455 CERROR("%s: del local inode "DFID": rc = %d\n",
3456 osd_name(osd), PFID(fid), rc);
3462 ldiskfs_htree_unlock(hlock);
3464 up_write(&obj->oo_ext_idx_sem);
3469 /* For inode on the remote MDT, .. will point to
3470 * /Agent directory, Check whether it needs to delete
3471 * from agent directory */
3472 if (unlikely(strcmp((char *)key, dotdot) == 0)) {
3473 rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj,
3475 if (rc != 0 && rc != -ENOENT) {
3476 CERROR("%s: delete agent inode "DFID": rc = %d\n",
3477 osd_name(osd), PFID(fid), rc);
3487 LASSERT(osd_invariant(obj));
3492 * Lookup index for \a key and copy record to \a rec.
3494 * \param dt osd index object
3495 * \param key key for index
3496 * \param rec record reference
3498 * \retval +ve success : exact mach
3499 * \retval 0 return record with key not greater than \a key
3500 * \retval -ve failure
3502 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3503 struct dt_rec *rec, const struct dt_key *key)
3505 struct osd_object *obj = osd_dt_obj(dt);
3506 struct iam_path_descr *ipd;
3507 struct iam_container *bag = &obj->oo_dir->od_container;
3508 struct osd_thread_info *oti = osd_oti_get(env);
3509 struct iam_iterator *it = &oti->oti_idx_it;
3510 struct iam_rec *iam_rec;
3514 if (!dt_object_exists(dt))
3517 LASSERT(osd_invariant(obj));
3518 LASSERT(!dt_object_remote(dt));
3519 LASSERT(bag->ic_object == obj->oo_inode);
3521 ipd = osd_idx_ipd_get(env, bag);
3525 /* got ipd now we can start iterator. */
3526 iam_it_init(it, bag, 0, ipd);
3528 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3529 /* swab quota uid/gid provided by caller */
3530 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3531 key = (const struct dt_key *)&oti->oti_quota_id;
3534 rc = iam_it_get(it, (struct iam_key *)key);
3536 if (S_ISDIR(obj->oo_inode->i_mode))
3537 iam_rec = (struct iam_rec *)oti->oti_ldp;
3539 iam_rec = (struct iam_rec *) rec;
3541 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3543 if (S_ISDIR(obj->oo_inode->i_mode))
3544 osd_fid_unpack((struct lu_fid *) rec,
3545 (struct osd_fid_pack *)iam_rec);
3546 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3547 osd_quota_unpack(obj, rec);
3552 osd_ipd_put(env, bag, ipd);
3554 LINVRNT(osd_invariant(obj));
3559 static int osd_index_declare_iam_insert(const struct lu_env *env,
3560 struct dt_object *dt,
3561 const struct dt_rec *rec,
3562 const struct dt_key *key,
3563 struct thandle *handle)
3565 struct osd_thandle *oh;
3567 LASSERT(handle != NULL);
3569 oh = container_of0(handle, struct osd_thandle, ot_super);
3570 LASSERT(oh->ot_handle == NULL);
3572 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
3573 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3579 * Inserts (key, value) pair in \a dt index object.
3581 * \param dt osd index object
3582 * \param key key for index
3583 * \param rec record reference
3584 * \param th transaction handler
3587 * \retval -ve failure
3589 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3590 const struct dt_rec *rec,
3591 const struct dt_key *key, struct thandle *th,
3594 struct osd_object *obj = osd_dt_obj(dt);
3595 struct iam_path_descr *ipd;
3596 struct osd_thandle *oh;
3597 struct iam_container *bag;
3598 struct osd_thread_info *oti = osd_oti_get(env);
3599 struct iam_rec *iam_rec;
3603 if (!dt_object_exists(dt))
3606 LINVRNT(osd_invariant(obj));
3607 LASSERT(!dt_object_remote(dt));
3609 bag = &obj->oo_dir->od_container;
3610 LASSERT(bag->ic_object == obj->oo_inode);
3611 LASSERT(th != NULL);
3613 osd_trans_exec_op(env, th, OSD_OT_INSERT);
3615 ipd = osd_idx_ipd_get(env, bag);
3616 if (unlikely(ipd == NULL))
3619 oh = container_of0(th, struct osd_thandle, ot_super);
3620 LASSERT(oh->ot_handle != NULL);
3621 LASSERT(oh->ot_handle->h_transaction != NULL);
3622 if (S_ISDIR(obj->oo_inode->i_mode)) {
3623 iam_rec = (struct iam_rec *)oti->oti_ldp;
3624 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3625 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3626 /* pack quota uid/gid */
3627 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3628 key = (const struct dt_key *)&oti->oti_quota_id;
3629 /* pack quota record */
3630 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3631 iam_rec = (struct iam_rec *)rec;
3633 iam_rec = (struct iam_rec *)rec;
3636 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3638 osd_ipd_put(env, bag, ipd);
3639 LINVRNT(osd_invariant(obj));
3644 * Calls ldiskfs_add_entry() to add directory entry
3645 * into the directory. This is required for
3646 * interoperability mode (b11826)
3648 * \retval 0, on success
3649 * \retval -ve, on error
3651 static int __osd_ea_add_rec(struct osd_thread_info *info,
3652 struct osd_object *pobj, struct inode *cinode,
3653 const char *name, const struct lu_fid *fid,
3654 struct htree_lock *hlock, struct thandle *th)
3656 struct ldiskfs_dentry_param *ldp;
3657 struct dentry *child;
3658 struct osd_thandle *oth;
3661 oth = container_of(th, struct osd_thandle, ot_super);
3662 LASSERT(oth->ot_handle != NULL);
3663 LASSERT(oth->ot_handle->h_transaction != NULL);
3664 LASSERT(pobj->oo_inode);
3666 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3667 if (unlikely(pobj->oo_inode ==
3668 osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
3671 osd_get_ldiskfs_dirent_param(ldp, fid);
3672 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3673 child->d_fsdata = (void *)ldp;
3674 ll_vfs_dq_init(pobj->oo_inode);
3675 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3676 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) {
3677 struct ldiskfs_dir_entry_2 *de;
3678 struct buffer_head *bh;
3681 bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de,
3684 rc1 = ldiskfs_journal_get_write_access(oth->ot_handle,
3687 if (S_ISDIR(cinode->i_mode))
3688 de->file_type = LDISKFS_DIRENT_LUFID |
3689 LDISKFS_FT_REG_FILE;
3691 de->file_type = LDISKFS_DIRENT_LUFID |
3693 ldiskfs_handle_dirty_metadata(oth->ot_handle,
3704 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3705 * into the directory.Also sets flags into osd object to
3706 * indicate dot and dotdot are created. This is required for
3707 * interoperability mode (b11826)
3709 * \param dir directory for dot and dotdot fixup.
3710 * \param obj child object for linking
3712 * \retval 0, on success
3713 * \retval -ve, on error
3715 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3716 struct osd_object *dir,
3717 struct inode *parent_dir, const char *name,
3718 const struct lu_fid *dot_fid,
3719 const struct lu_fid *dot_dot_fid,
3722 struct inode *inode = dir->oo_inode;
3723 struct osd_thandle *oth;
3726 oth = container_of(th, struct osd_thandle, ot_super);
3727 LASSERT(oth->ot_handle->h_transaction != NULL);
3728 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3730 if (strcmp(name, dot) == 0) {
3731 if (dir->oo_compat_dot_created) {
3734 LASSERT(inode == parent_dir);
3735 dir->oo_compat_dot_created = 1;
3738 } else if (strcmp(name, dotdot) == 0) {
3739 if (!dir->oo_compat_dot_created)
3741 /* in case of rename, dotdot is already created */
3742 if (dir->oo_compat_dotdot_created) {
3743 return __osd_ea_add_rec(info, dir, parent_dir, name,
3744 dot_dot_fid, NULL, th);
3747 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
3748 struct lu_fid tfid = *dot_dot_fid;
3751 result = osd_add_dot_dotdot_internal(info,
3752 dir->oo_inode, parent_dir, dot_fid,
3755 result = osd_add_dot_dotdot_internal(info,
3756 dir->oo_inode, parent_dir, dot_fid,
3761 dir->oo_compat_dotdot_created = 1;
3764 /* ldiskfs_init_new_dir() doesn't call ldiskfs_mark_inode_dirty()
3765 * this seem as an optimization as usually it's called
3766 * later to refresh mtime of the parent. Lustre does not
3767 * update mtime in few cases (e.g. PENDING, .lustre)
3768 * we still need to transfer i_size/etc to the buffer cache */
3769 ldiskfs_mark_inode_dirty(oth->ot_handle, dir->oo_inode);
3776 * It will call the appropriate osd_add* function and return the
3777 * value, return by respective functions.
3779 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3780 struct inode *cinode, const char *name,
3781 const struct lu_fid *fid, struct thandle *th)
3783 struct osd_thread_info *info = osd_oti_get(env);
3784 struct htree_lock *hlock;
3787 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3789 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3791 if (hlock != NULL) {
3792 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3795 down_write(&pobj->oo_ext_idx_sem);
3798 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3799 lu_object_fid(&pobj->oo_dt.do_lu),
3802 if (hlock != NULL) {
3803 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3804 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3806 down_write(&pobj->oo_ext_idx_sem);
3809 if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
3810 struct lu_fid *tfid = &info->oti_fid;
3814 rc = __osd_ea_add_rec(info, pobj, cinode, name,
3817 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3822 ldiskfs_htree_unlock(hlock);
3824 up_write(&pobj->oo_ext_idx_sem);
3830 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3831 struct osd_idmap_cache *oic)
3833 struct osd_scrub *scrub = &dev->od_scrub;
3834 struct lu_fid *fid = &oic->oic_fid;
3835 struct osd_inode_id *id = &oti->oti_id;
3840 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3843 if (scrub->os_pos_current > id->oii_ino)
3847 rc = osd_oi_lookup(oti, dev, fid, id, OI_CHECK_FLD);
3848 if (rc != 0 && rc != -ENOENT)
3851 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3854 if (thread_is_running(&scrub->os_thread)) {
3855 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3856 /* There is race condition between osd_oi_lookup and OI scrub.
3857 * The OI scrub finished just after osd_oi_lookup() failure.
3858 * Under such case, it is unnecessary to trigger OI scrub again,
3859 * but try to call osd_oi_lookup() again. */
3860 if (unlikely(rc == -EAGAIN))
3866 if (!dev->od_noscrub && ++once == 1) {
3867 rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN |
3869 CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC "
3870 "for "DFID", rc = %d [2]\n",
3871 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3873 if (rc == 0 || rc == -EALREADY)
3880 static int osd_fail_fid_lookup(struct osd_thread_info *oti,
3881 struct osd_device *dev,
3882 struct osd_idmap_cache *oic,
3883 struct lu_fid *fid, __u32 ino)
3885 struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
3886 struct inode *inode;
3889 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3890 inode = osd_iget(oti, dev, &oic->oic_lid);
3891 if (IS_ERR(inode)) {
3892 fid_zero(&oic->oic_fid);
3893 return PTR_ERR(inode);
3896 rc = osd_get_lma(oti, inode, &oti->oti_obj_dentry, lma);
3899 fid_zero(&oic->oic_fid);
3901 *fid = oic->oic_fid = lma->lma_self_fid;
3905 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
3906 struct osd_inode_id *id, const struct lu_fid *fid)
3908 CDEBUG(D_INODE, "add "DFID" %u:%u to info %p\n", PFID(fid),
3909 id->oii_ino, id->oii_gen, info);
3910 info->oti_cache.oic_lid = *id;
3911 info->oti_cache.oic_fid = *fid;
3912 info->oti_cache.oic_dev = osd;
3916 * Get parent FID from the linkEA.
3918 * For a directory which parent resides on remote MDT, to satisfy the
3919 * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
3920 * the other hand, to make the lookup(..) on the directory can return
3921 * the real parent FID, we append the real parent FID after its ".."
3922 * name entry in the /REMOTE_PARENT_DIR.
3924 * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
3925 * backup. So after the restore, we cannot get the right parent FID from
3926 * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
3927 * we have stored the real parent FID in the directory object's linkEA,
3928 * we can parse the linkEA for the real parent FID.
3930 * \param[in] env pointer to the thread context
3931 * \param[in] obj pointer to the object to be handled
3932 * \param[out]fid pointer to the buffer to hold the parent FID
3934 * \retval 0 for getting the real parent FID successfully
3935 * \retval negative error number on failure
3937 static int osd_get_pfid_from_linkea(const struct lu_env *env,
3938 struct osd_object *obj,
3941 struct osd_thread_info *oti = osd_oti_get(env);
3942 struct lu_buf *buf = &oti->oti_big_buf;
3943 struct dentry *dentry = &oti->oti_obj_dentry;
3944 struct inode *inode = obj->oo_inode;
3945 struct linkea_data ldata = { NULL };
3950 if (!S_ISDIR(inode->i_mode))
3954 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
3955 buf->lb_buf, buf->lb_len);
3956 if (rc == -ERANGE) {
3957 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
3960 lu_buf_realloc(buf, rc);
3961 if (buf->lb_buf == NULL)
3968 if (unlikely(rc == 0))
3974 if (unlikely(buf->lb_buf == NULL)) {
3975 lu_buf_realloc(buf, rc);
3976 if (buf->lb_buf == NULL)
3983 rc = linkea_init(&ldata);
3985 linkea_first_entry(&ldata);
3986 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
3993 * Calls ->lookup() to find dentry. From dentry get inode and
3994 * read inode's ea to get fid. This is required for interoperability
3997 * \retval 0, on success
3998 * \retval -ve, on error
4000 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
4001 struct dt_rec *rec, const struct dt_key *key)
4003 struct inode *dir = obj->oo_inode;
4004 struct dentry *dentry;
4005 struct ldiskfs_dir_entry_2 *de;
4006 struct buffer_head *bh;
4007 struct lu_fid *fid = (struct lu_fid *) rec;
4008 struct htree_lock *hlock = NULL;
4013 LASSERT(dir->i_op != NULL);
4014 LASSERT(dir->i_op->lookup != NULL);
4016 dentry = osd_child_dentry_get(env, obj,
4017 (char *)key, strlen((char *)key));
4019 if (obj->oo_hl_head != NULL) {
4020 hlock = osd_oti_get(env)->oti_hlock;
4021 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4022 dir, LDISKFS_HLOCK_LOOKUP);
4024 down_read(&obj->oo_ext_idx_sem);
4027 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
4029 struct osd_thread_info *oti = osd_oti_get(env);
4030 struct osd_inode_id *id = &oti->oti_id;
4031 struct osd_idmap_cache *oic = &oti->oti_cache;
4032 struct osd_device *dev = osd_obj2dev(obj);
4034 ino = le32_to_cpu(de->inode);
4035 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) {
4037 rc = osd_fail_fid_lookup(oti, dev, oic, fid, ino);
4041 rc = osd_get_fid_from_dentry(de, rec);
4043 /* done with de, release bh */
4046 if (unlikely(ino == osd_remote_parent_ino(dev))) {
4047 const char *name = (const char *)key;
4049 /* If the parent is on remote MDT, and there
4050 * is no FID-in-dirent, then we have to get
4051 * the parent FID from the linkEA. */
4052 if (likely(strlen(name) == 2 &&
4053 name[0] == '.' && name[1] == '.'))
4054 rc = osd_get_pfid_from_linkea(env, obj,
4057 rc = osd_ea_fid_get(env, obj, ino, fid, id);
4060 osd_id_gen(id, ino, OSD_OII_NOGEN);
4064 fid_zero(&oic->oic_fid);
4068 if (osd_remote_fid(env, dev, fid))
4071 osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid);
4072 osd_consistency_check(oti, dev, oic);
4081 ldiskfs_htree_unlock(hlock);
4083 up_read(&obj->oo_ext_idx_sem);
4088 * Find the osd object for given fid.
4090 * \param fid need to find the osd object having this fid
4092 * \retval osd_object on success
4093 * \retval -ve on error
4095 static struct osd_object *osd_object_find(const struct lu_env *env,
4096 struct dt_object *dt,
4097 const struct lu_fid *fid)
4099 struct lu_device *ludev = dt->do_lu.lo_dev;
4100 struct osd_object *child = NULL;
4101 struct lu_object *luch;
4102 struct lu_object *lo;
4105 * at this point topdev might not exist yet
4106 * (i.e. MGS is preparing profiles). so we can
4107 * not rely on topdev and instead lookup with
4108 * our device passed as topdev. this can't work
4109 * if the object isn't cached yet (as osd doesn't
4110 * allocate lu_header). IOW, the object must be
4111 * in the cache, otherwise lu_object_alloc() crashes
4114 luch = lu_object_find_at(env, ludev->ld_site->ls_top_dev == NULL ?
4115 ludev : ludev->ld_site->ls_top_dev,
4117 if (!IS_ERR(luch)) {
4118 if (lu_object_exists(luch)) {
4119 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
4121 child = osd_obj(lo);
4123 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4124 "lu_object can't be located"
4125 DFID"\n", PFID(fid));
4127 if (child == NULL) {
4128 lu_object_put(env, luch);
4129 CERROR("Unable to get osd_object\n");
4130 child = ERR_PTR(-ENOENT);
4133 LU_OBJECT_DEBUG(D_ERROR, env, luch,
4134 "lu_object does not exists "DFID"\n",
4136 lu_object_put(env, luch);
4137 child = ERR_PTR(-ENOENT);
4140 child = ERR_CAST(luch);
4147 * Put the osd object once done with it.
4149 * \param obj osd object that needs to be put
4151 static inline void osd_object_put(const struct lu_env *env,
4152 struct osd_object *obj)
4154 lu_object_put(env, &obj->oo_dt.do_lu);
4157 static int osd_index_declare_ea_insert(const struct lu_env *env,
4158 struct dt_object *dt,
4159 const struct dt_rec *rec,
4160 const struct dt_key *key,
4161 struct thandle *handle)
4163 struct osd_thandle *oh;
4164 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4165 struct lu_fid *fid = (struct lu_fid *)rec;
4169 LASSERT(!dt_object_remote(dt));
4170 LASSERT(handle != NULL);
4172 oh = container_of0(handle, struct osd_thandle, ot_super);
4173 LASSERT(oh->ot_handle == NULL);
4175 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4176 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
4178 if (osd_dt_obj(dt)->oo_inode != NULL) {
4179 struct inode *inode = osd_dt_obj(dt)->oo_inode;
4181 /* We ignore block quota on meta pool (MDTs), so needn't
4182 * calculate how many blocks will be consumed by this index
4184 rc = osd_declare_inode_qid(env, i_uid_read(inode),
4185 i_gid_read(inode), 0, oh,
4186 osd_dt_obj(dt), true, NULL, false);
4192 rc = osd_remote_fid(env, osd, fid);
4198 osd_trans_declare_op(env, oh, OSD_OT_CREATE,
4199 osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
4200 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4201 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4202 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
4203 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
4209 * Index add function for interoperability mode (b11826).
4210 * It will add the directory entry.This entry is needed to
4211 * maintain name->fid mapping.
4213 * \param key it is key i.e. file entry to be inserted
4214 * \param rec it is value of given key i.e. fid
4216 * \retval 0, on success
4217 * \retval -ve, on error
4219 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
4220 const struct dt_rec *rec,
4221 const struct dt_key *key, struct thandle *th,
4224 struct osd_object *obj = osd_dt_obj(dt);
4225 struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
4226 struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
4227 const struct lu_fid *fid = rec1->rec_fid;
4228 const char *name = (const char *)key;
4229 struct osd_thread_info *oti = osd_oti_get(env);
4230 struct osd_inode_id *id = &oti->oti_id;
4231 struct inode *child_inode = NULL;
4232 struct osd_object *child = NULL;
4236 if (!dt_object_exists(dt))
4239 LASSERT(osd_invariant(obj));
4240 LASSERT(!dt_object_remote(dt));
4241 LASSERT(th != NULL);
4243 osd_trans_exec_op(env, th, OSD_OT_INSERT);
4245 LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
4247 rc = osd_remote_fid(env, osd, fid);
4249 CERROR("%s: Can not find object "DFID" rc %d\n",
4250 osd_name(osd), PFID(fid), rc);
4255 /* Insert remote entry */
4256 if (strcmp(name, dotdot) == 0 && strlen(name) == 2) {
4257 struct osd_mdobj_map *omm = osd->od_mdt_map;
4258 struct osd_thandle *oh;
4260 /* If parent on remote MDT, we need put this object
4262 oh = container_of(th, typeof(*oh), ot_super);
4263 rc = osd_add_to_remote_parent(env, osd, obj, oh);
4265 CERROR("%s: add "DFID" error: rc = %d\n",
4267 PFID(lu_object_fid(&dt->do_lu)), rc);
4271 child_inode = igrab(omm->omm_remote_parent->d_inode);
4273 child_inode = osd_create_local_agent_inode(env, osd,
4274 obj, fid, rec1->rec_type & S_IFMT, th);
4275 if (IS_ERR(child_inode))
4276 RETURN(PTR_ERR(child_inode));
4279 /* Insert local entry */
4280 child = osd_object_find(env, dt, fid);
4281 if (IS_ERR(child)) {
4282 CERROR("%s: Can not find object "DFID"%u:%u: rc = %d\n",
4283 osd_name(osd), PFID(fid),
4284 id->oii_ino, id->oii_gen,
4285 (int)PTR_ERR(child));
4286 RETURN(PTR_ERR(child));
4288 child_inode = igrab(child->oo_inode);
4291 rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
4293 CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
4294 obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
4298 osd_object_put(env, child);
4299 LASSERT(osd_invariant(obj));
4304 * Initialize osd Iterator for given osd index object.
4306 * \param dt osd index object
4309 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
4310 struct dt_object *dt,
4313 struct osd_it_iam *it;
4314 struct osd_object *obj = osd_dt_obj(dt);
4315 struct lu_object *lo = &dt->do_lu;
4316 struct iam_path_descr *ipd;
4317 struct iam_container *bag = &obj->oo_dir->od_container;
4319 if (!dt_object_exists(dt))
4320 return ERR_PTR(-ENOENT);
4324 return ERR_PTR(-ENOMEM);
4326 ipd = osd_it_ipd_get(env, bag);
4327 if (likely(ipd != NULL)) {
4331 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
4332 return (struct dt_it *)it;
4335 return ERR_PTR(-ENOMEM);
4340 * free given Iterator.
4343 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
4345 struct osd_it_iam *it = (struct osd_it_iam *)di;
4346 struct osd_object *obj = it->oi_obj;
4348 iam_it_fini(&it->oi_it);
4349 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
4350 lu_object_put(env, &obj->oo_dt.do_lu);
4355 * Move Iterator to record specified by \a key
4357 * \param di osd iterator
4358 * \param key key for index
4360 * \retval +ve di points to record with least key not larger than key
4361 * \retval 0 di points to exact matched key
4362 * \retval -ve failure
4365 static int osd_it_iam_get(const struct lu_env *env,
4366 struct dt_it *di, const struct dt_key *key)
4368 struct osd_thread_info *oti = osd_oti_get(env);
4369 struct osd_it_iam *it = (struct osd_it_iam *)di;
4371 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4372 /* swab quota uid/gid */
4373 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
4374 key = (struct dt_key *)&oti->oti_quota_id;
4377 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
4383 * \param di osd iterator
4385 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
4387 struct osd_it_iam *it = (struct osd_it_iam *)di;
4389 iam_it_put(&it->oi_it);
4393 * Move iterator by one record
4395 * \param di osd iterator
4397 * \retval +1 end of container reached
4399 * \retval -ve failure
4402 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
4404 struct osd_it_iam *it = (struct osd_it_iam *)di;
4406 return iam_it_next(&it->oi_it);
4410 * Return pointer to the key under iterator.
4413 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
4414 const struct dt_it *di)
4416 struct osd_thread_info *oti = osd_oti_get(env);
4417 struct osd_it_iam *it = (struct osd_it_iam *)di;
4418 struct osd_object *obj = it->oi_obj;
4421 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
4423 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
4424 /* swab quota uid/gid */
4425 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
4426 key = (struct dt_key *)&oti->oti_quota_id;
4433 * Return size of key under iterator (in bytes)
4436 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
4438 struct osd_it_iam *it = (struct osd_it_iam *)di;
4440 return iam_it_key_size(&it->oi_it);
4444 osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
4446 /* check if file type is required */
4447 if (ent->lde_attrs & LUDA_TYPE) {
4448 struct luda_type *lt;
4449 int align = sizeof(*lt) - 1;
4451 len = (len + align) & ~align;
4452 lt = (struct luda_type *)(ent->lde_name + len);
4453 lt->lt_type = cpu_to_le16(DTTOIF(type));
4456 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
4460 * build lu direct from backend fs dirent.
4464 osd_it_pack_dirent(struct lu_dirent *ent, struct lu_fid *fid, __u64 offset,
4465 char *name, __u16 namelen, __u16 type, __u32 attr)
4467 ent->lde_attrs = attr | LUDA_FID;
4468 fid_cpu_to_le(&ent->lde_fid, fid);
4470 ent->lde_hash = cpu_to_le64(offset);
4471 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
4473 strncpy(ent->lde_name, name, namelen);
4474 ent->lde_name[namelen] = '\0';
4475 ent->lde_namelen = cpu_to_le16(namelen);
4477 /* append lustre attributes */
4478 osd_it_append_attrs(ent, namelen, type);
4482 * Return pointer to the record under iterator.
4484 static int osd_it_iam_rec(const struct lu_env *env,
4485 const struct dt_it *di,
4486 struct dt_rec *dtrec, __u32 attr)
4488 struct osd_it_iam *it = (struct osd_it_iam *)di;
4489 struct osd_thread_info *info = osd_oti_get(env);
4492 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
4493 const struct osd_fid_pack *rec;
4494 struct lu_fid *fid = &info->oti_fid;
4495 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4501 name = (char *)iam_it_key_get(&it->oi_it);
4503 RETURN(PTR_ERR(name));
4505 namelen = iam_it_key_size(&it->oi_it);
4507 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
4509 RETURN(PTR_ERR(rec));
4511 rc = osd_fid_unpack(fid, rec);
4515 hash = iam_it_store(&it->oi_it);
4517 /* IAM does not store object type in IAM index (dir) */
4518 osd_it_pack_dirent(lde, fid, hash, name, namelen,
4520 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
4521 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4522 (struct iam_rec *)dtrec);
4523 osd_quota_unpack(it->oi_obj, dtrec);
4525 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
4526 (struct iam_rec *)dtrec);
4533 * Returns cookie for current Iterator position.
4535 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
4537 struct osd_it_iam *it = (struct osd_it_iam *)di;
4539 return iam_it_store(&it->oi_it);
4543 * Restore iterator from cookie.
4545 * \param di osd iterator
4546 * \param hash Iterator location cookie
4548 * \retval +ve di points to record with least key not larger than key.
4549 * \retval 0 di points to exact matched key
4550 * \retval -ve failure
4553 static int osd_it_iam_load(const struct lu_env *env,
4554 const struct dt_it *di, __u64 hash)
4556 struct osd_it_iam *it = (struct osd_it_iam *)di;
4558 return iam_it_load(&it->oi_it, hash);
4561 static const struct dt_index_operations osd_index_iam_ops = {
4562 .dio_lookup = osd_index_iam_lookup,
4563 .dio_declare_insert = osd_index_declare_iam_insert,
4564 .dio_insert = osd_index_iam_insert,
4565 .dio_declare_delete = osd_index_declare_iam_delete,
4566 .dio_delete = osd_index_iam_delete,
4568 .init = osd_it_iam_init,
4569 .fini = osd_it_iam_fini,
4570 .get = osd_it_iam_get,
4571 .put = osd_it_iam_put,
4572 .next = osd_it_iam_next,
4573 .key = osd_it_iam_key,
4574 .key_size = osd_it_iam_key_size,
4575 .rec = osd_it_iam_rec,
4576 .store = osd_it_iam_store,
4577 .load = osd_it_iam_load
4583 * Creates or initializes iterator context.
4585 * \retval struct osd_it_ea, iterator structure on success
4588 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
4589 struct dt_object *dt,
4592 struct osd_object *obj = osd_dt_obj(dt);
4593 struct osd_thread_info *info = osd_oti_get(env);
4594 struct osd_it_ea *oie;
4596 struct lu_object *lo = &dt->do_lu;
4597 struct dentry *obj_dentry;
4600 if (!dt_object_exists(dt))
4601 RETURN(ERR_PTR(-ENOENT));
4603 OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
4605 RETURN(ERR_PTR(-ENOMEM));
4606 obj_dentry = &oie->oie_dentry;
4608 obj_dentry->d_inode = obj->oo_inode;
4609 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
4610 obj_dentry->d_name.hash = 0;
4612 oie->oie_rd_dirent = 0;
4613 oie->oie_it_dirent = 0;
4614 oie->oie_dirent = NULL;
4615 if (unlikely(!info->oti_it_ea_buf_used)) {
4616 oie->oie_buf = info->oti_it_ea_buf;
4617 info->oti_it_ea_buf_used = 1;
4619 OBD_ALLOC(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4620 if (oie->oie_buf == NULL)
4621 RETURN(ERR_PTR(-ENOMEM));
4625 file = &oie->oie_file;
4627 /* Only FMODE_64BITHASH or FMODE_32BITHASH should be set, NOT both. */
4628 if (attr & LUDA_64BITHASH)
4629 file->f_mode = FMODE_64BITHASH;
4631 file->f_mode = FMODE_32BITHASH;
4632 file->f_path.dentry = obj_dentry;
4633 file->f_mapping = obj->oo_inode->i_mapping;
4634 file->f_op = obj->oo_inode->i_fop;
4635 set_file_inode(file, obj->oo_inode);
4638 RETURN((struct dt_it *) oie);
4642 * Destroy or finishes iterator context.
4644 * \param di iterator structure to be destroyed
4646 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
4648 struct osd_thread_info *info = osd_oti_get(env);
4649 struct osd_it_ea *oie = (struct osd_it_ea *)di;
4650 struct osd_object *obj = oie->oie_obj;
4651 struct inode *inode = obj->oo_inode;
4654 oie->oie_file.f_op->release(inode, &oie->oie_file);
4655 lu_object_put(env, &obj->oo_dt.do_lu);
4656 if (unlikely(oie->oie_buf != info->oti_it_ea_buf))
4657 OBD_FREE(oie->oie_buf, OSD_IT_EA_BUFSIZE);
4659 info->oti_it_ea_buf_used = 0;
4660 OBD_SLAB_FREE_PTR(oie, osd_itea_cachep);
4665 * It position the iterator at given key, so that next lookup continues from
4666 * that key Or it is similar to dio_it->load() but based on a key,
4667 * rather than file position.
4669 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4672 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4674 static int osd_it_ea_get(const struct lu_env *env,
4675 struct dt_it *di, const struct dt_key *key)
4677 struct osd_it_ea *it = (struct osd_it_ea *)di;
4680 LASSERT(((const char *)key)[0] == '\0');
4681 it->oie_file.f_pos = 0;
4682 it->oie_rd_dirent = 0;
4683 it->oie_it_dirent = 0;
4684 it->oie_dirent = NULL;
4692 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4696 struct osd_filldir_cbs {
4697 #ifdef HAVE_DIR_CONTEXT
4698 struct dir_context ctx;
4700 struct osd_it_ea *it;
4703 * It is called internally by ->readdir(). It fills the
4704 * iterator's in-memory data structure with required
4705 * information i.e. name, namelen, rec_size etc.
4707 * \param buf in which information to be filled in.
4708 * \param name name of the file in given dir
4710 * \retval 0 on success
4711 * \retval 1 on buffer full
4713 static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen,
4714 loff_t offset, __u64 ino,
4717 struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it;
4718 struct osd_object *obj = it->oie_obj;
4719 struct osd_it_ea_dirent *ent = it->oie_dirent;
4720 struct lu_fid *fid = &ent->oied_fid;
4721 struct osd_fid_pack *rec;
4724 /* this should never happen */
4725 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4726 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4730 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4734 /* "." is just the object itself. */
4735 if (namelen == 1 && name[0] == '.') {
4736 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4737 } else if (d_type & LDISKFS_DIRENT_LUFID) {
4738 rec = (struct osd_fid_pack*) (name + namelen + 1);
4739 if (osd_fid_unpack(fid, rec) != 0)
4744 d_type &= ~LDISKFS_DIRENT_LUFID;
4746 /* NOT export local root. */
4747 if (unlikely(osd_sb(osd_obj2dev(obj))->s_root->d_inode->i_ino == ino)) {
4748 ino = obj->oo_inode->i_ino;
4749 *fid = obj->oo_dt.do_lu.lo_header->loh_fid;
4752 ent->oied_ino = ino;
4753 ent->oied_off = offset;
4754 ent->oied_namelen = namelen;
4755 ent->oied_type = d_type;
4757 memcpy(ent->oied_name, name, namelen);
4759 it->oie_rd_dirent++;
4760 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4765 * Calls ->readdir() to load a directory entry at a time
4766 * and stored it in iterator's in-memory data structure.
4768 * \param di iterator's in memory structure
4770 * \retval 0 on success
4771 * \retval -ve on error
4772 * \retval +1 reach the end of entry
4774 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4775 const struct dt_it *di)
4777 struct osd_it_ea *it = (struct osd_it_ea *)di;
4778 struct osd_object *obj = it->oie_obj;
4779 struct inode *inode = obj->oo_inode;
4780 struct htree_lock *hlock = NULL;
4781 struct file *filp = &it->oie_file;
4783 struct osd_filldir_cbs buf = {
4784 #ifdef HAVE_DIR_CONTEXT
4785 .ctx.actor = osd_ldiskfs_filldir,
4791 it->oie_dirent = it->oie_buf;
4792 it->oie_rd_dirent = 0;
4794 if (obj->oo_hl_head != NULL) {
4795 hlock = osd_oti_get(env)->oti_hlock;
4796 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4797 inode, LDISKFS_HLOCK_READDIR);
4799 down_read(&obj->oo_ext_idx_sem);
4802 #ifdef HAVE_DIR_CONTEXT
4803 buf.ctx.pos = filp->f_pos;
4804 rc = inode->i_fop->iterate(filp, &buf.ctx);
4805 filp->f_pos = buf.ctx.pos;
4807 rc = inode->i_fop->readdir(filp, &buf, osd_ldiskfs_filldir);
4811 ldiskfs_htree_unlock(hlock);
4813 up_read(&obj->oo_ext_idx_sem);
4815 if (it->oie_rd_dirent == 0) {
4816 /*If it does not get any dirent, it means it has been reached
4817 *to the end of the dir */
4818 it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
4822 it->oie_dirent = it->oie_buf;
4823 it->oie_it_dirent = 1;
4830 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4831 * to load a directory entry at a time and stored it in
4832 * iterator's in-memory data structure.
4834 * \param di iterator's in memory structure
4836 * \retval +ve iterator reached to end
4837 * \retval 0 iterator not reached to end
4838 * \retval -ve on error
4840 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4842 struct osd_it_ea *it = (struct osd_it_ea *)di;
4847 if (it->oie_it_dirent < it->oie_rd_dirent) {
4849 (void *) it->oie_dirent +
4850 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4851 it->oie_dirent->oied_namelen);
4852 it->oie_it_dirent++;
4855 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4858 rc = osd_ldiskfs_it_fill(env, di);
4865 * Returns the key at current position from iterator's in memory structure.
4867 * \param di iterator's in memory structure
4869 * \retval key i.e. struct dt_key on success
4871 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4872 const struct dt_it *di)
4874 struct osd_it_ea *it = (struct osd_it_ea *)di;
4876 return (struct dt_key *)it->oie_dirent->oied_name;
4880 * Returns the key's size at current position from iterator's in memory structure.
4882 * \param di iterator's in memory structure
4884 * \retval key_size i.e. struct dt_key on success
4886 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4888 struct osd_it_ea *it = (struct osd_it_ea *)di;
4890 return it->oie_dirent->oied_namelen;
4894 osd_dirent_update(handle_t *jh, struct super_block *sb,
4895 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
4896 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de)
4898 struct osd_fid_pack *rec;
4902 LASSERT(de->file_type & LDISKFS_DIRENT_LUFID);
4903 LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack));
4905 rc = ldiskfs_journal_get_write_access(jh, bh);
4909 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
4910 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
4911 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
4917 osd_dirent_has_space(__u16 reclen, __u16 namelen, unsigned blocksize)
4919 if (ldiskfs_rec_len_from_disk(reclen, blocksize) >=
4920 __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack)))
4927 osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot)
4929 LASSERTF(dot_dotdot == 1 || dot_dotdot == 2,
4930 "dot_dotdot = %d\n", dot_dotdot);
4932 if (LDISKFS_DIR_REC_LEN(de) >=
4933 __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack)))
4940 osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
4941 struct inode *dir, struct inode *inode,
4942 struct osd_it_ea_dirent *ent, struct lu_fid *fid,
4943 struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de,
4944 struct htree_lock *hlock)
4946 struct dentry *dentry;
4947 struct osd_fid_pack *rec;
4948 struct ldiskfs_dentry_param *ldp;
4952 if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb,
4953 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
4956 /* There is enough space to hold the FID-in-dirent. */
4957 if (osd_dirent_has_space(de->rec_len, ent->oied_namelen,
4958 dir->i_sb->s_blocksize)) {
4959 rc = ldiskfs_journal_get_write_access(jh, bh);
4963 de->name[de->name_len] = 0;
4964 rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
4965 rec->fp_len = sizeof(struct lu_fid) + 1;
4966 fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
4967 de->file_type |= LDISKFS_DIRENT_LUFID;
4969 rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh);
4974 rc = ldiskfs_delete_entry(jh, dir, de, bh);
4978 dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
4980 ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
4981 osd_get_ldiskfs_dirent_param(ldp, fid);
4982 dentry->d_fsdata = (void *)ldp;
4983 ll_vfs_dq_init(dir);
4984 rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock);
4985 /* It is too bad, we cannot reinsert the name entry back.
4986 * That means we lose it! */
4988 CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
4989 "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
4990 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
4991 dir->i_ino, dir->i_generation,
4992 ent->oied_namelen, ent->oied_name, PFID(fid), rc);
4998 osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj,
4999 struct osd_it_ea *it, struct lu_fid *fid,
5000 struct osd_inode_id *id, __u32 *attr)
5002 struct osd_thread_info *info = osd_oti_get(env);
5003 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
5004 struct osd_device *dev = osd_obj2dev(obj);
5005 struct super_block *sb = osd_sb(dev);
5006 const char *devname =
5007 LDISKFS_SB(sb)->s_es->s_volume_name;
5008 struct osd_it_ea_dirent *ent = it->oie_dirent;
5009 struct inode *dir = obj->oo_inode;
5010 struct htree_lock *hlock = NULL;
5011 struct buffer_head *bh = NULL;
5012 handle_t *jh = NULL;
5013 struct ldiskfs_dir_entry_2 *de;
5014 struct dentry *dentry;
5015 struct inode *inode;
5022 if (ent->oied_name[0] == '.') {
5023 if (ent->oied_namelen == 1)
5025 else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.')
5029 dentry = osd_child_dentry_get(env, obj, ent->oied_name,
5032 /* We need to ensure that the name entry is still valid.
5033 * Because it may be removed or renamed by other already.
5035 * The unlink or rename operation will start journal before PDO lock,
5036 * so to avoid deadlock, here we need to start journal handle before
5037 * related PDO lock also. But because we do not know whether there
5038 * will be something to be repaired before PDO lock, we just start
5039 * journal without conditions.
5041 * We may need to remove the name entry firstly, then insert back.
5042 * One credit is for user quota file update.
5043 * One credit is for group quota file update.
5044 * Two credits are for dirty inode. */
5045 credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] +
5046 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2;
5049 if (dev->od_dirent_journal != 0) {
5050 jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
5053 CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
5054 "check_repair, dir = %lu/%u, credits = %d, "
5055 "name = %.*s: rc = %d\n",
5056 devname, dir->i_ino, dir->i_generation, credits,
5057 ent->oied_namelen, ent->oied_name, rc);
5061 if (obj->oo_hl_head != NULL) {
5062 hlock = osd_oti_get(env)->oti_hlock;
5063 /* "0" means exclusive lock for the whole directory.
5064 * We need to prevent others access such name entry
5065 * during the delete + insert. Neither HLOCK_ADD nor
5066 * HLOCK_DEL cannot guarantee the atomicity. */
5067 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir, 0);
5069 down_write(&obj->oo_ext_idx_sem);
5072 if (obj->oo_hl_head != NULL) {
5073 hlock = osd_oti_get(env)->oti_hlock;
5074 ldiskfs_htree_lock(hlock, obj->oo_hl_head, dir,
5075 LDISKFS_HLOCK_LOOKUP);
5077 down_read(&obj->oo_ext_idx_sem);
5081 bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock);
5082 /* For dot/dotdot entry, if there is not enough space to hold the
5083 * FID-in-dirent, just keep them there. It only happens when the
5084 * device upgraded from 1.8 or restored from MDT file-level backup.
5085 * For the whole directory, only dot/dotdot entry have no FID-in-dirent
5086 * and needs to get FID from LMA when readdir, it will not affect the
5087 * performance much. */
5088 if ((bh == NULL) || (le32_to_cpu(de->inode) != ent->oied_ino) ||
5089 (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
5090 *attr |= LUDA_IGNORE;
5091 GOTO(out_journal, rc = 0);
5094 osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN);
5095 inode = osd_iget(info, dev, id);
5096 if (IS_ERR(inode)) {
5097 rc = PTR_ERR(inode);
5098 if (rc == -ENOENT || rc == -ESTALE)
5101 CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
5102 "check_repair, dir = %lu/%u, name = %.*s: "
5104 devname, dir->i_ino, dir->i_generation,
5105 ent->oied_namelen, ent->oied_name, rc);
5107 GOTO(out_journal, rc);
5110 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
5112 LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI));
5114 if (fid_is_sane(fid)) {
5115 /* FID-in-dirent is valid. */
5116 if (lu_fid_eq(fid, &lma->lma_self_fid))
5117 GOTO(out_inode, rc = 0);
5119 /* Do not repair under dryrun mode. */
5120 if (*attr & LUDA_VERIFY_DRYRUN) {
5121 *attr |= LUDA_REPAIR;
5122 GOTO(out_inode, rc = 0);
5125 if (dev->od_dirent_journal == 0) {
5129 ldiskfs_htree_unlock(hlock);
5131 up_read(&obj->oo_ext_idx_sem);
5132 dev->od_dirent_journal = 1;
5136 *fid = lma->lma_self_fid;
5138 /* Update the FID-in-dirent. */
5139 rc = osd_dirent_update(jh, sb, ent, fid, bh, de);
5141 *attr |= LUDA_REPAIR;
5143 CDEBUG(D_LFSCK, "%.16s: fail to update FID "
5144 "in the dirent, dir = %lu/%u, "
5145 "name = %.*s, "DFID": rc = %d\n",
5146 devname, dir->i_ino, dir->i_generation,
5147 ent->oied_namelen, ent->oied_name,
5150 /* Do not repair under dryrun mode. */
5151 if (*attr & LUDA_VERIFY_DRYRUN) {
5152 *fid = lma->lma_self_fid;
5153 *attr |= LUDA_REPAIR;
5154 GOTO(out_inode, rc = 0);
5157 if (dev->od_dirent_journal == 0) {
5161 ldiskfs_htree_unlock(hlock);
5163 up_read(&obj->oo_ext_idx_sem);
5164 dev->od_dirent_journal = 1;
5168 *fid = lma->lma_self_fid;
5170 /* Append the FID-in-dirent. */
5171 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5172 fid, bh, de, hlock);
5174 *attr |= LUDA_REPAIR;
5176 CDEBUG(D_LFSCK, "%.16s: fail to append FID "
5177 "after the dirent, dir = %lu/%u, "
5178 "name = %.*s, "DFID": rc = %d\n",
5179 devname, dir->i_ino, dir->i_generation,
5180 ent->oied_namelen, ent->oied_name,
5183 } else if (rc == -ENODATA) {
5184 /* Do not repair under dryrun mode. */
5185 if (*attr & LUDA_VERIFY_DRYRUN) {
5186 if (fid_is_sane(fid)) {
5187 *attr |= LUDA_REPAIR;
5189 lu_igif_build(fid, inode->i_ino,
5190 inode->i_generation);
5191 *attr |= LUDA_UPGRADE;
5193 GOTO(out_inode, rc = 0);
5196 if (dev->od_dirent_journal == 0) {
5200 ldiskfs_htree_unlock(hlock);
5202 up_read(&obj->oo_ext_idx_sem);
5203 dev->od_dirent_journal = 1;
5208 if (unlikely(fid_is_sane(fid))) {
5209 /* FID-in-dirent exists, but FID-in-LMA is lost.
5210 * Trust the FID-in-dirent, and add FID-in-LMA. */
5211 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
5213 *attr |= LUDA_REPAIR;
5215 CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
5216 "update dirent, dir = %lu/%u, "
5217 "name = %.*s, "DFID": rc = %d\n",
5218 devname, dir->i_ino, dir->i_generation,
5219 ent->oied_namelen, ent->oied_name,
5222 lu_igif_build(fid, inode->i_ino, inode->i_generation);
5223 /* It is probably IGIF object. Only aappend the
5224 * FID-in-dirent. OI scrub will process FID-in-LMA. */
5225 rc = osd_dirent_reinsert(env, jh, dir, inode, ent,
5226 fid, bh, de, hlock);
5228 *attr |= LUDA_UPGRADE;
5230 CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
5231 "after the dirent, dir = %lu/%u, "
5232 "name = %.*s, "DFID": rc = %d\n",
5233 devname, dir->i_ino, dir->i_generation,
5234 ent->oied_namelen, ent->oied_name,
5239 GOTO(out_inode, rc);
5246 if (hlock != NULL) {
5247 ldiskfs_htree_unlock(hlock);
5249 if (dev->od_dirent_journal != 0)
5250 up_write(&obj->oo_ext_idx_sem);
5252 up_read(&obj->oo_ext_idx_sem);
5255 ldiskfs_journal_stop(jh);
5256 if (rc >= 0 && !dirty)
5257 dev->od_dirent_journal = 0;
5262 * Returns the value at current position from iterator's in memory structure.
5264 * \param di struct osd_it_ea, iterator's in memory structure
5265 * \param attr attr requested for dirent.
5266 * \param lde lustre dirent
5268 * \retval 0 no error and \param lde has correct lustre dirent.
5269 * \retval -ve on error
5271 static inline int osd_it_ea_rec(const struct lu_env *env,
5272 const struct dt_it *di,
5273 struct dt_rec *dtrec, __u32 attr)
5275 struct osd_it_ea *it = (struct osd_it_ea *)di;
5276 struct osd_object *obj = it->oie_obj;
5277 struct osd_device *dev = osd_obj2dev(obj);
5278 struct osd_thread_info *oti = osd_oti_get(env);
5279 struct osd_inode_id *id = &oti->oti_id;
5280 struct lu_fid *fid = &it->oie_dirent->oied_fid;
5281 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
5282 __u32 ino = it->oie_dirent->oied_ino;
5286 LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
5288 if (attr & LUDA_VERIFY) {
5289 if (unlikely(ino == osd_remote_parent_ino(dev))) {
5290 attr |= LUDA_IGNORE;
5291 /* If the parent is on remote MDT, and there
5292 * is no FID-in-dirent, then we have to get
5293 * the parent FID from the linkEA. */
5294 if (!fid_is_sane(fid) &&
5295 it->oie_dirent->oied_namelen == 2 &&
5296 it->oie_dirent->oied_name[0] == '.' &&
5297 it->oie_dirent->oied_name[1] == '.')
5298 osd_get_pfid_from_linkea(env, obj, fid);
5300 rc = osd_dirent_check_repair(env, obj, it, fid, id,
5304 attr &= ~LU_DIRENT_ATTRS_MASK;
5305 if (!fid_is_sane(fid)) {
5306 if (it->oie_dirent->oied_namelen == 2 &&
5307 it->oie_dirent->oied_name[0] == '.' &&
5308 it->oie_dirent->oied_name[1] == '.') {
5309 /* If the parent is on remote MDT, and there
5310 * is no FID-in-dirent, then we have to get
5311 * the parent FID from the linkEA. */
5312 if (ino == osd_remote_parent_ino(dev))
5313 rc = osd_get_pfid_from_linkea(env, obj,
5316 if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
5319 rc = osd_ea_fid_get(env, obj, ino, fid, id);
5322 osd_id_gen(id, ino, OSD_OII_NOGEN);
5326 /* Pack the entry anyway, at least the offset is right. */
5327 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
5328 it->oie_dirent->oied_name,
5329 it->oie_dirent->oied_namelen,
5330 it->oie_dirent->oied_type, attr);
5335 if (osd_remote_fid(env, dev, fid))
5338 if (likely(!(attr & LUDA_IGNORE) && rc == 0))
5339 osd_add_oi_cache(oti, dev, id, fid);
5341 RETURN(rc > 0 ? 0 : rc);
5345 * Returns the record size size at current position.
5347 * This function will return record(lu_dirent) size in bytes.
5349 * \param[in] env execution environment
5350 * \param[in] di iterator's in memory structure
5351 * \param[in] attr attribute of the entry, only requires LUDA_TYPE to
5352 * calculate the lu_dirent size.
5354 * \retval record size(in bytes & in memory) of the current lu_dirent
5357 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
5360 struct osd_it_ea *it = (struct osd_it_ea *)di;
5362 return lu_dirent_calc_size(it->oie_dirent->oied_namelen, attr);
5366 * Returns a cookie for current position of the iterator head, so that
5367 * user can use this cookie to load/start the iterator next time.
5369 * \param di iterator's in memory structure
5371 * \retval cookie for current position, on success
5373 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
5375 struct osd_it_ea *it = (struct osd_it_ea *)di;
5377 return it->oie_dirent->oied_off;
5381 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
5382 * to load a directory entry at a time and stored it i inn,
5383 * in iterator's in-memory data structure.
5385 * \param di struct osd_it_ea, iterator's in memory structure
5387 * \retval +ve on success
5388 * \retval -ve on error
5390 static int osd_it_ea_load(const struct lu_env *env,
5391 const struct dt_it *di, __u64 hash)
5393 struct osd_it_ea *it = (struct osd_it_ea *)di;
5397 it->oie_file.f_pos = hash;
5399 rc = osd_ldiskfs_it_fill(env, di);
5410 * Index lookup function for interoperability mode (b11826).
5412 * \param key, key i.e. file name to be searched
5414 * \retval +ve, on success
5415 * \retval -ve, on error
5417 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
5418 struct dt_rec *rec, const struct dt_key *key)
5420 struct osd_object *obj = osd_dt_obj(dt);
5425 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
5426 LINVRNT(osd_invariant(obj));
5428 rc = osd_ea_lookup_rec(env, obj, rec, key);
5435 * Index and Iterator operations for interoperability
5436 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
5438 static const struct dt_index_operations osd_index_ea_ops = {
5439 .dio_lookup = osd_index_ea_lookup,
5440 .dio_declare_insert = osd_index_declare_ea_insert,
5441 .dio_insert = osd_index_ea_insert,
5442 .dio_declare_delete = osd_index_declare_ea_delete,
5443 .dio_delete = osd_index_ea_delete,
5445 .init = osd_it_ea_init,
5446 .fini = osd_it_ea_fini,
5447 .get = osd_it_ea_get,
5448 .put = osd_it_ea_put,
5449 .next = osd_it_ea_next,
5450 .key = osd_it_ea_key,
5451 .key_size = osd_it_ea_key_size,
5452 .rec = osd_it_ea_rec,
5453 .rec_size = osd_it_ea_rec_size,
5454 .store = osd_it_ea_store,
5455 .load = osd_it_ea_load
5459 static void *osd_key_init(const struct lu_context *ctx,
5460 struct lu_context_key *key)
5462 struct osd_thread_info *info;
5464 OBD_ALLOC_PTR(info);
5466 return ERR_PTR(-ENOMEM);
5468 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5469 if (info->oti_it_ea_buf == NULL)
5472 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
5474 info->oti_hlock = ldiskfs_htree_lock_alloc();
5475 if (info->oti_hlock == NULL)
5481 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5484 return ERR_PTR(-ENOMEM);
5487 static void osd_key_fini(const struct lu_context *ctx,
5488 struct lu_context_key *key, void* data)
5490 struct osd_thread_info *info = data;
5492 if (info->oti_inode != NULL)
5493 OBD_FREE_PTR(info->oti_inode);
5494 if (info->oti_hlock != NULL)
5495 ldiskfs_htree_lock_free(info->oti_hlock);
5496 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
5497 lu_buf_free(&info->oti_iobuf.dr_pg_buf);
5498 lu_buf_free(&info->oti_iobuf.dr_bl_buf);
5499 lu_buf_free(&info->oti_big_buf);
5503 static void osd_key_exit(const struct lu_context *ctx,
5504 struct lu_context_key *key, void *data)
5506 struct osd_thread_info *info = data;
5508 LASSERT(info->oti_r_locks == 0);
5509 LASSERT(info->oti_w_locks == 0);
5510 LASSERT(info->oti_txns == 0);
5513 /* type constructor/destructor: osd_type_init, osd_type_fini */
5514 LU_TYPE_INIT_FINI(osd, &osd_key);
5516 struct lu_context_key osd_key = {
5517 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
5518 .lct_init = osd_key_init,
5519 .lct_fini = osd_key_fini,
5520 .lct_exit = osd_key_exit
5524 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
5525 const char *name, struct lu_device *next)
5527 struct osd_device *osd = osd_dev(d);
5529 if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname))
5530 >= sizeof(osd->od_svname))
5532 return osd_procfs_init(osd, name);
5535 static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
5537 struct seq_server_site *ss = osd_seq_site(osd);
5541 if (osd->od_is_ost || osd->od_cl_seq != NULL)
5544 if (unlikely(ss == NULL))
5547 OBD_ALLOC_PTR(osd->od_cl_seq);
5548 if (osd->od_cl_seq == NULL)
5551 rc = seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
5552 osd->od_svname, ss->ss_server_seq);
5554 OBD_FREE_PTR(osd->od_cl_seq);
5555 osd->od_cl_seq = NULL;
5559 if (ss->ss_node_id == 0) {
5560 /* If the OSD on the sequence controller(MDT0), then allocate
5561 * sequence here, otherwise allocate sequence after connected
5562 * to MDT0 (see mdt_register_lwp_callback()). */
5563 rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
5564 &osd->od_cl_seq->lcs_space, env);
5570 static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
5572 if (osd->od_cl_seq == NULL)
5575 seq_client_fini(osd->od_cl_seq);
5576 OBD_FREE_PTR(osd->od_cl_seq);
5577 osd->od_cl_seq = NULL;
5580 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
5584 /* shutdown quota slave instance associated with the device */
5585 if (o->od_quota_slave != NULL) {
5586 qsd_fini(env, o->od_quota_slave);
5587 o->od_quota_slave = NULL;
5590 osd_fid_fini(env, o);
5595 static void osd_umount(const struct lu_env *env, struct osd_device *o)
5599 if (o->od_mnt != NULL) {
5600 shrink_dcache_sb(osd_sb(o));
5601 osd_sync(env, &o->od_dt_dev);
5610 static int osd_mount(const struct lu_env *env,
5611 struct osd_device *o, struct lustre_cfg *cfg)
5613 const char *name = lustre_cfg_string(cfg, 0);
5614 const char *dev = lustre_cfg_string(cfg, 1);
5616 unsigned long page, s_flags, lmd_flags = 0;
5617 struct page *__page;
5618 struct file_system_type *type;
5619 char *options = NULL;
5621 struct osd_thread_info *info = osd_oti_get(env);
5622 struct lu_fid *fid = &info->oti_fid;
5623 struct inode *inode;
5624 int rc = 0, force_over_128tb = 0;
5627 if (o->od_mnt != NULL)
5630 if (strlen(dev) >= sizeof(o->od_mntdev))
5632 strcpy(o->od_mntdev, dev);
5634 str = lustre_cfg_string(cfg, 2);
5635 s_flags = simple_strtoul(str, NULL, 0);
5636 str = strstr(str, ":");
5638 lmd_flags = simple_strtoul(str + 1, NULL, 0);
5639 opts = lustre_cfg_string(cfg, 3);
5641 if (opts == NULL || strstr(opts, "bigendian_extents") == NULL) {
5642 CERROR("%s: device %s extents feature is not guaranteed to "
5643 "work on big-endian systems. Use \"bigendian_extents\" "
5644 "mount option to override.\n", name, dev);
5648 if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
5649 force_over_128tb = 1;
5651 OBD_PAGE_ALLOC(__page, GFP_IOFS);
5653 GOTO(out, rc = -ENOMEM);
5654 page = (unsigned long)page_address(__page);
5655 options = (char *)page;
5658 /* strip out the options for back compatiblity */
5659 static char *sout[] = {
5666 /* strip out option we processed in osd */
5667 "bigendian_extents",
5671 strcat(options, opts);
5672 for (rc = 0, str = options; sout[rc]; ) {
5673 char *op = strstr(str, sout[rc]);
5679 if (op == options || *(op - 1) == ',') {
5680 str = op + strlen(sout[rc]);
5681 if (*str == ',' || *str == '\0') {
5682 *str == ',' ? str++ : str;
5683 memmove(op, str, strlen(str) + 1);
5686 for (str = op; *str != ',' && *str != '\0'; str++)
5690 strncat(options, "user_xattr,acl", 14);
5693 /* Glom up mount options */
5694 if (*options != '\0')
5695 strcat(options, ",");
5696 strlcat(options, "no_mbcache", PAGE_CACHE_SIZE);
5698 type = get_fs_type("ldiskfs");
5700 CERROR("%s: cannot find ldiskfs module\n", name);
5701 GOTO(out, rc = -ENODEV);
5704 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
5705 module_put(type->owner);
5707 if (IS_ERR(o->od_mnt)) {
5708 rc = PTR_ERR(o->od_mnt);
5710 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
5714 if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (8ULL << 32) &&
5715 force_over_128tb == 0) {
5716 CERROR("%s: device %s LDISKFS does not support filesystems "
5717 "greater than 128TB and can cause data corruption. "
5718 "Use \"force_over_128tb\" mount option to override.\n",
5720 GOTO(out, rc = -EINVAL);
5723 #ifdef HAVE_DEV_SET_RDONLY
5724 if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
5725 CERROR("%s: underlying device %s is marked as read-only. "
5726 "Setup failed\n", name, dev);
5727 GOTO(out_mnt, rc = -EROFS);
5731 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
5732 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
5733 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
5734 GOTO(out_mnt, rc = -EINVAL);
5737 #ifdef LDISKFS_MOUNT_DIRDATA
5738 if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
5739 LDISKFS_FEATURE_INCOMPAT_DIRDATA))
5740 LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
5741 else if (!o->od_is_ost)
5742 CWARN("%s: device %s was upgraded from Lustre-1.x without "
5743 "enabling the dirdata feature. If you do not want to "
5744 "downgrade to Lustre-1.x again, you can enable it via "
5745 "'tune2fs -O dirdata device'\n", name, dev);
5747 inode = osd_sb(o)->s_root->d_inode;
5748 lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
5749 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
5751 CERROR("%s: failed to set lma on %s root inode\n", name, dev);
5755 if (lmd_flags & LMD_FLG_NOSCRUB)
5766 OBD_PAGE_FREE(__page);
5771 static struct lu_device *osd_device_fini(const struct lu_env *env,
5772 struct lu_device *d)
5774 struct osd_device *o = osd_dev(d);
5777 osd_shutdown(env, o);
5779 osd_scrub_cleanup(env, o);
5780 osd_obj_map_fini(o);
5786 static int osd_device_init0(const struct lu_env *env,
5787 struct osd_device *o,
5788 struct lustre_cfg *cfg)
5790 struct lu_device *l = osd2lu_dev(o);
5791 struct osd_thread_info *info;
5795 /* if the module was re-loaded, env can loose its keys */
5796 rc = lu_env_refill((struct lu_env *) env);
5799 info = osd_oti_get(env);
5802 l->ld_ops = &osd_lu_ops;
5803 o->od_dt_dev.dd_ops = &osd_dt_ops;
5805 spin_lock_init(&o->od_osfs_lock);
5806 mutex_init(&o->od_otable_mutex);
5808 o->od_read_cache = 1;
5809 o->od_writethrough_cache = 1;
5810 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
5812 cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4),
5813 sizeof(o->od_svname));
5814 if (cplen >= sizeof(o->od_svname)) {
5819 if (server_name_is_ost(o->od_svname))
5822 o->od_full_scrub_ratio = OFSR_DEFAULT;
5823 o->od_full_scrub_threshold_rate = FULL_SCRUB_THRESHOLD_RATE_DEFAULT;
5824 rc = osd_mount(env, o, cfg);
5828 rc = osd_obj_map_init(env, o);
5832 rc = lu_site_init(&o->od_site, l);
5834 GOTO(out_compat, rc);
5835 o->od_site.ls_bottom_dev = l;
5837 rc = lu_site_init_finish(&o->od_site);
5841 INIT_LIST_HEAD(&o->od_ios_list);
5842 /* setup scrub, including OI files initialization */
5843 rc = osd_scrub_setup(env, o);
5847 rc = osd_procfs_init(o, o->od_svname);
5849 CERROR("%s: can't initialize procfs: rc = %d\n",
5851 GOTO(out_scrub, rc);
5854 LASSERT(l->ld_site->ls_linkage.next != NULL);
5855 LASSERT(l->ld_site->ls_linkage.prev != NULL);
5857 /* initialize quota slave instance */
5858 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
5860 if (IS_ERR(o->od_quota_slave)) {
5861 rc = PTR_ERR(o->od_quota_slave);
5862 o->od_quota_slave = NULL;
5863 GOTO(out_procfs, rc);
5871 osd_scrub_cleanup(env, o);
5873 lu_site_fini(&o->od_site);
5875 osd_obj_map_fini(o);
5882 static struct lu_device *osd_device_alloc(const struct lu_env *env,
5883 struct lu_device_type *t,
5884 struct lustre_cfg *cfg)
5886 struct osd_device *o;
5891 return ERR_PTR(-ENOMEM);
5893 rc = dt_device_init(&o->od_dt_dev, t);
5895 /* Because the ctx might be revived in dt_device_init,
5896 * refill the env here */
5897 lu_env_refill((struct lu_env *)env);
5898 rc = osd_device_init0(env, o, cfg);
5900 dt_device_fini(&o->od_dt_dev);
5903 if (unlikely(rc != 0))
5906 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
5909 static struct lu_device *osd_device_free(const struct lu_env *env,
5910 struct lu_device *d)
5912 struct osd_device *o = osd_dev(d);
5915 /* XXX: make osd top device in order to release reference */
5916 d->ld_site->ls_top_dev = d;
5917 lu_site_purge(env, d->ld_site, -1);
5918 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
5919 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
5920 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
5922 lu_site_fini(&o->od_site);
5923 dt_device_fini(&o->od_dt_dev);
5928 static int osd_process_config(const struct lu_env *env,
5929 struct lu_device *d, struct lustre_cfg *cfg)
5931 struct osd_device *o = osd_dev(d);
5935 switch (cfg->lcfg_command) {
5937 rc = osd_mount(env, o, cfg);
5940 lu_dev_del_linkage(d->ld_site, d);
5941 rc = osd_shutdown(env, o);
5944 LASSERT(&o->od_dt_dev);
5945 rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
5946 cfg, &o->od_dt_dev);
5947 if (rc > 0 || rc == -ENOSYS)
5948 rc = class_process_proc_param(PARAM_OST,
5949 lprocfs_osd_obd_vars,
5950 cfg, &o->od_dt_dev);
5959 static int osd_recovery_complete(const struct lu_env *env,
5960 struct lu_device *d)
5962 struct osd_device *osd = osd_dev(d);
5966 if (osd->od_quota_slave == NULL)
5969 /* start qsd instance on recovery completion, this notifies the quota
5970 * slave code that we are about to process new requests now */
5971 rc = qsd_start(env, osd->od_quota_slave);
5976 * we use exports to track all osd users
5978 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
5979 struct obd_device *obd, struct obd_uuid *cluuid,
5980 struct obd_connect_data *data, void *localdata)
5982 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
5983 struct lustre_handle conn;
5987 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
5989 rc = class_connect(&conn, obd, cluuid);
5993 *exp = class_conn2export(&conn);
5995 spin_lock(&osd->od_osfs_lock);
5997 spin_unlock(&osd->od_osfs_lock);
6003 * once last export (we don't count self-export) disappeared
6004 * osd can be released
6006 static int osd_obd_disconnect(struct obd_export *exp)
6008 struct obd_device *obd = exp->exp_obd;
6009 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6010 int rc, release = 0;
6013 /* Only disconnect the underlying layers on the final disconnect. */
6014 spin_lock(&osd->od_osfs_lock);
6016 if (osd->od_connects == 0)
6018 spin_unlock(&osd->od_osfs_lock);
6020 rc = class_disconnect(exp); /* bz 9811 */
6022 if (rc == 0 && release)
6023 class_manual_cleanup(obd);
6027 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
6028 struct lu_device *dev)
6030 struct osd_device *osd = osd_dev(dev);
6031 struct lr_server_data *lsd =
6032 &osd->od_dt_dev.dd_lu_dev.ld_site->ls_tgt->lut_lsd;
6036 if (osd->od_quota_slave != NULL) {
6037 /* set up quota slave objects */
6038 result = qsd_prepare(env, osd->od_quota_slave);
6043 if (lsd->lsd_feature_incompat & OBD_COMPAT_OST) {
6044 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 52, 0)
6045 if (lsd->lsd_feature_rocompat & OBD_ROCOMPAT_IDX_IN_IDIF) {
6046 osd->od_index_in_idif = 1;
6048 osd->od_index_in_idif = 0;
6049 result = osd_register_proc_index_in_idif(osd);
6054 osd->od_index_in_idif = 1;
6058 result = osd_fid_init(env, osd);
6063 static int osd_fid_alloc(const struct lu_env *env, struct obd_export *exp,
6064 struct lu_fid *fid, struct md_op_data *op_data)
6066 struct osd_device *osd = osd_dev(exp->exp_obd->obd_lu_dev);
6068 return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
6071 static const struct lu_object_operations osd_lu_obj_ops = {
6072 .loo_object_init = osd_object_init,
6073 .loo_object_delete = osd_object_delete,
6074 .loo_object_release = osd_object_release,
6075 .loo_object_free = osd_object_free,
6076 .loo_object_print = osd_object_print,
6077 .loo_object_invariant = osd_object_invariant
6080 const struct lu_device_operations osd_lu_ops = {
6081 .ldo_object_alloc = osd_object_alloc,
6082 .ldo_process_config = osd_process_config,
6083 .ldo_recovery_complete = osd_recovery_complete,
6084 .ldo_prepare = osd_prepare,
6087 static const struct lu_device_type_operations osd_device_type_ops = {
6088 .ldto_init = osd_type_init,
6089 .ldto_fini = osd_type_fini,
6091 .ldto_start = osd_type_start,
6092 .ldto_stop = osd_type_stop,
6094 .ldto_device_alloc = osd_device_alloc,
6095 .ldto_device_free = osd_device_free,
6097 .ldto_device_init = osd_device_init,
6098 .ldto_device_fini = osd_device_fini
6101 static struct lu_device_type osd_device_type = {
6102 .ldt_tags = LU_DEVICE_DT,
6103 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
6104 .ldt_ops = &osd_device_type_ops,
6105 .ldt_ctx_tags = LCT_LOCAL,
6108 static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
6110 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
6111 struct super_block *sb = osd_sb(osd);
6113 return (osd->od_mnt == NULL || sb->s_flags & MS_RDONLY);
6117 * lprocfs legacy support.
6119 static struct obd_ops osd_obd_device_ops = {
6120 .o_owner = THIS_MODULE,
6121 .o_connect = osd_obd_connect,
6122 .o_disconnect = osd_obd_disconnect,
6123 .o_fid_alloc = osd_fid_alloc,
6124 .o_health_check = osd_health_check,
6127 static int __init osd_mod_init(void)
6131 #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK)
6132 /* please, try to keep osd_thread_info smaller than a page */
6133 CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE);
6138 rc = lu_kmem_init(ldiskfs_caches);
6142 rc = class_register_type(&osd_obd_device_ops, NULL, true,
6143 lprocfs_osd_module_vars,
6144 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
6146 lu_kmem_fini(ldiskfs_caches);
6150 static void __exit osd_mod_exit(void)
6152 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
6153 lu_kmem_fini(ldiskfs_caches);
6156 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6157 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
6158 MODULE_VERSION(LUSTRE_VERSION_STRING);
6159 MODULE_LICENSE("GPL");
6161 module_init(osd_mod_init);
6162 module_exit(osd_mod_exit);