Skip to contentSkip to conversation

: Show sessions for a target on sysfs; sysfs interface to add luns to a given target.

PATCH New Daniel Debonzi 1 participant 1 message Jun 16, 2009 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Show sessions for a target on sysfs; sysfs interface to add luns to a given target.

The patch below show created sessions for a target on /sys/kernel/scst_tgt/targets/<target_driver_name>/<target>/session and allow creation of default LUNs (tgt->default_acg) to the target using targets/<target_driver_name>/<target>/luns/mgmt

please review.

---

include/scst.h   |    7
src/scst_lib.c   |   26 ---
src/scst_main.c  |   11 +
src/scst_priv.h  |    3
src/scst_sysfs.c |  387 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
src/scst_targ.c  |    7
6 files changed, 408 insertions(+), 33 deletions(-)
include/scst.h +7 -0
Index: scst/include/scst.h
===================================================================
@@ -931,6 +931,8 @@ struct scst_tgt {
 
 	struct scst_tgt_template *tgtt;	/* corresponding target template */
 
+	struct scst_acg *default_acg; /* The default acg for this target. */
+
 	/*
 	 * Maximum SG table size. Needed here, since different cards on the
 	 * same target template can have different SG table limitations.
@@ -1046,6 +1048,8 @@ struct scst_session {
 	/* Used if scst_unregister_session() called in wait mode */
 	struct completion *shutdown_compl;
 
+	struct kobject sess_kobj; /* kobject for this struct */
+
 	/*
 	 * Functions and data for user callbacks from scst_register_session()
 	 * and scst_unregister_session()
@@ -1631,6 +1635,9 @@ struct scst_acg_dev {
 
 	/* list entry in acg->acg_dev_list */
 	struct list_head acg_dev_list_entry;
+
+	/* kobject for this structure. */
+	struct kobject acg_dev_kobj;
 };
 
 /*
src/scst_main.c +10 -1
Index: scst/src/scst_main.c
===================================================================
@@ -394,9 +394,13 @@ struct scst_tgt *scst_register(struct sc
 			SCST_DEFAULT_TGT_NAME_SUFFIX, tgt_num++);
 	}
 
+	tgt->default_acg = scst_alloc_add_acg(target_name);
+	if (tgt->default_acg == NULL)
+		goto out_free_tgt_name;
+
 	rc = scst_build_proc_target_entries(tgt);
 	if (rc < 0)
-		goto out_free_tgt_name;
+		goto out_free_acg;
 
 	rc = scst_create_tgt_sysfs(tgt);
 	if (rc < 0)
@@ -422,6 +426,9 @@ out_clean_proc:
 out_free_tgt_name:
 	kfree(tgt->tgt_name);
 
+out_free_acg:
+	scst_destroy_acg(tgt->default_acg);
+
 out_free_def_name:
 	kfree(tgt->default_group_name);
 
@@ -499,6 +506,8 @@ again:
 	kfree(tgt->tgt_name);
 	kfree(tgt->default_group_name);
 
+	scst_destroy_acg(tgt->default_acg);
+
 	del_timer_sync(&tgt->retry_timer);
 
 	scst_cleanup_tgt_sysfs_put(tgt);
src/scst_priv.h +3 -0
Index: scst/src/scst_priv.h
===================================================================
@@ -291,6 +291,7 @@ struct scst_acg *scst_alloc_add_acg(cons
 int scst_destroy_acg(struct scst_acg *acg);
 
 int scst_sess_alloc_tgt_devs(struct scst_session *sess);
+void scst_sess_free_tgt_devs(struct scst_session *sess);
 void scst_nexus_loss(struct scst_tgt_dev *tgt_dev, bool queue_UA);
 
 int scst_acg_add_dev(struct scst_acg *acg, struct scst_device *dev,
@@ -390,6 +391,8 @@ int scst_create_tgtt_sysfs(struct scst_t
 void scst_cleanup_tgtt_sysfs(struct scst_tgt_template *vtt);
 int scst_create_tgt_sysfs(struct scst_tgt *tgt);
 void scst_cleanup_tgt_sysfs_put(struct scst_tgt *tgt);
+int scst_create_sess_sysfs(struct scst_session *sess);
+void scst_cleanup_sess_sysfs_put(struct scst_session *session);
 int scst_create_sgv_sysfs(struct sgv_pool *pool);
 void scst_cleanup_sgv_sysfs_put(struct sgv_pool *pool);
 
src/scst_lib.c +3 -23
Index: scst/src/scst_lib.c
===================================================================
@@ -45,7 +45,6 @@ static void scst_alloc_set_UA(struct scs
 	const uint8_t *sense, int sense_len, int flags);
 static void scst_free_all_UA(struct scst_tgt_dev *tgt_dev);
 static void scst_release_space(struct scst_cmd *cmd);
-static void scst_sess_free_tgt_devs(struct scst_session *sess);
 static void scst_unblock_cmds(struct scst_device *dev);
 
 #ifdef CONFIG_SCST_DEBUG_TM
@@ -925,12 +924,7 @@ static void scst_free_acg_dev(struct scs
 {
 	TRACE_ENTRY();
 
-	TRACE_DBG("Removing acg_dev %p from acg_dev_list and dev_acg_dev_list",
-		acg_dev);
-	list_del(&acg_dev->acg_dev_list_entry);
-	list_del(&acg_dev->dev_acg_dev_list_entry);
-
-	kmem_cache_free(scst_acgd_cachep, acg_dev);
+	kobject_put(&acg_dev->acg_dev_kobj);
 
 	TRACE_EXIT();
 	return;
@@ -1314,7 +1308,7 @@ out_free:
  * scst_mutex supposed to be held, there must not be parallel activity in this
  * session.
  */
-static void scst_sess_free_tgt_devs(struct scst_session *sess)
+void scst_sess_free_tgt_devs(struct scst_session *sess)
 {
 	int i;
 	struct scst_tgt_dev *tgt_dev, *t;
@@ -1890,21 +1884,7 @@ void scst_free_session(struct scst_sessi
 {
 	TRACE_ENTRY();
 
-	mutex_lock(&scst_mutex);
-
-	TRACE_DBG("Removing sess %p from the list", sess);
-	list_del(&sess->sess_list_entry);
-	TRACE_DBG("Removing session %p from acg %s", sess, sess->acg->acg_name);
-	list_del(&sess->acg_sess_list_entry);
-
-	scst_sess_free_tgt_devs(sess);
-
-	wake_up_all(&sess->tgt->unreg_waitQ);
-
-	mutex_unlock(&scst_mutex);
-
-	kfree(sess->initiator_name);
-	kmem_cache_free(scst_sess_cachep, sess);
+	scst_cleanup_sess_sysfs_put(sess);
 
 	TRACE_EXIT();
 	return;
src/scst_sysfs.c +379 -8

466 lines not on this page · raw message

src/scst_targ.c +6 -1
Index: scst/src/scst_targ.c
===================================================================
@@ -5288,12 +5288,13 @@ static int scst_init_session(struct scst
 
 	mutex_lock(&scst_mutex);
 
+/* 	debonzi: Not fully implemented. */
 	if (sess->initiator_name)
 		acg = scst_find_acg(sess->initiator_name);
 	if ((acg == NULL) && (sess->tgt->default_group_name != NULL))
 		acg = scst_find_acg_by_name(sess->tgt->default_group_name);
 	if (acg == NULL)
-		acg = scst_default_acg;
+		acg = sess->tgt->default_acg;
 
 	PRINT_INFO("Using security group \"%s\" for initiator \"%s\"",
 		acg->acg_name, sess->initiator_name);
@@ -5355,6 +5356,10 @@ restart:
 			&scst_active_mgmt_cmd_list);
 		mwake = 1;
 	}
+
+	if (res == 0)
+		res = scst_create_sess_sysfs(sess);
+
 	spin_unlock(&scst_mcmd_lock);
 	sess->init_phase = SCST_SESS_IPH_READY;
 	spin_unlock_irq(&sess->sess_list_lock);