Blob Blame History Raw
From 0cc447534209d48b7785db0200f196940eaf17c8 Mon Sep 17 00:00:00 2001
From: David Disseldorp <ddiss@suse.de>
Date: Sun, 11 Oct 2020 01:29:03 +0200
Subject: [PATCH] target/rbd: detect stripe_unit SCSI block size misalignment
References: bsc#1177090
Patch-mainline: Not yet, SES clustered LIO/RBD

SCSI compare-and-write must be handled atomically, but this won't be the
case if the single-block I/O spans multiple RADOS objects.

Signed-off-by: David Disseldorp <ddiss@suse.de>
Reviewed-by: Roman Penyaev <rpenyaev@suse.com>
Reviewed-by: Luis Henriques <lhenriques@suse.com>
---
 drivers/target/target_core_rbd.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_rbd.c b/drivers/target/target_core_rbd.c
index 09e662ec689c..1a0efe1254f6 100644
--- a/drivers/target/target_core_rbd.c
+++ b/drivers/target/target_core_rbd.c
@@ -120,10 +120,18 @@ static int tcm_rbd_configure_device(struct se_device *dev)
 	dev->dev_attrib.max_write_same_len = 0xFFFF;
 	dev->dev_attrib.is_nonrot = 1;
 
-	/*
-	 * TODO fail if RBD stripe unit isn't a multiple of SCSI block size:
-	 * multi-object compare-and-write isn't atomic.
-	 */
+	if (tcm_rbd_dev->rbd_dev->layout.stripe_unit % 4096) {
+		/*
+		 * SCSI compare-and-write must be handled atomically, but this
+		 * won't be the case if the single-block SCSI I/O spans multiple
+		 * RADOS objects. Can't use dev_attrib.block_size here, as it
+		 * may not be configured yet.
+		 */
+		pr_err("RBD: stripe unit %u must be a multiple of 4K\n",
+			tcm_rbd_dev->rbd_dev->layout.stripe_unit);
+		/* blkdev_put() called in destroy_device */
+		return -EINVAL;
+	}
 
 	/* disable standalone reservation handling */
 	dev->dev_attrib.emulate_pr = 0;
-- 
2.26.2