Whamcloud - gitweb
LU-11770 osd-ldiskfs: clean up inline macro usage 41/33841/7
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 12 Dec 2018 23:28:38 +0000 (16:28 -0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 30 Jan 2019 02:40:39 +0000 (02:40 +0000)
Remove inline macro usage as much as possible in the osd-ldiskfs
code, per Linux and Lustre code style.  Balance start/end braces
for functions to keep syntax highlighting working properly.

Change the autoconf macros to be checking for the new structure
fields instead of the old fields, and add compat macros for older
kernels so that they can later be removed without code churn.

Remove direct inode->truncate() usage and autoconf check, since
ldiskfs_truncate() has been exported since at least RHEL6.3.

Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ifc3187275c1841918228fac2368b18a9fa89a47d
Reviewed-on: https://review.whamcloud.com/33841
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/autoconf/lustre-core.m4
lustre/osd-ldiskfs/osd_compat.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_io.c

index 086d574..029a2f5 100644 (file)
@@ -716,23 +716,6 @@ blk_plug, [
 ]) # LC_HAVE_BLK_PLUG
 
 #
-# LC_IOP_TRUNCATE
-#
-# truncate callback removed since 2.6.39
-#
-AC_DEFUN([LC_IOP_TRUNCATE], [
-LB_CHECK_COMPILE([if 'inode_operations' has '.truncate' member function],
-inode_ops_truncate, [
-       #include <linux/fs.h>
-],[
-       ((struct inode_operations *)0)->truncate(NULL);
-],[
-       AC_DEFINE(HAVE_INODEOPS_TRUNCATE, 1,
-               [inode_operations has .truncate member function])
-])
-]) # LC_IOP_TRUNCATE
-
-#
 # LC_HAVE_FSTYPE_MOUNT
 #
 # 2.6.39 replace get_sb with mount in struct file_system_type
@@ -1770,81 +1753,6 @@ inode_ops_set_acl, [
 ]) # LC_IOP_SET_ACL
 
 #
-# LC_HAVE_BI_CNT
-#
-# 4.4 redefined bi_cnt as __bi_cnt
-#
-AC_DEFUN([LC_HAVE_BI_CNT], [
-LB_CHECK_COMPILE([if Linux kernel has bi_cnt in struct bio],
-have_bi_cnt, [
-       #include <asm/atomic.h>
-       #include <linux/bio.h>
-],[
-       struct bio bio = { };
-       int cnt;
-       cnt = atomic_read(&bio.bi_cnt);
-], [
-       AC_DEFINE(HAVE_BI_CNT, 1,
-               [struct bio has bi_cnt])
-])
-]) # LC_HAVE_BI_CNT
-
-#
-# LC_HAVE_BI_RW
-#
-# 4.4 redefined bi_rw as bi_opf
-#
-AC_DEFUN([LC_HAVE_BI_RW], [
-LB_CHECK_COMPILE([if Linux kernel has bi_rw in struct bio],
-have_bi_rw, [
-       #include <linux/bio.h>
-],[
-       struct bio bio;
-
-       bio.bi_rw = 0;
-], [
-       AC_DEFINE(HAVE_BI_RW, 1,
-               [struct bio has bi_rw])
-])
-]) # LC_HAVE_BI_RW
-
-#
-# LC_HAVE_SUBMIT_BIO_2ARGS
-#
-# 4.4 removed an argument from submit_bio
-#
-AC_DEFUN([LC_HAVE_SUBMIT_BIO_2ARGS], [
-LB_CHECK_COMPILE([if submit_bio takes two arguments],
-have_submit_bio_2args, [
-       #include <linux/bio.h>
-],[
-       struct bio bio;
-       submit_bio(READ, &bio);
-], [
-       AC_DEFINE(HAVE_SUBMIT_BIO_2ARGS, 1,
-               [submit_bio takes two arguments])
-])
-]) # LC_HAVE_SUBMIT_BIO_2_ARGS
-
-#
-# LC_HAVE_CLEAN_BDEV_ALIASES
-#
-# 4.4 unmap_underlying_metadata was replaced by clean_bdev_aliases
-#
-AC_DEFUN([LC_HAVE_CLEAN_BDEV_ALIASES], [
-LB_CHECK_COMPILE([if kernel has clean_bdev_aliases],
-have_clean_bdev_aliases, [
-       #include <linux/buffer_head.h>
-],[
-       struct block_device bdev;
-       clean_bdev_aliases(&bdev,1,1);
-], [
-       AC_DEFINE(HAVE_CLEAN_BDEV_ALIASES, 1,
-               [kernel has clean_bdev_aliases])
-])
-]) # LC_HAVE_CLEAN_BDEV_ALIASES
-
-#
 # LC_HAVE_TRUNCATE_IPAGE_FINAL
 #
 # 3.14 bring truncate_inode_pages_final for evict_inode
@@ -2203,6 +2111,27 @@ LB_CHECK_EXPORT([new_sync_read], [fs/read_write.c],
 ]) # LC_HAVE_SYNC_READ_WRITE
 
 #
+# LC_HAVE___BI_CNT
+#
+# 4.1 redefined bi_cnt as __bi_cnt in commit dac56212e8127dbc0
+#
+AC_DEFUN([LC_HAVE___BI_CNT], [
+LB_CHECK_COMPILE([if Linux kernel has __bi_cnt in struct bio],
+have___bi_cnt, [
+       #include <asm/atomic.h>
+       #include <linux/bio.h>
+       #include <linux/blk_types.h>
+],[
+       struct bio bio = { };
+       int cnt;
+       cnt = atomic_read(&bio.__bi_cnt);
+], [
+       AC_DEFINE(HAVE___BI_CNT, 1,
+               [struct bio has __bi_cnt])
+])
+]) # LC_HAVE___BI_CNT
+
+#
 # LC_NEW_CANCEL_DIRTY_PAGE
 #
 # 4.2 kernel has new cancel_dirty_page
@@ -2382,6 +2311,62 @@ bio_integrity_prep_fn, [
 ]) # LC_BIO_INTEGRITY_PREP_FN
 
 #
+# LC_HAVE_BI_OPF
+#
+# 4.4/4.8 redefined bi_rw as bi_opf (SLES12/kernel commit 4382e33ad37486)
+#
+AC_DEFUN([LC_HAVE_BI_OPF], [
+LB_CHECK_COMPILE([if Linux kernel has bi_opf in struct bio],
+have_bi_opf, [
+       #include <linux/bio.h>
+],[
+       struct bio bio;
+
+       bio.bi_opf = 0;
+], [
+       AC_DEFINE(HAVE_BI_OPF, 1,
+               [struct bio has bi_opf])
+])
+]) # LC_HAVE_BI_OPF
+
+#
+# LC_HAVE_SUBMIT_BIO_2ARGS
+#
+# 4.4 removed an argument from submit_bio
+#
+AC_DEFUN([LC_HAVE_SUBMIT_BIO_2ARGS], [
+LB_CHECK_COMPILE([if submit_bio takes two arguments],
+have_submit_bio_2args, [
+       #include <linux/bio.h>
+],[
+       struct bio bio;
+       submit_bio(READ, &bio);
+], [
+       AC_DEFINE(HAVE_SUBMIT_BIO_2ARGS, 1,
+               [submit_bio takes two arguments])
+])
+]) # LC_HAVE_SUBMIT_BIO_2_ARGS
+
+#
+# LC_HAVE_CLEAN_BDEV_ALIASES
+#
+# 4.4/4.9 unmap_underlying_metadata was replaced by clean_bdev_aliases
+# (SLES12/kernel commit 29f3ad7d8380364c)
+#
+AC_DEFUN([LC_HAVE_CLEAN_BDEV_ALIASES], [
+LB_CHECK_COMPILE([if kernel has clean_bdev_aliases],
+have_clean_bdev_aliases, [
+       #include <linux/buffer_head.h>
+],[
+       struct block_device bdev;
+       clean_bdev_aliases(&bdev,1,1);
+], [
+       AC_DEFINE(HAVE_CLEAN_BDEV_ALIASES, 1,
+               [kernel has clean_bdev_aliases])
+])
+]) # LC_HAVE_CLEAN_BDEV_ALIASES
+
+#
 # LC_HAVE_LOCKS_LOCK_FILE_WAIT
 #
 # 4.4 kernel have moved locks API users to
@@ -3048,7 +3033,6 @@ AC_DEFUN([LC_PROG_LINUX], [
        # 2.6.39
        LC_HAVE_FHANDLE_SYSCALLS
        LC_HAVE_FSTYPE_MOUNT
-       LC_IOP_TRUNCATE
        LC_HAVE_INODE_OWNER_OR_CAPABLE
        LC_HAVE_SECURITY_IINITSEC
 
@@ -3165,6 +3149,7 @@ AC_DEFUN([LC_PROG_LINUX], [
        # 4.1.0
        LC_IOV_ITER_RW
        LC_HAVE_SYNC_READ_WRITE
+       LC_HAVE___BI_CNT
 
        # 4.2
        LC_NEW_CANCEL_DIRTY_PAGE
@@ -3181,8 +3166,7 @@ AC_DEFUN([LC_PROG_LINUX], [
        LC_HAVE_LOCKS_LOCK_FILE_WAIT
        LC_HAVE_KEY_PAYLOAD_DATA_ARRAY
        LC_HAVE_XATTR_HANDLER_NAME
-       LC_HAVE_BI_CNT
-       LC_HAVE_BI_RW
+       LC_HAVE_BI_OPF
        LC_HAVE_SUBMIT_BIO_2ARGS
        LC_HAVE_CLEAN_BDEV_ALIASES
 
index 1374f90..680d236 100644 (file)
@@ -1407,11 +1407,7 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
 #ifndef HAVE_BIO_INTEGRITY_ENABLED
 bool bio_integrity_enabled(struct bio *bio)
 {
-# ifdef HAVE_BI_BDEV
-       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
-# else
-       struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
-# endif
+       struct blk_integrity *bi = blk_get_integrity(bio_get_disk(bio));
 
        if (bio_op(bio) != REQ_OP_READ && bio_op(bio) != REQ_OP_WRITE)
                return false;
index aa8a293..606c69c 100644 (file)
@@ -1371,10 +1371,13 @@ bool bio_integrity_enabled(struct bio *bio);
 #endif
 
 #ifdef HAVE_BI_BDEV
-# define bio_set_dev(bio, bdev) ((bio)->bi_bdev = bdev)
-# define bio_get_queue(bio)    bdev_get_queue((bio)->bi_bdev)
+# define bio_get_dev(bio)      ((bio)->bi_bdev)
+# define bio_get_disk(bio)     (bio_get_dev(bio)->bd_disk)
+# define bio_get_queue(bio)    bdev_get_queue(bio_get_dev(bio))
+# define bio_set_dev(bio, bdev) (bio_get_dev(bio) = (bdev))
 #else
-# define bio_get_queue(bio)    ((bio)->bi_disk->queue)
+# define bio_get_disk(bio)     ((bio)->bi_disk)
+# define bio_get_queue(bio)    (bio_get_disk(bio)->queue)
 #endif
 
 void ldiskfs_inc_count(handle_t *handle, struct inode *inode);
@@ -1444,6 +1447,29 @@ void osd_trunc_unlock_all(struct list_head *list);
 void osd_process_truncates(struct list_head *list);
 void osd_execute_truncate(struct osd_object *obj);
 
+#ifdef HAVE_BIO_ENDIO_USES_ONE_ARG
+#define osd_dio_complete_routine(bio, error) dio_complete_routine(bio)
+#else
+#define osd_dio_complete_routine(bio, error) dio_complete_routine(bio, error)
+#endif
+
+#ifndef HAVE___BI_CNT
+#define __bi_cnt bi_cnt
+#endif
+
+#ifndef HAVE_BI_OPF
+#define bi_opf bi_rw
+#endif
+
+#ifndef HAVE_CLEAN_BDEV_ALIASES
+#define clean_bdev_aliases(bdev, block, len)   \
+       unmap_underlying_metadata((bdev), (block))
+#endif
+
+#ifndef HAVE_BI_STATUS
+#define bi_status bi_error
+#endif
+
 /*
  * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
  * This limit is arbitrary, but is reasonable for the xattr API.
@@ -1460,6 +1486,22 @@ struct osd_bio_private {
 int osd_get_integrity_profile(struct osd_device *osd,
                              integrity_gen_fn **generate_fn,
                              integrity_vrfy_fn **verify_fn);
+#else
+#define integrity_gen_fn void
+#define integrity_vrfy_fn int
+static inline int osd_get_integrity_profile(struct osd_device *osd,
+                                           integrity_gen_fn **generate_fn,
+                                           integrity_vrfy_fn **verify_fn)
+{
+       return 0;
+}
+
+static inline bool bio_integrity_prep_fn(struct bio *bio,
+                                        integrity_gen_fn *generate_fn,
+                                        integrity_vrfy_fn *verify_fn)
+{
+       return bio_integrity_prep(bio);
+}
 #endif
 
 #endif /* _OSD_INTERNAL_H */
index fa04a31..134dcdb 100644 (file)
@@ -158,11 +158,7 @@ void osd_fini_iobuf(struct osd_device *d, struct osd_iobuf *iobuf)
 #ifdef HAVE_BIO_ENDIO_USES_ONE_ARG
 static void dio_complete_routine(struct bio *bio)
 {
-# ifdef HAVE_BI_STATUS
        int error = bio->bi_status;
-# else
-       int error = bio->bi_error;
-# endif
 #else
 static void dio_complete_routine(struct bio *bio, int error)
 {
@@ -183,28 +179,13 @@ static void dio_complete_routine(struct bio *bio, int error)
                       "(like SCSI errors, perhaps).  Because bi_private is "
                       "NULL, I can't wake up the thread that initiated this "
                       "IO - you will probably have to reboot this node.\n");
-               CERROR("bi_next: %p, bi_flags: %lx, "
-#ifdef HAVE_BI_RW
-                      "bi_rw: %lu,"
-#else
-                      "bi_opf: %u,"
-#endif
-                      "bi_vcnt: %d, bi_idx: %d, bi->size: %d, bi_end_io: %p,"
-                      "bi_cnt: %d, bi_private: %p\n", bio->bi_next,
-                       (unsigned long)bio->bi_flags,
-#ifdef HAVE_BI_RW
-                       bio->bi_rw,
-#else
-                       bio->bi_opf,
-#endif
-                       bio->bi_vcnt, bio_idx(bio),
-                       bio_sectors(bio) << 9, bio->bi_end_io,
-#ifdef HAVE_BI_CNT
-                       atomic_read(&bio->bi_cnt),
-#else
-                       atomic_read(&bio->__bi_cnt),
-#endif
-                       bio->bi_private);
+               CERROR("bi_next: %p, bi_flags: %lx, " __stringify(bi_opf)
+                      ": %x, bi_vcnt: %d, bi_idx: %d, bi->size: %d, bi_end_io: %p, bi_cnt: %d, bi_private: %p\n",
+                      bio->bi_next, (unsigned long)bio->bi_flags,
+                      (unsigned int)bio->bi_opf, bio->bi_vcnt, bio_idx(bio),
+                      bio_sectors(bio) << 9, bio->bi_end_io,
+                      atomic_read(&bio->__bi_cnt),
+                      bio->bi_private);
                return;
        }
 
@@ -273,15 +254,12 @@ static void record_start_io(struct osd_iobuf *iobuf, int size)
 
 static void osd_submit_bio(int rw, struct bio *bio)
 {
-        LASSERTF(rw == 0 || rw == 1, "%x\n", rw);
+       LASSERTF(rw == 0 || rw == 1, "%x\n", rw);
 #ifdef HAVE_SUBMIT_BIO_2ARGS
-        if (rw == 0)
-                submit_bio(READ, bio);
-        else
-                submit_bio(WRITE, bio);
+       submit_bio(rw ? WRITE : READ, bio);
 #else
-        bio->bi_opf |= rw;
-        submit_bio(bio);
+       bio->bi_opf |= rw;
+       submit_bio(bio);
 #endif
 }
 
@@ -381,26 +359,20 @@ static int osd_bio_integrity_handle(struct osd_device *osd, struct bio *bio,
                                    bool integrity_enabled)
 {
        struct super_block *sb = osd_sb(osd);
-       int rc;
-#ifdef HAVE_BIO_INTEGRITY_PREP_FN
        integrity_gen_fn *generate_fn = NULL;
        integrity_vrfy_fn *verify_fn = NULL;
-#endif
+       int rc;
 
        ENTRY;
 
        if (!integrity_enabled)
                RETURN(0);
 
-#ifdef HAVE_BIO_INTEGRITY_PREP_FN
        rc = osd_get_integrity_profile(osd, &generate_fn, &verify_fn);
        if (rc)
                RETURN(rc);
 
        rc = bio_integrity_prep_fn(bio, generate_fn, verify_fn);
-#else
-       rc = bio_integrity_prep(bio);
-#endif
        if (rc)
                RETURN(rc);
 
@@ -423,19 +395,14 @@ static int osd_bio_integrity_handle(struct osd_device *osd, struct bio *bio,
 #ifdef HAVE_BIO_INTEGRITY_PREP_FN
 #  ifdef HAVE_BIO_ENDIO_USES_ONE_ARG
 static void dio_integrity_complete_routine(struct bio *bio)
-{
 #  else
 static void dio_integrity_complete_routine(struct bio *bio, int error)
-{
 #  endif
+{
        struct osd_bio_private *bio_private = bio->bi_private;
 
        bio->bi_private = bio_private->obp_iobuf;
-#  ifdef HAVE_BIO_ENDIO_USES_ONE_ARG
-       dio_complete_routine(bio);
-#  else
-       dio_complete_routine(bio, error);
-#  endif
+       osd_dio_complete_routine(bio, error);
 
        OBD_FREE_PTR(bio_private);
 }
@@ -445,13 +412,14 @@ static int osd_bio_init(struct bio *bio, struct osd_iobuf *iobuf,
                        bool integrity_enabled, int start_page_idx,
                        struct osd_bio_private **pprivate)
 {
-#ifdef HAVE_BIO_INTEGRITY_PREP_FN
-       struct osd_bio_private *bio_private;
-
        ENTRY;
 
        *pprivate = NULL;
+
+#ifdef HAVE_BIO_INTEGRITY_PREP_FN
        if (integrity_enabled) {
+               struct osd_bio_private *bio_private = NULL;
+
                OBD_ALLOC_GFP(bio_private, sizeof(*bio_private), GFP_NOIO);
                if (bio_private == NULL)
                        RETURN(-ENOMEM);
@@ -460,18 +428,14 @@ static int osd_bio_init(struct bio *bio, struct osd_iobuf *iobuf,
                bio_private->obp_start_page_idx = start_page_idx;
                bio_private->obp_iobuf = iobuf;
                *pprivate = bio_private;
-       } else {
+       } else
+#endif
+       {
                bio->bi_end_io = dio_complete_routine;
                bio->bi_private = iobuf;
        }
-       RETURN(0);
-#else
-       ENTRY;
 
-       bio->bi_end_io = dio_complete_routine;
-       bio->bi_private = iobuf;
        RETURN(0);
-#endif
 }
 
 static int osd_do_bio(struct osd_device *osd, struct inode *inode,
@@ -588,11 +552,7 @@ static int osd_do_bio(struct osd_device *osd, struct inode *inode,
 
                        bio_set_dev(bio, bdev);
                        bio_set_sector(bio, sector);
-#ifdef HAVE_BI_RW
-                       bio->bi_rw = (iobuf->dr_rw == 0) ? READ : WRITE;
-#else
-                       bio->bi_opf = (iobuf->dr_rw == 0) ? READ : WRITE;
-#endif
+                       bio->bi_opf = iobuf->dr_rw ? WRITE : READ;
                        rc = osd_bio_init(bio, iobuf, integrity_enabled,
                                          bio_start_page_idx, &bio_private);
                        if (rc) {
@@ -1081,17 +1041,12 @@ map:
                                        i, cex->ec_len);
                for (; i < cex->ec_len && bp->num; i++) {
                        *(bp->blocks) = cex->ec_start + i;
-                       if (pblock != 0) {
-                               /* unmap any possible underlying metadata from
-                                * the block device mapping.  bug 6998. */
-#ifndef HAVE_CLEAN_BDEV_ALIASES
-                               unmap_underlying_metadata(inode->i_sb->s_bdev,
-                                                         *(bp->blocks));
-#else
+                       /* unmap any underlying metadata from
+                        * the block device mapping.  b=6998.
+                        */
+                       if (pblock != 0)
                                clean_bdev_aliases(inode->i_sb->s_bdev,
                                                   *(bp->blocks), 1);
-#endif
-                       }
                        bp->blocks++;
                        bp->num--;
                        bp->start++;
@@ -1279,15 +1234,9 @@ cont_map:
                                         * mapping.  bug 6998. */
                                        if ((map.m_flags & LDISKFS_MAP_NEW) &&
                                            create)
-#ifndef HAVE_CLEAN_BDEV_ALIASES
-                                               unmap_underlying_metadata(
-                                                       inode->i_sb->s_bdev,
-                                                       map.m_pblk + c);
-#else
                                                clean_bdev_aliases(
                                                        inode->i_sb->s_bdev,
                                                        map.m_pblk + c, 1);
-#endif
                                }
                        }
                        rc = 0;
@@ -2432,12 +2381,7 @@ void osd_execute_truncate(struct osd_object *obj)
                return;
        }
 
-#ifdef HAVE_INODEOPS_TRUNCATE
-       if (inode->i_op->truncate)
-               inode->i_op->truncate(inode);
-       else
-#endif
-               ldiskfs_truncate(inode);
+       ldiskfs_truncate(inode);
 
        /*
         * For a partial-page truncate, flush the page to disk immediately to