This action deserves its own function and makes main API call
structure much cleaner.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/vz/vz_driver.c | 61 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 25 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index f7e1c07..72774ae 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1583,6 +1583,41 @@ vzDomainBlockStats(virDomainPtr domain,
}
static int
+vzDomainBlockStatsToParams(virDomainBlockStatsPtr stats,
+ virTypedParameterPtr params,
+ int *nparams)
+{
+ size_t i;
+
+ if (*nparams == 0) {
+#define PARALLELS_COUNT_STATS(VAR, TYPE, NAME) \
+ if ((stats->VAR) != -1) \
+ ++*nparams;
+
+ PARALLELS_BLOCK_STATS_FOREACH(PARALLELS_COUNT_STATS)
+
+#undef PARALLELS_COUNT_STATS
+ return 0;
+ }
+
+ i = 0;
+#define PARALLELS_BLOCK_STATS_ASSIGN_PARAM(VAR, TYPE, NAME) \
+ if (i < *nparams && (stats->VAR) != -1) {
\
+ if (virTypedParameterAssign(params + i, TYPE, \
+ VIR_TYPED_PARAM_LLONG, (stats->VAR)) < 0) \
+ return -1; \
+ i++; \
+ }
+
+ PARALLELS_BLOCK_STATS_FOREACH(PARALLELS_BLOCK_STATS_ASSIGN_PARAM)
+
+#undef PARALLELS_BLOCK_STATS_ASSIGN_PARAM
+
+ *nparams = i;
+ return 0;
+}
+
+static int
vzDomainBlockStatsFlags(virDomainPtr domain,
const char *path,
virTypedParameterPtr params,
@@ -1592,7 +1627,6 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
virDomainBlockStatsStruct stats;
virDomainObjPtr dom;
int ret = -1;
- size_t i;
virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
/* We don't return strings, and thus trivially support this flag. */
@@ -1604,32 +1638,9 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
if (vzDomainBlockStatsImpl(dom, path, &stats) < 0)
goto cleanup;
- if (*nparams == 0) {
-#define PARALLELS_COUNT_STATS(VAR, TYPE, NAME) \
- if ((stats.VAR) != -1) \
- ++*nparams;
-
- PARALLELS_BLOCK_STATS_FOREACH(PARALLELS_COUNT_STATS)
-
-#undef PARALLELS_COUNT_STATS
- ret = 0;
+ if (vzDomainBlockStatsToParams(&stats, params, nparams) < 0)
goto cleanup;
- }
- i = 0;
-#define PARALLELS_BLOCK_STATS_ASSIGN_PARAM(VAR, TYPE, NAME) \
- if (i < *nparams && (stats.VAR) != -1) {
\
- if (virTypedParameterAssign(params + i, TYPE, \
- VIR_TYPED_PARAM_LLONG, (stats.VAR)) < 0) \
- goto cleanup; \
- i++; \
- }
-
- PARALLELS_BLOCK_STATS_FOREACH(PARALLELS_BLOCK_STATS_ASSIGN_PARAM)
-
-#undef PARALLELS_BLOCK_STATS_ASSIGN_PARAM
-
- *nparams = i;
ret = 0;
cleanup:
--
1.8.3.1