From 40d7fa0fcd0134d8d53649cec7a2afa4e6e7aa8b Mon Sep 17 00:00:00 2001
From: Mark Syms <mark.syms@citrix.com>
Date: Fri, 31 Oct 2025 11:39:22 +0000
Subject: [PATCH] CA-418775: ensure getsize and sg_readcap agree on resize

When resizing the LUN underneath a PV for and SR ensure that the size
property in `/sys/block/<device>` and `sg_readcap` agree on the device
size before request `pvresize`. Intermittent failures have been
observered where `pvresize` would be called and not increase the size
of the PV. It appears that this has some relation to data in the
kernel device not seeing the update as being complete.

Signed-off-by: Mark Syms <mark.syms@citrix.com>
---
 drivers/scsiutil.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsiutil.py b/drivers/scsiutil.py
index 2f6f743..abced6f 100755
--- a/drivers/scsiutil.py
+++ b/drivers/scsiutil.py
@@ -583,6 +583,9 @@ def refresh_lun_size_by_SCSIid(SCSIid):
                                        "current capacity."
                                        % devicesthatneedrefresh)
 
+        if any([getsize(x) != sg_readcap(x) for x in devices]):
+            raise util.SMException(f"Not all devices in {devices} agree on size and capacity")
+
     def refresh_mapper_if_needed(primarydevice, SCSIid, currentcapacity):
         if "/dev/mapper/" in primarydevice \
            and get_outdated_size_devices(currentcapacity, [primarydevice]):
-- 
2.51.0

