Re: [PATCH 13/18] nvmet: make TCP sectype settable via configfs

Hannes Reinecke
2023-03-30T17:37:20Z

On 3/30/23 18:07, Sagi Grimberg wrote:
>
>> Add a new configfs attribute 'addr_tsas' to make the TCP sectype
>> settable via configfs.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>   drivers/nvme/target/configfs.c | 67 ++++++++++++++++++++++++++++++++++
>>   1 file changed, 67 insertions(+)
>>
>> diff --git a/drivers/nvme/target/configfs.c
>> b/drivers/nvme/target/configfs.c
>> index 907143870da5..ca66ee6dc153 100644
>> --- a/drivers/nvme/target/configfs.c
>> +++ b/drivers/nvme/target/configfs.c
>> @@ -303,6 +303,11 @@ static void nvmet_port_init_tsas_rdma(struct
>> nvmet_port *port)
>>       port->disc_addr.tsas.rdma.cms = NVMF_RDMA_CMS_RDMA_CM;
>>   }
>> +static void nvmet_port_init_tsas_tcp(struct nvmet_port *port, int
>> sectype)
>> +{
>> +    port->disc_addr.tsas.tcp.sectype = sectype;
>> +}
>> +
>>   static ssize_t nvmet_addr_trtype_store(struct config_item *item,
>>           const char *page, size_t count)
>>   {
>> @@ -325,11 +330,72 @@ static ssize_t nvmet_addr_trtype_store(struct
>> config_item *item,
>>       port->disc_addr.trtype = nvmet_transport[i].type;
>>       if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA)
>>           nvmet_port_init_tsas_rdma(port);
>> +    else if (port->disc_addr.trtype == NVMF_TRTYPE_TCP)
>> +        nvmet_port_init_tsas_tcp(port, NVMF_TCP_SECTYPE_NONE);
>>       return count;
>>   }
>>   CONFIGFS_ATTR(nvmet_, addr_trtype);
>> +static const struct nvmet_type_name_map nvmet_addr_tsas_tcp[] = {
>> +    { NVMF_TCP_SECTYPE_NONE,    "none" },
>> +    { NVMF_TCP_SECTYPE_TLS13,    "tls1.3" },
>> +};
>> +
>> +static const struct nvmet_type_name_map nvmet_addr_tsas_rdma[] = {
>> +    { NVMF_RDMA_QPTYPE_CONNECTED,    "connected" },
>> +    { NVMF_RDMA_QPTYPE_DATAGRAM,    "datagram"  },
>> +};
>> +
>> +static ssize_t nvmet_addr_tsas_show(struct config_item *item,
>> +        char *page)
>> +{
>> +    struct nvmet_port *port = to_nvmet_port(item);
>> +    int i;
>> +
>> +    if (port->disc_addr.trtype == NVMF_TRTYPE_TCP) {
>> +        for (i = 0; i < ARRAY_SIZE(nvmet_addr_tsas_tcp); i++) {
>> +            if (port->disc_addr.tsas.tcp.sectype ==
>> nvmet_addr_tsas_tcp[i].type)
>> +                return sprintf(page, "%s\n",
>> nvmet_addr_tsas_tcp[i].name);
>> +        }
>> +        return sprintf(page, "reserved\n");
>
> What is reserved?
>
All other values?

>> +    } else if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA) {
>> +        for (i = 0; i < ARRAY_SIZE(nvmet_addr_tsas_rdma); i++) {
>> +            if (port->disc_addr.tsas.rdma.qptype ==
>> nvmet_addr_tsas_rdma[i].type)
>> +                return sprintf(page, "%s\n",
>> nvmet_addr_tsas_rdma[i].name);
>> +        }
>> +        return sprintf(page, "reserved\n");
>> +    }
>> +    return sprintf(page, "not required\n");
>> +}
>> +
>> +static ssize_t nvmet_addr_tsas_store(struct config_item *item,
>> +        const char *page, size_t count)
>> +{
>> +    struct nvmet_port *port = to_nvmet_port(item);
>> +    int i;
>> +
>> +    if (nvmet_is_port_enabled(port, __func__))
>> +        return -EACCES;
>> +
>> +    if (port->disc_addr.trtype != NVMF_TRTYPE_TCP)
>> +        return -EINVAL;
>> +
>> +    for (i = 0; i < ARRAY_SIZE(nvmet_addr_tsas_tcp); i++) {
>> +        if (sysfs_streq(page, nvmet_addr_tsas_tcp[i].name))
>> +            goto found;
>> +    }
>> +
>> +    pr_err("Invalid value '%s' for tsas\n", page);
>> +    return -EINVAL;
>> +
>> +found:
>> +    nvmet_port_init_tsas_tcp(port, nvmet_addr_tsas_tcp[i].type);
>> +    return count;
>> +}
>> +
>> +CONFIGFS_ATTR(nvmet_, addr_tsas);
>> +
>>   /*
>>    * Namespace structures & file operation functions below
>>    */
>> @@ -1741,6 +1807,7 @@ static struct configfs_attribute
>> *nvmet_port_attrs[] = {
>>       &nvmet_attr_addr_traddr,
>>       &nvmet_attr_addr_trsvcid,
>>       &nvmet_attr_addr_trtype,
>> +    &nvmet_attr_addr_tsas,
>>       &nvmet_attr_param_inline_data_size,
>>   #ifdef CONFIG_BLK_DEV_INTEGRITY
>>       &nvmet_attr_param_pi_enable,

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman