Skip to contentSkip to conversation

target: Fix bugs when dealing with unconfigured devices

PATCH New Nicholas A. Bellinger 1 participant 3 messages Jan 31, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover target: Fix bugs when dealing with unconfigured devices

From: Nicholas Bellinger <[email protected]>

Hi folks,

These two patches address two bugs that I've ran across when dealing with backend devices that have failed to be successfully enabled, and remain in an unconfigured state.

The first is a v3.8-rc1 specific regression due to fallout from the removal of struct se_subsystem_dev, and the second is to avoid a possible divide by zero when writing fabric_max_sectors when no block_size has been set by the device.

The latter is being CC'ed to stable.

Thanks,

--nab

Nicholas Bellinger (2):
target: Fix regression allowing unconfigured devices to fabric port
link
target: Fix divide by zero bug in fabric_max_sectors for unconfigured
devices

 drivers/target/target_core_device.c          |    8 +++++++-
 drivers/target/target_core_fabric_configfs.c |    5 +++++
 2 files changed, 12 insertions(+), 1 deletions(-)
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 1/2 target: Fix regression allowing unconfigured devices to fabric port link

From: Nicholas Bellinger <[email protected]>

This patch fixes a v3.8-rc1 regression bug where an unconfigured se_device was incorrectly allowed to perform a fabric port-link. This bug was introduced in commit:

commit 0fd97ccf45be26fb01b3a412f1f6c6b5044b2f16
Author: Christoph Hellwig <[email protected]>
Date: Mon Oct 8 00:03:19 2012 -0400

target: kill struct se_subsystem_dev

which ended up dropping the original se_subsystem_dev->se_dev_ptr check preventing this from happening with pre commit 0fd97ccf code.

---
 drivers/target/target_core_fabric_configfs.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/target/target_core_fabric_configfs.c +5 -0
index 810263d..c57bbbc 100644
@@ -754,6 +754,11 @@ static int target_fabric_port_link(
 		return -EFAULT;
 	}
 
+	if (!(dev->dev_flags & DF_CONFIGURED)) {
+		pr_err("se_device not configured yet, cannot port link\n");
+		return -ENODEV;
+	}
+
 	tpg_ci = &lun_ci->ci_parent->ci_group->cg_item;
 	se_tpg = container_of(to_config_group(tpg_ci),
 				struct se_portal_group, tpg_group);
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/2 target: Fix divide by zero bug in fabric_max_sectors for unconfigured devices

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch fixes a possible divide by zero bug when the fabric_max_sectors device attribute is written and backend se_device failed to be successfully configured -> enabled.

Go ahead and use block_size=512 within se_dev_set_fabric_max_sectors() in the event of a target_configure_device() failure case, as no valid dev->dev_attrib.block_size value will have been setup yet.

---
 drivers/target/target_core_device.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/target/target_core_device.c +7 -1
index e269510..f2aa754 100644
@@ -941,6 +941,8 @@ int se_dev_set_queue_depth(struct se_device *dev, u32 queue_depth)
 
 int se_dev_set_fabric_max_sectors(struct se_device *dev, u32 fabric_max_sectors)
 {
+	int block_size = dev->dev_attrib.block_size;
+
 	if (dev->export_count) {
 		pr_err("dev[%p]: Unable to change SE Device"
 			" fabric_max_sectors while export_count is %d\n",
@@ -978,8 +980,12 @@ int se_dev_set_fabric_max_sectors(struct se_device *dev, u32 fabric_max_sectors)
 	/*
 	 * Align max_sectors down to PAGE_SIZE to follow transport_allocate_data_tasks()
 	 */
+	if (!block_size) {
+		block_size = 512;
+		pr_warn("Defaulting to 512 for zero block_size\n");
+	}
 	fabric_max_sectors = se_dev_align_max_sectors(fabric_max_sectors,
-						      dev->dev_attrib.block_size);
+						      block_size);
 
 	dev->dev_attrib.fabric_max_sectors = fabric_max_sectors;
 	pr_debug("dev[%p]: SE Device max_sectors changed to %u\n",
Signature · 1 line
1.7.2.5