Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions tools/storage_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down