Discussion:
unknown
1970-01-01 00:00:00 UTC
Permalink
This patch does just that, thanks Christophe!

Signed-off-by: Tony Asleson <***@redhat.com>
---
.../libstoragemgmt/libstoragemgmt_capabilities.h | 2 ++
.../libstoragemgmt/libstoragemgmt_plug_interface.h | 7 +++---
c_binding/lsm_datatypes.cpp | 28 +++++++++-------------
plugin/simc/simc_lsmplugin.c | 5 ++--
test/tester.c | 5 ++--
5 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
index bc45f7e..8398a78 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
@@ -38,6 +38,8 @@ typedef enum {
/** \enum lsm_capability_value_type Capabilities supported by array */
typedef enum {

+ LSM_CAP_SET_N_SENTINEL = -1, /**< Used for last variable argument for lsm_capability_set_n */
+
LSM_CAP_VOLUMES = 20, /**< List volumes */
LSM_CAP_VOLUME_CREATE = 21, /**< Create volumes */
LSM_CAP_VOLUME_RESIZE = 22, /**< Resize volumes */
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
index 1deab9a..71a6579 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_plug_interface.h
@@ -1226,13 +1226,12 @@ int LSM_DLL_EXPORT lsm_capability_set(lsm_storage_capabilities *cap, lsm_capabil
* Sets 1 or more capabilities with the same value v
* @param cap Valid capability pointer
* @param v The value to set capabilities to
- * @param number Number of Capabilities to set
- * @param ... Which capabilites to set
+ * @param ... Which capabilites to set (Make sure to terminate list
+ * with LSM_CAP_SENTINEL)
* @return LSM_ERR_OK on success, else error reason
*/
int LSM_DLL_EXPORT lsm_capability_set_n( lsm_storage_capabilities *cap,
- lsm_capability_value_type v,
- uint32_t number, ... );
+ lsm_capability_value_type v, ... );

/**
* Allocated storage for capabilities
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index 4e8795a..f826852 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -1571,35 +1571,29 @@ int lsm_capability_set(lsm_storage_capabilities *cap, lsm_capability_type t,
}

int lsm_capability_set_n( lsm_storage_capabilities *cap,
- lsm_capability_value_type v, uint32_t number,
+ lsm_capability_value_type v,
... )
{
- uint32_t i = 0;
int rc = LSM_ERR_OK;
+ int index = 0;

if( !LSM_IS_CAPABILITIY(cap) ) {
return LSM_ERR_INVALID_CAPABILITY;
}

- if( number ) {
- va_list var_arg;
+ va_list var_arg;
+ va_start(var_arg, v);

- va_start(var_arg, number);
-
- for( i = 0; i < number; ++i ) {
- int index = va_arg(var_arg, int);
-
- if( index < (int)cap->len ) {
- cap->cap[index] = v;
- } else {
- rc = LSM_ERR_INVALID_ARGUMENT;
- break;
- }
+ while( (index = va_arg(var_arg, int)) != LSM_CAP_SET_N_SENTINEL ) {
+ if( index < (int)cap->len ) {
+ cap->cap[index] = v;
+ } else {
+ rc = LSM_ERR_INVALID_ARGUMENT;
+ break;
}
-
- va_end(var_arg);
}

+ va_end(var_arg);
return rc;
}

diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index b39d7ed..36d43d2 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -334,7 +334,7 @@ static int cap(lsm_plugin_ptr c, lsm_system *system,
*cap = lsm_capability_record_alloc(NULL);

if( *cap ) {
- rc = lsm_capability_set_n(*cap, LSM_CAPABILITY_SUPPORTED, 43,
+ rc = lsm_capability_set_n(*cap, LSM_CAPABILITY_SUPPORTED,
LSM_CAP_VOLUMES,
LSM_CAP_VOLUME_CREATE,
LSM_CAP_VOLUME_RESIZE,
@@ -377,7 +377,8 @@ static int cap(lsm_plugin_ptr c, lsm_system *system,
LSM_CAP_EXPORT_AUTH,
LSM_CAP_EXPORTS,
LSM_CAP_EXPORT_FS,
- LSM_CAP_EXPORT_REMOVE
+ LSM_CAP_EXPORT_REMOVE,
+ LSM_CAP_SET_N_SENTINEL
);

if( LSM_ERR_OK != rc ) {
diff --git a/test/tester.c b/test/tester.c
index e0f09aa..ac250c6 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2125,7 +2125,7 @@ START_TEST(test_capability)
fail_unless(cap != NULL);

if( cap ) {
- G(rc, lsm_capability_set_n, cap, LSM_CAPABILITY_SUPPORTED, 43,
+ G(rc, lsm_capability_set_n, cap, LSM_CAPABILITY_SUPPORTED,
LSM_CAP_VOLUMES,
LSM_CAP_VOLUME_CREATE,
LSM_CAP_VOLUME_RESIZE,
@@ -2168,7 +2168,8 @@ START_TEST(test_capability)
LSM_CAP_EXPORT_AUTH,
LSM_CAP_EXPORTS,
LSM_CAP_EXPORT_FS,
- LSM_CAP_EXPORT_REMOVE
+ LSM_CAP_EXPORT_REMOVE,
+ LSM_CAP_SET_N_SENTINEL
);

G(rc, lsm_capability_set, cap, LSM_CAP_EXPORTS,
--
1.8.2.1
Loading...