X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fosd-ldiskfs%2Fosd_handler.c;h=a928e77c3643c38e9511801f6ab34db0be44c448;hp=1815db21e8cb3908a53e2408b6fc55c377a150dc;hb=cfa981f3bf06d602aee998e64d4758e13f48aab8;hpb=2fe22edfe3c365b5c270050fdeed0a86fa74a919 diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 1815db2..a928e77 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2014, Intel Corporation. + * Copyright (c) 2011, 2016, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -60,6 +56,7 @@ #include #include +#include #undef ENTRY /* * struct OBD_{ALLOC,FREE}*() @@ -82,12 +79,12 @@ #include int ldiskfs_pdo = 1; -CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644, - "ldiskfs with parallel directory operations"); +module_param(ldiskfs_pdo, int, 0644); +MODULE_PARM_DESC(ldiskfs_pdo, "ldiskfs with parallel directory operations"); int ldiskfs_track_declares_assert; -CFS_MODULE_PARM(ldiskfs_track_declares_assert, "i", int, 0644, - "LBUG during tracking of declares"); +module_param(ldiskfs_track_declares_assert, int, 0644); +MODULE_PARM_DESC(ldiskfs_track_declares_assert, "LBUG during tracking of declares"); /* Slab to allocate dynlocks */ struct kmem_cache *dynlock_cachep; @@ -122,6 +119,11 @@ static const struct dt_object_operations osd_obj_otable_it_ops; static const struct dt_index_operations osd_index_iam_ops; static const struct dt_index_operations osd_index_ea_ops; +static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd, + const struct lu_fid *fid); +static int osd_process_scheduled_agent_removals(const struct lu_env *env, + struct osd_device *osd); + int osd_trans_declare_op2rb[] = { [OSD_OT_ATTR_SET] = OSD_OT_ATTR_SET, [OSD_OT_PUNCH] = OSD_OT_MAX, @@ -170,6 +172,153 @@ static int osd_root_get(const struct lu_env *env, } /* + * the following set of functions are used to maintain per-thread + * cache of FID->ino mapping. this mechanism is needed to resolve + * FID to inode at dt_insert() which in turn stores ino in the + * directory entries to keep ldiskfs compatible with ext[34]. + * due to locking-originated restrictions we can't lookup ino + * using LU cache (deadlock is possible). lookup using OI is quite + * expensive. so instead we maintain this cache and methods like + * dt_create() fill it. so in the majority of cases dt_insert() is + * able to find needed mapping in lockless manner. + */ +static struct osd_idmap_cache * +osd_idc_find(const struct lu_env *env, struct osd_device *osd, + const struct lu_fid *fid) +{ + struct osd_thread_info *oti = osd_oti_get(env); + struct osd_idmap_cache *idc = oti->oti_ins_cache; + int i; + for (i = 0; i < oti->oti_ins_cache_used; i++) { + if (!lu_fid_eq(&idc[i].oic_fid, fid)) + continue; + if (idc[i].oic_dev != osd) + continue; + + return idc + i; + } + + return NULL; +} + +static struct osd_idmap_cache * +osd_idc_add(const struct lu_env *env, struct osd_device *osd, + const struct lu_fid *fid) +{ + struct osd_thread_info *oti = osd_oti_get(env); + struct osd_idmap_cache *idc; + int i; + + if (unlikely(oti->oti_ins_cache_used >= oti->oti_ins_cache_size)) { + i = oti->oti_ins_cache_size * 2; + if (i == 0) + i = OSD_INS_CACHE_SIZE; + OBD_ALLOC(idc, sizeof(*idc) * i); + if (idc == NULL) + return ERR_PTR(-ENOMEM); + if (oti->oti_ins_cache != NULL) { + memcpy(idc, oti->oti_ins_cache, + oti->oti_ins_cache_used * sizeof(*idc)); + OBD_FREE(oti->oti_ins_cache, + oti->oti_ins_cache_used * sizeof(*idc)); + } + oti->oti_ins_cache = idc; + oti->oti_ins_cache_size = i; + } + + idc = oti->oti_ins_cache + oti->oti_ins_cache_used++; + idc->oic_fid = *fid; + idc->oic_dev = osd; + idc->oic_lid.oii_ino = 0; + idc->oic_lid.oii_gen = 0; + idc->oic_remote = 0; + + return idc; +} + +/* + * lookup mapping for the given fid in the cache, initialize a + * new one if not found. the initialization checks whether the + * object is local or remote. for local objects, OI is used to + * learn ino/generation. the function is used when the caller + * has no information about the object, e.g. at dt_insert(). + */ +static struct osd_idmap_cache * +osd_idc_find_or_init(const struct lu_env *env, struct osd_device *osd, + const struct lu_fid *fid) +{ + struct osd_idmap_cache *idc; + int rc; + + idc = osd_idc_find(env, osd, fid); + LASSERT(!IS_ERR(idc)); + if (idc != NULL) + return idc; + + /* new mapping is needed */ + idc = osd_idc_add(env, osd, fid); + if (IS_ERR(idc)) + return idc; + + /* initialize it */ + rc = osd_remote_fid(env, osd, fid); + if (unlikely(rc < 0)) + return ERR_PTR(rc); + + if (rc == 0) { + /* the object is local, lookup in OI */ + /* XXX: probably cheaper to lookup in LU first? */ + rc = osd_oi_lookup(osd_oti_get(env), osd, fid, + &idc->oic_lid, 0); + if (unlikely(rc < 0)) { + CERROR("can't lookup: rc = %d\n", rc); + return ERR_PTR(rc); + } + } else { + /* the object is remote */ + idc->oic_remote = 1; + } + + return idc; +} + +/* + * lookup mapping for given FID and fill it from the given object. + * the object is lolcal by definition. + */ +static int osd_idc_find_and_init(const struct lu_env *env, + struct osd_device *osd, + struct osd_object *obj) +{ + const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu); + struct osd_idmap_cache *idc; + + idc = osd_idc_find(env, osd, fid); + LASSERT(!IS_ERR(idc)); + if (idc != NULL) { + if (obj->oo_inode == NULL) + return 0; + if (idc->oic_lid.oii_ino != obj->oo_inode->i_ino) { + LASSERT(idc->oic_lid.oii_ino == 0); + idc->oic_lid.oii_ino = obj->oo_inode->i_ino; + idc->oic_lid.oii_gen = obj->oo_inode->i_generation; + } + return 0; + } + + /* new mapping is needed */ + idc = osd_idc_add(env, osd, fid); + if (IS_ERR(idc)) + return PTR_ERR(idc); + + if (obj->oo_inode != NULL) { + idc->oic_lid.oii_ino = obj->oo_inode->i_ino; + idc->oic_lid.oii_gen = obj->oo_inode->i_generation; + } + return 0; +} + +/* * OSD object methods. */ @@ -194,6 +343,7 @@ static struct lu_object *osd_object_alloc(const struct lu_env *env, init_rwsem(&mo->oo_sem); init_rwsem(&mo->oo_ext_idx_sem); spin_lock_init(&mo->oo_guard); + INIT_LIST_HEAD(&mo->oo_xattr_list); return l; } else { return NULL; @@ -235,8 +385,14 @@ int osd_get_lma(struct osd_thread_info *info, struct inode *inode, struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev, struct osd_inode_id *id) { + int rc; struct inode *inode = NULL; + /* if we look for an inode withing a running + * transaction, then we risk to deadlock */ + /* osd_dirent_check_repair() breaks this */ + /*LASSERT(current->journal_info == NULL);*/ + inode = ldiskfs_iget(osd_sb(dev), id->oii_ino); if (IS_ERR(inode)) { CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n", @@ -259,7 +415,11 @@ struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev, LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino); iput(inode); inode = ERR_PTR(-ENOENT); + } else if ((rc = osd_attach_jinode(inode))) { + iput(inode); + inode = ERR_PTR(rc); } else { + ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY); if (id->oii_gen == OSD_OII_NOGEN) osd_id_gen(id, inode->i_ino, inode->i_generation); @@ -274,6 +434,52 @@ struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev, return inode; } +int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd, + handle_t *handle, struct dentry *child, + struct inode *inode, struct htree_lock *hlock) +{ + int rc, rc2; + + rc = __ldiskfs_add_entry(handle, child, inode, hlock); + if (rc == -ENOBUFS || rc == -ENOSPC) { + struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs; + struct inode *parent = child->d_parent->d_inode; + struct lu_fid *fid = NULL; + + rc2 = osd_get_lma(info, parent, child->d_parent, lma); + if (rc2 == 0) { + fid = &lma->lma_self_fid; + } else if (rc2 == -ENODATA) { + if (unlikely(parent == inode->i_sb->s_root->d_inode)) { + fid = &info->oti_fid3; + lu_local_obj_fid(fid, OSD_FS_ROOT_OID); + } else if (!osd->od_is_ost && osd->od_index == 0) { + fid = &info->oti_fid3; + lu_igif_build(fid, parent->i_ino, + parent->i_generation); + } + } + + if (fid != NULL) + CWARN("%s: directory (inode: %lu, FID: "DFID") %s " + "maximum entry limit\n", + osd_name(osd), parent->i_ino, PFID(fid), + rc == -ENOSPC ? "has reached" : "is approaching"); + else + CWARN("%s: directory (inode: %lu, FID: unknown) %s " + "maximum entry limit\n", + osd_name(osd), parent->i_ino, + rc == -ENOSPC ? "has reached" : "is approaching"); + + /* ignore such error now */ + if (rc == -ENOBUFS) + rc = 0; + } + + return rc; +} + + static struct inode * osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev, struct osd_inode_id *id, struct lu_fid *fid) @@ -301,6 +507,136 @@ osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev, return inode; } +static struct inode *osd_iget_check(struct osd_thread_info *info, + struct osd_device *dev, + const struct lu_fid *fid, + struct osd_inode_id *id, + bool cached) +{ + struct inode *inode; + int rc = 0; + ENTRY; + + /* The cached OI mapping is trustable. If we cannot locate the inode + * via the cached OI mapping, then return the failure to the caller + * directly without further OI checking. */ + + inode = ldiskfs_iget(osd_sb(dev), id->oii_ino); + if (IS_ERR(inode)) { + rc = PTR_ERR(inode); + if (cached || (rc != -ENOENT && rc != -ESTALE)) { + CDEBUG(D_INODE, "no inode: ino = %u, rc = %d\n", + id->oii_ino, rc); + + GOTO(put, rc); + } + + goto check_oi; + } + + if (is_bad_inode(inode)) { + rc = -ENOENT; + if (cached) { + CDEBUG(D_INODE, "bad inode: ino = %u\n", id->oii_ino); + + GOTO(put, rc); + } + + goto check_oi; + } + + if (id->oii_gen != OSD_OII_NOGEN && + inode->i_generation != id->oii_gen) { + rc = -ESTALE; + if (cached) { + CDEBUG(D_INODE, "unmatched inode: ino = %u, " + "oii_gen = %u, i_generation = %u\n", + id->oii_ino, id->oii_gen, inode->i_generation); + + GOTO(put, rc); + } + + goto check_oi; + } + + if (inode->i_nlink == 0) { + rc = -ENOENT; + if (cached) { + CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino); + + GOTO(put, rc); + } + + goto check_oi; + } + + ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY); + +check_oi: + if (rc != 0) { + LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc); + + rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD); + /* XXX: There are four possible cases: + * 1. rc = 0. + * Backup/restore caused the OI invalid. + * 2. rc = 0. + * Someone unlinked the object but NOT removed + * the OI mapping, such as mount target device + * as ldiskfs, and modify something directly. + * 3. rc = -ENOENT. + * Someone just removed the object between the + * former oi_lookup and the iget. It is normal. + * 4. Other failure cases. + * + * Generally, when the device is mounted, it will + * auto check whether the system is restored from + * file-level backup or not. We trust such detect + * to distinguish the 1st case from the 2nd case: + * if the OI files are consistent but may contain + * stale OI mappings because of case 2, if iget() + * returns -ENOENT or -ESTALE, then it should be + * the case 2. */ + if (rc != 0) + /* If the OI mapping was in OI file before the + * osd_iget_check(), but now, it is disappear, + * then it must be removed by race. That is a + * normal race case. */ + GOTO(put, rc); + + if ((!IS_ERR(inode) && inode->i_generation != 0 && + inode->i_generation == id->oii_gen) || + (IS_ERR(inode) && !(dev->od_scrub.os_file.sf_flags & + SF_INCONSISTENT))) + rc = -ENOENT; + else + rc = -EREMCHG; + } else { + if (id->oii_gen == OSD_OII_NOGEN) + osd_id_gen(id, inode->i_ino, inode->i_generation); + + /* Do not update file c/mtime in ldiskfs. + * NB: we don't have any lock to protect this because we don't + * have reference on osd_object now, but contention with + * another lookup + attr_set can't happen in the tiny window + * between if (...) and set S_NOCMTIME. */ + if (!(inode->i_flags & S_NOCMTIME)) + inode->i_flags |= S_NOCMTIME; + } + + GOTO(put, rc); + +put: + if (rc != 0) { + if (!IS_ERR(inode)) + iput(inode); + + inode = ERR_PTR(rc); + } + + return inode; +} + /** * \retval +v: new filter_fid, does not contain self-fid * \retval 0: filter_fid_old, contains self-fid @@ -318,7 +654,8 @@ int osd_get_idif(struct osd_thread_info *info, struct inode *inode, rc = 0; ostid_set_seq(ostid, le64_to_cpu(ff->ff_seq)); ostid_set_id(ostid, le64_to_cpu(ff->ff_objid)); - /* XXX: should use real OST index in the future. LU-3569 */ + /* XXX: use 0 as the index for compatibility, the caller will + * handle index related issues when necessarry. */ ostid_to_fid(fid, ostid, 0); } else if (rc == sizeof(struct filter_fid)) { rc = 1; @@ -385,9 +722,6 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj) } } - if (unlikely(rc == -ENODATA)) - RETURN(0); - if (rc < 0) RETURN(rc); @@ -436,6 +770,185 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj) RETURN(rc); } +struct osd_check_lmv_buf { +#ifdef HAVE_DIR_CONTEXT + /* please keep it as first member */ + struct dir_context ctx; +#endif + struct osd_thread_info *oclb_info; + struct osd_device *oclb_dev; + struct osd_idmap_cache *oclb_oic; +}; + +/** + * It is called internally by ->readdir() to filter out the + * local slave object's FID of the striped directory. + * + * \retval 1 found the local slave's FID + * \retval 0 continue to check next item + * \retval -ve for failure + */ +#ifdef HAVE_FILLDIR_USE_CTX +static int osd_stripe_dir_filldir(struct dir_context *buf, +#else +static int osd_stripe_dir_filldir(void *buf, +#endif + const char *name, int namelen, + loff_t offset, __u64 ino, unsigned d_type) +{ + struct osd_check_lmv_buf *oclb = (struct osd_check_lmv_buf *)buf; + struct osd_thread_info *oti = oclb->oclb_info; + struct lu_fid *fid = &oti->oti_fid3; + struct osd_inode_id *id = &oti->oti_id3; + struct osd_device *dev = oclb->oclb_dev; + struct osd_idmap_cache *oic = oclb->oclb_oic; + struct inode *inode; + int rc; + + if (name[0] == '.') + return 0; + + fid_zero(fid); + sscanf(name + 1, SFID, RFID(fid)); + if (!fid_is_sane(fid)) + return 0; + + if (osd_remote_fid(oti->oti_env, dev, fid)) + return 0; + + osd_id_gen(id, ino, OSD_OII_NOGEN); + inode = osd_iget(oti, dev, id); + if (IS_ERR(inode)) + return PTR_ERR(inode); + + iput(inode); + osd_add_oi_cache(oti, dev, id, fid); + oic->oic_fid = *fid; + oic->oic_lid = *id; + oic->oic_dev = dev; + rc = osd_oii_insert(dev, oic, true); + + return rc == 0 ? 1 : rc; +} + +/* When lookup item under striped directory, we need to locate the master + * MDT-object of the striped directory firstly, then the client will send + * lookup (getattr_by_name) RPC to the MDT with some slave MDT-object's FID + * and the item's name. If the system is restored from MDT file level backup, + * then before the OI scrub completely built the OI files, the OI mappings of + * the master MDT-object and slave MDT-object may be invalid. Usually, it is + * not a problem for the master MDT-object. Because when locate the master + * MDT-object, we will do name based lookup (for the striped directory itself) + * firstly, during such process we can setup the correct OI mapping for the + * master MDT-object. But it will be trouble for the slave MDT-object. Because + * the client will not trigger name based lookup on the MDT to locate the slave + * MDT-object before locating item under the striped directory, then when + * osd_fid_lookup(), it will find that the OI mapping for the slave MDT-object + * is invalid and does not know what the right OI mapping is, then the MDT has + * to return -EINPROGRESS to the client to notify that the OI scrub is rebuiding + * the OI file, related OI mapping is unknown yet, please try again later. And + * then client will re-try the RPC again and again until related OI mapping has + * been updated. That is quite inefficient. + * + * To resolve above trouble, we will handle it as the following two cases: + * + * 1) The slave MDT-object and the master MDT-object are on different MDTs. + * It is relative easy. Be as one of remote MDT-objects, the slave MDT-object + * is linked under /REMOTE_PARENT_DIR with the name of its FID string. + * We can locate the slave MDT-object via lookup the /REMOTE_PARENT_DIR + * directly. Please check osd_fid_lookup(). + * + * 2) The slave MDT-object and the master MDT-object reside on the same MDT. + * Under such case, during lookup the master MDT-object, we will lookup the + * slave MDT-object via readdir against the master MDT-object, because the + * slave MDT-objects information are stored as sub-directories with the name + * "${FID}:${index}". Then when find the local slave MDT-object, its OI + * mapping will be recorded. Then subsequent osd_fid_lookup() will know + * the correct OI mapping for the slave MDT-object. */ +static int osd_check_lmv(struct osd_thread_info *oti, struct osd_device *dev, + struct inode *inode, struct osd_idmap_cache *oic) +{ + struct lu_buf *buf = &oti->oti_big_buf; + struct dentry *dentry = &oti->oti_obj_dentry; + struct file *filp = &oti->oti_file; + const struct file_operations *fops; + struct lmv_mds_md_v1 *lmv1; + struct osd_check_lmv_buf oclb = { +#ifdef HAVE_DIR_CONTEXT + .ctx.actor = osd_stripe_dir_filldir, +#endif + .oclb_info = oti, + .oclb_dev = dev, + .oclb_oic = oic + }; + int rc = 0; + ENTRY; + +again: + rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, buf->lb_buf, + buf->lb_len); + if (rc == -ERANGE) { + rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LMV, NULL, 0); + if (rc > 0) { + lu_buf_realloc(buf, rc); + if (buf->lb_buf == NULL) + GOTO(out, rc = -ENOMEM); + + goto again; + } + } + + if (unlikely(rc == 0 || rc == -ENODATA)) + GOTO(out, rc = 0); + + if (rc < 0) + GOTO(out, rc); + + if (unlikely(buf->lb_buf == NULL)) { + lu_buf_realloc(buf, rc); + if (buf->lb_buf == NULL) + GOTO(out, rc = -ENOMEM); + + goto again; + } + + lmv1 = buf->lb_buf; + if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1) + GOTO(out, rc = 0); + + fops = inode->i_fop; + dentry->d_inode = inode; + dentry->d_sb = inode->i_sb; + filp->f_pos = 0; + filp->f_path.dentry = dentry; + filp->f_mode = FMODE_64BITHASH; + filp->f_mapping = inode->i_mapping; + filp->f_op = fops; + filp->private_data = NULL; + set_file_inode(filp, inode); + +#ifdef HAVE_DIR_CONTEXT + oclb.ctx.pos = filp->f_pos; + rc = fops->iterate(filp, &oclb.ctx); + filp->f_pos = oclb.ctx.pos; +#else + rc = fops->readdir(filp, &oclb, osd_stripe_dir_filldir); +#endif + fops->release(inode, filp); + +out: + if (rc < 0) + CDEBUG(D_LFSCK, "%.16s: fail to check LMV EA, inode = %lu/%u," + DFID": rc = %d\n", + LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, + inode->i_ino, inode->i_generation, + PFID(&oic->oic_fid), rc); + else + rc = 0; + + RETURN(rc); +} + static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, const struct lu_fid *fid, const struct lu_object_conf *conf) @@ -445,14 +958,18 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, struct osd_device *dev; struct osd_idmap_cache *oic; struct osd_inode_id *id; - struct inode *inode; + struct osd_inode_id *tid; + struct inode *inode = NULL; struct osd_scrub *scrub; struct scrub_file *sf; - int result; - int saved = 0; - bool in_oi = false; - bool in_cache = false; - bool triggered = false; + __u32 flags = SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT | + SS_AUTO_FULL; + __u32 saved_ino; + __u32 saved_gen; + int result = 0; + int rc1 = 0; + bool cached = true; + bool remote = false; ENTRY; LINVRNT(osd_invariant(obj)); @@ -466,7 +983,7 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, LASSERT(info); oic = &info->oti_cache; - if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT)) + if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT)) RETURN(-ENOENT); /* For the object is created as locking anchor, or for the object to @@ -481,7 +998,6 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, if (lu_fid_eq(fid, &oic->oic_fid) && likely(oic->oic_dev == dev)) { id = &oic->oic_lid; - in_cache = true; goto iget; } @@ -493,10 +1009,12 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, goto iget; } + cached = false; /* Search order: 3. OI files. */ result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD); if (result == -ENOENT) { if (!(fid_is_norm(fid) || fid_is_igif(fid)) || + fid_is_on_ost(info, dev, fid, OI_CHECK_FLD) || !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid), sf->sf_oi_bitmap)) GOTO(out, result = 0); @@ -507,116 +1025,184 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj, if (result != 0) GOTO(out, result); - in_oi = true; - iget: - inode = osd_iget(info, dev, id); + inode = osd_iget_check(info, dev, fid, id, cached); if (IS_ERR(inode)) { result = PTR_ERR(inode); - if (result != -ENOENT && result != -ESTALE) - GOTO(out, result); + if (result == -ENOENT || result == -ESTALE) + GOTO(out, result = 0); - if (in_cache) - fid_zero(&oic->oic_fid); + if (result == -EREMCHG) { - result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD); - if (result != 0) - GOTO(out, result = (result == -ENOENT ? 0 : result)); +trigger: + /* We still have chance to get the valid inode: for the + * object which is referenced by remote name entry, the + * object on the local MDT will be linked under the dir + * of "/REMOTE_PARENT_DIR" with its FID string as name. + * + * We do not know whether the object for the given FID + * is referenced by some remote name entry or not, and + * especially for DNE II, a multiple-linked object may + * have many name entries reside on many MDTs. + * + * To simplify the operation, OSD will not distinguish + * more, just lookup "/REMOTE_PARENT_DIR". Usually, it + * only happened for the RPC from other MDT during the + * OI scrub, or for the client side RPC with FID only, + * such as FID to path, or from old connected client. */ + if (!remote && + !fid_is_on_ost(info, dev, fid, OI_CHECK_FLD)) { + rc1 = osd_lookup_in_remote_parent(info, dev, + fid, id); + if (rc1 == 0) { + remote = true; + cached = true; + flags |= SS_AUTO_PARTIAL; + flags &= ~SS_AUTO_FULL; + goto iget; + } + } - /* The OI mapping is there, but the inode is NOT there. - * Two possible cases for that: - * - * 1) Backup/restore caused the OI invalid. - * 2) Someone unlinked the object but NOT removed - * the OI mapping, such as mount target device - * as ldiskfs, and modify something directly. - * - * Generally, when the device is mounted, it will - * auto check whether the system is restored from - * file-level backup or not. We trust such detect - * to distinguish the 1st case from the 2nd case. */ - if (!(scrub->os_file.sf_flags & SF_INCONSISTENT)) - GOTO(out, result = 0); + if (thread_is_running(&scrub->os_thread)) { + if (scrub->os_partial_scan && + !scrub->os_in_join) { + goto join; + } else { + if (inode != NULL && !IS_ERR(inode)) { + LASSERT(remote); -trigger: - if (unlikely(triggered)) - GOTO(out, result = saved); - - triggered = true; - if (thread_is_running(&scrub->os_thread)) { - result = -EINPROGRESS; - } else if (!dev->od_noscrub) { - /* Since we do not know the right OI mapping, we have - * to trigger OI scrub to scan the whole device. */ - result = osd_scrub_start(dev, SS_AUTO_FULL | - SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT); - CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI " - "scrub by RPC for "DFID", rc = %d [1]\n", - osd_name(dev), PFID(fid), result); - if (result == 0 || result == -EALREADY) - result = -EINPROGRESS; - else + osd_add_oi_cache(info, dev, id, + fid); + osd_oii_insert(dev, oic, true); + } else { + result = -EINPROGRESS; + } + } + } else if (!dev->od_noscrub) { + +join: + rc1 = osd_scrub_start(dev, flags); + LCONSOLE_WARN("%.16s: trigger OI scrub by RPC " + "for the "DFID" with flags 0x%x," + " rc = %d\n", osd_name(dev), + PFID(fid), flags, rc1); + if (rc1 == 0 || rc1 == -EALREADY) { + if (inode != NULL && !IS_ERR(inode)) { + LASSERT(remote); + + osd_add_oi_cache(info, dev, id, + fid); + osd_oii_insert(dev, oic, true); + } else { + result = -EINPROGRESS; + } + } else { + result = -EREMCHG; + } + } else { result = -EREMCHG; + } } - /* We still have chance to get the valid inode: for the - * object which is referenced by remote name entry, the - * object on the local MDT will be linked under the dir - * of "/REMOTE_PARENT_DIR" with its FID string as name. - * - * We do not know whether the object for the given FID - * is referenced by some remote name entry or not, and - * especially for DNE II, a multiple-linked object may - * have many name entries reside on many MDTs. - * - * To simplify the operation, OSD will not distinguish - * more, just lookup "/REMOTE_PARENT_DIR". Usually, it - * only happened for the RPC from other MDT during the - * OI scrub, or for the client side RPC with FID only, - * such as FID to path, or from old connected client. */ - saved = result; - result = osd_lookup_in_remote_parent(info, dev, fid, id); - if (result == 0) { - in_oi = false; - goto iget; - } - - GOTO(out, result = saved); + if (inode == NULL || IS_ERR(inode)) + GOTO(out, result); + } else if (remote) { + goto trigger; } obj->oo_inode = inode; LASSERT(obj->oo_inode->i_sb == osd_sb(dev)); result = osd_check_lma(env, obj); - if (result != 0) { - iput(inode); - obj->oo_inode = NULL; + if (result == 0) + goto found; - if (result != -EREMCHG) - GOTO(out, result); + tid = &info->oti_id3; + LASSERT(tid != id); - if (in_cache) - fid_zero(&oic->oic_fid); + if (result == -ENODATA) { + if (!cached) + /* The current OI mapping is from the OI file, + * since the inode has been found via + * osd_iget_check(), no need recheck OI. */ + goto found; - result = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD); - if (result == 0) - goto trigger; + result = osd_oi_lookup(info, dev, fid, tid, OI_CHECK_FLD); + if (result == 0) { + LASSERTF(tid->oii_ino == id->oii_ino && + tid->oii_gen == id->oii_gen, + "OI mapping changed(1): %u/%u => %u/%u", + tid->oii_ino, tid->oii_gen, + id->oii_ino, id->oii_gen); + + LASSERTF(tid->oii_ino == inode->i_ino && + tid->oii_gen == inode->i_generation, + "locate wrong inode(1): %u/%u => %ld/%u", + tid->oii_ino, tid->oii_gen, + inode->i_ino, inode->i_generation); + + /* "result == 0" means the cached OI mapping is still in + * the OI file, so the target the inode is valid. */ + goto found; + } - if (result != -ENOENT) - GOTO(out, result); + /* "result == -ENOENT" means that the OI mappinghas been removed + * by race, the target inode belongs to other object. + * + * Others error can be returned directly. */ + if (result == -ENOENT) + result = 0; + } - if (!in_oi && (fid_is_norm(fid) || fid_is_igif(fid)) && - ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), - sf->sf_oi_bitmap)) - goto trigger; + saved_ino = inode->i_ino; + saved_gen = inode->i_generation; + iput(inode); + inode = NULL; + obj->oo_inode = NULL; - GOTO(out, result = 0); - } + if (result != -EREMCHG) + GOTO(out, result); + if (!cached) + /* The current OI mapping is from the OI file, + * since the inode has been found via + * osd_iget_check(), no need recheck OI. */ + goto trigger; + + result = osd_oi_lookup(info, dev, fid, tid, OI_CHECK_FLD); + /* "result == -ENOENT" means the cached OI mapping has been removed from + * the OI file by race, above target inode belongs to other object. + * + * Others error can be returned directly. */ + if (result != 0) + GOTO(out, result = (result == -ENOENT ? 0 : result)); + + LASSERTF(tid->oii_ino == id->oii_ino && tid->oii_gen == id->oii_gen, + "OI mapping changed(2): %u/%u => %u/%u", + tid->oii_ino, tid->oii_gen, id->oii_ino, id->oii_gen); + + LASSERTF(tid->oii_ino == saved_ino && tid->oii_gen == saved_gen, + "locate wrong inode(2): %u/%u => %u/%u", + tid->oii_ino, tid->oii_gen, saved_ino, saved_gen); + + goto trigger; + +found: obj->oo_compat_dot_created = 1; obj->oo_compat_dotdot_created = 1; - if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */ + if (S_ISDIR(inode->i_mode) && + (flags & SS_AUTO_PARTIAL || sf->sf_status == SS_SCANNING)) + osd_check_lmv(info, dev, inode, oic); + + result = osd_attach_jinode(inode); + if (result) { + obj->oo_inode = NULL; + iput(inode); + GOTO(out, result); + } + + if (!ldiskfs_pdo) GOTO(out, result = 0); LASSERT(obj->oo_hl_head == NULL); @@ -629,6 +1215,9 @@ trigger: GOTO(out, result = 0); out: + if (result != 0 && cached) + fid_zero(&oic->oic_fid); + LINVRNT(osd_invariant(obj)); return result; } @@ -664,13 +1253,158 @@ static int osd_object_init(const struct lu_env *env, struct lu_object *l, result = osd_fid_lookup(env, obj, lu_object_fid(l), conf); obj->oo_dt.do_body_ops = &osd_body_ops_new; - if (result == 0 && obj->oo_inode != NULL) + if (result == 0 && obj->oo_inode != NULL) { + struct osd_thread_info *oti = osd_oti_get(env); + struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs; + osd_object_init0(obj); + result = osd_get_lma(oti, obj->oo_inode, + &oti->oti_obj_dentry, lma); + if (result == 0) { + /* Convert LMAI flags to lustre LMA flags + * and cache it to oo_lma_flags */ + obj->oo_lma_flags = + lma_to_lustre_flags(lma->lma_incompat); + } else if (result == -ENODATA) { + result = 0; + } + } LINVRNT(osd_invariant(obj)); return result; } +/* The first part of oxe_buf is xattr name, and is '\0' terminated. + * The left part is for value, binary mode. */ +struct osd_xattr_entry { + struct list_head oxe_list; + size_t oxe_len; + size_t oxe_namelen; + bool oxe_exist; + struct rcu_head oxe_rcu; + char oxe_buf[0]; +}; + +static int osd_oxc_get(struct osd_object *obj, const char *name, + struct lu_buf *buf) +{ + struct osd_xattr_entry *tmp; + struct osd_xattr_entry *oxe = NULL; + size_t namelen = strlen(name); + int rc; + ENTRY; + + rcu_read_lock(); + list_for_each_entry_rcu(tmp, &obj->oo_xattr_list, oxe_list) { + if (namelen == tmp->oxe_namelen && + strncmp(name, tmp->oxe_buf, namelen) == 0) { + oxe = tmp; + break; + } + } + + if (oxe == NULL) + GOTO(out, rc = -ENOENT); + + if (!oxe->oxe_exist) + GOTO(out, rc = -ENODATA); + + /* vallen */ + rc = oxe->oxe_len - sizeof(*oxe) - oxe->oxe_namelen - 1; + LASSERT(rc > 0); + + if (buf->lb_buf == NULL) + GOTO(out, rc); + + if (buf->lb_len < rc) + GOTO(out, rc = -ERANGE); + + memcpy(buf->lb_buf, &oxe->oxe_buf[namelen + 1], rc); + EXIT; +out: + rcu_read_unlock(); + + return rc; +} + +static void osd_oxc_free(struct rcu_head *head) +{ + struct osd_xattr_entry *oxe; + + oxe = container_of(head, struct osd_xattr_entry, oxe_rcu); + OBD_FREE(oxe, oxe->oxe_len); +} + +static void osd_oxc_add(struct osd_object *obj, const char *name, + const char *buf, int buflen) +{ + struct osd_xattr_entry *oxe; + struct osd_xattr_entry *old = NULL; + struct osd_xattr_entry *tmp; + size_t namelen = strlen(name); + size_t len = sizeof(*oxe) + namelen + 1 + buflen; + + OBD_ALLOC(oxe, len); + if (oxe == NULL) + return; + + INIT_LIST_HEAD(&oxe->oxe_list); + oxe->oxe_len = len; + oxe->oxe_namelen = namelen; + memcpy(oxe->oxe_buf, name, namelen); + if (buflen > 0) { + LASSERT(buf != NULL); + memcpy(oxe->oxe_buf + namelen + 1, buf, buflen); + oxe->oxe_exist = true; + } else { + oxe->oxe_exist = false; + } + + /* this should be rarely called, just remove old and add new */ + spin_lock(&obj->oo_guard); + list_for_each_entry(tmp, &obj->oo_xattr_list, oxe_list) { + if (namelen == tmp->oxe_namelen && + strncmp(name, tmp->oxe_buf, namelen) == 0) { + old = tmp; + break; + } + } + if (old != NULL) { + list_replace_rcu(&old->oxe_list, &oxe->oxe_list); + call_rcu(&old->oxe_rcu, osd_oxc_free); + } else { + list_add_tail_rcu(&oxe->oxe_list, &obj->oo_xattr_list); + } + spin_unlock(&obj->oo_guard); +} + +static void osd_oxc_del(struct osd_object *obj, const char *name) +{ + struct osd_xattr_entry *oxe; + size_t namelen = strlen(name); + + spin_lock(&obj->oo_guard); + list_for_each_entry(oxe, &obj->oo_xattr_list, oxe_list) { + if (namelen == oxe->oxe_namelen && + strncmp(name, oxe->oxe_buf, namelen) == 0) { + list_del_rcu(&oxe->oxe_list); + call_rcu(&oxe->oxe_rcu, osd_oxc_free); + break; + } + } + spin_unlock(&obj->oo_guard); +} + +static void osd_oxc_fini(struct osd_object *obj) +{ + struct osd_xattr_entry *oxe, *next; + + list_for_each_entry_safe(oxe, next, &obj->oo_xattr_list, oxe_list) { + list_del(&oxe->oxe_list); + OBD_FREE(oxe, oxe->oxe_len); + } +} + /* * Concurrency: no concurrent access is possible that late in object * life-cycle. @@ -681,6 +1415,7 @@ static void osd_object_free(const struct lu_env *env, struct lu_object *l) LINVRNT(osd_invariant(obj)); + osd_oxc_fini(obj); dt_object_fini(&obj->oo_dt); if (obj->oo_hl_head != NULL) ldiskfs_htree_lock_head_free(obj->oo_hl_head); @@ -731,7 +1466,7 @@ enum { */ static void osd_th_alloced(struct osd_thandle *oth) { - oth->oth_alloced = cfs_time_current(); + oth->oth_alloced = ktime_get(); } /** @@ -739,58 +1474,42 @@ static void osd_th_alloced(struct osd_thandle *oth) */ static void osd_th_started(struct osd_thandle *oth) { - oth->oth_started = cfs_time_current(); + oth->oth_started = ktime_get(); } /** - * Helper function to convert time interval to microseconds packed in - * long int. + * Check whether the we deal with this handle for too long. */ -static long interval_to_usec(cfs_time_t start, cfs_time_t end) +static void __osd_th_check_slow(void *oth, struct osd_device *dev, + ktime_t alloced, ktime_t started, + ktime_t closed) { - struct timeval val; + ktime_t now = ktime_get(); - cfs_duration_usec(cfs_time_sub(end, start), &val); - return val.tv_sec * 1000000 + val.tv_usec; -} + LASSERT(dev != NULL); -/** - * Check whether the we deal with this handle for too long. - */ -static void __osd_th_check_slow(void *oth, struct osd_device *dev, - cfs_time_t alloced, cfs_time_t started, - cfs_time_t closed) -{ - cfs_time_t now = cfs_time_current(); - - LASSERT(dev != NULL); - - lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING, - interval_to_usec(alloced, started)); - lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN, - interval_to_usec(started, closed)); - lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING, - interval_to_usec(closed, now)); - - if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) { - CWARN("transaction handle %p was open for too long: " - "now "CFS_TIME_T" ," - "alloced "CFS_TIME_T" ," - "started "CFS_TIME_T" ," - "closed "CFS_TIME_T"\n", + lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING, + ktime_us_delta(started, alloced)); + lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN, + ktime_us_delta(closed, started)); + lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING, + ktime_us_delta(now, closed)); + + if (ktime_before(ktime_add_ns(alloced, 30 * NSEC_PER_SEC), now)) { + CWARN("transaction handle %p was open for too long: now %lld, alloced %lld, started %lld, closed %lld\n", oth, now, alloced, started, closed); libcfs_debug_dumpstack(NULL); } } -#define OSD_CHECK_SLOW_TH(oth, dev, expr) \ -{ \ - cfs_time_t __closed = cfs_time_current(); \ - cfs_time_t __alloced = oth->oth_alloced; \ - cfs_time_t __started = oth->oth_started; \ - \ - expr; \ - __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \ +#define OSD_CHECK_SLOW_TH(oth, dev, expr) \ +{ \ + ktime_t __closed = ktime_get(); \ + ktime_t __alloced = oth->oth_alloced; \ + ktime_t __started = oth->oth_started; \ + \ + expr; \ + __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \ } #else /* OSD_THANDLE_STATS */ @@ -849,6 +1568,11 @@ static void osd_trans_commit_cb(struct super_block *sb, OBD_FREE_PTR(oh); } +#ifndef HAVE_SB_START_WRITE +# define sb_start_write(sb) do {} while (0) +# define sb_end_write(sb) do {} while (0) +#endif + static struct thandle *osd_trans_create(const struct lu_env *env, struct dt_device *d) { @@ -861,7 +1585,8 @@ static struct thandle *osd_trans_create(const struct lu_env *env, /* on pending IO in this thread should left from prev. request */ LASSERT(atomic_read(&iobuf->dr_numreqs) == 0); - th = ERR_PTR(-ENOMEM); + sb_start_write(osd_sb(osd_dt_dev(d))); + OBD_ALLOC_GFP(oh, sizeof *oh, GFP_NOFS); if (oh != NULL) { oh->ot_quota_trans = &oti->oti_quota_trans; @@ -876,16 +1601,66 @@ static struct thandle *osd_trans_create(const struct lu_env *env, osd_th_alloced(oh); memset(oti->oti_declare_ops, 0, - sizeof(oti->oti_declare_ops)); - memset(oti->oti_declare_ops_rb, 0, - sizeof(oti->oti_declare_ops_rb)); + sizeof(oti->oti_declare_ops)); memset(oti->oti_declare_ops_cred, 0, - sizeof(oti->oti_declare_ops_cred)); - oti->oti_rollback = false; + sizeof(oti->oti_declare_ops_cred)); + memset(oti->oti_declare_ops_used, 0, + sizeof(oti->oti_declare_ops_used)); + } else { + sb_end_write(osd_sb(osd_dt_dev(d))); + th = ERR_PTR(-ENOMEM); } RETURN(th); } +void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th) +{ + struct osd_thread_info *oti = osd_oti_get(env); + struct osd_thandle *oh; + + oh = container_of0(th, struct osd_thandle, ot_super); + LASSERT(oh != NULL); + + CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n", + oti->oti_declare_ops[OSD_OT_CREATE], + oti->oti_declare_ops_cred[OSD_OT_CREATE], + oti->oti_declare_ops_used[OSD_OT_CREATE], + oti->oti_declare_ops[OSD_OT_DESTROY], + oti->oti_declare_ops_cred[OSD_OT_DESTROY], + oti->oti_declare_ops_used[OSD_OT_DESTROY]); + CWARN(" attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n", + oti->oti_declare_ops[OSD_OT_ATTR_SET], + oti->oti_declare_ops_cred[OSD_OT_ATTR_SET], + oti->oti_declare_ops_used[OSD_OT_ATTR_SET], + oti->oti_declare_ops[OSD_OT_XATTR_SET], + oti->oti_declare_ops_cred[OSD_OT_XATTR_SET], + oti->oti_declare_ops_used[OSD_OT_XATTR_SET]); + CWARN(" write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n", + oti->oti_declare_ops[OSD_OT_WRITE], + oti->oti_declare_ops_cred[OSD_OT_WRITE], + oti->oti_declare_ops_used[OSD_OT_WRITE], + oti->oti_declare_ops[OSD_OT_PUNCH], + oti->oti_declare_ops_cred[OSD_OT_PUNCH], + oti->oti_declare_ops_used[OSD_OT_PUNCH], + oti->oti_declare_ops[OSD_OT_QUOTA], + oti->oti_declare_ops_cred[OSD_OT_QUOTA], + oti->oti_declare_ops_used[OSD_OT_QUOTA]); + CWARN(" insert: %u/%u/%u, delete: %u/%u/%u\n", + oti->oti_declare_ops[OSD_OT_INSERT], + oti->oti_declare_ops_cred[OSD_OT_INSERT], + oti->oti_declare_ops_used[OSD_OT_INSERT], + oti->oti_declare_ops[OSD_OT_DELETE], + oti->oti_declare_ops_cred[OSD_OT_DELETE], + oti->oti_declare_ops_used[OSD_OT_DELETE]); + CWARN(" ref_add: %u/%u/%u, ref_del: %u/%u/%u\n", + oti->oti_declare_ops[OSD_OT_REF_ADD], + oti->oti_declare_ops_cred[OSD_OT_REF_ADD], + oti->oti_declare_ops_used[OSD_OT_REF_ADD], + oti->oti_declare_ops[OSD_OT_REF_DEL], + oti->oti_declare_ops_cred[OSD_OT_REF_DEL], + oti->oti_declare_ops_used[OSD_OT_REF_DEL]); +} + /* * Concurrency: shouldn't matter. */ @@ -914,41 +1689,15 @@ static int osd_trans_start(const struct lu_env *env, struct dt_device *d, static unsigned long last_printed; static int last_credits; - CWARN("%.16s: too many transaction credits (%d > %d)\n", - LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, - oh->ot_credits, - osd_journal(dev)->j_max_transaction_buffers); - CWARN(" create: %u/%u, destroy: %u/%u\n", - oti->oti_declare_ops[OSD_OT_CREATE], - oti->oti_declare_ops_cred[OSD_OT_CREATE], - oti->oti_declare_ops[OSD_OT_DESTROY], - oti->oti_declare_ops_cred[OSD_OT_DESTROY]); - CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n", - oti->oti_declare_ops[OSD_OT_ATTR_SET], - oti->oti_declare_ops_cred[OSD_OT_ATTR_SET], - oti->oti_declare_ops[OSD_OT_XATTR_SET], - oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]); - CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n", - oti->oti_declare_ops[OSD_OT_WRITE], - oti->oti_declare_ops_cred[OSD_OT_WRITE], - oti->oti_declare_ops[OSD_OT_PUNCH], - oti->oti_declare_ops_cred[OSD_OT_PUNCH], - oti->oti_declare_ops[OSD_OT_QUOTA], - oti->oti_declare_ops_cred[OSD_OT_QUOTA]); - CWARN(" insert: %u/%u, delete: %u/%u\n", - oti->oti_declare_ops[OSD_OT_INSERT], - oti->oti_declare_ops_cred[OSD_OT_INSERT], - oti->oti_declare_ops[OSD_OT_DELETE], - oti->oti_declare_ops_cred[OSD_OT_DELETE]); - CWARN(" ref_add: %u/%u, ref_del: %u/%u\n", - oti->oti_declare_ops[OSD_OT_REF_ADD], - oti->oti_declare_ops_cred[OSD_OT_REF_ADD], - oti->oti_declare_ops[OSD_OT_REF_DEL], - oti->oti_declare_ops_cred[OSD_OT_REF_DEL]); - + /* don't make noise on a tiny testing systems + * actual credits misuse will be caught anyway */ if (last_credits != oh->ot_credits && time_after(jiffies, last_printed + - msecs_to_jiffies(60 * MSEC_PER_SEC))) { + msecs_to_jiffies(60 * MSEC_PER_SEC)) && + osd_transaction_size(dev) > 512) { + CWARN("%s: credits %u > trans_max %u\n", osd_name(dev), + oh->ot_credits, osd_transaction_size(dev)); + osd_trans_dump_creds(env, th); libcfs_debug_dumpstack(NULL); last_credits = oh->ot_credits; last_printed = jiffies; @@ -1000,8 +1749,8 @@ static int osd_seq_exists(const struct lu_env *env, rc = osd_fld_lookup(env, osd, seq, range); if (rc != 0) { if (rc != -ENOENT) - CERROR("%s: can't lookup FLD sequence "LPX64 - ": rc = %d\n", osd_name(osd), seq, rc); + CERROR("%s: can't lookup FLD sequence %#llx: rc = %d\n", + osd_name(osd), seq, rc); RETURN(0); } @@ -1030,7 +1779,7 @@ static void osd_trans_stop_cb(struct osd_thandle *oth, int result) static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, struct thandle *th) { - int rc = 0; + int rc = 0, remove_agents = 0; struct osd_thandle *oh; struct osd_thread_info *oti = osd_oti_get(env); struct osd_iobuf *iobuf = &oti->oti_iobuf; @@ -1039,12 +1788,18 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, struct lquota_trans *qtrans; ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of0(th, struct osd_thandle, ot_super); + + /* reset OI cache for safety */ + oti->oti_ins_cache_used = 0; + + remove_agents = oh->ot_remove_agents; qtrans = oh->ot_quota_trans; oh->ot_quota_trans = NULL; if (oh->ot_handle != NULL) { + int rc2; handle_t *hdl = oh->ot_handle; /* @@ -1068,10 +1823,12 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, hdl->h_sync = th->th_sync; oh->ot_handle = NULL; - OSD_CHECK_SLOW_TH(oh, osd, rc = ldiskfs_journal_stop(hdl)); - if (rc != 0) + OSD_CHECK_SLOW_TH(oh, osd, rc2 = ldiskfs_journal_stop(hdl)); + if (rc2 != 0) CERROR("%s: failed to stop transaction: rc = %d\n", - osd_name(osd), rc); + osd_name(osd), rc2); + if (!rc) + rc = rc2; } else { osd_trans_stop_cb(oh, th->th_result); OBD_FREE_PTR(oh); @@ -1095,6 +1852,11 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, if (!rc) rc = iobuf->dr_error; + if (unlikely(remove_agents != 0)) + osd_process_scheduled_agent_removals(env, osd); + + sb_end_write(osd_sb(osd)); + RETURN(rc); } @@ -1160,6 +1922,12 @@ static void osd_object_delete(const struct lu_env *env, struct lu_object *l) static void osd_object_release(const struct lu_env *env, struct lu_object *l) { + struct osd_object *o = osd_obj(l); + /* nobody should be releasing a non-destroyed object with nlink=0 + * the API allows this, but ldiskfs doesn't like and then report + * this inode as deleted */ + if (unlikely(!o->oo_destroyed && o->oo_inode && o->oo_inode->i_nlink == 0)) + LBUG(); } /* @@ -1183,18 +1951,17 @@ static int osd_object_print(const struct lu_env *env, void *cookie, d ? d->id_ops->id_name : "plain"); } -#define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */ - /* * Concurrency: shouldn't matter. */ int osd_statfs(const struct lu_env *env, struct dt_device *d, struct obd_statfs *sfs) { - struct osd_device *osd = osd_dt_dev(d); - struct super_block *sb = osd_sb(osd); - struct kstatfs *ksfs; - int result = 0; + struct osd_device *osd = osd_dt_dev(d); + struct super_block *sb = osd_sb(osd); + struct kstatfs *ksfs; + __u64 reserved; + int result = 0; if (unlikely(osd->od_mnt == NULL)) return -EINPROGRESS; @@ -1208,30 +1975,40 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d, ksfs = &osd_oti_get(env)->oti_ksfs; } - spin_lock(&osd->od_osfs_lock); result = sb->s_op->statfs(sb->s_root, ksfs); - if (likely(result == 0)) { /* N.B. statfs can't really fail */ - statfs_pack(sfs, ksfs); - if (sb->s_flags & MS_RDONLY) - sfs->os_state = OS_STATE_READONLY; - } - - spin_unlock(&osd->od_osfs_lock); + if (result) + goto out; + + statfs_pack(sfs, ksfs); + if (unlikely(sb->s_flags & MS_RDONLY)) + sfs->os_state |= OS_STATE_READONLY; + if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, + LDISKFS_FEATURE_INCOMPAT_EXTENTS)) + sfs->os_maxbytes = sb->s_maxbytes; + else + sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes; - if (unlikely(env == NULL)) - OBD_FREE_PTR(ksfs); + /* + * Reserve some space so to avoid fragmenting the filesystem too much. + * Fragmentation not only impacts performance, but can also increase + * metadata overhead significantly, causing grant calculation to be + * wrong. + * + * Reserve 0.78% of total space, at least 8MB for small filesystems. + */ + CLASSERT(OSD_STATFS_RESERVED > LDISKFS_MAX_BLOCK_SIZE); + reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits; + if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT)) + reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT; - /* Reserve a small amount of space for local objects like last_rcvd, - * llog, quota files, ... */ - if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) { - sfs->os_bavail = 0; - } else { - sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS; - /** Take out metadata overhead for indirect blocks */ - sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3); - } + sfs->os_blocks -= reserved; + sfs->os_bfree -= min(reserved, sfs->os_bfree); + sfs->os_bavail -= min(reserved, sfs->os_bavail); - return result; +out: + if (unlikely(env == NULL)) + OBD_FREE_PTR(ksfs); + return result; } /** @@ -1260,18 +2037,23 @@ static void osd_conf_get(const struct lu_env *env, */ param->ddp_max_name_len = LDISKFS_NAME_LEN; param->ddp_max_nlink = LDISKFS_LINK_MAX; - param->ddp_block_shift = sb->s_blocksize_bits; + param->ddp_symlink_max = sb->s_blocksize; param->ddp_mount_type = LDD_MT_LDISKFS; - param->ddp_maxbytes = sb->s_maxbytes; - /* Overhead estimate should be fairly accurate, so we really take a tiny - * error margin which also avoids fragmenting the filesystem too much */ - param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */ + if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS)) + param->ddp_maxbytes = sb->s_maxbytes; + else + param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes; /* inode are statically allocated, so per-inode space consumption * is the space consumed by the directory entry */ param->ddp_inodespace = PER_OBJ_USAGE; - /* per-fragment overhead to be used by the client code */ - param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb); - param->ddp_mntopts = 0; + /* EXT_INIT_MAX_LEN is the theoretical maximum extent size (32k blocks + * = 128MB) which is unlikely to be hit in real life. Report a smaller + * maximum length to not under count the actual number of extents + * needed for writing a file. */ + param->ddp_max_extent_blks = EXT_INIT_MAX_LEN >> 2; + /* worst-case extent insertion metadata overhead */ + param->ddp_extent_tax = 6 * LDISKFS_BLOCK_SIZE(sb); + param->ddp_mntopts = 0; if (test_opt(sb, XATTR_USER)) param->ddp_mntopts |= MNTOPT_USERXATTR; if (test_opt(sb, POSIX_ACL)) @@ -1350,6 +2132,12 @@ static int osd_ro(const struct lu_env *env, struct dt_device *d) #ifdef HAVE_DEV_SET_RDONLY CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname); + if (sb->s_op->freeze_fs) { + rc = sb->s_op->freeze_fs(sb); + if (rc) + goto out; + } + if (jdev && (jdev != dev)) { CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n", (long)jdev); @@ -1357,10 +2145,16 @@ static int osd_ro(const struct lu_env *env, struct dt_device *d) } CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev); dev_set_rdonly(dev); -#else - CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n", - osd_dt_dev(d)->od_svname, (long)dev, rc); + + if (sb->s_op->unfreeze_fs) + sb->s_op->unfreeze_fs(sb); + +out: #endif + if (rc) + CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n", + osd_dt_dev(d)->od_svname, (long)dev, rc); + RETURN(rc); } @@ -1516,7 +2310,6 @@ static struct timespec *osd_inode_time(const struct lu_env *env, return t; } - static void osd_inode_getattr(const struct lu_env *env, struct inode *inode, struct lu_attr *attr) { @@ -1533,7 +2326,7 @@ static void osd_inode_getattr(const struct lu_env *env, attr->la_blocks = inode->i_blocks; attr->la_uid = i_uid_read(inode); attr->la_gid = i_gid_read(inode); - attr->la_flags = LDISKFS_I(inode)->i_flags; + attr->la_flags = ll_inode_to_ext_flags(inode->i_flags); attr->la_nlink = inode->i_nlink; attr->la_rdev = inode->i_rdev; attr->la_blksize = 1 << inode->i_blkbits; @@ -1546,7 +2339,9 @@ static int osd_attr_get(const struct lu_env *env, { struct osd_object *obj = osd_dt_obj(dt); - if (!dt_object_exists(dt)) + if (unlikely(!dt_object_exists(dt))) + return -ENOENT; + if (unlikely(obj->oo_destroyed)) return -ENOENT; LASSERT(!dt_object_remote(dt)); @@ -1554,7 +2349,10 @@ static int osd_attr_get(const struct lu_env *env, spin_lock(&obj->oo_guard); osd_inode_getattr(env, obj->oo_inode, attr); + if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) + attr->la_flags |= LUSTRE_ORPHAN_FL; spin_unlock(&obj->oo_guard); + return 0; } @@ -1586,6 +2384,9 @@ static int osd_declare_attr_set(const struct lu_env *env, osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]); + osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, + osd_dto_credits_noquota[DTO_XATTR_SET]); + if (attr == NULL || obj->oo_inode == NULL) RETURN(rc); @@ -1714,23 +2515,21 @@ static int osd_inode_setattr(const struct lu_env *env, if (bits == 0) return 0; - if (bits & LA_ATIME) - inode->i_atime = *osd_inode_time(env, inode, attr->la_atime); - if (bits & LA_CTIME) - inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime); - if (bits & LA_MTIME) - inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime); - if (bits & LA_SIZE) { - LDISKFS_I(inode)->i_disksize = attr->la_size; - i_size_write(inode, attr->la_size); - } + if (bits & LA_ATIME) + inode->i_atime = *osd_inode_time(env, inode, attr->la_atime); + if (bits & LA_CTIME) + inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime); + if (bits & LA_MTIME) + inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime); + if (bits & LA_SIZE) { + spin_lock(&inode->i_lock); + LDISKFS_I(inode)->i_disksize = attr->la_size; + i_size_write(inode, attr->la_size); + spin_unlock(&inode->i_lock); + } -#if 0 - /* OSD should not change "i_blocks" which is used by quota. - * "i_blocks" should be changed by ldiskfs only. */ - if (bits & LA_BLOCKS) - inode->i_blocks = attr->la_blocks; -#endif + /* OSD should not change "i_blocks" which is used by quota. + * "i_blocks" should be changed by ldiskfs only. */ if (bits & LA_MODE) inode->i_mode = (inode->i_mode & S_IFMT) | (attr->la_mode & ~S_IFMT); @@ -1743,12 +2542,12 @@ static int osd_inode_setattr(const struct lu_env *env, if (bits & LA_RDEV) inode->i_rdev = attr->la_rdev; - if (bits & LA_FLAGS) { - /* always keep S_NOCMTIME */ - inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) | - S_NOCMTIME; - } - return 0; + if (bits & LA_FLAGS) { + /* always keep S_NOCMTIME */ + inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) | + S_NOCMTIME; + } + return 0; } static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr) @@ -1830,9 +2629,43 @@ static int osd_attr_set(const struct lu_env *env, spin_lock(&obj->oo_guard); rc = osd_inode_setattr(env, inode, attr); spin_unlock(&obj->oo_guard); + if (rc != 0) + GOTO(out, rc); + + ll_dirty_inode(inode, I_DIRTY_DATASYNC); + + if (!(attr->la_valid & LA_FLAGS)) + GOTO(out, rc); + + /* Let's check if there are extra flags need to be set into LMA */ + if (attr->la_flags & LUSTRE_LMA_FL_MASKS) { + struct osd_thread_info *info = osd_oti_get(env); + struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs; + + rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma); + if (rc != 0) + GOTO(out, rc); + + lma->lma_incompat |= + lustre_to_lma_flags(attr->la_flags); + lustre_lma_swab(lma); + rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, + lma, sizeof(*lma), XATTR_REPLACE); + if (rc != 0) { + struct osd_device *osd = osd_obj2dev(obj); + + CWARN("%s: set "DFID" lma flags %u failed: rc = %d\n", + osd_name(osd), PFID(lu_object_fid(&dt->do_lu)), + lma->lma_incompat, rc); + } else { + obj->oo_lma_flags = + attr->la_flags & LUSTRE_LMA_FL_MASKS; + } + osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET); + } +out: + osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET); - if (!rc) - ll_dirty_inode(inode, I_DIRTY_DATASYNC); return rc; } @@ -1866,8 +2699,9 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, oth = container_of(th, struct osd_thandle, ot_super); LASSERT(oth->ot_handle->h_transaction != NULL); - if (hint && hint->dah_parent) - parent = hint->dah_parent; + if (hint != NULL && hint->dah_parent != NULL && + !dt_object_remote(hint->dah_parent)) + parent = hint->dah_parent; inode = ldiskfs_create_inode(oth->ot_handle, parent ? osd_dt_obj(parent)->oo_inode : @@ -1899,22 +2733,22 @@ enum { }; static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj, - struct lu_attr *attr, - struct dt_allocation_hint *hint, - struct dt_object_format *dof, - struct thandle *th) + struct lu_attr *attr, + struct dt_allocation_hint *hint, + struct dt_object_format *dof, + struct thandle *th) { - int result; - struct osd_thandle *oth; - __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX)); + int result; + struct osd_thandle *oth; + __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX | S_ISGID)); - LASSERT(S_ISDIR(attr->la_mode)); + LASSERT(S_ISDIR(attr->la_mode)); - oth = container_of(th, struct osd_thandle, ot_super); - LASSERT(oth->ot_handle->h_transaction != NULL); - result = osd_mkfile(info, obj, mode, hint, th); + oth = container_of(th, struct osd_thandle, ot_super); + LASSERT(oth->ot_handle->h_transaction != NULL); + result = osd_mkfile(info, obj, mode, hint, th); - return result; + return result; } static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj, @@ -2047,6 +2881,12 @@ static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah, ah->dah_parent = parent; ah->dah_mode = child_mode; + + if (parent != NULL && !dt_object_remote(parent)) { + /* will help to find FID->ino at dt_insert("..") */ + struct osd_object *pobj = osd_dt_obj(parent); + osd_idc_find_and_init(env, osd_obj2dev(pobj), pobj); + } } static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj, @@ -2071,20 +2911,20 @@ static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj, if (result) return; - if (attr->la_valid != 0) { - result = osd_inode_setattr(info->oti_env, inode, attr); - /* - * The osd_inode_setattr() should always succeed here. The - * only error that could be returned is EDQUOT when we are - * trying to change the UID or GID of the inode. However, this - * should not happen since quota enforcement is no longer - * enabled on ldiskfs (lquota takes care of it). - */ + if (attr->la_valid != 0) { + result = osd_inode_setattr(info->oti_env, inode, attr); + /* + * The osd_inode_setattr() should always succeed here. The + * only error that could be returned is EDQUOT when we are + * trying to change the UID or GID of the inode. However, this + * should not happen since quota enforcement is no longer + * enabled on ldiskfs (lquota takes care of it). + */ LASSERTF(result == 0, "%d\n", result); ll_dirty_inode(inode, I_DIRTY_DATASYNC); - } + } - attr->la_valid = valid; + attr->la_valid = valid; } /** @@ -2101,6 +2941,8 @@ static int __osd_object_create(struct osd_thread_info *info, int result; __u32 umask; + osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE); + /* we drop umask so that permissions we pass are not affected */ umask = current->fs->umask; current->fs->umask = 0; @@ -2123,6 +2965,8 @@ static int __osd_object_create(struct osd_thread_info *info, /* restore previous umask value */ current->fs->umask = umask; + osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE); + return result; } @@ -2138,14 +2982,20 @@ static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj, struct osd_inode_id *id = &info->oti_id; struct osd_device *osd = osd_obj2dev(obj); struct osd_thandle *oh; + int rc; LASSERT(obj->oo_inode != NULL); oh = container_of0(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle); + osd_trans_exec_op(env, th, OSD_OT_INSERT); osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation); - return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD); + rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle, + OI_CHECK_FLD, NULL); + osd_trans_exec_check(env, th, OSD_OT_INSERT); + + return rc; } int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd, @@ -2193,24 +3043,18 @@ static int osd_declare_object_create(const struct lu_env *env, oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); + /* EA object consumes more credits than regular object: osd_mk_index + * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and + * leaf_node, could involves the block, block bitmap, groups, GDT + * change for each block, so add 4 * 2 credits in that case. */ osd_trans_declare_op(env, oh, OSD_OT_CREATE, - osd_dto_credits_noquota[DTO_OBJECT_CREATE]); + osd_dto_credits_noquota[DTO_OBJECT_CREATE] + + (dof->dof_type == DFT_INDEX) ? 4 * 2 : 0); /* Reuse idle OI block may cause additional one OI block * to be changed. */ osd_trans_declare_op(env, oh, OSD_OT_INSERT, osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1); - /* If this is directory, then we expect . and .. to be inserted as - * well. The one directory block always needs to be created for the - * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap, - * block), there is no danger of needing a tree for the first block. - */ - if (attr && S_ISDIR(attr->la_mode)) { - osd_trans_declare_op(env, oh, OSD_OT_INSERT, - osd_dto_credits_noquota[DTO_WRITE_BASE]); - osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0); - } - if (!attr) RETURN(0); @@ -2219,6 +3063,10 @@ static int osd_declare_object_create(const struct lu_env *env, if (rc != 0) RETURN(rc); + /* will help to find FID->ino mapping at dt_insert() */ + rc = osd_idc_find_and_init(env, osd_obj2dev(osd_dt_obj(dt)), + osd_dt_obj(dt)); + RETURN(rc); } @@ -2246,18 +3094,17 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt, * 'tune2fs -O quota' will take care of creating them */ RETURN(-EPERM); - osd_trans_exec_op(env, th, OSD_OT_CREATE); - osd_trans_declare_rb(env, th, OSD_OT_REF_ADD); - - result = __osd_object_create(info, obj, attr, hint, dof, th); - if (result == 0) - result = __osd_oi_insert(env, obj, fid, th); - + result = __osd_object_create(info, obj, attr, hint, dof, th); + if (result == 0) { + result = __osd_oi_insert(env, obj, fid, th); + if (obj->oo_dt.do_body_ops == &osd_body_ops_new) + obj->oo_dt.do_body_ops = &osd_body_ops; + } LASSERT(ergo(result == 0, - dt_object_exists(dt) && !dt_object_remote(dt))); + dt_object_exists(dt) && !dt_object_remote(dt))); - LASSERT(osd_invariant(obj)); - RETURN(result); + LASSERT(osd_invariant(obj)); + RETURN(result); } /** @@ -2275,15 +3122,18 @@ static int osd_declare_object_destroy(const struct lu_env *env, int rc; ENTRY; + if (inode == NULL) + RETURN(-ENOENT); + oh = container_of0(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); - LASSERT(inode); osd_trans_declare_op(env, oh, OSD_OT_DESTROY, osd_dto_credits_noquota[DTO_OBJECT_DELETE]); /* Recycle idle OI leaf may cause additional three OI blocks * to be changed. */ - osd_trans_declare_op(env, oh, OSD_OT_DELETE, + if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2)) + osd_trans_declare_op(env, oh, OSD_OT_DELETE, osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3); /* one less inode */ rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), @@ -2293,6 +3143,13 @@ static int osd_declare_object_destroy(const struct lu_env *env, /* data to be truncated */ rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), 0, oh, obj, true, NULL, false); + if (rc) + RETURN(rc); + + /* will help to find FID->ino when this object is being + * added to PENDING/ */ + rc = osd_idc_find_and_init(env, osd_obj2dev(obj), obj); + RETURN(rc); } @@ -2322,10 +3179,10 @@ static int osd_object_destroy(const struct lu_env *env, /* it will check/delete the inode from remote parent, * how to optimize it? unlink performance impaction XXX */ result = osd_delete_from_remote_parent(env, osd, obj, oh); - if (result != 0 && result != -ENOENT) { + if (result != 0) CERROR("%s: delete inode "DFID": rc = %d\n", osd_name(osd), PFID(fid), result); - } + spin_lock(&obj->oo_guard); clear_nlink(inode); spin_unlock(&obj->oo_guard); @@ -2334,16 +3191,21 @@ static int osd_object_destroy(const struct lu_env *env, osd_trans_exec_op(env, th, OSD_OT_DESTROY); - result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle, - OI_CHECK_FLD); + ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_DESTROY); - /* XXX: add to ext3 orphan list */ - /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */ + if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ2)) + result = osd_oi_delete(osd_oti_get(env), osd, fid, + oh->ot_handle, OI_CHECK_FLD); - /* not needed in the cache anymore */ - set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags); + osd_trans_exec_check(env, th, OSD_OT_DESTROY); + /* XXX: add to ext3 orphan list */ + /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */ - RETURN(0); + /* not needed in the cache anymore */ + set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags); + obj->oo_destroyed = 1; + + RETURN(0); } /** @@ -2366,6 +3228,9 @@ int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode, if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA)) RETURN(0); + if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET)) + rc = -ENOMEM; + lustre_lma_init(lma, fid, compat, incompat); lustre_lma_swab(lma); @@ -2453,14 +3318,32 @@ static int osd_add_dot_dotdot_internal(struct osd_thread_info *info, { struct ldiskfs_dentry_param *dot_ldp; struct ldiskfs_dentry_param *dot_dot_ldp; + __u32 saved_nlink = dir->i_nlink; + int rc; dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2; osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid); dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp; dot_ldp->edp_magic = 0; - return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir, - dir, dot_ldp, dot_dot_ldp); + + rc = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir, + dir, dot_ldp, dot_dot_ldp); + /* The ldiskfs_add_dot_dotdot() may dir->i_nlink as 2, then + * the subseqent ref_add() will increase the dir->i_nlink + * as 3. That is incorrect for new created directory. + * + * It looks like hack, because we want to make the OSD API + * to be order-independent for new created directory object + * between dt_insert(..) and ref_add() operations. + * + * Here, we only restore the in-RAM dir-inode's nlink attr, + * becuase if the nlink attr is not 2, then there will be + * ref_add() called following the dt_insert(..), such call + * will make both the in-RAM and on-disk dir-inode's nlink + * attr to be set as 2. LU-7447 */ + set_nlink(dir, saved_nlink); + return rc; } /** @@ -2490,6 +3373,9 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, RETURN(local); } + /* restore i_gid in case S_ISGID is set, we will inherit S_ISGID and set + * correct gid on remote file, not agent here */ + local->i_gid = current_fsgid(); ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB); unlock_new_inode(local); @@ -2517,33 +3403,86 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, } /** - * Delete local agent inode for remote entry + * when direntry is deleted, we have to take care of possible agent inode + * referenced by that. unfortunately we can't do this at that point: + * iget() within a running transaction leads to deadlock and we better do + * not call that every delete declaration to save performance. so we put + * a potention agent inode on a list and process that once the transaction + * is over. Notice it's not any worse in terms of real orphans as regular + * object destroy doesn't put inodes on the on-disk orphan list. this should + * be addressed separately */ -static int osd_delete_local_agent_inode(const struct lu_env *env, - struct osd_device *osd, - const struct lu_fid *fid, - __u32 ino, struct osd_thandle *oh) +static int osd_schedule_agent_inode_removal(const struct lu_env *env, + struct osd_thandle *oh, + __u32 ino) { - struct osd_thread_info *oti = osd_oti_get(env); - struct osd_inode_id *id = &oti->oti_id; - struct inode *inode; - ENTRY; + struct osd_device *osd = osd_dt_dev(oh->ot_super.th_dev); + struct osd_obj_orphan *oor; - id->oii_ino = le32_to_cpu(ino); - id->oii_gen = OSD_OII_NOGEN; - inode = osd_iget(oti, osd, id); - if (IS_ERR(inode)) { - CERROR("%s: iget error "DFID" id %u:%u\n", osd_name(osd), - PFID(fid), id->oii_ino, id->oii_gen); - RETURN(PTR_ERR(inode)); + OBD_ALLOC_PTR(oor); + if (oor == NULL) + return -ENOMEM; + + oor->oor_ino = ino; + oor->oor_env = (struct lu_env *)env; + spin_lock(&osd->od_osfs_lock); + list_add(&oor->oor_list, &osd->od_orphan_list); + spin_unlock(&osd->od_osfs_lock); + + oh->ot_remove_agents = 1; + + return 0; + +} + +static int osd_process_scheduled_agent_removals(const struct lu_env *env, + struct osd_device *osd) +{ + struct osd_thread_info *info = osd_oti_get(env); + struct osd_obj_orphan *oor, *tmp; + struct osd_inode_id id; + struct list_head list; + struct inode *inode; + struct lu_fid fid; + handle_t *jh; + __u32 ino; + + INIT_LIST_HEAD(&list); + + spin_lock(&osd->od_osfs_lock); + list_for_each_entry_safe(oor, tmp, &osd->od_orphan_list, oor_list) { + if (oor->oor_env == env) { + list_del(&oor->oor_list); + list_add(&oor->oor_list, &list); + } } + spin_unlock(&osd->od_osfs_lock); - clear_nlink(inode); - mark_inode_dirty(inode); - CDEBUG(D_INODE, "%s: delete remote inode "DFID" %lu\n", - osd_name(osd), PFID(fid), inode->i_ino); - iput(inode); - RETURN(0); + list_for_each_entry_safe(oor, tmp, &list, oor_list) { + + ino = oor->oor_ino; + + list_del(&oor->oor_list); + OBD_FREE_PTR(oor); + + osd_id_gen(&id, ino, OSD_OII_NOGEN); + inode = osd_iget_fid(info, osd, &id, &fid); + if (IS_ERR(inode)) + continue; + + if (!osd_remote_fid(env, osd, &fid)) { + iput(inode); + continue; + } + + jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC, 1); + clear_nlink(inode); + mark_inode_dirty(inode); + ldiskfs_journal_stop(jh); + iput(inode); + } + + return 0; } /** @@ -2563,7 +3502,7 @@ static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt, const struct lu_fid *fid = lu_object_fid(&dt->do_lu); struct osd_object *obj = osd_dt_obj(dt); struct osd_thread_info *info = osd_oti_get(env); - int result; + int result, on_ost = 0; ENTRY; @@ -2580,9 +3519,6 @@ static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt, * 'tune2fs -O quota' will take care of creating them */ RETURN(-EPERM); - osd_trans_exec_op(env, th, OSD_OT_CREATE); - osd_trans_declare_rb(env, th, OSD_OT_REF_ADD); - result = __osd_object_create(info, obj, attr, hint, dof, th); if (result == 0) { if (fid_is_idif(fid) && @@ -2592,19 +3528,32 @@ static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt, fid_to_ostid(fid, oi); ostid_to_fid(tfid, oi, 0); + on_ost = 1; result = osd_ea_fid_set(info, obj->oo_inode, tfid, LMAC_FID_ON_OST, 0); } else { + on_ost = fid_is_on_ost(info, osd_obj2dev(obj), + fid, OI_CHECK_FLD); result = osd_ea_fid_set(info, obj->oo_inode, fid, - fid_is_on_ost(info, osd_obj2dev(obj), - fid, OI_CHECK_FLD) ? - LMAC_FID_ON_OST : 0, 0); + on_ost ? LMAC_FID_ON_OST : 0, + 0); } + if (obj->oo_dt.do_body_ops == &osd_body_ops_new) + obj->oo_dt.do_body_ops = &osd_body_ops; } if (result == 0) result = __osd_oi_insert(env, obj, fid, th); + /* a small optimization - dt_insert() isn't usually applied + * to OST objects, so we don't need to cache OI mapping for + * OST objects */ + if (result == 0 && on_ost == 0) { + struct osd_device *osd = osd_dev(dt->do_lu.lo_dev); + result = osd_idc_find_and_init(env, osd, obj); + LASSERT(result == 0); + } + LASSERT(ergo(result == 0, dt_object_exists(dt) && !dt_object_remote(dt))); LINVRNT(osd_invariant(obj)); @@ -2640,7 +3589,7 @@ static int osd_object_ref_add(const struct lu_env *env, struct osd_thandle *oh; int rc = 0; - if (!dt_object_exists(dt)) + if (!dt_object_exists(dt) || obj->oo_destroyed) return -ENOENT; LINVRNT(osd_invariant(obj)); @@ -2680,6 +3629,8 @@ static int osd_object_ref_add(const struct lu_env *env, ll_dirty_inode(inode, I_DIRTY_DATASYNC); LINVRNT(osd_invariant(obj)); + osd_trans_exec_check(env, th, OSD_OT_REF_ADD); + return rc; } @@ -2689,6 +3640,9 @@ static int osd_declare_object_ref_del(const struct lu_env *env, { struct osd_thandle *oh; + if (!dt_object_exists(dt)) + return -ENOENT; + LASSERT(!dt_object_remote(dt)); LASSERT(handle != NULL); @@ -2747,6 +3701,8 @@ static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt, ll_dirty_inode(inode, I_DIRTY_DATASYNC); LINVRNT(osd_invariant(obj)); + osd_trans_exec_check(env, th, OSD_OT_REF_DEL); + return 0; } @@ -2758,7 +3714,7 @@ static int osd_object_version_get(const struct lu_env *env, { struct inode *inode = osd_dt_obj(dt)->oo_inode; - CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n", + CDEBUG(D_INODE, "Get version %#llx for inode %lu\n", LDISKFS_I(inode)->i_fs_version, inode->i_ino); *ver = LDISKFS_I(inode)->i_fs_version; return 0; @@ -2770,15 +3726,17 @@ static int osd_object_version_get(const struct lu_env *env, static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt, struct lu_buf *buf, const char *name) { - struct osd_object *obj = osd_dt_obj(dt); - struct inode *inode = obj->oo_inode; - struct osd_thread_info *info = osd_oti_get(env); - struct dentry *dentry = &info->oti_obj_dentry; + struct osd_object *obj = osd_dt_obj(dt); + struct inode *inode = obj->oo_inode; + struct osd_thread_info *info = osd_oti_get(env); + struct dentry *dentry = &info->oti_obj_dentry; + bool cache_xattr = false; + int rc; - /* version get is not real XATTR but uses xattr API */ - if (strcmp(name, XATTR_NAME_VERSION) == 0) { - /* for version we are just using xattr API but change inode - * field instead */ + /* version get is not real XATTR but uses xattr API */ + if (strcmp(name, XATTR_NAME_VERSION) == 0) { + /* for version we are just using xattr API but change inode + * field instead */ if (buf->lb_len == 0) return sizeof(dt_obj_version_t); @@ -2788,7 +3746,7 @@ static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt, osd_object_version_get(env, dt, buf->lb_buf); return sizeof(dt_obj_version_t); - } + } if (!dt_object_exists(dt)) return -ENOENT; @@ -2797,9 +3755,26 @@ static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt, LASSERT(inode->i_op != NULL); LASSERT(inode->i_op->getxattr != NULL); - return __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len); -} + if (strcmp(name, XATTR_NAME_LOV) == 0 || + strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) + cache_xattr = true; + + if (cache_xattr) { + rc = osd_oxc_get(obj, name, buf); + if (rc != -ENOENT) + return rc; + } + + rc = __osd_xattr_get(inode, dentry, name, buf->lb_buf, buf->lb_len); + if (cache_xattr) { + if (rc == -ENOENT || rc == -ENODATA) + osd_oxc_add(obj, name, NULL, 0); + else if (rc > 0 && buf->lb_buf != NULL) + osd_oxc_add(obj, name, buf->lb_buf, rc); + } + return rc; +} static int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt, @@ -2815,25 +3790,50 @@ static int osd_declare_xattr_set(const struct lu_env *env, oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); - /* optimistic optimization: LMA is set first and usually fit inode */ if (strcmp(name, XATTR_NAME_LMA) == 0) { - if (dt_object_exists(dt)) + /* For non-upgrading case, the LMA is set first and + * usually fit inode. But for upgrade case, the LMA + * may be in another separated EA block. */ + if (!dt_object_exists(dt)) credits = 0; - else + else if (fl == LU_XATTR_REPLACE) credits = 1; + else + goto upgrade; } else if (strcmp(name, XATTR_NAME_VERSION) == 0) { credits = 1; } else { +upgrade: credits = osd_dto_credits_noquota[DTO_XATTR_SET]; - if (buf && buf->lb_len > sb->s_blocksize) { - credits *= (buf->lb_len + sb->s_blocksize - 1) >> - sb->s_blocksize_bits; + + if (buf != NULL) { + ssize_t buflen; + + if (buf->lb_buf == NULL && dt_object_exists(dt)) { + /* learn xattr size from osd_xattr_get if + attribute has not been read yet */ + buflen = __osd_xattr_get( + osd_dt_obj(dt)->oo_inode, + &osd_oti_get(env)->oti_obj_dentry, + name, NULL, 0); + if (buflen < 0) + buflen = 0; + } else { + buflen = buf->lb_len; + } + + if (buflen > sb->s_blocksize) { + credits += osd_calc_bkmap_credits( + sb, NULL, 0, -1, + (buflen + sb->s_blocksize - 1) >> + sb->s_blocksize_bits); + } } /* * xattr set may involve inode quota change, reserve credits for * dquot_initialize() */ - oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb); + credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb); } osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits); @@ -2850,7 +3850,7 @@ static void osd_object_version_set(const struct lu_env *env, { struct inode *inode = osd_dt_obj(dt)->oo_inode; - CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n", + CDEBUG(D_INODE, "Set version %#llx (old %#llx) for inode %lu\n", *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino); LDISKFS_I(inode)->i_fs_version = *new_version; @@ -2870,18 +3870,19 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt, struct inode *inode = obj->oo_inode; struct osd_thread_info *info = osd_oti_get(env); int fs_flags = 0; + int rc; ENTRY; - LASSERT(handle != NULL); + LASSERT(handle != NULL); - /* version set is not real XATTR */ - if (strcmp(name, XATTR_NAME_VERSION) == 0) { - /* for version we are just using xattr API but change inode - * field instead */ - LASSERT(buf->lb_len == sizeof(dt_obj_version_t)); - osd_object_version_set(env, dt, buf->lb_buf); - return sizeof(dt_obj_version_t); - } + /* version set is not real XATTR */ + if (strcmp(name, XATTR_NAME_VERSION) == 0) { + /* for version we are just using xattr API but change inode + * field instead */ + LASSERT(buf->lb_len == sizeof(dt_obj_version_t)); + osd_object_version_set(env, dt, buf->lb_buf); + return sizeof(dt_obj_version_t); + } CDEBUG(D_INODE, DFID" set xattr '%s' with size %zu\n", PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len); @@ -2895,7 +3896,6 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt, if (strcmp(name, XATTR_NAME_LMV) == 0) { struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs; - int rc; rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma); if (rc != 0) @@ -2909,12 +3909,16 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt, RETURN(rc); } - if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_OVERFLOW) && - strcmp(name, XATTR_NAME_LINK) == 0) - return -ENOSPC; - - return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len, + rc = __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len, fs_flags); + osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET); + + if (rc == 0 && + (strcmp(name, XATTR_NAME_LOV) == 0 || + strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)) + osd_oxc_add(obj, name, buf->lb_buf, buf->lb_len); + + return rc; } /* @@ -2990,6 +3994,13 @@ static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt, dentry->d_inode = inode; dentry->d_sb = inode->i_sb; rc = inode->i_op->removexattr(dentry, name); + osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET); + + if (rc == 0 && + (strcmp(name, XATTR_NAME_LOV) == 0 || + strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)) + osd_oxc_del(obj, name); + return rc; } @@ -3017,6 +4028,11 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt, RETURN(rc); } +static int osd_invalidate(const struct lu_env *env, struct dt_object *dt) +{ + return 0; +} + /* * Index operations. */ @@ -3089,7 +4105,7 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt, result = 0; } else if (feat == &dt_directory_features) { dt->do_index_ops = &osd_index_ea_ops; - if (obj->oo_inode != NULL && S_ISDIR(obj->oo_inode->i_mode)) + if (obj->oo_inode == NULL || S_ISDIR(obj->oo_inode->i_mode)) result = 0; else result = -ENOTDIR; @@ -3143,9 +4159,9 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt, } LINVRNT(osd_invariant(obj)); - if (result == 0 && is_quota_glb_feat(feat) && + if (result == 0 && feat == &dt_quota_glb_features && fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB) - result = osd_quota_migration(env, dt, feat); + result = osd_quota_migration(env, dt); return result; } @@ -3184,6 +4200,7 @@ static const struct dt_object_operations osd_obj_ops = { .do_xattr_del = osd_xattr_del, .do_xattr_list = osd_xattr_list, .do_object_sync = osd_object_sync, + .do_invalidate = osd_invalidate, }; /** @@ -3216,6 +4233,7 @@ static const struct dt_object_operations osd_obj_ea_ops = { .do_xattr_del = osd_xattr_del, .do_xattr_list = osd_xattr_list, .do_object_sync = osd_object_sync, + .do_invalidate = osd_invalidate, }; static const struct dt_object_operations osd_obj_otable_it_ops = { @@ -3233,8 +4251,9 @@ static int osd_index_declare_iam_delete(const struct lu_env *env, oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); + /* Recycle may cause additional three blocks to be changed. */ osd_trans_declare_op(env, oh, OSD_OT_DELETE, - osd_dto_credits_noquota[DTO_INDEX_DELETE]); + osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3); return 0; } @@ -3289,6 +4308,7 @@ static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt, rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd); osd_ipd_put(env, bag, ipd); LINVRNT(osd_invariant(obj)); + osd_trans_exec_check(env, handle, OSD_OT_DELETE); RETURN(rc); } @@ -3299,7 +4319,7 @@ static int osd_index_declare_ea_delete(const struct lu_env *env, { struct osd_thandle *oh; struct inode *inode; - int rc; + int rc, credits; ENTRY; LASSERT(!dt_object_remote(dt)); @@ -3308,11 +4328,18 @@ static int osd_index_declare_ea_delete(const struct lu_env *env, oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); - osd_trans_declare_op(env, oh, OSD_OT_DELETE, - osd_dto_credits_noquota[DTO_INDEX_DELETE]); + credits = osd_dto_credits_noquota[DTO_INDEX_DELETE]; + if (key != NULL && unlikely(strcmp((char *)key, dotdot) == 0)) { + /* '..' to a remote object has a local representative */ + credits += osd_dto_credits_noquota[DTO_INDEX_DELETE]; + /* to reset LMAI_REMOTE_PARENT */ + credits += 1; + } + osd_trans_declare_op(env, oh, OSD_OT_DELETE, credits); inode = osd_dt_obj(dt)->oo_inode; - LASSERT(inode); + if (inode == NULL) + RETURN(-ENOENT); rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), 0, oh, osd_dt_obj(dt), true, NULL, false); @@ -3408,9 +4435,7 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt, } bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock); - if (bh) { - __u32 ino = 0; - + if (!IS_ERR(bh)) { /* If this is not the ".." entry, it might be a remote DNE * entry and we need to check if the FID is for a remote * MDT. If the FID is not in the directory entry (e.g. @@ -3428,59 +4453,22 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt, if (strcmp((char *)key, dotdot) != 0) { LASSERT(de != NULL); rc = osd_get_fid_from_dentry(de, (struct dt_rec *)fid); - /* If Fid is not in dentry, try to get it from LMA */ if (rc == -ENODATA) { - struct osd_inode_id *id; - struct inode *inode; - - /* Before trying to get fid from the inode, - * check whether the inode is valid. - * - * If the inode has been deleted, do not go - * ahead to do osd_ea_fid_get, which will set - * the inode to bad inode, which might cause - * the inode to be deleted uncorrectly */ - inode = ldiskfs_iget(osd_sb(osd), - le32_to_cpu(de->inode)); - if (IS_ERR(inode)) { - CDEBUG(D_INODE, "%s: "DFID"get inode" - "error.\n", osd_name(osd), - PFID(fid)); - rc = PTR_ERR(inode); - } else { - if (likely(inode->i_nlink != 0)) { - id = &osd_oti_get(env)->oti_id; - rc = osd_ea_fid_get(env, obj, - le32_to_cpu(de->inode), - fid, id); - } else { - CDEBUG(D_INFO, "%s: %u "DFID - "deleted.\n", - osd_name(osd), - le32_to_cpu(de->inode), - PFID(fid)); - rc = -ESTALE; - } - iput(inode); - } + /* can't get FID, postpone to the end of the + * transaction when iget() is safe */ + osd_schedule_agent_inode_removal(env, oh, + le32_to_cpu(de->inode)); + } else if (rc == 0 && + unlikely(osd_remote_fid(env, osd, fid))) { + osd_schedule_agent_inode_removal(env, oh, + le32_to_cpu(de->inode)); } - if (rc == 0 && - unlikely(osd_remote_fid(env, osd, fid))) - /* Need to delete agent inode */ - ino = le32_to_cpu(de->inode); - } - rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh); - brelse(bh); - if (rc == 0 && unlikely(ino != 0)) { - rc = osd_delete_local_agent_inode(env, osd, fid, ino, - oh); - if (rc != 0) - CERROR("%s: del local inode "DFID": rc = %d\n", - osd_name(osd), PFID(fid), rc); } - } else { - rc = -ENOENT; - } + rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh); + brelse(bh); + } else { + rc = PTR_ERR(bh); + } if (hlock != NULL) ldiskfs_htree_unlock(hlock); else @@ -3493,21 +4481,21 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt, * /Agent directory, Check whether it needs to delete * from agent directory */ if (unlikely(strcmp((char *)key, dotdot) == 0)) { - rc = osd_delete_from_remote_parent(env, osd_obj2dev(obj), obj, - oh); - if (rc != 0 && rc != -ENOENT) { - CERROR("%s: delete agent inode "DFID": rc = %d\n", - osd_name(osd), PFID(fid), rc); - } - - if (rc == -ENOENT) - rc = 0; - - GOTO(out, rc); + int ret; + + ret = osd_delete_from_remote_parent(env, osd_obj2dev(obj), + obj, oh); + if (ret != 0) + /* Sigh, the entry has been deleted, and + * it is not easy to revert it back, so + * let's keep this error private, and let + * LFSCK fix it. XXX */ + CERROR("%s: delete remote parent "DFID": rc = %d\n", + osd_name(osd), PFID(fid), ret); } out: - LASSERT(osd_invariant(obj)); + osd_trans_exec_check(env, handle, OSD_OT_DELETE); RETURN(rc); } @@ -3660,6 +4648,7 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt, iam_rec, ipd); osd_ipd_put(env, bag, ipd); LINVRNT(osd_invariant(obj)); + osd_trans_exec_check(env, th, OSD_OT_INSERT); RETURN(rc); } @@ -3695,7 +4684,8 @@ static int __osd_ea_add_rec(struct osd_thread_info *info, child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name)); child->d_fsdata = (void *)ldp; ll_vfs_dq_init(pobj->oo_inode); - rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock); + rc = osd_ldiskfs_add_entry(info, osd_obj2dev(pobj), oth->ot_handle, + child, cinode, hlock); if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_TYPE)) { struct ldiskfs_dir_entry_2 *de; struct buffer_head *bh; @@ -3703,7 +4693,7 @@ static int __osd_ea_add_rec(struct osd_thread_info *info, bh = osd_ldiskfs_find_entry(pobj->oo_inode, &child->d_name, &de, NULL, hlock); - if (bh != NULL) { + if (!IS_ERR(bh)) { rc1 = ldiskfs_journal_get_write_access(oth->ot_handle, bh); if (rc1 == 0) { @@ -3715,8 +4705,8 @@ static int __osd_ea_add_rec(struct osd_thread_info *info, LDISKFS_FT_DIR; ldiskfs_handle_dirty_metadata(oth->ot_handle, NULL, bh); - brelse(bh); } + brelse(bh); } } @@ -3754,7 +4744,7 @@ static int osd_add_dot_dotdot(struct osd_thread_info *info, if (dir->oo_compat_dot_created) { result = -EEXIST; } else { - LASSERT(inode == parent_dir); + LASSERT(inode->i_ino == parent_dir->i_ino); dir->oo_compat_dot_created = 1; result = 0; } @@ -3784,13 +4774,6 @@ static int osd_add_dot_dotdot(struct osd_thread_info *info, dir->oo_compat_dotdot_created = 1; } - /* ldiskfs_init_new_dir() doesn't call ldiskfs_mark_inode_dirty() - * this seem as an optimization as usually it's called - * later to refresh mtime of the parent. Lustre does not - * update mtime in few cases (e.g. PENDING, .lustre) - * we still need to transfer i_size/etc to the buffer cache */ - ldiskfs_mark_inode_dirty(oth->ot_handle, dir->oo_inode); - return result; } @@ -3849,33 +4832,69 @@ static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj, return rc; } -static void +static int osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev, struct osd_idmap_cache *oic) { - struct osd_scrub *scrub = &dev->od_scrub; - struct lu_fid *fid = &oic->oic_fid; - struct osd_inode_id *id = &oti->oti_id; - int once = 0; - int rc; + struct osd_scrub *scrub = &dev->od_scrub; + struct lu_fid *fid = &oic->oic_fid; + struct osd_inode_id *id = &oic->oic_lid; + struct inode *inode = NULL; + int once = 0; + bool insert; + int rc; ENTRY; - if (!fid_is_norm(fid) && !fid_is_igif(fid)) - RETURN_EXIT; + if (!fid_is_norm(fid) && !fid_is_igif(fid)) + RETURN(0); + + if (scrub->os_pos_current > id->oii_ino) + RETURN(0); + +again: + rc = osd_oi_lookup(oti, dev, fid, &oti->oti_id, 0); + if (rc == -ENOENT) { + __u32 gen = id->oii_gen; + + insert = true; + if (inode != NULL) + goto trigger; - if (scrub->os_pos_current > id->oii_ino) - RETURN_EXIT; + inode = osd_iget(oti, dev, id); + /* The inode has been removed (by race maybe). */ + if (IS_ERR(inode)) { + rc = PTR_ERR(inode); -again: - rc = osd_oi_lookup(oti, dev, fid, id, OI_CHECK_FLD); - if (rc != 0 && rc != -ENOENT) - RETURN_EXIT; + RETURN(rc == -ESTALE ? -ENOENT : rc); + } + + /* The OI mapping is lost. */ + if (gen != OSD_OII_NOGEN) + goto trigger; - if (rc == 0 && osd_id_eq(id, &oic->oic_lid)) - RETURN_EXIT; + iput(inode); + /* The inode may has been reused by others, we do not know, + * leave it to be handled by subsequent osd_fid_lookup(). */ + RETURN(0); + } else if (rc != 0 || osd_id_eq(id, &oti->oti_id)) { + RETURN(rc); + } else { + insert = false; + } +trigger: if (thread_is_running(&scrub->os_thread)) { - rc = osd_oii_insert(dev, oic, rc == -ENOENT); + if (inode == NULL) { + inode = osd_iget(oti, dev, id); + /* The inode has been removed (by race maybe). */ + if (IS_ERR(inode)) { + rc = PTR_ERR(inode); + + RETURN(rc == -ESTALE ? -ENOENT : rc); + } + } + + rc = osd_oii_insert(dev, oic, insert); /* There is race condition between osd_oi_lookup and OI scrub. * The OI scrub finished just after osd_oi_lookup() failure. * Under such case, it is unnecessary to trigger OI scrub again, @@ -3883,21 +4902,31 @@ again: if (unlikely(rc == -EAGAIN)) goto again; - RETURN_EXIT; + if (!S_ISDIR(inode->i_mode)) + rc = 0; + else + rc = osd_check_lmv(oti, dev, inode, oic); + + iput(inode); + RETURN(rc); } if (!dev->od_noscrub && ++once == 1) { rc = osd_scrub_start(dev, SS_AUTO_PARTIAL | SS_CLEAR_DRYRUN | SS_CLEAR_FAILOUT); - CDEBUG(D_LFSCK | D_CONSOLE, "%.16s: trigger OI scrub by RPC " - "for "DFID", rc = %d [2]\n", + CDEBUG(D_LFSCK | D_CONSOLE | D_WARNING, + "%.16s: trigger partial OI scrub for RPC inconsistency " + "checking FID "DFID": rc = %d\n", LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, PFID(fid), rc); if (rc == 0 || rc == -EALREADY) goto again; } - EXIT; + if (inode != NULL) + iput(inode); + + RETURN(rc); } static int osd_fail_fid_lookup(struct osd_thread_info *oti, @@ -4003,8 +5032,8 @@ again: } ldata.ld_buf = buf; - rc = linkea_init(&ldata); - if (rc == 0) { + rc = linkea_init_with_rec(&ldata); + if (!rc) { linkea_first_entry(&ldata); linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid); } @@ -4012,6 +5041,48 @@ again: RETURN(rc); } +static int osd_verify_ent_by_linkea(const struct lu_env *env, + struct inode *inode, + const struct lu_fid *pfid, + const char *name, const int namelen) +{ + struct osd_thread_info *oti = osd_oti_get(env); + struct lu_buf *buf = &oti->oti_big_buf; + struct dentry *dentry = &oti->oti_obj_dentry; + struct linkea_data ldata = { NULL }; + struct lu_name cname = { .ln_name = name, + .ln_namelen = namelen }; + int rc; + ENTRY; + +again: + rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK, + buf->lb_buf, buf->lb_len); + if (rc == -ERANGE) + rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK, NULL, 0); + + if (rc < 0) + RETURN(rc); + + if (unlikely(rc == 0)) + RETURN(-ENODATA); + + if (buf->lb_len < rc) { + lu_buf_realloc(buf, rc); + if (buf->lb_buf == NULL) + RETURN(-ENOMEM); + + goto again; + } + + ldata.ld_buf = buf; + rc = linkea_init_with_rec(&ldata); + if (!rc) + rc = linkea_links_find(&ldata, &cname, pfid); + + RETURN(rc); +} + /** * Calls ->lookup() to find dentry. From dentry get inode and * read inode's ea to get fid. This is required for interoperability @@ -4048,7 +5119,7 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, } bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock); - if (bh) { + if (!IS_ERR(bh)) { struct osd_thread_info *oti = osd_oti_get(env); struct osd_inode_id *id = &oti->oti_id; struct osd_idmap_cache *oic = &oti->oti_cache; @@ -4083,18 +5154,18 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, osd_id_gen(id, ino, OSD_OII_NOGEN); } - if (rc != 0) { + if (rc != 0 || osd_remote_fid(env, dev, fid)) { fid_zero(&oic->oic_fid); + GOTO(out, rc); } - if (osd_remote_fid(env, dev, fid)) - GOTO(out, rc = 0); - osd_add_oi_cache(osd_oti_get(env), osd_obj2dev(obj), id, fid); - osd_consistency_check(oti, dev, oic); + rc = osd_consistency_check(oti, dev, oic); + if (rc != 0) + fid_zero(&oic->oic_fid); } else { - rc = -ENOENT; + rc = PTR_ERR(bh); } GOTO(out, rc); @@ -4108,65 +5179,6 @@ out: } /** - * Find the osd object for given fid. - * - * \param fid need to find the osd object having this fid - * - * \retval osd_object on success - * \retval -ve on error - */ -static struct osd_object *osd_object_find(const struct lu_env *env, - struct dt_object *dt, - const struct lu_fid *fid) -{ - struct lu_device *ludev = dt->do_lu.lo_dev; - struct osd_object *child = NULL; - struct lu_object *luch; - struct lu_object *lo; - - /* - * at this point topdev might not exist yet - * (i.e. MGS is preparing profiles). so we can - * not rely on topdev and instead lookup with - * our device passed as topdev. this can't work - * if the object isn't cached yet (as osd doesn't - * allocate lu_header). IOW, the object must be - * in the cache, otherwise lu_object_alloc() crashes - * -bzzz - */ - luch = lu_object_find_at(env, ludev->ld_site->ls_top_dev == NULL ? - ludev : ludev->ld_site->ls_top_dev, - fid, NULL); - if (!IS_ERR(luch)) { - if (lu_object_exists(luch)) { - lo = lu_object_locate(luch->lo_header, ludev->ld_type); - if (lo != NULL) - child = osd_obj(lo); - else - LU_OBJECT_DEBUG(D_ERROR, env, luch, - "lu_object can't be located" - DFID"\n", PFID(fid)); - - if (child == NULL) { - lu_object_put(env, luch); - CERROR("Unable to get osd_object\n"); - child = ERR_PTR(-ENOENT); - } - } else { - LU_OBJECT_DEBUG(D_ERROR, env, luch, - "lu_object does not exists "DFID"\n", - PFID(fid)); - lu_object_put(env, luch); - child = ERR_PTR(-ENOENT); - } - } else { - child = ERR_CAST(luch); - } - - return child; -} - -/** * Put the osd object once done with it. * * \param obj osd object that needs to be put @@ -4185,18 +5197,37 @@ static int osd_index_declare_ea_insert(const struct lu_env *env, { struct osd_thandle *oh; struct osd_device *osd = osd_dev(dt->do_lu.lo_dev); - struct lu_fid *fid = (struct lu_fid *)rec; - int rc; + struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec; + const struct lu_fid *fid = rec1->rec_fid; + int credits, rc = 0; + struct osd_idmap_cache *idc; ENTRY; LASSERT(!dt_object_remote(dt)); LASSERT(handle != NULL); + LASSERT(fid != NULL); + LASSERT(rec1->rec_type != 0); oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); - osd_trans_declare_op(env, oh, OSD_OT_INSERT, - osd_dto_credits_noquota[DTO_INDEX_INSERT]); + credits = osd_dto_credits_noquota[DTO_INDEX_INSERT]; + + /* we can't call iget() while a transactions is running + * (this can lead to a deadlock), but we need to know + * inum and object type. so we find this information at + * declaration and cache in per-thread info */ + idc = osd_idc_find_or_init(env, osd, fid); + if (IS_ERR(idc)) + RETURN(PTR_ERR(idc)); + if (idc->oic_remote) { + /* a reference to remote inode is represented by an + * agent inode which we have to create */ + credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE]; + credits += osd_dto_credits_noquota[DTO_INDEX_INSERT]; + } + + osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits); if (osd_dt_obj(dt)->oo_inode != NULL) { struct inode *inode = osd_dt_obj(dt)->oo_inode; @@ -4209,22 +5240,6 @@ static int osd_index_declare_ea_insert(const struct lu_env *env, osd_dt_obj(dt), true, NULL, false); } - if (fid == NULL) - RETURN(0); - - rc = osd_remote_fid(env, osd, fid); - if (rc <= 0) - RETURN(rc); - - rc = 0; - - osd_trans_declare_op(env, oh, OSD_OT_CREATE, - osd_dto_credits_noquota[DTO_OBJECT_CREATE]); - osd_trans_declare_op(env, oh, OSD_OT_INSERT, - osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1); - osd_trans_declare_op(env, oh, OSD_OT_INSERT, - osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1); - RETURN(rc); } @@ -4250,9 +5265,8 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt, const struct lu_fid *fid = rec1->rec_fid; const char *name = (const char *)key; struct osd_thread_info *oti = osd_oti_get(env); - struct osd_inode_id *id = &oti->oti_id; struct inode *child_inode = NULL; - struct osd_object *child = NULL; + struct osd_idmap_cache *idc; int rc; ENTRY; @@ -4267,14 +5281,22 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt, LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid)); - rc = osd_remote_fid(env, osd, fid); - if (rc < 0) { - CERROR("%s: Can not find object "DFID" rc %d\n", - osd_name(osd), PFID(fid), rc); - RETURN(rc); + idc = osd_idc_find(env, osd, fid); + if (unlikely(idc == NULL)) { + /* this dt_insert() wasn't declared properly, so + * FID is missing in OI cache. we better do not + * lookup FID in FLDB/OI and don't risk to deadlock, + * but in some special cases (lfsck testing, etc) + * it's much simpler than fixing a caller */ + CERROR("%s: "DFID" wasn't declared for insert\n", + osd_name(osd), PFID(fid)); + dump_stack(); + idc = osd_idc_find_or_init(env, osd, fid); + if (IS_ERR(idc)) + RETURN(PTR_ERR(idc)); } - if (rc == 1) { + if (idc->oic_remote) { /* Insert remote entry */ if (strcmp(name, dotdot) == 0 && strlen(name) == 2) { struct osd_mdobj_map *omm = osd->od_mdt_map; @@ -4300,15 +5322,23 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt, } } else { /* Insert local entry */ - child = osd_object_find(env, dt, fid); - if (IS_ERR(child)) { - CERROR("%s: Can not find object "DFID"%u:%u: rc = %d\n", - osd_name(osd), PFID(fid), - id->oii_ino, id->oii_gen, - (int)PTR_ERR(child)); - RETURN(PTR_ERR(child)); + if (unlikely(idc->oic_lid.oii_ino == 0)) { + /* for a reason OI cache wasn't filled properly */ + CERROR("%s: OIC for "DFID" isn't filled\n", + osd_name(osd), PFID(fid)); + RETURN(-EINVAL); + } + child_inode = oti->oti_inode; + if (unlikely(child_inode == NULL)) { + struct ldiskfs_inode_info *lii; + OBD_ALLOC_PTR(lii); + if (lii == NULL) + RETURN(-ENOMEM); + child_inode = oti->oti_inode = &lii->vfs_inode; } - child_inode = igrab(child->oo_inode); + child_inode->i_sb = osd_sb(osd); + child_inode->i_ino = idc->oic_lid.oii_ino; + child_inode->i_mode = rec1->rec_type & S_IFMT; } rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th); @@ -4316,10 +5346,10 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt, CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n", obj->oo_inode->i_ino, name, child_inode->i_ino, rc); - iput(child_inode); - if (child != NULL) - osd_object_put(env, child); + if (child_inode && child_inode != oti->oti_inode) + iput(child_inode); LASSERT(osd_invariant(obj)); + osd_trans_exec_check(env, th, OSD_OT_INSERT); RETURN(rc); } @@ -4620,7 +5650,7 @@ static struct dt_it *osd_it_ea_init(const struct lu_env *env, struct dentry *obj_dentry; ENTRY; - if (!dt_object_exists(dt)) + if (!dt_object_exists(dt) || obj->oo_destroyed) RETURN(ERR_PTR(-ENOENT)); OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS); @@ -4733,11 +5763,16 @@ struct osd_filldir_cbs { * \retval 0 on success * \retval 1 on buffer full */ -static int osd_ldiskfs_filldir(void *buf, const char *name, int namelen, - loff_t offset, __u64 ino, - unsigned d_type) +#ifdef HAVE_FILLDIR_USE_CTX +static int osd_ldiskfs_filldir(struct dir_context *buf, +#else +static int osd_ldiskfs_filldir(void *buf, +#endif + const char *name, int namelen, + loff_t offset, __u64 ino, unsigned d_type) { - struct osd_it_ea *it = ((struct osd_filldir_cbs *)buf)->it; + struct osd_it_ea *it = + ((struct osd_filldir_cbs *)buf)->it; struct osd_object *obj = it->oie_obj; struct osd_it_ea_dirent *ent = it->oie_dirent; struct lu_fid *fid = &ent->oied_fid; @@ -4913,63 +5948,43 @@ static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di) return it->oie_dirent->oied_namelen; } -static int -osd_dirent_update(handle_t *jh, struct super_block *sb, - struct osd_it_ea_dirent *ent, struct lu_fid *fid, - struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de) +static inline bool osd_dotdot_has_space(struct ldiskfs_dir_entry_2 *de) { - struct osd_fid_pack *rec; - int rc; - ENTRY; - - LASSERT(de->file_type & LDISKFS_DIRENT_LUFID); - LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack)); - - rc = ldiskfs_journal_get_write_access(jh, bh); - if (rc != 0) - RETURN(rc); - - rec = (struct osd_fid_pack *)(de->name + de->name_len + 1); - fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid); - rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh); + if (LDISKFS_DIR_REC_LEN(de) >= + __LDISKFS_DIR_REC_LEN(2 + 1 + sizeof(struct osd_fid_pack))) + return true; - RETURN(rc); + return false; } -static inline int -osd_dirent_has_space(__u16 reclen, __u16 namelen, unsigned blocksize) +static inline bool +osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen, + unsigned blocksize, bool dotdot) { - if (ldiskfs_rec_len_from_disk(reclen, blocksize) >= - __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack))) - return 1; - else - return 0; -} + if (dotdot) + return osd_dotdot_has_space(de); -static inline int -osd_dot_dotdot_has_space(struct ldiskfs_dir_entry_2 *de, int dot_dotdot) -{ - LASSERTF(dot_dotdot == 1 || dot_dotdot == 2, - "dot_dotdot = %d\n", dot_dotdot); + if (ldiskfs_rec_len_from_disk(de->rec_len, blocksize) >= + __LDISKFS_DIR_REC_LEN(namelen + 1 + sizeof(struct osd_fid_pack))) + return true; - if (LDISKFS_DIR_REC_LEN(de) >= - __LDISKFS_DIR_REC_LEN(dot_dotdot + 1 + sizeof(struct osd_fid_pack))) - return 1; - else - return 0; + return false; } static int -osd_dirent_reinsert(const struct lu_env *env, handle_t *jh, - struct inode *dir, struct inode *inode, - struct osd_it_ea_dirent *ent, struct lu_fid *fid, - struct buffer_head *bh, struct ldiskfs_dir_entry_2 *de, - struct htree_lock *hlock) -{ - struct dentry *dentry; +osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev, + handle_t *jh, struct dentry *dentry, + const struct lu_fid *fid, struct buffer_head *bh, + struct ldiskfs_dir_entry_2 *de, struct htree_lock *hlock, + bool dotdot) +{ + struct inode *dir = dentry->d_parent->d_inode; + struct inode *inode = dentry->d_inode; struct osd_fid_pack *rec; struct ldiskfs_dentry_param *ldp; + int namelen = dentry->d_name.len; int rc; + struct osd_thread_info *info = osd_oti_get(env); ENTRY; if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb, @@ -4977,42 +5992,40 @@ osd_dirent_reinsert(const struct lu_env *env, handle_t *jh, RETURN(0); /* There is enough space to hold the FID-in-dirent. */ - if (osd_dirent_has_space(de->rec_len, ent->oied_namelen, - dir->i_sb->s_blocksize)) { + if (osd_dirent_has_space(de, namelen, dir->i_sb->s_blocksize, dotdot)) { rc = ldiskfs_journal_get_write_access(jh, bh); if (rc != 0) RETURN(rc); - de->name[de->name_len] = 0; - rec = (struct osd_fid_pack *)(de->name + de->name_len + 1); + de->name[namelen] = 0; + rec = (struct osd_fid_pack *)(de->name + namelen + 1); rec->fp_len = sizeof(struct lu_fid) + 1; fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid); de->file_type |= LDISKFS_DIRENT_LUFID; - rc = ldiskfs_handle_dirty_metadata(jh, NULL, bh); RETURN(rc); } + LASSERT(!dotdot); + rc = ldiskfs_delete_entry(jh, dir, de, bh); if (rc != 0) RETURN(rc); - dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name, - ent->oied_namelen); ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp; osd_get_ldiskfs_dirent_param(ldp, fid); dentry->d_fsdata = (void *)ldp; ll_vfs_dq_init(dir); - rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock); + rc = osd_ldiskfs_add_entry(info, dev, jh, dentry, inode, hlock); /* It is too bad, we cannot reinsert the name entry back. * That means we lose it! */ if (rc != 0) CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, " "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n", LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, - dir->i_ino, dir->i_generation, - ent->oied_namelen, ent->oied_name, PFID(fid), rc); + dir->i_ino, dir->i_generation, namelen, + dentry->d_name.name, PFID(fid), rc); RETURN(rc); } @@ -5026,8 +6039,7 @@ osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj, struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs; struct osd_device *dev = osd_obj2dev(obj); struct super_block *sb = osd_sb(dev); - const char *devname = - LDISKFS_SB(sb)->s_es->s_volume_name; + const char *devname = osd_name(dev); struct osd_it_ea_dirent *ent = it->oie_dirent; struct inode *dir = obj->oo_inode; struct htree_lock *hlock = NULL; @@ -5036,21 +6048,49 @@ osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj, struct ldiskfs_dir_entry_2 *de; struct dentry *dentry; struct inode *inode; + const struct lu_fid *pfid = lu_object_fid(&obj->oo_dt.do_lu); int credits; int rc; - int dot_dotdot = 0; + bool dotdot = false; bool dirty = false; ENTRY; if (ent->oied_name[0] == '.') { if (ent->oied_namelen == 1) - dot_dotdot = 1; - else if (ent->oied_namelen == 2 && ent->oied_name[1] == '.') - dot_dotdot = 2; + RETURN(0); + + if (ent->oied_namelen == 2 && ent->oied_name[1] == '.') + dotdot = true; + } + + osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN); + inode = osd_iget(info, dev, id); + if (IS_ERR(inode)) { + rc = PTR_ERR(inode); + if (rc == -ENOENT || rc == -ESTALE) { + /* Maybe dangling name entry, or + * corrupted directory entry. */ + *attr |= LUDA_UNKNOWN; + rc = 0; + } else { + CDEBUG(D_LFSCK, "%s: fail to iget() for dirent " + "check_repair, dir = %lu/%u, name = %.*s, " + "ino = %llu, rc = %d\n", + devname, dir->i_ino, dir->i_generation, + ent->oied_namelen, ent->oied_name, + ent->oied_ino, rc); + } + + RETURN(rc); } - dentry = osd_child_dentry_get(env, obj, ent->oied_name, - ent->oied_namelen); + dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name, + ent->oied_namelen); + rc = osd_get_lma(info, inode, dentry, lma); + if (rc == -ENODATA || !fid_is_sane(&lma->lma_self_fid)) + lma = NULL; + else if (rc != 0) + GOTO(out, rc); /* We need to ensure that the name entry is still valid. * Because it may be removed or renamed by other already. @@ -5068,17 +6108,20 @@ osd_dirent_check_repair(const struct lu_env *env, struct osd_object *obj, credits = osd_dto_credits_noquota[DTO_INDEX_DELETE] + osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1 + 1 + 2; -again: if (dev->od_dirent_journal != 0) { + +again: jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits); if (IS_ERR(jh)) { rc = PTR_ERR(jh); - CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent " + CDEBUG(D_LFSCK, "%s: fail to start trans for dirent " "check_repair, dir = %lu/%u, credits = %d, " - "name = %.*s: rc = %d\n", + "name = %.*s, ino = %llu: rc = %d\n", devname, dir->i_ino, dir->i_generation, credits, - ent->oied_namelen, ent->oied_name, rc); - RETURN(rc); + ent->oied_namelen, ent->oied_name, + ent->oied_ino, rc); + + GOTO(out_inode, rc); } if (obj->oo_hl_head != NULL) { @@ -5102,128 +6145,145 @@ again: } bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, hlock); - /* For dot/dotdot entry, if there is not enough space to hold the + if (IS_ERR(bh) || le32_to_cpu(de->inode) != inode->i_ino) { + *attr |= LUDA_IGNORE; + + GOTO(out, rc = 0); + } + + /* For dotdot entry, if there is not enough space to hold the * FID-in-dirent, just keep them there. It only happens when the * device upgraded from 1.8 or restored from MDT file-level backup. - * For the whole directory, only dot/dotdot entry have no FID-in-dirent + * For the whole directory, only dotdot entry have no FID-in-dirent * and needs to get FID from LMA when readdir, it will not affect the * performance much. */ - if ((bh == NULL) || (le32_to_cpu(de->inode) != ent->oied_ino) || - (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) { - *attr |= LUDA_IGNORE; - GOTO(out_journal, rc = 0); + if (dotdot && !osd_dotdot_has_space(de)) { + *attr |= LUDA_UNKNOWN; + + GOTO(out, rc = 0); } - osd_id_gen(id, ent->oied_ino, OSD_OII_NOGEN); - inode = osd_iget(info, dev, id); - if (IS_ERR(inode)) { - rc = PTR_ERR(inode); - if (rc == -ENOENT || rc == -ESTALE) - rc = 1; - else - CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent " - "check_repair, dir = %lu/%u, name = %.*s: " - "rc = %d\n", - devname, dir->i_ino, dir->i_generation, - ent->oied_namelen, ent->oied_name, rc); + if (lma != NULL) { + if (lu_fid_eq(fid, &lma->lma_self_fid)) + GOTO(out, rc = 0); + + if (unlikely(lma->lma_compat & LMAC_NOT_IN_OI)) { + struct lu_fid *tfid = &lma->lma_self_fid; - GOTO(out_journal, rc); + if (likely(dotdot && + fid_seq(tfid) == FID_SEQ_LOCAL_FILE && + fid_oid(tfid) == REMOTE_PARENT_DIR_OID)) { + /* It must be REMOTE_PARENT_DIR and as the + * 'dotdot' entry of remote directory */ + *attr |= LUDA_IGNORE; + } else { + CDEBUG(D_LFSCK, "%s: expect remote agent " + "parent directory, but got %.*s under " + "dir = %lu/%u with the FID "DFID"\n", + devname, ent->oied_namelen, + ent->oied_name, dir->i_ino, + dir->i_generation, PFID(tfid)); + + *attr |= LUDA_UNKNOWN; + } + + GOTO(out, rc = 0); + } } - rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma); - if (rc == 0) { - LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI)); + if (!fid_is_zero(fid)) { + rc = osd_verify_ent_by_linkea(env, inode, pfid, ent->oied_name, + ent->oied_namelen); + if (rc == -ENOENT || + (rc == -ENODATA && + !(dev->od_scrub.os_file.sf_flags & SF_UPGRADE))) { + /* linkEA does not recognize the dirent entry, + * it may because the dirent entry corruption + * and points to other's inode. */ + CDEBUG(D_LFSCK, "%s: the target inode does not " + "recognize the dirent, dir = %lu/%u, " + " name = %.*s, ino = %llu, " + DFID": rc = %d\n", devname, dir->i_ino, + dir->i_generation, ent->oied_namelen, + ent->oied_name, ent->oied_ino, PFID(fid), rc); + *attr |= LUDA_UNKNOWN; - if (fid_is_sane(fid)) { - /* FID-in-dirent is valid. */ - if (lu_fid_eq(fid, &lma->lma_self_fid)) - GOTO(out_inode, rc = 0); + GOTO(out, rc = 0); + } - /* Do not repair under dryrun mode. */ - if (*attr & LUDA_VERIFY_DRYRUN) { - *attr |= LUDA_REPAIR; - GOTO(out_inode, rc = 0); - } + if (rc && rc != -ENODATA) { + CDEBUG(D_LFSCK, "%s: fail to verify FID in the dirent, " + "dir = %lu/%u, name = %.*s, ino = %llu, " + DFID": rc = %d\n", devname, dir->i_ino, + dir->i_generation, ent->oied_namelen, + ent->oied_name, ent->oied_ino, PFID(fid), rc); + *attr |= LUDA_UNKNOWN; - if (dev->od_dirent_journal == 0) { - iput(inode); - brelse(bh); - if (hlock != NULL) - ldiskfs_htree_unlock(hlock); - else - up_read(&obj->oo_ext_idx_sem); - dev->od_dirent_journal = 1; - goto again; - } + GOTO(out, rc = 0); + } + } + if (lma != NULL) { + /* linkEA recognizes the dirent entry, the FID-in-LMA is + * valid, trusted, in spite of fid_is_sane(fid) or not. */ + if (*attr & LUDA_VERIFY_DRYRUN) { *fid = lma->lma_self_fid; - dirty = true; - /* Update the FID-in-dirent. */ - rc = osd_dirent_update(jh, sb, ent, fid, bh, de); - if (rc == 0) - *attr |= LUDA_REPAIR; - else - CDEBUG(D_LFSCK, "%.16s: fail to update FID " - "in the dirent, dir = %lu/%u, " - "name = %.*s, "DFID": rc = %d\n", - devname, dir->i_ino, dir->i_generation, - ent->oied_namelen, ent->oied_name, - PFID(fid), rc); - } else { - /* Do not repair under dryrun mode. */ - if (*attr & LUDA_VERIFY_DRYRUN) { - *fid = lma->lma_self_fid; - *attr |= LUDA_REPAIR; - GOTO(out_inode, rc = 0); - } + *attr |= LUDA_REPAIR; - if (dev->od_dirent_journal == 0) { - iput(inode); - brelse(bh); - if (hlock != NULL) - ldiskfs_htree_unlock(hlock); - else - up_read(&obj->oo_ext_idx_sem); - dev->od_dirent_journal = 1; - goto again; + GOTO(out, rc = 0); + } + + if (jh == NULL) { + brelse(bh); + dev->od_dirent_journal = 1; + if (hlock != NULL) { + ldiskfs_htree_unlock(hlock); + hlock = NULL; + } else { + up_read(&obj->oo_ext_idx_sem); } - *fid = lma->lma_self_fid; - dirty = true; - /* Append the FID-in-dirent. */ - rc = osd_dirent_reinsert(env, jh, dir, inode, ent, - fid, bh, de, hlock); - if (rc == 0) - *attr |= LUDA_REPAIR; - else - CDEBUG(D_LFSCK, "%.16s: fail to append FID " - "after the dirent, dir = %lu/%u, " - "name = %.*s, "DFID": rc = %d\n", - devname, dir->i_ino, dir->i_generation, - ent->oied_namelen, ent->oied_name, - PFID(fid), rc); + goto again; } - } else if (rc == -ENODATA) { - /* Do not repair under dryrun mode. */ + + *fid = lma->lma_self_fid; + dirty = true; + /* Update or append the FID-in-dirent. */ + rc = osd_dirent_reinsert(env, dev, jh, dentry, fid, + bh, de, hlock, dotdot); + if (rc == 0) + *attr |= LUDA_REPAIR; + else + CDEBUG(D_LFSCK, "%s: fail to re-insert FID after " + "the dirent, dir = %lu/%u, name = %.*s, " + "ino = %llu, "DFID": rc = %d\n", + devname, dir->i_ino, dir->i_generation, + ent->oied_namelen, ent->oied_name, + ent->oied_ino, PFID(fid), rc); + } else { + /* lma is NULL, trust the FID-in-dirent if it is valid. */ if (*attr & LUDA_VERIFY_DRYRUN) { if (fid_is_sane(fid)) { *attr |= LUDA_REPAIR; - } else { + } else if (dev->od_index == 0) { lu_igif_build(fid, inode->i_ino, inode->i_generation); *attr |= LUDA_UPGRADE; } - GOTO(out_inode, rc = 0); + + GOTO(out, rc = 0); } - if (dev->od_dirent_journal == 0) { - iput(inode); + if (jh == NULL) { brelse(bh); - if (hlock != NULL) + dev->od_dirent_journal = 1; + if (hlock != NULL) { ldiskfs_htree_unlock(hlock); - else + hlock = NULL; + } else { up_read(&obj->oo_ext_idx_sem); - dev->od_dirent_journal = 1; + } + goto again; } @@ -5235,37 +6295,37 @@ again: if (rc == 0) *attr |= LUDA_REPAIR; else - CDEBUG(D_LFSCK, "%.16s: fail to set LMA for " + CDEBUG(D_LFSCK, "%s: fail to set LMA for " "update dirent, dir = %lu/%u, " - "name = %.*s, "DFID": rc = %d\n", + "name = %.*s, ino = %llu, " + DFID": rc = %d\n", devname, dir->i_ino, dir->i_generation, ent->oied_namelen, ent->oied_name, - PFID(fid), rc); - } else { + ent->oied_ino, PFID(fid), rc); + } else if (dev->od_index == 0) { lu_igif_build(fid, inode->i_ino, inode->i_generation); /* It is probably IGIF object. Only aappend the * FID-in-dirent. OI scrub will process FID-in-LMA. */ - rc = osd_dirent_reinsert(env, jh, dir, inode, ent, - fid, bh, de, hlock); + rc = osd_dirent_reinsert(env, dev, jh, dentry, fid, + bh, de, hlock, dotdot); if (rc == 0) *attr |= LUDA_UPGRADE; else - CDEBUG(D_LFSCK, "%.16s: fail to append IGIF " + CDEBUG(D_LFSCK, "%s: fail to append IGIF " "after the dirent, dir = %lu/%u, " - "name = %.*s, "DFID": rc = %d\n", + "name = %.*s, ino = %llu, " + DFID": rc = %d\n", devname, dir->i_ino, dir->i_generation, ent->oied_namelen, ent->oied_name, - PFID(fid), rc); + ent->oied_ino, PFID(fid), rc); } } - GOTO(out_inode, rc); - -out_inode: - iput(inode); + GOTO(out, rc); -out_journal: - brelse(bh); +out: + if (!IS_ERR(bh)) + brelse(bh); if (hlock != NULL) { ldiskfs_htree_unlock(hlock); } else { @@ -5274,10 +6334,15 @@ out_journal: else up_read(&obj->oo_ext_idx_sem); } + if (jh != NULL) ldiskfs_journal_stop(jh); + +out_inode: + iput(inode); if (rc >= 0 && !dirty) dev->od_dirent_journal = 0; + return rc; } @@ -5323,20 +6388,25 @@ static inline int osd_it_ea_rec(const struct lu_env *env, rc = osd_dirent_check_repair(env, obj, it, fid, id, &attr); } + + if (!fid_is_sane(fid)) + attr |= LUDA_UNKNOWN; } else { attr &= ~LU_DIRENT_ATTRS_MASK; if (!fid_is_sane(fid)) { + bool is_dotdot = false; if (it->oie_dirent->oied_namelen == 2 && it->oie_dirent->oied_name[0] == '.' && - it->oie_dirent->oied_name[1] == '.') { - /* If the parent is on remote MDT, and there - * is no FID-in-dirent, then we have to get - * the parent FID from the linkEA. */ - if (ino == osd_remote_parent_ino(dev)) - rc = osd_get_pfid_from_linkea(env, obj, - fid); + it->oie_dirent->oied_name[1] == '.') + is_dotdot = true; + /* If the parent is on remote MDT, and there + * is no FID-in-dirent, then we have to get + * the parent FID from the linkEA. */ + if (ino == osd_remote_parent_ino(dev) && is_dotdot) { + rc = osd_get_pfid_from_linkea(env, obj, fid); } else { - if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) + if (is_dotdot == false && + OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP)) RETURN(-ENOENT); rc = osd_ea_fid_get(env, obj, ino, fid, id); @@ -5358,7 +6428,7 @@ static inline int osd_it_ea_rec(const struct lu_env *env, if (osd_remote_fid(env, dev, fid)) RETURN(0); - if (likely(!(attr & LUDA_IGNORE) && rc == 0)) + if (likely(!(attr & (LUDA_IGNORE | LUDA_UNKNOWN)) && rc == 0)) osd_add_oi_cache(oti, dev, id, fid); RETURN(rc > 0 ? 0 : rc); @@ -5511,15 +6581,23 @@ static void osd_key_fini(const struct lu_context *ctx, struct lu_context_key *key, void* data) { struct osd_thread_info *info = data; + struct ldiskfs_inode_info *lli = LDISKFS_I(info->oti_inode); + struct osd_idmap_cache *idc = info->oti_ins_cache; if (info->oti_inode != NULL) - OBD_FREE_PTR(info->oti_inode); + OBD_FREE_PTR(lli); if (info->oti_hlock != NULL) ldiskfs_htree_lock_free(info->oti_hlock); OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE); lu_buf_free(&info->oti_iobuf.dr_pg_buf); lu_buf_free(&info->oti_iobuf.dr_bl_buf); lu_buf_free(&info->oti_big_buf); + if (idc != NULL) { + LASSERT(info->oti_ins_cache_size > 0); + OBD_FREE(idc, sizeof(*idc) * info->oti_ins_cache_size); + info->oti_ins_cache = NULL; + info->oti_ins_cache_size = 0; + } OBD_FREE_PTR(info); } @@ -5644,7 +6722,7 @@ static int osd_mount(const struct lu_env *env, struct osd_thread_info *info = osd_oti_get(env); struct lu_fid *fid = &info->oti_fid; struct inode *inode; - int rc = 0, force_over_128tb = 0; + int rc = 0, force_over_512tb = 0; ENTRY; if (o->od_mnt != NULL) @@ -5668,10 +6746,27 @@ static int osd_mount(const struct lu_env *env, RETURN(-EINVAL); } #endif - if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) - force_over_128tb = 1; +#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0) + if (opts != NULL && strstr(opts, "force_over_128tb") != NULL) { + CWARN("force_over_128tb option is deprecated. " + "Filesystems less than 512TB can be created without any " + "force options. Use force_over_512tb option for " + "filesystems greater than 512TB.\n"); + } +#endif +#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 1, 53, 0) + if (opts != NULL && strstr(opts, "force_over_256tb") != NULL) { + CWARN("force_over_256tb option is deprecated. " + "Filesystems less than 512TB can be created without any " + "force options. Use force_over_512tb option for " + "filesystems greater than 512TB.\n"); + } +#endif + + if (opts != NULL && strstr(opts, "force_over_512tb") != NULL) + force_over_512tb = 1; - OBD_PAGE_ALLOC(__page, GFP_IOFS); + __page = alloc_page(GFP_KERNEL); if (__page == NULL) GOTO(out, rc = -ENOMEM); page = (unsigned long)page_address(__page); @@ -5689,6 +6784,8 @@ static int osd_mount(const struct lu_env *env, /* strip out option we processed in osd */ "bigendian_extents", "force_over_128tb", + "force_over_256tb", + "force_over_512tb", NULL }; strcat(options, opts); @@ -5716,7 +6813,7 @@ static int osd_mount(const struct lu_env *env, /* Glom up mount options */ if (*options != '\0') strcat(options, ","); - strlcat(options, "no_mbcache", PAGE_CACHE_SIZE); + strlcat(options, "no_mbcache,nodelalloc", PAGE_SIZE); type = get_fs_type("ldiskfs"); if (!type) { @@ -5734,11 +6831,12 @@ static int osd_mount(const struct lu_env *env, GOTO(out, rc); } - if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) > (8ULL << 32) && - force_over_128tb == 0) { + if (ldiskfs_blocks_count(LDISKFS_SB(osd_sb(o))->s_es) << + osd_sb(o)->s_blocksize_bits > 512ULL << 40 && + force_over_512tb == 0) { CERROR("%s: device %s LDISKFS does not support filesystems " - "greater than 128TB and can cause data corruption. " - "Use \"force_over_128tb\" mount option to override.\n", + "greater than 512TB and can cause data corruption. " + "Use \"force_over_512tb\" mount option to override.\n", name, dev); GOTO(out, rc = -EINVAL); } @@ -5786,7 +6884,7 @@ out_mnt: out: if (__page) - OBD_PAGE_FREE(__page); + __free_page(__page); return rc; } @@ -5827,6 +6925,7 @@ static int osd_device_init0(const struct lu_env *env, spin_lock_init(&o->od_osfs_lock); mutex_init(&o->od_otable_mutex); + INIT_LIST_HEAD(&o->od_orphan_list); o->od_read_cache = 1; o->od_writethrough_cache = 1; @@ -5839,7 +6938,9 @@ static int osd_device_init0(const struct lu_env *env, GOTO(out, rc); } - if (server_name_is_ost(o->od_svname)) + o->od_index = -1; /* -1 means index is invalid */ + rc = server_name2index(o->od_svname, &o->od_index, NULL); + if (rc == LDD_F_SV_TYPE_OST) o->od_is_ost = 1; o->od_full_scrub_ratio = OFSR_DEFAULT; @@ -6147,10 +7248,11 @@ static struct obd_ops osd_obd_device_ops = { .o_health_check = osd_health_check, }; -static int __init osd_mod_init(void) +static int __init osd_init(void) { int rc; + LASSERT(BH_DXLock < sizeof(((struct buffer_head *)0)->b_state) * 8); #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK) /* please, try to keep osd_thread_info smaller than a page */ CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE); @@ -6170,16 +7272,16 @@ static int __init osd_mod_init(void) return rc; } -static void __exit osd_mod_exit(void) +static void __exit osd_exit(void) { class_unregister_type(LUSTRE_OSD_LDISKFS_NAME); lu_kmem_fini(ldiskfs_caches); } -MODULE_AUTHOR("Sun Microsystems, Inc. "); +MODULE_AUTHOR("OpenSFS, Inc. "); MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")"); MODULE_VERSION(LUSTRE_VERSION_STRING); MODULE_LICENSE("GPL"); -module_init(osd_mod_init); -module_exit(osd_mod_exit); +module_init(osd_init); +module_exit(osd_exit);