From 3ed0a4a64642751931fcc397511c4a118e3d1a51 Mon Sep 17 00:00:00 2001 From: Fan Yong Date: Fri, 8 Jul 2016 05:30:25 +0800 Subject: [PATCH] LU-8579 osd-ldiskfs: code cleanup for osd_ldiskfs_add_entry Commit 07660ad33a7d1 can give more warning message when directory size exceeds limitation. But some variables that are allocated on stack are unnecessary and may cause overflow. Further more, the "osd_thread_info::oti_dev" is obsolete, should not be used any more. The fid_seq_is_mdt0() is used against zero FID, will be replaced by checking whether the device is for MDT0. Signed-off-by: Fan Yong Change-Id: Idfe2a4546535b3863e84ce5753b8a86c369dadae Reviewed-on: http://review.whamcloud.com/22307 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_compat.c | 6 +-- lustre/osd-ldiskfs/osd_handler.c | 80 +++++++++++++++++++-------------------- lustre/osd-ldiskfs/osd_internal.h | 6 +-- lustre/osd-ldiskfs/osd_oi.c | 2 +- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index 500c6e7..cf94373 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -248,7 +248,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd, dentry = osd_child_dentry_by_inode(env, parent->d_inode, name, strlen(name)); mutex_lock(&parent->d_inode->i_mutex); - rc = osd_ldiskfs_add_entry(info, oh->ot_handle, dentry, + rc = osd_ldiskfs_add_entry(info, osd, oh->ot_handle, dentry, obj->oo_inode, NULL); CDEBUG(D_INODE, "%s: add %s:%lu to remote parent %lu.\n", osd_name(osd), name, obj->oo_inode->i_ino, parent->d_inode->i_ino); @@ -748,7 +748,7 @@ static int osd_obj_add_entry(struct osd_thread_info *info, ll_vfs_dq_init(dir->d_inode); mutex_lock(&dir->d_inode->i_mutex); - rc = osd_ldiskfs_add_entry(info, th, child, inode, NULL); + rc = osd_ldiskfs_add_entry(info, osd, th, child, inode, NULL); mutex_unlock(&dir->d_inode->i_mutex); RETURN(rc); @@ -1192,7 +1192,7 @@ int osd_obj_map_recover(struct osd_thread_info *info, if (rc != 0) GOTO(unlock, rc); - rc = osd_ldiskfs_add_entry(info, jh, tgt_child, inode, NULL); + rc = osd_ldiskfs_add_entry(info, osd, jh, tgt_child, inode, NULL); GOTO(unlock, rc); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index c9cbcba..e63e1c7 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -434,7 +434,7 @@ 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, +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) { @@ -442,41 +442,40 @@ int osd_ldiskfs_add_entry(struct osd_thread_info *info, rc = __ldiskfs_add_entry(handle, child, inode, hlock); if (rc == -ENOBUFS || rc == -ENOSPC) { - char fidbuf[FID_LEN + 1]; - struct lustre_mdt_attrs lma; - struct lu_fid fid = { }; - char *errstr; - struct dentry *p_dentry = child->d_parent; - - rc2 = osd_get_lma(info, p_dentry->d_inode, p_dentry, - &lma); + 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; - snprintf(fidbuf, sizeof(fidbuf), DFID, PFID(&fid)); + fid = &lma->lma_self_fid; } else if (rc2 == -ENODATA) { - if (unlikely(p_dentry->d_inode == - inode->i_sb->s_root->d_inode)) - lu_local_obj_fid(&fid, OSD_FS_ROOT_OID); - else if (info->oti_dev && !info->oti_dev->od_is_ost && - fid_seq_is_mdt0(fid_seq(&fid))) - lu_igif_build(&fid, p_dentry->d_inode->i_ino, - p_dentry->d_inode->i_generation); - snprintf(fidbuf, sizeof(fidbuf), DFID, PFID(&fid)); - } else { - snprintf(fidbuf, FID_LEN, "%s", "unknown"); + 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 (rc == -ENOSPC) - errstr = "has reached"; + 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 - errstr = "is approaching"; - CWARN("%.16s: directory (inode: %lu FID: %s) %s maximum entry limit\n", - LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, - p_dentry->d_inode->i_ino, fidbuf, errstr); + 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; } @@ -4690,8 +4689,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(info, 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; @@ -5940,10 +5939,11 @@ osd_dirent_has_space(struct ldiskfs_dir_entry_2 *de, __u16 namelen, } static int -osd_dirent_reinsert(const struct lu_env *env, 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, int dot_dotdot) +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, + int dot_dotdot) { struct inode *dir = dentry->d_parent->d_inode; struct inode *inode = dentry->d_inode; @@ -5985,7 +5985,7 @@ osd_dirent_reinsert(const struct lu_env *env, handle_t *jh, osd_get_ldiskfs_dirent_param(ldp, fid); dentry->d_fsdata = (void *)ldp; ll_vfs_dq_init(dir); - rc = osd_ldiskfs_add_entry(info, 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) @@ -6172,8 +6172,8 @@ again: *fid = lma->lma_self_fid; dirty = true; /* Update the FID-in-dirent. */ - rc = osd_dirent_reinsert(env, jh, dentry, fid, bh, de, - hlock, dot_dotdot); + rc = osd_dirent_reinsert(env, dev, jh, dentry, fid, + bh, de, hlock, dot_dotdot); if (rc == 0) *attr |= LUDA_REPAIR; else @@ -6208,8 +6208,8 @@ again: *fid = lma->lma_self_fid; dirty = true; /* Append the FID-in-dirent. */ - rc = osd_dirent_reinsert(env, jh, dentry, fid, bh, de, - hlock, dot_dotdot); + rc = osd_dirent_reinsert(env, dev, jh, dentry, fid, + bh, de, hlock, dot_dotdot); if (rc == 0) *attr |= LUDA_REPAIR; else @@ -6265,8 +6265,8 @@ again: 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, dentry, fid, bh, de, - hlock, dot_dotdot); + rc = osd_dirent_reinsert(env, dev, jh, dentry, fid, + bh, de, hlock, dot_dotdot); if (rc == 0) *attr |= LUDA_UPGRADE; else diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 9b9870d..7bf0738 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -178,7 +178,7 @@ struct osd_mdobj { struct osd_mdobj_map { struct dentry *omm_remote_parent; }; -int osd_ldiskfs_add_entry(struct osd_thread_info *info, +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); @@ -547,10 +547,6 @@ struct osd_thread_info { */ struct timespec oti_time; - /** osd_device reference, initialized in osd_trans_start() and - used in osd_trans_stop() */ - struct osd_device *oti_dev; - /** * following ipd and it structures are used for osd_index_iam_lookup() * these are defined separately as we might do index operation diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index 2889143..77bd554 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -150,7 +150,7 @@ static int osd_oi_index_create_one(struct osd_thread_info *info, feat->dif_ptrsize, feat->dif_recsize_max, jh); dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name)); - rc = osd_ldiskfs_add_entry(info, jh, dentry, inode, NULL); + rc = osd_ldiskfs_add_entry(info, osd, jh, dentry, inode, NULL); ldiskfs_journal_stop(jh); iput(inode); return rc; -- 1.8.3.1