Whamcloud - gitweb
LU-7939 osd-ldiskfs: check IS_ERR() instead of NULL 97/19197/5
authorDmitry Eremin <dmitry.eremin@intel.com>
Tue, 29 Mar 2016 17:57:36 +0000 (20:57 +0300)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 27 Jul 2016 03:01:34 +0000 (03:01 +0000)
osd_ldiskfs_find_entry() returns ERR_PTR() but checked for NULL.

Change-Id: I9bf6a7f331fd1e6c34c7ea2209944748e832891d
Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-on: http://review.whamcloud.com/19197
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/osd-ldiskfs/osd_compat.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_oi.c

index cec04db..0fd606c 100644 (file)
@@ -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);
        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);
                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);
        }
        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);
        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);
        } 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);
        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);
 
        if (le32_to_cpu(de->inode) == id->oii_ino)
                GOTO(out, rc = 1);
@@ -652,7 +652,8 @@ update:
        GOTO(out, rc);
 
 out:
        GOTO(out, rc);
 
 out:
-       brelse(bh);
+       if (!IS_ERR(bh))
+               brelse(bh);
        mutex_unlock(&parent->i_mutex);
        return rc;
 }
        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);
 
        ll_vfs_dq_init(dir);
        mutex_lock(&dir->i_mutex);
-       rc = -ENOENT;
        bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
        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);
        }
                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);
 
        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);
 
        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);
        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
                /* 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);
 
        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);
 
        rc = ldiskfs_delete_entry(jh, src_parent, de, bh);
        brelse(bh);
index a7d5744..fd97306 100644 (file)
@@ -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);
         }
 
         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.
                /* 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));
                        }
                }
                                                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
         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);
 
                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) {
                        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);
                                                        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);
        }
 
        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;
                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 {
                if (rc != 0)
                        fid_zero(&oic->oic_fid);
        } else {
-               rc = -ENOENT;
+               rc = PTR_ERR(bh);
        }
 
        GOTO(out, rc);
        }
 
        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. */
         * 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;
 
            (dot_dotdot != 0 && !osd_dot_dotdot_has_space(de, dot_dotdot))) {
                *attr |= LUDA_IGNORE;
 
@@ -6042,7 +6042,8 @@ again:
        GOTO(out, rc);
 
 out:
        GOTO(out, rc);
 
 out:
-       brelse(bh);
+       if (!IS_ERR(bh))
+               brelse(bh);
        if (hlock != NULL) {
                ldiskfs_htree_unlock(hlock);
        } else {
        if (hlock != NULL) {
                ldiskfs_htree_unlock(hlock);
        } else {
index d7baa6a..90cb723 100644 (file)
@@ -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) \
 # 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) \
 # 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) \
 }
 
 # 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) \
 # define osd_journal_start(inode, type, nblocks) \
                ldiskfs_journal_start(inode, nblocks)
 # define osd_transaction_size(dev) \
index a57e21a..2889143 100644 (file)
@@ -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);
 
        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);
                osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
                brelse(bh);
                inode = osd_iget(info, osd, id);