Tony Asleson
2014-06-03 21:40:13 UTC
Patch to add property filtering on some of the listing functions.
I tried a few different approaches, but ended up going with this.
V2: Code change reductions, memory leak fixes, added capability
constants and error code for invalid key.
V3: Re-name filtering functions to be closer to python name
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 52 +-
.../libstoragemgmt/libstoragemgmt_capabilities.h | 10 +-
.../include/libstoragemgmt/libstoragemgmt_error.h | 5 +-
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 110 +++-
c_binding/lsm_mgmt.cpp | 129 ++++-
c_binding/lsm_plugin_ipc.cpp | 298 +++++++++-
plugin/simc/simc_lsmplugin.c | 57 +-
test/tester.c | 622 +++++++++++++++++----
8 files changed, 1112 insertions(+), 171 deletions(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index 96be652..cca683a 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -226,12 +226,15 @@ extern "C" {
/**
* Query the list of storage pools on the array.
* @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] pool_array Array of storage pools
* @param[out] count Number of storage pools
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_pool_list(lsm_connect *conn, lsm_pool **pool_array[],
+ int LSM_DLL_EXPORT lsm_pool_list(lsm_connect *conn, char *search_key,
+ char *search_value, lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -363,25 +366,36 @@ extern "C" {
/**
* Gets a list of logical units for this array.
- * @param[in] conn Valid connection @see lsm_connect_password
- * @param[out] volumes An array of lsm_volume
- * @param[out] count Number of elements in the lsm_volume array
- * @param[in] flags Reserved for future use, must be zero.
+ * @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param[out] volumes An array of lsm_volume
+ * @param[out] count Number of elements in the lsm_volume array
+ * @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_volume_list(lsm_connect *conn, lsm_volume **volumes[],
+ int LSM_DLL_EXPORT lsm_volume_list(lsm_connect *conn,
+ const char *search_key,
+ const char *search_value,
+ lsm_volume **volumes[],
uint32_t *count, lsm_flag flags);
/**
* Get a list of disk for this array.
- * @param [in] conn Valid connection @see lsm_connect_password
- * @param [out] disks An array of lsm_disk types
- * @param [out] count Number of disks
- * @param [in] flags Use LSM_DISK_RETRIEVE_FULL_INFO for all data, else 0
+ * @param [in] conn Valid connection @see
+ * lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param [out] disks An array of lsm_disk types
+ * @param [out] count Number of disks
+ * @param [in] flags Use LSM_DISK_RETRIEVE_FULL_INFO for all
+ * data, else 0
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_disk_list(lsm_connect *conn, lsm_disk **disks[],
- uint32_t *count, lsm_flag flags);
+ int LSM_DLL_EXPORT lsm_disk_list(lsm_connect *conn, const char * search_key,
+ const char *search_value,
+ lsm_disk **disks[], uint32_t *count,
+ lsm_flag flags);
/**
* Creates a new volume (aka. LUN).
@@ -550,12 +564,16 @@ extern "C" {
/**
* Retrieves a list of access groups.
* @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] groups Array of access groups
* @param[out] group_count Size of array
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success, else error reason.
*/
int LSM_DLL_EXPORT lsm_access_group_list(lsm_connect *conn,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count,
lsm_flag flags);
@@ -745,12 +763,15 @@ extern "C" {
/**
* Retrieves information about the available file systems.
* @param[in] conn Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] fs Array of lsm_fs
* @param[out] fs_count Number of file systems
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success, else error reason
*/
- int LSM_DLL_EXPORT lsm_fs_list(lsm_connect *conn, lsm_fs **fs[],
+ int LSM_DLL_EXPORT lsm_fs_list(lsm_connect *conn, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
uint32_t *fs_count, lsm_flag flags);
/**
@@ -935,12 +956,15 @@ extern "C" {
/**
* Lists the nfs exports on the specified array.
* @param[in] c Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] exports An array of lsm_nfs_export
* @param[out] count Number of items in array
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error code.
*/
- int LSM_DLL_EXPORT lsm_nfs_list( lsm_connect *c,
+ int LSM_DLL_EXPORT lsm_nfs_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
lsm_nfs_export **exports[],
uint32_t *count, lsm_flag flags);
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
index 5a3bc86..6f0e57c 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
@@ -142,7 +142,15 @@ typedef enum {
LSM_CAP_POOL_CREATE_VOLUME_RAID_16 = 173,
LSM_CAP_POOL_CREATE_VOLUME_RAID_NOT_APPLICABLE = 174,
- LSM_CAP_POOL_DELETE = 200 /**< Pool delete support */
+ LSM_CAP_POOL_DELETE = 200, /**< Pool delete support */
+
+ LSM_CAP_POOLS_QUICK_SEARCH = 210, /**< Seach occurs on array */
+ LSM_CAP_VOLUMES_QUICK_SEARCH = 211, /**< Seach occurs on array */
+ LSM_CAP_DISKS_QUICK_SEARCH = 212, /**< Seach occurs on array */
+ LSM_CAP_ACCESS_GROUPS_QUICK_SEARCH = 213, /**< Seach occurs on array */
+ LSM_CAP_FS_QUICK_SEARCH = 214, /**< Seach occurs on array */
+ LSM_CAP_NFS_EXPORTS_QUICK_SEARCH = 215 /**< Seach occurs on array */
+
} lsm_capability_type;
/**
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_error.h b/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
index 03fb079..68954c8 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
@@ -134,7 +134,10 @@ typedef enum {
LSM_ERR_UNSUPPORTED_REPLICATION_TYPE = 452, /**< Unsupported replication type */
LSM_ERR_DISK_BUSY = 500, /* Disk already in use */
- LSM_ERR_VOLUME_BUSY = 501 /* Volume already in use */
+ LSM_ERR_VOLUME_BUSY = 501, /* Volume already in use */
+
+
+ LSM_ERR_UNSUPPORTED_SEARCH_KEY = 510 /**< Unsupport search key */
} lsm_error_number;
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index dc18fa4..b76805c 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -151,12 +151,16 @@ typedef int (*lsm_plug_job_free)(lsm_plugin_ptr c, char *job_id, lsm_flag flags)
/**
* Retrieves a list of pools callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] pool_array List of pools
* @param[out] count Number of items in array
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_pool_list)( lsm_plugin_ptr c, lsm_pool **pool_array[],
+typedef int (*lsm_plug_pool_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -196,23 +200,31 @@ typedef int (*lsm_plug_init_list)( lsm_plugin_ptr c, lsm_initiator **init_array[
/**
* Retrieve a list of volumes.
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] vol_array Array of volumes
* @param[out] count Number of volumes
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_volume_list)( lsm_plugin_ptr c, lsm_volume **vol_array[],
+typedef int (*lsm_plug_volume_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_val,
+ lsm_volume **vol_array[],
uint32_t *count, lsm_flag flags);
/**
* Retrieve a list of volumes.
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] disk_array Array of disk pointers
* @param[out] count Number of disks
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, lsm_disk **disk_array[],
+typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_disk **disk_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -497,12 +509,16 @@ typedef int (*lsm_plug_iscsi_chap_auth)(lsm_plugin_ptr c,
/**
* Retrieve a list of access groups, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Field to search on
+ * @param[in] search_value Field value
* @param[out] groups Array of groups
* @param[out] group_count Number of groups
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
typedef int (*lsm_plug_access_group_list)(lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count, lsm_flag flags);
/**
@@ -657,12 +673,15 @@ typedef int (*lsm_plug_volume_child_dependency_delete)(lsm_plugin_ptr c,
/**
* File system list, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] fs An array of file systems
* @param[out] fs_count Number of file systems
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_fs_list)(lsm_plugin_ptr c, lsm_fs **fs[],
+typedef int (*lsm_plug_fs_list)(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
uint32_t *fs_count, lsm_flag flags);
/**
@@ -827,14 +846,17 @@ typedef int (*lsm_plug_nfs_auth_types)( lsm_plugin_ptr c,
/**
* Retrieve a list of NFS exports, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] exports An array of exported file systems
* @param[out] count Number of exported file systems
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_nfs_list)( lsm_plugin_ptr c,
- lsm_nfs_export **exports[],
- uint32_t *count, lsm_flag flags);
+typedef int (*lsm_plug_nfs_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_nfs_export **exports[],
+ uint32_t *count, lsm_flag flags);
/**
* Exports a file system via NFS, callback function signature
* @param[in] c Valid lsm plug-in pointer
@@ -1278,6 +1300,80 @@ int LSM_DLL_EXPORT lsm_uri_parse(const char *uri, char **scheme, char **user,
char **server, int *port, char **path,
lsm_optional_data **query_params);
+/**
+ * Provides for volume filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] vols Array to filter
+ * @param[in,out] count Number of volumes to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_volume_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_volume *vols[],
+ uint32_t *count);
+
+/**
+ * Provides for pool filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] pools Array to filter
+ * @param[in,out] count Number of pools to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_pool_search_filter( const char *search_key,
+ const char *search_value,
+ lsm_pool *pools[], uint32_t *count);
+
+/**
+ * Provides for disk filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] disks Array to filter
+ * @param[in,out] count Number of disks to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_disk_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_disk *disks[], uint32_t *count);
+
+/**
+ * Provides for access group filtering when an array doesn't support this
+ * natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] disks Array to filter
+ * @param[in,out] count Number of access groups to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_access_group_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_access_group *ag[], uint32_t *count);
+
+/**
+ * Provides for fs filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] fs Array to filter
+ * @param[in,out] count Number of file systems to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_fs_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_fs *fs[], uint32_t *count);
+
+/**
+ * Provides for nfs filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] fs Array to filter
+ * @param[in,out] count Number of nfs exports to filter, number remain
+ */
+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);
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 61c3d0f..bbdad07 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -29,6 +29,26 @@
#include "lsm_datatypes.hpp"
#include "lsm_convert.hpp"
+#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+
+static const char * const POOL_SEARCH_KEYS[] = { "id", "system_id" };
+#define POOL_SEARCH_KEYS_COUNT COUNT_OF(POOL_SEARCH_KEYS)
+
+static const char * const VOLUME_SEARCH_KEYS[] = {"id", "system_id", "pool_id"};
+#define VOLUME_SEARCH_KEYS_COUNT COUNT_OF(VOLUME_SEARCH_KEYS)
+
+static const char * const DISK_SEARCH_KEYS[] = {"id", "system_id"};
+#define DISK_SEARCH_KEYS_COUNT COUNT_OF(DISK_SEARCH_KEYS)
+
+static const char * const FS_SEARCH_KEYS[] = {"id", "system_id", "pool_id"};
+#define FS_SEARCH_KEYS_COUNT COUNT_OF(FS_SEARCH_KEYS)
+
+static const char * const NFS_EXPORT_SEARCH_KEYS[] = {"id", "fs_id"};
+#define NFS_EXPORT_SEARCH_KEYS_COUNT COUNT_OF(NFS_EXPORT_SEARCH_KEYS)
+
+static const char * const ACCESS_GROUP_SEARCH_KEYS[] = {"id", "system_id"};
+#define ACCESS_GROUP_SEARCH_KEYS_COUNT COUNT_OF(ACCESS_GROUP_SEARCH_KEYS)
+
/**
* Common code to validate and initialize the connection.
*/
@@ -40,6 +60,19 @@
c->error = NULL; \
} while (0)
+static int check_search_key(const char *search_key,
+ const char * const supported_keys[],
+ size_t supported_keys_count)
+{
+ size_t i = 0;
+ for( i = 0; i < supported_keys_count; ++i ) {
+ if( 0 == strcmp(search_key, supported_keys[i])) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
/**
* Strings are non null with a len >= 1
*/
@@ -184,6 +217,24 @@ static int getAccessGroups( lsm_connect *c, int rc, Value &response,
return rc;
}
+static int add_search_params(std::map<std::string, Value> &p, const char *k,
+ const char *v, const char * const supported_keys[],
+ size_t supported_keys_count)
+{
+ if( k ) {
+ if( v ) {
+ if( !check_search_key(k, supported_keys, supported_keys_count) ) {
+ return LSM_ERR_UNSUPPORTED_SEARCH_KEY;
+ }
+ } else {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+ }
+ p["search_key"] = Value(k);
+ p["search_value"] = Value(v);
+ return LSM_ERR_OK;
+}
+
int lsm_connect_close(lsm_connect *c, lsm_flag flags)
{
CONN_SETUP(c);
@@ -625,8 +676,8 @@ int lsm_capabilities(lsm_connect *c, lsm_system *system,
return rc;
}
-int lsm_pool_list(lsm_connect *c, lsm_pool **poolArray[],
- uint32_t *count, lsm_flag flags)
+int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,
+ lsm_pool **poolArray[], uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -637,6 +688,13 @@ int lsm_pool_list(lsm_connect *c, lsm_pool **poolArray[],
try {
std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value, POOL_SEARCH_KEYS,
+ POOL_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
@@ -737,8 +795,9 @@ static int get_volume_array(lsm_connect *c, int rc, Value &response,
}
-int lsm_volume_list(lsm_connect *c, lsm_volume **volumes[], uint32_t *count,
- lsm_flag flags)
+int lsm_volume_list(lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_volume **volumes[],
+ uint32_t *count, lsm_flag flags)
{
CONN_SETUP(c);
@@ -750,10 +809,16 @@ int lsm_volume_list(lsm_connect *c, lsm_volume **volumes[], uint32_t *count,
std::map<std::string, Value> p;
p["flags"] = Value(flags);
+ int rc = add_search_params(p, search_key, search_value, VOLUME_SEARCH_KEYS,
+ VOLUME_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
Value parameters(p);
Value response;
- int rc = rpc(c, "volumes", parameters, response);
+ rc = rpc(c, "volumes", parameters, response);
return get_volume_array(c, rc, response, volumes, count);
}
@@ -771,8 +836,9 @@ static int get_disk_array(lsm_connect *c, int rc, Value &response,
return rc;
}
-int lsm_disk_list(lsm_connect *c, lsm_disk **disks[],
- uint32_t *count, lsm_flag flags)
+int lsm_disk_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_disk **disks[], uint32_t *count, lsm_flag flags)
{
CONN_SETUP(c);
@@ -783,10 +849,16 @@ int lsm_disk_list(lsm_connect *c, lsm_disk **disks[],
std::map<std::string, Value> p;
p["flags"] = Value(flags);
+ int rc = add_search_params(p, search_key, search_value, DISK_SEARCH_KEYS,
+ DISK_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
Value parameters(p);
Value response;
- int rc = rpc(c, "disks", parameters, response);
+ rc = rpc(c, "disks", parameters, response);
return get_disk_array(c, rc, response, disks, count);
}
@@ -1468,8 +1540,10 @@ int lsm_volume_offline(lsm_connect *c, lsm_volume *volume, lsm_flag flags)
return online_offline(c, volume, "volume_offline", flags);
}
-int lsm_access_group_list( lsm_connect *c, lsm_access_group **groups[],
- uint32_t *groupCount, lsm_flag flags)
+int lsm_access_group_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_access_group **groups[], uint32_t *groupCount,
+ lsm_flag flags)
{
CONN_SETUP(c);
@@ -1478,11 +1552,19 @@ int lsm_access_group_list( lsm_connect *c, lsm_access_group **groups[],
}
std::map<std::string, Value> p;
+
+ int rc = add_search_params(p, search_key, search_value,
+ ACCESS_GROUP_SEARCH_KEYS,
+ ACCESS_GROUP_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
- int rc = rpc(c, "access_groups", parameters, response);
+ rc = rpc(c, "access_groups", parameters, response);
return getAccessGroups(c, rc, response, groups, groupCount);
}
@@ -1849,8 +1931,9 @@ int lsm_system_list(lsm_connect *c, lsm_system **systems[],
return rc;
}
-int lsm_fs_list(lsm_connect *c, lsm_fs **fs[], uint32_t *fsCount,
- lsm_flag flags)
+int lsm_fs_list(lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
+ uint32_t *fsCount, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -1861,6 +1944,13 @@ int lsm_fs_list(lsm_connect *c, lsm_fs **fs[], uint32_t *fsCount,
try {
std::map<std::string, Value> p;
+
+ int rc = add_search_params(p, search_key, search_value, FS_SEARCH_KEYS,
+ FS_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
@@ -2289,8 +2379,9 @@ int lsm_fs_ss_restore(lsm_connect *c, lsm_fs *fs, lsm_fs_ss *ss,
}
-int lsm_nfs_list( lsm_connect *c, lsm_nfs_export **exports[], uint32_t *count,
- lsm_flag flags)
+int lsm_nfs_list( lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_nfs_export **exports[],
+ uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -2301,6 +2392,14 @@ int lsm_nfs_list( lsm_connect *c, lsm_nfs_export **exports[], uint32_t *count,
try {
std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value,
+ NFS_EXPORT_SEARCH_KEYS,
+ NFS_EXPORT_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index bd60516..2f880b1 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -203,6 +203,33 @@ static void error_send(lsm_plugin_ptr p, int error_code)
}
}
+static int get_search_params(Value ¶ms, char **k, char **v)
+{
+ int rc = LSM_ERR_OK;
+ Value key = params["search_key"];
+ Value val = params["search_value"];
+
+ if( Value::string_t == key.valueType() ) {
+ if ( Value::string_t == val.valueType() ) {
+ *k = strdup(key.asC_str());
+ *v = strdup(val.asC_str());
+
+ if( *k == NULL || *v == NULL ) {
+ free( *k );
+ *k = NULL;
+ free( *v );
+ *v = NULL;
+ rc = LSM_ERR_NO_MEMORY;
+ }
+ } else {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+ } else if( Value::null_t != key.valueType() ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+
+ return rc;
+}
/**
* Checks to see if a character string is an integer and returns result
@@ -450,13 +477,16 @@ static int handle_system_list(lsm_plugin_ptr p, Value ¶ms,
static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->mgmt_ops && p->mgmt_ops->pool_list ) {
lsm_pool **pools = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->mgmt_ops->pool_list(p, &pools, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
+ rc = p->mgmt_ops->pool_list(p, key, val, &pools, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc) {
std::vector<Value> result;
@@ -469,8 +499,12 @@ static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
pools = NULL;
response = Value(result);
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -772,19 +806,26 @@ static void get_volumes(int rc, lsm_volume **vols, uint32_t count,
static int handle_volumes(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->vol_get ) {
lsm_volume **vols = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->san_ops->vol_get(p, &vols, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->san_ops->vol_get(p, key, val, &vols, &count,
LSM_FLAG_GET_VALUE(params));
get_volumes(rc, vols, count, response);
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -808,17 +849,24 @@ static void get_disks(int rc, lsm_disk **disks, uint32_t count, Value &response)
static int handle_disks(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->disk_get ) {
lsm_disk **disks = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->san_ops->disk_get(p, &disks, &count,
- LSM_FLAG_GET_VALUE(params));
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->san_ops->disk_get(p, key, val, &disks, &count,
+ LSM_FLAG_GET_VALUE(params));
get_disks(rc, disks, count, response);
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -1120,14 +1168,17 @@ static int handle_volume_offline(lsm_plugin_ptr p, Value ¶ms, Value &respons
static int ag_list(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->ag_list ) {
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
lsm_access_group **groups = NULL;
uint32_t count;
- rc = p->san_ops->ag_list(p, &groups, &count,
+ rc = p->san_ops->ag_list(p, key, val, &groups, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
response = access_group_list_to_value(groups, count);
@@ -1135,8 +1186,12 @@ static int ag_list(lsm_plugin_ptr p, Value ¶ms, Value &response)
/* Free the memory */
lsm_access_group_record_array_free(groups, count);
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -1500,14 +1555,17 @@ static int volume_dependency_rm(lsm_plugin_ptr p, Value ¶ms, Value &response
static int fs(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->fs_ops->fs_list ) {
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
lsm_fs **fs = NULL;
uint32_t count = 0;
- rc = p->fs_ops->fs_list(p, &fs, &count,
+ rc = p->fs_ops->fs_list(p, key, val, &fs, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
@@ -1521,8 +1579,12 @@ static int fs(lsm_plugin_ptr p, Value ¶ms, Value &response)
lsm_fs_record_array_free(fs, count);
fs = NULL;
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -2051,13 +2113,16 @@ static int export_auth(lsm_plugin_ptr p, Value ¶ms, Value &response)
static int exports(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->nas_ops && p->nas_ops->nfs_list ) {
lsm_nfs_export **exports = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->nas_ops->nfs_list(p, &exports, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->nas_ops->nfs_list(p, key, val, &exports, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
@@ -2072,8 +2137,12 @@ static int exports(lsm_plugin_ptr p, Value ¶ms, Value &response)
exports = NULL;
count = 0;
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
@@ -2610,4 +2679,195 @@ int LSM_DLL_EXPORT lsm_uri_parse(const char *uri, char **scheme, char **user,
}
}
return rc;
+}
+
+
+typedef int (*array_cmp)(void *item, void *cmp_data);
+typedef void (*free_item)(void *item);
+
+#define CMP_FUNCTION(name, method, method_type) \
+static int name(void *i, void *d) \
+{ \
+ method_type *v = (method_type *)i; \
+ char *val = (char *)d; \
+ \
+ if( strcmp(method(v), val) == 0 ) { \
+ return 1; \
+ } \
+ return 0; \
+} \
+
+
+#define CMP_FREE_FUNCTION(name, method, method_type) \
+static void name(void *i) \
+{ \
+ method((method_type *)i); \
+} \
+
+int filter(void *a[], size_t size, array_cmp cmp, void *cmp_data, free_item fo)
+{
+ int remaining = 0;
+ size_t i = 0;
+
+ for( i = 0; i < size; ++i ) {
+ if( cmp(a[i], cmp_data) ) {
+ memmove(&a[remaining], &a[i], sizeof(void *));
+ remaining += 1;
+ } else {
+ fo(a[i]);
+ a[i] = NULL;
+ }
+ }
+ return remaining;
+}
+
+CMP_FUNCTION(volume_compare_id, lsm_volume_id_get, lsm_volume)
+CMP_FUNCTION(volume_compare_system, lsm_volume_system_id_get, lsm_volume)
+CMP_FUNCTION(volume_compare_pool, lsm_volume_pool_id_get, lsm_volume)
+CMP_FREE_FUNCTION(volume_free, lsm_volume_record_free, lsm_volume)
+
+void lsm_plug_volume_search_filter(const char *search_key, const char *search_value,
+ lsm_volume *vols[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = volume_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = volume_compare_system;
+ } else if ( 0 == strcmp("pool_id", search_key) ) {
+ cmp = volume_compare_pool;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)vols, *count, cmp, (void*)search_value,
+ volume_free);
+ }
+ }
+}
+
+CMP_FUNCTION(pool_compare_id, lsm_pool_id_get, lsm_pool)
+CMP_FUNCTION(pool_compare_system, lsm_pool_system_id_get, lsm_pool)
+CMP_FREE_FUNCTION(pool_free, lsm_pool_record_free, lsm_pool);
+
+void lsm_plug_pool_search_filter(const char *search_key, const char *search_value,
+ lsm_pool *pools[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = pool_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = pool_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)pools, *count, cmp, (void*)search_value,
+ pool_free);
+ }
+ }
+}
+
+CMP_FUNCTION(disk_compare_id, lsm_disk_id_get, lsm_disk)
+CMP_FUNCTION(disk_compare_system, lsm_disk_system_id_get, lsm_disk)
+CMP_FREE_FUNCTION(disk_free, lsm_disk_record_free, lsm_disk)
+
+void lsm_plug_disk_search_filter(const char *search_key, const char *search_value,
+ lsm_disk *disks[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = disk_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = disk_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)disks, *count, cmp, (void*)search_value,
+ disk_free);
+ }
+ }
+}
+
+CMP_FUNCTION(access_group_compare_id, lsm_access_group_id_get, lsm_access_group)
+CMP_FUNCTION(access_group_compare_system, lsm_access_group_system_id_get, lsm_access_group)
+CMP_FREE_FUNCTION(access_group_free, lsm_access_group_record_free,
+ lsm_access_group);
+
+void lsm_plug_access_group_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_access_group *ag[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = access_group_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = access_group_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)ag, *count, cmp, (void*)search_value,
+ access_group_free);
+ }
+ }
+}
+
+CMP_FUNCTION(fs_compare_id, lsm_fs_id_get, lsm_fs)
+CMP_FUNCTION(fs_compare_system, lsm_fs_system_id_get, lsm_fs)
+CMP_FREE_FUNCTION(fs_free, lsm_fs_record_free, lsm_fs);
+
+void lsm_plug_fs_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_fs *fs[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = fs_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = fs_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)fs, *count, cmp, (void*)search_value,
+ fs_free);
+ }
+ }
+}
+
+CMP_FUNCTION(nfs_compare_id, lsm_nfs_export_id_get, lsm_nfs_export)
+CMP_FUNCTION(nfs_compare_fs_id, lsm_nfs_export_fs_id_get, lsm_nfs_export)
+CMP_FREE_FUNCTION(nfs_free, lsm_nfs_export_record_free, lsm_nfs_export)
+
+void lsm_plug_nfs_export_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_nfs_export *exports[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = nfs_compare_id;
+ } else if( 0 == strcmp("fs_id", search_key) ) {
+ cmp = nfs_compare_fs_id;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)exports, *count, cmp, (void*)search_value,
+ nfs_free);
+ }
+ }
}
\ No newline at end of file
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 3749ede..2b1d0ab 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -429,7 +429,8 @@ static int job_status(lsm_plugin_ptr c, const char *job_id,
return rc;
}
-static int list_pools(lsm_plugin_ptr c, lsm_pool **pool_array[],
+static int list_pools(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
@@ -459,6 +460,11 @@ static int list_pools(lsm_plugin_ptr c, lsm_pool **pool_array[],
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_pool_search_filter(search_key, search_value, *pool_array, count);
+ }
+
return rc;
}
@@ -628,14 +634,14 @@ static int list_initiators(lsm_plugin_ptr c, lsm_initiator **init_array[],
return _list_initiators(c, init_array, count, flags, NULL);
}
-static int list_volumes(lsm_plugin_ptr c, lsm_volume **vols[],
- uint32_t *count, lsm_flag flags)
+static int list_volumes(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_volume **vols[], uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
*count = g_hash_table_size(pd->volumes);
-
if( *count ) {
*vols = lsm_volume_record_array_alloc( *count );
if( *vols ) {
@@ -659,11 +665,17 @@ static int list_volumes(lsm_plugin_ptr c, lsm_volume **vols[],
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_volume_search_filter(search_key, search_value, *vols, count);
+ }
+
return rc;
}
-static int list_disks(lsm_plugin_ptr c, lsm_disk **disks[], uint32_t *count,
- lsm_flag flags)
+static int list_disks(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_disk **disks[],
+ uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
@@ -693,6 +705,11 @@ static int list_disks(lsm_plugin_ptr c, lsm_disk **disks[], uint32_t *count,
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_disk_search_filter(search_key, search_value, *disks, count);
+ }
+
return rc;
}
@@ -1171,6 +1188,8 @@ static int volume_online_offline(lsm_plugin_ptr c, lsm_volume *v,
}
static int access_group_list(lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count, lsm_flag flags)
{
@@ -1205,6 +1224,12 @@ static int access_group_list(lsm_plugin_ptr c,
rc = LSM_ERR_NO_MEMORY;
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_access_group_search_filter(search_key, search_value, *groups,
+ group_count);
+ }
+
return rc;
}
@@ -1653,7 +1678,7 @@ static lsm_access_group *get_access_group( lsm_plugin_ptr c, char *group_name,
lsm_access_group **groups = NULL;
uint32_t count = 0;
- int rc = access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ int rc = access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
uint32_t i;
@@ -1862,7 +1887,8 @@ static struct lsm_san_ops_v1 san_ops = {
};
-static int fs_list(lsm_plugin_ptr c, lsm_fs **fs[], uint32_t *count,
+static int fs_list(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_fs **fs[], uint32_t *count,
lsm_flag flags)
{
int rc = LSM_ERR_OK;
@@ -1892,6 +1918,11 @@ static int fs_list(lsm_plugin_ptr c, lsm_fs **fs[], uint32_t *count,
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_fs_search_filter(search_key, search_value, *fs, count);
+ }
+
return rc;
}
@@ -2248,8 +2279,10 @@ static int nfs_auth_types(lsm_plugin_ptr c, lsm_string_list **types,
return rc;
}
-static int nfs_export_list( lsm_plugin_ptr c, lsm_nfs_export **exports[],
- uint32_t *count, lsm_flag flags)
+static int nfs_export_list( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_nfs_export **exports[], uint32_t *count,
+ lsm_flag flags)
{
int rc = LSM_ERR_OK;
GHashTableIter fs_iter;
@@ -2303,6 +2336,10 @@ static int nfs_export_list( lsm_plugin_ptr c, lsm_nfs_export **exports[],
result = NULL;
}
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_nfs_export_search_filter(search_key, search_value, *exports, count);
+ }
+
return rc;
}
diff --git a/test/tester.c b/test/tester.c
index aa67460..6918e97 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -25,7 +25,7 @@
#include <libstoragemgmt/libstoragemgmt.h>
#include <libstoragemgmt/libstoragemgmt_plug_interface.h>
-const char uri[] = "sim://localhost/?statefile=/tmp/%d/lsm_sim_%s";
+const char URI[] = "sim://localhost/?statefile=/tmp/%d/lsm_sim_%s";
const char SYSTEM_NAME[] = "LSM simulated storage plug-in";
const char SYSTEM_ID[] = "sim-01";
const char *ISCSI_HOST[2] = { "iqn.1994-05.com.domain:01.89bd01",
@@ -68,8 +68,10 @@ void generate_random(char *buff, uint32_t len)
char *plugin_to_use()
{
- if( which_plugin == 1) {
- return "simc://";
+ char *uri_to_use = "sim://";
+
+ if( which_plugin == 1 ) {
+ uri_to_use = "simc://";
} else {
char *rundir = getenv("LSM_TEST_RUNDIR");
@@ -82,14 +84,14 @@ char *plugin_to_use()
static char fn[128];
static char name[32];
generate_random(name, sizeof(name));
- snprintf(fn, sizeof(fn), uri, rdir, name);
- printf("URI = %s\n", fn);
- return fn;
+ snprintf(fn, sizeof(fn), URI, rdir, name);
+ uri_to_use = fn;
} else {
printf("Missing LSM_TEST_RUNDIR, expect test failures!\n");
- return "sim://";
}
}
+ printf("URI = %s\n", uri_to_use);
+ return uri_to_use;
}
lsm_pool *get_test_pool(lsm_connect *c)
@@ -98,7 +100,7 @@ lsm_pool *get_test_pool(lsm_connect *c)
uint32_t count = 0;
lsm_pool *test_pool = NULL;
- int rc = lsm_pool_list(c, &pools, &count, LSM_FLAG_RSVD);
+ int rc = lsm_pool_list(c, NULL, NULL, &pools, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
uint32_t i = 0;
for(i = 0; i < count; ++i ) {
@@ -388,7 +390,7 @@ START_TEST(test_smoke_test)
int poolToUse = -1;
//Get pool list
- rc = lsm_pool_list(c, &pools, &poolCount, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &poolCount, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
error(lsm_error_last_get(c)));
@@ -537,7 +539,7 @@ START_TEST(test_smoke_test)
lsm_volume **volumes = NULL;
count = 0;
/* Get a list of volumes */
- rc = lsm_volume_list(c, &volumes, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc , "lsmVolumeList %d (%s)",rc,
@@ -609,10 +611,11 @@ START_TEST(test_access_groups)
lsm_access_group *group = NULL;
uint32_t count = 0;
uint32_t i = 0;
+ lsm_string_list *init_list = NULL;
fail_unless(c!=NULL);
- int rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ int rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "Expected success on listing access groups %d", rc);
fail_unless(count == 0, "Expect 0 access groups, got %"PRIu32, count);
@@ -654,7 +657,7 @@ START_TEST(test_access_groups)
init_copy = NULL;
}
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
lsm_access_group_record_array_free(groups, count);
@@ -671,17 +674,19 @@ START_TEST(test_access_groups)
fail_unless(LSM_ERR_OK == rc, "Expected success on lsmAccessGroupInitiatorAdd %d", rc);
}
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
- lsm_string_list *init_list = lsm_access_group_initiator_id_get(groups[0]);
- fail_unless( lsm_string_list_size(init_list) == 2, "Expecting 2 initiators, current num = %d\n", lsm_string_list_size(init_list) );
- for( i = 0; i < lsm_string_list_size(init_list); ++i) {
- printf("%d = %s\n", i, lsm_string_list_elem_get(init_list, i));
+ if( count ) {
+ init_list = lsm_access_group_initiator_id_get(groups[0]);
+ fail_unless( lsm_string_list_size(init_list) == 2, "Expecting 2 initiators, current num = %d\n", lsm_string_list_size(init_list) );
+ for( i = 0; i < lsm_string_list_size(init_list); ++i) {
+ printf("%d = %s\n", i, lsm_string_list_elem_get(init_list, i));
+ }
+ lsm_string_list_free(init_list);
+ init_list = NULL;
}
- lsm_string_list_free(init_list);
-
uint32_t init_list_count = 0;
lsm_initiator **inits = NULL;
@@ -708,20 +713,21 @@ START_TEST(test_access_groups)
groups = NULL;
count = 0;
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
- init_list = lsm_access_group_initiator_id_get(groups[0]);
- fail_unless( init_list != NULL);
- fail_unless( lsm_string_list_size(init_list) == 0);
-
- lsm_access_group_record_array_free(groups, count);
- groups = NULL;
- count = 0;
-
+ if( count ) {
+ init_list = lsm_access_group_initiator_id_get(groups[0]);
+ fail_unless( init_list != NULL);
+ fail_unless( lsm_string_list_size(init_list) == 0);
+ lsm_string_list_free(init_list);
+ init_list = NULL;
+ lsm_access_group_record_array_free(groups, count);
+ groups = NULL;
+ count = 0;
+ }
}
-
END_TEST
START_TEST(test_access_groups_grant_revoke)
@@ -813,7 +819,7 @@ START_TEST(test_fs)
lsm_pool *test_pool = get_test_pool(c);
- rc = lsm_fs_list(c, &fs_list, &fs_count, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fs_list, &fs_count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc);
fail_unless(0 == fs_count);
@@ -850,7 +856,7 @@ START_TEST(test_fs)
}
- rc = lsm_fs_list(c, &fs_list, &fs_count, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fs_list, &fs_count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc);
fail_unless(2 == fs_count, "fs_count = %d", fs_count);
@@ -1040,7 +1046,7 @@ START_TEST(test_disks)
fail_unless(c!=NULL);
- int rc = lsm_disk_list(c, &d, &count, 0);
+ int rc = lsm_disk_list(c, NULL, NULL, &d, &count, 0);
if( LSM_ERR_OK == rc ) {
fail_unless(LSM_ERR_OK == rc, "%d", rc);
@@ -1125,7 +1131,7 @@ START_TEST(test_nfs_exports)
uint32_t count = 0;
if( nfs ) {
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmNfsList rc= %d\n", rc);
fail_unless(count == 0);
@@ -1148,7 +1154,7 @@ START_TEST(test_nfs_exports)
lsm_nfs_export_record_free(e);
e=NULL;
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( exports != NULL);
fail_unless( count == 1 );
@@ -1160,7 +1166,7 @@ START_TEST(test_nfs_exports)
exports = NULL;
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmNfsList rc= %d\n", rc);
fail_unless(count == 0);
@@ -1334,20 +1340,39 @@ START_TEST(test_invalid_input)
free(bogus_job);
+ /* lsm_disk_list */
+ uint32_t count = 0;
+ lsm_disk **disks = NULL;
+
+ rc = lsm_disk_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d, rc");
+
+ rc = lsm_disk_list(c, "bogus_key", NULL, &disks, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d, rc");
+
+ rc = lsm_disk_list(c, "bogus_key", "nope", &disks, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d, rc");
+
/* lsmPoolList */
- rc = lsm_pool_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
lsm_pool **pools = NULL;
- rc = lsm_pool_list(c, &pools, NULL, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
- uint32_t count = 0;
- rc = lsm_pool_list(c, NULL, &count, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, NULL, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
pools = (lsm_pool **)&bad;
- rc = lsm_pool_list(c, &pools, &count, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
+
+ pools = NULL;
+ rc = lsm_pool_list(c, "bogus_key", "nope", &pools, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d", rc);
+
+ rc = lsm_pool_list(c, "bogus_key", NULL, &pools, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmInitiatorList */
@@ -1366,18 +1391,25 @@ START_TEST(test_invalid_input)
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmVolumeList */
- rc = lsm_volume_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
lsm_volume **vols = NULL;
- rc = lsm_volume_list(c, &vols, NULL, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &vols, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
- rc = lsm_volume_list(c, NULL, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, NULL, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
vols = (lsm_volume **)&bad;
- rc = lsm_volume_list(c, &vols, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &vols, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
+
+ vols = NULL;
+ rc = lsm_volume_list(c, "bogus_key", "nope", &vols, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d", rc);
+
+ rc = lsm_volume_list(c, "bogus_key", NULL, &vols, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmVolumeCreate */
@@ -1471,8 +1503,10 @@ START_TEST(test_invalid_input)
rc = lsm_capabilities(c, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_SYSTEM, "rc %d", rc);
- rc = lsm_capabilities(c, sys[0], NULL, LSM_FLAG_RSVD);
- fail_unless(LSM_ERR_INVALID_ARGUMENT, "rc %d", rc);
+ if( num_systems ) {
+ rc = lsm_capabilities(c, sys[0], NULL, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT, "rc %d", rc);
+ }
/* lsmVolumeReplicate */
lsm_volume *cloned = NULL;
@@ -1605,13 +1639,15 @@ START_TEST(test_invalid_input)
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
/* lsmFsList */
- rc = lsm_fs_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
lsm_fs **fsl = NULL;
- rc = lsm_fs_list(c, &fsl, NULL, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fsl, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
+ rc = lsm_fs_list(c, "bogus_key", "nope", &fsl, &count, LSM_FLAG_RSVD);
+ fail_unless(rc == LSM_ERR_UNSUPPORTED_SEARCH_KEY, "rc = %d", rc);
/*lsmFsCreate*/
rc = lsm_fs_create(c, NULL, NULL, 0, NULL, NULL, LSM_FLAG_RSVD);
@@ -1736,7 +1772,7 @@ START_TEST(test_invalid_input)
rc = lsm_fs_ss_restore(c, arg_fs, arg_ss, f, f, 0, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
- rc = lsm_nfs_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
@@ -1833,58 +1869,60 @@ START_TEST(test_capabilities)
fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
fail_unless( sys_count >= 1, "count = %d", sys_count);
- printf("lsmCapabilities\n");
- rc = lsm_capabilities(c, sys[0], &cap, LSM_FLAG_RSVD);
- fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
+ if( sys_count > 0 ) {
+ printf("lsmCapabilities %d\n", sys_count);
+ rc = lsm_capabilities(c, sys[0], &cap, LSM_FLAG_RSVD);
+ fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
- if( LSM_ERR_OK == rc ) {
- cap_test(cap, LSM_CAP_BLOCK_SUPPORT);
- cap_test(cap, LSM_CAP_FS_SUPPORT);
- cap_test(cap, LSM_CAP_VOLUMES);
- cap_test(cap, LSM_CAP_VOLUME_CREATE);
- cap_test(cap, LSM_CAP_VOLUME_RESIZE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_CLONE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_COPY);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_ASYNC);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_SYNC);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_BLOCK_SIZE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_CLONE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_COPY);
- cap_test(cap, LSM_CAP_VOLUME_DELETE);
- cap_test(cap, LSM_CAP_VOLUME_ONLINE);
- cap_test(cap, LSM_CAP_VOLUME_OFFLINE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_GRANT);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_REVOKE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_LIST);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_CREATE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_DELETE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_ADD_INITIATOR);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_DEL_INITIATOR);
- cap_test(cap, LSM_CAP_VOLUMES_ACCESSIBLE_BY_ACCESS_GROUP);
- cap_test(cap, LSM_CAP_ACCESS_GROUPS_GRANTED_TO_VOLUME);
- cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY);
- cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY_RM);
- cap_test(cap, LSM_CAP_FS);
- cap_test(cap, LSM_CAP_FS_DELETE);
- cap_test(cap, LSM_CAP_FS_RESIZE);
- cap_test(cap, LSM_CAP_FS_CREATE);
- cap_test(cap, LSM_CAP_FS_CLONE);
- cap_test(cap, LSM_CAP_FILE_CLONE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOTS);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE_SPECIFIC_FILES);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_DELETE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT_SPECIFIC_FILES);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM_SPECIFIC_FILES );
- cap_test(cap, LSM_CAP_EXPORT_AUTH);
- cap_test(cap, LSM_CAP_EXPORTS);
- cap_test(cap, LSM_CAP_EXPORT_FS);
- cap_test(cap, LSM_CAP_EXPORT_REMOVE);
+ if( LSM_ERR_OK == rc ) {
+ cap_test(cap, LSM_CAP_BLOCK_SUPPORT);
+ cap_test(cap, LSM_CAP_FS_SUPPORT);
+ cap_test(cap, LSM_CAP_VOLUMES);
+ cap_test(cap, LSM_CAP_VOLUME_CREATE);
+ cap_test(cap, LSM_CAP_VOLUME_RESIZE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_CLONE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_COPY);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_ASYNC);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_SYNC);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_BLOCK_SIZE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_CLONE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_COPY);
+ cap_test(cap, LSM_CAP_VOLUME_DELETE);
+ cap_test(cap, LSM_CAP_VOLUME_ONLINE);
+ cap_test(cap, LSM_CAP_VOLUME_OFFLINE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_GRANT);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_REVOKE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_LIST);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_CREATE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_DELETE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_ADD_INITIATOR);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_DEL_INITIATOR);
+ cap_test(cap, LSM_CAP_VOLUMES_ACCESSIBLE_BY_ACCESS_GROUP);
+ cap_test(cap, LSM_CAP_ACCESS_GROUPS_GRANTED_TO_VOLUME);
+ cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY);
+ cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY_RM);
+ cap_test(cap, LSM_CAP_FS);
+ cap_test(cap, LSM_CAP_FS_DELETE);
+ cap_test(cap, LSM_CAP_FS_RESIZE);
+ cap_test(cap, LSM_CAP_FS_CREATE);
+ cap_test(cap, LSM_CAP_FS_CLONE);
+ cap_test(cap, LSM_CAP_FILE_CLONE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOTS);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE_SPECIFIC_FILES);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_DELETE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT_SPECIFIC_FILES);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM_SPECIFIC_FILES );
+ cap_test(cap, LSM_CAP_EXPORT_AUTH);
+ cap_test(cap, LSM_CAP_EXPORTS);
+ cap_test(cap, LSM_CAP_EXPORT_FS);
+ cap_test(cap, LSM_CAP_EXPORT_REMOVE);
+ }
}
}
END_TEST
@@ -2484,7 +2522,7 @@ START_TEST(test_pool_create)
/*
* Test pool creations from disks
*/
- rc = lsm_disk_list(c, &disks, &num_disks, LSM_FLAG_RSVD);
+ rc = lsm_disk_list(c, NULL, NULL, &disks, &num_disks, LSM_FLAG_RSVD);
lsm_disk *disks_to_use[128];
uint32_t num_disks_to_use = 0;
@@ -2543,11 +2581,12 @@ START_TEST(test_pool_create)
memset(volumes_to_use, 0, sizeof(volumes_to_use));
/* Create some volumes */
- rc = lsm_pool_list(c, &pools, &num_pools, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &num_pools, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "rc %d", rc);
+ fail_unless(num_pools > 0, "num pools = %d", num_pools);
- if( LSM_ERR_OK == rc ) {
+ if( LSM_ERR_OK == rc && num_pools > 0) {
pool_one = lsm_pool_record_copy(pools[0]);
@@ -2571,7 +2610,7 @@ START_TEST(test_pool_create)
}
}
- rc = lsm_volume_list(c, &volumes, &num_volumes, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &num_volumes, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc );
if( num_volumes ) {
@@ -2685,6 +2724,376 @@ START_TEST(test_uri_parse)
}
END_TEST
+START_TEST(test_search_pools)
+{
+ int rc;
+ lsm_pool **pools = NULL;
+ uint32_t poolCount = 0;
+
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &poolCount, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ if( LSM_ERR_OK == rc && poolCount ) {
+ lsm_pool **search_pools = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_pool_list(c, "id", lsm_pool_id_get(pools[0]), &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 pool, got %d", search_count);
+
+ rc = lsm_pool_record_array_free(search_pools, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+
+ /* Search for non-existent pool*/
+ search_pools = NULL;
+ search_count = 0;
+
+ rc = lsm_pool_list(c, "id", "non-existent-id", &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no pools! %d", search_count);
+
+ /* Search which results in all pools */
+ rc = lsm_pool_list(c, "system_id", lsm_pool_system_id_get(pools[0]),
+ &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == poolCount, "Expecting %d pools, got %d",
+ poolCount, search_count);
+
+ rc = lsm_pool_record_array_free(search_pools, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+
+
+ rc = lsm_pool_record_array_free(pools, poolCount);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+ }
+
+}
+END_TEST
+
+START_TEST(test_search_volumes)
+{
+ int rc;
+ lsm_volume **volumes = NULL;
+ uint32_t volume_count = 0;
+
+ lsm_pool *pool = get_test_pool(c);
+
+ // Make some volumes to we can actually filter
+ create_volumes(c, pool, 10);
+
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &volume_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(volume_count > 0, "We are expecting some volumes!");
+
+ if( LSM_ERR_OK == rc && volume_count ) {
+ lsm_volume **search_volume = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_volume_list(c, "id", lsm_volume_id_get(volumes[0]),
+ &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 pool, got %d", search_count);
+
+ rc = lsm_volume_record_array_free(search_volume, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_volume = NULL;
+ search_count = 0;
+
+ rc = lsm_volume_list(c, "id", "non-existent-id", &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no volumes! %d", search_count);
+
+ /* Search which results in all volumes */
+ rc = lsm_volume_list(c, "system_id", lsm_volume_system_id_get(volumes[0]),
+ &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == volume_count, "Expecting %d volumes, got %d",
+ volume_count, search_count);
+
+ rc = lsm_volume_record_array_free(search_volume, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+
+
+ rc = lsm_volume_record_array_free(volumes, volume_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_disks)
+{
+ int rc;
+ lsm_disk **disks = NULL;
+ uint32_t disk_count = 0;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ rc = lsm_disk_list(c, NULL, NULL, &disks, &disk_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(disk_count > 0, "We are expecting some disks!");
+
+ if( LSM_ERR_OK == rc && disk_count ) {
+
+ lsm_disk **search_disks = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_disk_list(c, "id", lsm_disk_id_get(disks[0]),
+ &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 disk, got %d", search_count);
+
+ rc = lsm_disk_record_array_free(search_disks, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_disks = NULL;
+ search_count = 0;
+
+ rc = lsm_disk_list(c, "id", "non-existent-id", &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no disks! %d", search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_disk_list(c, "system_id", lsm_disk_system_id_get(disks[0]),
+ &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == disk_count, "Expecting %d disks, got %d",
+ disk_count, search_count);
+
+ rc = lsm_disk_record_array_free(search_disks, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+
+
+ rc = lsm_disk_record_array_free(disks, disk_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_access_groups)
+{
+ int rc;
+ lsm_access_group **ag = NULL;
+ uint32_t count = 0;
+ int i = 0;
+ lsm_access_group *group = NULL;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ for( i = 0; i < 2; ++i ) {
+ char ag_name[64];
+
+ snprintf(ag_name, sizeof(ag_name), "test_access_group_%d", i);
+
+ rc = lsm_access_group_create(c, ag_name, ISCSI_HOST[i],
+ LSM_INITIATOR_ISCSI, SYSTEM_ID, &group, LSM_FLAG_RSVD);
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_access_group_record_free(group);
+ group = NULL;
+ }
+ }
+
+ rc = lsm_access_group_list(c, NULL, NULL, &ag, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(count > 0, "We are expecting some access_groups!");
+
+ if( LSM_ERR_OK == rc && count ) {
+
+ lsm_access_group **search_ag = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_access_group_list(c, "id", lsm_access_group_id_get(ag[0]),
+ &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 access group, got %d",
+ search_count);
+
+ rc = lsm_access_group_record_array_free(search_ag, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+
+ /* Search for non-existent */
+ search_ag = NULL;
+ search_count = 0;
+
+ rc = lsm_access_group_list(c, "id", "non-existent-id", &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no access groups! %d",
+ search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_access_group_list(c, "system_id",
+ lsm_access_group_system_id_get(ag[0]),
+ &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == count, "Expecting %d access groups, got %d",
+ count, search_count);
+
+ rc = lsm_access_group_record_array_free(search_ag, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+
+
+ rc = lsm_access_group_record_array_free(ag, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_fs)
+{
+ int rc;
+ lsm_fs **fsl = NULL;
+ lsm_fs *fs = NULL;
+ uint32_t count = 0;
+ int i = 0;
+ char *job = NULL;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ for( i = 0; i < 2; ++i ) {
+ char fs_name[64];
+
+ snprintf(fs_name, sizeof(fs_name), "test_fs_%d", i);
+
+ rc = lsm_fs_create(c, pool, fs_name, 50000000, &fs, &job, LSM_FLAG_RSVD);
+
+ if( LSM_ERR_JOB_STARTED == rc ) {
+ fail_unless(NULL == fs);
+ fs = wait_for_job_fs(c, &job);
+ } else {
+ fail_unless(LSM_ERR_OK == rc);
+ }
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_fs_record_free(fs);
+ }
+ fs = NULL;
+ }
+
+ rc = lsm_fs_list(c, NULL, NULL, &fsl, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(count > 0, "We are expecting some file systems!");
+
+ if( LSM_ERR_OK == rc && count ) {
+
+ lsm_fs **search_fs = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_fs_list(c, "id", lsm_fs_id_get(fsl[0]),
+ &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 fs, got %d",
+ search_count);
+
+ rc = lsm_fs_record_array_free(search_fs, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_fs = NULL;
+ search_count = 0;
+
+ rc = lsm_fs_list(c, "id", "non-existent-id", &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no fs! %d", search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_fs_list(c, "system_id",
+ lsm_fs_system_id_get(fsl[0]),
+ &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == count, "Expecting %d fs, got %d",
+ count, search_count);
+
+ rc = lsm_fs_record_array_free(search_fs, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+
+
+ rc = lsm_fs_record_array_free(fsl, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
Suite * lsm_suite(void)
{
Suite *s = suite_create("libStorageMgmt");
@@ -2692,6 +3101,11 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
+ tcase_add_test(basic, test_search_fs);
+ tcase_add_test(basic, test_search_access_groups);
+ tcase_add_test(basic, test_search_disks);
+ tcase_add_test(basic, test_search_volumes);
+ tcase_add_test(basic, test_search_pools);
tcase_add_test(basic, test_pool_delete);
tcase_add_test(basic, test_pool_create);
I tried a few different approaches, but ended up going with this.
V2: Code change reductions, memory leak fixes, added capability
constants and error code for invalid key.
V3: Re-name filtering functions to be closer to python name
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 52 +-
.../libstoragemgmt/libstoragemgmt_capabilities.h | 10 +-
.../include/libstoragemgmt/libstoragemgmt_error.h | 5 +-
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 110 +++-
c_binding/lsm_mgmt.cpp | 129 ++++-
c_binding/lsm_plugin_ipc.cpp | 298 +++++++++-
plugin/simc/simc_lsmplugin.c | 57 +-
test/tester.c | 622 +++++++++++++++++----
8 files changed, 1112 insertions(+), 171 deletions(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index 96be652..cca683a 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -226,12 +226,15 @@ extern "C" {
/**
* Query the list of storage pools on the array.
* @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] pool_array Array of storage pools
* @param[out] count Number of storage pools
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_pool_list(lsm_connect *conn, lsm_pool **pool_array[],
+ int LSM_DLL_EXPORT lsm_pool_list(lsm_connect *conn, char *search_key,
+ char *search_value, lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -363,25 +366,36 @@ extern "C" {
/**
* Gets a list of logical units for this array.
- * @param[in] conn Valid connection @see lsm_connect_password
- * @param[out] volumes An array of lsm_volume
- * @param[out] count Number of elements in the lsm_volume array
- * @param[in] flags Reserved for future use, must be zero.
+ * @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param[out] volumes An array of lsm_volume
+ * @param[out] count Number of elements in the lsm_volume array
+ * @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_volume_list(lsm_connect *conn, lsm_volume **volumes[],
+ int LSM_DLL_EXPORT lsm_volume_list(lsm_connect *conn,
+ const char *search_key,
+ const char *search_value,
+ lsm_volume **volumes[],
uint32_t *count, lsm_flag flags);
/**
* Get a list of disk for this array.
- * @param [in] conn Valid connection @see lsm_connect_password
- * @param [out] disks An array of lsm_disk types
- * @param [out] count Number of disks
- * @param [in] flags Use LSM_DISK_RETRIEVE_FULL_INFO for all data, else 0
+ * @param [in] conn Valid connection @see
+ * lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
+ * @param [out] disks An array of lsm_disk types
+ * @param [out] count Number of disks
+ * @param [in] flags Use LSM_DISK_RETRIEVE_FULL_INFO for all
+ * data, else 0
* @return LSM_ERR_OK on success else error reason
*/
- int LSM_DLL_EXPORT lsm_disk_list(lsm_connect *conn, lsm_disk **disks[],
- uint32_t *count, lsm_flag flags);
+ int LSM_DLL_EXPORT lsm_disk_list(lsm_connect *conn, const char * search_key,
+ const char *search_value,
+ lsm_disk **disks[], uint32_t *count,
+ lsm_flag flags);
/**
* Creates a new volume (aka. LUN).
@@ -550,12 +564,16 @@ extern "C" {
/**
* Retrieves a list of access groups.
* @param[in] conn Valid connection @see lsm_connect_password
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] groups Array of access groups
* @param[out] group_count Size of array
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success, else error reason.
*/
int LSM_DLL_EXPORT lsm_access_group_list(lsm_connect *conn,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count,
lsm_flag flags);
@@ -745,12 +763,15 @@ extern "C" {
/**
* Retrieves information about the available file systems.
* @param[in] conn Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] fs Array of lsm_fs
* @param[out] fs_count Number of file systems
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success, else error reason
*/
- int LSM_DLL_EXPORT lsm_fs_list(lsm_connect *conn, lsm_fs **fs[],
+ int LSM_DLL_EXPORT lsm_fs_list(lsm_connect *conn, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
uint32_t *fs_count, lsm_flag flags);
/**
@@ -935,12 +956,15 @@ extern "C" {
/**
* Lists the nfs exports on the specified array.
* @param[in] c Valid connection
+ * @param[in] search_key Search key (NULL for all)
+ * @param[in] search_value Search value
* @param[out] exports An array of lsm_nfs_export
* @param[out] count Number of items in array
* @param[in] flags Reserved for future use, must be zero.
* @return LSM_ERR_OK on success else error code.
*/
- int LSM_DLL_EXPORT lsm_nfs_list( lsm_connect *c,
+ int LSM_DLL_EXPORT lsm_nfs_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
lsm_nfs_export **exports[],
uint32_t *count, lsm_flag flags);
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
index 5a3bc86..6f0e57c 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
@@ -142,7 +142,15 @@ typedef enum {
LSM_CAP_POOL_CREATE_VOLUME_RAID_16 = 173,
LSM_CAP_POOL_CREATE_VOLUME_RAID_NOT_APPLICABLE = 174,
- LSM_CAP_POOL_DELETE = 200 /**< Pool delete support */
+ LSM_CAP_POOL_DELETE = 200, /**< Pool delete support */
+
+ LSM_CAP_POOLS_QUICK_SEARCH = 210, /**< Seach occurs on array */
+ LSM_CAP_VOLUMES_QUICK_SEARCH = 211, /**< Seach occurs on array */
+ LSM_CAP_DISKS_QUICK_SEARCH = 212, /**< Seach occurs on array */
+ LSM_CAP_ACCESS_GROUPS_QUICK_SEARCH = 213, /**< Seach occurs on array */
+ LSM_CAP_FS_QUICK_SEARCH = 214, /**< Seach occurs on array */
+ LSM_CAP_NFS_EXPORTS_QUICK_SEARCH = 215 /**< Seach occurs on array */
+
} lsm_capability_type;
/**
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_error.h b/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
index 03fb079..68954c8 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_error.h
@@ -134,7 +134,10 @@ typedef enum {
LSM_ERR_UNSUPPORTED_REPLICATION_TYPE = 452, /**< Unsupported replication type */
LSM_ERR_DISK_BUSY = 500, /* Disk already in use */
- LSM_ERR_VOLUME_BUSY = 501 /* Volume already in use */
+ LSM_ERR_VOLUME_BUSY = 501, /* Volume already in use */
+
+
+ LSM_ERR_UNSUPPORTED_SEARCH_KEY = 510 /**< Unsupport search key */
} lsm_error_number;
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index dc18fa4..b76805c 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -151,12 +151,16 @@ typedef int (*lsm_plug_job_free)(lsm_plugin_ptr c, char *job_id, lsm_flag flags)
/**
* Retrieves a list of pools callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] pool_array List of pools
* @param[out] count Number of items in array
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_pool_list)( lsm_plugin_ptr c, lsm_pool **pool_array[],
+typedef int (*lsm_plug_pool_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -196,23 +200,31 @@ typedef int (*lsm_plug_init_list)( lsm_plugin_ptr c, lsm_initiator **init_array[
/**
* Retrieve a list of volumes.
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] vol_array Array of volumes
* @param[out] count Number of volumes
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_volume_list)( lsm_plugin_ptr c, lsm_volume **vol_array[],
+typedef int (*lsm_plug_volume_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_val,
+ lsm_volume **vol_array[],
uint32_t *count, lsm_flag flags);
/**
* Retrieve a list of volumes.
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] disk_array Array of disk pointers
* @param[out] count Number of disks
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, lsm_disk **disk_array[],
+typedef int (*lsm_plug_disk_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_disk **disk_array[],
uint32_t *count, lsm_flag flags);
/**
@@ -497,12 +509,16 @@ typedef int (*lsm_plug_iscsi_chap_auth)(lsm_plugin_ptr c,
/**
* Retrieve a list of access groups, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Field to search on
+ * @param[in] search_value Field value
* @param[out] groups Array of groups
* @param[out] group_count Number of groups
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
typedef int (*lsm_plug_access_group_list)(lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count, lsm_flag flags);
/**
@@ -657,12 +673,15 @@ typedef int (*lsm_plug_volume_child_dependency_delete)(lsm_plugin_ptr c,
/**
* File system list, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] fs An array of file systems
* @param[out] fs_count Number of file systems
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_fs_list)(lsm_plugin_ptr c, lsm_fs **fs[],
+typedef int (*lsm_plug_fs_list)(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
uint32_t *fs_count, lsm_flag flags);
/**
@@ -827,14 +846,17 @@ typedef int (*lsm_plug_nfs_auth_types)( lsm_plugin_ptr c,
/**
* Retrieve a list of NFS exports, callback function signature
* @param[in] c Valid lsm plug-in pointer
+ * @param[in] search_key Search key
+ * @param[in] search_value Search value
* @param[out] exports An array of exported file systems
* @param[out] count Number of exported file systems
* @param[in] flags Reserved
* @return LSM_ERR_OK, else error reason
*/
-typedef int (*lsm_plug_nfs_list)( lsm_plugin_ptr c,
- lsm_nfs_export **exports[],
- uint32_t *count, lsm_flag flags);
+typedef int (*lsm_plug_nfs_list)( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_nfs_export **exports[],
+ uint32_t *count, lsm_flag flags);
/**
* Exports a file system via NFS, callback function signature
* @param[in] c Valid lsm plug-in pointer
@@ -1278,6 +1300,80 @@ int LSM_DLL_EXPORT lsm_uri_parse(const char *uri, char **scheme, char **user,
char **server, int *port, char **path,
lsm_optional_data **query_params);
+/**
+ * Provides for volume filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] vols Array to filter
+ * @param[in,out] count Number of volumes to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_volume_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_volume *vols[],
+ uint32_t *count);
+
+/**
+ * Provides for pool filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] pools Array to filter
+ * @param[in,out] count Number of pools to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_pool_search_filter( const char *search_key,
+ const char *search_value,
+ lsm_pool *pools[], uint32_t *count);
+
+/**
+ * Provides for disk filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] disks Array to filter
+ * @param[in,out] count Number of disks to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_disk_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_disk *disks[], uint32_t *count);
+
+/**
+ * Provides for access group filtering when an array doesn't support this
+ * natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] disks Array to filter
+ * @param[in,out] count Number of access groups to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_access_group_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_access_group *ag[], uint32_t *count);
+
+/**
+ * Provides for fs filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] fs Array to filter
+ * @param[in,out] count Number of file systems to filter, number remain
+ */
+void LSM_DLL_EXPORT lsm_plug_fs_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_fs *fs[], uint32_t *count);
+
+/**
+ * Provides for nfs filtering when an array doesn't support this natively.
+ * Note: Filters in place removing and freeing those that don't match.
+ * @param search_key Search field
+ * @param search_value Search value
+ * @param[in,out] fs Array to filter
+ * @param[in,out] count Number of nfs exports to filter, number remain
+ */
+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);
#ifdef __cplusplus
}
#endif
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 61c3d0f..bbdad07 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -29,6 +29,26 @@
#include "lsm_datatypes.hpp"
#include "lsm_convert.hpp"
+#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+
+static const char * const POOL_SEARCH_KEYS[] = { "id", "system_id" };
+#define POOL_SEARCH_KEYS_COUNT COUNT_OF(POOL_SEARCH_KEYS)
+
+static const char * const VOLUME_SEARCH_KEYS[] = {"id", "system_id", "pool_id"};
+#define VOLUME_SEARCH_KEYS_COUNT COUNT_OF(VOLUME_SEARCH_KEYS)
+
+static const char * const DISK_SEARCH_KEYS[] = {"id", "system_id"};
+#define DISK_SEARCH_KEYS_COUNT COUNT_OF(DISK_SEARCH_KEYS)
+
+static const char * const FS_SEARCH_KEYS[] = {"id", "system_id", "pool_id"};
+#define FS_SEARCH_KEYS_COUNT COUNT_OF(FS_SEARCH_KEYS)
+
+static const char * const NFS_EXPORT_SEARCH_KEYS[] = {"id", "fs_id"};
+#define NFS_EXPORT_SEARCH_KEYS_COUNT COUNT_OF(NFS_EXPORT_SEARCH_KEYS)
+
+static const char * const ACCESS_GROUP_SEARCH_KEYS[] = {"id", "system_id"};
+#define ACCESS_GROUP_SEARCH_KEYS_COUNT COUNT_OF(ACCESS_GROUP_SEARCH_KEYS)
+
/**
* Common code to validate and initialize the connection.
*/
@@ -40,6 +60,19 @@
c->error = NULL; \
} while (0)
+static int check_search_key(const char *search_key,
+ const char * const supported_keys[],
+ size_t supported_keys_count)
+{
+ size_t i = 0;
+ for( i = 0; i < supported_keys_count; ++i ) {
+ if( 0 == strcmp(search_key, supported_keys[i])) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
/**
* Strings are non null with a len >= 1
*/
@@ -184,6 +217,24 @@ static int getAccessGroups( lsm_connect *c, int rc, Value &response,
return rc;
}
+static int add_search_params(std::map<std::string, Value> &p, const char *k,
+ const char *v, const char * const supported_keys[],
+ size_t supported_keys_count)
+{
+ if( k ) {
+ if( v ) {
+ if( !check_search_key(k, supported_keys, supported_keys_count) ) {
+ return LSM_ERR_UNSUPPORTED_SEARCH_KEY;
+ }
+ } else {
+ return LSM_ERR_INVALID_ARGUMENT;
+ }
+ }
+ p["search_key"] = Value(k);
+ p["search_value"] = Value(v);
+ return LSM_ERR_OK;
+}
+
int lsm_connect_close(lsm_connect *c, lsm_flag flags)
{
CONN_SETUP(c);
@@ -625,8 +676,8 @@ int lsm_capabilities(lsm_connect *c, lsm_system *system,
return rc;
}
-int lsm_pool_list(lsm_connect *c, lsm_pool **poolArray[],
- uint32_t *count, lsm_flag flags)
+int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,
+ lsm_pool **poolArray[], uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -637,6 +688,13 @@ int lsm_pool_list(lsm_connect *c, lsm_pool **poolArray[],
try {
std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value, POOL_SEARCH_KEYS,
+ POOL_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
@@ -737,8 +795,9 @@ static int get_volume_array(lsm_connect *c, int rc, Value &response,
}
-int lsm_volume_list(lsm_connect *c, lsm_volume **volumes[], uint32_t *count,
- lsm_flag flags)
+int lsm_volume_list(lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_volume **volumes[],
+ uint32_t *count, lsm_flag flags)
{
CONN_SETUP(c);
@@ -750,10 +809,16 @@ int lsm_volume_list(lsm_connect *c, lsm_volume **volumes[], uint32_t *count,
std::map<std::string, Value> p;
p["flags"] = Value(flags);
+ int rc = add_search_params(p, search_key, search_value, VOLUME_SEARCH_KEYS,
+ VOLUME_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
Value parameters(p);
Value response;
- int rc = rpc(c, "volumes", parameters, response);
+ rc = rpc(c, "volumes", parameters, response);
return get_volume_array(c, rc, response, volumes, count);
}
@@ -771,8 +836,9 @@ static int get_disk_array(lsm_connect *c, int rc, Value &response,
return rc;
}
-int lsm_disk_list(lsm_connect *c, lsm_disk **disks[],
- uint32_t *count, lsm_flag flags)
+int lsm_disk_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_disk **disks[], uint32_t *count, lsm_flag flags)
{
CONN_SETUP(c);
@@ -783,10 +849,16 @@ int lsm_disk_list(lsm_connect *c, lsm_disk **disks[],
std::map<std::string, Value> p;
p["flags"] = Value(flags);
+ int rc = add_search_params(p, search_key, search_value, DISK_SEARCH_KEYS,
+ DISK_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
Value parameters(p);
Value response;
- int rc = rpc(c, "disks", parameters, response);
+ rc = rpc(c, "disks", parameters, response);
return get_disk_array(c, rc, response, disks, count);
}
@@ -1468,8 +1540,10 @@ int lsm_volume_offline(lsm_connect *c, lsm_volume *volume, lsm_flag flags)
return online_offline(c, volume, "volume_offline", flags);
}
-int lsm_access_group_list( lsm_connect *c, lsm_access_group **groups[],
- uint32_t *groupCount, lsm_flag flags)
+int lsm_access_group_list(lsm_connect *c, const char *search_key,
+ const char *search_value,
+ lsm_access_group **groups[], uint32_t *groupCount,
+ lsm_flag flags)
{
CONN_SETUP(c);
@@ -1478,11 +1552,19 @@ int lsm_access_group_list( lsm_connect *c, lsm_access_group **groups[],
}
std::map<std::string, Value> p;
+
+ int rc = add_search_params(p, search_key, search_value,
+ ACCESS_GROUP_SEARCH_KEYS,
+ ACCESS_GROUP_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
- int rc = rpc(c, "access_groups", parameters, response);
+ rc = rpc(c, "access_groups", parameters, response);
return getAccessGroups(c, rc, response, groups, groupCount);
}
@@ -1849,8 +1931,9 @@ int lsm_system_list(lsm_connect *c, lsm_system **systems[],
return rc;
}
-int lsm_fs_list(lsm_connect *c, lsm_fs **fs[], uint32_t *fsCount,
- lsm_flag flags)
+int lsm_fs_list(lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_fs **fs[],
+ uint32_t *fsCount, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -1861,6 +1944,13 @@ int lsm_fs_list(lsm_connect *c, lsm_fs **fs[], uint32_t *fsCount,
try {
std::map<std::string, Value> p;
+
+ int rc = add_search_params(p, search_key, search_value, FS_SEARCH_KEYS,
+ FS_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
@@ -2289,8 +2379,9 @@ int lsm_fs_ss_restore(lsm_connect *c, lsm_fs *fs, lsm_fs_ss *ss,
}
-int lsm_nfs_list( lsm_connect *c, lsm_nfs_export **exports[], uint32_t *count,
- lsm_flag flags)
+int lsm_nfs_list( lsm_connect *c, const char *search_key,
+ const char *search_value, lsm_nfs_export **exports[],
+ uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
CONN_SETUP(c);
@@ -2301,6 +2392,14 @@ int lsm_nfs_list( lsm_connect *c, lsm_nfs_export **exports[], uint32_t *count,
try {
std::map<std::string, Value> p;
+
+ rc = add_search_params(p, search_key, search_value,
+ NFS_EXPORT_SEARCH_KEYS,
+ NFS_EXPORT_SEARCH_KEYS_COUNT);
+ if( LSM_ERR_OK != rc ) {
+ return rc;
+ }
+
p["flags"] = Value(flags);
Value parameters(p);
Value response;
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index bd60516..2f880b1 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -203,6 +203,33 @@ static void error_send(lsm_plugin_ptr p, int error_code)
}
}
+static int get_search_params(Value ¶ms, char **k, char **v)
+{
+ int rc = LSM_ERR_OK;
+ Value key = params["search_key"];
+ Value val = params["search_value"];
+
+ if( Value::string_t == key.valueType() ) {
+ if ( Value::string_t == val.valueType() ) {
+ *k = strdup(key.asC_str());
+ *v = strdup(val.asC_str());
+
+ if( *k == NULL || *v == NULL ) {
+ free( *k );
+ *k = NULL;
+ free( *v );
+ *v = NULL;
+ rc = LSM_ERR_NO_MEMORY;
+ }
+ } else {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+ } else if( Value::null_t != key.valueType() ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
+
+ return rc;
+}
/**
* Checks to see if a character string is an integer and returns result
@@ -450,13 +477,16 @@ static int handle_system_list(lsm_plugin_ptr p, Value ¶ms,
static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->mgmt_ops && p->mgmt_ops->pool_list ) {
lsm_pool **pools = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->mgmt_ops->pool_list(p, &pools, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
+ rc = p->mgmt_ops->pool_list(p, key, val, &pools, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc) {
std::vector<Value> result;
@@ -469,8 +499,12 @@ static int handle_pools(lsm_plugin_ptr p, Value ¶ms, Value &response)
pools = NULL;
response = Value(result);
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -772,19 +806,26 @@ static void get_volumes(int rc, lsm_volume **vols, uint32_t count,
static int handle_volumes(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->vol_get ) {
lsm_volume **vols = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->san_ops->vol_get(p, &vols, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->san_ops->vol_get(p, key, val, &vols, &count,
LSM_FLAG_GET_VALUE(params));
get_volumes(rc, vols, count, response);
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -808,17 +849,24 @@ static void get_disks(int rc, lsm_disk **disks, uint32_t count, Value &response)
static int handle_disks(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->disk_get ) {
lsm_disk **disks = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->san_ops->disk_get(p, &disks, &count,
- LSM_FLAG_GET_VALUE(params));
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->san_ops->disk_get(p, key, val, &disks, &count,
+ LSM_FLAG_GET_VALUE(params));
get_disks(rc, disks, count, response);
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -1120,14 +1168,17 @@ static int handle_volume_offline(lsm_plugin_ptr p, Value ¶ms, Value &respons
static int ag_list(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->san_ops->ag_list ) {
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
lsm_access_group **groups = NULL;
uint32_t count;
- rc = p->san_ops->ag_list(p, &groups, &count,
+ rc = p->san_ops->ag_list(p, key, val, &groups, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
response = access_group_list_to_value(groups, count);
@@ -1135,8 +1186,12 @@ static int ag_list(lsm_plugin_ptr p, Value ¶ms, Value &response)
/* Free the memory */
lsm_access_group_record_array_free(groups, count);
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -1500,14 +1555,17 @@ static int volume_dependency_rm(lsm_plugin_ptr p, Value ¶ms, Value &response
static int fs(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->san_ops && p->fs_ops->fs_list ) {
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ ((rc = get_search_params(params, &key, &val)) == LSM_ERR_OK )) {
lsm_fs **fs = NULL;
uint32_t count = 0;
- rc = p->fs_ops->fs_list(p, &fs, &count,
+ rc = p->fs_ops->fs_list(p, key, val, &fs, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
@@ -1521,8 +1579,12 @@ static int fs(lsm_plugin_ptr p, Value ¶ms, Value &response)
lsm_fs_record_array_free(fs, count);
fs = NULL;
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
return rc;
@@ -2051,13 +2113,16 @@ static int export_auth(lsm_plugin_ptr p, Value ¶ms, Value &response)
static int exports(lsm_plugin_ptr p, Value ¶ms, Value &response)
{
int rc = LSM_ERR_NO_SUPPORT;
+ char *key = NULL;
+ char *val = NULL;
if( p && p->nas_ops && p->nas_ops->nfs_list ) {
lsm_nfs_export **exports = NULL;
uint32_t count = 0;
- if( LSM_FLAG_EXPECTED_TYPE(params) ) {
- rc = p->nas_ops->nfs_list(p, &exports, &count,
+ if( LSM_FLAG_EXPECTED_TYPE(params) &&
+ (rc = get_search_params(params, &key, &val)) == LSM_ERR_OK ) {
+ rc = p->nas_ops->nfs_list(p, key, val, &exports, &count,
LSM_FLAG_GET_VALUE(params));
if( LSM_ERR_OK == rc ) {
@@ -2072,8 +2137,12 @@ static int exports(lsm_plugin_ptr p, Value ¶ms, Value &response)
exports = NULL;
count = 0;
}
+ free(key);
+ free(val);
} else {
- rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ if( rc == LSM_ERR_NO_SUPPORT ) {
+ rc = LSM_ERR_TRANSPORT_INVALID_ARG;
+ }
}
}
@@ -2610,4 +2679,195 @@ int LSM_DLL_EXPORT lsm_uri_parse(const char *uri, char **scheme, char **user,
}
}
return rc;
+}
+
+
+typedef int (*array_cmp)(void *item, void *cmp_data);
+typedef void (*free_item)(void *item);
+
+#define CMP_FUNCTION(name, method, method_type) \
+static int name(void *i, void *d) \
+{ \
+ method_type *v = (method_type *)i; \
+ char *val = (char *)d; \
+ \
+ if( strcmp(method(v), val) == 0 ) { \
+ return 1; \
+ } \
+ return 0; \
+} \
+
+
+#define CMP_FREE_FUNCTION(name, method, method_type) \
+static void name(void *i) \
+{ \
+ method((method_type *)i); \
+} \
+
+int filter(void *a[], size_t size, array_cmp cmp, void *cmp_data, free_item fo)
+{
+ int remaining = 0;
+ size_t i = 0;
+
+ for( i = 0; i < size; ++i ) {
+ if( cmp(a[i], cmp_data) ) {
+ memmove(&a[remaining], &a[i], sizeof(void *));
+ remaining += 1;
+ } else {
+ fo(a[i]);
+ a[i] = NULL;
+ }
+ }
+ return remaining;
+}
+
+CMP_FUNCTION(volume_compare_id, lsm_volume_id_get, lsm_volume)
+CMP_FUNCTION(volume_compare_system, lsm_volume_system_id_get, lsm_volume)
+CMP_FUNCTION(volume_compare_pool, lsm_volume_pool_id_get, lsm_volume)
+CMP_FREE_FUNCTION(volume_free, lsm_volume_record_free, lsm_volume)
+
+void lsm_plug_volume_search_filter(const char *search_key, const char *search_value,
+ lsm_volume *vols[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = volume_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = volume_compare_system;
+ } else if ( 0 == strcmp("pool_id", search_key) ) {
+ cmp = volume_compare_pool;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)vols, *count, cmp, (void*)search_value,
+ volume_free);
+ }
+ }
+}
+
+CMP_FUNCTION(pool_compare_id, lsm_pool_id_get, lsm_pool)
+CMP_FUNCTION(pool_compare_system, lsm_pool_system_id_get, lsm_pool)
+CMP_FREE_FUNCTION(pool_free, lsm_pool_record_free, lsm_pool);
+
+void lsm_plug_pool_search_filter(const char *search_key, const char *search_value,
+ lsm_pool *pools[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = pool_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = pool_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)pools, *count, cmp, (void*)search_value,
+ pool_free);
+ }
+ }
+}
+
+CMP_FUNCTION(disk_compare_id, lsm_disk_id_get, lsm_disk)
+CMP_FUNCTION(disk_compare_system, lsm_disk_system_id_get, lsm_disk)
+CMP_FREE_FUNCTION(disk_free, lsm_disk_record_free, lsm_disk)
+
+void lsm_plug_disk_search_filter(const char *search_key, const char *search_value,
+ lsm_disk *disks[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = disk_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = disk_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)disks, *count, cmp, (void*)search_value,
+ disk_free);
+ }
+ }
+}
+
+CMP_FUNCTION(access_group_compare_id, lsm_access_group_id_get, lsm_access_group)
+CMP_FUNCTION(access_group_compare_system, lsm_access_group_system_id_get, lsm_access_group)
+CMP_FREE_FUNCTION(access_group_free, lsm_access_group_record_free,
+ lsm_access_group);
+
+void lsm_plug_access_group_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_access_group *ag[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = access_group_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = access_group_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)ag, *count, cmp, (void*)search_value,
+ access_group_free);
+ }
+ }
+}
+
+CMP_FUNCTION(fs_compare_id, lsm_fs_id_get, lsm_fs)
+CMP_FUNCTION(fs_compare_system, lsm_fs_system_id_get, lsm_fs)
+CMP_FREE_FUNCTION(fs_free, lsm_fs_record_free, lsm_fs);
+
+void lsm_plug_fs_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_fs *fs[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = fs_compare_id;
+ } else if( 0 == strcmp("system_id", search_key) ) {
+ cmp = fs_compare_system;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)fs, *count, cmp, (void*)search_value,
+ fs_free);
+ }
+ }
+}
+
+CMP_FUNCTION(nfs_compare_id, lsm_nfs_export_id_get, lsm_nfs_export)
+CMP_FUNCTION(nfs_compare_fs_id, lsm_nfs_export_fs_id_get, lsm_nfs_export)
+CMP_FREE_FUNCTION(nfs_free, lsm_nfs_export_record_free, lsm_nfs_export)
+
+void lsm_plug_nfs_export_search_filter(const char *search_key,
+ const char *search_value,
+ lsm_nfs_export *exports[], uint32_t *count)
+{
+ array_cmp cmp = NULL;
+
+ if( search_key ) {
+
+ if( 0 == strcmp("id", search_key) ) {
+ cmp = nfs_compare_id;
+ } else if( 0 == strcmp("fs_id", search_key) ) {
+ cmp = nfs_compare_fs_id;
+ }
+
+ if( cmp ) {
+ *count = filter((void **)exports, *count, cmp, (void*)search_value,
+ nfs_free);
+ }
+ }
}
\ No newline at end of file
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 3749ede..2b1d0ab 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -429,7 +429,8 @@ static int job_status(lsm_plugin_ptr c, const char *job_id,
return rc;
}
-static int list_pools(lsm_plugin_ptr c, lsm_pool **pool_array[],
+static int list_pools(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_pool **pool_array[],
uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
@@ -459,6 +460,11 @@ static int list_pools(lsm_plugin_ptr c, lsm_pool **pool_array[],
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_pool_search_filter(search_key, search_value, *pool_array, count);
+ }
+
return rc;
}
@@ -628,14 +634,14 @@ static int list_initiators(lsm_plugin_ptr c, lsm_initiator **init_array[],
return _list_initiators(c, init_array, count, flags, NULL);
}
-static int list_volumes(lsm_plugin_ptr c, lsm_volume **vols[],
- uint32_t *count, lsm_flag flags)
+static int list_volumes(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_volume **vols[], uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
*count = g_hash_table_size(pd->volumes);
-
if( *count ) {
*vols = lsm_volume_record_array_alloc( *count );
if( *vols ) {
@@ -659,11 +665,17 @@ static int list_volumes(lsm_plugin_ptr c, lsm_volume **vols[],
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_volume_search_filter(search_key, search_value, *vols, count);
+ }
+
return rc;
}
-static int list_disks(lsm_plugin_ptr c, lsm_disk **disks[], uint32_t *count,
- lsm_flag flags)
+static int list_disks(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_disk **disks[],
+ uint32_t *count, lsm_flag flags)
{
int rc = LSM_ERR_OK;
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
@@ -693,6 +705,11 @@ static int list_disks(lsm_plugin_ptr c, lsm_disk **disks[], uint32_t *count,
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_disk_search_filter(search_key, search_value, *disks, count);
+ }
+
return rc;
}
@@ -1171,6 +1188,8 @@ static int volume_online_offline(lsm_plugin_ptr c, lsm_volume *v,
}
static int access_group_list(lsm_plugin_ptr c,
+ const char *search_key,
+ const char *search_value,
lsm_access_group **groups[],
uint32_t *group_count, lsm_flag flags)
{
@@ -1205,6 +1224,12 @@ static int access_group_list(lsm_plugin_ptr c,
rc = LSM_ERR_NO_MEMORY;
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_access_group_search_filter(search_key, search_value, *groups,
+ group_count);
+ }
+
return rc;
}
@@ -1653,7 +1678,7 @@ static lsm_access_group *get_access_group( lsm_plugin_ptr c, char *group_name,
lsm_access_group **groups = NULL;
uint32_t count = 0;
- int rc = access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ int rc = access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
uint32_t i;
@@ -1862,7 +1887,8 @@ static struct lsm_san_ops_v1 san_ops = {
};
-static int fs_list(lsm_plugin_ptr c, lsm_fs **fs[], uint32_t *count,
+static int fs_list(lsm_plugin_ptr c, const char *search_key,
+ const char *search_value, lsm_fs **fs[], uint32_t *count,
lsm_flag flags)
{
int rc = LSM_ERR_OK;
@@ -1892,6 +1918,11 @@ static int fs_list(lsm_plugin_ptr c, lsm_fs **fs[], uint32_t *count,
rc = lsm_log_error_basic(c, LSM_ERR_NO_MEMORY, "ENOMEM");
}
}
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_fs_search_filter(search_key, search_value, *fs, count);
+ }
+
return rc;
}
@@ -2248,8 +2279,10 @@ static int nfs_auth_types(lsm_plugin_ptr c, lsm_string_list **types,
return rc;
}
-static int nfs_export_list( lsm_plugin_ptr c, lsm_nfs_export **exports[],
- uint32_t *count, lsm_flag flags)
+static int nfs_export_list( lsm_plugin_ptr c, const char *search_key,
+ const char *search_value,
+ lsm_nfs_export **exports[], uint32_t *count,
+ lsm_flag flags)
{
int rc = LSM_ERR_OK;
GHashTableIter fs_iter;
@@ -2303,6 +2336,10 @@ static int nfs_export_list( lsm_plugin_ptr c, lsm_nfs_export **exports[],
result = NULL;
}
+ if( LSM_ERR_OK == rc ) {
+ lsm_plug_nfs_export_search_filter(search_key, search_value, *exports, count);
+ }
+
return rc;
}
diff --git a/test/tester.c b/test/tester.c
index aa67460..6918e97 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -25,7 +25,7 @@
#include <libstoragemgmt/libstoragemgmt.h>
#include <libstoragemgmt/libstoragemgmt_plug_interface.h>
-const char uri[] = "sim://localhost/?statefile=/tmp/%d/lsm_sim_%s";
+const char URI[] = "sim://localhost/?statefile=/tmp/%d/lsm_sim_%s";
const char SYSTEM_NAME[] = "LSM simulated storage plug-in";
const char SYSTEM_ID[] = "sim-01";
const char *ISCSI_HOST[2] = { "iqn.1994-05.com.domain:01.89bd01",
@@ -68,8 +68,10 @@ void generate_random(char *buff, uint32_t len)
char *plugin_to_use()
{
- if( which_plugin == 1) {
- return "simc://";
+ char *uri_to_use = "sim://";
+
+ if( which_plugin == 1 ) {
+ uri_to_use = "simc://";
} else {
char *rundir = getenv("LSM_TEST_RUNDIR");
@@ -82,14 +84,14 @@ char *plugin_to_use()
static char fn[128];
static char name[32];
generate_random(name, sizeof(name));
- snprintf(fn, sizeof(fn), uri, rdir, name);
- printf("URI = %s\n", fn);
- return fn;
+ snprintf(fn, sizeof(fn), URI, rdir, name);
+ uri_to_use = fn;
} else {
printf("Missing LSM_TEST_RUNDIR, expect test failures!\n");
- return "sim://";
}
}
+ printf("URI = %s\n", uri_to_use);
+ return uri_to_use;
}
lsm_pool *get_test_pool(lsm_connect *c)
@@ -98,7 +100,7 @@ lsm_pool *get_test_pool(lsm_connect *c)
uint32_t count = 0;
lsm_pool *test_pool = NULL;
- int rc = lsm_pool_list(c, &pools, &count, LSM_FLAG_RSVD);
+ int rc = lsm_pool_list(c, NULL, NULL, &pools, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
uint32_t i = 0;
for(i = 0; i < count; ++i ) {
@@ -388,7 +390,7 @@ START_TEST(test_smoke_test)
int poolToUse = -1;
//Get pool list
- rc = lsm_pool_list(c, &pools, &poolCount, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &poolCount, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
error(lsm_error_last_get(c)));
@@ -537,7 +539,7 @@ START_TEST(test_smoke_test)
lsm_volume **volumes = NULL;
count = 0;
/* Get a list of volumes */
- rc = lsm_volume_list(c, &volumes, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc , "lsmVolumeList %d (%s)",rc,
@@ -609,10 +611,11 @@ START_TEST(test_access_groups)
lsm_access_group *group = NULL;
uint32_t count = 0;
uint32_t i = 0;
+ lsm_string_list *init_list = NULL;
fail_unless(c!=NULL);
- int rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ int rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "Expected success on listing access groups %d", rc);
fail_unless(count == 0, "Expect 0 access groups, got %"PRIu32, count);
@@ -654,7 +657,7 @@ START_TEST(test_access_groups)
init_copy = NULL;
}
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
lsm_access_group_record_array_free(groups, count);
@@ -671,17 +674,19 @@ START_TEST(test_access_groups)
fail_unless(LSM_ERR_OK == rc, "Expected success on lsmAccessGroupInitiatorAdd %d", rc);
}
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
- lsm_string_list *init_list = lsm_access_group_initiator_id_get(groups[0]);
- fail_unless( lsm_string_list_size(init_list) == 2, "Expecting 2 initiators, current num = %d\n", lsm_string_list_size(init_list) );
- for( i = 0; i < lsm_string_list_size(init_list); ++i) {
- printf("%d = %s\n", i, lsm_string_list_elem_get(init_list, i));
+ if( count ) {
+ init_list = lsm_access_group_initiator_id_get(groups[0]);
+ fail_unless( lsm_string_list_size(init_list) == 2, "Expecting 2 initiators, current num = %d\n", lsm_string_list_size(init_list) );
+ for( i = 0; i < lsm_string_list_size(init_list); ++i) {
+ printf("%d = %s\n", i, lsm_string_list_elem_get(init_list, i));
+ }
+ lsm_string_list_free(init_list);
+ init_list = NULL;
}
- lsm_string_list_free(init_list);
-
uint32_t init_list_count = 0;
lsm_initiator **inits = NULL;
@@ -708,20 +713,21 @@ START_TEST(test_access_groups)
groups = NULL;
count = 0;
- rc = lsm_access_group_list(c, &groups, &count, LSM_FLAG_RSVD);
+ rc = lsm_access_group_list(c, NULL, NULL, &groups, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( 1 == count );
- init_list = lsm_access_group_initiator_id_get(groups[0]);
- fail_unless( init_list != NULL);
- fail_unless( lsm_string_list_size(init_list) == 0);
-
- lsm_access_group_record_array_free(groups, count);
- groups = NULL;
- count = 0;
-
+ if( count ) {
+ init_list = lsm_access_group_initiator_id_get(groups[0]);
+ fail_unless( init_list != NULL);
+ fail_unless( lsm_string_list_size(init_list) == 0);
+ lsm_string_list_free(init_list);
+ init_list = NULL;
+ lsm_access_group_record_array_free(groups, count);
+ groups = NULL;
+ count = 0;
+ }
}
-
END_TEST
START_TEST(test_access_groups_grant_revoke)
@@ -813,7 +819,7 @@ START_TEST(test_fs)
lsm_pool *test_pool = get_test_pool(c);
- rc = lsm_fs_list(c, &fs_list, &fs_count, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fs_list, &fs_count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc);
fail_unless(0 == fs_count);
@@ -850,7 +856,7 @@ START_TEST(test_fs)
}
- rc = lsm_fs_list(c, &fs_list, &fs_count, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fs_list, &fs_count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc);
fail_unless(2 == fs_count, "fs_count = %d", fs_count);
@@ -1040,7 +1046,7 @@ START_TEST(test_disks)
fail_unless(c!=NULL);
- int rc = lsm_disk_list(c, &d, &count, 0);
+ int rc = lsm_disk_list(c, NULL, NULL, &d, &count, 0);
if( LSM_ERR_OK == rc ) {
fail_unless(LSM_ERR_OK == rc, "%d", rc);
@@ -1125,7 +1131,7 @@ START_TEST(test_nfs_exports)
uint32_t count = 0;
if( nfs ) {
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmNfsList rc= %d\n", rc);
fail_unless(count == 0);
@@ -1148,7 +1154,7 @@ START_TEST(test_nfs_exports)
lsm_nfs_export_record_free(e);
e=NULL;
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc);
fail_unless( exports != NULL);
fail_unless( count == 1 );
@@ -1160,7 +1166,7 @@ START_TEST(test_nfs_exports)
exports = NULL;
- rc = lsm_nfs_list(c, &exports, &count, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, &exports, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "lsmNfsList rc= %d\n", rc);
fail_unless(count == 0);
@@ -1334,20 +1340,39 @@ START_TEST(test_invalid_input)
free(bogus_job);
+ /* lsm_disk_list */
+ uint32_t count = 0;
+ lsm_disk **disks = NULL;
+
+ rc = lsm_disk_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d, rc");
+
+ rc = lsm_disk_list(c, "bogus_key", NULL, &disks, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d, rc");
+
+ rc = lsm_disk_list(c, "bogus_key", "nope", &disks, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d, rc");
+
/* lsmPoolList */
- rc = lsm_pool_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
lsm_pool **pools = NULL;
- rc = lsm_pool_list(c, &pools, NULL, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
- uint32_t count = 0;
- rc = lsm_pool_list(c, NULL, &count, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, NULL, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
pools = (lsm_pool **)&bad;
- rc = lsm_pool_list(c, &pools, &count, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
+
+ pools = NULL;
+ rc = lsm_pool_list(c, "bogus_key", "nope", &pools, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d", rc);
+
+ rc = lsm_pool_list(c, "bogus_key", NULL, &pools, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmInitiatorList */
@@ -1366,18 +1391,25 @@ START_TEST(test_invalid_input)
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmVolumeList */
- rc = lsm_volume_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
lsm_volume **vols = NULL;
- rc = lsm_volume_list(c, &vols, NULL, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &vols, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
- rc = lsm_volume_list(c, NULL, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, NULL, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
vols = (lsm_volume **)&bad;
- rc = lsm_volume_list(c, &vols, &count, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &vols, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
+
+ vols = NULL;
+ rc = lsm_volume_list(c, "bogus_key", "nope", &vols, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_UNSUPPORTED_SEARCH_KEY == rc, "rc %d", rc);
+
+ rc = lsm_volume_list(c, "bogus_key", NULL, &vols, &count, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_ARGUMENT == rc, "rc %d", rc);
/* lsmVolumeCreate */
@@ -1471,8 +1503,10 @@ START_TEST(test_invalid_input)
rc = lsm_capabilities(c, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_INVALID_SYSTEM, "rc %d", rc);
- rc = lsm_capabilities(c, sys[0], NULL, LSM_FLAG_RSVD);
- fail_unless(LSM_ERR_INVALID_ARGUMENT, "rc %d", rc);
+ if( num_systems ) {
+ rc = lsm_capabilities(c, sys[0], NULL, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_INVALID_ARGUMENT, "rc %d", rc);
+ }
/* lsmVolumeReplicate */
lsm_volume *cloned = NULL;
@@ -1605,13 +1639,15 @@ START_TEST(test_invalid_input)
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
/* lsmFsList */
- rc = lsm_fs_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
lsm_fs **fsl = NULL;
- rc = lsm_fs_list(c, &fsl, NULL, LSM_FLAG_RSVD);
+ rc = lsm_fs_list(c, NULL, NULL, &fsl, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
+ rc = lsm_fs_list(c, "bogus_key", "nope", &fsl, &count, LSM_FLAG_RSVD);
+ fail_unless(rc == LSM_ERR_UNSUPPORTED_SEARCH_KEY, "rc = %d", rc);
/*lsmFsCreate*/
rc = lsm_fs_create(c, NULL, NULL, 0, NULL, NULL, LSM_FLAG_RSVD);
@@ -1736,7 +1772,7 @@ START_TEST(test_invalid_input)
rc = lsm_fs_ss_restore(c, arg_fs, arg_ss, f, f, 0, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
- rc = lsm_nfs_list(c, NULL, NULL, LSM_FLAG_RSVD);
+ rc = lsm_nfs_list(c, NULL, NULL, NULL, NULL, LSM_FLAG_RSVD);
fail_unless(rc == LSM_ERR_INVALID_ARGUMENT, "rc = %d", rc);
@@ -1833,58 +1869,60 @@ START_TEST(test_capabilities)
fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
fail_unless( sys_count >= 1, "count = %d", sys_count);
- printf("lsmCapabilities\n");
- rc = lsm_capabilities(c, sys[0], &cap, LSM_FLAG_RSVD);
- fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
+ if( sys_count > 0 ) {
+ printf("lsmCapabilities %d\n", sys_count);
+ rc = lsm_capabilities(c, sys[0], &cap, LSM_FLAG_RSVD);
+ fail_unless( LSM_ERR_OK == rc, "rc = %d", rc);
- if( LSM_ERR_OK == rc ) {
- cap_test(cap, LSM_CAP_BLOCK_SUPPORT);
- cap_test(cap, LSM_CAP_FS_SUPPORT);
- cap_test(cap, LSM_CAP_VOLUMES);
- cap_test(cap, LSM_CAP_VOLUME_CREATE);
- cap_test(cap, LSM_CAP_VOLUME_RESIZE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_CLONE);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_COPY);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_ASYNC);
- cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_SYNC);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_BLOCK_SIZE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_CLONE);
- cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_COPY);
- cap_test(cap, LSM_CAP_VOLUME_DELETE);
- cap_test(cap, LSM_CAP_VOLUME_ONLINE);
- cap_test(cap, LSM_CAP_VOLUME_OFFLINE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_GRANT);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_REVOKE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_LIST);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_CREATE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_DELETE);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_ADD_INITIATOR);
- cap_test(cap, LSM_CAP_ACCESS_GROUP_DEL_INITIATOR);
- cap_test(cap, LSM_CAP_VOLUMES_ACCESSIBLE_BY_ACCESS_GROUP);
- cap_test(cap, LSM_CAP_ACCESS_GROUPS_GRANTED_TO_VOLUME);
- cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY);
- cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY_RM);
- cap_test(cap, LSM_CAP_FS);
- cap_test(cap, LSM_CAP_FS_DELETE);
- cap_test(cap, LSM_CAP_FS_RESIZE);
- cap_test(cap, LSM_CAP_FS_CREATE);
- cap_test(cap, LSM_CAP_FS_CLONE);
- cap_test(cap, LSM_CAP_FILE_CLONE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOTS);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE_SPECIFIC_FILES);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_DELETE);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT);
- cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT_SPECIFIC_FILES);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM);
- cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM_SPECIFIC_FILES );
- cap_test(cap, LSM_CAP_EXPORT_AUTH);
- cap_test(cap, LSM_CAP_EXPORTS);
- cap_test(cap, LSM_CAP_EXPORT_FS);
- cap_test(cap, LSM_CAP_EXPORT_REMOVE);
+ if( LSM_ERR_OK == rc ) {
+ cap_test(cap, LSM_CAP_BLOCK_SUPPORT);
+ cap_test(cap, LSM_CAP_FS_SUPPORT);
+ cap_test(cap, LSM_CAP_VOLUMES);
+ cap_test(cap, LSM_CAP_VOLUME_CREATE);
+ cap_test(cap, LSM_CAP_VOLUME_RESIZE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_CLONE);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_COPY);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_ASYNC);
+ cap_test(cap, LSM_CAP_VOLUME_REPLICATE_MIRROR_SYNC);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_BLOCK_SIZE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_CLONE);
+ cap_test(cap, LSM_CAP_VOLUME_COPY_RANGE_COPY);
+ cap_test(cap, LSM_CAP_VOLUME_DELETE);
+ cap_test(cap, LSM_CAP_VOLUME_ONLINE);
+ cap_test(cap, LSM_CAP_VOLUME_OFFLINE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_GRANT);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_REVOKE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_LIST);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_CREATE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_DELETE);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_ADD_INITIATOR);
+ cap_test(cap, LSM_CAP_ACCESS_GROUP_DEL_INITIATOR);
+ cap_test(cap, LSM_CAP_VOLUMES_ACCESSIBLE_BY_ACCESS_GROUP);
+ cap_test(cap, LSM_CAP_ACCESS_GROUPS_GRANTED_TO_VOLUME);
+ cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY);
+ cap_test(cap, LSM_CAP_VOLUME_CHILD_DEPENDENCY_RM);
+ cap_test(cap, LSM_CAP_FS);
+ cap_test(cap, LSM_CAP_FS_DELETE);
+ cap_test(cap, LSM_CAP_FS_RESIZE);
+ cap_test(cap, LSM_CAP_FS_CREATE);
+ cap_test(cap, LSM_CAP_FS_CLONE);
+ cap_test(cap, LSM_CAP_FILE_CLONE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOTS);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_CREATE_SPECIFIC_FILES);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_DELETE);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT);
+ cap_test(cap, LSM_CAP_FS_SNAPSHOT_REVERT_SPECIFIC_FILES);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM);
+ cap_test(cap, LSM_CAP_FS_CHILD_DEPENDENCY_RM_SPECIFIC_FILES );
+ cap_test(cap, LSM_CAP_EXPORT_AUTH);
+ cap_test(cap, LSM_CAP_EXPORTS);
+ cap_test(cap, LSM_CAP_EXPORT_FS);
+ cap_test(cap, LSM_CAP_EXPORT_REMOVE);
+ }
}
}
END_TEST
@@ -2484,7 +2522,7 @@ START_TEST(test_pool_create)
/*
* Test pool creations from disks
*/
- rc = lsm_disk_list(c, &disks, &num_disks, LSM_FLAG_RSVD);
+ rc = lsm_disk_list(c, NULL, NULL, &disks, &num_disks, LSM_FLAG_RSVD);
lsm_disk *disks_to_use[128];
uint32_t num_disks_to_use = 0;
@@ -2543,11 +2581,12 @@ START_TEST(test_pool_create)
memset(volumes_to_use, 0, sizeof(volumes_to_use));
/* Create some volumes */
- rc = lsm_pool_list(c, &pools, &num_pools, LSM_FLAG_RSVD);
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &num_pools, LSM_FLAG_RSVD);
fail_unless(LSM_ERR_OK == rc, "rc %d", rc);
+ fail_unless(num_pools > 0, "num pools = %d", num_pools);
- if( LSM_ERR_OK == rc ) {
+ if( LSM_ERR_OK == rc && num_pools > 0) {
pool_one = lsm_pool_record_copy(pools[0]);
@@ -2571,7 +2610,7 @@ START_TEST(test_pool_create)
}
}
- rc = lsm_volume_list(c, &volumes, &num_volumes, LSM_FLAG_RSVD);
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &num_volumes, LSM_FLAG_RSVD);
fail_unless( LSM_ERR_OK == rc );
if( num_volumes ) {
@@ -2685,6 +2724,376 @@ START_TEST(test_uri_parse)
}
END_TEST
+START_TEST(test_search_pools)
+{
+ int rc;
+ lsm_pool **pools = NULL;
+ uint32_t poolCount = 0;
+
+ rc = lsm_pool_list(c, NULL, NULL, &pools, &poolCount, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ if( LSM_ERR_OK == rc && poolCount ) {
+ lsm_pool **search_pools = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_pool_list(c, "id", lsm_pool_id_get(pools[0]), &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 pool, got %d", search_count);
+
+ rc = lsm_pool_record_array_free(search_pools, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+
+ /* Search for non-existent pool*/
+ search_pools = NULL;
+ search_count = 0;
+
+ rc = lsm_pool_list(c, "id", "non-existent-id", &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no pools! %d", search_count);
+
+ /* Search which results in all pools */
+ rc = lsm_pool_list(c, "system_id", lsm_pool_system_id_get(pools[0]),
+ &search_pools,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsmPoolList rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == poolCount, "Expecting %d pools, got %d",
+ poolCount, search_count);
+
+ rc = lsm_pool_record_array_free(search_pools, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+
+
+ rc = lsm_pool_record_array_free(pools, poolCount);
+ fail_unless(LSM_ERR_OK == rc, "lsm_pool_record_array_free %d", rc);
+ }
+
+}
+END_TEST
+
+START_TEST(test_search_volumes)
+{
+ int rc;
+ lsm_volume **volumes = NULL;
+ uint32_t volume_count = 0;
+
+ lsm_pool *pool = get_test_pool(c);
+
+ // Make some volumes to we can actually filter
+ create_volumes(c, pool, 10);
+
+ rc = lsm_volume_list(c, NULL, NULL, &volumes, &volume_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(volume_count > 0, "We are expecting some volumes!");
+
+ if( LSM_ERR_OK == rc && volume_count ) {
+ lsm_volume **search_volume = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_volume_list(c, "id", lsm_volume_id_get(volumes[0]),
+ &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 pool, got %d", search_count);
+
+ rc = lsm_volume_record_array_free(search_volume, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_volume = NULL;
+ search_count = 0;
+
+ rc = lsm_volume_list(c, "id", "non-existent-id", &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no volumes! %d", search_count);
+
+ /* Search which results in all volumes */
+ rc = lsm_volume_list(c, "system_id", lsm_volume_system_id_get(volumes[0]),
+ &search_volume,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == volume_count, "Expecting %d volumes, got %d",
+ volume_count, search_count);
+
+ rc = lsm_volume_record_array_free(search_volume, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+
+
+ rc = lsm_volume_record_array_free(volumes, volume_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_volume_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_disks)
+{
+ int rc;
+ lsm_disk **disks = NULL;
+ uint32_t disk_count = 0;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ rc = lsm_disk_list(c, NULL, NULL, &disks, &disk_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(disk_count > 0, "We are expecting some disks!");
+
+ if( LSM_ERR_OK == rc && disk_count ) {
+
+ lsm_disk **search_disks = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_disk_list(c, "id", lsm_disk_id_get(disks[0]),
+ &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 disk, got %d", search_count);
+
+ rc = lsm_disk_record_array_free(search_disks, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_disks = NULL;
+ search_count = 0;
+
+ rc = lsm_disk_list(c, "id", "non-existent-id", &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no disks! %d", search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_disk_list(c, "system_id", lsm_disk_system_id_get(disks[0]),
+ &search_disks,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == disk_count, "Expecting %d disks, got %d",
+ disk_count, search_count);
+
+ rc = lsm_disk_record_array_free(search_disks, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+
+
+ rc = lsm_disk_record_array_free(disks, disk_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_access_groups)
+{
+ int rc;
+ lsm_access_group **ag = NULL;
+ uint32_t count = 0;
+ int i = 0;
+ lsm_access_group *group = NULL;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ for( i = 0; i < 2; ++i ) {
+ char ag_name[64];
+
+ snprintf(ag_name, sizeof(ag_name), "test_access_group_%d", i);
+
+ rc = lsm_access_group_create(c, ag_name, ISCSI_HOST[i],
+ LSM_INITIATOR_ISCSI, SYSTEM_ID, &group, LSM_FLAG_RSVD);
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_access_group_record_free(group);
+ group = NULL;
+ }
+ }
+
+ rc = lsm_access_group_list(c, NULL, NULL, &ag, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(count > 0, "We are expecting some access_groups!");
+
+ if( LSM_ERR_OK == rc && count ) {
+
+ lsm_access_group **search_ag = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_access_group_list(c, "id", lsm_access_group_id_get(ag[0]),
+ &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 access group, got %d",
+ search_count);
+
+ rc = lsm_access_group_record_array_free(search_ag, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+
+ /* Search for non-existent */
+ search_ag = NULL;
+ search_count = 0;
+
+ rc = lsm_access_group_list(c, "id", "non-existent-id", &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no access groups! %d",
+ search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_access_group_list(c, "system_id",
+ lsm_access_group_system_id_get(ag[0]),
+ &search_ag,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_disk_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == count, "Expecting %d access groups, got %d",
+ count, search_count);
+
+ rc = lsm_access_group_record_array_free(search_ag, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+
+
+ rc = lsm_access_group_record_array_free(ag, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_access_group_record_array_free %d",
+ rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
+START_TEST(test_search_fs)
+{
+ int rc;
+ lsm_fs **fsl = NULL;
+ lsm_fs *fs = NULL;
+ uint32_t count = 0;
+ int i = 0;
+ char *job = NULL;
+
+ lsm_pool *pool = get_test_pool(c);
+
+
+ for( i = 0; i < 2; ++i ) {
+ char fs_name[64];
+
+ snprintf(fs_name, sizeof(fs_name), "test_fs_%d", i);
+
+ rc = lsm_fs_create(c, pool, fs_name, 50000000, &fs, &job, LSM_FLAG_RSVD);
+
+ if( LSM_ERR_JOB_STARTED == rc ) {
+ fail_unless(NULL == fs);
+ fs = wait_for_job_fs(c, &job);
+ } else {
+ fail_unless(LSM_ERR_OK == rc);
+ }
+
+ if( LSM_ERR_OK == rc ) {
+ lsm_fs_record_free(fs);
+ }
+ fs = NULL;
+ }
+
+ rc = lsm_fs_list(c, NULL, NULL, &fsl, &count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(count > 0, "We are expecting some file systems!");
+
+ if( LSM_ERR_OK == rc && count ) {
+
+ lsm_fs **search_fs = NULL;
+ uint32_t search_count = 0;
+
+ rc = lsm_fs_list(c, "id", lsm_fs_id_get(fsl[0]),
+ &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 1, "Expecting 1 fs, got %d",
+ search_count);
+
+ rc = lsm_fs_record_array_free(search_fs, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+
+ /* Search for non-existent */
+ search_fs = NULL;
+ search_count = 0;
+
+ rc = lsm_fs_list(c, "id", "non-existent-id", &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == 0, "Expecting no fs! %d", search_count);
+
+ /* Search which results in all disks */
+ rc = lsm_fs_list(c, "system_id",
+ lsm_fs_system_id_get(fsl[0]),
+ &search_fs,
+ &search_count, LSM_FLAG_RSVD);
+
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_list rc =%d (%s)", rc,
+ error(lsm_error_last_get(c)));
+
+ fail_unless(search_count == count, "Expecting %d fs, got %d",
+ count, search_count);
+
+ rc = lsm_fs_record_array_free(search_fs, search_count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+
+
+ rc = lsm_fs_record_array_free(fsl, count);
+ fail_unless(LSM_ERR_OK == rc, "lsm_fs_record_array_free %d", rc);
+ }
+
+ lsm_pool_record_free(pool);
+}
+END_TEST
+
Suite * lsm_suite(void)
{
Suite *s = suite_create("libStorageMgmt");
@@ -2692,6 +3101,11 @@ Suite * lsm_suite(void)
TCase *basic = tcase_create("Basic");
tcase_add_checked_fixture (basic, setup, teardown);
+ tcase_add_test(basic, test_search_fs);
+ tcase_add_test(basic, test_search_access_groups);
+ tcase_add_test(basic, test_search_disks);
+ tcase_add_test(basic, test_search_volumes);
+ tcase_add_test(basic, test_search_pools);
tcase_add_test(basic, test_pool_delete);
tcase_add_test(basic, test_pool_create);
--
1.8.2.1
1.8.2.1