From: Jens Axboe Date: Tue, 7 Oct 2014 14:27:19 +0000 (-0600) Subject: t/dedupe: use generic blockdev_size() to get size X-Git-Tag: fio-2.1.14~95 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=d08a6886fa57f819682f05548d284a079a99e77d t/dedupe: use generic blockdev_size() to get size This means we can skip the Linux specific compile, so enable it on all platforms. Signed-off-by: Jens Axboe --- diff --git a/Makefile b/Makefile index 56620152..795f75ca 100644 --- a/Makefile +++ b/Makefile @@ -194,13 +194,11 @@ T_BTRACE_FIO_OBJS += fifo.o lib/flist_sort.o t/log.o lib/linux-dev-lookup.o T_BTRACE_FIO_PROGS = t/btrace2fio endif -ifeq ($(CONFIG_TARGET_OS), Linux) T_DEDUPE_OBJS = t/dedupe.o T_DEDUPE_OBJS += lib/rbtree.o t/log.o mutex.o smalloc.o gettime.o crc/md5.o \ memalign.o lib/bloom.o t/debug.o crc/xxhash.o crc/murmur3.o \ crc/crc32c.o crc/crc32c-intel.o crc/fnv.o T_DEDUPE_PROGS = t/dedupe -endif T_OBJS = $(T_SMALLOC_OBJS) T_OBJS += $(T_IEEE_OBJS) diff --git a/t/dedupe.c b/t/dedupe.c index 1577a691..0a033a4c 100644 --- a/t/dedupe.c +++ b/t/dedupe.c @@ -78,17 +78,20 @@ static uint64_t total_size; static uint64_t cur_offset; static struct fio_mutex *size_lock; -static int dev_fd; +static struct fio_file file; -static uint64_t get_size(int fd, struct stat *sb) +static uint64_t get_size(struct fio_file *f, struct stat *sb) { uint64_t ret; if (S_ISBLK(sb->st_mode)) { - if (ioctl(fd, BLKGETSIZE64, &ret) < 0) { - perror("ioctl"); + unsigned long long bytes; + + if (blockdev_size(f, &bytes)) { + log_err("dedupe: failed getting bdev size\n"); return 0; } + ret = bytes; } else ret = sb->st_size; @@ -164,10 +167,10 @@ static int col_check(struct chunk *c, struct item *i) ibuf = fio_memalign(blocksize, blocksize); e = flist_entry(c->extent_list[0].next, struct extent, list); - if (read_block(dev_fd, cbuf, e->offset)) + if (read_block(file.fd, cbuf, e->offset)) goto out; - if (read_block(dev_fd, ibuf, i->offset)) + if (read_block(file.fd, ibuf, i->offset)) goto out; ret = memcmp(ibuf, cbuf, blocksize); @@ -372,8 +375,8 @@ static void show_progress(struct worker_thread *threads, unsigned long total) }; } -static int run_dedupe_threads(int fd, uint64_t dev_size, uint64_t *nextents, - uint64_t *nchunks) +static int run_dedupe_threads(struct fio_file *f, uint64_t dev_size, + uint64_t *nextents, uint64_t *nchunks) { struct worker_thread *threads; unsigned long nitems, total_items; @@ -386,7 +389,7 @@ static int run_dedupe_threads(int fd, uint64_t dev_size, uint64_t *nextents, threads = malloc(num_threads * sizeof(struct worker_thread)); for (i = 0; i < num_threads; i++) { - threads[i].fd = fd; + threads[i].fd = f->fd; threads[i].items = 0; threads[i].err = 0; threads[i].done = 0; @@ -431,23 +434,23 @@ static int dedupe_check(const char *filename, uint64_t *nextents, if (odirect) flags |= O_DIRECT; - dev_fd = open(filename, flags); - if (dev_fd == -1) { + memset(&file, 0, sizeof(file)); + file.file_name = strdup(filename); + + file.fd = open(filename, flags); + if (file.fd == -1) { perror("open"); - return 1; + goto err; } - if (fstat(dev_fd, &sb) < 0) { + if (fstat(file.fd, &sb) < 0) { perror("fstat"); - close(dev_fd); - return 1; + goto err; } - dev_size = get_size(dev_fd, &sb); - if (!dev_size) { - close(dev_fd); - return 1; - } + dev_size = get_size(&file, &sb); + if (!dev_size) + goto err; if (use_bloom) { uint64_t bloom_entries; @@ -458,7 +461,12 @@ static int dedupe_check(const char *filename, uint64_t *nextents, printf("Will check <%s>, size <%llu>, using %u threads\n", filename, (unsigned long long) dev_size, num_threads); - return run_dedupe_threads(dev_fd, dev_size, nextents, nchunks); + return run_dedupe_threads(&file, dev_size, nextents, nchunks); +err: + if (file.fd != -1) + close(file.fd); + free(file.file_name); + return 1; } static void show_chunk(struct chunk *c)