t/dedupe: use generic blockdev_size() to get size
authorJens Axboe <axboe@fb.com>
Tue, 7 Oct 2014 14:27:19 +0000 (08:27 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 7 Oct 2014 14:27:19 +0000 (08:27 -0600)
This means we can skip the Linux specific compile, so enable it
on all platforms.

Signed-off-by: Jens Axboe <axboe@fb.com>
Makefile
t/dedupe.c

index 5662015218aaf9ed3867aba5042e3332f232afb8..795f75ca2210667acc19ea26b2a757956bd0f8cd 100644 (file)
--- 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)
index 1577a691eb0dfc575913bd40e18afa54741615a6..0a033a4c91e48e77b6a0790b0cf5c45bee4d6134 100644 (file)
@@ -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)