iscsi: iSCSI connection use spdk_scsi_dev_get_first/next_lun() to iterate LUNs
Use two new public APIs spdk_scsi_dev_get_first_lun() and spdk_scsi_dev_get_next_lun() to manage iSCSI LUNs by linked list and to traverse all LUNs of the SCSI device. By these changes, we can remove the dependency on the macro constant SPDK_SCSI_DEV_MAX_LUN from lib/iscsi. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I3237e7f887dd761d6812ed4313f87b6e7884ea29 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9610 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
153373a5e7
commit
356df80468
@ -248,7 +248,7 @@ iscsi_conn_construct(struct spdk_iscsi_portal *portal,
|
||||
TAILQ_INIT(&conn->queued_r2t_tasks);
|
||||
TAILQ_INIT(&conn->active_r2t_tasks);
|
||||
TAILQ_INIT(&conn->queued_datain_tasks);
|
||||
memset(&conn->luns, 0, sizeof(conn->luns));
|
||||
TAILQ_INIT(&conn->luns);
|
||||
|
||||
rc = spdk_sock_getaddr(sock, conn->target_addr, sizeof conn->target_addr, NULL,
|
||||
conn->initiator_addr, sizeof conn->initiator_addr, NULL);
|
||||
@ -424,11 +424,9 @@ end:
|
||||
}
|
||||
|
||||
static void
|
||||
iscsi_conn_close_lun(struct spdk_iscsi_conn *conn, int lun_id)
|
||||
iscsi_conn_close_lun(struct spdk_iscsi_conn *conn,
|
||||
struct spdk_iscsi_lun *iscsi_lun)
|
||||
{
|
||||
struct spdk_iscsi_lun *iscsi_lun;
|
||||
|
||||
iscsi_lun = conn->luns[lun_id];
|
||||
if (iscsi_lun == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -436,18 +434,20 @@ iscsi_conn_close_lun(struct spdk_iscsi_conn *conn, int lun_id)
|
||||
spdk_scsi_lun_free_io_channel(iscsi_lun->desc);
|
||||
spdk_scsi_lun_close(iscsi_lun->desc);
|
||||
spdk_poller_unregister(&iscsi_lun->remove_poller);
|
||||
|
||||
TAILQ_REMOVE(&conn->luns, iscsi_lun, tailq);
|
||||
|
||||
free(iscsi_lun);
|
||||
|
||||
conn->luns[lun_id] = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
iscsi_conn_close_luns(struct spdk_iscsi_conn *conn)
|
||||
{
|
||||
int i;
|
||||
struct spdk_iscsi_lun *iscsi_lun, *tmp;
|
||||
|
||||
for (i = 0; i < SPDK_SCSI_DEV_MAX_LUN; i++) {
|
||||
iscsi_conn_close_lun(conn, i);
|
||||
TAILQ_FOREACH_SAFE(iscsi_lun, &conn->luns, tailq, tmp) {
|
||||
iscsi_conn_close_lun(conn, iscsi_lun);
|
||||
}
|
||||
}
|
||||
|
||||
@ -492,12 +492,11 @@ iscsi_conn_remove_lun(void *ctx)
|
||||
struct spdk_iscsi_lun *iscsi_lun = ctx;
|
||||
struct spdk_iscsi_conn *conn = iscsi_lun->conn;
|
||||
struct spdk_scsi_lun *lun = iscsi_lun->lun;
|
||||
int lun_id = spdk_scsi_lun_get_id(lun);
|
||||
|
||||
if (!iscsi_conn_check_tasks_for_lun(conn, lun)) {
|
||||
return SPDK_POLLER_BUSY;
|
||||
}
|
||||
iscsi_conn_close_lun(conn, lun_id);
|
||||
iscsi_conn_close_lun(conn, iscsi_lun);
|
||||
return SPDK_POLLER_BUSY;
|
||||
}
|
||||
|
||||
@ -533,8 +532,7 @@ iscsi_conn_hotremove_lun(struct spdk_scsi_lun *lun, void *remove_ctx)
|
||||
}
|
||||
|
||||
static int
|
||||
iscsi_conn_open_lun(struct spdk_iscsi_conn *conn, int lun_id,
|
||||
struct spdk_scsi_lun *lun)
|
||||
iscsi_conn_open_lun(struct spdk_iscsi_conn *conn, struct spdk_scsi_lun *lun)
|
||||
{
|
||||
int rc;
|
||||
struct spdk_iscsi_lun *iscsi_lun;
|
||||
@ -560,7 +558,7 @@ iscsi_conn_open_lun(struct spdk_iscsi_conn *conn, int lun_id,
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn->luns[lun_id] = iscsi_lun;
|
||||
TAILQ_INSERT_TAIL(&conn->luns, iscsi_lun, tailq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -568,16 +566,12 @@ iscsi_conn_open_lun(struct spdk_iscsi_conn *conn, int lun_id,
|
||||
static void
|
||||
iscsi_conn_open_luns(struct spdk_iscsi_conn *conn)
|
||||
{
|
||||
int i, rc;
|
||||
int rc;
|
||||
struct spdk_scsi_lun *lun;
|
||||
|
||||
for (i = 0; i < SPDK_SCSI_DEV_MAX_LUN; i++) {
|
||||
lun = spdk_scsi_dev_get_lun(conn->dev, i);
|
||||
if (lun == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = iscsi_conn_open_lun(conn, i, lun);
|
||||
for (lun = spdk_scsi_dev_get_first_lun(conn->dev); lun != NULL;
|
||||
lun = spdk_scsi_dev_get_next_lun(lun)) {
|
||||
rc = iscsi_conn_open_lun(conn, lun);
|
||||
if (rc != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ struct spdk_iscsi_lun {
|
||||
struct spdk_scsi_lun *lun;
|
||||
struct spdk_scsi_lun_desc *desc;
|
||||
struct spdk_poller *remove_poller;
|
||||
TAILQ_ENTRY(spdk_iscsi_lun) tailq;
|
||||
};
|
||||
|
||||
struct spdk_iscsi_conn {
|
||||
@ -205,7 +206,7 @@ struct spdk_iscsi_conn {
|
||||
TAILQ_HEAD(active_r2t_tasks, spdk_iscsi_task) active_r2t_tasks;
|
||||
TAILQ_HEAD(queued_datain_tasks, spdk_iscsi_task) queued_datain_tasks;
|
||||
|
||||
struct spdk_iscsi_lun *luns[SPDK_SCSI_DEV_MAX_LUN];
|
||||
TAILQ_HEAD(, spdk_iscsi_lun) luns;
|
||||
|
||||
TAILQ_ENTRY(spdk_iscsi_conn) conn_link;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user