From 52a465cf16b438b6777675c35ed653063d936ad2 Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Tue, 29 Mar 2016 20:57:36 +0300 Subject: [PATCH] LU-7939 osd-ldiskfs: check IS_ERR() instead of NULL osd_ldiskfs_find_entry() returns ERR_PTR() but checked for NULL. Change-Id: I9bf6a7f331fd1e6c34c7ea2209944748e832891d Signed-off-by: Dmitry Eremin Reviewed-on: http://review.whamcloud.com/19197 Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_compat.c | 30 ++++++++++++++++-------------- lustre/osd-ldiskfs/osd_handler.c | 25 +++++++++++++------------ lustre/osd-ldiskfs/osd_internal.h | 6 ++++-- lustre/osd-ldiskfs/osd_oi.c | 2 +- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index cec04db..0fd606c 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -288,9 +288,9 @@ int osd_delete_from_remote_parent(const struct lu_env *env, mutex_lock(&parent->d_inode->i_mutex); bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de, NULL, NULL); - if (bh == NULL) { + if (IS_ERR(bh)) { mutex_unlock(&parent->d_inode->i_mutex); - RETURN(-ENOENT); + RETURN(PTR_ERR(bh)); } CDEBUG(D_INODE, "%s: el %s:%lu to remote parent %lu.\n", osd_name(osd), name, obj->oo_inode->i_ino, parent->d_inode->i_ino); @@ -329,8 +329,8 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti, mutex_lock(&parent->d_inode->i_mutex); bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de, NULL, NULL); - if (bh == NULL) { - rc = -ENOENT; + if (IS_ERR(bh)) { + rc = PTR_ERR(bh); } else { rc = 0; osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN); @@ -549,8 +549,8 @@ static int osd_obj_update_entry(struct osd_thread_info *info, ll_vfs_dq_init(parent); mutex_lock(&parent->i_mutex); bh = osd_ldiskfs_find_entry(parent, &child->d_name, &de, NULL, NULL); - if (bh == NULL) - GOTO(out, rc = -ENOENT); + if (IS_ERR(bh)) + GOTO(out, rc = PTR_ERR(bh)); if (le32_to_cpu(de->inode) == id->oii_ino) GOTO(out, rc = 1); @@ -652,7 +652,8 @@ update: GOTO(out, rc); out: - brelse(bh); + if (!IS_ERR(bh)) + brelse(bh); mutex_unlock(&parent->i_mutex); return rc; } @@ -682,9 +683,10 @@ static int osd_obj_del_entry(struct osd_thread_info *info, ll_vfs_dq_init(dir); mutex_lock(&dir->i_mutex); - rc = -ENOENT; bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL); - if (bh) { + if (IS_ERR(bh)) { + rc = PTR_ERR(bh); + } else { rc = ldiskfs_delete_entry(th, dir, de, bh); brelse(bh); } @@ -953,8 +955,8 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev, bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL); mutex_unlock(&dir->i_mutex); - if (bh == NULL) - RETURN(-ENOENT); + if (IS_ERR(bh)) + RETURN(PTR_ERR(bh)); osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN); brelse(bh); @@ -1136,7 +1138,7 @@ int osd_obj_map_recover(struct osd_thread_info *info, mutex_lock(&src_parent->i_mutex); mutex_lock(&dir->i_mutex); bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL); - if (bh != NULL) { + if (!IS_ERR(bh)) { /* XXX: If some other object occupied the same slot. And If such * inode is zero-sized and with SUID+SGID, then means it is * a new created one. Maybe we can remove it and insert the @@ -1172,8 +1174,8 @@ int osd_obj_map_recover(struct osd_thread_info *info, bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, &de, NULL, NULL); - if (unlikely(bh == NULL)) - GOTO(unlock, rc = -ENOENT); + if (unlikely(IS_ERR(bh))) + GOTO(unlock, rc = PTR_ERR(bh)); rc = ldiskfs_delete_entry(jh, src_parent, de, bh); brelse(bh); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index a7d5744..fd97306 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -4225,7 +4225,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) { + 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. @@ -4254,11 +4254,11 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt, le32_to_cpu(de->inode)); } } - rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh); - brelse(bh); - } 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 @@ -4484,7 +4484,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) { @@ -4496,8 +4496,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); } } @@ -4842,7 +4842,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; @@ -4888,7 +4888,7 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj, if (rc != 0) fid_zero(&oic->oic_fid); } else { - rc = -ENOENT; + rc = PTR_ERR(bh); } GOTO(out, rc); @@ -5874,7 +5874,7 @@ again: * For the whole directory, only dot/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) != inode->i_ino) || + if (IS_ERR(bh) || (le32_to_cpu(de->inode) != inode->i_ino) || (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) { *attr |= LUDA_IGNORE; @@ -6042,7 +6042,8 @@ again: GOTO(out, rc); out: - brelse(bh); + if (!IS_ERR(bh)) + brelse(bh); if (hlock != NULL) { ldiskfs_htree_unlock(hlock); } else { diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index d7baa6a..90cb723 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -784,7 +784,8 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) # define osd_ldiskfs_append(handle, inode, nblock) \ ldiskfs_append(handle, inode, nblock) # define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \ - __ldiskfs_find_entry(dir, name, de, inlined, lock) + (__ldiskfs_find_entry(dir, name, de, inlined, lock) ?: \ + ERR_PTR(-ENOENT)) # define osd_journal_start(inode, type, nblocks) \ ldiskfs_journal_start(inode, type, nblocks) # define osd_transaction_size(dev) \ @@ -809,7 +810,8 @@ static inline struct buffer_head *osd_ldiskfs_append(handle_t *handle, } # define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \ - __ldiskfs_find_entry(dir, name, de, lock) + (__ldiskfs_find_entry(dir, name, de, lock) ?: \ + ERR_PTR(-ENOENT)) # define osd_journal_start(inode, type, nblocks) \ ldiskfs_journal_start(inode, nblocks) # define osd_transaction_size(dev) \ diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index a57e21a..2889143 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -117,7 +117,7 @@ static int osd_oi_index_create_one(struct osd_thread_info *info, dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name)); bh = osd_ldiskfs_find_entry(dir, &dentry->d_name, &de, NULL, NULL); - if (bh) { + if (!IS_ERR(bh)) { osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN); brelse(bh); inode = osd_iget(info, osd, id); -- 1.8.3.1