[Stgt-devel] [Patch 1/1] device_reserved fastpath

Robert Jennings rcj
Mon Oct 1 21:56:26 CEST 2007


Maintain a count of logical units with reservations in the target 
structure.  For each IO we'll save traversing the entire list of 
logical units for a target to check for a reservation.  Attach more 
than one logicalunit to a target and this saves that many more 
lookups per IO.

Signed-off-by: rcj at linux.vnet.ibm.com

---
 usr/target.c |    8 ++++++++
 usr/target.h |    1 +
 2 files changed, 9 insertions(+)

Index: b/usr/target.c
===================================================================
--- a/usr/target.c
+++ b/usr/target.c
@@ -331,6 +331,9 @@ int tgt_device_destroy(int tid, uint64_t
 		lu->bst->bs_close(lu);
 	}
 
+	if (lu->reserve_id)
+		(target->reservations)--;
+
 	list_del(&lu->device_siblings);
 	free(lu);
 
@@ -409,6 +412,7 @@ int device_reserve(struct scsi_cmd *cmd)
 		return -EBUSY;
 	}
 
+	(cmd->c_target->reservations)++;
 	lu->reserve_id = cmd->cmd_itn_id;
 	return 0;
 }
@@ -426,6 +430,7 @@ int device_release(int tid, uint64_t itn
 
 	if (force || lu->reserve_id == itn_id) {
 		lu->reserve_id = 0;
+		(target->reservations)--;
 		return 0;
 	}
 
@@ -436,6 +441,9 @@ int device_reserved(struct scsi_cmd *cmd
 {
 	struct scsi_lu *lu;
 
+	if (cmd->c_target->reservations == 0)
+		return 0;
+
 	lu = device_lookup(cmd->c_target, cmd->dev->lun);
 	if (!lu || !lu->reserve_id || lu->reserve_id == cmd->cmd_itn_id)
 		return 0;
Index: b/usr/target.h
===================================================================
--- a/usr/target.h
+++ b/usr/target.h
@@ -25,6 +25,7 @@ struct target {
 
 	int tid;
 	int lid;
+	uint reservations;
 
 	enum scsi_target_state target_state;
 



More information about the stgt mailing list