From d9c82cc530b26b21bc9e390c130a0e41c4ab5a09 Mon Sep 17 00:00:00 2001 From: Teruyoshi Kaneko Date: Thu, 30 May 2024 16:01:17 +0900 Subject: [PATCH] storage-mon: Don't use random seeking when O_DIRECT is enabled --- tools/storage_mon.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/storage_mon.c b/tools/storage_mon.c index f94268f6f..8d6fd0374 100644 --- a/tools/storage_mon.c +++ b/tools/storage_mon.c @@ -121,7 +121,6 @@ static void *test_device(const char *device, int verbose, int inject_error_perce int flags = O_RDONLY | O_DIRECT; int device_fd; int res; - off_t seek_spot; if (verbose) { printf("Testing device %s\n", device); @@ -155,16 +154,6 @@ static void *test_device(const char *device, int verbose, int inject_error_perce /* Don't fret about real randomness */ srand(time(NULL) + getpid()); - /* Pick a random place on the device - sector aligned */ - seek_spot = (rand() % (devsize-1024)) & 0xFFFFFFFFFFFFFE00; - res = lseek(device_fd, seek_spot, SEEK_SET); - if (res < 0) { - PRINT_STORAGE_MON_ERR("Failed to seek %s: %s", device, strerror(errno)); - goto error; - } - if (verbose) { - PRINT_STORAGE_MON_INFO("%s: reading from pos %ld", device, seek_spot); - } if (flags & O_DIRECT) { int sec_size = 0; @@ -195,8 +184,20 @@ static void *test_device(const char *device, int verbose, int inject_error_perce goto error; } } else { + off_t seek_spot; char buffer[512]; + /* Pick a random place on the device - sector aligned */ + seek_spot = (rand() % (devsize-1024)) & 0xFFFFFFFFFFFFFE00; + res = lseek(device_fd, seek_spot, SEEK_SET); + if (res < 0) { + PRINT_STORAGE_MON_ERR("Failed to seek %s: %s", device, strerror(errno)); + goto error; + } + if (verbose) { + PRINT_STORAGE_MON_INFO("%s: reading from pos %ld", device, seek_spot); + } + res = read(device_fd, buffer, sizeof(buffer)); if (res < 0) { PRINT_STORAGE_MON_ERR("Failed to read %s: %s", device, strerror(errno));