examples/iscsi-dd: check for clock_gettime() errors

Only dump performance details if we have valid start and end times.

Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
David Disseldorp
2020-02-24 13:32:59 +01:00
parent 829c6351ed
commit 8ae813bae9

View File

@@ -571,7 +571,7 @@ int main(int argc, char *argv[])
struct client client; struct client client;
struct timespec start_time; struct timespec start_time;
struct timespec end_time; struct timespec end_time;
int gettime_ret;
static struct option long_options[] = { static struct option long_options[] = {
{"dst", required_argument, NULL, 'd'}, {"dst", required_argument, NULL, 'd'},
{"src", required_argument, NULL, 's'}, {"src", required_argument, NULL, 's'},
@@ -725,7 +725,10 @@ int main(int argc, char *argv[])
exit(10); exit(10);
} }
clock_gettime(CLOCK_MONOTONIC, &start_time); gettime_ret = clock_gettime(CLOCK_MONOTONIC, &start_time);
if (gettime_ret < 0) {
fprintf(stderr, "clock_gettime(CLOCK_MONOTONIC) failed\n");
}
if (client.use_xcopy) { if (client.use_xcopy) {
fill_xcopy_queue(&client); fill_xcopy_queue(&client);
@@ -758,8 +761,14 @@ int main(int argc, char *argv[])
} }
} }
clock_gettime(CLOCK_MONOTONIC, &end_time); if (gettime_ret == 0) {
show_perf(&start_time, &end_time, client.pos, client.src_blocksize); /* start_time is valid, so dump perf with a valid end_time */
gettime_ret = clock_gettime(CLOCK_MONOTONIC, &end_time);
if (gettime_ret == 0) {
show_perf(&start_time, &end_time, client.pos,
client.src_blocksize);
}
}
iscsi_logout_sync(client.src_iscsi); iscsi_logout_sync(client.src_iscsi);
iscsi_destroy_context(client.src_iscsi); iscsi_destroy_context(client.src_iscsi);