From 41cb40ad90654f5930e14c95ee5ed9563a4bd919 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 17 Apr 2012 13:11:09 -0700 Subject: [PATCH] filestore: factor block device size probe out into helper Signed-off-by: Sage Weil --- src/Makefile.am | 2 ++ src/os/FileJournal.cc | 21 ++------------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index d734d2166b574..64269c078f17e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1011,6 +1011,7 @@ libcommon_files = \ osd/OSDMap.cc \ osd/osd_types.cc \ mds/MDSMap.cc \ + common/blkdev.cc \ common/common_init.cc \ common/pipe.c \ common/ceph_argparse.cc \ @@ -1204,6 +1205,7 @@ noinst_HEADERS = \ common/ceph_argparse.h\ common/ceph_context.h\ common/xattr.h\ + common/blkdev.h\ common/compiler_extensions.h\ common/debug.h\ common/dout.h\ diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index bf7abe2e4ff93..fce1b0350028b 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -29,9 +29,7 @@ #include #include -#if defined(__FreeBSD__) -#include -#endif +#include "common/blkdev.h" #define dout_subsys ceph_subsys_journal @@ -124,23 +122,8 @@ int FileJournal::_open(bool forwrite, bool create) int FileJournal::_open_block_device() { - int ret = 0; int64_t bdev_sz = 0; -#if defined(__FreeBSD__) - ret = ::ioctl(fd, DIOCGMEDIASIZE, &bdev_sz); -#elif defined(__linux__) -#ifdef BLKGETSIZE64 - // ioctl block device - ret = ::ioctl(fd, BLKGETSIZE64, &bdev_sz); -#elif BLKGETSIZE - // hrm, try the 32 bit ioctl? - unsigned long sectors = 0; - ret = ::ioctl(fd, BLKGETSIZE, §ors); - bdev_sz = sectors * 512ULL; -#endif -#else -#error "Compile error: we don't know how to get the size of a raw block device." -#endif /* !__FreeBSD__ */ + int ret = get_block_device_size(fd, &bdev_sz); if (ret) { dout(0) << __func__ << ": failed to read block device size." << dendl; return -EIO; -- 2.39.5