fread and fwrite return values does not match blktrace output

182 views Asked by At

I'm doing some experiment on SSDs to check weather they have data loss under power fault. At the first step I write a random data on SSD and then in the next step I inject a power fault to it. At the end I read from the SSD and check weather the data match to data I've written before power fault. Unfortunately all the tests passed without any data loss.

Here's a sample code for my experiment.

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
using namespace std;

int main()
{
   FILE *fp = fopen("/dev/sdb", "rb+");

   char* writeBuffer = (char*) malloc(4096 * 16 * sizeof(char));
   char* readBuffer = (char*) malloc(4096 * 16 * sizeof(char));

   for(int i = 0; i < 4096 * 16; i++)
     readBuffer[i] = rand() % 256;

   fseeko64(fp, (unsigned long long int) 6107552 * 4096, SEEK_SET);
   int writeBytes = fwrite((void*) writeBuffer, sizeof(char), 4096 * 16, fp);

   sleep(2); // power fault injection

   fseeko64(fp, (unsigned long long int) 6107552 * 4096, SEEK_SET);
   int readBytes = fread((void*) readBuffer, sizeof(char), 4096 * 16, fp);

   cout << "Write Bytes : " << writeBytes
        << "    Read Bytes : " << readBytes << endl;

   fclose(fp);
   return 0;
}

I executed the code above while running blktrace on /dev/sdb. I got the following result. fread() has no trace in blktrace output.

  blktrace -d /dev/sdb -o - | blkparse -i -
  8,16   3        1     0.000000000    74  Q   W 48860416 + 8 [kworker/u16:1]
  8,16   3        2     0.000005829    74  G   W 48860416 + 8 [kworker/u16:1]
  8,16   3        3     0.000007357    74  P   N [kworker/u16:1]
  8,16   3        4     0.000010943    74  Q   W 48860424 + 8 [kworker/u16:1]
  8,16   3        5     0.000012601    74  M   W 48860424 + 8 [kworker/u16:1]
  8,16   3        6     0.000014427    74  Q   W 48860432 + 8 [kworker/u16:1]
  8,16   3        7     0.000014899    74  M   W 48860432 + 8 [kworker/u16:1]
  8,16   3        8     0.000016525    74  Q   W 48860440 + 8 [kworker/u16:1]
  8,16   3        9     0.000016780    74  M   W 48860440 + 8 [kworker/u16:1]
  8,16   3       10     0.000018818    74  Q   W 48860448 + 8 [kworker/u16:1]
  8,16   3       11     0.000019168    74  M   W 48860448 + 8 [kworker/u16:1]
  8,16   3       12     0.000022649    74  Q   W 48860456 + 8 [kworker/u16:1]
  8,16   3       13     0.000022929    74  M   W 48860456 + 8 [kworker/u16:1]
  8,16   3       14     0.000024345    74  Q   W 48860464 + 8 [kworker/u16:1]
  8,16   3       15     0.000024682    74  M   W 48860464 + 8 [kworker/u16:1]
  8,16   3       16     0.000025933    74  Q   W 48860472 + 8 [kworker/u16:1]
  8,16   3       17     0.000026205    74  M   W 48860472 + 8 [kworker/u16:1]
  8,16   3       18     0.000027480    74  Q   W 48860480 + 8 [kworker/u16:1]
  8,16   3       19     0.000027803    74  M   W 48860480 + 8 [kworker/u16:1]
  8,16   3       20     0.000029141    74  Q   W 48860488 + 8 [kworker/u16:1]
  8,16   3       21     0.000029416    74  M   W 48860488 + 8 [kworker/u16:1]
  8,16   3       22     0.000030519    74  Q   W 48860496 + 8 [kworker/u16:1]
  8,16   3       23     0.000030856    74  M   W 48860496 + 8 [kworker/u16:1]
  8,16   3       24     0.000032865    74  Q   W 48860504 + 8 [kworker/u16:1]
  8,16   3       25     0.000033172    74  M   W 48860504 + 8 [kworker/u16:1]
  8,16   3       26     0.000034933    74  Q   W 48860512 + 8 [kworker/u16:1]
  8,16   3       27     0.000035258    74  M   W 48860512 + 8 [kworker/u16:1]
  8,16   3       28     0.000036723    74  Q   W 48860520 + 8 [kworker/u16:1]
  8,16   3       29     0.000037081    74  M   W 48860520 + 8 [kworker/u16:1]
  8,16   3       30     0.000044758    74  Q   W 48860528 + 8 [kworker/u16:1]
  8,16   3       31     0.000045026    74  M   W 48860528 + 8 [kworker/u16:1]
  8,16   3       32     0.000046789    74  Q   W 48860536 + 8 [kworker/u16:1]
  8,16   3       33     0.000047079    74  M   W 48860536 + 8 [kworker/u16:1]
  8,16   3       34     0.000048702    74  I   W 48860416 + 128 [kworker/u16:1]
  8,16   3       35     0.000050392    74  U   N [kworker/u16:1] 1
  8,16   3       36     0.000052170    74  D   W 48860416 + 128 [kworker/u16:1]
  8,16   2        1     0.000885952     0  C   W 48860416 + 128 [0]

How can I disable reading from buffer?

0

There are 0 answers