Discussion:
[Libstoragemgmt-devel] [PATCH 06/12] lsm_mgmt.cpp: Fix double free
Tony Asleson
2014-02-04 00:16:28 UTC
Permalink
Set the freed error pointer to prevent us from
doing a double free on it.

Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_mgmt.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lsm_mgmt.cpp b/src/lsm_mgmt.cpp
index 98ae5ee..f9ad961 100644
--- a/src/lsm_mgmt.cpp
+++ b/src/lsm_mgmt.cpp
@@ -37,6 +37,7 @@
return LSM_ERR_INVALID_CONN; \
} \
lsmErrorFree(c->error); \
+ c->error = NULL; \
} while (0)

/**
@@ -118,7 +119,7 @@ static lsmErrorNumber logException(lsmConnect *c, lsmErrorNumber error,
LSM_ERR_LEVEL_ERROR, message,
exception_msg, NULL,
NULL, 0);
- if( err && c ) {
+ if( err ) {
lsmErrorLog(c, err);
}
return error;
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:29 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/simc_lsmplugin.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/plugin/simc_lsmplugin.c b/plugin/simc_lsmplugin.c
index 237b84e..e12c630 100644
--- a/plugin/simc_lsmplugin.c
+++ b/plugin/simc_lsmplugin.c
@@ -567,7 +567,8 @@ static int _list_initiators(lsmPluginPtr c, lsmInitiator **initArray[],
if( init_key && init_val ) {
g_hash_table_insert(tmp_inits, init_key, init_val);
} else {
- g_hash_table_destroy(tmp_inits);
+ free(init_key);
+ lsmInitiatorRecordFree(init_val);
rc = LSM_ERR_NO_MEMORY;
}
}
@@ -1594,6 +1595,7 @@ static int vol_accessible_by_init(lsmPluginPtr c,
lsmVolumeRecordFreeArray(*volumes, alloc_count);
*count = 0;
*volumes = NULL;
+ break;
} else {
alloc_count += 1;
}
@@ -2221,8 +2223,25 @@ int load( lsmPluginPtr c, xmlURIPtr uri, const char *password,

if( !data->system[0] || !data->pool[0] || !data->pool[1] ||
!data->pool[2] || !data->pool[3] || !data->access_groups ||
- !data->group_grant || !data->fs) {
- rc = LSM_ERR_NO_MEMORY;
+ !data->group_grant || !data->fs || !data->jobs ) {
+ rc = LSM_ERR_NO_MEMORY; /* We need to free data and everything else */
+
+ if( data->jobs )
+ g_hash_table_destroy(data->jobs);
+ if( data->fs )
+ g_hash_table_destroy(data->fs);
+ if( data->group_grant )
+ g_hash_table_destroy(data->group_grant);
+ if( data->access_groups )
+ g_hash_table_destroy(data->access_groups);
+ lsmPoolRecordFree(data->pool[3]);
+ lsmPoolRecordFree(data->pool[2]);
+ lsmPoolRecordFree(data->pool[1]);
+ lsmPoolRecordFree(data->pool[0]);
+ lsmSystemRecordFree(data->system[0]);
+ memset(data, 0xAA, sizeof(struct plugin_data));
+ free(data);
+ data = NULL;
} else {
rc = lsmRegisterPluginV1( c, data, &mgmOps,
&sanOps, &fsOps, &nfsOps);
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:27 UTC
Permalink
This is done after the record is no longer in use so
that if a stray pointer uses it we will get a bad fd
error.

Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_daemon.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lsm_daemon.c b/src/lsm_daemon.c
index 670fb17..04eed85 100644
--- a/src/lsm_daemon.c
+++ b/src/lsm_daemon.c
@@ -42,6 +42,7 @@
#include <libgen.h>
#include <assert.h>
#include <grp.h>
+#include <limits.h>

#define BASE_DIR "/var/run/lsm"
#define SOCKET_DIR BASE_DIR"/ipc"
@@ -379,7 +380,7 @@ void empty_plugin_list(struct plugin_list *list)

free(item->file_path);
item->file_path = NULL;
- item->fd = -1;
+ item->fd = INT_MAX;
free(item);
}
}
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:24 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 1 +
plugin/simc_lsmplugin.c | 7 +++---
src/lsm_convert.cpp | 3 +++
src/lsm_mgmt.cpp | 27 ++++++++++++++--------
4 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 24c84d0..c0e29a3 100644
--- a/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1016,6 +1016,7 @@ lsmDisk LSM_DLL_EXPORT **lsmDiskRecordAllocArray( uint32_t size );
* @param block_count Number of blocks for disk
* @param disk_status Status
* @param op OptionalData can be NULL if not available
+ * NOTE: op gets copied internally
* @param system_id System id this disk resides in
* @return Pointer to allocated disk record or NULL on memory error.
*/
diff --git a/plugin/simc_lsmplugin.c b/plugin/simc_lsmplugin.c
index f9c4530..237b84e 100644
--- a/plugin/simc_lsmplugin.c
+++ b/plugin/simc_lsmplugin.c
@@ -652,12 +652,12 @@ static int list_disks(lsmPluginPtr c, lsmDisk **disks[], uint32_t *count,
{
int i;
int rc = LSM_ERR_OK;
- struct plugin_data *pd = (struct plugin_data*)lsmGetPrivateData(c);
char name[17];
char sn[32];
+ struct plugin_data *pd = (struct plugin_data*)lsmGetPrivateData(c);
lsmOptionalData *od = lsmOptionalDataRecordAlloc();

- if(pd) {
+ if(pd && od) {
// For now we are going to make up some disks to return. Later we will
// try to make a simulated array that makes sense.
*count = 10;
@@ -672,11 +672,12 @@ static int list_disks(lsmPluginPtr c, lsmDisk **disks[], uint32_t *count,
(*disks)[i] = lsmDiskRecordAlloc(md5(name), name, LSM_DISK_TYPE_SOP, 512,
0x8000000000000, LSM_DISK_STATUS_OK, od, sys_id);
}
- lsmOptionalDataRecordFree(od);
+
} else {
rc = LSM_ERR_INVALID_PLUGIN;
}

+ lsmOptionalDataRecordFree(od);
return rc;
}

diff --git a/src/lsm_convert.cpp b/src/lsm_convert.cpp
index 54100a5..242efe9 100644
--- a/src/lsm_convert.cpp
+++ b/src/lsm_convert.cpp
@@ -95,6 +95,9 @@ lsmDisk *valueToDisk(Value &disk)
op,
d["system_id"].asString().c_str()
);
+
+ /* Optional data gets copied in lsmDiskRecordAlloc */
+ lsmOptionalDataRecordFree(op);
}
return rc;
}
diff --git a/src/lsm_mgmt.cpp b/src/lsm_mgmt.cpp
index f5c96a1..98ae5ee 100644
--- a/src/lsm_mgmt.cpp
+++ b/src/lsm_mgmt.cpp
@@ -242,16 +242,17 @@ int LSM_DLL_EXPORT lsmGetAvailablePlugins(const char *sep,
char *version = NULL;
char *s = NULL;
const char *uds_dir = uds_path();
- lsmStringList *plugin_list = lsmStringListAlloc(0);
-
- if( !plugin_list ) {
- return LSM_ERR_NO_MEMORY;
- }
+ lsmStringList *plugin_list = NULL;

if( CHECK_STR(sep) || CHECK_RP(plugins) || LSM_FLAG_UNUSED_CHECK(flags)) {
return LSM_ERR_INVALID_ARGUMENT;
}

+ plugin_list = lsmStringListAlloc(0);
+ if( !plugin_list ) {
+ return LSM_ERR_NO_MEMORY;
+ }
+
dirp = opendir(uds_dir);
if( dirp ) {
for(;;) {
@@ -277,28 +278,32 @@ int LSM_DLL_EXPORT lsmGetAvailablePlugins(const char *sep,

if( -1 == format ) {
rc = LSM_ERR_NO_MEMORY;
- goto bail;
+ break;
}

rc = lsmStringListAppend(plugin_list, s);
free(s);
s = NULL;
if( LSM_ERR_OK != rc ) {
- goto bail;
+ break;
}

}
} else {
- goto bail;
+ break;
}

freeConnection(c);
c = NULL;
}
}
+ } /* for(;;) */
+
+ if( e ) {
+ lsmErrorFree(e);
+ e = NULL;
}

- bail:
if( c ) {
freeConnection(c);
c = NULL;
@@ -309,7 +314,8 @@ int LSM_DLL_EXPORT lsmGetAvailablePlugins(const char *sep,
//log the error
rc = LSM_ERR_INTERNAL_ERROR;
}
- } else {
+
+ } else { /* If dirp == NULL */
//Log the error
rc = LSM_ERR_INTERNAL_ERROR;
}
@@ -318,6 +324,7 @@ int LSM_DLL_EXPORT lsmGetAvailablePlugins(const char *sep,
*plugins = plugin_list;
} else {
lsmStringListFree(plugin_list);
+ plugin_list = NULL;
}

return rc;
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:25 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_ipc.cpp | 1 +
1 file changed, 1 insertion(+)

diff --git a/src/lsm_ipc.cpp b/src/lsm_ipc.cpp
index 355abee..099ba5f 100644
--- a/src/lsm_ipc.cpp
+++ b/src/lsm_ipc.cpp
@@ -147,6 +147,7 @@ int Transport::getSocket(const std::string& path, int &error_code)
if (rc != 0) {
error_code = errno;
rc = -1; //Redundant, connect should set to -1 on error
+ ::close(sfd);
} else {
rc = sfd; //We are good to go.
}
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:26 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_datatypes.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/lsm_datatypes.cpp b/src/lsm_datatypes.cpp
index d989c32..7e6415d 100644
--- a/src/lsm_datatypes.cpp
+++ b/src/lsm_datatypes.cpp
@@ -1560,7 +1560,12 @@ static uint8_t *stringToBytes(const char *hex_string, uint32_t *l)
*l = len;

for( i = 0; i < len; ++i ) {
- sscanf(t, "%02hhx", &rc[i]);
+ if( 1 != sscanf(t, "%02hhx", &rc[i])) {
+ free(rc);
+ rc = NULL;
+ *l = 0;
+ break;
+ }
t += 2;
}
}
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:30 UTC
Permalink
The protocol is to read a len header and they the json
payload. Put in a limit to prevent a bogus header
length from causing the code to allocate to much
memory.

Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_ipc.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/lsm_ipc.cpp b/src/lsm_ipc.cpp
index 099ba5f..4a2d07d 100644
--- a/src/lsm_ipc.cpp
+++ b/src/lsm_ipc.cpp
@@ -121,9 +121,13 @@ std::string Transport::recvMsg(int &error_code)
{
std::string msg;
error_code = 0;
+ unsigned long int payload_len = 0;
std::string len = readString(s, HDR_LEN, error_code); //Read the length
if (len.size() && error_code == 0) {
- msg = readString(s, strtoul(len.c_str(), NULL, 10), error_code);
+ payload_len = strtoul(len.c_str(), NULL, 10);
+ if( payload_len < 0x80000000 ) { /* Should be big enough */
+ msg = readString(s, payload_len, error_code);
+ }
//fprintf(stderr, "<<< %s\n", msg.c_str());
}
return msg;
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:34 UTC
Permalink
Make sure that there exists no possiblity of an
un-caught exception making it out of the library.

Signed-off-by: Tony Asleson <***@redhat.com>
---
src/lsm_mgmt.cpp | 587 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 360 insertions(+), 227 deletions(-)

diff --git a/src/lsm_mgmt.cpp b/src/lsm_mgmt.cpp
index f9ad961..224fe34 100644
--- a/src/lsm_mgmt.cpp
+++ b/src/lsm_mgmt.cpp
@@ -148,19 +148,23 @@ static int rpc(lsmConnect *c, const char *method, const Value &parameters,

static int jobCheck( int rc, Value &response, char **job )
{
- if( LSM_ERR_OK == rc ) {
- //We get a value back, either null or job id.
- if( Value::string_t == response.valueType() ) {
- *job = strdup(response.asString().c_str());
-
- if( *job ) {
- rc = LSM_ERR_JOB_STARTED;
+ try {
+ if( LSM_ERR_OK == rc ) {
+ //We get a value back, either null or job id.
+ if( Value::string_t == response.valueType() ) {
+ *job = strdup(response.asString().c_str());
+
+ if( *job ) {
+ rc = LSM_ERR_JOB_STARTED;
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
- rc = LSM_ERR_NO_MEMORY;
+ *job = NULL;
}
- } else {
- *job = NULL;
}
+ } catch (ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -198,6 +202,7 @@ int lsmConnectClose(lsmConnect *c, lsmFlag_t flags)
int LSM_DLL_EXPORT lsmPluginGetInfo(lsmConnect *c, char **desc,
char **version, lsmFlag_t flags)
{
+ int rc = LSM_ERR_OK;
CONN_SETUP(c);

if( LSM_FLAG_UNUSED_CHECK(flags) ) {
@@ -208,23 +213,31 @@ int LSM_DLL_EXPORT lsmPluginGetInfo(lsmConnect *c, char **desc,
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;

- int rc = rpc(c, "plugin_info", parameters, response);
+ rc = rpc(c, "plugin_info", parameters, response);

- if( rc == LSM_ERR_OK ) {
- std::vector<Value> j = response.asArray();
- *desc = strdup(j[0].asC_str());
- *version = strdup(j[1].asC_str());
+ if( rc == LSM_ERR_OK ) {
+ std::vector<Value> j = response.asArray();
+ *desc = strdup(j[0].asC_str());
+ *version = strdup(j[1].asC_str());

- if( !*desc || !*version ) {
- rc = LSM_ERR_NO_MEMORY;
- free(*desc);
- free(*version);
+ if( !*desc || !*version ) {
+ rc = LSM_ERR_NO_MEMORY;
+ free(*desc);
+ free(*version);
+ }
}
+ } catch (ValueException &ve) {
+ free(*desc);
+ *desc = NULL;
+ free(*version);
+ *version = NULL;
+ rc = LSM_ERR_INTERNAL_ERROR;
}

return rc;
@@ -351,20 +364,26 @@ int lsmConnectSetTimeout(lsmConnect *c, uint32_t timeout, lsmFlag_t flags)

int lsmConnectGetTimeout(lsmConnect *c, uint32_t *timeout, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
-
- int rc = rpc(c, "get_time_out", parameters, response);
- if( rc == LSM_ERR_OK ) {
- *timeout = response.asUint32_t();
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "get_time_out", parameters, response);
+ if( rc == LSM_ERR_OK ) {
+ *timeout = response.asUint32_t();
+ }
+ }
+ catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -373,26 +392,31 @@ static int jobStatus( lsmConnect *c, const char *job,
lsmJobStatus *status, uint8_t *percentComplete,
Value &returned_value, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !job || !status || !percentComplete ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["job_id"] = Value(job);
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
-
- int rc = rpc(c, "job_status", parameters, response);
- if( LSM_ERR_OK == rc ) {
- //We get back an array [status, percent, volume]
- std::vector<Value> j = response.asArray();
- *status = (lsmJobStatus)j[0].asInt32_t();
- *percentComplete = (uint8_t)j[1].asUint32_t();
-
- returned_value = j[2];
+ try {
+ std::map<std::string, Value> p;
+ p["job_id"] = Value(job);
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "job_status", parameters, response);
+ if( LSM_ERR_OK == rc ) {
+ //We get back an array [status, percent, volume]
+ std::vector<Value> j = response.asArray();
+ *status = (lsmJobStatus)j[0].asInt32_t();
+ *percentComplete = (uint8_t)j[1].asUint32_t();
+
+ returned_value = j[2];
+ }
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -536,30 +560,35 @@ int lsmCapabilities(lsmConnect *c, lsmSystem *system,
int lsmPoolList(lsmConnect *c, lsmPool **poolArray[],
uint32_t *count, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !poolArray || !count || CHECK_RP(poolArray) || LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;

- int rc = rpc(c, "pools", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> pools = response.asArray();
+ rc = rpc(c, "pools", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> pools = response.asArray();

- *count = pools.size();
+ *count = pools.size();

- if( pools.size() ) {
- *poolArray = lsmPoolRecordAllocArray(pools.size());
+ if( pools.size() ) {
+ *poolArray = lsmPoolRecordAllocArray(pools.size());

- for( size_t i = 0; i < pools.size(); ++i ) {
- (*poolArray)[i] = valueToPool(pools[i]);
+ for( size_t i = 0; i < pools.size(); ++i ) {
+ (*poolArray)[i] = valueToPool(pools[i]);
+ }
}
}
+ } catch(ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -567,25 +596,29 @@ int lsmPoolList(lsmConnect *c, lsmPool **poolArray[],
static int get_initiator_array(int rc, Value &response,
lsmInitiator **initiators[], uint32_t *count)
{
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> inits = response.asArray();
+ try {
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> inits = response.asArray();

- *count = inits.size();
+ *count = inits.size();

- if( inits.size() ) {
+ if( inits.size() ) {

- *initiators = lsmInitiatorRecordAllocArray(inits.size());
+ *initiators = lsmInitiatorRecordAllocArray(inits.size());

- if( *initiators ) {
+ if( *initiators ) {


- for( size_t i = 0; i < inits.size(); ++i ) {
- (*initiators)[i] = valueToInitiator(inits[i]);
+ for( size_t i = 0; i < inits.size(); ++i ) {
+ (*initiators)[i] = valueToInitiator(inits[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
- } else {
- rc = LSM_ERR_NO_MEMORY;
}
}
+ } catch (ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -612,22 +645,26 @@ int lsmInitiatorList(lsmConnect *c, lsmInitiator **initiators[],
static int get_volume_array(int rc, Value response,
lsmVolume **volumes[], uint32_t *count)
{
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> vol = response.asArray();
+ try {
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> vol = response.asArray();

- *count = vol.size();
+ *count = vol.size();

- if( vol.size() ) {
- *volumes = lsmVolumeRecordAllocArray(vol.size());
+ if( vol.size() ) {
+ *volumes = lsmVolumeRecordAllocArray(vol.size());

- if( *volumes ){
- for( size_t i = 0; i < vol.size(); ++i ) {
- (*volumes)[i] = valueToVolume(vol[i]);
+ if( *volumes ){
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = valueToVolume(vol[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
- } else {
- rc = LSM_ERR_NO_MEMORY;
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -655,22 +692,29 @@ int lsmVolumeList(lsmConnect *c, lsmVolume **volumes[], uint32_t *count,
static int get_disk_array(int rc, Value &response, lsmDisk **disks[],
uint32_t *count)
{
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> d = response.asArray();
+ try {
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> d = response.asArray();

- *count = d.size();
+ *count = d.size();

- if( d.size() ) {
- *disks = lsmDiskRecordAllocArray(d.size());
+ if( d.size() ) {
+ *disks = lsmDiskRecordAllocArray(d.size());

- if( *disks ){
- for( size_t i = 0; i < d.size(); ++i ) {
- (*disks)[i] = valueToDisk(d[i]);
+ if( *disks ){
+ for( size_t i = 0; i < d.size(); ++i ) {
+ (*disks)[i] = valueToDisk(d[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
- } else {
- rc = LSM_ERR_NO_MEMORY;
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *disks && *count ) {
+ lsmDiskRecordFreeArray(*disks, *count);
+ }
}
return rc;

@@ -700,22 +744,29 @@ typedef void* (*convert)(Value &v);
static void* parse_job_response(Value response, int &rc, char **job, convert conv)
{
void *val = NULL;
- //We get an array back. first value is job, second is data of interest.
- if( Value::array_t == response.valueType() ) {
- std::vector<Value> r = response.asArray();
- if( Value::string_t == r[0].valueType()) {
- *job = strdup((r[0].asString()).c_str());
- if( *job ) {
+
+ try {
+ //We get an array back. first value is job, second is data of interest.
+ if( Value::array_t == response.valueType() ) {
+ std::vector<Value> r = response.asArray();
+ if( Value::string_t == r[0].valueType()) {
+ *job = strdup((r[0].asString()).c_str());
+ if( *job ) {
+ rc = LSM_ERR_JOB_STARTED;
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
+
rc = LSM_ERR_JOB_STARTED;
- } else {
- rc = LSM_ERR_NO_MEMORY;
}
-
- rc = LSM_ERR_JOB_STARTED;
- }
- if( Value::object_t == r[1].valueType() ) {
- val = conv(r[1]);
+ if( Value::object_t == r[1].valueType() ) {
+ val = conv(r[1]);
+ }
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ free(*job);
+ *job = NULL;
}
return val;
}
@@ -831,6 +882,7 @@ int lsmVolumeReplicate(lsmConnect *c, lsmPool *pool,
int lsmVolumeReplicateRangeBlockSize(lsmConnect *c, lsmSystem *system,
uint32_t *bs, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !bs || LSM_FLAG_UNUSED_CHECK(flags) ) {
@@ -841,17 +893,21 @@ int lsmVolumeReplicateRangeBlockSize(lsmConnect *c, lsmSystem *system,
return LSM_ERR_INVALID_SYSTEM;
}

- std::map<std::string, Value> p;
- p["system"] = systemToValue(system);
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
-
- int rc = rpc(c, "volume_replicate_range_block_size", parameters, response);
- if( LSM_ERR_OK == rc ) {
- if( Value::numeric_t == response.valueType() ) {
- *bs = response.asUint32_t();
+ try {
+ std::map<std::string, Value> p;
+ p["system"] = systemToValue(system);
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "volume_replicate_range_block_size", parameters, response);
+ if( LSM_ERR_OK == rc ) {
+ if( Value::numeric_t == response.valueType() ) {
+ *bs = response.asUint32_t();
+ }
}
+ } catch( ValueException &ve ) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -893,6 +949,7 @@ int lsmVolumeReplicateRange(lsmConnect *c,
int lsmVolumeDelete(lsmConnect *c, lsmVolume *volume, char **job,
lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !LSM_IS_VOL(volume) ) {
@@ -903,25 +960,29 @@ int lsmVolumeDelete(lsmConnect *c, lsmVolume *volume, char **job,
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["volume"] = volumeToValue(volume);
- p["flags"] = Value(flags);
-
- Value parameters(p);
- Value response;
-
- int rc = rpc(c, "volume_delete", parameters, response);
- if( LSM_ERR_OK == rc ) {
- //We get a value back, either null or job id.
- if( Value::string_t == response.valueType() ) {
- *job = strdup(response.asString().c_str());
-
- if( *job ) {
- rc = LSM_ERR_JOB_STARTED;
- } else {
- rc = LSM_ERR_NO_MEMORY;
+ try {
+ std::map<std::string, Value> p;
+ p["volume"] = volumeToValue(volume);
+ p["flags"] = Value(flags);
+
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "volume_delete", parameters, response);
+ if( LSM_ERR_OK == rc ) {
+ //We get a value back, either null or job id.
+ if( Value::string_t == response.valueType() ) {
+ *job = strdup(response.asString().c_str());
+
+ if( *job ) {
+ rc = LSM_ERR_JOB_STARTED;
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;

@@ -1287,6 +1348,7 @@ int lsmVolumesAccessibleByAccessGroup(lsmConnect *c,
lsmVolume **volumes[],
uint32_t *count, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !LSM_IS_ACCESS_GROUP(group)) {
@@ -1297,26 +1359,35 @@ int lsmVolumesAccessibleByAccessGroup(lsmConnect *c,
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["group"] = accessGroupToValue(group);
- p["flags"] = Value(flags);
+ try {
+ std::map<std::string, Value> p;
+ p["group"] = accessGroupToValue(group);
+ p["flags"] = Value(flags);

- Value parameters(p);
- Value response;
+ Value parameters(p);
+ Value response;

- int rc = rpc(c, "volumes_accessible_by_access_group", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> vol = response.asArray();
+ rc = rpc(c, "volumes_accessible_by_access_group", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> vol = response.asArray();

- *count = vol.size();
+ *count = vol.size();

- if( vol.size() ) {
- *volumes = lsmVolumeRecordAllocArray(vol.size());
+ if( vol.size() ) {
+ *volumes = lsmVolumeRecordAllocArray(vol.size());

- for( size_t i = 0; i < vol.size(); ++i ) {
- (*volumes)[i] = valueToVolume(vol[i]);
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = valueToVolume(vol[i]);
+ }
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *volumes && *count ) {
+ lsmVolumeRecordFreeArray(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
}
return rc;
}
@@ -1350,6 +1421,7 @@ int lsmAccessGroupsGrantedToVolume(lsmConnect *c,
int lsmVolumeChildDependency(lsmConnect *c, lsmVolume *volume,
uint8_t *yes, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !LSM_IS_VOL(volume)) {
@@ -1360,25 +1432,29 @@ int lsmVolumeChildDependency(lsmConnect *c, lsmVolume *volume,
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["volume"] = volumeToValue(volume);
- p["flags"] = Value(flags);
+ try {
+ std::map<std::string, Value> p;
+ p["volume"] = volumeToValue(volume);
+ p["flags"] = Value(flags);

- Value parameters(p);
- Value response;
+ Value parameters(p);
+ Value response;

- *yes = 0;
+ *yes = 0;

- int rc = rpc(c, "volume_child_dependency", parameters, response);
- if( LSM_ERR_OK == rc ) {
- //We should be getting a boolean value back.
- if( Value::boolean_t == response.valueType() ) {
- if( response.asBool() ) {
- *yes = 1;
+ rc = rpc(c, "volume_child_dependency", parameters, response);
+ if( LSM_ERR_OK == rc ) {
+ //We should be getting a boolean value back.
+ if( Value::boolean_t == response.valueType() ) {
+ if( response.asBool() ) {
+ *yes = 1;
+ }
+ } else {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
- } else {
- rc = LSM_ERR_INTERNAL_ERROR;
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -1410,39 +1486,49 @@ int lsmVolumeChildDependencyRm(lsmConnect *c, lsmVolume *volume,
int lsmSystemList(lsmConnect *c, lsmSystem **systems[],
uint32_t *systemCount, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !systems || ! systemCount || LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
-
- int rc = rpc(c, "systems", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> sys = response.asArray();
-
- *systemCount = sys.size();
-
- if( sys.size() ) {
- *systems = lsmSystemRecordAllocArray(sys.size());
-
- if( *systems ) {
- for( size_t i = 0; i < sys.size(); ++i ) {
- (*systems)[i] = valueToSystem(sys[i]);
- if( !(*systems)[i] ) {
- lsmSystemRecordFreeArray(*systems, i);
- rc = LSM_ERR_NO_MEMORY;
- break;
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;
+
+ rc = rpc(c, "systems", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> sys = response.asArray();
+
+ *systemCount = sys.size();
+
+ if( sys.size() ) {
+ *systems = lsmSystemRecordAllocArray(sys.size());
+
+ if( *systems ) {
+ for( size_t i = 0; i < sys.size(); ++i ) {
+ (*systems)[i] = valueToSystem(sys[i]);
+ if( !(*systems)[i] ) {
+ lsmSystemRecordFreeArray(*systems, i);
+ rc = LSM_ERR_NO_MEMORY;
+ break;
+ }
}
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
- } else {
- rc = LSM_ERR_NO_MEMORY;
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *systems ) {
+ lsmSystemRecordFreeArray( *systems, *systemCount);
+ *systems = NULL;
+ *systemCount = 0;
+ }
}
return rc;
}
@@ -1450,30 +1536,44 @@ int lsmSystemList(lsmConnect *c, lsmSystem **systems[],
int lsmFsList(lsmConnect *c, lsmFs **fs[], uint32_t *fsCount,
lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !fs || !fsCount || LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;

- int rc = rpc(c, "fs", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> sys = response.asArray();
+ rc = rpc(c, "fs", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> sys = response.asArray();

- *fsCount = sys.size();
+ *fsCount = sys.size();

- if( sys.size() ) {
- *fs = lsmFsRecordAllocArray(sys.size());
+ if( sys.size() ) {
+ *fs = lsmFsRecordAllocArray(sys.size());

- for( size_t i = 0; i < sys.size(); ++i ) {
- (*fs)[i] = valueToFs(sys[i]);
+ if( *fs ) {
+ for( size_t i = 0; i < sys.size(); ++i ) {
+ (*fs)[i] = valueToFs(sys[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
+ } catch( ValueException &ve) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *fs && *fsCount) {
+ lsmFsRecordFreeArray(*fs, *fsCount);
+ *fs = NULL;
+ *fsCount = 0;
+ }
}
return rc;

@@ -1629,6 +1729,7 @@ int lsmFsFileClone(lsmConnect *c, lsmFs *fs, const char *src_file_name,
int lsmFsChildDependency( lsmConnect *c, lsmFs *fs, lsmStringList *files,
uint8_t *yes, lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( !LSM_IS_FS(fs) ) {
@@ -1645,26 +1746,30 @@ int lsmFsChildDependency( lsmConnect *c, lsmFs *fs, lsmStringList *files,
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["fs"] = fsToValue(fs);
- p["files"] = stringListToValue(files);
- p["flags"] = Value(flags);
-
- Value parameters(p);
- Value response;
-
- *yes = 0;
-
- int rc = rpc(c, "fs_child_dependency", parameters, response);
- if( LSM_ERR_OK == rc ) {
- //We should be getting a boolean value back.
- if( Value::boolean_t == response.valueType() ) {
- if( response.asBool() ) {
- *yes = 1;
+ try {
+ std::map<std::string, Value> p;
+ p["fs"] = fsToValue(fs);
+ p["files"] = stringListToValue(files);
+ p["flags"] = Value(flags);
+
+ Value parameters(p);
+ Value response;
+
+ *yes = 0;
+
+ rc = rpc(c, "fs_child_dependency", parameters, response);
+ if( LSM_ERR_OK == rc ) {
+ //We should be getting a boolean value back.
+ if( Value::boolean_t == response.valueType() ) {
+ if( response.asBool() ) {
+ *yes = 1;
+ }
+ } else {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
- } else {
- rc = LSM_ERR_INTERNAL_ERROR;
}
+ } catch( ValueException &e) {
+ rc = LSM_ERR_INTERNAL_ERROR;
}
return rc;
}
@@ -1703,6 +1808,7 @@ int lsmFsChildDependencyRm( lsmConnect *c, lsmFs *fs, lsmStringList *files,
int lsmFsSsList(lsmConnect *c, lsmFs *fs, lsmSs **ss[],
uint32_t *ssCount, lsmFlag_t flags )
{
+ int rc = 0;
CONN_SETUP(c);

if( !LSM_IS_FS(fs) ) {
@@ -1720,19 +1826,32 @@ int lsmFsSsList(lsmConnect *c, lsmFs *fs, lsmSs **ss[],
Value parameters(p);
Value response;

- int rc = rpc(c, "fs_snapshots", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> sys = response.asArray();
+ try {
+ rc = rpc(c, "fs_snapshots", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> sys = response.asArray();

- *ssCount = sys.size();
+ *ssCount = sys.size();

- if( sys.size() ) {
- *ss = lsmSsRecordAllocArray(sys.size());
+ if( sys.size() ) {
+ *ss = lsmSsRecordAllocArray(sys.size());

- for( size_t i = 0; i < sys.size(); ++i ) {
- (*ss)[i] = valueToSs(sys[i]);
+ if( *ss ) {
+ for( size_t i = 0; i < sys.size(); ++i ) {
+ (*ss)[i] = valueToSs(sys[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
+ } catch( ValueException &ve ) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *ss && *ssCount ) {
+ lsmSsRecordFreeArray(*ss, *ssCount);
+ *ss = NULL;
+ *ssCount = 0;
+ }
}
return rc;

@@ -1854,30 +1973,44 @@ int lsmFsSsRevert(lsmConnect *c, lsmFs *fs, lsmSs *ss,
int lsmNfsList( lsmConnect *c, lsmNfsExport **exports[], uint32_t *count,
lsmFlag_t flags)
{
+ int rc = 0;
CONN_SETUP(c);

if( CHECK_RP(exports) || !count || LSM_FLAG_UNUSED_CHECK(flags) ) {
return LSM_ERR_INVALID_ARGUMENT;
}

- std::map<std::string, Value> p;
- p["flags"] = Value(flags);
- Value parameters(p);
- Value response;
+ try {
+ std::map<std::string, Value> p;
+ p["flags"] = Value(flags);
+ Value parameters(p);
+ Value response;

- int rc = rpc(c, "exports", parameters, response);
- if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- std::vector<Value> exps = response.asArray();
+ rc = rpc(c, "exports", parameters, response);
+ if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
+ std::vector<Value> exps = response.asArray();

- *count = exps.size();
+ *count = exps.size();

- if( *count ) {
- *exports = lsmNfsExportRecordAllocArray(*count);
+ if( *count ) {
+ *exports = lsmNfsExportRecordAllocArray(*count);

- for( size_t i = 0; i < *count; ++i ) {
- (*exports)[i] = valueToNfsExport(exps[i]);
+ if( *exports ) {
+ for( size_t i = 0; i < *count; ++i ) {
+ (*exports)[i] = valueToNfsExport(exps[i]);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
+ } catch( ValueException &ve ) {
+ rc = LSM_ERR_INTERNAL_ERROR;
+ if( *exports && *count ) {
+ lsmNfsExportRecordFreeArray( *exports, *count );
+ *exports = NULL;
+ *count = 0;
+ }
}
return rc;
}
--
1.8.2.1
Tony Asleson
2014-02-04 00:16:33 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
configure.ac | 1 -
tools/Makefile.am | 2 +-
tools/lsmcli/Makefile.am | 9 -
tools/lsmcli/arguments.cpp | 477 -------------------------------------------
tools/lsmcli/arguments.h | 226 --------------------
tools/lsmcli/lsmcli.cpp | 86 --------
tools/lsmcli/lsmcli_func.cpp | 426 --------------------------------------
tools/lsmcli/lsmcli_func.h | 117 -----------
8 files changed, 1 insertion(+), 1343 deletions(-)
delete mode 100644 tools/lsmcli/Makefile.am
delete mode 100644 tools/lsmcli/arguments.cpp
delete mode 100644 tools/lsmcli/arguments.h
delete mode 100644 tools/lsmcli/lsmcli.cpp
delete mode 100644 tools/lsmcli/lsmcli_func.cpp
delete mode 100644 tools/lsmcli/lsmcli_func.h

diff --git a/configure.ac b/configure.ac
index ab25017..c13bc55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,7 +150,6 @@ AC_OUTPUT(libstoragemgmt.pc \
doc/man/lsmd.1 \
doc/doxygen.conf \
tools/Makefile \
- tools/lsmcli/Makefile \
tools/udev/Makefile \
include/Makefile \
include/libstoragemgmt/Makefile \
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d0689f6..b097ed0 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,3 +1,3 @@
## Process this file with automake to produce Makefile.in

-SUBDIRS = lsmcli lsmclipy udev
+SUBDIRS = lsmclipy udev
diff --git a/tools/lsmcli/Makefile.am b/tools/lsmcli/Makefile.am
deleted file mode 100644
index d383737..0000000
--- a/tools/lsmcli/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include -***@srcdir@/include
-
-noinst_PROGRAMS = lsmcli
-#bin_PROGRAMS = lsmcli
-lsmcli_LDADD = ../../src/libstoragemgmt.la
-lsmcli_SOURCES = lsmcli.cpp \
- arguments.h arguments.cpp \
- lsmcli_func.h lsmcli_func.cpp
-
diff --git a/tools/lsmcli/arguments.cpp b/tools/lsmcli/arguments.cpp
deleted file mode 100644
index 1484c7d..0000000
--- a/tools/lsmcli/arguments.cpp
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#include "arguments.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <iomanip>
-#include <sstream>
-#include <algorithm>
-
-
-namespace LSM {
-
-#define _(text) text
-const char *list_types[] = { LIST_TYPE_VOL, LIST_TYPE_POOL, LIST_TYPE_INIT };
-const std::vector<std::string> listTypes(list_types, list_types + 3);
-
-const char *init_types[] = { INIT_TYPE_WWPN, INIT_TYPE_WWNN, INIT_TYPE_ISCSI,
- INIT_TYPE_HN };
-const std::vector<std::string> initTypes(init_types, init_types + 4);
-
-const char *prov_types[] = { PROV_TYPE_DEFAULT, PROV_TYPE_THIN, PROV_TYPE_FULL};
-const std::vector<std::string> provTypes(prov_types, prov_types + 3);
-
-const char *rep_types[] = { REP_TYPE_SNAPSHOT, REP_TYPE_CLONE, REP_TYPE_COPY, REP_TYPE_MIRROR };
-const std::vector<std::string> repTypes(rep_types, rep_types + 4);
-
-const char *access_types[] = { ACCESS_TYPE_RW, ACCESS_TYPE_RO };
-const std::vector<std::string> accessTypes(access_types, access_types + 2);
-
-lsmInitiatorType Arguments::initiatorType() const
-{
- lsmInitiatorType rc = LSM_INITIATOR_OTHER;
- if( type.value == INIT_TYPE_WWPN ) {
- rc = LSM_INITIATOR_PORT_WWN;
- } else if( type.value == INIT_TYPE_WWNN ) {
- rc = LSM_INITIATOR_NODE_WWN;
- } else if( type.value == INIT_TYPE_ISCSI ) {
- rc = LSM_INITIATOR_ISCSI;
- } else if( type.value == INIT_TYPE_HN ) {
- rc = LSM_INITIATOR_HOSTNAME;
- }
- return rc;
-}
-
-lsmProvisionType Arguments::provisionType() const
-{
- lsmProvisionType rc = LSM_PROVISION_UNKNOWN;
- if( provisioning.value == PROV_TYPE_DEFAULT ) {
- rc = LSM_PROVISION_DEFAULT;
- } else if( provisioning.value == PROV_TYPE_THIN ) {
- rc = LSM_PROVISION_THIN;
- } else if( provisioning.value == PROV_TYPE_FULL) {
- rc = LSM_PROVISION_FULL;
- }
- return rc;
-}
-
-lsmReplicationType Arguments::replicationType() const
-{
- lsmReplicationType rc = LSM_VOLUME_REPLICATE_UNKNOWN;
-
- if( type.value == REP_TYPE_SNAPSHOT ) {
- rc = LSM_VOLUME_REPLICATE_SNAPSHOT;
- } else if ( type.value == REP_TYPE_CLONE) {
- rc = LSM_VOLUME_REPLICATE_CLONE;
- } else if ( type.value == REP_TYPE_COPY) {
- rc = LSM_VOLUME_REPLICATE_COPY;
- } else if ( type.value == REP_TYPE_MIRROR ) {
- rc = LSM_VOLUME_REPLICATE_MIRROR_ASYNC;
- }
- return rc;
-}
-
-lsmAccessType Arguments::accessType() const
-{
- lsmAccessType rc = LSM_VOLUME_ACCESS_NONE;
- if( access.value == ACCESS_TYPE_RW ) {
- rc = LSM_VOLUME_ACCESS_READ_WRITE;
- } else {
- rc = LSM_VOLUME_ACCESS_READ_ONLY;
- }
- return rc;
-}
-
-void syntaxError(const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
- exit(1);
-}
-
-void usage()
-{
- printf(_("Usage: %s [OPTIONS]... [COMAND]...\n"), "lsmcli");
- fputs(_("\
-Manage storage in external storage arrays.\n\
-\n\
-"), stdout);
- fputs(_("\
-Options include:\n\
- -u, --uri uniform resource identifier (LSMCLI_URI) \n\
- -P, --prompt prompt for password (LSMCLI_PASSWORD)\n\
- -H, print sizes in human readable format\n\
- (e.g., MiB, GiB, TiB)\n\
- -t, --terse=SEP print output in terse form with \"SEP\" as a \n\
- record separator\n\
-"), stdout);
-
- fputs(_("\
- --create-volume=NAME requires:\n\
- --size <volume size> Can use M, G, T\n\
- --pool <pool id>\n\
- --provisioning [DEFAULT|THIN|FULL]\n\
- --delete-volume=ID deletes a volume given its volume id\n\
-"), stdout);
- fputs(_("\
- -r, --replicate=VOLUME_ID replicates a volume, requires:\n\
- --type [SNAPSHOT|CLONE|COPY|MIRROR]\n\
- --pool <pool id>\n\
- --name <human name>\n\
- , --resize-volume=VOLUME_ID resizes a volume, requires:\n\
- --size <new size>\n\
-"), stdout);
- fputs(_("\
- -v, --version print version information and exit\n\
- -h, --help print help text\n\n\n\
-Please report bugs to libstoragemgmt-***@lists.sourceforge.net\n\
-"), stdout);
-
- exit(1);
-}
-
-void version()
-{
- printf("lsmcli version %s, built on %s\n\n", "0.01", __DATE__ ", " __TIME__);
- printf("Copyright 2011 Red Hat, Inc.\n");
- exit(0);
-}
-
-static std::string join(std::vector<std::string> s, std::string del)
-{
- std::string rc = "";
-
- for( size_t i = 0; i < s.size(); ++i) {
- rc += s[i];
- if( i + 1 < s.size()) {
- rc +=del;
- }
- }
-
- return rc;
-}
-
-std::string validateDomain( std::string option, std::string value,
- const std::vector<std::string> &domain)
-{
- std::string arg(value);
- std::transform(arg.begin(), arg.end(), arg.begin(), ::toupper);
-
- for( size_t i = 0; i < domain.size(); ++i ) {
- if( arg == domain[i] ) {
- return arg;
- }
- }
- syntaxError("option (%s) with value (%s) not in set [%s]\n", option.c_str(),
- value.c_str(), join(domain, "|").c_str());
-
- return "Never get here!";
-}
-
-void setCommand( Arguments &args, const std::string &cs, commandTypes c,
- std::string value)
-{
- if( args.c != NONE ) {
- syntaxError(" only one command can be specified at a time, "
- "previous is (%s)\n", args.commandStr.c_str());
- } else {
- args.commandStr = cs;
- args.c = c;
- args.commandValue = value;
- }
-}
-
-static struct option long_options[] = {
- /* These options set a flag. */
- {"uri", required_argument, 0, 'u'}, //0
- {"list", required_argument, 0, 'l'}, //1
- {"create-initiator", required_argument, 0, 0}, //2
- {"create-volume", required_argument, 0, 0}, //3
- {"delete-initiator", required_argument, 0, 0}, //4 //Future use
- {"delete-volume", required_argument, 0, 0}, //5
- {"replicate", required_argument, 0, 'r'}, //6
- {"access-grant", required_argument, 0, 0}, //7
- {"access-revoke", required_argument, 0, 0}, //8
- {"terse", required_argument, 0, 0}, //9
- {"help", no_argument, 0, 'h'}, //10
- {"prompt", no_argument, 0, 'P'}, //11
- {"version", no_argument, 0, 'v'}, //12
- {"size", required_argument, 0, 0}, //13
- {"type", required_argument, 0, 0}, //14
- {"provisioning", required_argument, 0, 0}, //15
- {"access", required_argument, 0, 0}, //16
- {"volume", required_argument, 0, 0}, //17
- {"id", required_argument, 0, 0}, //18
- {"pool", required_argument, 0, 0}, //19
- {"name", required_argument, 0, 0}, //20
- {"resize-volume", required_argument, 0, 0}, //21
- {0, 0, 0, 0}
-};
-
-void parseArguments(int argc, char **argv, Arguments &args) {
- int c;
-
- while (1) {
-
- int long_opt_index = 0;
-
- c = getopt_long(argc, argv, "u:PHr:vht:l:",
- long_options, &long_opt_index);
-
- /* Detect the end of the options. */
- if (c == -1)
- break;
-
- switch (c) {
- case 0: {
- /* If this option set a flag, do nothing else now. */
- if (long_options[long_opt_index].flag != 0)
- break;
-
- if( long_opt_index <= REPLICATE ) {
- setCommand(args, long_options[long_opt_index].name,
- (commandTypes)long_opt_index, optarg);
- } else {
- switch (long_opt_index) {
- case (13): {
- uint64_t s = 0;
-
- if( ! sizeArg(optarg, &s) ) {
- syntaxError("--size %s not in the form "
- "<num>|<num>[M|G|T]\n", optarg);
- }
- args.size.set(optarg);
- break;
- }
- case (14): {
- args.type.set(optarg);
- break;
- }
- case (15): {
- args.provisioning.set(optarg);
- break;
- }
- case (16): {
- args.access.set(optarg);
- break;
- }
- case (17): {
- args.volume.set(optarg);
- break;
- }
- case (18): {
- args.id.set(optarg);
- break;
- }
- case (19): {
- args.pool.set(optarg);
- break;
- }
- case (20): {
- args.name.set(optarg);
- break;
- }
- case (21): {
- setCommand(args, long_options[long_opt_index].name,
- (commandTypes)long_opt_index, optarg);
- break;
- }
- }
- }
- break;
- }
- case('u'): {
- args.uri.set(optarg);
- break;
- }
- case 'l': {
- setCommand(args, "l", LIST, validateDomain("-l", optarg,
- listTypes));
- break;
- }
- case 'h': {
- usage();
- break;
- }
- case 'H': {
- args.human.set(true);
- break;
- }
- case 'P': {
- args.prompt.set(true);
- break;
- }
- case 't': {
- args.terse.set(optarg);
- break;
- }
- case 'v': {
- version();
- break;
- }
- case 'r': {
- setCommand(args, "r", REPLICATE, optarg);
- break;
- }
- case '?': {
- break;
- }
- default: {
- syntaxError("Code bug, missing handler for option %c\n", c);
- }
- }
- }
-}
-
-//Everything parsed, lets see if it logically makes sense.
-void requiredArguments( Arguments &args)
-{
- if( args.c == NONE ) {
- syntaxError("No command specified. -h for help\n");
- } else {
- switch ( args.c ) {
- case (CREATE_VOL) : {
- if( args.size.present && args.pool.present &&
- args.provisioning.present ) {
-
- //Verify provisioning
- validateDomain("--provisioning", args.provisioning.value,
- provTypes);
- } else {
- syntaxError("--%s requires --size, --pool and "
- "--provisioning!\n", args.commandStr.c_str());
- }
- break;
- }
-
- case ( REPLICATE ) : {
- if( args.type.present && args.pool.present &&
- args.name.present) {
-
- validateDomain("--type", args.type.value, repTypes);
-
- } else {
- syntaxError("-%s requires --type and --pool and --name \n",
- args.commandStr.c_str());
- }
- break;
- }
- case ( RESIZE_VOLUME ) : {
- if( !args.size.present ) {
- syntaxError("--%s requires --size\n",
- args.commandStr.c_str());
- }
- break;
- }
- case ( NONE ):
- case ( DELETE_VOL ):
- case ( LIST ) : {
- break;
- }
-
- }
-
- //Check other values.
- if( !args.uri.present ) {
- char *uri_env = getenv("LSMCLI_URI");
- if( uri_env ) {
- args.uri.set(uri_env);
- }
- }
-
- if( !args.uri.present ) {
- syntaxError("uri missing, please use -u "
- "or export LSMCLI_URI=<uri>\n");
- }
-
- //Not prompting for password, then check for ENV.
- if( !args.prompt.present ) {
- char *pw = getenv("LSMCLI_PASSWORD");
- if( pw ) {
- args.password.set(std::string(pw));
- }
- } else {
- args.password.set(std::string(getpass("Password: ")));
- }
- }
-}
-
-void processCommandLine( int argc, char **argv, Arguments &args )
-{
- parseArguments(argc, argv, args);
- requiredArguments(args);
-}
-
-int sizeArg(const char *s, uint64_t *size)
-{
- char units = 'M';
- int rc = 0;
-
- if( s != NULL && size != NULL &&
- (2 == sscanf(s,"%"PRIu64"%c", size, &units)) &&
- (units == 'M' || units == 'G' || units == 'T') ) {
-
- if( units == 'M') {
- *size *= MiB;
- } else if (units == 'G') {
- *size *= GiB;
- } else if (units == 'T') {
- *size *= TiB;
- }
- rc = 1;
- }
- return rc;
-}
-
-std::string sizeHuman(bool human, uint64_t size)
-{
- std::string units ="";
- double s = size;
-
- if( human ) {
- if( size >= TiB ) {
- units=" TiB";
- s /= (double)TiB;
-
- } else if( size >= GiB ) {
- units=" GiB";
- s /= (double)GiB;
-
- } else if( size >= MiB ) {
- units=" MiB";
- s /= (double)MiB;
- }
- }
-
- std::ostringstream o;
- if( human && (size >= MiB) ) {
- o << std::setiosflags(std::ios::fixed) << std::setprecision(2) << s;
- } else {
- o << size;
- }
-
- return o.str() + units;
-}
-
-} //Namespace
diff --git a/tools/lsmcli/arguments.h b/tools/lsmcli/arguments.h
deleted file mode 100644
index 367673d..0000000
--- a/tools/lsmcli/arguments.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#ifndef __ARGUMENTS_H
-#define __ARGUMENTS_H
-
-#include <string>
-#include <vector>
-#include <stdint.h>
-#include <libstoragemgmt/libstoragemgmt_types.h>
-
-namespace LSM {
-
-#define LIST_TYPE_VOL "VOLUMES"
-#define LIST_TYPE_POOL "POOLS"
-#define LIST_TYPE_INIT "INITIATORS"
-
-#define INIT_TYPE_WWPN "WWPN"
-#define INIT_TYPE_WWNN "WWNN"
-#define INIT_TYPE_ISCSI "ISCSI"
-#define INIT_TYPE_HN "HOSTNAME"
-
-#define PROV_TYPE_DEFAULT "DEFAULT"
-#define PROV_TYPE_THIN "THIN"
-#define PROV_TYPE_FULL "FULL"
-
-#define REP_TYPE_SNAPSHOT "SNAPSHOT"
-#define REP_TYPE_CLONE "CLONE"
-#define REP_TYPE_COPY "COPY"
-#define REP_TYPE_MIRROR "MIRROR"
-
-#define ACCESS_TYPE_RW "RW"
-#define ACCESS_TYPE_RO "RO"
-
-template <class Type>
-class Arg {
-public:
- bool present;
- Type value;
-
- Arg() : present(false) {
- }
-
- void set(Type t) {
- present = true;
- value = t;
- }
-};
-
-/**
- * Enumerated commands. Note: make sure they match array index for long_options
- */
-typedef enum {
- NONE = -1,
- LIST = 1,
- //CREATE_INIT = 2,
- CREATE_VOL = 3,
- //DELETE_INIT = 4,
- DELETE_VOL = 5,
- REPLICATE = 6,
- //ACCESS_GRANT = 7,
- //ACCESS_REVOKE = 8,
- RESIZE_VOLUME = 21,
-} commandTypes;
-
-/**
- * Class the encapsulates the command line arguments.
- */
-class Arguments {
-public:
- Arguments():c(NONE){}
-
- /**
- * Uri.
- */
- Arg<std::string> uri;
-
- /**
- * Prompt for password
- */
- Arg<bool> prompt;
-
- /**
- * Output sizes as human
- */
- Arg<bool> human;
-
- /**
- * Use terse output
- */
- Arg<std::string> terse;
-
- /**
- * Generic identifier, needs command for context.
- */
- Arg<std::string> id;
-
- /**
- * Generic type, needs command for context.
- */
- Arg<std::string> type;
-
- /**
- * Generic name, needs command for context.
- */
- Arg<std::string> name;
-
- /**
- * Size specifier, needs command for context.
- */
- Arg<std::string> size;
-
- /**
- * Pool specifier, needs command for context.
- */
- Arg<std::string> pool;
-
- /**
- * Provision specifier, needs command for context.
- */
- Arg<std::string> provisioning;
-
- /**
- * Access specifier, needs command for context.
- */
- Arg<std::string> access;
-
- /**
- * Connection password, needs command for context.
- */
- Arg<std::string> password;
-
- /**
- * Volume specifier, needs command for context.
- */
- Arg<std::string> volume;
-
- /**
- * Actual command to execute
- */
- commandTypes c;
-
- /**
- * String representation of command.
- */
- std::string commandStr;
-
- /**
- * Command value.
- */
- std::string commandValue;
-
- /**
- * Convert string representation to enum.
- * @return lsmInitiatorType value
- */
- lsmInitiatorType initiatorType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmProvisionType value
- */
- lsmProvisionType provisionType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmReplicationType value.
- */
- lsmReplicationType replicationType() const;
-
- /**
- * Convert string representation to enum.
- * @return lsmAccessType value.
- */
- lsmAccessType accessType() const;
-};
-
-/**
- * Processes the command line arguments.
- * Note: This function will exit() on missing/bad arguments.
- * @param argc Command line argument count
- * @param argv Arguments
- * @param args Class which holds the parsed arguments.
- */
-void processCommandLine( int argc, char **argv, Arguments &args );
-
-
-const uint64_t MiB = 1048576; //2**20
-const uint64_t GiB = 1073741824; //2**30
-const uint64_t TiB = 1099511627776ULL; //2**40
-
-/**
- * Validates and returns the value of size that the user supplied
- * @param s String in the form [0-9]+[MGT]
- * @param[out] size Size in bytes.
- * @return 1 if parsed OK, else 0.
- */
-int sizeArg(const char* s, uint64_t *size);
-
-/**
- * Returns a string representation of a size
- * @param human True use human readable size.
- * @param size Size to represent
- * @return Size represented as a string.
- */
-std::string sizeHuman(bool human, uint64_t size);
-
-} //namespace
-
-#endif
diff --git a/tools/lsmcli/lsmcli.cpp b/tools/lsmcli/lsmcli.cpp
deleted file mode 100644
index 0b3b6a3..0000000
--- a/tools/lsmcli/lsmcli.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#include <iostream>
-#include <string>
-#include <stdio.h>
-#include "arguments.h"
-#include "lsmcli_func.h"
-#include <libstoragemgmt/libstoragemgmt.h>
-
-void debug_plugin(void)
-{
- char *debug = getenv("LSM_DEBUG_PLUGIN");
- if( debug ) {
- printf("Attach debugger to plug-in, press any key when ready...");
- ::getchar();
- }
-}
-
-
-int main(int argc, char *argv[])
-{
- lsmConnect *c = NULL;
- lsmErrorPtr e = NULL;
-
- LSM::Arguments a;
- LSM::processCommandLine(argc, argv, a);
-
- int main_rc = 0;
- int lib_rc = lsmConnectPassword(a.uri.value.c_str(),
- a.password.value.c_str(), &c, 30000, &e,
- LSM_FLAG_RSVD);
-
- if( LSM_ERR_OK == lib_rc ) {
- debug_plugin();
- switch( a.c ) {
- case (LSM::LIST) : {
- main_rc = list(a,c);
- break;
- }
- case (LSM::CREATE_VOL) : {
- main_rc = createVolume(a,c);
- break;
- }
- case (LSM::DELETE_VOL) : {
- main_rc = deleteVolume(a,c);
- break;
- }
- case (LSM::REPLICATE) : {
- main_rc = replicateVolume(a,c);
- break;
- }
- case (LSM::RESIZE_VOLUME) : {
- main_rc = resizeVolume(a,c);
- break;
- }
- case (LSM::NONE): {
- break;
- }
- }
-
- lib_rc = lsmConnectClose(c, LSM_FLAG_RSVD);
- if( LSM_ERR_OK != lib_rc ) {
- printf("Error on close %d!\n", lib_rc);
- }
- } else {
- dumpError(lib_rc, e);
- }
- return main_rc;
-}
\ No newline at end of file
diff --git a/tools/lsmcli/lsmcli_func.cpp b/tools/lsmcli/lsmcli_func.cpp
deleted file mode 100644
index 323eaa4..0000000
--- a/tools/lsmcli/lsmcli_func.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-#include "lsmcli_func.h"
-#include "arguments.h"
-#include <stdio.h>
-#include <assert.h>
-#include <stdint.h>
-#define __STDC_FORMAT_MACROS /* To use PRIu64 */
-#include <inttypes.h>
-#include <unistd.h>
-
-lsmInitiator *getInitiator(lsmConnect *c, std::string initId);
-
-void printVolume(const LSM::Arguments &a, lsmVolume *v)
-{
- const char *id = lsmVolumeIdGet(v);
- const char *name = lsmVolumeNameGet(v);
- const char *vpd = lsmVolumeVpd83Get(v);
- uint64_t block_size = lsmVolumeBlockSizeGet(v);
- uint64_t block_num = lsmVolumeNumberOfBlocksGet(v);
- uint32_t status = lsmVolumeOpStatusGet(v);
- uint64_t size = block_size * block_num;
- std::string s = LSM::sizeHuman(a.human.present, size);
-
- if( a.terse.present ) {
- const char *sep = a.terse.value.c_str();
-
- printf("%s%s%s%s%s%s%"PRIu64"%s%"PRIu64"%s%u%s%s\n", id, sep, name,
- sep, vpd, sep, block_size, sep, block_num, sep,
- status, sep, s.c_str());
- } else {
- printf("%s %-40s\t%s %-8"PRIu64"\t%-17"PRIu64"\t%u\t%20s\n", id, name,
- vpd, block_size, block_num, status, s.c_str());
- }
-}
-
-void printInitiator(const LSM::Arguments &a, lsmInitiator *i)
-{
- const char format[] = "%-40s%-16s%-5d\n";
- const char *sep = NULL;
-
- const char *id = lsmInitiatorIdGet(i);
- const char *name = lsmInitiatorNameGet(i);
- lsmInitiatorType type = lsmInitiatorTypeGet(i);
-
- if( a.terse.present ) {
- sep = a.terse.value.c_str();
- }
-
- if( a.terse.present ) {
- printf("%s%s%s%s%d\n", id, sep, name, sep, type);
- } else {
- printf(format, id, name, type);
- }
-}
-
-int waitForJob(int cmd_rc, lsmConnect *c, char *job,
- const LSM::Arguments &a, lsmVolume **vol)
-{
- lsmVolume *new_volume = NULL;
- int rc = cmd_rc;
- //Check to see if we are done!
- if( LSM_ERR_OK != rc ) {
- if ( LSM_ERR_JOB_STARTED == rc ) {
- //We have a job to wait for.
- lsmJobStatus status;
- uint8_t percent = 0;
-
- do {
- usleep(10000);
- rc = lsmJobStatusVolumeGet(c, job, &status, &percent, &new_volume, 0);
- //printf("job = %s, status %d, percent %d\n", job, status, percent);
- } while ( (LSM_JOB_INPROGRESS == status) && (LSM_ERR_OK == rc) );
-
- if( vol != NULL) {
- *vol = new_volume;
- } else {
- if( new_volume ) {
- lsmVolumeRecordFree(new_volume);
- new_volume = NULL;
- }
- }
-
- if( (LSM_ERR_OK == rc) && (LSM_JOB_COMPLETE == status) && new_volume ) {
- printVolume(a, new_volume);
- } else {
- printf("RC = %d, job = %s, status %d, percent %d\n", rc, job, status, percent);
- }
-
- //Clean up the job
- int jf = lsmJobFree(c, &job, 0);
- if( LSM_ERR_OK != jf ) {
- printf("lsmJobFree rc= %d\n", jf);
- }
- assert(LSM_ERR_OK == jf);
-
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- } else {
- if( vol ) {
- printVolume(a, *vol);
- }
- }
-
- if( vol ) {
- lsmVolumeRecordFree(*vol);
- }
-
- return rc;
-}
-
-void dumpError(int ec, lsmErrorPtr e)
-{
- printf("Error occurred: %d\n", ec);
-
- if( e ) {
- printf("Msg: %s\n", lsmErrorGetMessage(e));
- printf("Exception: %s\n", lsmErrorGetException(e));
- lsmErrorFree(e);
- }
-}
-
-//NOTE: Re-factor these three functions as they are too similar and could be
-//consolidated.
-static int listVolumes(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmVolume **vol = NULL;
- uint32_t num_vol = 0;
-
- rc = lsmVolumeList(c, &vol, & num_vol, 0);
-
- if( rc == LSM_ERR_OK ) {
- uint32_t i;
-
- if( !a.terse.present ) {
- printf("ID Name vpd83 "
- " bs #blocks status size\n");
- }
-
- for( i = 0; i < num_vol; ++i ) {
- printVolume(a, vol[i]);
- }
-
- lsmVolumeRecordFreeArray(vol, num_vol);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-static int listInitiators(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmInitiator **init = NULL;
- uint32_t num_init = 0;
- const char format[] = "%-40s%-16s%-5s\n";
-
- rc = lsmInitiatorList(c, &init, &num_init, 0);
-
- if( LSM_ERR_OK == rc ) {
- uint32_t i = 0;
-
- if( !a.terse.present ) {
- printf(format, "ID", "Name", "Type");
- }
-
- for( i = 0; i < num_init; ++i ) {
- printInitiator(a,init[i]);
- }
- lsmInitiatorRecordFreeArray(init,num_init);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-static int listPools(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmPool **pool = NULL;
- uint32_t num_pool = 0;
- const char *sep = NULL;
-
- rc = lsmPoolList(c, &pool, &num_pool, 0);
-
- if( LSM_ERR_OK == rc ) {
- uint32_t i = 0;
-
- if( a.terse.present ) {
- sep = a.terse.value.c_str();
- } else {
- printf("ID Name"
- " Total space "
- " Free space\n");
- }
-
- for( i = 0; i < num_pool; ++i ) {
- const char *id = lsmPoolIdGet(pool[i]);
- const char *name = lsmPoolNameGet(pool[i]);
- uint64_t total = lsmPoolTotalSpaceGet(pool[i]);
- uint64_t free = lsmPoolFreeSpaceGet(pool[i]);
-
- if( a.terse.present ) {
- printf("%s%s%s%s%s%s%s\n", id, sep, name, sep,
- LSM::sizeHuman(a.human.present, total).c_str(), sep,
- LSM::sizeHuman(a.human.present, free).c_str());
- } else {
- printf("%s\t%s\t%32s\t%32s\n", id, name,
- LSM::sizeHuman(a.human.present, total).c_str(),
- LSM::sizeHuman(a.human.present, free).c_str() );
- }
- }
-
- lsmPoolRecordFreeArray(pool,num_pool);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return rc;
-}
-
-int list(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- if( a.commandValue == LIST_TYPE_VOL ) {
- rc = listVolumes(a,c);
- } else if ( a.commandValue == LIST_TYPE_INIT ) {
- rc = listInitiators(a,c);
- } else if ( a.commandValue == LIST_TYPE_POOL ) {
- rc = listPools(a,c);
- }
-
- return rc;
-}
-
-//Re-factor these next three functions as they are similar.
-lsmPool *getPool(lsmConnect *c, std::string poolId)
-{
- int rc = 0;
- lsmPool *p = NULL;
- lsmPool **pool = NULL;
- uint32_t num_pool = 0;
- uint32_t i = 0;
-
- rc = lsmPoolList(c, &pool, &num_pool, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_pool; ++i ) {
- if( poolId == lsmPoolIdGet(pool[i])) {
- p = lsmPoolRecordCopy(pool[i]);
- break;
- }
- }
- lsmPoolRecordFreeArray(pool, num_pool);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-lsmVolume *getVolume(lsmConnect *c, std::string volumeId)
-{
- int rc = 0;
- lsmVolume *p = NULL;
- lsmVolume **vol = NULL;
- uint32_t num_vol = 0;
- uint32_t i = 0;
-
- rc = lsmVolumeList(c, &vol, &num_vol, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_vol; ++i ) {
- if( volumeId == lsmVolumeIdGet(vol[i])) {
- p = lsmVolumeRecordCopy(vol[i]);
- break;
- }
- }
- lsmVolumeRecordFreeArray(vol, num_vol);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-lsmInitiator *getInitiator(lsmConnect *c, std::string initId)
-{
- int rc = 0;
- lsmInitiator *p = NULL;
- lsmInitiator **inits = NULL;
- uint32_t num_inits = 0;
- uint32_t i = 0;
-
- rc = lsmInitiatorList(c, &inits, &num_inits, 0);
-
- if( LSM_ERR_OK == rc ) {
- for( i = 0; i < num_inits; ++i ) {
- if( initId == lsmInitiatorIdGet(inits[i])) {
- p = lsmInitiatorRecordCopy(inits[i]);
- break;
- }
- }
- lsmInitiatorRecordFreeArray(inits, num_inits);
- } else {
- dumpError(rc, lsmErrorGetLast(c));
- }
- return p;
-}
-
-int createVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- lsmVolume *vol = NULL;
- char *job = NULL;
- uint64_t size = 0;
- lsmPool *pool = NULL;
-
- //Get the pool of interest
- pool = getPool(c, a.pool.value);
- if( pool ) {
-
- LSM::sizeArg(a.size.value.c_str(), &size);
-
- rc = lsmVolumeCreate(c,pool, a.commandValue.c_str(),
- size, a.provisionType(), &vol, &job, 0);
-
- rc = waitForJob(rc, c, job, a, &vol);
-
- lsmPoolRecordFree(pool);
- } else {
- printf("Pool with id= %s not found!\n", a.pool.value.c_str());
- }
- return rc;
-}
-
-int deleteVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- //Get the volume pointer to the record in question to delete.
- lsmVolume *vol = getVolume(c, a.commandValue);
-
- if( vol ) {
- rc = lsmVolumeDelete(c, vol, &job, 0);
- rc = waitForJob(rc, c, job, a);
- } else {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
- return rc;
-}
-
-int replicateVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- lsmVolume *newVol = NULL;
- lsmVolume *vol = getVolume(c, a.commandValue);
- lsmPool *pool = getPool(c, a.pool.value);
-
-
- if( vol && pool ) {
- rc = lsmVolumeReplicate(c, pool, a.replicationType(), vol,
- a.name.value.c_str(), &newVol, &job, 0);
- rc = waitForJob(rc, c, job, a, &newVol);
- } else {
- if( !vol ) {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
-
- if( !pool ) {
- printf("Pool with id= %s not found!\n", a.pool.value.c_str());
- }
- }
-
- if( vol ) {
- lsmVolumeRecordFree(vol);
- vol = NULL;
- }
-
- if( pool ) {
- lsmPoolRecordFree(pool);
- pool = NULL;
- }
-
- return rc;
-}
-
-int resizeVolume(const LSM::Arguments &a, lsmConnect *c)
-{
- int rc = 0;
- char *job = NULL;
- uint64_t size = 0;
- lsmVolume *newVol = NULL;
- lsmVolume *vol = getVolume(c, a.commandValue);
-
- LSM::sizeArg(a.size.value.c_str(), &size);
-
- if( vol ) {
- rc = lsmVolumeResize(c, vol, size, &newVol, &job, 0);
- rc = waitForJob(rc, c, job, a, &newVol);
- } else {
- printf("Volume with id= %s not found!\n", a.commandValue.c_str());
- }
-
- if( vol ) {
- lsmVolumeRecordFree(vol);
- vol = NULL;
- }
- return rc;
-}
diff --git a/tools/lsmcli/lsmcli_func.h b/tools/lsmcli/lsmcli_func.h
deleted file mode 100644
index 840b773..0000000
--- a/tools/lsmcli/lsmcli_func.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2011-2013 Red Hat, Inc.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author: tasleson
- */
-
-#ifndef _LSMCLI_FUNC_H
-#define _LSMCLI_FUNC_H
-
-#include "arguments.h"
-#include <libstoragemgmt/libstoragemgmt.h>
-
-/**
- * Used to wait for a job to complete.
- * @param cmd_rc The return code of the library call that may have a job
- * @param c Connection
- * @param job Job id
- * @param a Command line arguments
- * @param vol New volume to print out.
- * @return LSM_ERR_OK on success else error reason.
- */
-int waitForJob(int cmd_rc, lsmConnect *c, char *job,
- const LSM::Arguments &a, lsmVolume **vol = NULL);
-
-/**
- * Dumps error information to stdout.
- * @param ec Error code
- * @param e Error record.
- */
-void dumpError(int ec, lsmErrorPtr e);
-
-/**
- * Dumps Volumes, initiators, pools to stdout.
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int list(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Creates an initiator to use for access granting.
- * @param a Command Line arguments
- * @param c Connection.
- * @return LSM_ERR_OK on success, else error reason.
- */
-int createInit(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Deletes an initiator
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int deleteInit(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Creates a volume
- * @param a Command line arguments.
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int createVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Deletes a volume
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int deleteVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Replicates a volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int replicateVolume(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Allows an initiator to use a volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int accessGrant(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Revokes access for an initiator to a volume.
- * @param a Command line arguments.
- * @param c Connection.
- * @return LSM_ERR_OK on success, else error reason.
- */
-int accessRevoke(const LSM::Arguments &a, lsmConnect *c);
-
-/**
- * Resize an existing volume.
- * @param a Command line arguments
- * @param c Connection
- * @return LSM_ERR_OK on success, else error reason.
- */
-int resizeVolume(const LSM::Arguments &a, lsmConnect *c);
-
-#endif
\ No newline at end of file
--
1.8.2.1
Loading...