Tony Asleson
2014-06-26 23:08:18 UTC
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 17 ++++++
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 17 ++++++
c_binding/lsm_mgmt.cpp | 56 +++++++++++++++++++
c_binding/lsm_plugin_ipc.cpp | 38 +++++++++++++
plugin/simc/simc_lsmplugin.c | 62 +++++++++++++++++++++-
test/tester.c | 35 ++++++++++++
6 files changed, 224 insertions(+), 1 deletion(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index 0a90de3..764b70f 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -908,6 +908,23 @@ extern "C" {
int LSM_DLL_EXPORT lsm_nfs_export_delete( lsm_connect *c, lsm_nfs_export *e,
lsm_flag flags );
+/**
+ * Retrieve a list of target ports
+ * @param[in] c Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param[out] target_ports Array of target ports
+ * @param[out] count Number of target ports
+ * @param[in] flags Reserved, set to 0
+ * @return LSM_ERR_OK on success else error reason
+ */
+ int LSM_DLL_EXPORT lsm_target_port_list(lsm_connect *c,
+ const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_ports[],
+ uint32_t *count,
+ lsm_flag flags);
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index bfc08e5..8d96be2 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -214,6 +214,22 @@ typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, const char *search_key,
uint32_t *count, lsm_flag flags);
/**
+ * Retrieve a list of target ports.
+ * @param[in] c Valid lsm plugin-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
+ * @parma[out] target_port_array Array of target port pointers
+ * @param[out] count Number of target ports
+ * @param[in] flags Reserved
+ * @return LSM_ERR_OK, else error reason
+ */
+typedef int (*lsm_plug_target_port_list)( lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_port_array[],
+ uint32_t *count, lsm_flag flags);
+
+/**
* Create a pool.
* @param[in] c Valid lsm plug-in pointer
* @param[in] system System
@@ -841,6 +857,7 @@ struct lsm_san_ops_v1 {
lsm_plug_access_groups_granted_to_volume ag_granted_to_vol; /**< access groups granted to a volume */
lsm_plug_volume_child_dependency vol_child_depends; /**< volume child dependencies */
lsm_plug_volume_child_dependency_delete vol_child_depends_rm; /**<Callback to remove volume child dependencies */
+ lsm_plug_target_port_list target_port_list; /**< Callback to get list of target ports */
};
/** \struct lsm_fs_ops_v1
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 0ad8597..9b14bef 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -49,6 +49,9 @@ static const char * const NFS_EXPORT_SEARCH_KEYS[] = {"id", "fs_id"};
static const char * const ACCESS_GROUP_SEARCH_KEYS[] = {"id", "system_id"};
#define ACCESS_GROUP_SEARCH_KEYS_COUNT COUNT_OF(ACCESS_GROUP_SEARCH_KEYS)
+static const char * const TARGET_PORT_SEARCH_KEYS[] = {"id", "system_id"};
+#define TARGET_PORT_SEARCH_KEYS_COUNT COUNT_OF(TARGET_PORT_SEARCH_KEYS)
+
/**
* Common code to validate and initialize the connection.
*/
@@ -725,6 +728,59 @@ int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,
return rc;
}
+int lsm_target_port_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_ports[],
+ uint32_t *count,
+ lsm_flag flags)
+{
+ int rc = LSM_ERR_OK;
+ CONN_SETUP(c);
+
+ if( !target_ports || !count || CHECK_RP(target_ports )) {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+
+ try {
+ std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value,
+ TARGET_PORT_SEARCH_KEYS,
+ TARGET_PORT_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "target_ports", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> tp = response.asArray();
+
+ *count = tp.size();
+
+ if( tp.size() ) {
+ *target_ports = lsm_target_port_record_array_alloc(tp.size());
+
+ for( size_t i = 0; i < tp.size(); ++i ) {
+ (*target_ports)[i] = value_to_target_port(tp[i]);
+ }
+ }
+ }
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_INTERNAL_ERROR, "Unexpected type",
+ ve.what());
+ if( *target_ports && *count ) {
+ lsm_target_port_record_array_free(*target_ports, *count);
+ *target_ports = NULL;
+ *count = 0;
+ }
+ }
+ return rc;
+}
+
static int get_volume_array(lsm_connect *c, int rc, Value &response,
lsm_volume **volumes[], uint32_t *count)
{
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 8be63b0..ae9b880 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -29,6 +29,7 @@
#include "libstoragemgmt/libstoragemgmt_snapshot.h"
#include "libstoragemgmt/libstoragemgmt_nfsexport.h"
#include "libstoragemgmt/libstoragemgmt_plug_interface.h"
+#include "libstoragemgmt/libstoragemgmt_targetport.h"
#include "libstoragemgmt/libstoragemgmt_volumes.h"
#include "libstoragemgmt/libstoragemgmt_pool.h"
#include <errno.h>
@@ -506,6 +507,42 @@ static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
return rc;
}
+static int handle_target_ports(lsm_plugin_ptr p, Value ¶ms, Value &response)
+{
+ int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
+
+ if( p && p->san_ops && p->san_ops->target_port_list ) {
+ lsm_target_port **target_ports = NULL;
+ uint32_t count = 0;
+
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
+ rc = p->san_ops->target_port_list(p, key, val, &target_ports, &count,
+ LSM_FLAG_GET_VALUE(params));
+ if( LSM_ERR_OK == rc) {
+ std::vector<Value> result;
+
+ for( uint32_t i = 0; i < count; ++i ) {
+ result.push_back(target_port_to_value(target_ports[i]));
+ }
+
+ lsm_target_port_record_array_free(target_ports, count);
+ target_ports = NULL;
+ response = Value(result);
+ }
+ free(key);
+ free(val);
+ } else {
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+ }
+ }
+ return rc;
+}
+
static int handle_pool_create(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
@@ -2239,6 +2276,7 @@ static std::map<std::string,handler> dispatch = static_map<std::string,handler>
("pool_create_from_disks", handle_pool_create_from_disks)
("pool_create_from_pool", handle_pool_create_from_pool)
("pool_delete", handle_pool_delete)
+ ("target_ports", handle_target_ports)
("time_out_set", handle_set_time_out)
("plugin_unregister", handle_unregister)
("plugin_register", handle_register)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 065dc61..a40fac1 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <openssl/md5.h>
+#include "libstoragemgmt/libstoragemgmt_targetport.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -593,6 +595,63 @@ static int list_disks(lsm_plugin_ptr c, const char *search_key,
return rc;
}
+static int list_targets(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_target_port **tp[],
+ uint32_t *count, lsm_flag flags)
+{
+ uint32_t i = 0;
+ const char p0[] = "50:0a:09:86:99:4b:8d:c5";
+ const char p1[] = "50:0a:09:86:99:4b:8d:c6";
+ int rc = LSM_ERR_OK;
+
+ *count = 5;
+ *tp = lsm_target_port_record_array_alloc(*count);
+
+ if( *tp ) {
+ (*tp)[0] = lsm_target_port_record_alloc("TGT_PORT_ID_01",
+ LSM_PORT_TYPE_FC, p0, p0, p0,
+ "FC_a_0b", sys_id, NULL);
+
+ (*tp)[1] = lsm_target_port_record_alloc("TGT_PORT_ID_02",
+ LSM_PORT_TYPE_FCOE, p1, p1, p1,
+ "FC_a_0c", sys_id, NULL);
+
+ (*tp)[2] = lsm_target_port_record_alloc("TGT_PORT_ID_03",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "sim-iscsi-tgt-3.example.com:3260",
+ "a4:4e:31:47:f4:e0",
+ "iSCSI_c_0d", sys_id, NULL);
+
+ (*tp)[3] = lsm_target_port_record_alloc("TGT_PORT_ID_04",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "10.0.0.1:3260",
+ "a4:4e:31:47:f4:e1",
+ "iSCSI_c_0e", sys_id, NULL);
+
+ (*tp)[4] = lsm_target_port_record_alloc("TGT_PORT_ID_05",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "[2001:470:1f09:efe:a64e:31ff::1]:3260",
+ "a4:4e:31:47:f4:e1",
+ "iSCSI_c_0e", sys_id, NULL);
+
+ for( i = 0; i < *count; ++i ) {
+ if ( !(*tp)[i] ) {
+ rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
+ lsm_target_port_record_array_free(*tp, *count);
+ *count = 0;
+ break;
+ }
+ }
+ } else {
+ rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
+ *count = 0;
+ }
+ return rc;
+}
+
static uint64_t pool_allocate(lsm_pool *p, uint64_t size)
{
uint64_t rounded_size = 0;
@@ -1517,7 +1576,8 @@ static struct lsm_san_ops_v1 san_ops = {
vol_accessible_by_ag,
ag_granted_to_volume,
volume_dependency,
- volume_dependency_rm
+ volume_dependency_rm,
+ list_targets
};
diff --git a/test/tester.c b/test/tester.c
index d19333f..35aac6a 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2838,6 +2838,40 @@ START_TEST(test_search_fs)
}
END_TEST
+START_TEST(test_target_ports)
+{
+ lsm_target_port **tp = NULL;
+ uint32_t count = 0;
+ uint32_t i = 0;
+ int rc = 0;
+
+
+ rc = lsm_target_port_list(c, NULL, NULL, &tp, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_target_port_list %d", rc);
+
+ if( LSM_ERR_OK != rc ) {
+ dump_error(lsm_error_last_get(c));
+ }
+
+ if( LSM_ERR_OK == rc ) {
+ for( i = 0; i < count; ++i ) {
+ printf("%s - %d - %s - %s - %s - %s - %s\n",
+ lsm_target_port_id_get(tp[i]),
+ lsm_target_port_type_get(tp[i]),
+ lsm_target_port_service_address_get(tp[i]),
+ lsm_target_port_network_address_get(tp[i]),
+ lsm_target_port_physical_address_get(tp[i]),
+ lsm_target_port_physical_name_get(tp[i]),
+ lsm_target_port_system_id_get(tp[i]));
+ }
+
+ rc = lsm_target_port_record_array_free(tp, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_target_port_record_array_free %d", rc);
+ }
+
+}
+END_TEST
+
Suite * lsm_suite(void)
{
Suite *s = suite_create("libStorageMgmt");
@@ -2845,6 +2879,7 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
+ tcase_add_test(basic, test_target_ports);
tcase_add_test(basic, test_search_fs);
tcase_add_test(basic, test_search_access_groups);
tcase_add_test(basic, test_search_disks);
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 17 ++++++
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 17 ++++++
c_binding/lsm_mgmt.cpp | 56 +++++++++++++++++++
c_binding/lsm_plugin_ipc.cpp | 38 +++++++++++++
plugin/simc/simc_lsmplugin.c | 62 +++++++++++++++++++++-
test/tester.c | 35 ++++++++++++
6 files changed, 224 insertions(+), 1 deletion(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index 0a90de3..764b70f 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -908,6 +908,23 @@ extern "C" {
int LSM_DLL_EXPORT lsm_nfs_export_delete( lsm_connect *c, lsm_nfs_export *e,
lsm_flag flags );
+/**
+ * Retrieve a list of target ports
+ * @param[in] c Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param[out] target_ports Array of target ports
+ * @param[out] count Number of target ports
+ * @param[in] flags Reserved, set to 0
+ * @return LSM_ERR_OK on success else error reason
+ */
+ int LSM_DLL_EXPORT lsm_target_port_list(lsm_connect *c,
+ const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_ports[],
+ uint32_t *count,
+ lsm_flag flags);
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index bfc08e5..8d96be2 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -214,6 +214,22 @@ typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, const char *search_key,
uint32_t *count, lsm_flag flags);
/**
+ * Retrieve a list of target ports.
+ * @param[in] c Valid lsm plugin-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
+ * @parma[out] target_port_array Array of target port pointers
+ * @param[out] count Number of target ports
+ * @param[in] flags Reserved
+ * @return LSM_ERR_OK, else error reason
+ */
+typedef int (*lsm_plug_target_port_list)( lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_port_array[],
+ uint32_t *count, lsm_flag flags);
+
+/**
* Create a pool.
* @param[in] c Valid lsm plug-in pointer
* @param[in] system System
@@ -841,6 +857,7 @@ struct lsm_san_ops_v1 {
lsm_plug_access_groups_granted_to_volume ag_granted_to_vol; /**< access groups granted to a volume */
lsm_plug_volume_child_dependency vol_child_depends; /**< volume child dependencies */
lsm_plug_volume_child_dependency_delete vol_child_depends_rm; /**<Callback to remove volume child dependencies */
+ lsm_plug_target_port_list target_port_list; /**< Callback to get list of target ports */
};
/** \struct lsm_fs_ops_v1
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 0ad8597..9b14bef 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -49,6 +49,9 @@ static const char * const NFS_EXPORT_SEARCH_KEYS[] = {"id", "fs_id"};
static const char * const ACCESS_GROUP_SEARCH_KEYS[] = {"id", "system_id"};
#define ACCESS_GROUP_SEARCH_KEYS_COUNT COUNT_OF(ACCESS_GROUP_SEARCH_KEYS)
+static const char * const TARGET_PORT_SEARCH_KEYS[] = {"id", "system_id"};
+#define TARGET_PORT_SEARCH_KEYS_COUNT COUNT_OF(TARGET_PORT_SEARCH_KEYS)
+
/**
* Common code to validate and initialize the connection.
*/
@@ -725,6 +728,59 @@ int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,
return rc;
}
+int lsm_target_port_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_target_port **target_ports[],
+ uint32_t *count,
+ lsm_flag flags)
+{
+ int rc = LSM_ERR_OK;
+ CONN_SETUP(c);
+
+ if( !target_ports || !count || CHECK_RP(target_ports )) {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+
+ try {
+ std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value,
+ TARGET_PORT_SEARCH_KEYS,
+ TARGET_PORT_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "target_ports", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> tp = response.asArray();
+
+ *count = tp.size();
+
+ if( tp.size() ) {
+ *target_ports = lsm_target_port_record_array_alloc(tp.size());
+
+ for( size_t i = 0; i < tp.size(); ++i ) {
+ (*target_ports)[i] = value_to_target_port(tp[i]);
+ }
+ }
+ }
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_INTERNAL_ERROR, "Unexpected type",
+ ve.what());
+ if( *target_ports && *count ) {
+ lsm_target_port_record_array_free(*target_ports, *count);
+ *target_ports = NULL;
+ *count = 0;
+ }
+ }
+ return rc;
+}
+
static int get_volume_array(lsm_connect *c, int rc, Value &response,
lsm_volume **volumes[], uint32_t *count)
{
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 8be63b0..ae9b880 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -29,6 +29,7 @@
#include "libstoragemgmt/libstoragemgmt_snapshot.h"
#include "libstoragemgmt/libstoragemgmt_nfsexport.h"
#include "libstoragemgmt/libstoragemgmt_plug_interface.h"
+#include "libstoragemgmt/libstoragemgmt_targetport.h"
#include "libstoragemgmt/libstoragemgmt_volumes.h"
#include "libstoragemgmt/libstoragemgmt_pool.h"
#include <errno.h>
@@ -506,6 +507,42 @@ static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
return rc;
}
+static int handle_target_ports(lsm_plugin_ptr p, Value ¶ms, Value &response)
+{
+ int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
+
+ if( p && p->san_ops && p->san_ops->target_port_list ) {
+ lsm_target_port **target_ports = NULL;
+ uint32_t count = 0;
+
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
+ rc = p->san_ops->target_port_list(p, key, val, &target_ports, &count,
+ LSM_FLAG_GET_VALUE(params));
+ if( LSM_ERR_OK == rc) {
+ std::vector<Value> result;
+
+ for( uint32_t i = 0; i < count; ++i ) {
+ result.push_back(target_port_to_value(target_ports[i]));
+ }
+
+ lsm_target_port_record_array_free(target_ports, count);
+ target_ports = NULL;
+ response = Value(result);
+ }
+ free(key);
+ free(val);
+ } else {
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+ }
+ }
+ return rc;
+}
+
static int handle_pool_create(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
@@ -2239,6 +2276,7 @@ static std::map<std::string,handler> dispatch = static_map<std::string,handler>
("pool_create_from_disks", handle_pool_create_from_disks)
("pool_create_from_pool", handle_pool_create_from_pool)
("pool_delete", handle_pool_delete)
+ ("target_ports", handle_target_ports)
("time_out_set", handle_set_time_out)
("plugin_unregister", handle_unregister)
("plugin_register", handle_register)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 065dc61..a40fac1 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <openssl/md5.h>
+#include "libstoragemgmt/libstoragemgmt_targetport.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -593,6 +595,63 @@ static int list_disks(lsm_plugin_ptr c, const char *search_key,
return rc;
}
+static int list_targets(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_target_port **tp[],
+ uint32_t *count, lsm_flag flags)
+{
+ uint32_t i = 0;
+ const char p0[] = "50:0a:09:86:99:4b:8d:c5";
+ const char p1[] = "50:0a:09:86:99:4b:8d:c6";
+ int rc = LSM_ERR_OK;
+
+ *count = 5;
+ *tp = lsm_target_port_record_array_alloc(*count);
+
+ if( *tp ) {
+ (*tp)[0] = lsm_target_port_record_alloc("TGT_PORT_ID_01",
+ LSM_PORT_TYPE_FC, p0, p0, p0,
+ "FC_a_0b", sys_id, NULL);
+
+ (*tp)[1] = lsm_target_port_record_alloc("TGT_PORT_ID_02",
+ LSM_PORT_TYPE_FCOE, p1, p1, p1,
+ "FC_a_0c", sys_id, NULL);
+
+ (*tp)[2] = lsm_target_port_record_alloc("TGT_PORT_ID_03",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "sim-iscsi-tgt-3.example.com:3260",
+ "a4:4e:31:47:f4:e0",
+ "iSCSI_c_0d", sys_id, NULL);
+
+ (*tp)[3] = lsm_target_port_record_alloc("TGT_PORT_ID_04",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "10.0.0.1:3260",
+ "a4:4e:31:47:f4:e1",
+ "iSCSI_c_0e", sys_id, NULL);
+
+ (*tp)[4] = lsm_target_port_record_alloc("TGT_PORT_ID_05",
+ LSM_PORT_TYPE_ISCSI,
+ "iqn.1986-05.com.example:sim-tgt-03",
+ "[2001:470:1f09:efe:a64e:31ff::1]:3260",
+ "a4:4e:31:47:f4:e1",
+ "iSCSI_c_0e", sys_id, NULL);
+
+ for( i = 0; i < *count; ++i ) {
+ if ( !(*tp)[i] ) {
+ rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
+ lsm_target_port_record_array_free(*tp, *count);
+ *count = 0;
+ break;
+ }
+ }
+ } else {
+ rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
+ *count = 0;
+ }
+ return rc;
+}
+
static uint64_t pool_allocate(lsm_pool *p, uint64_t size)
{
uint64_t rounded_size = 0;
@@ -1517,7 +1576,8 @@ static struct lsm_san_ops_v1 san_ops = {
vol_accessible_by_ag,
ag_granted_to_volume,
volume_dependency,
- volume_dependency_rm
+ volume_dependency_rm,
+ list_targets
};
diff --git a/test/tester.c b/test/tester.c
index d19333f..35aac6a 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2838,6 +2838,40 @@ START_TEST(test_search_fs)
}
END_TEST
+START_TEST(test_target_ports)
+{
+ lsm_target_port **tp = NULL;
+ uint32_t count = 0;
+ uint32_t i = 0;
+ int rc = 0;
+
+
+ rc = lsm_target_port_list(c, NULL, NULL, &tp, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_target_port_list %d", rc);
+
+ if( LSM_ERR_OK != rc ) {
+ dump_error(lsm_error_last_get(c));
+ }
+
+ if( LSM_ERR_OK == rc ) {
+ for( i = 0; i < count; ++i ) {
+ printf("%s - %d - %s - %s - %s - %s - %s\n",
+ lsm_target_port_id_get(tp[i]),
+ lsm_target_port_type_get(tp[i]),
+ lsm_target_port_service_address_get(tp[i]),
+ lsm_target_port_network_address_get(tp[i]),
+ lsm_target_port_physical_address_get(tp[i]),
+ lsm_target_port_physical_name_get(tp[i]),
+ lsm_target_port_system_id_get(tp[i]));
+ }
+
+ rc = lsm_target_port_record_array_free(tp, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_target_port_record_array_free %d", rc);
+ }
+
+}
+END_TEST
+
Suite * lsm_suite(void)
{
Suite *s = suite_create("libStorageMgmt");
@@ -2845,6 +2879,7 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
+ tcase_add_test(basic, test_target_ports);
tcase_add_test(basic, test_search_fs);
tcase_add_test(basic, test_search_access_groups);
tcase_add_test(basic, test_search_disks);
--
1.8.2.1
1.8.2.1