Whamcloud - gitweb
LU-7311 osd: ext4_bread has one less parameter in kernel 3.18 92/16892/7
authorfrank zago <fzago@cray.com>
Wed, 20 Jul 2016 23:24:17 +0000 (19:24 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 27 Jul 2016 03:02:01 +0000 (03:02 +0000)
The returned error code was the 5th parameter to ext4_bread until the
kernel 3.18. It was then removed and integrated into the returned
pointer. Create a shim to emulate the newer version of ext4_bread with
older kernels.

Signed-off-by: frank zago <fzago@cray.com>
Change-Id: I3dacd8b24ae7a3a823f5cc662b2ee3627f8fcda7
Reviewed-on: http://review.whamcloud.com/16892
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
config/lustre-build-ldiskfs.m4
lustre/osd-ldiskfs/osd_iam.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_io.c

index 0e6a2b0..25cca46 100644 (file)
@@ -125,6 +125,23 @@ ext4_map_blocks, [
 ])
 
 #
 ])
 
 #
+# LB_EXT4_BREAD_4ARGS
+#
+# 3.18 ext4_bread has 4 arguments
+#
+AC_DEFUN([LB_EXT4_BREAD_4ARGS], [
+LB_CHECK_COMPILE([if ext4_bread takes 4 arguments],
+ext4_bread, [
+       #include <linux/fs.h>
+       #include "$EXT4_SRC_DIR/ext4.h"
+],[
+       ext4_bread(NULL, NULL, 0, 0);
+],[
+       AC_DEFINE(HAVE_EXT4_BREAD_4ARGS, 1, [ext4_bread takes 4 arguments])
+])
+]) # LB_EXT4_BREAD_4ARGS
+
+#
 # LDISKFS_AC_PATCH_PROGRAM
 #
 # Determine which program should be used to apply the patches to
 # LDISKFS_AC_PATCH_PROGRAM
 #
 # Determine which program should be used to apply the patches to
@@ -203,6 +220,7 @@ AS_IF([test x$enable_ldiskfs != xno],[
        LB_EXT_PBLOCK
        LB_EXT4_JOURNAL_START_3ARGS
        LB_LDISKFS_MAP_BLOCKS
        LB_EXT_PBLOCK
        LB_EXT4_JOURNAL_START_3ARGS
        LB_LDISKFS_MAP_BLOCKS
+       LB_EXT4_BREAD_4ARGS
        AC_DEFINE(CONFIG_LDISKFS_FS_POSIX_ACL, 1, [posix acls for ldiskfs])
        AC_DEFINE(CONFIG_LDISKFS_FS_SECURITY, 1, [fs security for ldiskfs])
        AC_DEFINE(CONFIG_LDISKFS_FS_XATTR, 1, [extened attributes for ldiskfs])
        AC_DEFINE(CONFIG_LDISKFS_FS_POSIX_ACL, 1, [posix acls for ldiskfs])
        AC_DEFINE(CONFIG_LDISKFS_FS_SECURITY, 1, [fs security for ldiskfs])
        AC_DEFINE(CONFIG_LDISKFS_FS_XATTR, 1, [extened attributes for ldiskfs])
index 8e2e0c5..8b7047c 100644 (file)
@@ -174,20 +174,21 @@ iam_load_idle_blocks(struct iam_container *c, iam_ptr_t blk)
        struct inode *inode = c->ic_object;
        struct iam_idle_head *head;
        struct buffer_head *bh;
        struct inode *inode = c->ic_object;
        struct iam_idle_head *head;
        struct buffer_head *bh;
-       int err = 0;
 
        LASSERT(mutex_is_locked(&c->ic_idle_mutex));
 
        if (blk == 0)
                return NULL;
 
 
        LASSERT(mutex_is_locked(&c->ic_idle_mutex));
 
        if (blk == 0)
                return NULL;
 
-       bh = ldiskfs_bread(NULL, inode, blk, 0, &err);
-       if (bh == NULL) {
-               CERROR("%.16s: cannot load idle blocks, blk = %u, err = %d\n",
-                      LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, blk, err);
+       bh = __ldiskfs_bread(NULL, inode, blk, 0);
+       if (IS_ERR_OR_NULL(bh)) {
+               CERROR("%.16s: cannot load idle blocks, blk = %u, err = %ld\n",
+                      LDISKFS_SB(inode->i_sb)->s_es->s_volume_name, blk,
+                      bh ? PTR_ERR(bh) : -EIO);
                c->ic_idle_failed = 1;
                c->ic_idle_failed = 1;
-               err = err ? err : -EIO;
-               return ERR_PTR(err);
+               if (bh == NULL)
+                       bh = ERR_PTR(-EIO);
+               return bh;
        }
 
        head = (struct iam_idle_head *)(bh->b_data);
        }
 
        head = (struct iam_idle_head *)(bh->b_data);
@@ -359,8 +360,6 @@ void iam_ipd_free(struct iam_path_descr *ipd)
 int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
                   handle_t *h, struct buffer_head **bh)
 {
 int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
                   handle_t *h, struct buffer_head **bh)
 {
-        int result = 0;
-
         /* NB: it can be called by iam_lfix_guess() which is still at
          * very early stage, c->ic_root_bh and c->ic_descr->id_ops
          * haven't been intialized yet.
         /* NB: it can be called by iam_lfix_guess() which is still at
          * very early stage, c->ic_root_bh and c->ic_descr->id_ops
          * haven't been intialized yet.
@@ -373,10 +372,14 @@ int iam_node_read(struct iam_container *c, iam_ptr_t ptr,
                 return 0;
         }
 
                 return 0;
         }
 
-        *bh = ldiskfs_bread(h, c->ic_object, (int)ptr, 0, &result);
-        if (*bh == NULL)
-               result = result ? result : -EIO;
-        return result;
+       *bh = __ldiskfs_bread(h, c->ic_object, (int)ptr, 0);
+       if (IS_ERR(*bh))
+               return PTR_ERR(*bh);
+
+       if (*bh == NULL)
+               return -EIO;
+
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -1632,9 +1635,12 @@ iam_new_node(handle_t *h, struct iam_container *c, iam_ptr_t *b, int *e)
                        goto fail;
 
                mutex_unlock(&c->ic_idle_mutex);
                        goto fail;
 
                mutex_unlock(&c->ic_idle_mutex);
-               bh = ldiskfs_bread(NULL, inode, *b, 0, e);
-               if (bh == NULL) {
-                       *e = *e ? *e : -EIO;
+               bh = __ldiskfs_bread(NULL, inode, *b, 0);
+               if (IS_ERR_OR_NULL(bh)) {
+                       if (IS_ERR(bh))
+                               *e = PTR_ERR(bh);
+                       else
+                               *e = -EIO;
                        return NULL;
                }
                goto got;
                        return NULL;
                }
                goto got;
index 90cb723..1280721 100644 (file)
@@ -1208,6 +1208,30 @@ static inline unsigned long osd_remote_parent_ino(struct osd_device *dev)
        return dev->od_mdt_map->omm_remote_parent->d_inode->i_ino;
 }
 
        return dev->od_mdt_map->omm_remote_parent->d_inode->i_ino;
 }
 
+/**
+ * ext4_bread/ldiskfs_bread has either 5 or 4 parameters. The error
+ * return code has been removed and integrated into the pointer in the
+ * kernel 3.18.
+ */
+static inline struct buffer_head *__ldiskfs_bread(handle_t *handle,
+                                                 struct inode *inode,
+                                                 ldiskfs_lblk_t block,
+                                                 int create)
+{
+#ifdef HAVE_EXT4_BREAD_4ARGS
+       return ldiskfs_bread(handle, inode, block, create);
+#else
+       struct buffer_head *bh;
+       int error = 0;
+
+       bh = ldiskfs_bread(handle, inode, block, create, &error);
+       if (bh == NULL && error != 0)
+               bh = ERR_PTR(error);
+
+       return bh;
+#endif
+}
+
 void ldiskfs_inc_count(handle_t *handle, struct inode *inode);
 void ldiskfs_dec_count(handle_t *handle, struct inode *inode);
 
 void ldiskfs_inc_count(handle_t *handle, struct inode *inode);
 void ldiskfs_dec_count(handle_t *handle, struct inode *inode);
 
index bdbee56..6996f63 100644 (file)
@@ -1411,7 +1411,6 @@ int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs)
         int blocksize;
         int csize;
         int boffs;
         int blocksize;
         int csize;
         int boffs;
-       int err = 0;
 
         /* prevent reading after eof */
        spin_lock(&inode->i_lock);
 
         /* prevent reading after eof */
        spin_lock(&inode->i_lock);
@@ -1437,14 +1436,13 @@ int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs)
                 block = *offs >> inode->i_blkbits;
                 boffs = *offs & (blocksize - 1);
                 csize = min(blocksize - boffs, size);
                 block = *offs >> inode->i_blkbits;
                 boffs = *offs & (blocksize - 1);
                 csize = min(blocksize - boffs, size);
-                bh = ldiskfs_bread(NULL, inode, block, 0, &err);
-               if (err != 0) {
-                       CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n",
+               bh = __ldiskfs_bread(NULL, inode, block, 0);
+               if (IS_ERR(bh)) {
+                       CERROR("%s: can't read %u@%llu on ino %lu: rc = %ld\n",
                               LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
                               LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
-                              csize, *offs, inode->i_ino, err);
-                       if (bh != NULL)
-                               brelse(bh);
-                       return err;
+                              csize, *offs, inode->i_ino,
+                              PTR_ERR(bh));
+                       return PTR_ERR(bh);
                }
 
                if (bh != NULL) {
                }
 
                if (bh != NULL) {
@@ -1667,12 +1665,17 @@ int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
                 if (bh != NULL)
                         brelse(bh);
 
                 if (bh != NULL)
                         brelse(bh);
 
-                block = offset >> inode->i_blkbits;
-                boffs = offset & (blocksize - 1);
-                size = min(blocksize - boffs, bufsize);
-                bh = ldiskfs_bread(handle, inode, block, 1, &err);
-                if (!bh) {
-                       err = err ? err : -EIO;
+               block = offset >> inode->i_blkbits;
+               boffs = offset & (blocksize - 1);
+               size = min(blocksize - boffs, bufsize);
+               bh = __ldiskfs_bread(handle, inode, block, 1);
+               if (IS_ERR_OR_NULL(bh)) {
+                       if (bh == NULL) {
+                               err = -EIO;
+                       } else {
+                               err = PTR_ERR(bh);
+                               bh = NULL;
+                       }
                         CERROR("%s: error reading offset %llu (block %lu): "
                                "rc = %d\n",
                                inode->i_sb->s_id, offset, block, err);
                         CERROR("%s: error reading offset %llu (block %lu): "
                                "rc = %d\n",
                                inode->i_sb->s_id, offset, block, err);
@@ -1961,4 +1964,3 @@ const struct dt_body_operations osd_body_ops = {
        .dbo_fiemap_get                 = osd_fiemap_get,
        .dbo_ladvise                    = osd_ladvise,
 };
        .dbo_fiemap_get                 = osd_fiemap_get,
        .dbo_ladvise                    = osd_ladvise,
 };
-