From 632b3591b6ea21e3029299ef875179a4b5ca918f Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 26 Dec 2018 02:29:55 -0700 Subject: [PATCH] LU-11830 lov: avoid signed vs. unsigned comparison In the expansion of do_div64() GCC complains about pointer comparison because loff_t is not a u64 variable as it should be. lov_do_div64() also has signed vs. unsigned comparisons due to a signed loff_t. Change lov_do_div() to use a 64-bit variable for do_div() instead of loff_t to avoid these warnings. Change OST_MAXREQSIZE and friends to be consistently unsigned values to avoid compiler warnings. Fix "lfs mirror resync" to avoid comparing signed and unsigned valued. Signed-off-by: Andreas Dilger Change-Id: I6df31a2c0d75e5777f471fe8cb252715dd85a5b1 Reviewed-on: https://review.whamcloud.com/33921 Reviewed-by: Jian Yu Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/lustre_net.h | 27 ++++++++++++++------------- lustre/lov/lov_internal.h | 17 ++++++++++------- lustre/obdclass/lprocfs_status.c | 2 +- lustre/tests/mirror_io.c | 4 ++-- lustre/utils/liblustreapi_layout.c | 13 +++++++------ lustre/utils/liblustreapi_mirror.c | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index 3e1e299..7fe6619 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -474,20 +474,21 @@ * - OST_IO_MAXREQSIZE must be at least 1 page of cookies plus some spillover * - Must be a multiple of 1024 */ -#define _OST_MAXREQSIZE_BASE (sizeof(struct lustre_msg) + \ - sizeof(struct ptlrpc_body) + \ - sizeof(struct obdo) + \ - sizeof(struct obd_ioobj) + \ - sizeof(struct niobuf_remote)) -#define _OST_MAXREQSIZE_SUM (_OST_MAXREQSIZE_BASE + \ - sizeof(struct niobuf_remote) * \ - (DT_MAX_BRW_PAGES - 1)) +#define _OST_MAXREQSIZE_BASE ((unsigned long)(sizeof(struct lustre_msg) + \ + sizeof(struct ptlrpc_body) + \ + sizeof(struct obdo) + \ + sizeof(struct obd_ioobj) + \ + sizeof(struct niobuf_remote))) +#define _OST_MAXREQSIZE_SUM ((unsigned long)(_OST_MAXREQSIZE_BASE + \ + sizeof(struct niobuf_remote) * \ + (DT_MAX_BRW_PAGES - 1))) /** * FIEMAP request can be 4K+ for now */ -#define OST_MAXREQSIZE (16 * 1024) -#define OST_IO_MAXREQSIZE max_t(int, OST_MAXREQSIZE, \ - (((_OST_MAXREQSIZE_SUM - 1) | (1024 - 1)) + 1)) +#define OST_MAXREQSIZE (16UL * 1024UL) +#define OST_IO_MAXREQSIZE max(OST_MAXREQSIZE, \ + ((_OST_MAXREQSIZE_SUM - 1) | \ + (1024UL - 1)) + 1) /* Safe estimate of free space in standard RPC, provides upper limit for # of * bytes of i/o to pack in RPC (skipping bulk transfer). */ #define OST_SHORT_IO_SPACE (OST_IO_MAXREQSIZE - _OST_MAXREQSIZE_BASE) @@ -495,8 +496,8 @@ /* Actual size used for short i/o buffer. Calculation means this: * At least one page (for large PAGE_SIZE), or 16 KiB, but not more * than the available space aligned to a page boundary. */ -#define OBD_MAX_SHORT_IO_BYTES (min(max(PAGE_SIZE, 16UL * 1024UL), \ - OST_SHORT_IO_SPACE & PAGE_MASK)) +#define OBD_MAX_SHORT_IO_BYTES min(max(PAGE_SIZE, 16UL * 1024UL), \ + OST_SHORT_IO_SPACE & PAGE_MASK) #define OST_MAXREPSIZE (9 * 1024) #define OST_IO_MAXREPSIZE OST_MAXREPSIZE diff --git a/lustre/lov/lov_internal.h b/lustre/lov/lov_internal.h index 8454856..05bfc12 100644 --- a/lustre/lov/lov_internal.h +++ b/lustre/lov/lov_internal.h @@ -195,19 +195,22 @@ void lsm_free(struct lov_stripe_md *lsm); }) #elif BITS_PER_LONG == 32 # define lov_do_div64(n, base) ({ \ + uint64_t __num = (n); \ uint64_t __rem; \ if ((sizeof(base) > 4) && (((base) & 0xffffffff00000000ULL) != 0)) { \ - int __remainder; \ - LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), "64 bit lov " \ - "division %llu / %llu\n", (n), (uint64_t)(base)); \ - __remainder = (n) & (LOV_MIN_STRIPE_SIZE - 1); \ - (n) >>= LOV_MIN_STRIPE_BITS; \ - __rem = do_div(n, (base) >> LOV_MIN_STRIPE_BITS); \ + int __remainder; \ + LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), \ + "64 bit lov division %llu / %llu\n", \ + __num, (uint64_t)(base)); \ + __remainder = __num & (LOV_MIN_STRIPE_SIZE - 1); \ + __num >>= LOV_MIN_STRIPE_BITS; \ + __rem = do_div(__num, (base) >> LOV_MIN_STRIPE_BITS); \ __rem <<= LOV_MIN_STRIPE_BITS; \ __rem += __remainder; \ } else { \ - __rem = do_div(n, base); \ + __rem = do_div(__num, base); \ } \ + (n) = __num; \ __rem; \ }) #endif diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 34a0192..b352d6e 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2363,7 +2363,7 @@ ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr, EXPORT_SYMBOL(short_io_bytes_show); /* Used to catch people who think they're specifying pages. */ -#define MIN_SHORT_IO_BYTES 64 +#define MIN_SHORT_IO_BYTES 64U ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr, const char *buffer, size_t count) diff --git a/lustre/tests/mirror_io.c b/lustre/tests/mirror_io.c index 903a4f7..d3fb3a5 100644 --- a/lustre/tests/mirror_io.c +++ b/lustre/tests/mirror_io.c @@ -364,7 +364,7 @@ ssize_t mirror_resync_one(int fd, struct llapi_layout *layout, { uint64_t mirror_end = 0; ssize_t result = 0; - size_t count; + uint64_t count; if (end == OBD_OBJECT_EOF) count = OBD_OBJECT_EOF; @@ -373,7 +373,7 @@ ssize_t mirror_resync_one(int fd, struct llapi_layout *layout, while (count > 0) { uint32_t src; - size_t to_copy; + uint64_t to_copy; ssize_t copied; src = llapi_mirror_find(layout, start, end, &mirror_end); diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index f84b3b3..591946e 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -2569,7 +2569,7 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, struct llapi_resync_comp *comp_array, int comp_size, uint64_t start, uint64_t end) { - size_t count; + uint64_t count; size_t page_size = sysconf(_SC_PAGESIZE); const size_t buflen = 4 << 20; /* 4M */ void *buf; @@ -2589,6 +2589,7 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, while (count > 0) { uint32_t src; uint64_t mirror_end = 0; + uint64_t bytes_left; ssize_t bytes_read; size_t to_read; size_t to_write; @@ -2598,12 +2599,12 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, return -ENOENT; if (mirror_end == OBD_OBJECT_EOF) { - to_read = count; + bytes_left = count; } else { - to_read = MIN(count, mirror_end - pos); - to_read = (to_read + page_size - 1) & ~(page_size - 1); + bytes_left = MIN(count, mirror_end - pos); + bytes_left = ((bytes_left - 1) | (page_size - 1)) + 1; } - to_read = MIN(buflen, to_read); + to_read = MIN(buflen, bytes_left); bytes_read = llapi_mirror_read(fd, src, buf, to_read, pos); if (bytes_read == 0) { @@ -2616,7 +2617,7 @@ int llapi_mirror_resync_many(int fd, struct llapi_layout *layout, } /* round up to page align to make direct IO happy. */ - to_write = (bytes_read + page_size - 1) & ~(page_size - 1); + to_write = ((bytes_read - 1) | (page_size - 1)) + 1; for (i = 0; i < comp_size; i++) { ssize_t written; diff --git a/lustre/utils/liblustreapi_mirror.c b/lustre/utils/liblustreapi_mirror.c index 4a59b46..c7e5726 100644 --- a/lustre/utils/liblustreapi_mirror.c +++ b/lustre/utils/liblustreapi_mirror.c @@ -252,7 +252,7 @@ ssize_t llapi_mirror_copy_many(int fd, unsigned int src, unsigned int *dst, /* round up to page align to make direct IO happy. * this implies the last segment to write. */ - to_write = (bytes_read + page_size - 1) & ~(page_size - 1); + to_write = ((bytes_read - 1) | (page_size - 1)) + 1; for (i = 0; i < nr; i++) { ssize_t written; -- 1.8.3.1