Merge lp:~mdcallag/sysbench/0.4-bugfix into lp:sysbench/0.4

Proposed by Mark Callaghan
Status: Merged
Merged at revision: 77
Proposed branch: lp:~mdcallag/sysbench/0.4-bugfix
Merge into: lp:sysbench/0.4
Diff against target: 132 lines (+9/-15)
1 file modified
sysbench/tests/fileio/sb_fileio.c (+9/-15)
To merge this branch: bzr merge lp:~mdcallag/sysbench/0.4-bugfix
Reviewer Review Type Date Requested Status
Mark Callaghan Approve
Review via email: mp+40244@code.launchpad.net

Description of the change

Fix race conditions in fileio tests. Global variables were referenced without a mutex lock. fsync calls could be done for bogus file descriptors

To post a comment you must log in.
Revision history for this message
Mark Callaghan (mdcallag) wrote :

Tests ran without errors

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sysbench/tests/fileio/sb_fileio.c'
--- sysbench/tests/fileio/sb_fileio.c 2010-11-01 08:35:41 +0000
+++ sysbench/tests/fileio/sb_fileio.c 2010-11-06 01:08:49 +0000
@@ -153,7 +153,6 @@
153static unsigned int current_file; /* current file */153static unsigned int current_file; /* current file */
154static unsigned int fsynced_file; /* file number to be fsynced (periodic) */154static unsigned int fsynced_file; /* file number to be fsynced (periodic) */
155static unsigned int fsynced_file2; /* fsyncing in the end */155static unsigned int fsynced_file2; /* fsyncing in the end */
156static pthread_mutex_t fsync_mutex; /* used to sync access to counters */
157156
158static int is_dirty; /* any writes after last fsync series ? */157static int is_dirty; /* any writes after last fsync series ? */
159static int read_ops;158static int read_ops;
@@ -355,8 +354,6 @@
355 return 1;354 return 1;
356#endif355#endif
357356
358 pthread_mutex_init(&fsync_mutex, NULL);
359
360 return 0; 357 return 0;
361}358}
362359
@@ -385,8 +382,6 @@
385 if (buffer != NULL)382 if (buffer != NULL)
386 sb_free_memaligned(buffer);383 sb_free_memaligned(buffer);
387384
388 pthread_mutex_destroy(&fsync_mutex);
389
390 return 0;385 return 0;
391}386}
392387
@@ -412,6 +407,7 @@
412 sb_file_request_t *file_req = &sb_req.u.file_request;407 sb_file_request_t *file_req = &sb_req.u.file_request;
413408
414 sb_req.type = SB_REQ_TYPE_FILE;409 sb_req.type = SB_REQ_TYPE_FILE;
410 SB_THREAD_MUTEX_LOCK();
415 411
416 /* assume function is called with correct mode always */412 /* assume function is called with correct mode always */
417 if (test_mode == MODE_WRITE || test_mode == MODE_REWRITE)413 if (test_mode == MODE_WRITE || test_mode == MODE_REWRITE)
@@ -435,7 +431,6 @@
435 }431 }
436 432
437 /* Advance pointers, if we're not in the fsync phase */ 433 /* Advance pointers, if we're not in the fsync phase */
438 pthread_mutex_lock(&fsync_mutex);
439 if(current_file != num_files)434 if(current_file != num_files)
440 position += file_req->size;435 position += file_req->size;
441 /* scroll to the next file if not already out of bound */436 /* scroll to the next file if not already out of bound */
@@ -444,14 +439,13 @@
444 current_file++;439 current_file++;
445 position=0;440 position=0;
446441
447 pthread_mutex_unlock(&fsync_mutex);
448
449 if (sb_globals.validate)442 if (sb_globals.validate)
450 {443 {
451 check_seq_req(&prev_req, file_req);444 check_seq_req(&prev_req, file_req);
452 prev_req = *file_req;445 prev_req = *file_req;
453 }446 }
454 447
448 SB_THREAD_MUTEX_UNLOCK();
455 return sb_req; /* This request is valid even for last file */449 return sb_req; /* This request is valid even for last file */
456 } 450 }
457 451
@@ -471,7 +465,7 @@
471 else 465 else
472 sb_req.type = SB_REQ_TYPE_NULL;466 sb_req.type = SB_REQ_TYPE_NULL;
473 } 467 }
474 pthread_mutex_unlock(&fsync_mutex);468 SB_THREAD_MUTEX_UNLOCK();
475469
476 if (sb_globals.validate)470 if (sb_globals.validate)
477 {471 {
@@ -496,6 +490,7 @@
496 int mode = test_mode;490 int mode = test_mode;
497 491
498 sb_req.type = SB_REQ_TYPE_FILE;492 sb_req.type = SB_REQ_TYPE_FILE;
493 SB_THREAD_MUTEX_LOCK();
499 494
500 /*495 /*
501 Convert mode for combined tests. Locking to get consistent values496 Convert mode for combined tests. Locking to get consistent values
@@ -503,12 +498,10 @@
503 */498 */
504 if (test_mode==MODE_RND_RW)499 if (test_mode==MODE_RND_RW)
505 {500 {
506 SB_THREAD_MUTEX_LOCK();
507 if ((double)(real_read_ops + 1) / (real_write_ops + 1) < file_rw_ratio)501 if ((double)(real_read_ops + 1) / (real_write_ops + 1) < file_rw_ratio)
508 mode=MODE_RND_READ;502 mode=MODE_RND_READ;
509 else503 else
510 mode=MODE_RND_WRITE;504 mode=MODE_RND_WRITE;
511 SB_THREAD_MUTEX_UNLOCK();
512 }505 }
513506
514 /* fsync all files (if requested by user) as soon as we are done */507 /* fsync all files (if requested by user) as soon as we are done */
@@ -518,7 +511,6 @@
518 (real_mode == MODE_RND_WRITE || real_mode == MODE_RND_RW ||511 (real_mode == MODE_RND_WRITE || real_mode == MODE_RND_RW ||
519 real_mode == MODE_MIXED))512 real_mode == MODE_MIXED))
520 {513 {
521 pthread_mutex_lock(&fsync_mutex);
522 if(fsynced_file2 < num_files)514 if(fsynced_file2 < num_files)
523 {515 {
524 file_req->file_id = fsynced_file2;516 file_req->file_id = fsynced_file2;
@@ -526,14 +518,14 @@
526 file_req->pos = 0;518 file_req->pos = 0;
527 file_req->size = 0;519 file_req->size = 0;
528 fsynced_file2++;520 fsynced_file2++;
529 pthread_mutex_unlock(&fsync_mutex);521
530 522 SB_THREAD_MUTEX_UNLOCK();
531 return sb_req;523 return sb_req;
532 }524 }
533 pthread_mutex_unlock(&fsync_mutex);
534 }525 }
535 sb_req.type = SB_REQ_TYPE_NULL;526 sb_req.type = SB_REQ_TYPE_NULL;
536527
528 SB_THREAD_MUTEX_UNLOCK();
537 return sb_req;529 return sb_req;
538 }530 }
539531
@@ -556,6 +548,7 @@
556 is_dirty = 0;548 is_dirty = 0;
557 }549 }
558 550
551 SB_THREAD_MUTEX_UNLOCK();
559 return sb_req;552 return sb_req;
560 }553 }
561 }554 }
@@ -576,6 +569,7 @@
576 if (file_req->operation == FILE_OP_TYPE_WRITE) 569 if (file_req->operation == FILE_OP_TYPE_WRITE)
577 is_dirty = 1;570 is_dirty = 1;
578571
572 SB_THREAD_MUTEX_UNLOCK();
579 return sb_req;573 return sb_req;
580}574}
581575

Subscribers

People subscribed via source and target branches