scst_sysfs branch: /targets/<target_driver_name> subdirectories and /targets/<target_name>/target subdirectory.
PATCH 1/1 scst_sysfs branch: /targets/<target_driver_name> subdirectories and /targets/<target_name>/target subdirectory.
Hi Vlad,
Here comes a patch that adds the target_driver_name subdirectories and target_name inside them when a target (like iscsi-scst) is added.
Some possible things that may be worth to comment.
* function names: I am not that good choosing functions name, so if
anyone disagree/don't like them, feel free to comment or suggest.
* Code duplication: You can see that functions likescst_create_scst_template_kobj and scst_create_tgt_kobj does almost the same thing. One possibility I see here is to have an create_general_kobj(kobj, patent_kobj) function to make it. It would avoid code to be duplicated but on the other hand the call side would possibly be less intuitive. Also, It will not be flexible if we need to make specific things (like create files or links) on the kobject directory. If anyone has something to tell about it, be my guess.
Regards,
Daniel Debonzi
scst.h +4 -0
@@ -757,6 +757,8 @@ struct scst_tgt_template {/* The pointer to the /proc directory entry */ struct proc_dir_entry *proc_tgt_root; +struct kobject *kobj;/* kobject for this struct. */ +/* Device number in /proc */ int proc_dev_num; };
@@ -958,6 +960,8 @@ struct scst_tgt {/* Name on the default security group ("Default_target_name") */ char *default_group_name; + +struct kobject *kobj;/* kobject for this struct. */ };/* Hash size and hash fn for hash based lun translation */
scst_main.c +15 -2
@@ -206,6 +206,10 @@ int __scst_register_target_template(stru goto out_err; } + res =scst_create_scst_template_kobj (vtt); +if (res) + goto out_err; +if (!vtt->no_proc_entry) { res =scst_build_proc_target_dir_entries (vtt);if (res <0 )
@@ -300,6 +304,7 @@ restart: out_up:mutex_unlock (&scst_mutex); +scst_destroy_scst_template_kobj (vtt);scst_cleanup_proc_target_dir_entries (vtt);TRACE_EXIT ();
@@ -360,8 +365,12 @@ struct scst_tgt *scst_register(struct sc rc =scst_build_proc_target_entries (tgt);if (rc <0 ) goto out_free_name; -else -list_add_tail (&tgt->tgt_list_entry, &vtt->tgt_list); + + rc =scst_create_tgt_kobj (tgt); +if (rc <0 ) + goto out_kobj_err; + +list_add_tail (&tgt->tgt_list_entry, &vtt->tgt_list);mutex_unlock (&scst_mutex);scst_resume_activity ();
@@ -373,6 +382,9 @@ out:TRACE_EXIT ();return tgt; +out_kobj_err: +scst_cleanup_proc_target_entries (tgt); + out_free_name:kfree (tgt->default_group_name);
@@ -440,6 +452,7 @@ again:list_del (&tgt->tgt_list_entry);scst_cleanup_proc_target_entries (tgt); +scst_destroy_scst_tgt_kobj (tgt);kfree (tgt->default_group_name);
scst_priv.h +4 -0
@@ -386,6 +386,10 @@ void scst_cleanup_proc_dev_handler_dir_e/* sysfs support */ int scst_sysfs_init (void );void scst_sysfs_cleanup (void ); +int scst_create_scst_template_kobj (struct scst_tgt_template *vtt); +void scst_destroy_scst_template_kobj (struct scst_tgt_template *vtt); +int scst_create_tgt_kobj (struct scst_tgt *tgt); +void scst_destroy_scst_tgt_kobj (struct scst_tgt *tgt);int scst_get_cdb_len (const uint8_t *cdb);
scst_sysfs.c +91 -15
168 lines not on this page · raw message