Skip to contentSkip to conversation

src: fix compiler warnings

PATCH In review Theodore Ts'o 2 participants 3 messages May 1, 2017 – May 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: fix compiler warnings

Most of the fixes are printf format type warnings, but apparently GCC 6 is smart enough to realize is that if you don't do proper error checking with posix_memalign, the resulting pointer can be undefined, and whines about it. So while fixing this in aio-dio-fcntl-race, I also cleaned up the error checking and reporting.

---
 src/aio-dio-regress/aio-dio-eof-race.c   |  3 ++-
 src/aio-dio-regress/aio-dio-fcntl-race.c | 32 +++++++++++++++++++++++---------
 src/dio-invalidate-cache.c               |  6 ++++--
 src/holetest.c                           |  8 ++++----
 src/t_rename_overwrite.c                 |  3 ++-
 5 files changed, 35 insertions(+), 17 deletions(-)
src/aio-dio-regress/aio-dio-eof-race.c +2 -1
index bd71b030..67c0b2de 100644
@@ -202,7 +202,8 @@ int main(int argc, char *argv[])
 		 * a seamless buf_size worth of IO_PATTERN to the last block.
 		 */
 		if (memcmp(buf, cmp_buf, buf_size)) {
-			printf("corruption while extending from %ld\n", eof);
+			printf("corruption while extending from %lld\n",
+			       (unsigned long long) eof);
 			dump_buffer(buf, 0, buf_size);
 			return 1;
 		}
src/aio-dio-regress/aio-dio-fcntl-race.c +23 -9
index cdf97736..88a27472 100644
@@ -92,12 +92,16 @@ int main(int argc, char **argv)
 		return 1;
 	}
 	fd = open(argv[1], O_CREAT | O_TRUNC | O_RDWR, 0600);
-	if (fd < 0)
+	if (fd < 0) {
+		perror("open");
 		return 1;
+	}
 
 	pid1 = fork();
-	if (pid1 < 0)
+	if (pid1 < 0) {
+		perror("fork");
 		return 1;
+	}
 
 	if (pid1 == 0) {
 		struct timeval start, now, delta = { 0, 0 };
@@ -108,12 +112,15 @@ int main(int argc, char **argv)
 		flags = fcntl(fd, F_GETFL);
 		while (1) {
 			ret = fcntl(fd, F_SETFL, flags | O_DIRECT);
-			if (ret)
-				return ret;
+			if (ret) {
+				perror("fcntl O_DIRECT");
+				return 1;
+			}
 			ret = fcntl(fd, F_SETFL, flags);
-			if (ret)
-				return ret;
-
+			if (ret) {
+				perror("fcntl");
+				return 1;
+			}
 			gettimeofday(&now, NULL);
 			timersub(&now, &start, &delta);
 			if (delta.tv_sec >= LOOP_SECONDS)
@@ -121,8 +128,15 @@ int main(int argc, char **argv)
 		}
 	} else {
 		/* parent: AIO */
-		void *buf;
-		posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		void *buf = NULL;
+		int err;
+
+		err = posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		if (err || buf == NULL) {
+			fprintf(stderr, "posix_memalign failed: %s\n",
+				strerror(err));
+			exit(1);
+		}
 		/* Two tasks which performs unaligned aio will be serialized
 		   which maks race window wider */
 		pid2 = fork();
src/dio-invalidate-cache.c +4 -2
index 4c40c87d..004588ab 100644
@@ -160,7 +160,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 	/* seek, write, read and verify */
 	for (i = 0; i < nr_iter; i++) {
 		memset(buf_wr, i + 1, blksz);
-		log("pwrite(fd_wr, %p, %d, %lu)\n", buf_wr, blksz, seekoff);
+		log("pwrite(fd_wr, %p, %d, %llu)\n", buf_wr, blksz,
+		    (unsigned long long) seekoff);
 		if (pwrite(fd_wr, buf_wr, blksz, seekoff) != blksz) {
 			perror("direct write");
 			exit(EXIT_FAILURE);
@@ -174,7 +175,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 			}
 		}
 
-		log("pread(fd_rd, %p, %d, %lu)\n", buf_rd, blksz, seekoff);
+		log("pread(fd_rd, %p, %d, %llu)\n", buf_rd, blksz,
+		    (unsigned long long) seekoff);
 		if (pread(fd_rd, buf_rd, blksz, seekoff) != blksz) {
 			perror("buffer read");
 			exit(EXIT_FAILURE);
src/holetest.c +4 -4
index edd85fe7..1939b35f 100644
@@ -101,10 +101,10 @@ int verify_mapping(char *vastart, long npages, uint64_t *expect)
 		for (i = 0; i < THREADS; i++) {
 			if (*(uint64_t*)(va + page_offs[i]) != expect[i]) {
 				printf("ERROR: thread %d, "
-				       "offset %08lx, %08lx != %08lx\n", i,
-				       (va + page_offs[i] - vastart),
-				       *(uint64_t*)(va + page_offs[i]),
-				       expect[i]);
+				       "offset %08llx, %08llx != %08llx\n", i,
+				       (unsigned long long) (va + page_offs[i] - vastart),
+				       (unsigned long long) *(uint64_t*)(va + page_offs[i]),
+				       (unsigned long long) expect[i]);
 				errcnt++;
 			}
 		}
src/t_rename_overwrite.c +2 -1
index fe17f9d5..c5cdd1db 100644
@@ -31,7 +31,8 @@ int main(int argc, char *argv[])
 		err(1, "fstat(%i)", fd);
 
 	if (stbuf.st_nlink != 0) {
-		fprintf(stderr, "nlink is %lu, should be 0\n", stbuf.st_nlink);
+		fprintf(stderr, "nlink is %lu, should be 0\n",
+			(unsigned long) stbuf.st_nlink);
 		return 1;
 	}
 
Signature · 1 line
2.11.0.rc0.7.gbe5a750
#1 lore raw
Quoted 20 lines · Theodore Ts'o

Most of the fixes are printf format type warnings, but apparently GCC 6 is smart enough to realize is that if you don't do proper error checking with posix_memalign, the resulting pointer can be undefined, and whines about it. So while fixing this in aio-dio-fcntl-race, I also cleaned up the error checking and reporting.

---
 src/aio-dio-regress/aio-dio-eof-race.c   |  3 ++-
 src/aio-dio-regress/aio-dio-fcntl-race.c | 32 +++++++++++++++++++++++---------
 src/dio-invalidate-cache.c               |  6 ++++--
 src/holetest.c                           |  8 ++++----
 src/t_rename_overwrite.c                 |  3 ++-
 5 files changed, 35 insertions(+), 17 deletions(-)
src/aio-dio-regress/aio-dio-eof-race.c +0 -0
index bd71b030..67c0b2de 100644

src/aio-dio-regress/aio-dio-eof-race.c int main(int argc, char *argv[]) · line 206

Quoted 6 lines
src/aio-dio-regress/aio-dio-eof-race.c +2 -1
@@ -202,7 +202,8 @@ int main(int argc, char *argv[])
 		 * a seamless buf_size worth of IO_PATTERN to the last block.
 		 */
 		if (memcmp(buf, cmp_buf, buf_size)) {
-			printf("corruption while extending from %ld\n", eof);
+			printf("corruption while extending from %lld\n",
+			       (unsigned long long) eof);

The format is %lld, cast eof to (long long)? off_t seems to be a signed value.

Quoted 70 lines
src/aio-dio-regress/aio-dio-eof-race.c +0 -0
 			dump_buffer(buf, 0, buf_size);
 			return 1;
 		}
src/aio-dio-regress/aio-dio-fcntl-race.c +23 -9
index cdf97736..88a27472 100644
@@ -92,12 +92,16 @@ int main(int argc, char **argv)
 		return 1;
 	}
 	fd = open(argv[1], O_CREAT | O_TRUNC | O_RDWR, 0600);
-	if (fd < 0)
+	if (fd < 0) {
+		perror("open");
 		return 1;
+	}
 
 	pid1 = fork();
-	if (pid1 < 0)
+	if (pid1 < 0) {
+		perror("fork");
 		return 1;
+	}
 
 	if (pid1 == 0) {
 		struct timeval start, now, delta = { 0, 0 };
@@ -108,12 +112,15 @@ int main(int argc, char **argv)
 		flags = fcntl(fd, F_GETFL);
 		while (1) {
 			ret = fcntl(fd, F_SETFL, flags | O_DIRECT);
-			if (ret)
-				return ret;
+			if (ret) {
+				perror("fcntl O_DIRECT");
+				return 1;
+			}
 			ret = fcntl(fd, F_SETFL, flags);
-			if (ret)
-				return ret;
-
+			if (ret) {
+				perror("fcntl");
+				return 1;
+			}
 			gettimeofday(&now, NULL);
 			timersub(&now, &start, &delta);
 			if (delta.tv_sec >= LOOP_SECONDS)
@@ -121,8 +128,15 @@ int main(int argc, char **argv)
 		}
 	} else {
 		/* parent: AIO */
-		void *buf;
-		posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		void *buf = NULL;
+		int err;
+
+		err = posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		if (err || buf == NULL) {
+			fprintf(stderr, "posix_memalign failed: %s\n",
+				strerror(err));
+			exit(1);
+		}
 		/* Two tasks which performs unaligned aio will be serialized
 		   which maks race window wider */
 		pid2 = fork();
src/dio-invalidate-cache.c +0 -0
index 4c40c87d..004588ab 100644

src/dio-invalidate-cache.c static int run_test(const char *filename, int n_child, int blksz, off_t offset, · line 164

Quoted 6 lines
src/dio-invalidate-cache.c +2 -1
@@ -160,7 +160,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 	/* seek, write, read and verify */
 	for (i = 0; i < nr_iter; i++) {
 		memset(buf_wr, i + 1, blksz);
-		log("pwrite(fd_wr, %p, %d, %lu)\n", buf_wr, blksz, seekoff);
+		log("pwrite(fd_wr, %p, %d, %llu)\n", buf_wr, blksz,
+		    (unsigned long long) seekoff);

Same here, change format to %lld and cast seekoff to (long long)?

src/dio-invalidate-cache.c static int run_test(const char *filename, int n_child, int blksz, off_t offset, · line 179

Quoted 10 lines
src/dio-invalidate-cache.c +2 -1
 		if (pwrite(fd_wr, buf_wr, blksz, seekoff) != blksz) {
 			perror("direct write");
 			exit(EXIT_FAILURE);
@@ -174,7 +175,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 			}
 		}
 
-		log("pread(fd_rd, %p, %d, %lu)\n", buf_rd, blksz, seekoff);
+		log("pread(fd_rd, %p, %d, %llu)\n", buf_rd, blksz,
+		    (unsigned long long) seekoff);

Same here.

Thanks,
Eryu

Quoted 43 lines
src/dio-invalidate-cache.c +0 -0
 		if (pread(fd_rd, buf_rd, blksz, seekoff) != blksz) {
 			perror("buffer read");
 			exit(EXIT_FAILURE);
src/holetest.c +4 -4
index edd85fe7..1939b35f 100644
@@ -101,10 +101,10 @@ int verify_mapping(char *vastart, long npages, uint64_t *expect)
 		for (i = 0; i < THREADS; i++) {
 			if (*(uint64_t*)(va + page_offs[i]) != expect[i]) {
 				printf("ERROR: thread %d, "
-				       "offset %08lx, %08lx != %08lx\n", i,
-				       (va + page_offs[i] - vastart),
-				       *(uint64_t*)(va + page_offs[i]),
-				       expect[i]);
+				       "offset %08llx, %08llx != %08llx\n", i,
+				       (unsigned long long) (va + page_offs[i] - vastart),
+				       (unsigned long long) *(uint64_t*)(va + page_offs[i]),
+				       (unsigned long long) expect[i]);
 				errcnt++;
 			}
 		}
src/t_rename_overwrite.c +2 -1
index fe17f9d5..c5cdd1db 100644
@@ -31,7 +31,8 @@ int main(int argc, char *argv[])
 		err(1, "fstat(%i)", fd);
 
 	if (stbuf.st_nlink != 0) {
-		fprintf(stderr, "nlink is %lu, should be 0\n", stbuf.st_nlink);
+		fprintf(stderr, "nlink is %lu, should be 0\n",
+			(unsigned long) stbuf.st_nlink);
 		return 1;
 	}
 
Signature · 6 lines
2.11.0.rc0.7.gbe5a750

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 1/1 src: fix compiler warnings

Most of the fixes are printf format type warnings, but apparently GCC 6 is smart enough to realize is that if you don't do proper error checking with posix_memalign, the resulting pointer can be undefined, and whines about it. So while fixing this in aio-dio-fcntl-race, I also cleaned up the error checking and reporting.

---
 src/aio-dio-regress/aio-dio-eof-race.c   |  3 ++-
 src/aio-dio-regress/aio-dio-fcntl-race.c | 32 +++++++++++++++++++++++---------
 src/dio-invalidate-cache.c               |  6 ++++--
 src/holetest.c                           |  8 ++++----
 src/t_rename_overwrite.c                 |  3 ++-
 5 files changed, 35 insertions(+), 17 deletions(-)
src/aio-dio-regress/aio-dio-eof-race.c +2 -1
index bd71b030..bb1890b5 100644
@@ -202,7 +202,8 @@ int main(int argc, char *argv[])
 		 * a seamless buf_size worth of IO_PATTERN to the last block.
 		 */
 		if (memcmp(buf, cmp_buf, buf_size)) {
-			printf("corruption while extending from %ld\n", eof);
+			printf("corruption while extending from %lld\n",
+			       (long long) eof);
 			dump_buffer(buf, 0, buf_size);
 			return 1;
 		}
src/aio-dio-regress/aio-dio-fcntl-race.c +23 -9
index cdf97736..88a27472 100644
@@ -92,12 +92,16 @@ int main(int argc, char **argv)
 		return 1;
 	}
 	fd = open(argv[1], O_CREAT | O_TRUNC | O_RDWR, 0600);
-	if (fd < 0)
+	if (fd < 0) {
+		perror("open");
 		return 1;
+	}
 
 	pid1 = fork();
-	if (pid1 < 0)
+	if (pid1 < 0) {
+		perror("fork");
 		return 1;
+	}
 
 	if (pid1 == 0) {
 		struct timeval start, now, delta = { 0, 0 };
@@ -108,12 +112,15 @@ int main(int argc, char **argv)
 		flags = fcntl(fd, F_GETFL);
 		while (1) {
 			ret = fcntl(fd, F_SETFL, flags | O_DIRECT);
-			if (ret)
-				return ret;
+			if (ret) {
+				perror("fcntl O_DIRECT");
+				return 1;
+			}
 			ret = fcntl(fd, F_SETFL, flags);
-			if (ret)
-				return ret;
-
+			if (ret) {
+				perror("fcntl");
+				return 1;
+			}
 			gettimeofday(&now, NULL);
 			timersub(&now, &start, &delta);
 			if (delta.tv_sec >= LOOP_SECONDS)
@@ -121,8 +128,15 @@ int main(int argc, char **argv)
 		}
 	} else {
 		/* parent: AIO */
-		void *buf;
-		posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		void *buf = NULL;
+		int err;
+
+		err = posix_memalign(&buf, BUF_SIZE, BUF_SIZE);
+		if (err || buf == NULL) {
+			fprintf(stderr, "posix_memalign failed: %s\n",
+				strerror(err));
+			exit(1);
+		}
 		/* Two tasks which performs unaligned aio will be serialized
 		   which maks race window wider */
 		pid2 = fork();
src/dio-invalidate-cache.c +4 -2
index 4c40c87d..0f87d668 100644
@@ -160,7 +160,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 	/* seek, write, read and verify */
 	for (i = 0; i < nr_iter; i++) {
 		memset(buf_wr, i + 1, blksz);
-		log("pwrite(fd_wr, %p, %d, %lu)\n", buf_wr, blksz, seekoff);
+		log("pwrite(fd_wr, %p, %d, %lld)\n", buf_wr, blksz,
+		    (long long) seekoff);
 		if (pwrite(fd_wr, buf_wr, blksz, seekoff) != blksz) {
 			perror("direct write");
 			exit(EXIT_FAILURE);
@@ -174,7 +175,8 @@ static int run_test(const char *filename, int n_child, int blksz, off_t offset,
 			}
 		}
 
-		log("pread(fd_rd, %p, %d, %lu)\n", buf_rd, blksz, seekoff);
+		log("pread(fd_rd, %p, %d, %lld)\n", buf_rd, blksz,
+		    (long long) seekoff);
 		if (pread(fd_rd, buf_rd, blksz, seekoff) != blksz) {
 			perror("buffer read");
 			exit(EXIT_FAILURE);
src/holetest.c +4 -4
index edd85fe7..1939b35f 100644
@@ -101,10 +101,10 @@ int verify_mapping(char *vastart, long npages, uint64_t *expect)
 		for (i = 0; i < THREADS; i++) {
 			if (*(uint64_t*)(va + page_offs[i]) != expect[i]) {
 				printf("ERROR: thread %d, "
-				       "offset %08lx, %08lx != %08lx\n", i,
-				       (va + page_offs[i] - vastart),
-				       *(uint64_t*)(va + page_offs[i]),
-				       expect[i]);
+				       "offset %08llx, %08llx != %08llx\n", i,
+				       (unsigned long long) (va + page_offs[i] - vastart),
+				       (unsigned long long) *(uint64_t*)(va + page_offs[i]),
+				       (unsigned long long) expect[i]);
 				errcnt++;
 			}
 		}
src/t_rename_overwrite.c +2 -1
index fe17f9d5..c5cdd1db 100644
@@ -31,7 +31,8 @@ int main(int argc, char *argv[])
 		err(1, "fstat(%i)", fd);
 
 	if (stbuf.st_nlink != 0) {
-		fprintf(stderr, "nlink is %lu, should be 0\n", stbuf.st_nlink);
+		fprintf(stderr, "nlink is %lu, should be 0\n",
+			(unsigned long) stbuf.st_nlink);
 		return 1;
 	}
 
Signature · 1 line
2.11.0.rc0.7.gbe5a750