scsi: target: Add default fabric ops callouts

There are several callouts in target fabric ops that most of fabric drivers
fill with a function returning the same value.

Stop requiring such callouts to exist in the ops, fill them in TCM Core.

Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Link: https://lore.kernel.org/r/20230313181110.20566-2-d.bogdanov@yadro.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Dmitry Bogdanov 2023-03-13 21:10:59 +03:00 committed by Martin K. Petersen
parent fe15c26ee2
commit e5dc6e445c
1 changed files with 61 additions and 33 deletions

View File

@ -335,6 +335,29 @@ EXPORT_SYMBOL(target_undepend_item);
/*##############################################################################
// Start functions called by external Target Fabrics Modules
//############################################################################*/
static int target_disable_feature(struct se_portal_group *se_tpg)
{
return 0;
}
static u32 target_default_get_inst_index(struct se_portal_group *se_tpg)
{
return 1;
}
static u32 target_default_sess_get_index(struct se_session *se_sess)
{
return 0;
}
static void target_set_default_node_attributes(struct se_node_acl *se_acl)
{
}
static int target_default_get_cmd_state(struct se_cmd *se_cmd)
{
return 0;
}
static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
{
@ -362,46 +385,14 @@ static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
pr_err("Missing tfo->tpg_get_tag()\n");
return -EINVAL;
}
if (!tfo->tpg_check_demo_mode) {
pr_err("Missing tfo->tpg_check_demo_mode()\n");
return -EINVAL;
}
if (!tfo->tpg_check_demo_mode_cache) {
pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
return -EINVAL;
}
if (!tfo->tpg_check_demo_mode_write_protect) {
pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
return -EINVAL;
}
if (!tfo->tpg_check_prod_mode_write_protect) {
pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
return -EINVAL;
}
if (!tfo->tpg_get_inst_index) {
pr_err("Missing tfo->tpg_get_inst_index()\n");
return -EINVAL;
}
if (!tfo->release_cmd) {
pr_err("Missing tfo->release_cmd()\n");
return -EINVAL;
}
if (!tfo->sess_get_index) {
pr_err("Missing tfo->sess_get_index()\n");
return -EINVAL;
}
if (!tfo->write_pending) {
pr_err("Missing tfo->write_pending()\n");
return -EINVAL;
}
if (!tfo->set_default_node_attributes) {
pr_err("Missing tfo->set_default_node_attributes()\n");
return -EINVAL;
}
if (!tfo->get_cmd_state) {
pr_err("Missing tfo->get_cmd_state()\n");
return -EINVAL;
}
if (!tfo->queue_data_in) {
pr_err("Missing tfo->queue_data_in()\n");
return -EINVAL;
@ -447,8 +438,36 @@ static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
return 0;
}
static void target_set_default_ops(struct target_core_fabric_ops *tfo)
{
if (!tfo->tpg_check_demo_mode)
tfo->tpg_check_demo_mode = target_disable_feature;
if (!tfo->tpg_check_demo_mode_cache)
tfo->tpg_check_demo_mode_cache = target_disable_feature;
if (!tfo->tpg_check_demo_mode_write_protect)
tfo->tpg_check_demo_mode_write_protect = target_disable_feature;
if (!tfo->tpg_check_prod_mode_write_protect)
tfo->tpg_check_prod_mode_write_protect = target_disable_feature;
if (!tfo->tpg_get_inst_index)
tfo->tpg_get_inst_index = target_default_get_inst_index;
if (!tfo->sess_get_index)
tfo->sess_get_index = target_default_sess_get_index;
if (!tfo->set_default_node_attributes)
tfo->set_default_node_attributes = target_set_default_node_attributes;
if (!tfo->get_cmd_state)
tfo->get_cmd_state = target_default_get_cmd_state;
}
int target_register_template(const struct target_core_fabric_ops *fo)
{
struct target_core_fabric_ops *tfo;
struct target_fabric_configfs *tf;
int ret;
@ -461,10 +480,18 @@ int target_register_template(const struct target_core_fabric_ops *fo)
pr_err("%s: could not allocate memory!\n", __func__);
return -ENOMEM;
}
tfo = kzalloc(sizeof(struct target_core_fabric_ops), GFP_KERNEL);
if (!tfo) {
kfree(tf);
pr_err("%s: could not allocate memory!\n", __func__);
return -ENOMEM;
}
memcpy(tfo, fo, sizeof(*tfo));
target_set_default_ops(tfo);
INIT_LIST_HEAD(&tf->tf_list);
atomic_set(&tf->tf_access_cnt, 0);
tf->tf_ops = fo;
tf->tf_ops = tfo;
target_fabric_setup_cits(tf);
mutex_lock(&g_tf_lock);
@ -492,6 +519,7 @@ void target_unregister_template(const struct target_core_fabric_ops *fo)
*/
rcu_barrier();
kfree(t->tf_tpg_base_cit.ct_attrs);
kfree(t->tf_ops);
kfree(t);
return;
}