Tony Asleson
2014-06-05 23:30:38 UTC
Python had optional_data, but C did not.
Note: The optional_data for python was retaining the value
type. The C version requires that the value is always a
string, so I needed to put in changes to convert everything
to a string and convert things to numeric values when needed.
If we require this ability we will should probably store the
value in C with some type of variant structure and provide
functions to determine what type it is and then have a function
that will return it in that form.
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 13 ++++++-
.../include/libstoragemgmt/libstoragemgmt_pool.h | 7 ++++
c_binding/lsm_convert.cpp | 42 +++++++++-----------
c_binding/lsm_datatypes.cpp | 45 ++++++++++++++++------
c_binding/lsm_datatypes.hpp | 14 +++++++
plugin/sim/sim_lsmplugin | 20 +++++-----
plugin/simc/simc_lsmplugin.c | 6 +--
python_binding/lsm/_data.py | 8 ++--
test/tester.c | 7 ++--
tools/lsmcli/data_display.py | 3 ++
10 files changed, 109 insertions(+), 56 deletions(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 0c6c1ab..b934e72 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1078,13 +1078,24 @@ void LSM_DLL_EXPORT lsm_pool_free_space_set(lsm_pool *p, uint64_t free_space);
* @param status Pool status, bit field (See LSM_POOL_STATUS_XXXX constants)
* @param status_info Additional textual information on status
* @param system_id System id
+ * @param optiona_data Optional data
+ * @param plugin_data Reserved for plugin writer use
* @return LSM_ERR_OK on success, else error reason.
*/
lsm_pool LSM_DLL_EXPORT *lsm_pool_record_alloc(const char *id, const char *name,
uint64_t total_space,
uint64_t free_space,
uint64_t status, const char* status_info,
- const char *system_id);
+ const char *system_id,
+ lsm_optional_data *optional_data,
+ const char * plugin_data);
+
+/**
+ * Used to retrieve the plugin-private data for a specfic pool
+ * @param p Pool to retrieve plugin private data for
+ * @return NULL if donesn't exists, else data.
+ */
+const char *lsm_pool_plugin_data_get(lsm_pool *p);
/**
* Allocate the storage needed for and array of Initiator records.
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h b/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
index 61ebccf..1e8f0a5 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
@@ -100,6 +100,13 @@ const char LSM_DLL_EXPORT *lsm_pool_status_info_get( lsm_pool *s );
*/
char LSM_DLL_EXPORT *lsm_pool_system_id_get( lsm_pool *p );
+/**
+ * Retrieve the optional data for the specified pool
+ * @param p Pool pointer
+ * @return Pointer to optional data
+ */
+lsm_optional_data *lsm_pool_optional_data_get( lsm_pool *p );
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 77e7bee..fbe88d2 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -114,11 +114,8 @@ lsm_disk *value_to_disk(Value &disk)
lsm_disk *rc = NULL;
if (is_expected_object(disk, "Disk")) {
lsm_optional_data *op = NULL;
-
- if( disk.asObject().find("optional_data") != disk.asObject().end() ) {
- Value opv = disk["optional_data"];
- op = value_to_optional_data(opv);
- }
+ Value opv = disk["optional_data"];
+ op = value_to_optional_data(opv);
std::map<std::string, Value> d = disk.asObject();
rc = lsm_disk_record_alloc(
@@ -151,10 +148,7 @@ Value disk_to_value(lsm_disk *disk)
d["num_of_blocks"] = Value(disk->block_count);
d["status"] = Value(disk->disk_status);
d["system_id"] = Value(disk->system_id);
-
- if( disk->optional_data ) {
- d["optional_data"] = optional_data_to_value(disk->optional_data);
- }
+ d["optional_data"] = optional_data_to_value(disk->optional_data);
return Value(d);
}
@@ -229,14 +223,20 @@ lsm_pool *value_to_pool(Value &pool)
lsm_pool *rc = NULL;
if (is_expected_object(pool, "Pool")) {
+ lsm_optional_data *op = NULL;
std::map<std::string, Value> i = pool.asObject();
+ Value opv = i["optional_data"];
+ op = value_to_optional_data(opv);
+
rc = lsm_pool_record_alloc(i["id"].asString().c_str(),
i["name"].asString().c_str(),
i["total_space"].asUint64_t(),
i["free_space"].asUint64_t(),
i["status"].asUint64_t(),
i["status_info"].asString().c_str(),
- i["system_id"].asString().c_str());
+ i["system_id"].asString().c_str(),
+ op,
+ i["plugin_data"].asC_str());
}
return rc;
}
@@ -253,6 +253,8 @@ Value pool_to_value(lsm_pool *pool)
p["status"] = Value(pool->status);
p["status_info"] = Value(pool->status_info);
p["system_id"] = Value(pool->system_id);
+ p["optional_data"] = optional_data_to_value(pool->optional_data);
+ p["plugin_data"] = Value(pool->plugin_data);
return Value(p);
}
return Value();
@@ -328,13 +330,9 @@ lsm_access_group *value_to_access_group( Value &group )
if( is_expected_object(group, "AccessGroup")) {
std::map<std::string, Value> vAg = group.asObject();
-
il = value_to_string_list(vAg["init_ids"]);
-
- if( group.asObject().find("optional_data") != group.asObject().end() ) {
- Value opv = group["optional_data"];
- op = value_to_optional_data(opv);
- }
+ Value opv = group["optional_data"];
+ op = value_to_optional_data(opv);
if( il ) {
ag = lsm_access_group_record_alloc(
@@ -345,11 +343,10 @@ lsm_access_group *value_to_access_group( Value &group )
vAg["system_id"].asString().c_str(),
op,
vAg["plugin_data"].asC_str());
-
- /* This stuff is copied in lsm_access_group_record_alloc */
- lsm_string_list_free(il);
- lsm_optional_data_record_free(op);
}
+ /* This stuff is copied in lsm_access_group_record_alloc */
+ lsm_string_list_free(il);
+ lsm_optional_data_record_free(op);
}
return ag;
}
@@ -365,10 +362,7 @@ Value access_group_to_value( lsm_access_group *group )
ag["init_type"] = Value(group->init_type);
ag["system_id"] = Value(group->system_id);
ag["plugin_data"] = Value(group->plugin_data);
-
- if( group->optional_data ) {
- ag["optional_data"] = optional_data_to_value(group->optional_data);
- }
+ ag["optional_data"] = optional_data_to_value(group->optional_data);
return Value(ag);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 442a989..fda2f08 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -52,6 +52,14 @@ extern "C" {
#define LSM_DEFAULT_PLUGIN_DIR "/var/run/lsm/ipc"
+/* We would certainly expand this to encompass the entire function */
+#define MEMBER_GET(x, validation, member, error) \
+ if( validation(x) ) { \
+ return x->member; \
+ } else { \
+ return error; \
+ }
+
int lsm_string_list_append(lsm_string_list *sl, const char *value)
{
int rc = LSM_ERR_INVALID_SL;
@@ -496,7 +504,7 @@ CREATE_ALLOC_ARRAY_FUNC(lsm_pool_record_array_alloc, lsm_pool *)
lsm_pool *lsm_pool_record_alloc(const char *id, const char *name,
uint64_t totalSpace, uint64_t freeSpace, uint64_t status, const char* status_info,
- const char *system_id)
+ const char *system_id, lsm_optional_data* optional_data, const char * plugin_data)
{
lsm_pool *rc = (lsm_pool *)calloc(1, sizeof(lsm_pool));
if (rc) {
@@ -508,8 +516,15 @@ lsm_pool *lsm_pool_record_alloc(const char *id, const char *name,
rc->status = status;
rc->status_info = strdup(status_info);
rc->system_id = strdup(system_id);
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
- if( !rc->id || !rc->name || !rc->system_id || !rc->status_info ) {
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }
+
+ if( !rc->id || !rc->name || !rc->system_id || !rc->status_info ||
+ (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_pool_record_free(rc);
rc = NULL;
}
@@ -532,7 +547,9 @@ lsm_pool * lsm_pool_record_copy( lsm_pool *toBeCopied)
toBeCopied->free_space,
toBeCopied->status,
toBeCopied->status_info,
- toBeCopied->system_id);
+ toBeCopied->system_id,
+ toBeCopied->optional_data,
+ toBeCopied->plugin_data);
}
return NULL;
}
@@ -560,6 +577,12 @@ int lsm_pool_record_free(lsm_pool *p)
free(p->system_id);
p->system_id = NULL;
}
+
+ lsm_optional_data_record_free(p->optional_data);
+ p->optional_data = NULL;
+ free(p->plugin_data);
+ p->plugin_data = NULL;
+
free(p);
return LSM_ERR_OK;
}
@@ -609,7 +632,7 @@ uint64_t lsm_pool_status_get( lsm_pool *p )
return UINT64_MAX;
}
-const char LSM_DLL_EXPORT *lsm_pool_status_info_get( lsm_pool *p )
+const char *lsm_pool_status_info_get( lsm_pool *p )
{
if (LSM_IS_POOL(p)) {
return p->status_info;
@@ -625,6 +648,12 @@ char *lsm_pool_system_id_get( lsm_pool *p )
return NULL;
}
+MEMBER_FUNC_GET(lsm_optional_data *, lsm_pool_optional_data_get, lsm_pool *p,
+ p, LSM_IS_POOL, optional_data, NULL)
+
+MEMBER_FUNC_GET(const char *, lsm_pool_plugin_data_get, lsm_pool *p,
+ p, LSM_IS_POOL, plugin_data, NULL)
+
CREATE_ALLOC_ARRAY_FUNC(lsm_initiator_record_array_alloc, lsm_initiator *)
lsm_initiator *lsm_initiator_record_alloc(lsm_initiator_type idType, const char* id,
@@ -920,14 +949,6 @@ CREATE_FREE_ARRAY_FUNC( lsm_disk_record_array_free, lsm_disk_record_free,
lsm_disk *, LSM_ERR_INVALID_DISK)
/* We would certainly expand this to encompass the entire function */
-#define MEMBER_GET(x, validation, member, error) \
- if( validation(x) ) { \
- return x->member; \
- } else { \
- return error; \
- }
-
-/* We would certainly expand this to encompass the entire function */
#define MEMBER_SET_REF(x, validation, member, value, alloc_func, free_func, error) \
if( validation(x) ) { \
if(x->member) { \
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index 5b134dc..521c23c 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -31,6 +31,18 @@
extern "C" {
#endif
+/* Helper macros to ease getter construction */
+
+/* Implementation for generic getter */
+#define MEMBER_FUNC_GET(return_type, name, param_sig, x, validation, member, error) \
+return_type name( param_sig ) {\
+ if( validation(x) ) { \
+ return x->member; \
+ } else { \
+ return error; \
+ } \
+} \
+
#define MAGIC_CHECK(obj, m) ((obj) && \
((obj)->magic==(m) ))
#define LSM_DEL_MAGIC(obj) ((obj & 0x0FFFFFFF) | 0xD0000000)
@@ -72,6 +84,8 @@ struct LSM_DLL_LOCAL _lsm_pool {
uint64_t status; /**< Status of pool */
char *status_info; /**< Status info for pool */
char *system_id; /**< system id */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Private data for plugin */
};
diff --git a/plugin/sim/sim_lsmplugin b/plugin/sim/sim_lsmplugin
index 9fce142..cb47f2a 100755
--- a/plugin/sim/sim_lsmplugin
+++ b/plugin/sim/sim_lsmplugin
@@ -20,17 +20,17 @@
import sys
import syslog
-try:
- from lsm import PluginRunner
- from lsm.plugin.sim.simulator import SimPlugin
+#try:
+from lsm import PluginRunner
+from lsm.plugin.sim.simulator import SimPlugin
- if __name__ == '__main__':
- PluginRunner(SimPlugin, sys.argv).run()
-except Exception as e:
+if __name__ == '__main__':
+ PluginRunner(SimPlugin, sys.argv).run()
+#except Exception as e:
#This should be quite rare, but when it does happen this is pretty
#key in understanding what happened, especially when it happens when
#running from the daemon.
- msg = "Exception: %s\n" % str(e)
- syslog.syslog(syslog.LOG_ERR, msg)
- sys.stderr.write(msg)
- sys.exit(1)
+# msg = "Exception: %s\n" % str(e)
+# syslog.syslog(syslog.LOG_ERR, msg)
+# sys.stderr.write(msg)
+# sys.exit(1)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index f242a7d..96c1aad 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -1008,7 +1008,7 @@ static int _pool_create(lsm_plugin_ptr c, lsm_system *system,
/* Create the pool */
new_pool = lsm_pool_record_alloc(md5(pool_name), pool_name, size_bytes,
size_bytes, LSM_POOL_STATUS_OK, "",
- lsm_system_id_get(system));
+ lsm_system_id_get(system), NULL, NULL);
pool_to_store = lsm_pool_record_copy(new_pool);
key = strdup(lsm_pool_id_get(pool_to_store));
@@ -2518,7 +2518,7 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
p = lsm_pool_record_alloc("POOL_3", "lsm_test_aggr",
UINT64_MAX, UINT64_MAX,
LSM_POOL_STATUS_OK, "",
- sys_id);
+ sys_id, NULL, NULL);
if( p ) {
pd->pools = g_hash_table_new_full(g_str_hash, g_str_equal, free,
free_pool_record);
@@ -2531,7 +2531,7 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
p = lsm_pool_record_alloc(name, name, UINT64_MAX,
UINT64_MAX, LSM_POOL_STATUS_OK, "",
- sys_id);
+ sys_id, NULL, NULL);
if( p ) {
g_hash_table_insert(pd->pools, strdup(lsm_pool_id_get(p)), p);
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 18a22a9..50d43ea 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -22,7 +22,6 @@ try:
except ImportError:
import json
-from datetime import datetime
from json.decoder import WHITESPACE
from lsm import LsmError, ErrorNumber
from _common import get_class, sh, default_property
@@ -486,6 +485,7 @@ The lsm.System class does not have class methods.
@default_property('status_info', doc="Text explaining status")
@default_property('system_id', doc="System identifier")
@default_property("optional_data", doc="Optional data")
+@default_property("plugin_data", doc="Plug-in private data")
class Pool(IData):
"""
Pool specific information
@@ -679,7 +679,8 @@ class Pool(IData):
'element_type', 'thinp_type']
def __init__(self, _id, _name, _total_space, _free_space, _status,
- _status_info, _system_id, _optional_data=None):
+ _status_info, _system_id, _optional_data=None,
+ _plugin_data=None):
self._id = _id # Identifier
self._name = _name # Human recognisable name
self._total_space = _total_space # Total size
@@ -687,6 +688,7 @@ class Pool(IData):
self._status = _status # Status of pool.
self._status_info = _status_info # Additional status text of pool
self._system_id = _system_id # System id this pool belongs
+ self._plugin_data = _plugin_data # Plugin private data
if _optional_data is None:
self._optional_data = OptionalData()
@@ -824,7 +826,7 @@ class OptionalData(IData):
return self._values[key]
def set(self, key, value):
- self._values[key] = value
+ self._values[str(key)] = str(value)
class Capabilities(IData):
diff --git a/test/tester.c b/test/tester.c
index f882a63..6a288da 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -228,7 +228,8 @@ lsm_pool *wait_for_job_pool(lsm_connect *c, char **job_id)
do {
rc = lsm_job_status_pool_get(c, *job_id, &status, &pc, &pool, LSM_FLAG_RSVD);
- fail_unless( LSM_ERR_OK == rc, "rc = %d (%s)", rc, error(lsm_error_last_get(c)));
+ fail_unless( LSM_ERR_OK == rc, "rc = %d (%s) plugin=%d", rc,
+ error(lsm_error_last_get(c)), which_plugin);
printf("POOL: Job %s in progress, %d done, status = %d\n", *job_id, pc, status);
usleep(POLL_SLEEP);
@@ -2514,7 +2515,8 @@ START_TEST(test_pool_create)
if( LSM_ERR_JOB_STARTED == rc ) {
pool = wait_for_job_pool(c, &job);
} else {
- fail_unless(LSM_ERR_OK == rc, "rc %d", rc);
+ fail_unless(LSM_ERR_OK == rc, "rc %d which_plugin %d", rc,
+ which_plugin);
}
lsm_pool_record_free(pool);
@@ -3102,7 +3104,6 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
- tcase_add_test(basic, test_access_groups);
tcase_add_test(basic, test_search_fs);
tcase_add_test(basic, test_search_access_groups);
tcase_add_test(basic, test_search_disks);
diff --git a/tools/lsmcli/data_display.py b/tools/lsmcli/data_display.py
index e9b7c19..d9424dc 100644
--- a/tools/lsmcli/data_display.py
+++ b/tools/lsmcli/data_display.py
@@ -49,6 +49,7 @@ def _txt_a(txt, append):
def _bit_map_to_str(bit_map, conv_dict):
rc = ''
+ bit_map = int(bit_map)
for cur_enum in conv_dict.keys():
if cur_enum & bit_map:
rc = _txt_a(rc, conv_dict[cur_enum])
@@ -59,6 +60,8 @@ def _bit_map_to_str(bit_map, conv_dict):
def _enum_type_to_str(int_type, conv_dict):
rc = ''
+ int_type = int(int_type)
+
if int_type in conv_dict.keys():
return conv_dict[int_type]
return 'Unknown(%d)' % int_type
Note: The optional_data for python was retaining the value
type. The C version requires that the value is always a
string, so I needed to put in changes to convert everything
to a string and convert things to numeric values when needed.
If we require this ability we will should probably store the
value in C with some type of variant structure and provide
functions to determine what type it is and then have a function
that will return it in that form.
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 13 ++++++-
.../include/libstoragemgmt/libstoragemgmt_pool.h | 7 ++++
c_binding/lsm_convert.cpp | 42 +++++++++-----------
c_binding/lsm_datatypes.cpp | 45 ++++++++++++++++------
c_binding/lsm_datatypes.hpp | 14 +++++++
plugin/sim/sim_lsmplugin | 20 +++++-----
plugin/simc/simc_lsmplugin.c | 6 +--
python_binding/lsm/_data.py | 8 ++--
test/tester.c | 7 ++--
tools/lsmcli/data_display.py | 3 ++
10 files changed, 109 insertions(+), 56 deletions(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 0c6c1ab..b934e72 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1078,13 +1078,24 @@ void LSM_DLL_EXPORT lsm_pool_free_space_set(lsm_pool *p, uint64_t free_space);
* @param status Pool status, bit field (See LSM_POOL_STATUS_XXXX constants)
* @param status_info Additional textual information on status
* @param system_id System id
+ * @param optiona_data Optional data
+ * @param plugin_data Reserved for plugin writer use
* @return LSM_ERR_OK on success, else error reason.
*/
lsm_pool LSM_DLL_EXPORT *lsm_pool_record_alloc(const char *id, const char *name,
uint64_t total_space,
uint64_t free_space,
uint64_t status, const char* status_info,
- const char *system_id);
+ const char *system_id,
+ lsm_optional_data *optional_data,
+ const char * plugin_data);
+
+/**
+ * Used to retrieve the plugin-private data for a specfic pool
+ * @param p Pool to retrieve plugin private data for
+ * @return NULL if donesn't exists, else data.
+ */
+const char *lsm_pool_plugin_data_get(lsm_pool *p);
/**
* Allocate the storage needed for and array of Initiator records.
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h b/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
index 61ebccf..1e8f0a5 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_pool.h
@@ -100,6 +100,13 @@ const char LSM_DLL_EXPORT *lsm_pool_status_info_get( lsm_pool *s );
*/
char LSM_DLL_EXPORT *lsm_pool_system_id_get( lsm_pool *p );
+/**
+ * Retrieve the optional data for the specified pool
+ * @param p Pool pointer
+ * @return Pointer to optional data
+ */
+lsm_optional_data *lsm_pool_optional_data_get( lsm_pool *p );
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 77e7bee..fbe88d2 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -114,11 +114,8 @@ lsm_disk *value_to_disk(Value &disk)
lsm_disk *rc = NULL;
if (is_expected_object(disk, "Disk")) {
lsm_optional_data *op = NULL;
-
- if( disk.asObject().find("optional_data") != disk.asObject().end() ) {
- Value opv = disk["optional_data"];
- op = value_to_optional_data(opv);
- }
+ Value opv = disk["optional_data"];
+ op = value_to_optional_data(opv);
std::map<std::string, Value> d = disk.asObject();
rc = lsm_disk_record_alloc(
@@ -151,10 +148,7 @@ Value disk_to_value(lsm_disk *disk)
d["num_of_blocks"] = Value(disk->block_count);
d["status"] = Value(disk->disk_status);
d["system_id"] = Value(disk->system_id);
-
- if( disk->optional_data ) {
- d["optional_data"] = optional_data_to_value(disk->optional_data);
- }
+ d["optional_data"] = optional_data_to_value(disk->optional_data);
return Value(d);
}
@@ -229,14 +223,20 @@ lsm_pool *value_to_pool(Value &pool)
lsm_pool *rc = NULL;
if (is_expected_object(pool, "Pool")) {
+ lsm_optional_data *op = NULL;
std::map<std::string, Value> i = pool.asObject();
+ Value opv = i["optional_data"];
+ op = value_to_optional_data(opv);
+
rc = lsm_pool_record_alloc(i["id"].asString().c_str(),
i["name"].asString().c_str(),
i["total_space"].asUint64_t(),
i["free_space"].asUint64_t(),
i["status"].asUint64_t(),
i["status_info"].asString().c_str(),
- i["system_id"].asString().c_str());
+ i["system_id"].asString().c_str(),
+ op,
+ i["plugin_data"].asC_str());
}
return rc;
}
@@ -253,6 +253,8 @@ Value pool_to_value(lsm_pool *pool)
p["status"] = Value(pool->status);
p["status_info"] = Value(pool->status_info);
p["system_id"] = Value(pool->system_id);
+ p["optional_data"] = optional_data_to_value(pool->optional_data);
+ p["plugin_data"] = Value(pool->plugin_data);
return Value(p);
}
return Value();
@@ -328,13 +330,9 @@ lsm_access_group *value_to_access_group( Value &group )
if( is_expected_object(group, "AccessGroup")) {
std::map<std::string, Value> vAg = group.asObject();
-
il = value_to_string_list(vAg["init_ids"]);
-
- if( group.asObject().find("optional_data") != group.asObject().end() ) {
- Value opv = group["optional_data"];
- op = value_to_optional_data(opv);
- }
+ Value opv = group["optional_data"];
+ op = value_to_optional_data(opv);
if( il ) {
ag = lsm_access_group_record_alloc(
@@ -345,11 +343,10 @@ lsm_access_group *value_to_access_group( Value &group )
vAg["system_id"].asString().c_str(),
op,
vAg["plugin_data"].asC_str());
-
- /* This stuff is copied in lsm_access_group_record_alloc */
- lsm_string_list_free(il);
- lsm_optional_data_record_free(op);
}
+ /* This stuff is copied in lsm_access_group_record_alloc */
+ lsm_string_list_free(il);
+ lsm_optional_data_record_free(op);
}
return ag;
}
@@ -365,10 +362,7 @@ Value access_group_to_value( lsm_access_group *group )
ag["init_type"] = Value(group->init_type);
ag["system_id"] = Value(group->system_id);
ag["plugin_data"] = Value(group->plugin_data);
-
- if( group->optional_data ) {
- ag["optional_data"] = optional_data_to_value(group->optional_data);
- }
+ ag["optional_data"] = optional_data_to_value(group->optional_data);
return Value(ag);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 442a989..fda2f08 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -52,6 +52,14 @@ extern "C" {
#define LSM_DEFAULT_PLUGIN_DIR "/var/run/lsm/ipc"
+/* We would certainly expand this to encompass the entire function */
+#define MEMBER_GET(x, validation, member, error) \
+ if( validation(x) ) { \
+ return x->member; \
+ } else { \
+ return error; \
+ }
+
int lsm_string_list_append(lsm_string_list *sl, const char *value)
{
int rc = LSM_ERR_INVALID_SL;
@@ -496,7 +504,7 @@ CREATE_ALLOC_ARRAY_FUNC(lsm_pool_record_array_alloc, lsm_pool *)
lsm_pool *lsm_pool_record_alloc(const char *id, const char *name,
uint64_t totalSpace, uint64_t freeSpace, uint64_t status, const char* status_info,
- const char *system_id)
+ const char *system_id, lsm_optional_data* optional_data, const char * plugin_data)
{
lsm_pool *rc = (lsm_pool *)calloc(1, sizeof(lsm_pool));
if (rc) {
@@ -508,8 +516,15 @@ lsm_pool *lsm_pool_record_alloc(const char *id, const char *name,
rc->status = status;
rc->status_info = strdup(status_info);
rc->system_id = strdup(system_id);
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
- if( !rc->id || !rc->name || !rc->system_id || !rc->status_info ) {
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }
+
+ if( !rc->id || !rc->name || !rc->system_id || !rc->status_info ||
+ (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_pool_record_free(rc);
rc = NULL;
}
@@ -532,7 +547,9 @@ lsm_pool * lsm_pool_record_copy( lsm_pool *toBeCopied)
toBeCopied->free_space,
toBeCopied->status,
toBeCopied->status_info,
- toBeCopied->system_id);
+ toBeCopied->system_id,
+ toBeCopied->optional_data,
+ toBeCopied->plugin_data);
}
return NULL;
}
@@ -560,6 +577,12 @@ int lsm_pool_record_free(lsm_pool *p)
free(p->system_id);
p->system_id = NULL;
}
+
+ lsm_optional_data_record_free(p->optional_data);
+ p->optional_data = NULL;
+ free(p->plugin_data);
+ p->plugin_data = NULL;
+
free(p);
return LSM_ERR_OK;
}
@@ -609,7 +632,7 @@ uint64_t lsm_pool_status_get( lsm_pool *p )
return UINT64_MAX;
}
-const char LSM_DLL_EXPORT *lsm_pool_status_info_get( lsm_pool *p )
+const char *lsm_pool_status_info_get( lsm_pool *p )
{
if (LSM_IS_POOL(p)) {
return p->status_info;
@@ -625,6 +648,12 @@ char *lsm_pool_system_id_get( lsm_pool *p )
return NULL;
}
+MEMBER_FUNC_GET(lsm_optional_data *, lsm_pool_optional_data_get, lsm_pool *p,
+ p, LSM_IS_POOL, optional_data, NULL)
+
+MEMBER_FUNC_GET(const char *, lsm_pool_plugin_data_get, lsm_pool *p,
+ p, LSM_IS_POOL, plugin_data, NULL)
+
CREATE_ALLOC_ARRAY_FUNC(lsm_initiator_record_array_alloc, lsm_initiator *)
lsm_initiator *lsm_initiator_record_alloc(lsm_initiator_type idType, const char* id,
@@ -920,14 +949,6 @@ CREATE_FREE_ARRAY_FUNC( lsm_disk_record_array_free, lsm_disk_record_free,
lsm_disk *, LSM_ERR_INVALID_DISK)
/* We would certainly expand this to encompass the entire function */
-#define MEMBER_GET(x, validation, member, error) \
- if( validation(x) ) { \
- return x->member; \
- } else { \
- return error; \
- }
-
-/* We would certainly expand this to encompass the entire function */
#define MEMBER_SET_REF(x, validation, member, value, alloc_func, free_func, error) \
if( validation(x) ) { \
if(x->member) { \
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index 5b134dc..521c23c 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -31,6 +31,18 @@
extern "C" {
#endif
+/* Helper macros to ease getter construction */
+
+/* Implementation for generic getter */
+#define MEMBER_FUNC_GET(return_type, name, param_sig, x, validation, member, error) \
+return_type name( param_sig ) {\
+ if( validation(x) ) { \
+ return x->member; \
+ } else { \
+ return error; \
+ } \
+} \
+
#define MAGIC_CHECK(obj, m) ((obj) && \
((obj)->magic==(m) ))
#define LSM_DEL_MAGIC(obj) ((obj & 0x0FFFFFFF) | 0xD0000000)
@@ -72,6 +84,8 @@ struct LSM_DLL_LOCAL _lsm_pool {
uint64_t status; /**< Status of pool */
char *status_info; /**< Status info for pool */
char *system_id; /**< system id */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Private data for plugin */
};
diff --git a/plugin/sim/sim_lsmplugin b/plugin/sim/sim_lsmplugin
index 9fce142..cb47f2a 100755
--- a/plugin/sim/sim_lsmplugin
+++ b/plugin/sim/sim_lsmplugin
@@ -20,17 +20,17 @@
import sys
import syslog
-try:
- from lsm import PluginRunner
- from lsm.plugin.sim.simulator import SimPlugin
+#try:
+from lsm import PluginRunner
+from lsm.plugin.sim.simulator import SimPlugin
- if __name__ == '__main__':
- PluginRunner(SimPlugin, sys.argv).run()
-except Exception as e:
+if __name__ == '__main__':
+ PluginRunner(SimPlugin, sys.argv).run()
+#except Exception as e:
#This should be quite rare, but when it does happen this is pretty
#key in understanding what happened, especially when it happens when
#running from the daemon.
- msg = "Exception: %s\n" % str(e)
- syslog.syslog(syslog.LOG_ERR, msg)
- sys.stderr.write(msg)
- sys.exit(1)
+# msg = "Exception: %s\n" % str(e)
+# syslog.syslog(syslog.LOG_ERR, msg)
+# sys.stderr.write(msg)
+# sys.exit(1)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index f242a7d..96c1aad 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -1008,7 +1008,7 @@ static int _pool_create(lsm_plugin_ptr c, lsm_system *system,
/* Create the pool */
new_pool = lsm_pool_record_alloc(md5(pool_name), pool_name, size_bytes,
size_bytes, LSM_POOL_STATUS_OK, "",
- lsm_system_id_get(system));
+ lsm_system_id_get(system), NULL, NULL);
pool_to_store = lsm_pool_record_copy(new_pool);
key = strdup(lsm_pool_id_get(pool_to_store));
@@ -2518,7 +2518,7 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
p = lsm_pool_record_alloc("POOL_3", "lsm_test_aggr",
UINT64_MAX, UINT64_MAX,
LSM_POOL_STATUS_OK, "",
- sys_id);
+ sys_id, NULL, NULL);
if( p ) {
pd->pools = g_hash_table_new_full(g_str_hash, g_str_equal, free,
free_pool_record);
@@ -2531,7 +2531,7 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
p = lsm_pool_record_alloc(name, name, UINT64_MAX,
UINT64_MAX, LSM_POOL_STATUS_OK, "",
- sys_id);
+ sys_id, NULL, NULL);
if( p ) {
g_hash_table_insert(pd->pools, strdup(lsm_pool_id_get(p)), p);
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 18a22a9..50d43ea 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -22,7 +22,6 @@ try:
except ImportError:
import json
-from datetime import datetime
from json.decoder import WHITESPACE
from lsm import LsmError, ErrorNumber
from _common import get_class, sh, default_property
@@ -486,6 +485,7 @@ The lsm.System class does not have class methods.
@default_property('status_info', doc="Text explaining status")
@default_property('system_id', doc="System identifier")
@default_property("optional_data", doc="Optional data")
+@default_property("plugin_data", doc="Plug-in private data")
class Pool(IData):
"""
Pool specific information
@@ -679,7 +679,8 @@ class Pool(IData):
'element_type', 'thinp_type']
def __init__(self, _id, _name, _total_space, _free_space, _status,
- _status_info, _system_id, _optional_data=None):
+ _status_info, _system_id, _optional_data=None,
+ _plugin_data=None):
self._id = _id # Identifier
self._name = _name # Human recognisable name
self._total_space = _total_space # Total size
@@ -687,6 +688,7 @@ class Pool(IData):
self._status = _status # Status of pool.
self._status_info = _status_info # Additional status text of pool
self._system_id = _system_id # System id this pool belongs
+ self._plugin_data = _plugin_data # Plugin private data
if _optional_data is None:
self._optional_data = OptionalData()
@@ -824,7 +826,7 @@ class OptionalData(IData):
return self._values[key]
def set(self, key, value):
- self._values[key] = value
+ self._values[str(key)] = str(value)
class Capabilities(IData):
diff --git a/test/tester.c b/test/tester.c
index f882a63..6a288da 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -228,7 +228,8 @@ lsm_pool *wait_for_job_pool(lsm_connect *c, char **job_id)
do {
rc = lsm_job_status_pool_get(c, *job_id, &status, &pc, &pool, LSM_FLAG_RSVD);
- fail_unless( LSM_ERR_OK == rc, "rc = %d (%s)", rc, error(lsm_error_last_get(c)));
+ fail_unless( LSM_ERR_OK == rc, "rc = %d (%s) plugin=%d", rc,
+ error(lsm_error_last_get(c)), which_plugin);
printf("POOL: Job %s in progress, %d done, status = %d\n", *job_id, pc, status);
usleep(POLL_SLEEP);
@@ -2514,7 +2515,8 @@ START_TEST(test_pool_create)
if( LSM_ERR_JOB_STARTED == rc ) {
pool = wait_for_job_pool(c, &job);
} else {
- fail_unless(LSM_ERR_OK == rc, "rc %d", rc);
+ fail_unless(LSM_ERR_OK == rc, "rc %d which_plugin %d", rc,
+ which_plugin);
}
lsm_pool_record_free(pool);
@@ -3102,7 +3104,6 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
- tcase_add_test(basic, test_access_groups);
tcase_add_test(basic, test_search_fs);
tcase_add_test(basic, test_search_access_groups);
tcase_add_test(basic, test_search_disks);
diff --git a/tools/lsmcli/data_display.py b/tools/lsmcli/data_display.py
index e9b7c19..d9424dc 100644
--- a/tools/lsmcli/data_display.py
+++ b/tools/lsmcli/data_display.py
@@ -49,6 +49,7 @@ def _txt_a(txt, append):
def _bit_map_to_str(bit_map, conv_dict):
rc = ''
+ bit_map = int(bit_map)
for cur_enum in conv_dict.keys():
if cur_enum & bit_map:
rc = _txt_a(rc, conv_dict[cur_enum])
@@ -59,6 +60,8 @@ def _bit_map_to_str(bit_map, conv_dict):
def _enum_type_to_str(int_type, conv_dict):
rc = ''
+ int_type = int(int_type)
+
if int_type in conv_dict.keys():
return conv_dict[int_type]
return 'Unknown(%d)' % int_type
--
1.8.2.1
1.8.2.1