summaryrefslogtreecommitdiff
path: root/sys-cluster/ceph/files/ceph-10.2.9-rbd-nbd_relax_size_check_for_newer_kernel_versions.patch
blob: 5cb89be0edf15a448cc65e0cc68106208ea275cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc
index 2e399ab832..88e1e0ff65 100644
--- a/src/tools/rbd_nbd/rbd-nbd.cc
+++ b/src/tools/rbd_nbd/rbd-nbd.cc
@@ -469,6 +469,10 @@ static int open_device(const char* path, bool try_load_moudle = 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;
@@ -480,6 +484,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;