Discussion:
[Libstoragemgmt-devel] [PATCH 4/6] C API: Remove duplicate & un-used fs structure
Tony Asleson
2014-06-06 23:22:41 UTC
Permalink
Not sure how this managed to stay in the code base
without anyone noticing, including myself.

Signed-off-by: Tony Asleson <***@redhat.com>
---
.../include/libstoragemgmt/libstoragemgmt_types.h | 6 ----
c_binding/lsm_datatypes.hpp | 41 +++++++---------------
2 files changed, 13 insertions(+), 34 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_types.h b/c_binding/include/libstoragemgmt/libstoragemgmt_types.h
index 74811b4..eb22df4 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_types.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_types.h
@@ -70,12 +70,6 @@ typedef struct _lsm_storage_capabilities lsm_storage_capabilities;
typedef struct _lsm_access_group lsm_access_group;

/**
- * Opaque data type for file system
- */
-typedef struct _lsm_file_system lsm_file_system;
-
-
-/**
* Opaque data type for nfs exports
*/
typedef struct _lsm_nfs_export lsm_nfs_export;
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index ef3a6ae..4a5d098 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -120,24 +120,6 @@ struct _lsm_access_group {
char *plugin_data; /**< Reserved for the plugin to use */
};

-#define LSM_FILE_SYSTEM_MAGIC 0xAA7A0004
-#define LSM_IS_FILE_SYSTEM(obj) MAGIC_CHECK(obj, LSM_FILE_SYSTEM_MAGIC)
-
-/**
- * Structure for file systems
- */
-struct _lsm_file_system {
- uint32_t magic; /**< Used for verification */
- char *id; /**< Id */
- char *name; /**< Name */
- uint64_t total_space; /**< Total space */
- uint64_t free_space; /**< Free space */
- char *pool_id; /**< Pool ID */
- char *system_id; /**< System ID */
- lsm_optional_data *optional_data; /**< Optional data */
- char *plugin_data; /**< Reserved for the plugin to use */
-};
-
#define LSM_SNAP_SHOT_MAGIC 0xAA7A0005
#define LSM_IS_SNAP_SHOT(obj) MAGIC_CHECK(obj, LSM_SNAP_SHOT_MAGIC)

@@ -281,18 +263,21 @@ struct LSM_DLL_LOCAL _lsm_string_list {
GPtrArray *values;
};

+/**
+ * Structure for File system information.
+ */
#define LSM_FS_MAGIC 0xAA7A000E
-#define LSM_IS_FS(obj) MAGIC_CHECK(obj, LSM_FS_MAGIC)
+#define LSM_IS_FS(obj) MAGIC_CHECK(obj, LSM_FS_MAGIC)
struct LSM_DLL_LOCAL _lsm_fs {
- uint32_t magic;
- char *id;
- char *name;
- char *pool_id;
- uint64_t total_space;
- uint64_t free_space;
- char *system_id;
- lsm_optional_data *optional_data;
- char *plugin_data;
+ uint32_t magic; /**< Magic, used for struct validation */
+ char *id; /**< Id */
+ char *name; /**< Name */
+ char *pool_id; /**< Pool ID */
+ uint64_t total_space; /**< Total space */
+ uint64_t free_space; /**< Free space */
+ char *system_id; /**< System ID */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Plugin private data */
};

#define LSM_SS_MAGIC 0xAA7A000F
--
1.8.2.1
Tony Asleson
2014-06-06 23:22:39 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 15 ++++++++++++--
.../libstoragemgmt/libstoragemgmt_volumes.h | 8 ++++++++
c_binding/lsm_convert.cpp | 16 ++++++++++++---
c_binding/lsm_datatypes.cpp | 24 ++++++++++++++++++----
c_binding/lsm_datatypes.hpp | 2 ++
plugin/simc/simc_lsmplugin.c | 4 ++--
python_binding/lsm/_data.py | 8 +++++++-
7 files changed, 65 insertions(+), 12 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index b934e72..5deca6d 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1158,15 +1158,26 @@ lsm_disk LSM_DLL_EXPORT *lsm_disk_record_alloc(const char *id, const char *name,
* @param status Volume status
* @param system_id System id
* @param pool_id Pool id this volume is created from
+ * @param optional_data Optional data
+ * @param plugin_data Private data for plugin use
* @return Allocated memory or NULL on error.
*/
-lsm_volume LSM_DLL_EXPORT *lsm_volume_record_alloc( const char *id,
+lsm_volume LSM_DLL_EXPORT *lsm_volume_record_alloc(const char *id,
const char *name, const char *vpd83,
uint64_t block_size,
uint64_t number_of_blocks,
uint32_t status,
const char *system_id,
- const char *pool_id);
+ const char *pool_id,
+ lsm_optional_data* optional_data,
+ const char* plugin_data);
+
+/**
+ * Retrieve the private plug-in data from the volume record.
+ * @param v Volume pointer
+ * @return Private data, else NULL if it doesn't exist.
+ */
+const char LSM_DLL_EXPORT *lsm_volume_plugin_data_get( lsm_volume *v);

/**
* Allocate the storage needed for and array of System records.
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
index 303d287..5d77844 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
@@ -107,6 +107,14 @@ char LSM_DLL_EXPORT *lsm_volume_system_id_get( lsm_volume *v);
*/
char LSM_DLL_EXPORT *lsm_volume_pool_id_get( lsm_volume *v);

+
+/**
+ * Retrieves the optional data for a volume.
+ * @param v Volume ptr.
+ * @return Optional_data, else NULL if not present.
+ */
+lsm_optional_data LSM_DLL_EXPORT *lsm_volume_optional_data_get( lsm_volume *v );
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index fbe88d2..4d28135 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -41,15 +41,23 @@ lsm_volume *value_to_volume(Value &vol)

if (is_expected_object(vol, "Volume")) {
std::map<std::string, Value> v = vol.asObject();
- rc = lsm_volume_record_alloc(
- v["id"].asString().c_str(),
+ lsm_optional_data *op = NULL;
+ Value opv = v["optional_data"];
+ op = value_to_optional_data(opv);
+
+ rc = lsm_volume_record_alloc(v["id"].asString().c_str(),
v["name"].asString().c_str(),
v["vpd83"].asString().c_str(),
v["block_size"].asUint64_t(),
v["num_of_blocks"].asUint64_t(),
v["status"].asUint32_t(),
v["system_id"].asString().c_str(),
- v["pool_id"].asString().c_str());
+ v["pool_id"].asString().c_str(),
+ op,
+ v["plugin_data"].asC_str());
+
+ /* Optional data gets copied so free */
+ lsm_optional_data_record_free(op);
}

return rc;
@@ -68,6 +76,8 @@ Value volume_to_value(lsm_volume *vol)
v["status"] = Value(vol->status);
v["system_id"] = Value(vol->system_id);
v["pool_id"] = Value(vol->pool_id);
+ v["optional_data"] = optional_data_to_value(vol->optional_data);
+ v["plugin_data"] = Value(vol->plugin_data);
return Value(v);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index fda2f08..26335a0 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -731,9 +731,10 @@ CREATE_ALLOC_ARRAY_FUNC(lsm_volume_record_array_alloc, lsm_volume *)
lsm_volume * lsm_volume_record_alloc(const char *id, const char *name,
const char *vpd83, uint64_t blockSize,
uint64_t numberOfBlocks,
- uint32_t status, const char *system_id, const char *pool_id)
+ uint32_t status, const char *system_id, const char *pool_id,
+ lsm_optional_data* optional_data, const char* plugin_data)
{
- lsm_volume *rc = (lsm_volume *)malloc(sizeof(lsm_volume));
+ lsm_volume *rc = (lsm_volume *)calloc(1, sizeof(lsm_volume));
if (rc) {
rc->magic = LSM_VOL_MAGIC;
rc->id = strdup(id);
@@ -744,9 +745,15 @@ lsm_volume * lsm_volume_record_alloc(const char *id, const char *name,
rc->status = status;
rc->system_id = strdup(system_id);
rc->pool_id = strdup(pool_id);
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
+
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }

if( !rc->id || !rc->name || !rc->vpd83 || !rc->system_id ||
- !rc->pool_id) {
+ !rc->pool_id || (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_volume_record_free(rc);
rc = NULL;
}
@@ -868,7 +875,8 @@ lsm_volume *lsm_volume_record_copy(lsm_volume *vol)
if( LSM_IS_VOL(vol) ) {
rc = lsm_volume_record_alloc(vol->id, vol->name, vol->vpd83,
vol->block_size, vol->number_of_blocks,
- vol->status, vol->system_id, vol->pool_id);
+ vol->status, vol->system_id, vol->pool_id,
+ vol->optional_data, vol->plugin_data);
}
return rc;
}
@@ -903,6 +911,11 @@ int lsm_volume_record_free(lsm_volume *v)
v->pool_id = NULL;
}

+ lsm_optional_data_record_free(v->optional_data);
+ v->optional_data = NULL;
+ free(v->plugin_data);
+ v->plugin_data = NULL;
+
free(v);
return LSM_ERR_OK;
}
@@ -1015,6 +1028,9 @@ char *lsm_volume_pool_id_get( lsm_volume *v)
MEMBER_GET(v, LSM_IS_VOL, pool_id, NULL);
}

+MEMBER_FUNC_GET(lsm_optional_data *, lsm_volume_optional_data_get, lsm_volume *v, v, LSM_IS_VOL, optional_data, NULL)
+MEMBER_FUNC_GET(const char *, lsm_volume_plugin_data_get, lsm_volume *v, v, LSM_IS_VOL, plugin_data, NULL)
+
const char *lsm_disk_id_get( lsm_disk *d)
{
MEMBER_GET(d, LSM_IS_DISK, id, NULL);
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index 521c23c..9ac70c1 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -67,6 +67,8 @@ struct LSM_DLL_LOCAL _lsm_volume {
uint32_t status; /**< Status */
char *system_id; /**< System this volume belongs */
char *pool_id; /**< Pool this volume is derived from */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Private data for plugin */
};

#define LSM_POOL_MAGIC 0xAA7A0001
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 96c1aad..cfb050b 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -805,7 +805,7 @@ static int volume_create(lsm_plugin_ptr c, lsm_pool *pool,

lsm_volume *v = lsm_volume_record_alloc(id, volume_name,
"VPD", BS, allocated_size/BS, 0, sys_id,
- lsm_pool_id_get(pool));
+ lsm_pool_id_get(pool), NULL, NULL);

lsm_volume *to_store = lsm_volume_record_copy(v);
struct allocated_volume *av = malloc(sizeof(struct allocated_volume));
@@ -933,7 +933,7 @@ static int volume_resize(lsm_plugin_ptr c, lsm_volume *volume,
lsm_volume_vpd83_get(v),
lsm_volume_block_size_get(v),
resized_size/BS, 0, sys_id,
- lsm_volume_pool_id_get(volume));
+ lsm_volume_pool_id_get(volume), NULL, NULL);

if( vp ) {
av->v = vp;
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 50d43ea..97a56b0 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -336,6 +336,8 @@ class Disk(IData):
@default_property('status', doc="Enumerated volume status")
@default_property('system_id', "System identifier")
@default_property('pool_id', "Pool identifier")
+@default_property("optional_data", "Optional data")
+@default_property("plugin_data", "Private plugin data")
class Volume(IData):
"""
Represents a volume.
@@ -366,7 +368,8 @@ class Volume(IData):
return Volume.ACCESS_READ_ONLY

def __init__(self, _id, _name, _vpd83, _block_size, _num_of_blocks,
- _status, _system_id, _pool_id):
+ _status, _system_id, _pool_id, _optional_data=None,
+ _plugin_data=None):
self._id = _id # Identifier
self._name = _name # Human recognisable name
self._vpd83 = _vpd83 # SCSI page 83 unique ID
@@ -375,6 +378,9 @@ class Volume(IData):
self._status = _status # Status
self._system_id = _system_id # System id this volume belongs
self._pool_id = _pool_id # Pool id this volume belongs
+ self._optional_data = _check_opt_data(_optional_data,
+ Volume.OPT_PROPERTIES)
+ self._plugin_data = _plugin_data

@property
def size_bytes(self):
--
1.8.2.1
Tony Asleson
2014-06-06 23:22:38 UTC
Permalink
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.

V2: Remove debug code in simulator plugin

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/simc/simc_lsmplugin.c | 6 +--
python_binding/lsm/_data.py | 8 ++--
test/tester.c | 7 ++--
tools/lsmcli/data_display.py | 3 ++
9 files changed, 99 insertions(+), 46 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/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
Tony Asleson
2014-06-06 23:22:42 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_nfsexport.h | 32 +++++++++++++-------
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 7 +++++
c_binding/lsm_convert.cpp | 14 ++++++---
c_binding/lsm_datatypes.cpp | 35 ++++++++++++++++++----
c_binding/lsm_datatypes.hpp | 2 ++
plugin/simc/simc_lsmplugin.c | 2 +-
python_binding/lsm/_data.py | 9 +++++-
test/tester.c | 3 +-
8 files changed, 82 insertions(+), 22 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_nfsexport.h b/c_binding/include/libstoragemgmt/libstoragemgmt_nfsexport.h
index 389ca08..b42d9a5 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_nfsexport.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_nfsexport.h
@@ -44,18 +44,22 @@ extern "C" {
* @param anongid Group id that should be mapped to anonymous
* (Valid or set to ANON_UID_GID_NA)
* @param options String of options passed to array
+ * @param optional_data Optional data
+ * @param plugin_data Reserved for plug-in use
* @return Valid export pointer, else NULL on error.
*/
-lsm_nfs_export LSM_DLL_EXPORT * lsm_nfs_export_record_alloc( const char *id,
- const char *fs_id,
- const char *export_path,
- const char *auth,
- lsm_string_list *root,
- lsm_string_list *rw,
- lsm_string_list *ro,
- uint64_t anonuid,
- uint64_t anongid,
- const char *options);
+lsm_nfs_export LSM_DLL_EXPORT * lsm_nfs_export_record_alloc(const char *id,
+ const char *fs_id,
+ const char *export_path,
+ const char *auth,
+ lsm_string_list *root,
+ lsm_string_list *rw,
+ lsm_string_list *ro,
+ uint64_t anonuid,
+ uint64_t anongid,
+ const char *options,
+ lsm_optional_data * optional_data,
+ const char * plugin_data);

/**
* Allocated the memory for an array of NFS export records.
@@ -177,6 +181,14 @@ int LSM_DLL_EXPORT lsm_nfs_export_options_set( lsm_nfs_export *exp,
const char *value);


+/**
+ * Retrieve optional data.
+ * @param exp Valid nfs export
+ * @return optional data, else NULL
+ */
+lsm_optional_data LSM_DLL_EXPORT *lsm_nfs_export_optional_data_get(
+ lsm_nfs_export *exp );
+
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index f113d5c..d7a557e 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1411,6 +1411,13 @@ void LSM_DLL_EXPORT lsm_plug_nfs_export_search_filter(const char *search_key,
const char *search_value,
lsm_nfs_export *exports[],
uint32_t *count);
+
+/**
+ * Retrieve private data from nfs export record.
+ * @param exp Valid nfs export record
+ * @return Private data, else NULL
+ */
+const char LSM_DLL_EXPORT *lsm_nfs_export_plugin_data_get( lsm_nfs_export *exp);
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 7c636e8..51689e0 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -573,8 +573,11 @@ lsm_nfs_export *value_to_nfs_export(Value &exp)
}

if( ok ) {
- rc = lsm_nfs_export_record_alloc(
- i["id"].asC_str(),
+ lsm_optional_data *op = NULL;
+ Value opv = i["optional_data"];
+ op = value_to_optional_data(opv);
+
+ rc = lsm_nfs_export_record_alloc(i["id"].asC_str(),
i["fs_id"].asC_str(),
i["export_path"].asC_str(),
i["auth"].asC_str(),
@@ -583,8 +586,9 @@ lsm_nfs_export *value_to_nfs_export(Value &exp)
ro,
i["anonuid"].asUint64_t(),
i["anongid"].asUint64_t(),
- i["options"].asC_str()
- );
+ i["options"].asC_str(),
+ op,
+ i["plugin_data"].asC_str());

lsm_string_list_free(root);
lsm_string_list_free(rw);
@@ -609,6 +613,8 @@ Value nfs_export_to_value(lsm_nfs_export *exp)
f["anonuid"] = Value(exp->anonuid);
f["anongid"] = Value(exp->anongid);
f["options"] = Value(exp->options);
+ f["optional_data"] = optional_data_to_value(exp->optional_data);
+ f["plugin_data"] = Value(exp->plugin_data);
return Value(f);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 0313ba2..16e9fbe 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -1413,7 +1413,7 @@ uint64_t lsm_fs_ss_time_stamp_get(lsm_fs_ss *ss)
MEMBER_GET(ss, LSM_IS_SS, ts, 0);
}

-lsm_nfs_export *lsm_nfs_export_record_alloc( const char *id,
+lsm_nfs_export *lsm_nfs_export_record_alloc(const char *id,
const char *fs_id,
const char *export_path,
const char *auth,
@@ -1422,13 +1422,15 @@ lsm_nfs_export *lsm_nfs_export_record_alloc( const char *id,
lsm_string_list *ro,
uint64_t anonuid,
uint64_t anongid,
- const char *options)
+ const char *options,
+ lsm_optional_data * optional_data,
+ const char * plugin_data)
{
lsm_nfs_export *rc = NULL;

/* This is required */
if( fs_id ) {
- rc = (lsm_nfs_export *)malloc(sizeof(lsm_nfs_export));
+ rc = (lsm_nfs_export *)calloc(1, sizeof(lsm_nfs_export));
if( rc ) {
rc->magic = LSM_NFS_EXPORT_MAGIC;
rc->id = (id) ? strdup(id) : NULL;
@@ -1441,8 +1443,22 @@ lsm_nfs_export *lsm_nfs_export_record_alloc( const char *id,
rc->anonuid = anonuid;
rc->anongid = anongid;
rc->options = (options) ? strdup(options) : NULL;
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
+
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }

- if( !rc->fs_id ) {
+ if( !rc->id ||
+ !rc->fs_id ||
+ (export_path && !rc->export_path) ||
+ (auth && !rc->auth_type) ||
+ (root && !rc->root) ||
+ (rw && !rc->rw) ||
+ (ro && !rc->ro) ||
+ (options && !rc->options) ||
+ (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_nfs_export_record_free(rc);
rc = NULL;
}
@@ -1464,6 +1480,8 @@ int lsm_nfs_export_record_free( lsm_nfs_export *exp )
lsm_string_list_free(exp->rw);
lsm_string_list_free(exp->ro);
free(exp->options);
+ lsm_optional_data_record_free(exp->optional_data);
+ free(exp->plugin_data);

free(exp);
return LSM_ERR_OK;
@@ -1477,7 +1495,8 @@ lsm_nfs_export *lsm_nfs_export_record_copy( lsm_nfs_export *s )
if(LSM_IS_NFS_EXPORT(s)) {
return lsm_nfs_export_record_alloc(s->id, s->fs_id, s->export_path,
s->auth_type, s->root, s->rw, s->ro, s->anonuid,
- s->anongid, s->options);
+ s->anongid, s->options, s->optional_data,
+ s->plugin_data);
}
return NULL;
}
@@ -1596,6 +1615,12 @@ int lsm_nfs_export_options_set( lsm_nfs_export *exp, const char *value )
LSM_ERR_INVALID_NFS);
}

+MEMBER_FUNC_GET(lsm_optional_data *, lsm_nfs_export_optional_data_get,
+ lsm_nfs_export *exp, exp, LSM_IS_NFS_EXPORT, optional_data, NULL)
+
+MEMBER_FUNC_GET(const char *, lsm_nfs_export_plugin_data_get,
+ lsm_nfs_export *exp, exp, LSM_IS_NFS_EXPORT, plugin_data, NULL)
+
lsm_capability_value_type lsm_capability_get(lsm_storage_capabilities *cap,
lsm_capability_type t)
{
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index 4a5d098..f526495 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -151,6 +151,8 @@ struct _lsm_nfs_export {
uint64_t anonuid; /**< Uid that should map to anonymous */
uint64_t anongid; /**< Gid that should map to anonymous */
char *options; /**< Options */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Reserved for the plugin to use */
};

#define LSM_BLOCK_RANGE_MAGIC 0xAA7A0007
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 381d725..78bf1d4 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -2378,7 +2378,7 @@ static int nfs_export_create( lsm_plugin_ptr c,
ro_list,
anon_uid,
anon_gid,
- options);
+ options, NULL, NULL);

lsm_nfs_export *value = lsm_nfs_export_record_copy(*exported);

diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 8a97b50..0395061 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -755,13 +755,16 @@ class FsSnapshot(IData):
@default_property('anonuid', doc="UID for anonymous user id")
@default_property('anongid', doc="GID for anonymous group id")
@default_property('options', doc="String containing advanced options")
+@default_property('optional_data', doc="Optional data")
+@default_property('plugin_data', doc="Plugin private data")
class NfsExport(IData):
SUPPORTED_SEARCH_KEYS = ['id', 'fs_id']
ANON_UID_GID_NA = -1
ANON_UID_GID_ERROR = (ANON_UID_GID_NA - 1)

def __init__(self, _id, _fs_id, _export_path, _auth, _root, _rw, _ro,
- _anonuid, _anongid, _options):
+ _anonuid, _anongid, _options, _optional_data=None,
+ _plugin_data=None):
assert (_fs_id is not None)
assert (_export_path is not None)

@@ -775,6 +778,10 @@ class NfsExport(IData):
self._anonuid = _anonuid # uid for anonymous user id
self._anongid = _anongid # gid for anonymous group id
self._options = _options # NFS options
+ self._optional_data = _check_opt_data(_optional_data,
+ self.OPT_PROPERTIES)
+ self._plugin_data = _plugin_data
+


@default_property('src_block', doc="Source logical block address")
diff --git a/test/tester.c b/test/tester.c
index d9b8d8a..07136bf 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2346,6 +2346,7 @@ START_TEST(test_nfs_export_funcs)
uint64_t anonuid = 1021;
uint64_t anongid = 1000;
const char options[] = "vendor_specific_option";
+ const char p_data[] = "plug-in private data";
char rstring[33];


@@ -2364,7 +2365,7 @@ START_TEST(test_nfs_export_funcs)


lsm_nfs_export *export = lsm_nfs_export_record_alloc(id, fs_id, export_path, auth,
- root, rw, ro, anonuid, anongid, options);
+ root, rw, ro, anonuid, anongid, options, NULL, p_data);

lsm_nfs_export *copy = lsm_nfs_export_record_copy(export);
--
1.8.2.1
Tony Asleson
2014-06-06 23:22:40 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../include/libstoragemgmt/libstoragemgmt_fs.h | 6 +++++
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 15 ++++++++++--
c_binding/lsm_convert.cpp | 12 +++++++++-
c_binding/lsm_datatypes.cpp | 28 ++++++++++++++++++----
c_binding/lsm_datatypes.hpp | 4 ++++
plugin/simc/simc_lsmplugin.c | 4 ++--
python_binding/lsm/_data.py | 7 +++++-
test/tester.c | 4 +---
8 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_fs.h b/c_binding/include/libstoragemgmt/libstoragemgmt_fs.h
index 788c7ec..5524603 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_fs.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_fs.h
@@ -90,6 +90,12 @@ uint64_t LSM_DLL_EXPORT lsm_fs_total_space_get(lsm_fs *fs);
*/
uint64_t LSM_DLL_EXPORT lsm_fs_free_space_get(lsm_fs *fs);

+/**
+ * Retrieves the optional data for a file system.
+ * @param fs fs ptr.
+ * @return Optional_data, else NULL if not present.
+ */
+lsm_optional_data LSM_DLL_EXPORT *lsm_fs_optional_data_get( lsm_fs *fs );

#ifdef __cplusplus
}
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 5deca6d..f113d5c 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1242,13 +1242,17 @@ void LSM_DLL_EXPORT lsm_access_group_initiator_id_set( lsm_access_group *group,
* @param free_space Free space
* @param pool_id Pool id
* @param system_id System id
+ * @param optional_data Optional data
+ * @param plugin_data Reserved for plug-in use only
* @return lsm_fs, NULL on error
*/
-lsm_fs LSM_DLL_EXPORT *lsm_fs_record_alloc( const char *id, const char *name,
+lsm_fs LSM_DLL_EXPORT *lsm_fs_record_alloc(const char *id, const char *name,
uint64_t total_space,
uint64_t free_space,
const char *pool_id,
- const char *system_id);
+ const char *system_id,
+ lsm_optional_data * optional_data,
+ const char* plugin_data);

/**
* Allocates the memory for the array of file system records.
@@ -1258,6 +1262,13 @@ lsm_fs LSM_DLL_EXPORT *lsm_fs_record_alloc( const char *id, const char *name,
lsm_fs LSM_DLL_EXPORT **lsm_fs_record_array_alloc( uint32_t size );

/**
+ * Used to retrieve the plug-in private data for a specific pool
+ * @param p Pool to retrieve plug-in private data for
+ * @return NULL if doesn't exist, else data.
+ */
+const char *lsm_fs_plugin_data_get(lsm_fs *fs);
+
+/**
* Allocates the memory for single snap shot record.
* @param id ID
* @param name Name
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 4d28135..7c636e8 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -479,12 +479,20 @@ lsm_fs *value_to_fs(Value &fs)
lsm_fs *rc = NULL;
if( is_expected_object(fs, "FileSystem") ) {
std::map<std::string, Value> f = fs.asObject();
+ lsm_optional_data *op = NULL;
+ Value opv = f["optional_data"];
+ op = value_to_optional_data(opv);
+
rc = lsm_fs_record_alloc(f["id"].asString().c_str(),
f["name"].asString().c_str(),
f["total_space"].asUint64_t(),
f["free_space"].asUint64_t(),
f["pool_id"].asString().c_str(),
- f["system_id"].asString().c_str());
+ f["system_id"].asString().c_str(),
+ op,
+ f["plugin_data"].asC_str());
+
+ lsm_optional_data_record_free(op);
}
return rc;
}
@@ -500,6 +508,8 @@ Value fs_to_value(lsm_fs *fs)
f["free_space"] = Value(fs->free_space);
f["pool_id"] = Value(fs->pool_id);
f["system_id"] = Value(fs->system_id);
+ f["optional_data"] = optional_data_to_value(fs->optional_data);
+ f["plugin_data"] = Value(fs->plugin_data);
return Value(f);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 26335a0..0313ba2 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -1250,14 +1250,16 @@ uint64_t lsm_block_range_block_count_get(lsm_block_range *br)
MEMBER_GET(br, LSM_IS_BLOCK_RANGE, block_count, 0);
}

-lsm_fs * lsm_fs_record_alloc( const char *id, const char *name,
+lsm_fs * lsm_fs_record_alloc(const char *id, const char *name,
uint64_t total_space,
uint64_t free_space,
const char *pool_id,
- const char *system_id)
+ const char *system_id,
+ lsm_optional_data *optional_data,
+ const char* plugin_data)
{
lsm_fs *rc = NULL;
- rc = (lsm_fs *)malloc(sizeof(lsm_fs));
+ rc = (lsm_fs *)calloc(1, sizeof(lsm_fs));
if( rc ) {
rc->magic = LSM_FS_MAGIC;
rc->id = strdup(id);
@@ -1266,8 +1268,15 @@ lsm_fs * lsm_fs_record_alloc( const char *id, const char *name,
rc->system_id = strdup(system_id);
rc->total_space = total_space;
rc->free_space = free_space;
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
+
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }

- if( !rc->id || !rc->name || !rc->pool_id || !rc->system_id ) {
+ if( !rc->id || !rc->name || !rc->pool_id || !rc->system_id ||
+ (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_fs_record_free(rc);
rc = NULL;
}
@@ -1283,6 +1292,8 @@ int lsm_fs_record_free( lsm_fs *fs)
free(fs->name);
free(fs->pool_id);
free(fs->system_id);
+ lsm_optional_data_record_free(fs->optional_data);
+ free(fs->plugin_data);
free(fs);
return LSM_ERR_OK;
}
@@ -1297,7 +1308,8 @@ lsm_fs *lsm_fs_record_copy(lsm_fs *source)
dest = lsm_fs_record_alloc(source->id, source->name,
source->total_space, source->free_space,
source->pool_id,
- source->system_id);
+ source->system_id, source->optional_data,
+ source->plugin_data);
}
return dest;
}
@@ -1335,6 +1347,12 @@ uint64_t lsm_fs_free_space_get(lsm_fs *fs)
MEMBER_GET(fs, LSM_IS_FS, free_space, 0);
}

+MEMBER_FUNC_GET(lsm_optional_data *, lsm_fs_optional_data_get, lsm_fs *fs,
+ fs, LSM_IS_POOL, optional_data, NULL)
+
+MEMBER_FUNC_GET(const char *, lsm_fs_plugin_data_get, lsm_fs *fs,
+ fs, LSM_IS_POOL, plugin_data, NULL)
+
lsm_fs_ss * lsm_fs_ss_record_alloc( const char *id, const char *name,
uint64_t ts)
{
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index 9ac70c1..ef3a6ae 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -134,6 +134,8 @@ struct _lsm_file_system {
uint64_t free_space; /**< Free space */
char *pool_id; /**< Pool ID */
char *system_id; /**< System ID */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Reserved for the plugin to use */
};

#define LSM_SNAP_SHOT_MAGIC 0xAA7A0005
@@ -289,6 +291,8 @@ struct LSM_DLL_LOCAL _lsm_fs {
uint64_t total_space;
uint64_t free_space;
char *system_id;
+ lsm_optional_data *optional_data;
+ char *plugin_data;
};

#define LSM_SS_MAGIC 0xAA7A000F
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index cfb050b..381d725 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -1943,7 +1943,7 @@ static int fs_create(lsm_plugin_ptr c, lsm_pool *pool, const char *name,

/* Make a copy to store and a copy to hand back to caller */
lsm_fs *tfs = lsm_fs_record_alloc(id, name, allocated_size,
- allocated_size, lsm_pool_id_get(pool), sys_id);
+ allocated_size, lsm_pool_id_get(pool), sys_id, NULL, NULL);
new_fs = lsm_fs_record_copy(tfs);

/* Allocate the memory to keep the associations */
@@ -2017,7 +2017,7 @@ static int fs_resize(lsm_plugin_ptr c, lsm_fs *fs,
new_size_bytes,
new_size_bytes,
lsm_fs_pool_id_get(tfs),
- lsm_fs_system_id_get(tfs));
+ lsm_fs_system_id_get(tfs), NULL, NULL);
lsm_fs *returned_copy = lsm_fs_record_copy(resized);

if( resized && returned_copy ) {
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 97a56b0..8a97b50 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -717,17 +717,22 @@ class Pool(IData):
@default_property('free_space', doc="Free space available")
@default_property('pool_id', doc="What pool the file system resides on")
@default_property('system_id', doc="System ID")
+@default_property("optional_data", "Optional data")
+@default_property("plugin_data", "Private plugin data")
class FileSystem(IData):
SUPPORTED_SEARCH_KEYS = ['id', 'system_id', 'pool_id']

def __init__(self, _id, _name, _total_space, _free_space, _pool_id,
- _system_id):
+ _system_id, _optional_data=None, _plugin_data=None):
self._id = _id
self._name = _name
self._total_space = _total_space
self._free_space = _free_space
self._pool_id = _pool_id
self._system_id = _system_id
+ self._optional_data = _check_opt_data(_optional_data,
+ self.OPT_PROPERTIES)
+ self._plugin_data = _plugin_data


@default_property('id', doc="Unique identifier")
diff --git a/test/tester.c b/test/tester.c
index 6a288da..d9b8d8a 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -3032,9 +3032,7 @@ START_TEST(test_search_fs)
fail_unless(LSM_ERR_OK == rc);
}

- if( LSM_ERR_OK == rc ) {
- lsm_fs_record_free(fs);
- }
+ lsm_fs_record_free(fs);
fs = NULL;
}
--
1.8.2.1
Tony Asleson
2014-06-06 23:22:43 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 19 +++++++++++---
.../libstoragemgmt/libstoragemgmt_systems.h | 9 ++++++-
c_binding/lsm_convert.cpp | 14 ++++++++--
c_binding/lsm_datatypes.cpp | 30 ++++++++++++++++++----
c_binding/lsm_datatypes.hpp | 2 ++
plugin/simc/simc_lsmplugin.c | 2 +-
python_binding/lsm/_data.py | 8 +++++-
7 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index d7a557e..777fba7 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1192,12 +1192,23 @@ lsm_system LSM_DLL_EXPORT **lsm_system_record_array_alloc( uint32_t size );
* @param[in] name System name (human readable)
* @param[in] status Status of the system
* @oaram[in] status_info Additional text for status
+ * @param[in] optional_data Optional data
+ * @param[in] plugin_data Private plugin data
* @return Allocated memory or NULL on error.
*/
-lsm_system LSM_DLL_EXPORT *lsm_system_record_alloc( const char *id,
- const char *name,
- uint32_t status,
- const char *status_info);
+lsm_system LSM_DLL_EXPORT *lsm_system_record_alloc(const char *id,
+ const char *name,
+ uint32_t status,
+ const char *status_info,
+ lsm_optional_data *optional_data,
+ const char* plugin_data);
+
+/**
+ * Retrieve plugin private data
+ * @param s System
+ * @return Optional data, NULL if none exist
+ */
+const char LSM_DLL_EXPORT *lsm_system_plugin_data_get( lsm_system *s);

/**
* Allocates storage for Access_group array
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_systems.h b/c_binding/include/libstoragemgmt/libstoragemgmt_systems.h
index 1441f19..e700e25 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_systems.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_systems.h
@@ -73,7 +73,14 @@ const char LSM_DLL_EXPORT *lsm_system_name_get(lsm_system *s);
* @return System status which is a bit sensitive field, returns UINT32_MAX on
* bad system pointer.
*/
-uint32_t lsm_system_status_get(lsm_system *s);
+uint32_t LSM_DLL_EXPORT lsm_system_status_get(lsm_system *s);
+
+/**
+ * Retrieve the optional data for the system.
+ * @param s System to retrieve optional data
+ * @return optional_data, NULL if none exists
+ */
+lsm_optional_data LSM_DLL_EXPORT *lsm_system_optional_data_get(lsm_system *s);

#ifdef __cplusplus
}
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 51689e0..a971f15 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -275,10 +275,18 @@ lsm_system *value_to_system(Value &system)
lsm_system *rc = NULL;
if (is_expected_object(system, "System")) {
std::map<std::string, Value> i = system.asObject();
- rc = lsm_system_record_alloc( i["id"].asString().c_str(),
+ lsm_optional_data *op = NULL;
+ Value opv = i["optional_data"];
+ op = value_to_optional_data(opv);
+
+ rc = lsm_system_record_alloc(i["id"].asString().c_str(),
i["name"].asString().c_str(),
i["status"].asUint32_t(),
- i["status_info"].asString().c_str());
+ i["status_info"].asString().c_str(),
+ op,
+ i["plugin_data"].asC_str());
+
+ lsm_optional_data_record_free(op);
}
return rc;
}
@@ -292,6 +300,8 @@ Value system_to_value(lsm_system *system)
s["name"] = Value(system->name);
s["status"] = Value(system->status);
s["status_info"] = Value(system->status_info);
+ s["optional_data"] = optional_data_to_value(system->optional_data);
+ s["plugin_data"] = Value(system->plugin_data);
return Value(s);
}
return Value();
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 16e9fbe..6791127 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -789,17 +789,27 @@ lsm_disk *lsm_disk_record_alloc(const char *id, const char *name,

CREATE_ALLOC_ARRAY_FUNC(lsm_system_record_array_alloc, lsm_system *)

-lsm_system *lsm_system_record_alloc( const char *id, const char *name,
- uint32_t status, const char *status_info)
+lsm_system *lsm_system_record_alloc(const char *id, const char *name,
+ uint32_t status, const char *status_info,
+ lsm_optional_data *optional_data,
+ const char* plugin_data)
{
- lsm_system *rc = (lsm_system *)malloc(sizeof(lsm_system));
+ lsm_system *rc = (lsm_system *)calloc(1, sizeof(lsm_system));
if (rc) {
rc->magic = LSM_SYSTEM_MAGIC;
rc->id = strdup(id);
rc->name = strdup(name);
rc->status = status;
rc->status_info = strdup(status_info);
- if( !rc->name || !rc->id || !rc->status_info ) {
+ rc->optional_data = lsm_optional_data_record_copy(optional_data);
+
+ if( plugin_data ) {
+ rc->plugin_data = strdup(plugin_data);
+ }
+
+ if( !rc->name || !rc->id || !rc->status_info ||
+ (optional_data && !rc->optional_data) ||
+ (plugin_data && !rc->plugin_data)) {
lsm_system_record_free(rc);
rc = NULL;
}
@@ -827,6 +837,9 @@ int lsm_system_record_free(lsm_system *s)
s->status_info = NULL;
}

+ lsm_optional_data_record_free(s->optional_data);
+ free(s->plugin_data);
+
free(s);
return LSM_ERR_OK;
}
@@ -840,7 +853,8 @@ lsm_system *lsm_system_record_copy(lsm_system *s)
{
lsm_system *rc = NULL;
if( LSM_IS_SYSTEM(s) ) {
- rc = lsm_system_record_alloc(s->id, s->name, s->status, s->status_info);
+ rc = lsm_system_record_alloc(s->id, s->name, s->status, s->status_info,
+ s->optional_data, s->plugin_data);
}
return rc;
}
@@ -869,6 +883,12 @@ uint32_t lsm_system_status_get(lsm_system *s)
return UINT32_MAX;
}

+MEMBER_FUNC_GET(lsm_optional_data *, lsm_system_optional_data_get,
+ lsm_system *s, s, LSM_IS_SYSTEM, optional_data, NULL)
+
+MEMBER_FUNC_GET(const char *, lsm_system_plugin_data_get, lsm_system *s,
+ s, LSM_IS_SYSTEM, plugin_data, NULL)
+
lsm_volume *lsm_volume_record_copy(lsm_volume *vol)
{
lsm_volume *rc = NULL;
diff --git a/c_binding/lsm_datatypes.hpp b/c_binding/lsm_datatypes.hpp
index f526495..b863f5d 100644
--- a/c_binding/lsm_datatypes.hpp
+++ b/c_binding/lsm_datatypes.hpp
@@ -194,6 +194,8 @@ struct _lsm_system {
char *name; /**< Name */
uint32_t status; /**< Enumerated status value */
char *status_info; /**< System status text */
+ lsm_optional_data *optional_data; /**< Optional data */
+ char *plugin_data; /**< Reserved for the plugin to use */
};

#define LSM_CONNECT_MAGIC 0xAA7A000A
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 78bf1d4..0632efc 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -2513,7 +2513,7 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
pd->num_systems = 1;
pd->system[0] = lsm_system_record_alloc(sys_id,
"LSM simulated storage plug-in",
- LSM_SYSTEM_STATUS_OK, "");
+ LSM_SYSTEM_STATUS_OK, "", NULL, NULL);

p = lsm_pool_record_alloc("POOL_3", "lsm_test_aggr",
UINT64_MAX, UINT64_MAX,
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 0395061..e10b982 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -397,6 +397,8 @@ class Volume(IData):
@default_property('name', doc="User defined system name")
@default_property('status', doc="Enumerated status of system")
@default_property('status_info', doc="Detail status information of system")
+@default_property("optional_data", doc="Optional data")
+@default_property("plugin_data", doc="Private plugin data")
class System(IData):
"""
### 11.3 System -- lsm.System
@@ -476,11 +478,15 @@ The lsm.System class does not have class methods.
STATUS_STOPPED = 1 << 8
STATUS_OTHER = 1 << 9

- def __init__(self, _id, _name, _status, _status_info):
+ def __init__(self, _id, _name, _status, _status_info, _optional_data=None,
+ _plugin_data=None):
self._id = _id
self._name = _name
self._status = _status
self._status_info = _status_info
+ self._optional_data = _check_opt_data(_optional_data,
+ self.OPT_PROPERTIES)
+ self._plugin_data = _plugin_data


@default_property('id', doc="Unique identifier")
--
1.8.2.1
Loading...