Signed-off-by: Jens Axboe <axboe@fb.com>
-static int read_block(int fd, void *buf, off_t offset)
+static int __read_block(int fd, void *buf, off_t offset, size_t count)
- ret = pread(fd, buf, blocksize, offset);
+ ret = pread(fd, buf, count, offset);
if (ret < 0) {
perror("pread");
return 1;
} else if (!ret)
return 1;
if (ret < 0) {
perror("pread");
return 1;
} else if (!ret)
return 1;
- else if (ret != blocksize) {
+ else if (ret != count) {
log_err("dedupe: short read on block\n");
return 1;
}
log_err("dedupe: short read on block\n");
return 1;
}
+static int read_block(int fd, void *buf, off_t offset)
+{
+ return __read_block(fd, buf, offset, blocksize);
+}
+
static void add_item(struct chunk *c, struct item *i)
{
/*
static void add_item(struct chunk *c, struct item *i)
{
/*
+static unsigned int read_blocks(int fd, void *buf, off_t offset, size_t size)
+{
+ if (__read_block(fd, buf, offset, size))
+ return 0;
+
+ return size / blocksize;
+}
+
static int do_work(struct worker_thread *thread, void *buf)
{
unsigned int nblocks, i;
off_t offset;
static int do_work(struct worker_thread *thread, void *buf)
{
unsigned int nblocks, i;
off_t offset;
- int err = 0, nitems = 0;
uint64_t ndupes = 0;
struct item *items;
uint64_t ndupes = 0;
struct item *items;
- nblocks = thread->size / blocksize;
offset = thread->cur_offset;
offset = thread->cur_offset;
+
+ nblocks = read_blocks(thread->fd, buf, offset, min(thread->size, (uint64_t)chunk_size));
+ if (!nblocks)
+ return 1;
+
items = malloc(sizeof(*items) * nblocks);
for (i = 0; i < nblocks; i++) {
items = malloc(sizeof(*items) * nblocks);
for (i = 0; i < nblocks; i++) {
- if (read_block(thread->fd, buf, offset))
- break;
+ void *thisptr = buf + (i * blocksize);
+
if (items)
items[i].offset = offset;
if (items)
items[i].offset = offset;
- crc_buf(buf, items[i].hash);
+ crc_buf(thisptr, items[i].hash);
offset += blocksize;
nitems++;
}
offset += blocksize;
nitems++;
}
free(items);
thread->items += nitems;
thread->dupes += ndupes;
free(items);
thread->items += nitems;
thread->dupes += ndupes;
}
static void *thread_fn(void *data)
}
static void *thread_fn(void *data)
struct worker_thread *thread = data;
void *buf;
struct worker_thread *thread = data;
void *buf;
- buf = fio_memalign(blocksize, blocksize);
+ buf = fio_memalign(blocksize, chunk_size);
do {
if (get_work(&thread->cur_offset, &thread->size)) {
do {
if (get_work(&thread->cur_offset, &thread->size)) {
} while (1);
thread->done = 1;
} while (1);
thread->done = 1;
- fio_memfree(buf, blocksize);
+ fio_memfree(buf, chunk_size);