generic/465: just check the actual read data under dio read/write
authorXiao Yang <yangx.jy@cn.fujitsu.com>
Mon, 27 Nov 2017 02:34:27 +0000 (10:34 +0800)
committerEryu Guan <eguan@redhat.com>
Tue, 28 Nov 2017 07:23:59 +0000 (15:23 +0800)
I got the following message when running generic/465 in ext4
data=journal mode
---------------------------------------------------------------
QA output created by 465
non-aio dio test
encounter an error: block 0 offset 4096, content 62
encounter an error: block 0 offset 122880, content 62
encounter an error: block 0 offset 274432, content 62
encounter an error: block 0 offset 86016, content 62
aio-dio test
encounter an error: block 0 offset 28672, content 62
encounter an error: block 0 offset 12288, content 62
encounter an error: block 2 offset 16384, content 62
encounter an error: block 1 offset 565248, content 62
---------------------------------------------------------------

In ext4 data=journal mode, direct read will fall back to buffer
read, and buffer read doesn't take inode lock, so it doesn't need to
wait for the writer to finish first and sees the intermediate inode
size and returns data less than 1M.

We can just check the actual read data instead of the whole read
buffer.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
src/aio-dio-regress/aio-dio-append-write-read-race.c

index 8f94d503c955f0bb978db2423ed95f40a338d82e..443994771623bd6c8160feb0901c6de3b14b509d 100644 (file)
@@ -43,6 +43,7 @@ struct io_data {
        off_t offset;
        char *buf;
        int use_aio;
        off_t offset;
        char *buf;
        int use_aio;
+       ssize_t read_sz;
 };
 
 int reader_ready = 0;
 };
 
 int reader_ready = 0;
@@ -57,15 +58,15 @@ static void usage(const char *prog)
 static void *reader(void *arg)
 {
        struct io_data *data = (struct io_data *)arg;
 static void *reader(void *arg)
 {
        struct io_data *data = (struct io_data *)arg;
-       int ret;
 
        memset(data->buf, 'b', data->blksize);
        reader_ready = 1;
        do {
 
        memset(data->buf, 'b', data->blksize);
        reader_ready = 1;
        do {
-               ret = pread(data->fd, data->buf, data->blksize, data->offset);
-               if (ret < 0)
+               data->read_sz = pread(data->fd, data->buf, data->blksize,
+                                     data->offset);
+               if (data->read_sz < 0)
                        perror("read file");
                        perror("read file");
-       } while (ret <= 0);
+       } while (data->read_sz <= 0);
 
        return NULL;
 }
 
        return NULL;
 }
@@ -203,7 +204,7 @@ int main(int argc, char *argv[])
                        goto err;
                }
 
                        goto err;
                }
 
-               for (j = 0; j < blksize; j++) {
+               for (j = 0; j < rdata.read_sz; j++) {
                        if (rdata.buf[j] != 'a') {
                                fail("encounter an error: "
                                        "block %d offset %d, content %x\n",
                        if (rdata.buf[j] != 'a') {
                                fail("encounter an error: "
                                        "block %d offset %d, content %x\n",