Discussion:
[Libstoragemgmt-devel] [PATCH 2/3] PY & C API: pool_create_from_pool use pool obj.
Tony Asleson
2014-04-15 00:00:38 UTC
Permalink
Change to use pool object instead of pool id as
source of creating pool from pool (sub pool).

Signed-off-by: Tony Asleson <***@redhat.com>
---
include/libstoragemgmt/libstoragemgmt.h | 8 ++++----
include/libstoragemgmt/libstoragemgmt_plug_interface.h | 8 ++++----
lsm/lsm/_client.py | 4 ++--
lsm/lsm/_cmdline.py | 9 ++-------
lsm/lsm/simulator.py | 4 ++--
plugin/simc_lsmplugin.c | 8 ++++----
src/lsm_mgmt.cpp | 16 ++++++++++------
src/lsm_plugin_ipc.cpp | 13 +++++++------
test/tester.c | 9 +++++++--
9 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/include/libstoragemgmt/libstoragemgmt.h b/include/libstoragemgmt/libstoragemgmt.h
index 34fb781..5b43575 100644
--- a/include/libstoragemgmt/libstoragemgmt.h
+++ b/include/libstoragemgmt/libstoragemgmt.h
@@ -316,9 +316,9 @@ extern "C" {
* @param [in] system System of where pool will reside
* @param [in] pool_name The name of the new pool, will not fail
* if request name cannot be fulfilled
- * @param [in] member_id The ID of pool to create new pool from
+ * @param [in] pool The pool to create new pool from
* @param [in] size_bytes Desired size of new pool
- * @param [out] pool Newly created pool
+ * @param [out] created_pool Newly created pool
* @param [out] job Job ID of aysnc.
* @param [in] flags Reserved for future use, must be zero
* @return LSM_ERR_OK on success, LSM_ERR_JOB_STARTED if async.,
@@ -326,8 +326,8 @@ extern "C" {
*/
int LSM_DLL_EXPORT lsm_pool_create_from_pool(lsm_connect *conn,
lsm_system *system, const char *pool_name,
- const char *member_id, uint64_t size_bytes,
- lsm_pool** pool, char **job, lsm_flag flags);
+ lsm_pool *pool, uint64_t size_bytes,
+ lsm_pool** created_pool, char **job, lsm_flag flags);

/**
* Deletes a pool
diff --git a/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 6b685bc..9ad7983 100644
--- a/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -271,16 +271,16 @@ typedef int (*lsm_plug_pool_create_from_volumes)( lsm_plugin_ptr c,
* @param[in] c Valid lsm plug-in pointer
* @param[in] system System id
* @param[in] pool_name Human name of pool
- * @param[in] member_id ID of pool to create pool from
+ * @param[in] pool Pool to create pool from
* @param[in] size_bytes Size of pool
- * @param[out] pool Newly create pool if done sync.
+ * @param[out] created_pool Newly create pool if done sync.
* @param[out] job Job id if execution is async.
* @return LSM_ERR_OK, else error reason
*/
typedef int (*lsm_plug_pool_create_from_pool)( lsm_plugin_ptr c,
lsm_system *system,
- const char *pool_name, const char *member_id,
- uint64_t size_bytes, lsm_pool **pool, char **job,
+ const char *pool_name, lsm_pool *pool,
+ uint64_t size_bytes, lsm_pool **created_pool, char **job,
lsm_flag flags );


diff --git a/lsm/lsm/_client.py b/lsm/lsm/_client.py
index 9d86994..a769412 100644
--- a/lsm/lsm/_client.py
+++ b/lsm/lsm/_client.py
@@ -388,13 +388,13 @@ class Client(INetworkAttachedStorage):
# @param system_id The id of system where new pool should reside.
# @param pool_name The name for new pool. Will not fail if created
# pool_name is not the same as requested.
- # @param member_id The id of pool to allocate space from for new pool.
+ # @param pool The pool to allocate space from for new pool.
# @param size_bytes The size of the new pool.
# @param flags Reserved for future use.
# @returns A tuple (job_id, new_pool), when one is None the other is
# valid.
@_return_requires(unicode, Pool)
- def pool_create_from_pool(self, system_id, pool_name, member_id,
+ def pool_create_from_pool(self, system_id, pool_name, pool,
size_bytes, flags=0):
"""
Creates pool from volumes.
diff --git a/lsm/lsm/_cmdline.py b/lsm/lsm/_cmdline.py
index a679583..7408292 100644
--- a/lsm/lsm/_cmdline.py
+++ b/lsm/lsm/_cmdline.py
@@ -1746,12 +1746,7 @@ class CmdLine:
"from pool only allow one member pool")

member_id = member_ids[0]
-
- pools = self.c.pools()
- pool_ids = [p.id for p in pools]
- if member_id not in pool_ids:
- raise ArgError("Invalid pools ID specified in " +
- "--member-id %s " % member_id)
+ pool = _get_item(self.c.pools(), member_id, "pool id")

size_bytes = self._size(self.args.size)

@@ -1759,7 +1754,7 @@ class CmdLine:
pool = self._wait_for_it(
"pool-create-from-pool",
*self.c.pool_create_from_pool(
- system, pool_name, member_id, size_bytes, 0))
+ system, pool_name, pool, size_bytes, 0))
self.display_data([pool])

def _read_configfile(self):
diff --git a/lsm/lsm/simulator.py b/lsm/lsm/simulator.py
index e5a3630..05bb21e 100644
--- a/lsm/lsm/simulator.py
+++ b/lsm/lsm/simulator.py
@@ -105,10 +105,10 @@ class SimPlugin(INfs, IStorageAreaNetwork):
return self.sim_array.pool_create_from_volumes(
system.id, pool_name, member_ids, raid_type, flags)

- def pool_create_from_pool(self, system, pool_name, member_id,
+ def pool_create_from_pool(self, system, pool_name, pool,
size_bytes, flags=0):
return self.sim_array.pool_create_from_pool(
- system.id, pool_name, member_id, size_bytes, flags)
+ system.id, pool_name, pool.id, size_bytes, flags)

def pool_delete(self, pool, flags=0):
return self.sim_array.pool_delete(pool.id, flags)
diff --git a/plugin/simc_lsmplugin.c b/plugin/simc_lsmplugin.c
index 3269506..fe8506f 100644
--- a/plugin/simc_lsmplugin.c
+++ b/plugin/simc_lsmplugin.c
@@ -1095,17 +1095,17 @@ bail:
}

static int pool_create_from_pool(lsm_plugin_ptr c, lsm_system *system,
- const char *pool_name, const char *member_id,
- uint64_t size_bytes, lsm_pool **pool, char **job,
+ const char *pool_name, lsm_pool *pool,
+ uint64_t size_bytes, lsm_pool **created_pool, char **job,
lsm_flag flags )
{
/* Check that the disks are valid, then call common routine */
int rc = LSM_ERR_OK;
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
- lsm_pool *p = find_pool(pd, member_id);
+ lsm_pool *p = find_pool(pd, lsm_pool_id_get(pool));

if( p ) {
- rc = _pool_create(c, system, pool_name, size_bytes, pool, job);
+ rc = _pool_create(c, system, pool_name, size_bytes, created_pool, job);
} else {
rc = lsm_log_error_basic(c, LSM_ERR_NOT_FOUND_POOL, "Pool not found");
}
diff --git a/src/lsm_mgmt.cpp b/src/lsm_mgmt.cpp
index 09497f1..bad3a1b 100644
--- a/src/lsm_mgmt.cpp
+++ b/src/lsm_mgmt.cpp
@@ -1013,8 +1013,8 @@ int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *c,


int lsm_pool_create_from_pool(lsm_connect *c, lsm_system *system,
- const char *pool_name, const char *member_id,
- uint64_t size_bytes, lsm_pool **pool, char **job,
+ const char *pool_name, lsm_pool *pool,
+ uint64_t size_bytes, lsm_pool **created_pool, char **job,
lsm_flag flags)
{
CONN_SETUP(c);
@@ -1023,8 +1023,12 @@ int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *c,
return LSM_ERR_INVALID_SYSTEM;
}

- if( CHECK_STR(pool_name) || CHECK_STR(member_id) ||
- !size_bytes || CHECK_RP(pool)|| CHECK_RP(job) ||
+ if( !LSM_IS_POOL(pool) ) {
+ return LSM_ERR_INVALID_POOL;
+ }
+
+ if( CHECK_STR(pool_name) ||
+ !size_bytes || CHECK_RP(created_pool)|| CHECK_RP(job) ||
LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}
@@ -1033,7 +1037,7 @@ int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *c,
p["system"] = system_to_value(system);
p["pool_name"] = Value(pool_name);
p["size_bytes"] = Value(size_bytes);
- p["member_id"] = Value(member_id);
+ p["pool"] = pool_to_value(pool);
p["flags"] = Value(flags);

Value parameters(p);
@@ -1041,7 +1045,7 @@ int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *c,

int rc = rpc(c, "pool_create_from_pool", parameters, response);
if( LSM_ERR_OK == rc ) {
- *pool = (lsm_pool *)parse_job_response(c, response, rc, job,
+ *created_pool = (lsm_pool *)parse_job_response(c, response, rc, job,
(convert)value_to_pool);
}
return rc;
diff --git a/src/lsm_plugin_ipc.cpp b/src/lsm_plugin_ipc.cpp
index 7e8b676..c71f752 100644
--- a/src/lsm_plugin_ipc.cpp
+++ b/src/lsm_plugin_ipc.cpp
@@ -598,29 +598,30 @@ static int handle_pool_create_from_pool(lsm_plugin_ptr p, Value &params, Value &

Value v_sys = params["system"];
Value v_pool_name = params["pool_name"];
- Value v_member_id = params["member_id"];
+ Value v_pool = params["pool"];
Value v_size = params["size_bytes"];

if( Value::object_t == v_sys.valueType() &&
Value::string_t == v_pool_name.valueType() &&
- Value::string_t == v_member_id.valueType() &&
+ Value::object_t == v_pool.valueType() &&
Value::numeric_t == v_size.valueType() &&
LSM_FLAG_EXPECTED_TYPE(params)) {

lsm_system *sys = value_to_system(v_sys);
const char *pool_name = v_pool_name.asC_str();
- const char *member_id = v_member_id.asC_str();
+ lsm_pool *pool = value_to_pool(v_pool);
uint64_t size = v_size.asUint64_t();

- lsm_pool *pool = NULL;
+ lsm_pool *created_pool = NULL;
char *job = NULL;

rc = p->san_ops->pool_create_from_pool(p, sys, pool_name,
- member_id, size, &pool, &job,
+ pool, size, &created_pool, &job,
LSM_FLAG_GET_VALUE(params));

- Value p = pool_to_value(pool);
+ Value p = pool_to_value(created_pool);
response = job_handle(p, job);
+ lsm_pool_record_free(created_pool);
lsm_pool_record_free(pool);
lsm_system_record_free(sys);
free(job);
diff --git a/test/tester.c b/test/tester.c
index b7742b6..6da6461 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2457,7 +2457,7 @@ START_TEST(test_pool_create)
lsm_disk **disks = NULL;
uint32_t num_disks = 0;
lsm_string_list *member_ids = lsm_string_list_alloc(0);
- char *pool_one = NULL;
+ lsm_pool *pool_one = NULL;
lsm_system *system = get_system(c);

/*
@@ -2533,7 +2533,7 @@ START_TEST(test_pool_create)

if( LSM_ERR_OK == rc ) {

- pool_one = strdup(lsm_pool_id_get(pools[0]));
+ pool_one = lsm_pool_record_copy(pools[0]);

for( i = 0; i < num_pools; ++i ) {
job = NULL;
@@ -2618,6 +2618,11 @@ START_TEST(test_pool_create)
}
}

+ if( pool_one ) {
+ lsm_pool_record_free(pool_one);
+ pool_one = NULL;
+ }
+
if( system ) {
lsm_system_record_free(system);
system = NULL;
--
1.8.2.1
Tony Asleson
2014-04-15 00:00:39 UTC
Permalink
Convert these two methods to use object instead of
object ids.

Signed-off-by: Tony Asleson <***@redhat.com>
---
include/libstoragemgmt/libstoragemgmt.h | 10 ++-
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 11 +--
lsm/lsm/_client.py | 8 +--
lsm/lsm/_cmdline.py | 10 +--
lsm/lsm/simarray.py | 4 +-
lsm/lsm/simulator.py | 8 ++-
plugin/simc_lsmplugin.c | 10 ++-
src/lsm_convert.cpp | 66 +++++++++++++++++
src/lsm_convert.hpp | 12 ++++
src/lsm_mgmt.cpp | 50 +++++++++----
src/lsm_plugin_ipc.cpp | 84 ++++++++++++++--------
test/tester.c | 33 ++++++---
12 files changed, 227 insertions(+), 79 deletions(-)

diff --git a/include/libstoragemgmt/libstoragemgmt.h b/include/libstoragemgmt/libstoragemgmt.h
index 5b43575..b18adff 100644
--- a/include/libstoragemgmt/libstoragemgmt.h
+++ b/include/libstoragemgmt/libstoragemgmt.h
@@ -269,11 +269,13 @@ extern "C" {
* @param [in] system System of where pool will reside
* @param [in] pool_name The name of the new pool, will not fail
* if request name cannot be fulfilled
- * @param [in] member_ids The IDs of disks to create new pool from
+ * @param [in] disks An array of disk pointers to create new
+ * pool from.
* The new pool could contain more disks
* than requested due to internal needs,
* but if possible should only contain
* requested disks.
+ * @param [in] num_disks Number of disks in disks array
* @param [in] raid_type The RAID type for new pool
* @param [out] pool Newly created pool
* @param [out] job Job ID of aysnc.
@@ -283,7 +285,8 @@ extern "C" {
*/
int LSM_DLL_EXPORT lsm_pool_create_from_disks(lsm_connect *conn,
lsm_system *system, const char *pool_name,
- lsm_string_list *member_ids, lsm_pool_raid_type raid_type,
+ lsm_disk *disks[], uint32_t num_disks,
+ lsm_pool_raid_type raid_type,
lsm_pool** pool, char **job, lsm_flag flags);

/**
@@ -307,7 +310,8 @@ extern "C" {
*/
int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *conn,
lsm_system *system, const char *pool_name,
- lsm_string_list *member_ids, lsm_pool_raid_type raid_type,
+ lsm_volume *volumes[], uint32_t num_volumes,
+ lsm_pool_raid_type raid_type,
lsm_pool** pool, char **job, lsm_flag flags);

/**
diff --git a/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 9ad7983..0ed9807 100644
--- a/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -237,7 +237,8 @@ typedef int (*lsm_plug_pool_create)( lsm_plugin_ptr c, lsm_system* system,
* @param[in] c Valid lsm plug-in pointer
* @param[in] system System
* @param[in] pool_name Human name of pool
- * @param[in] member_ids List of disk IDs to create pool from
+ * @param[in] disks Array of disk pointers to create pool from
+ * @param[in] num_disks Number of disks
* @param[in] raid_type Raid type for pool
* @param[out] pool Newly create pool if done sync.
* @param[out] job Job id if execution is async.
@@ -245,7 +246,7 @@ typedef int (*lsm_plug_pool_create)( lsm_plugin_ptr c, lsm_system* system,
*/
typedef int (*lsm_plug_pool_create_from_disks)( lsm_plugin_ptr c,
lsm_system *system,
- const char *pool_name, lsm_string_list *member_ids,
+ const char *pool_name, lsm_disk *disks[], uint32_t num_disks,
lsm_pool_raid_type raid_type, lsm_pool **pool, char **job,
lsm_flag flags);

@@ -254,7 +255,8 @@ typedef int (*lsm_plug_pool_create_from_disks)( lsm_plugin_ptr c,
* @param[in] c Valid lsm plug-in pointer
* @param[in] system System
* @param[in] pool_name Human name of pool
- * @param[in] member_ids List of volume IDs to create pool from
+ * @param[in] volumes Array of volume pointers
+ * @param[in] num_volumes Number of volumes
* @param[in] raid_type Raid type for pool
* @param[out] pool Newly create pool if done sync.
* @param[out] job Job id if execution is async.
@@ -262,7 +264,8 @@ typedef int (*lsm_plug_pool_create_from_disks)( lsm_plugin_ptr c,
*/
typedef int (*lsm_plug_pool_create_from_volumes)( lsm_plugin_ptr c,
lsm_system *system,
- const char *pool_name, lsm_string_list *member_ids,
+ const char *pool_name, lsm_volume *volumes[],
+ uint32_t num_volumes,
lsm_pool_raid_type raid_type, lsm_pool** pool, char **job,
lsm_flag flags);

diff --git a/lsm/lsm/_client.py b/lsm/lsm/_client.py
index a769412..a8a30c2 100644
--- a/lsm/lsm/_client.py
+++ b/lsm/lsm/_client.py
@@ -334,7 +334,7 @@ class Client(INetworkAttachedStorage):
# @param system_id The id of system where new pool should reside.
# @param pool_name The name for new pool. Will not fail if created
# pool_name is not the same as requested.
- # @param member_ids The ids of disks to create new pool.
+ # @param Disks The disks (list) to create new pool from.
# The new pool could contain more disks than
# requested due to internal needs, but if possible,
# new pool should only contain requested disks.
@@ -345,7 +345,7 @@ class Client(INetworkAttachedStorage):
# @returns A tuple (job_id, new_pool), when one is None the other is
# valid.
@_return_requires(unicode, Pool)
- def pool_create_from_disks(self, system_id, pool_name, member_ids,
+ def pool_create_from_disks(self, system_id, pool_name, disks,
raid_type, flags=0):
"""
Creates pool from disks.
@@ -361,7 +361,7 @@ class Client(INetworkAttachedStorage):
# @param system_id The id of system where new pool should reside.
# @param pool_name The name for new pool. Will not fail if created
# pool_name is not the same as requested.
- # @param member_ids The ids of volumes to create new pool.
+ # @param volumes The volumes to create new pool from.
# The new pool could contain more volumes than
# requested due to internal needs, but if possible,
# new pool should only contain requested volumes.
@@ -372,7 +372,7 @@ class Client(INetworkAttachedStorage):
# @returns A tuple (job_id, new_pool), when one is None the other is
# valid.
@_return_requires(unicode, Pool)
- def pool_create_from_volumes(self, system_id, pool_name, member_ids,
+ def pool_create_from_volumes(self, system_id, pool_name, volumes,
raid_type, flags=0):
"""
Creates pool from volumes.
diff --git a/lsm/lsm/_cmdline.py b/lsm/lsm/_cmdline.py
index 7408292..778647e 100644
--- a/lsm/lsm/_cmdline.py
+++ b/lsm/lsm/_cmdline.py
@@ -1689,15 +1689,17 @@ class CmdLine:
raise ArgError("No disk ID was provided for new pool")

member_ids = args.member_id
+ disks_to_use = []
disks = self.c.disks()
- disk_ids = [d.id for d in disks]
+ disk_ids = dict((x.id, x) for x in disks)
for member_id in member_ids:
if member_id not in disk_ids:
raise ArgError("Invalid Disk ID specified in " +
"--member-id %s " % member_id)
+ else:
+ disks_to_use.append(disk_ids[member_id])

- raid_type = Pool._raid_type_str_to_type(
- self.args.raid_type)
+ raid_type = Pool._raid_type_str_to_type(self.args.raid_type)
if raid_type == Pool.RAID_TYPE_UNKNOWN:
raise ArgError("Unknown RAID type specified: %s" %
self.args.raid_type)
@@ -1706,7 +1708,7 @@ class CmdLine:
pool = self._wait_for_it(
"pool-create-from-disks",
*self.c.pool_create_from_disks(
- system, pool_name, member_ids, raid_type, 0))
+ system, pool_name, disks_to_use, raid_type, 0))
self.display_data([pool])

def pool_create_from_volumes(self, args):
diff --git a/lsm/lsm/simarray.py b/lsm/lsm/simarray.py
index a563ee4..1ddf3f2 100644
--- a/lsm/lsm/simarray.py
+++ b/lsm/lsm/simarray.py
@@ -184,10 +184,10 @@ class SimArray(object):
return self.data.job_create(
self._sim_pool_2_lsm(sim_pool, Pool.RETRIEVE_FULL_INFO))

- def pool_create_from_disks(self, sys_id, pool_name, member_ids, raid_type,
+ def pool_create_from_disks(self, sys_id, pool_name, disks_ids, raid_type,
flags=0):
sim_pool = self.data.pool_create_from_disks(
- sys_id, pool_name, member_ids, raid_type, flags)
+ sys_id, pool_name, disks_ids, raid_type, flags)
return self.data.job_create(
self._sim_pool_2_lsm(sim_pool, Pool.RETRIEVE_FULL_INFO))

diff --git a/lsm/lsm/simulator.py b/lsm/lsm/simulator.py
index 05bb21e..1ea1a45 100644
--- a/lsm/lsm/simulator.py
+++ b/lsm/lsm/simulator.py
@@ -16,7 +16,7 @@
# Author: tasleson

from lsm import (uri_parse, VERSION, Capabilities, Pool, INfs,
- IStorageAreaNetwork)
+ IStorageAreaNetwork, Error)

from simarray import SimArray

@@ -95,13 +95,15 @@ class SimPlugin(INfs, IStorageAreaNetwork):
return self.sim_array.pool_create(
system.id, pool_name, size_bytes, raid_type, member_type, flags)

- def pool_create_from_disks(self, system, pool_name, member_ids,
+ def pool_create_from_disks(self, system, pool_name, disks,
raid_type, flags=0):
+ member_ids = [x.id for x in disks]
return self.sim_array.pool_create_from_disks(
system.id, pool_name, member_ids, raid_type, flags)

- def pool_create_from_volumes(self, system, pool_name, member_ids,
+ def pool_create_from_volumes(self, system, pool_name, volumes,
raid_type, flags=0):
+ member_ids = [x.id for x in volumes]
return self.sim_array.pool_create_from_volumes(
system.id, pool_name, member_ids, raid_type, flags)

diff --git a/plugin/simc_lsmplugin.c b/plugin/simc_lsmplugin.c
index fe8506f..dfd8b99 100644
--- a/plugin/simc_lsmplugin.c
+++ b/plugin/simc_lsmplugin.c
@@ -1029,7 +1029,7 @@ static int pool_create(lsm_plugin_ptr c, lsm_system *system,
}

static int pool_create_from_disks( lsm_plugin_ptr c, lsm_system *system,
- const char *pool_name, lsm_string_list *member_ids,
+ const char *pool_name, lsm_disk *disks[], uint32_t num_disks,
lsm_pool_raid_type raid_type, lsm_pool **pool, char **job,
lsm_flag flags)
{
@@ -1037,12 +1037,11 @@ static int pool_create_from_disks( lsm_plugin_ptr c, lsm_system *system,
uint64_t size = 0;
int rc = LSM_ERR_OK;
int i = 0;
- int num_disks = lsm_string_list_size(member_ids);
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);

if( num_disks ) {
for( i = 0; i < num_disks; ++i ) {
- lsm_disk *d = find_disk(pd, lsm_string_list_elem_get(member_ids, i));
+ lsm_disk *d = find_disk(pd, lsm_disk_id_get(disks[i]));
if( d ) {
size += (lsm_disk_number_of_blocks_get(d) * lsm_disk_block_size_get(d));
} else {
@@ -1061,7 +1060,7 @@ bail:
}

static int pool_create_from_volumes( lsm_plugin_ptr c, lsm_system *system,
- const char *pool_name, lsm_string_list *member_ids,
+ const char *pool_name, lsm_volume *volumes[], uint32_t num_volumes,
lsm_pool_raid_type raid_type, lsm_pool **pool, char **job,
lsm_flag flags)
{
@@ -1069,13 +1068,12 @@ static int pool_create_from_volumes( lsm_plugin_ptr c, lsm_system *system,
uint64_t size = 0;
int rc = LSM_ERR_OK;
int i = 0;
- int num_volumes = lsm_string_list_size(member_ids);
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);

if( num_volumes ) {
for( i = 0; i < num_volumes; ++i ) {
struct allocated_volume *v =
- find_volume(pd, lsm_string_list_elem_get(member_ids, i));
+ find_volume(pd, lsm_volume_id_get(volumes[i]));
if( v ) {
size += (lsm_volume_number_of_blocks_get(v->v) *
lsm_volume_number_of_blocks_get(v->v));
diff --git a/src/lsm_convert.cpp b/src/lsm_convert.cpp
index ff717df..cef3f4c 100644
--- a/src/lsm_convert.cpp
+++ b/src/lsm_convert.cpp
@@ -73,6 +73,40 @@ Value volume_to_value(lsm_volume *vol)
return Value();
}

+int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
+ uint32_t *count)
+{
+ int rc = LSM_ERR_OK;
+ try {
+ if( Value::array_t == volume_values.valueType()) {
+ std::vector<Value> vol = volume_values.asArray();
+
+ *count = vol.size();
+
+ if( vol.size() ) {
+ *volumes = lsm_volume_record_array_alloc(vol.size());
+
+ if( *volumes ){
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = value_to_volume(vol[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
+ }
+ }
+ } catch( const ValueException &ve) {
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
+
+ rc = LSM_ERR_INTERNAL_ERROR;
+ }
+ return rc;
+}
+
lsm_disk *value_to_disk(Value &disk)
{
lsm_disk *rc = NULL;
@@ -125,6 +159,38 @@ Value disk_to_value(lsm_disk *disk)
return Value();
}

+int value_array_to_disks(Value &disk_values, lsm_disk **disks[], uint32_t *count)
+{
+ int rc = LSM_ERR_OK;
+ try {
+ if( Value::array_t == disk_values.valueType()) {
+ std::vector<Value> d = disk_values.asArray();
+
+ *count = d.size();
+
+ if( d.size() ) {
+ *disks = lsm_disk_record_array_alloc(d.size());
+
+ if( *disks ){
+ for( size_t i = 0; i < d.size(); ++i ) {
+ (*disks)[i] = value_to_disk(d[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
+ }
+ }
+ } catch( const ValueException &ve ) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *disks && *count ) {
+ lsm_disk_record_array_free(*disks, *count);
+ *disks = NULL;
+ *count = 0;
+ }
+ }
+ return rc;
+}
+
lsm_initiator *value_to_initiator(Value &init)
{
lsm_initiator *rc = NULL;
diff --git a/src/lsm_convert.hpp b/src/lsm_convert.hpp
index 366234d..988fa6c 100644
--- a/src/lsm_convert.hpp
+++ b/src/lsm_convert.hpp
@@ -51,6 +51,9 @@ lsm_volume * value_to_volume(Value &vol);
*/
Value volume_to_value(lsm_volume *vol);

+int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
+ uint32_t *count);
+
/**
* Converts a Value to a lsm_disk
* @param disk Value representing a disk
@@ -66,6 +69,15 @@ lsm_disk *value_to_disk(Value &disk);
Value disk_to_value(lsm_disk *disk);

/**
+ * Converts a vector of disk values to an array.
+ * @param disks Vector of values that represents disks
+ * @param disks An array of disk pointers
+ * @param count Number of disks
+ * @return LSM_ERR_OK on success, else error reason.
+ */
+int value_array_to_disks(Value &disk_values, lsm_disk **disks[], uint32_t *count);
+
+/**
* Converts a value to lsm_initiator *
* @param init to convert
* @return lsm_initiator *, else NULL on error.
diff --git a/src/lsm_mgmt.cpp b/src/lsm_mgmt.cpp
index bad3a1b..6a87522 100644
--- a/src/lsm_mgmt.cpp
+++ b/src/lsm_mgmt.cpp
@@ -954,9 +954,9 @@ int lsm_pool_create(lsm_connect *c, lsm_system *system,

static int lsm_pool_create_from(lsm_connect *c,
lsm_system *system, const char *pool_name,
- lsm_string_list *member_ids, lsm_pool_raid_type raid_type,
+ std::vector<Value> &member_ids, lsm_pool_raid_type raid_type,
lsm_pool** pool, char **job, lsm_flag flags,
- const char *method)
+ const char *member_id, const char *method)
{
CONN_SETUP(c);

@@ -970,14 +970,11 @@ static int lsm_pool_create_from(lsm_connect *c,
return LSM_ERR_INVALID_ARGUMENT;
}

- if( !LSM_IS_STRING_LIST(member_ids) ) {
- return LSM_ERR_INVALID_SL;
- }

std::map<std::string, Value> p;
p["system"] = system_to_value(system);
p["pool_name"] = Value(pool_name);
- p["member_ids"] = string_list_to_value(member_ids);
+ p[member_id] = Value(member_ids);
p["raid_type"] = Value((int32_t)raid_type);
p["flags"] = Value(flags);

@@ -994,20 +991,49 @@ static int lsm_pool_create_from(lsm_connect *c,

int LSM_DLL_EXPORT lsm_pool_create_from_disks(lsm_connect *c,
lsm_system *system, const char *pool_name,
- lsm_string_list *member_ids, lsm_pool_raid_type raid_type,
+ lsm_disk *disks[], uint32_t num_disks,
+ lsm_pool_raid_type raid_type,
lsm_pool** pool, char **job, lsm_flag flags)
{
- return lsm_pool_create_from(c, system, pool_name, member_ids, raid_type,
- pool, job, flags, "pool_create_from_disks");
+ uint32_t i;
+
+ CONN_SETUP(c);
+
+ if( !disks || !num_disks ) {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+
+ /* Create disks container */
+ std::vector<Value> d;
+ for( i = 0; i < num_disks; ++i ) {
+ d.push_back(disk_to_value(disks[i]));
+ }
+
+ return lsm_pool_create_from(c, system, pool_name, d, raid_type, pool, job,
+ flags, "disks", "pool_create_from_disks");
+
}

int LSM_DLL_EXPORT lsm_pool_create_from_volumes(lsm_connect *c,
lsm_system *system, const char *pool_name,
- lsm_string_list *member_ids, lsm_pool_raid_type raid_type,
+ lsm_volume *volumes[], uint32_t num_volumes,
+ lsm_pool_raid_type raid_type,
lsm_pool** pool, char **job, lsm_flag flags)
{
- return lsm_pool_create_from(c, system, pool_name, member_ids, raid_type,
- pool, job, flags,
+ uint32_t i;
+
+ if( !volumes || !num_volumes ) {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+
+ /* Create disks container */
+ std::vector<Value> vols;
+ for( i = 0; i < num_volumes; ++i ) {
+ vols.push_back(volume_to_value(volumes[i]));
+ }
+
+ return lsm_pool_create_from(c, system, pool_name, vols, raid_type,
+ pool, job, flags, "volumes",
"pool_create_from_volumes");
}

diff --git a/src/lsm_plugin_ipc.cpp b/src/lsm_plugin_ipc.cpp
index c71f752..dde2d65 100644
--- a/src/lsm_plugin_ipc.cpp
+++ b/src/lsm_plugin_ipc.cpp
@@ -519,34 +519,28 @@ static int handle_pool_create(lsm_plugin_ptr p, Value &params, Value &response)
return rc;
}

-typedef int (*lsmPlugPoolCreateFrom)( lsm_plugin_ptr c,
- lsm_system *system,
- const char *pool_name, lsm_string_list *member_ids,
- lsm_pool_raid_type raid_type, lsm_pool** pool, char **job,
- lsm_flag flags);
-
-
-static int handle_pool_create_from( lsm_plugin_ptr p, Value &params,
- Value &response,
- lsmPlugPoolCreate

Loading...