Skip to contentSkip to conversation

Target_Core_Mod/Persistent_Reservations]: Add APTPL feature support

PATCH New Nicholas A. Bellinger 1 participant 1 message Aug 10, 2009

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

PATCH 1/2 Target_Core_Mod/Persistent_Reservations]: Add APTPL feature support

Hello,

This patch adds complete running support for persistent reservations feature:
Activate Persist across Target Power Loss (APTPL) against all of spc4r17 defined PROUT service actions. This patch has been tested with PROUT service actions REGISTER, RESERVE, RELEASE, CLEAR, PREEMPT_AND_ABORT and REGISTER_AND_MOVE from a IBLOCK exported LVM dm block device on v2.6.31-rc5 x86 HVM.

This patch adds new functions core_scsi3_alloc_aptpl_registration() and core_scsi3_aptpl_reserve() for handling the incoming PR APTPL metadata from new target_core_mod/ConfigFS attributes. These allocate and pre-register the incoming persistent reservations metadata with target_core_mod, and then proceeds to execute the PR operations as other different configfs operations take place during normal target restart to bring up the fabric where the PR APTPL metadata for each target_core_mod defined storage objects is re-read.

This patch also adds core_scsi3_check_aptpl_registration() that is called by TCM Device Core code in core_dev_add_initiator_node_lun_acl() for making the final association between the APTPL metadata registrations+reservation when the
SCSI Initiator LUN ACL (eg: iSCSI Initiator LUN ACL with lio_node.py --addlunacl) is created during LIO-Target configfs bringup. It also adds [__]core_scsi3_update_aptpl_buf(), [__]core_scsi3_write_aptpl_to_file() for handling the writing out of metadata from the dynamically allocated at registration time t10_pr_registration_t->pr_aptpl_buf and out to struct file at /var/target/pr/aptpl_$T10_UNIT_SERIAL.

For PRIN service actions, it updates core_scsi3_pri_report_capabilities() to support APTPL_C and APTPL_A feature bits.

Here is what it looks like as sg_persist operations after 2x REGISTER, a RESERVE, then and PREEMPT_AND_ABORT, and REGISTER_AND_MOVE:

    target# tcm_node --prshowmd iblock_0/lvm_test0
    PR_REG_START: 0
    initiator_fabric=iSCSI
    initiator_node=iqn.1993-08.org.debian:01:2dadf92d0ef
    sa_res_key=1450770431
    res_holder=0
    res_all_tg_pt=0
    mapped_lun=0
    target_fabric=iSCSI
    target_node=iqn.2003-01.org.linux-iscsi.target.i686:sn.cff3eedbd2fd
    tpgt=1
    port_rtpi=1
    target_lun=0
    PR_REG_END: 0
    PR_REG_START: 1
    initiator_fabric=iSCSI
    initiator_node=iqn.1996-04.de.suse:01:1661f9ee7b5
    sa_res_key=1450770431
    res_holder=1
    res_type=05
    res_scope=00
    res_all_tg_pt=0
    mapped_lun=0
    target_fabric=iSCSI
    target_node=iqn.2003-01.org.linux-iscsi.target.i686:sn.e475ed6fcdd0
    tpgt=1
    port_rtpi=2
    target_lun=0
    PR_REG_END: 1

And from doing /etc/init.d/target restart at this point, the reload looks like:

target# tcm_node --pr iblock_0/lvm_test0
APTPL Bit Status: Activated
Ready to process PR APTPL metadata..
SPC-3 Reservation: iSCSI Initiator: iqn.1996-04.de.suse:01:1661f9ee7b5 SPC-3 Reservation: Single Target Port registration
0x00000002
SPC-3 Reservation: iSCSI Target Node Endpoint:
iqn.2003-01.org.linux-iscsi.target.i686:sn.e475ed6fcdd0
SPC-3 Reservation: Relative Port Identifer Tag: 2 iSCSI Portal Group Tag: 1 iSCSI Logical Unit: 0
SPC-3 PR Registrations:
iSCSI Node: iqn.1993-08.org.debian:01:2dadf92d0ef Key: 0x000000005678ffff
PRgen: 0x00000000
iSCSI Node: iqn.1996-04.de.suse:01:1661f9ee7b5 Key: 0x000000005678ffff PRgen:
0x00000001
SPC-3 Reservation Type: Write Exclusive Access, Registrants Only SPC3_PERSISTENT_RESERVATIONS

---
 drivers/target/target_core_device.c |    6 +-
 drivers/target/target_core_pr.c     |  602 +++++++++++++++++++++++++++++++++--
 include/target/target_core_base.h   |   18 +
 include/target/target_core_pr.h     |   10 +
 4 files changed, 605 insertions(+), 31 deletions(-)
drivers/target/target_core_device.c +5 -1
index fbdadb3..46cc450 100644
@@ -1380,7 +1380,11 @@ int core_dev_add_initiator_node_lun_acl(
 		TPG_TFO(tpg)->tpg_get_tag(tpg), unpacked_lun, lacl->mapped_lun,
 		(lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO",
 		lacl->initiatorname);
-
+	/*
+	 * Check to see if there are any existing persistent reservation APTPL
+	 * pre-registrations that need to be enabled for this LUN ACL..
+	 */
+	core_scsi3_check_aptpl_registration(lun->se_dev, tpg, lun, lacl);
 	return 0;
 }
 EXPORT_SYMBOL(core_dev_add_initiator_node_lun_acl);
drivers/target/target_core_pr.c +572 -30

835 lines not on this page · raw message

include/target/target_core_base.h +18 -0
index 580fa94..41aec3e 100644
@@ -72,6 +72,11 @@
 #define SNAP_GROUP_LEN				128
 /* Used for se_dev_snap_attrib->lvc_size */
 #define SNAP_LVC_LEN				32
+/* Used by t10_reservation_template_s->pr_[i,t]_port[] */
+#define PR_APTPL_MAX_IPORT_LEN			256
+#define PR_APTPL_MAX_TPORT_LEN			256
+/* Used by t10_reservation_template_s->pr_aptpl_buf_len */
+#define PR_APTPL_BUF_LEN			8192
 
 /* used by PSCSI and iBlock Transport drivers */
 #define READ_BLOCK_LEN          		6
@@ -291,11 +296,18 @@ typedef enum {
 struct se_cmd_s;
 
 typedef struct t10_pr_registration_s {
+	unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN]; /* Used during APTPL metadata reading */
+	unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN]; /* Used during APTPL metadata reading */
+	unsigned char *pr_aptpl_buf; /* For writing out live meta data */
+	u16 pr_aptpl_rpti;
+	u16 pr_reg_tpgt;
 	int pr_reg_all_tg_pt; /* Reservation effects all target ports */
+	int pr_reg_aptpl; /* Activate Persistence across Target Power Loss */
 	int pr_res_holder;
 	int pr_res_type;
 	int pr_res_scope;
 	u32 pr_res_mapped_lun;
+	u32 pr_aptpl_target_lun;
 	u32 pr_res_generation;
 	u64 pr_res_key;
 	atomic_t pr_res_holders;
@@ -304,17 +316,23 @@ typedef struct t10_pr_registration_s {
 	struct se_lun_s *pr_reg_tg_pt_lun;
 	struct list_head pr_reg_list;
 	struct list_head pr_reg_abort_list;
+	struct list_head pr_reg_aptpl_list;
 } ____cacheline_aligned t10_pr_registration_t;
 
 typedef struct t10_reservation_template_s {
 	/* Reservation effects all target ports */
 	int pr_all_tg_pt;
+	/* Activate Persistence across Target Power Loss enabled for SCSI device */
+	int pr_aptpl_active;
+	u32 pr_aptpl_buf_len;
 	u32 pr_generation;
 	t10_reservations_index_t res_type;
 	spinlock_t registration_lock;
+	spinlock_t aptpl_reg_lock;
 	/* Reservation holder when pr_all_tg_pt=1 */
 	struct se_node_acl_s *pr_res_holder;
 	struct list_head registration_list;
+	struct list_head aptpl_reg_list;
 	int (*t10_reservation_check)(struct se_cmd_s *, u32 *);
 	int (*t10_reserve)(struct se_cmd_s *);
 	int (*t10_release)(struct se_cmd_s *);
include/target/target_core_pr.h +10 -0
index 23d9e18..c791506 100644
@@ -40,8 +40,18 @@
 #define PR_TYPE_WRITE_EXCLUSIVE_ALLREG		0x07
 #define PR_TYPE_EXCLUSIVE_ACCESS_ALLREG		0x08
 
+#define PR_APTPL_MAX_IPORT_LEN			256
+#define PR_APTPL_MAX_TPORT_LEN			256
+
 extern struct kmem_cache *t10_pr_reg_cache;
 
+extern int core_scsi3_alloc_aptpl_registration(
+			struct t10_reservation_template_s *, u64,
+			unsigned char *, u32, unsigned char *, u16, u32,
+			int, int, u8);
+extern int core_scsi3_check_aptpl_registration(struct se_device_s *,
+			struct se_portal_group_s *, struct se_lun_s *,
+			struct se_lun_acl_s *);
 extern void core_scsi3_free_pr_reg_from_nacl(struct se_device_s *,
 					     struct se_node_acl_s *);
 extern void core_scsi3_free_all_registrations(struct se_device_s *);
Signature · 1 line
1.5.4.1