linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 13/18] xfs_io: rename global buffer variable
Date: Wed, 10 Oct 2018 15:01:17 -0500	[thread overview]
Message-ID: <1539201682-22198-14-git-send-email-sandeen@redhat.com> (raw)
In-Reply-To: <1539201682-22198-1-git-send-email-sandeen@redhat.com>

"buffer" is a pretty poor name for a global variable, and leads to
shadow variable warnings from sparse when other functions (reasonably)
think it's a nice local variable name.

Rename it to io_buffer for less namespace pollution, and rename
buffersize to io_buffersize to go with it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
 io/io.h     |  4 ++--
 io/mmap.c   |  6 +++---
 io/pread.c  | 56 ++++++++++++++++++++++++++++----------------------------
 io/pwrite.c | 28 ++++++++++++++--------------
 4 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/io/io.h b/io/io.h
index 9278ad0..bc1e806 100644
--- a/io/io.h
+++ b/io/io.h
@@ -79,8 +79,8 @@ extern void		printxattr(uint, int, int, const char *, int, int);
 extern unsigned int	recurse_all;
 extern unsigned int	recurse_dir;
 
-extern void		*buffer;
-extern size_t		buffersize;
+extern void		*io_buffer;
+extern size_t		io_buffersize;
 extern int		vectors;
 extern struct iovec	*iov;
 extern int		alloc_buffer(size_t, int, unsigned int);
diff --git a/io/mmap.c b/io/mmap.c
index 44749bb..f9383e5 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -436,7 +436,7 @@ mread_f(
 
 	if (alloc_buffer(pagesize, 0, 0) < 0)
 		return 0;
-	bp = (char *)buffer;
+	bp = (char *)io_buffer;
 
 	dumplen = length % pagesize;
 	if (!dumplen)
@@ -451,7 +451,7 @@ mread_f(
 					dump_buffer(printoffset, dumplen);
 					printoffset += dumplen;
 				}
-				bp = (char *)buffer;
+				bp = (char *)io_buffer;
 				dumplen = pagesize;
 				cnt = 0;
 			} else {
@@ -466,7 +466,7 @@ mread_f(
 				if (dump)
 					dump_buffer(printoffset + tmp -
 						(dumplen - 1), dumplen);
-				bp = (char *)buffer;
+				bp = (char *)io_buffer;
 				dumplen = pagesize;
 				cnt = 0;
 			} else {
diff --git a/io/pread.c b/io/pread.c
index e573377..1b4352b 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -47,9 +47,9 @@ pread_help(void)
 "\n"));
 }
 
-void	*buffer;
+void	*io_buffer;
 size_t	highwater;
-size_t	buffersize;
+size_t	io_buffersize;
 int	vectors;
 struct iovec *iov;
 
@@ -65,7 +65,7 @@ alloc_iovec(
 	if (!iov)
 		return -1;
 
-	buffersize = 0;
+	io_buffersize = 0;
 	for (i = 0; i < vectors; i++) {
 		iov[i].iov_base = memalign(pagesize, bsize);
 		if (!iov[i].iov_base) {
@@ -76,7 +76,7 @@ alloc_iovec(
 		if (!uflag)
 			memset(iov[i].iov_base, seed, bsize);
 	}
-	buffersize = bsize * vectors;
+	io_buffersize = bsize * vectors;
 	return 0;
 unwind:
 	for( ; i >= 0; i--)
@@ -96,19 +96,19 @@ alloc_buffer(
 		return alloc_iovec(bsize, uflag, seed);
 
 	if (bsize > highwater) {
-		if (buffer)
-			free(buffer);
-		buffer = memalign(pagesize, bsize);
-		if (!buffer) {
+		if (io_buffer)
+			free(io_buffer);
+		io_buffer = memalign(pagesize, bsize);
+		if (!io_buffer) {
 			perror("memalign");
-			highwater = buffersize = 0;
+			highwater = io_buffersize = 0;
 			return -1;
 		}
 		highwater = bsize;
 	}
-	buffersize = bsize;
+	io_buffersize = bsize;
 	if (!uflag)
-		memset(buffer, seed, buffersize);
+		memset(io_buffer, seed, io_buffersize);
 	return 0;
 }
 
@@ -146,7 +146,7 @@ dump_buffer(
 	int		i, l;
 
 	if (!vectors) {
-		__dump_buffer(buffer, offset, len);
+		__dump_buffer(io_buffer, offset, len);
 		return;
 	}
 
@@ -171,7 +171,7 @@ do_preadv(
 	ssize_t		bytes = 0;
 
 	/* trim the iovec if necessary */
-	if (count < buffersize) {
+	if (count < io_buffersize) {
 		size_t	len = 0;
 		while (len + iov[vecs].iov_len < count) {
 			len += iov[vecs].iov_len;
@@ -203,7 +203,7 @@ do_pread(
 	size_t		buffer_size)
 {
 	if (!vectors)
-		return pread(fd, buffer, min(count, buffer_size), offset);
+		return pread(fd, io_buffer, min(count, buffer_size), offset);
 
 	return do_preadv(fd, offset, count);
 }
@@ -224,22 +224,22 @@ read_random(
 	srandom(seed);
 	end = lseek(fd, 0, SEEK_END);
 	offset = (eof || offset > end) ? end : offset;
-	if ((bytes = (offset % buffersize)))
+	if ((bytes = (offset % io_buffersize)))
 		offset -= bytes;
 	offset = max(0, offset);
-	if ((bytes = (count % buffersize)))
+	if ((bytes = (count % io_buffersize)))
 		count += bytes;
-	count = max(buffersize, count);
-	range = count - buffersize;
+	count = max(io_buffersize, count);
+	range = count - io_buffersize;
 
 	*total = 0;
 	while (count > 0) {
 		if (range)
-			off = ((offset + (random() % range)) / buffersize) *
-				buffersize;
+			off = ((offset + (random() % range)) / io_buffersize) *
+				io_buffersize;
 		else
 			off = offset;
-		bytes = do_pread(fd, off, buffersize, buffersize);
+		bytes = do_pread(fd, off, io_buffersize, io_buffersize);
 		if (bytes == 0)
 			break;
 		if (bytes < 0) {
@@ -248,7 +248,7 @@ read_random(
 		}
 		ops++;
 		*total += bytes;
-		if (bytes < buffersize)
+		if (bytes < io_buffersize)
 			break;
 		count -= bytes;
 	}
@@ -279,9 +279,9 @@ read_backward(
 	*offset = off;
 
 	/* Do initial unaligned read if needed */
-	if ((bytes_requested = (off % buffersize))) {
+	if ((bytes_requested = (off % io_buffersize))) {
 		off -= bytes_requested;
-		bytes = do_pread(fd, off, bytes_requested, buffersize);
+		bytes = do_pread(fd, off, bytes_requested, io_buffersize);
 		if (bytes == 0)
 			return ops;
 		if (bytes < 0) {
@@ -297,9 +297,9 @@ read_backward(
 
 	/* Iterate backward through the rest of the range */
 	while (cnt > end) {
-		bytes_requested = min(cnt, buffersize);
+		bytes_requested = min(cnt, io_buffersize);
 		off -= bytes_requested;
-		bytes = do_pread(fd, off, cnt, buffersize);
+		bytes = do_pread(fd, off, cnt, io_buffersize);
 		if (bytes == 0)
 			break;
 		if (bytes < 0) {
@@ -330,7 +330,7 @@ read_forward(
 
 	*total = 0;
 	while (count > 0 || eof) {
-		bytes = do_pread(fd, offset, count, buffersize);
+		bytes = do_pread(fd, offset, count, io_buffersize);
 		if (bytes == 0)
 			break;
 		if (bytes < 0) {
@@ -341,7 +341,7 @@ read_forward(
 		if (verbose)
 			dump_buffer(offset, bytes);
 		*total += bytes;
-		if (onlyone || bytes < min(count, buffersize))
+		if (onlyone || bytes < min(count, io_buffersize))
 			break;
 		offset += bytes;
 		count -= bytes;
diff --git a/io/pwrite.c b/io/pwrite.c
index 34235ca..ccf14be 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -62,7 +62,7 @@ do_pwritev(
 	ssize_t bytes = 0;
 
 	/* trim the iovec if necessary */
-	if (count < buffersize) {
+	if (count < io_buffersize) {
 		size_t	len = 0;
 		while (len + iov[vecs].iov_len < count) {
 			len += iov[vecs].iov_len;
@@ -102,7 +102,7 @@ do_pwrite(
 	int		pwritev2_flags)
 {
 	if (!vectors)
-		return pwrite(fd, buffer, min(count, buffer_size), offset);
+		return pwrite(fd, io_buffer, min(count, buffer_size), offset);
 
 	return do_pwritev(fd, offset, count, pwritev2_flags);
 }
@@ -120,22 +120,22 @@ write_random(
 	int		ops = 0;
 
 	srandom(seed);
-	if ((bytes = (offset % buffersize)))
+	if ((bytes = (offset % io_buffersize)))
 		offset -= bytes;
 	offset = max(0, offset);
-	if ((bytes = (count % buffersize)))
+	if ((bytes = (count % io_buffersize)))
 		count += bytes;
-	count = max(buffersize, count);
-	range = count - buffersize;
+	count = max(io_buffersize, count);
+	range = count - io_buffersize;
 
 	*total = 0;
 	while (count > 0) {
 		if (range)
-			off = ((offset + (random() % range)) / buffersize) *
-				buffersize;
+			off = ((offset + (random() % range)) / io_buffersize) *
+				io_buffersize;
 		else
 			off = offset;
-		bytes = do_pwrite(file->fd, off, buffersize, buffersize,
+		bytes = do_pwrite(file->fd, off, io_buffersize, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			break;
@@ -145,7 +145,7 @@ write_random(
 		}
 		ops++;
 		*total += bytes;
-		if (bytes < buffersize)
+		if (bytes < io_buffersize)
 			break;
 		count -= bytes;
 	}
@@ -172,10 +172,10 @@ write_backward(
 	*count = cnt;
 
 	/* Do initial unaligned write if needed */
-	if ((bytes_requested = (off % buffersize))) {
+	if ((bytes_requested = (off % io_buffersize))) {
 		bytes_requested = min(cnt, bytes_requested);
 		off -= bytes_requested;
-		bytes = do_pwrite(file->fd, off, bytes_requested, buffersize,
+		bytes = do_pwrite(file->fd, off, bytes_requested, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			return ops;
@@ -192,9 +192,9 @@ write_backward(
 
 	/* Iterate backward through the rest of the range */
 	while (cnt > end) {
-		bytes_requested = min(cnt, buffersize);
+		bytes_requested = min(cnt, io_buffersize);
 		off -= bytes_requested;
-		bytes = do_pwrite(file->fd, off, cnt, buffersize,
+		bytes = do_pwrite(file->fd, off, cnt, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			break;
-- 
1.8.3.1

  parent reply	other threads:[~2018-10-11  3:25 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 20:01 [PATCH 00/18] xfsprogs: finer-grained sparse fixes Eric Sandeen
2018-10-10 20:01 ` [PATCH 01/18] xfsprogs: enable sparse checking with "make C=[12]" Eric Sandeen
2018-10-10 21:24   ` Darrick J. Wong
2018-10-10 22:18   ` [PATCH 01/18 V2] " Eric Sandeen
2018-10-11  5:57     ` Christoph Hellwig
2018-10-11 14:09       ` Eric Sandeen
2018-10-10 20:01 ` [PATCH 02/18] xfs_db: convert single-bit bitfields to bools Eric Sandeen
2018-10-11  5:58   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 03/18] xfsprogs: minor endian annotation fixes Eric Sandeen
2018-10-11  5:59   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 04/18] xfsprogs: avoid redefinition of NBBY Eric Sandeen
2018-10-11  5:59   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 05/18] xfsprogs: include headers for extern variables Eric Sandeen
2018-10-11  5:59   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 06/18] libxfs: add several zone extern declarations to libxfs_priv.h Eric Sandeen
2018-10-11  5:59   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 07/18] libxfs: silence static warnings about platform_* functions Eric Sandeen
2018-10-11  6:00   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 08/18] xfs_io: include io.h to silence static function warnings Eric Sandeen
2018-10-11  6:00   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 09/18] libxfs: silence sparse static function warnings in util.c Eric Sandeen
2018-10-11  6:00   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 10/18] avl64: export avl64_firstino / avl64_firstino from avl64.h Eric Sandeen
2018-10-11  6:01   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 11/18] xfsprogs: misc static function warning fixes Eric Sandeen
2018-10-11  6:01   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 12/18] xfsprogs: don't shadow global libxfs_init x variable Eric Sandeen
2018-10-11  6:02   ` Christoph Hellwig
2018-10-10 20:01 ` Eric Sandeen [this message]
2018-10-11  6:02   ` [PATCH 13/18] xfs_io: rename global buffer variable Christoph Hellwig
2018-10-10 20:01 ` [PATCH 14/18] xfs_logprint: fix shadow var in xlog_print_trans_buffer Eric Sandeen
2018-10-11  6:03   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 15/18] xfs_repair: fix 'bno' shadow vars in scan.c Eric Sandeen
2018-10-11  6:03   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 16/18] xfs_scrub: remove shadow var from run_scrub_phases() Eric Sandeen
2018-10-11  6:03   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 17/18] xfs_metadump: remove shadow variable Eric Sandeen
2018-10-10 21:34   ` Darrick J. Wong
2018-10-11  6:04   ` Christoph Hellwig
2018-10-10 20:01 ` [PATCH 18/18] libfrog: change project entity variable scope to local/static Eric Sandeen
2018-10-10 21:37 ` [PATCH 00/18] xfsprogs: finer-grained sparse fixes Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1539201682-22198-14-git-send-email-sandeen@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).