From 82d7a68109b144046161001f89e5007947302b2f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 17 Apr 2012 13:12:50 -0700 Subject: [PATCH] rbd: fix probe of source when block device Fixes: #2304 Signed-off-by: Sage Weil --- src/common/fiemap.cc | 1 - src/rbd.cc | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common/fiemap.cc b/src/common/fiemap.cc index dd239058a00e4..0df12d6e8fd1e 100644 --- a/src/common/fiemap.cc +++ b/src/common/fiemap.cc @@ -58,7 +58,6 @@ struct fiemap *read_fiemap(int fd) /* Find out how many extents there are */ r = ioctl(fd, FS_IOC_FIEMAP, fiemap); if (r < 0) { - fprintf(stderr, "fiemap ioctl() failed\n"); goto done_err; } diff --git a/src/rbd.cc b/src/rbd.cc index 48f13dd5b805d..cb82f9cc70fe6 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -28,6 +28,7 @@ #include "include/intarith.h" #include "include/compat.h" +#include "common/blkdev.h" #include #include @@ -405,7 +406,7 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx, { int fd = open(path, O_RDONLY); int r; - uint64_t size; + int64_t size = 0; struct stat stat_buf; string md_oid; struct fiemap *fiemap; @@ -424,6 +425,13 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx, return r; } size = (uint64_t)stat_buf.st_size; + if (!size) { + r = get_block_device_size(fd, &size); + if (r < 0) { + cerr << "unable to get size of file/block device: " << cpp_strerror(r) << std::endl; + return r; + } + } assert(imgname); -- 2.39.5