Mark Callaghan has proposed merging lp:~mdcallag/sysbench/0.4-bugfix into 
lp:sysbench/0.4.

Requested reviews:
  sysbench-developers (sysbench-developers)


Fix race conditions in fileio tests. Global variables were referenced without a 
mutex lock. fsync calls could be done for bogus file descriptors
-- 
https://code.launchpad.net/~mdcallag/sysbench/0.4-bugfix/+merge/40244
Your team sysbench-developers is requested to review the proposed merge of 
lp:~mdcallag/sysbench/0.4-bugfix into lp:sysbench/0.4.
=== 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 @@
 static unsigned int    current_file;  /* current file */
 static unsigned int    fsynced_file;  /* file number to be fsynced (periodic) */
 static unsigned int    fsynced_file2; /* fsyncing in the end */
-static pthread_mutex_t fsync_mutex;   /* used to sync access to counters */
 
 static int is_dirty;               /* any writes after last fsync series ? */
 static int read_ops;
@@ -355,8 +354,6 @@
     return 1;
 #endif
 
-  pthread_mutex_init(&fsync_mutex, NULL);
-  
   return 0; 
 }
 
@@ -385,8 +382,6 @@
   if (buffer != NULL)
     sb_free_memaligned(buffer);
 
-  pthread_mutex_destroy(&fsync_mutex);
-  
   return 0;
 }
 
@@ -412,6 +407,7 @@
   sb_file_request_t    *file_req = &sb_req.u.file_request;
 
   sb_req.type = SB_REQ_TYPE_FILE;
+  SB_THREAD_MUTEX_LOCK();
   
   /* assume function is called with correct mode always */
   if (test_mode == MODE_WRITE || test_mode == MODE_REWRITE)
@@ -435,7 +431,6 @@
   }
   
   /* Advance pointers, if we're not in the fsync phase */ 
-  pthread_mutex_lock(&fsync_mutex);
   if(current_file != num_files)
     position += file_req->size;
   /* scroll to the next file if not already out of bound */
@@ -444,14 +439,13 @@
     current_file++;
     position=0;
 
-    pthread_mutex_unlock(&fsync_mutex);
-    
     if (sb_globals.validate)
     {
       check_seq_req(&prev_req, file_req);
       prev_req = *file_req;
     }
     
+    SB_THREAD_MUTEX_UNLOCK(); 
     return sb_req; /* This request is valid even for last file */
   }      
   
@@ -471,7 +465,7 @@
     else 
       sb_req.type = SB_REQ_TYPE_NULL;
   }  
-  pthread_mutex_unlock(&fsync_mutex);
+  SB_THREAD_MUTEX_UNLOCK(); 
 
   if (sb_globals.validate)
   {
@@ -496,6 +490,7 @@
   int                  mode = test_mode;
   
   sb_req.type = SB_REQ_TYPE_FILE;
+  SB_THREAD_MUTEX_LOCK(); 
   
   /*
     Convert mode for combined tests. Locking to get consistent values
@@ -503,12 +498,10 @@
   */
   if (test_mode==MODE_RND_RW)
   {
-    SB_THREAD_MUTEX_LOCK();
     if ((double)(real_read_ops + 1) / (real_write_ops + 1) < file_rw_ratio)
       mode=MODE_RND_READ;
     else
       mode=MODE_RND_WRITE;
-    SB_THREAD_MUTEX_UNLOCK();
   }
 
   /* fsync all files (if requested by user) as soon as we are done */
@@ -518,7 +511,6 @@
         (real_mode == MODE_RND_WRITE || real_mode == MODE_RND_RW ||
          real_mode == MODE_MIXED))
     {
-      pthread_mutex_lock(&fsync_mutex);
       if(fsynced_file2 < num_files)
       {
         file_req->file_id = fsynced_file2;
@@ -526,14 +518,14 @@
         file_req->pos = 0;
         file_req->size = 0;
         fsynced_file2++;
-        pthread_mutex_unlock(&fsync_mutex);
-        
+
+        SB_THREAD_MUTEX_UNLOCK();        
         return sb_req;
       }
-      pthread_mutex_unlock(&fsync_mutex);
     }
     sb_req.type = SB_REQ_TYPE_NULL;
 
+    SB_THREAD_MUTEX_UNLOCK();        
     return sb_req;
   }
 
@@ -556,6 +548,7 @@
         is_dirty = 0;
       }
       
+      SB_THREAD_MUTEX_UNLOCK();        
       return sb_req;
     }
   }
@@ -576,6 +569,7 @@
   if (file_req->operation == FILE_OP_TYPE_WRITE) 
     is_dirty = 1;
 
+  SB_THREAD_MUTEX_UNLOCK();        
   return sb_req;
 }
 

_______________________________________________
Mailing list: https://launchpad.net/~sysbench-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sysbench-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to