From: Andreas Gruenbacher <agruenba@redhat.com>
To: fstests@vger.kernel.org
Cc: Andreas Gruenbacher <agruenba@redhat.com>, Jan Kara <jack@suse.cz>
Subject: [PATCH] seek_sanity_test: Report the actual allocation size
Date: Fri, 23 Jun 2017 02:11:15 +0200 [thread overview]
Message-ID: <1498176676-30021-1-git-send-email-agruenba@redhat.com> (raw)
Instead of reporting the preferred block size for I/O as returned by
stat(2) as the allocation size, report the actual allocation size.
Clean things up a little in the process.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
src/seek_sanity_test.c | 84 ++++++++++++++++++++++++++------------------------
1 file changed, 44 insertions(+), 40 deletions(-)
diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
index 064a8fa..c9e9366 100644
--- a/src/seek_sanity_test.c
+++ b/src/seek_sanity_test.c
@@ -51,19 +51,51 @@ static void get_file_system(int fd)
static int get_io_sizes(int fd)
{
- struct stat buf;
- int ret;
+ off_t pos = 0, offset = 1;
+ struct stat buf;
+ int shift, ret;
- ret = fstat(fd, &buf);
- if (ret)
- fprintf(stderr, " ERROR %d: Failed to find io blocksize\n",
- errno);
+ ret = fstat(fd, &buf);
+ if (ret) {
+ fprintf(stderr, " ERROR %d: Failed to find io blocksize\n",
+ errno);
+ return ret;
+ }
- /* st_blksize is typically also the allocation size */
- alloc_size = buf.st_blksize;
- fprintf(stdout, "Allocation size: %ld\n", alloc_size);
+ /* st_blksize is typically also the allocation size */
+ alloc_size = buf.st_blksize;
- return ret;
+ /* try to discover the actual alloc size */
+ while (pos == 0 && offset < alloc_size) {
+ offset <<= 1;
+ ftruncate(fd, 0);
+ pwrite(fd, "a", 1, offset);
+ pos = lseek(fd, 0, SEEK_DATA);
+ if (pos == -1)
+ goto fail;
+ }
+
+ /* bisect */
+ shift = offset >> 2;
+ while (shift && offset < alloc_size) {
+ ftruncate(fd, 0);
+ pwrite(fd, "a", 1, offset);
+ pos = lseek(fd, 0, SEEK_DATA);
+ if (pos == -1)
+ goto fail;
+ offset += pos ? -shift : shift;
+ shift >>= 1;
+ }
+ if (!shift)
+ offset += pos ? 0 : 1;
+ alloc_size = offset;
+ fprintf(stdout, "Allocation size: %ld\n", alloc_size);
+ return 0;
+
+fail:
+ fprintf(stderr, "Kernel does not support llseek(2) extension "
+ "SEEK_DATA. Aborting.\n");
+ return -1;
}
#define do_free(x) do { if(x) free(x); } while(0);
@@ -902,8 +934,8 @@ static int run_test(struct testrec *tr)
static int test_basic_support(void)
{
- int ret = -1, fd, shift;
- off_t pos = 0, offset = 1;
+ int ret = -1, fd;
+ off_t pos;
char *buf = NULL;
int bufsz, filsz;
@@ -917,34 +949,6 @@ static int test_basic_support(void)
if (ret)
goto out;
- /* try to discover the actual alloc size */
- while (pos == 0 && offset < alloc_size) {
- offset <<= 1;
- ftruncate(fd, 0);
- pwrite(fd, "a", 1, offset);
- pos = lseek(fd, 0, SEEK_DATA);
- }
-
- /* bisect */
- shift = offset >> 2;
- while (shift && offset < alloc_size) {
- ftruncate(fd, 0);
- pwrite(fd, "a", 1, offset);
- pos = lseek(fd, 0, SEEK_DATA);
- offset += pos ? -shift : shift;
- shift >>= 1;
- }
- if (!shift)
- offset += pos ? 0 : 1;
- alloc_size = offset;
-
- if (pos == -1) {
- fprintf(stderr, "Kernel does not support llseek(2) extension "
- "SEEK_DATA. Aborting.\n");
- ret = -1;
- goto out;
- }
-
ftruncate(fd, 0);
bufsz = alloc_size * 2;
filsz = bufsz * 2;
--
2.7.5
next reply other threads:[~2017-06-23 0:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-23 0:11 Andreas Gruenbacher [this message]
2017-06-23 0:11 ` [PATCH] generic/441: Another SEEK_HOLE/SEEK_DATA sanity test Andreas Gruenbacher
2017-06-23 8:40 ` Eryu Guan
2017-06-23 10:28 ` Andreas Gruenbacher
2017-06-26 7:24 ` Eryu Guan
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=1498176676-30021-1-git-send-email-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=fstests@vger.kernel.org \
--cc=jack@suse.cz \
/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