Commit f61d81e4 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

scsi: Add spdk_scsi_dev_get_first/next_lun() to traverse all LUNs



Add two public APIs spdk_scsi_dev_get_first_lun() and
spdk_scsi_dev_get_next_lun() to remove the dependency on the macro
constant SPDK_SCSI_DEV_MAX_LUN from lib/iscsi and lib/vhost.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I6546697f823fe9f4fa34e1161f5c7fa912dd2d59
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9608


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 266ef922
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ Added `spdk_nvme_ctrlr_get_opts` to retrieve the current controller options.

Updated DPDK submodule to DPDK 21.08.

### scsi

New functions, `spdk_scsi_dev_get_first_lun` and `spdk_scsi_dev_get_next_lun`
have been added to iterate LUNs of a SCSI device.

### util

The `spdk_fd_group_add` API now takes a `name` parameter.
+18 −0
Original line number Diff line number Diff line
@@ -229,6 +229,24 @@ int spdk_scsi_dev_get_id(const struct spdk_scsi_dev *dev);
 */
struct spdk_scsi_lun *spdk_scsi_dev_get_lun(struct spdk_scsi_dev *dev, int lun_id);

/**
 * Get the first logical unit of the given SCSI device.
 *
 * \param dev SCSI device.
 *
 * \return the first logical unit on success, or NULL if there is no logical unit.
 */
struct spdk_scsi_lun *spdk_scsi_dev_get_first_lun(struct spdk_scsi_dev *dev);

/**
 * Get the next logical unit of a SCSI device.
 *
 * \param lun Previous logical unit.
 *
 * \return the next logical unit of a SCSI device, or NULL if the prev_lun was the last.
 */
struct spdk_scsi_lun *spdk_scsi_dev_get_next_lun(struct spdk_scsi_lun *prev_lun);

/**
 * Check whether the SCSI device has any pending task.
 *
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 4
SO_MINOR := 0
SO_MINOR := 1

C_SRCS = dev.c lun.c port.c scsi.c scsi_bdev.c scsi_pr.c scsi_rpc.c task.c
LIBNAME = scsi
+39 −0
Original line number Diff line number Diff line
@@ -436,6 +436,45 @@ spdk_scsi_dev_get_lun(struct spdk_scsi_dev *dev, int lun_id)
	}
}

struct spdk_scsi_lun *
spdk_scsi_dev_get_first_lun(struct spdk_scsi_dev *dev)
{
	struct spdk_scsi_lun *lun;
	int lun_id;

	for (lun_id = 0; lun_id < SPDK_SCSI_DEV_MAX_LUN; lun_id++) {
		lun = dev->lun[lun_id];
		if (lun != NULL && !spdk_scsi_lun_is_removing(lun)) {
			return lun;
		}
	}

	return NULL;
}

struct spdk_scsi_lun *
spdk_scsi_dev_get_next_lun(struct spdk_scsi_lun *prev_lun)
{
	struct spdk_scsi_dev *dev;
	struct spdk_scsi_lun *lun;
	int lun_id;

	if (prev_lun == NULL) {
		return NULL;
	}

	dev = prev_lun->dev;

	for (lun_id = prev_lun->id + 1; lun_id < SPDK_SCSI_DEV_MAX_LUN; lun_id++) {
		lun = dev->lun[lun_id];
		if (lun != NULL && !spdk_scsi_lun_is_removing(lun)) {
			return lun;
		}
	}

	return NULL;
}

bool
spdk_scsi_dev_has_pending_tasks(const struct spdk_scsi_dev *dev,
				const struct spdk_scsi_port *initiator_port)
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
	spdk_scsi_dev_get_name;
	spdk_scsi_dev_get_id;
	spdk_scsi_dev_get_lun;
	spdk_scsi_dev_get_first_lun;
	spdk_scsi_dev_get_next_lun;
	spdk_scsi_dev_has_pending_tasks;
	spdk_scsi_dev_destruct;
	spdk_scsi_dev_queue_mgmt_task;
Loading