diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index 2d0da6dec..ff3e63983 100644 --- a/iscsi-scst/kernel/config.c +++ b/iscsi-scst/kernel/config.c @@ -672,12 +672,13 @@ static ssize_t iscsi_attr_store(struct kobject *kobj, res = -ENOMEM; goto out; } - memcpy(buffer, buf, count); buffer[count] = '\0'; tgt_attr = container_of(attr, struct iscsi_attr, attr); + TRACE_DBG("attr %s, buffer %s", tgt_attr->attr.attr.name, buffer); + res = iscsi_sysfs_send_event( (tgt_attr->target != NULL) ? tgt_attr->target->tid : 0, E_SET_ATTR_VALUE, tgt_attr->name, buffer, NULL); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 99ba7d649..63d74485f 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4072,15 +4072,20 @@ void scst_free_session(struct scst_session *sess) mutex_lock(&scst_mutex); + scst_sess_free_tgt_devs(sess); + + scst_sess_sysfs_del(sess); + + /* + * The lists delete must be after sysfs del. Otherwise it would break + * logic in scst_sess_sysfs_create() to avoid duplicate sysfs names. + */ + 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); - - scst_sess_sysfs_del(sess); - /* Called under lock to protect from too early tgt release */ wake_up_all(&sess->tgt->unreg_waitQ); diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 18af86441..3bed91df7 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -993,7 +993,7 @@ static int scst_process_tgt_enable_store(struct scst_tgt *tgt, bool enable) /* Tgt protected by kobject reference */ - TRACE_DBG("tgt%p, enable %d", tgt, enable); + TRACE_DBG("tgt %s, enable %d", tgt->tgt_name, enable); if (enable && (tgt->rel_tgt_id == 0)) { res = gen_relative_target_port_id(&tgt->rel_tgt_id); @@ -2341,6 +2341,7 @@ restart: list_for_each_entry(s, &sess->tgt->sess_list, sess_list_entry) { if (!sess->sess_kobj_ready) continue; + if (strcmp(name, kobject_name(&s->sess_kobj)) == 0) { if (s == sess) continue; @@ -2406,9 +2407,11 @@ void scst_sess_sysfs_del(struct scst_session *sess) TRACE_ENTRY(); - if (sess->sess_kobj_ready) + if (!sess->sess_kobj_ready) goto out; + TRACE_DBG("Deleting session %s", kobject_name(&sess->sess_kobj)); + kobject_del(&sess->sess_kobj); kobject_put(&sess->sess_kobj); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 873e462b8..2dd64f118 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -6251,7 +6251,7 @@ EXPORT_SYMBOL(scst_initiator_has_luns); static int scst_init_session(struct scst_session *sess) { - int res = 0, rc; + int res = 0; struct scst_cmd *cmd; struct scst_mgmt_cmd *mcmd, *tm; int mwake = 0; @@ -6284,14 +6284,11 @@ static int scst_init_session(struct scst_session *sess) sess->transport_id), sess->tgt->rel_tgt_id); } - /* Let's always create sysfs to simplify code */ - rc = scst_sess_sysfs_create(sess); - if (res == 0) - res = rc; + res = scst_sess_sysfs_create(sess); + if (res != 0) + goto failed; - rc = scst_sess_alloc_tgt_devs(sess); - if (res == 0) - res = rc; + res = scst_sess_alloc_tgt_devs(sess); failed: mutex_unlock(&scst_mutex);