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
1=== modified file 'sysbench/tests/fileio/sb_fileio.c'
2--- sysbench/tests/fileio/sb_fileio.c 2010-11-01 08:35:41 +0000
3+++ sysbench/tests/fileio/sb_fileio.c 2010-11-06 01:08:49 +0000
4@@ -153,7 +153,6 @@
5 static unsigned int current_file; /* current file */
6 static unsigned int fsynced_file; /* file number to be fsynced (periodic) */
7 static unsigned int fsynced_file2; /* fsyncing in the end */
8-static pthread_mutex_t fsync_mutex; /* used to sync access to counters */
9
10 static int is_dirty; /* any writes after last fsync series ? */
11 static int read_ops;
12@@ -355,8 +354,6 @@
13 return 1;
14 #endif
15
16- pthread_mutex_init(&fsync_mutex, NULL);
17-
18 return 0;
19 }
20
21@@ -385,8 +382,6 @@
22 if (buffer != NULL)
23 sb_free_memaligned(buffer);
24
25- pthread_mutex_destroy(&fsync_mutex);
26-
27 return 0;
28 }
29
30@@ -412,6 +407,7 @@
31 sb_file_request_t *file_req = &sb_req.u.file_request;
32
33 sb_req.type = SB_REQ_TYPE_FILE;
34+ SB_THREAD_MUTEX_LOCK();
35
36 /* assume function is called with correct mode always */
37 if (test_mode == MODE_WRITE || test_mode == MODE_REWRITE)
38@@ -435,7 +431,6 @@
39 }
40
41 /* Advance pointers, if we're not in the fsync phase */
42- pthread_mutex_lock(&fsync_mutex);
43 if(current_file != num_files)
44 position += file_req->size;
45 /* scroll to the next file if not already out of bound */
46@@ -444,14 +439,13 @@
47 current_file++;
48 position=0;
49
50- pthread_mutex_unlock(&fsync_mutex);
51-
52 if (sb_globals.validate)
53 {
54 check_seq_req(&prev_req, file_req);
55 prev_req = *file_req;
56 }
57
58+ SB_THREAD_MUTEX_UNLOCK();
59 return sb_req; /* This request is valid even for last file */
60 }
61
62@@ -471,7 +465,7 @@
63 else
64 sb_req.type = SB_REQ_TYPE_NULL;
65 }
66- pthread_mutex_unlock(&fsync_mutex);
67+ SB_THREAD_MUTEX_UNLOCK();
68
69 if (sb_globals.validate)
70 {
71@@ -496,6 +490,7 @@
72 int mode = test_mode;
73
74 sb_req.type = SB_REQ_TYPE_FILE;
75+ SB_THREAD_MUTEX_LOCK();
76
77 /*
78 Convert mode for combined tests. Locking to get consistent values
79@@ -503,12 +498,10 @@
80 */
81 if (test_mode==MODE_RND_RW)
82 {
83- SB_THREAD_MUTEX_LOCK();
84 if ((double)(real_read_ops + 1) / (real_write_ops + 1) < file_rw_ratio)
85 mode=MODE_RND_READ;
86 else
87 mode=MODE_RND_WRITE;
88- SB_THREAD_MUTEX_UNLOCK();
89 }
90
91 /* fsync all files (if requested by user) as soon as we are done */
92@@ -518,7 +511,6 @@
93 (real_mode == MODE_RND_WRITE || real_mode == MODE_RND_RW ||
94 real_mode == MODE_MIXED))
95 {
96- pthread_mutex_lock(&fsync_mutex);
97 if(fsynced_file2 < num_files)
98 {
99 file_req->file_id = fsynced_file2;
100@@ -526,14 +518,14 @@
101 file_req->pos = 0;
102 file_req->size = 0;
103 fsynced_file2++;
104- pthread_mutex_unlock(&fsync_mutex);
105-
106+
107+ SB_THREAD_MUTEX_UNLOCK();
108 return sb_req;
109 }
110- pthread_mutex_unlock(&fsync_mutex);
111 }
112 sb_req.type = SB_REQ_TYPE_NULL;
113
114+ SB_THREAD_MUTEX_UNLOCK();
115 return sb_req;
116 }
117
118@@ -556,6 +548,7 @@
119 is_dirty = 0;
120 }
121
122+ SB_THREAD_MUTEX_UNLOCK();
123 return sb_req;
124 }
125 }
126@@ -576,6 +569,7 @@
127 if (file_req->operation == FILE_OP_TYPE_WRITE)
128 is_dirty = 1;
129
130+ SB_THREAD_MUTEX_UNLOCK();
131 return sb_req;
132 }
133

Subscribers

People subscribed via source and target branches