From 8e912b9a0564a57f1b761e9e567771197bd0fb98 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 5 May 2017 15:59:44 +0200 Subject: [PATCH] rbd-nbd: relax size check for newer kernel versions Fixes: http://tracker.ceph.com/issues/19871 Signed-off-by: Mykola Golub --- src/tools/rbd_nbd/rbd-nbd.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 8ba83208b2e..8b59ccd267e 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -500,6 +500,10 @@ static int open_device(const char* path, bool try_load_module = false) static int check_device_size(int nbd_index, unsigned long expected_size) { + // There are bugs with some older kernel versions that result in an + // overflow for large image sizes. This check is to ensure we are + // not affected. + unsigned long size = 0; std::string path = "/sys/block/nbd" + stringify(nbd_index) + "/size"; std::ifstream ifs; @@ -511,6 +515,12 @@ static int check_device_size(int nbd_index, unsigned long expected_size) ifs >> size; size *= RBD_NBD_BLKSIZE; + if (size == 0) { + // Newer kernel versions will report real size only after nbd + // connect. Assume this is the case and return success. + return 0; + } + if (size != expected_size) { cerr << "rbd-nbd: kernel reported invalid device size (" << size << ", expected " << expected_size << ")" << std::endl; -- 2.39.5