target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: Dmitry Bogdanov <d.bogdanov@yadro.com>,
	Martin Petersen <martin.petersen@oracle.com>,
	target-devel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org, linux@yadro.com,
	Roman Bolshakov <r.bolshakov@yadro.com>
Subject: Re: [PATCH 2/7] scsi: target: core: Add RTPI field to target port
Date: Thu, 29 Sep 2022 17:26:10 -0500	[thread overview]
Message-ID: <6f4dba25-33af-b268-bf6f-541febf3c939@oracle.com> (raw)
In-Reply-To: <20220906154519.27487-3-d.bogdanov@yadro.com>

On 9/6/22 10:45 AM, Dmitry Bogdanov wrote:
> From: Roman Bolshakov <r.bolshakov@yadro.com>
> 
> SAM-5 4.6.5.2 (Relative Port Identifier attribute) defines the attribute
> as unique across SCSI target ports.
> 
> The change introduces RTPI attribute to se_portal group. The value is
> auto-incremented and unique across all SCSI target ports. It also limits
> number of SCSI target ports to 65535.
> 
> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
> ---
>  drivers/target/target_core_tpg.c  | 78 +++++++++++++++++++++++++++++--
>  include/target/target_core_base.h |  4 ++
>  2 files changed, 77 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
> index f0d38d77edcc..325ef439fb42 100644
> --- a/drivers/target/target_core_tpg.c
> +++ b/drivers/target/target_core_tpg.c
> @@ -31,6 +31,10 @@
>  #include "target_core_ua.h"
>  
>  extern struct se_device *g_lun0_dev;
> +static u16 g_tpg_count;
> +static u16 g_tpg_rtpi_counter = 1;
> +static LIST_HEAD(g_tpg_list);
> +static DEFINE_SPINLOCK(g_tpg_lock);
>  
>  /*	__core_tpg_get_initiator_node_acl():
>   *
> @@ -439,6 +443,57 @@ static void core_tpg_lun_ref_release(struct percpu_ref *ref)
>  	complete(&lun->lun_shutdown_comp);
>  }
>  
> +static int core_tpg_register_rtpi(struct se_portal_group *se_tpg)
> +{
> +	struct se_portal_group *tpg;
> +
> +	/*
> +	 * Allocate the next RELATIVE TARGET PORT IDENTIFIER.
> +	 * Here is the table from SPC-4 4.3.4:
> +	 *
> +	 *    Table 34 -- Relative target port identifier values
> +	 *
> +	 * Value		Description
> +	 * 0h			Reserved
> +	 * 1h			Relative port 1, historically known as port A
> +	 * 2h			Relative port 2, historically known as port B
> +	 * 3h to FFFFh		Relative port 3 through 65 535
> +	 */
> +	spin_lock(&g_tpg_lock);
> +
> +	if (g_tpg_count == 0xffff) {
> +		spin_unlock(&g_tpg_lock);
> +		pr_warn("Reached g_tpg_count == 0xffff\n");
> +		return -ENOSPC;
> +	}
> +again:
> +	se_tpg->tpg_rtpi = g_tpg_rtpi_counter++;
> +	if (!se_tpg->tpg_rtpi)
> +		goto again;
> +
> +	list_for_each_entry(tpg, &g_tpg_list, tpg_list) {
> +		/*
> +		 * Make sure RELATIVE TARGET PORT IDENTIFIER is unique
> +		 * for 16-bit wrap..
> +		 */
> +		if (se_tpg->tpg_rtpi == tpg->tpg_rtpi)
> +			goto again;
> +	}
> +	list_add(&se_tpg->tpg_list, &g_tpg_list);
> +	g_tpg_count++;
> +	spin_unlock(&g_tpg_lock);
> +

I think you could just use an ida.



  reply	other threads:[~2022-09-29 22:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 15:45 [PATCH 0/7] scsi: target: make RTPI an TPG identifier Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 1/7] scsi: target: core: Add cleanup sequence in core_tpg_register() Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 2/7] scsi: target: core: Add RTPI field to target port Dmitry Bogdanov
2022-09-29 22:26   ` Mike Christie [this message]
2022-09-29 23:57     ` Mike Christie
2022-10-04 16:11       ` Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 3/7] scsi: target: core: Use RTPI from " Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 4/7] scsi: target: core: Drop device-based RTPI Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 5/7] scsi: target: core: Add common port attributes Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 6/7] scsi: target: core: Add RTPI attribute for target port Dmitry Bogdanov
2022-09-30  0:03   ` Mike Christie
2022-10-04 16:12     ` Dmitry Bogdanov
2022-09-06 15:45 ` [PATCH 7/7] target: core: check RTPI uniquity for enabled TPG Dmitry Bogdanov
2022-09-30  0:02   ` Mike Christie
2022-10-01 16:19     ` michael.christie
2022-10-04 16:41       ` Dmitry Bogdanov
2022-10-04 16:37     ` Dmitry Bogdanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f4dba25-33af-b268-bf6f-541febf3c939@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=d.bogdanov@yadro.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@yadro.com \
    --cc=martin.petersen@oracle.com \
    --cc=r.bolshakov@yadro.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).