Compare commits
2 Commits
c5d8b27c44
...
3b9c970e00
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 3b9c970e00 | |
Vitaliy Filippov | 48f023292d |
|
@ -25,7 +25,7 @@
|
||||||
#include "malloc_or_die.h"
|
#include "malloc_or_die.h"
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
|
||||||
//#define BLOCKSTORE_DEBUG
|
#define BLOCKSTORE_DEBUG
|
||||||
|
|
||||||
// States are not stored on disk. Instead, they're deduced from the journal
|
// States are not stored on disk. Instead, they're deduced from the journal
|
||||||
|
|
||||||
|
|
|
@ -369,6 +369,8 @@ std::vector<osd_chain_read_t> osd_t::collect_chained_read_requests(osd_op_t *cur
|
||||||
global_bitmap[cur>>3] = global_bitmap[cur>>3] | (part_bitmap[cur>>3] & (1 << (cur&7)));
|
global_bitmap[cur>>3] = global_bitmap[cur>>3] | (part_bitmap[cur>>3] & (1 << (cur&7)));
|
||||||
}
|
}
|
||||||
// Add request
|
// Add request
|
||||||
|
if (cur_op->req.rw.len)
|
||||||
|
{
|
||||||
chain_reads.push_back((osd_chain_read_t){
|
chain_reads.push_back((osd_chain_read_t){
|
||||||
.chain_pos = chain_pos,
|
.chain_pos = chain_pos,
|
||||||
.inode = op_data->read_chain[chain_pos],
|
.inode = op_data->read_chain[chain_pos],
|
||||||
|
@ -377,6 +379,7 @@ std::vector<osd_chain_read_t> osd_t::collect_chained_read_requests(osd_op_t *cur
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return chain_reads;
|
return chain_reads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@ target_link_libraries(stub_bench tcmalloc_minimal)
|
||||||
add_executable(osd_test osd_test.cpp ../util/rw_blocking.cpp ../util/addr_util.cpp)
|
add_executable(osd_test osd_test.cpp ../util/rw_blocking.cpp ../util/addr_util.cpp)
|
||||||
target_link_libraries(osd_test tcmalloc_minimal)
|
target_link_libraries(osd_test tcmalloc_minimal)
|
||||||
|
|
||||||
|
# bindiff
|
||||||
|
add_executable(bindiff
|
||||||
|
bindiff.c
|
||||||
|
)
|
||||||
|
|
||||||
# stub_uring_osd
|
# stub_uring_osd
|
||||||
add_executable(stub_uring_osd
|
add_executable(stub_uring_osd
|
||||||
stub_uring_osd.cpp
|
stub_uring_osd.cpp
|
||||||
|
|
|
@ -0,0 +1,177 @@
|
||||||
|
// Copyright (c) Vitaliy Filippov, 2004+
|
||||||
|
// License: VNPL-1.1 (see README.md for details)
|
||||||
|
|
||||||
|
#ifndef _LARGEFILE64_SOURCE
|
||||||
|
#define _LARGEFILE64_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define BUFSIZE 0x100000
|
||||||
|
|
||||||
|
uint64_t filelength(int fd)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "fstat failed: %s\n", strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (st.st_size < 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (uint64_t)st.st_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t read_blocking(int fd, void *read_buf, size_t remaining)
|
||||||
|
{
|
||||||
|
size_t done = 0;
|
||||||
|
while (done < remaining)
|
||||||
|
{
|
||||||
|
ssize_t r = read(fd, read_buf, remaining-done);
|
||||||
|
if (r <= 0)
|
||||||
|
{
|
||||||
|
if (!errno)
|
||||||
|
{
|
||||||
|
// EOF
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
else if (errno != EINTR && errno != EAGAIN && errno != EPIPE)
|
||||||
|
{
|
||||||
|
perror("read");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
done += (size_t)r;
|
||||||
|
read_buf = (uint8_t*)read_buf + r;
|
||||||
|
}
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t write_blocking(int fd, void *write_buf, size_t remaining)
|
||||||
|
{
|
||||||
|
size_t done = 0;
|
||||||
|
while (done < remaining)
|
||||||
|
{
|
||||||
|
ssize_t r = write(fd, write_buf, remaining-done);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
if (errno != EINTR && errno != EAGAIN && errno != EPIPE)
|
||||||
|
{
|
||||||
|
perror("write");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
done += (size_t)r;
|
||||||
|
write_buf = (uint8_t*)write_buf + r;
|
||||||
|
}
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int narg, char *args[])
|
||||||
|
{
|
||||||
|
int fd1 = -1, fd2 = -1;
|
||||||
|
uint8_t *buf1 = NULL, *buf2 = NULL;
|
||||||
|
uint64_t addr = 0, l1 = 0, l2 = 0, l = 0, diffl = 0;
|
||||||
|
size_t buf1_len = 0, buf2_len = 0, i = 0, j = 0, dl = 0;
|
||||||
|
int argoff = 0;
|
||||||
|
int nosource = 0;
|
||||||
|
fprintf(stderr, "VMX HexDiff v2.1\nLicense: GPLv3.0+, (c) 2005+, Vitaliy Filippov\n");
|
||||||
|
argoff = 1;
|
||||||
|
if (narg > argoff && strcmp(args[argoff], "-n") == 0)
|
||||||
|
{
|
||||||
|
nosource = 1;
|
||||||
|
argoff++;
|
||||||
|
}
|
||||||
|
if (narg < argoff+2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "USAGE: bindiff [-n] <file1> <file2>\n"
|
||||||
|
"This will create hex patch file1->file2 and write it to stdout.\n"
|
||||||
|
"[-n] = do not write file1 data in patch, only file2.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fd1 = open(args[argoff], O_RDONLY);
|
||||||
|
if (fd1 < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't open %s: %s\n", args[argoff], strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fd2 = open(args[argoff+1], O_RDONLY);
|
||||||
|
if (fd2 < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't open %s: %s\n", args[argoff+1], strerror(errno));
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
l1 = filelength(fd1);
|
||||||
|
l2 = filelength(fd2);
|
||||||
|
if (l1 < l2)
|
||||||
|
l = l1;
|
||||||
|
else
|
||||||
|
l = l2;
|
||||||
|
addr = diffl = 0;
|
||||||
|
buf1 = malloc(BUFSIZE+1);
|
||||||
|
buf2 = malloc(BUFSIZE+1);
|
||||||
|
while ((buf1_len = read_blocking(fd1, buf1, BUFSIZE)) > 0 && (buf2_len = read_blocking(fd2, buf2, BUFSIZE)) > 0)
|
||||||
|
{
|
||||||
|
buf1[buf1_len] = buf2[buf2_len] = 0;
|
||||||
|
for (dl = 0, i = 0; i <= buf1_len && i <= buf2_len; i++, addr++)
|
||||||
|
{
|
||||||
|
if (buf1[i] != buf2[i])
|
||||||
|
{
|
||||||
|
dl++;
|
||||||
|
}
|
||||||
|
else if (dl)
|
||||||
|
{
|
||||||
|
printf("%08jX: ", addr-dl);
|
||||||
|
if (!nosource)
|
||||||
|
{
|
||||||
|
for (j = i-dl; j < i; j++)
|
||||||
|
printf("%02X", buf1[j]);
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
for (j = i-dl; j < i; j++)
|
||||||
|
printf("%02X", buf2[j]);
|
||||||
|
printf("\n");
|
||||||
|
diffl += dl;
|
||||||
|
dl = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addr--;
|
||||||
|
}
|
||||||
|
if (l1 < l2)
|
||||||
|
{
|
||||||
|
printf("%08zX: ", i);
|
||||||
|
while ((buf2_len = read_blocking(fd2, buf2, BUFSIZE)) > 0)
|
||||||
|
{
|
||||||
|
for (j = 0; j < buf2_len; j++, i++)
|
||||||
|
printf("%02X", buf2[j]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
else if (l1 > l2)
|
||||||
|
{
|
||||||
|
printf("SIZE %08zX\n", l2);
|
||||||
|
}
|
||||||
|
if (diffl != 0 || l1 != l2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Difference in %zu of %zu common bytes\n", diffl, l);
|
||||||
|
if (l1 != l2)
|
||||||
|
fprintf(stderr, "Length difference!\nFile \"%s\": %zu\nFile \"%s\": %zu\n", args [1], l1, args [2], l2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Files are equal\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include "rw_blocking.h"
|
#include "rw_blocking.h"
|
||||||
|
|
||||||
int read_blocking(int fd, void *read_buf, size_t remaining)
|
size_t read_blocking(int fd, void *read_buf, size_t remaining)
|
||||||
{
|
{
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
while (done < remaining)
|
while (done < remaining)
|
||||||
|
@ -30,13 +30,13 @@ int read_blocking(int fd, void *read_buf, size_t remaining)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
done += r;
|
done += (size_t)r;
|
||||||
read_buf = (uint8_t*)read_buf + r;
|
read_buf = (uint8_t*)read_buf + r;
|
||||||
}
|
}
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_blocking(int fd, void *write_buf, size_t remaining)
|
size_t write_blocking(int fd, void *write_buf, size_t remaining)
|
||||||
{
|
{
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
while (done < remaining)
|
while (done < remaining)
|
||||||
|
@ -51,7 +51,7 @@ int write_blocking(int fd, void *write_buf, size_t remaining)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
done += r;
|
done += (size_t)r;
|
||||||
write_buf = (uint8_t*)write_buf + r;
|
write_buf = (uint8_t*)write_buf + r;
|
||||||
}
|
}
|
||||||
return done;
|
return done;
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
int read_blocking(int fd, void *read_buf, size_t remaining);
|
size_t read_blocking(int fd, void *read_buf, size_t remaining);
|
||||||
int write_blocking(int fd, void *write_buf, size_t remaining);
|
size_t write_blocking(int fd, void *write_buf, size_t remaining);
|
||||||
int readv_blocking(int fd, iovec *iov, int iovcnt);
|
int readv_blocking(int fd, iovec *iov, int iovcnt);
|
||||||
int writev_blocking(int fd, iovec *iov, int iovcnt);
|
int writev_blocking(int fd, iovec *iov, int iovcnt);
|
||||||
int sendv_blocking(int fd, iovec *iov, int iovcnt, int flags);
|
int sendv_blocking(int fd, iovec *iov, int iovcnt, int flags);
|
||||||
|
|
|
@ -60,6 +60,7 @@ qemu-img convert -S 4096 -p \
|
||||||
-O raw ./testdata/bin/read.bin
|
-O raw ./testdata/bin/read.bin
|
||||||
|
|
||||||
if ! diff -q ./testdata/bin/read.bin ./testdata/bin/mirror.bin; then
|
if ! diff -q ./testdata/bin/read.bin ./testdata/bin/mirror.bin; then
|
||||||
|
build/src/test/bindiff ./testdata/bin/read.bin ./testdata/bin/mirror.bin
|
||||||
format_error Data lost during self-heal
|
format_error Data lost during self-heal
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue