This patch adds a flag VIR_TYPED_PARAM_HISTOGRAM_OKAY which works similar to VIR_TYPED_PARAM_STRING_OKAY to maintain server-client compatibility. Signed-off-by: Amneesh Singh <natto@xxxxxxxxxxxxx> --- include/libvirt/libvirt-common.h.in | 5 ++++ src/admin/admin_server_dispatch.c | 6 +++- src/libvirt.c | 46 +++++++++++++++++++---------- src/remote/remote_daemon_dispatch.c | 14 +++++---- src/remote/remote_driver.c | 16 ++++++---- src/rpc/gendispatch.pl | 4 +-- src/util/virtypedparam.c | 7 +++++ 7 files changed, 69 insertions(+), 29 deletions(-) diff --git a/include/libvirt/libvirt-common.h.in b/include/libvirt/libvirt-common.h.in index 11338d9191..39f96691c3 100644 --- a/include/libvirt/libvirt-common.h.in +++ b/include/libvirt/libvirt-common.h.in @@ -206,6 +206,11 @@ typedef enum { */ VIR_TYPED_PARAM_STRING_OKAY = 1 << 2, + /* Same as VIR_TYPED_PARAM_STRING_OKAY but for histograms + * Since: 8.8.0 + */ + VIR_TYPED_PARAM_HISTOGRAM_OKAY = 1 << 3, + } virTypedParameterFlags; /** diff --git a/src/admin/admin_server_dispatch.c b/src/admin/admin_server_dispatch.c index b3e7be8965..0bf852b053 100644 --- a/src/admin/admin_server_dispatch.c +++ b/src/admin/admin_server_dispatch.c @@ -37,6 +37,10 @@ VIR_LOG_INIT("daemon.admin"); +#define VIR_TYPED_PARAM_OKAY_FLAGS \ + VIR_TYPED_PARAM_STRING_OKAY | \ + VIR_TYPED_PARAM_HISTOGRAM_OKAY + typedef struct daemonAdmClientPrivate daemonAdmClientPrivate; /* Separate private data for admin connection */ struct daemonAdmClientPrivate { @@ -322,7 +326,7 @@ adminDispatchClientGetInfo(virNetServer *server G_GNUC_UNUSED, ADMIN_CLIENT_INFO_PARAMETERS_MAX, (struct _virTypedParameterRemote **) &ret->params.params_val, &ret->params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) goto cleanup; rv = 0; diff --git a/src/libvirt.c b/src/libvirt.c index 748f2d8ba0..6dbb11aeb5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1331,12 +1331,36 @@ virTypedParameterValidateSet(virConnectPtr conn, int nparams) { int string_okay; + int histogram_okay; size_t i; string_okay = VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn, VIR_DRV_FEATURE_TYPED_PARAM_STRING); if (string_okay < 0) return -1; + + histogram_okay = VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn, + VIR_DRV_FEATURE_TYPED_PARAM_HISTOGRAM); + if (histogram_okay < 0) + return -1; + +#define VALIDATE_NULLABLE_PARAM_TYPE(LVAR, UVAR, UNIONMEM) \ + if (params[i].type == VIR_TYPED_PARAM_##UVAR) { \ + if (LVAR##_okay) { \ + if (!params[i].value.UNIONMEM) { \ + virReportInvalidArg(params, \ + _("NULL "#LVAR" parameter '%s'"), \ + params[i].field); \ + return -1; \ + } \ + } else { \ + virReportInvalidArg(params, \ + _(#LVAR" parameter '%s' unsupported"), \ + params[i].field); \ + return -1; \ + } \ + } + for (i = 0; i < nparams; i++) { if (strnlen(params[i].field, VIR_TYPED_PARAM_FIELD_LENGTH) == VIR_TYPED_PARAM_FIELD_LENGTH) { @@ -1346,21 +1370,13 @@ virTypedParameterValidateSet(virConnectPtr conn, params[i].field); return -1; } - if (params[i].type == VIR_TYPED_PARAM_STRING) { - if (string_okay) { - if (!params[i].value.s) { - virReportInvalidArg(params, - _("NULL string parameter '%s'"), - params[i].field); - return -1; - } - } else { - virReportInvalidArg(params, - _("string parameter '%s' unsupported"), - params[i].field); - return -1; - } - } + + VALIDATE_NULLABLE_PARAM_TYPE(string, STRING, s); + VALIDATE_NULLABLE_PARAM_TYPE(histogram, HISTOGRAM, h); + } + +#undef VALIDATE_NULLABLE_PARAM_TYPE + return 0; } diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index a5837dce26..888dee10b9 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -69,6 +69,10 @@ VIR_LOG_INIT("daemon.remote"); # define HYPER_TO_ULONG(_to, _from) (_to) = (_from) #endif +#define VIR_TYPED_PARAM_OKAY_FLAGS \ + VIR_TYPED_PARAM_STRING_OKAY | \ + VIR_TYPED_PARAM_HISTOGRAM_OKAY + struct daemonClientEventCallback { virNetServerClient *client; virNetServerProgram *program; @@ -1033,7 +1037,7 @@ remoteRelayDomainEventTunable(virConnectPtr conn, REMOTE_DOMAIN_EVENT_TUNABLE_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, &data.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) return -1; data.callbackID = callback->callbackID; @@ -1173,7 +1177,7 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn, REMOTE_DOMAIN_JOB_STATS_MAX, (struct _virTypedParameterRemote **) &data.params.params_val, &data.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) return -1; data.callbackID = callback->callbackID; @@ -5468,7 +5472,7 @@ remoteDispatchDomainGetJobStats(virNetServer *server G_GNUC_UNUSED, REMOTE_DOMAIN_JOB_STATS_MAX, (struct _virTypedParameterRemote **) &ret->params.params_val, &ret->params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) goto cleanup; rv = 0; @@ -6757,7 +6761,7 @@ remoteDispatchConnectGetAllDomainStats(virNetServer *server G_GNUC_UNUSED, REMOTE_CONNECT_GET_ALL_DOMAIN_STATS_MAX, (struct _virTypedParameterRemote **) &dst->params.params_val, &dst->params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) goto cleanup; } } else { @@ -7308,7 +7312,7 @@ remoteDispatchDomainGetGuestInfo(virNetServer *server G_GNUC_UNUSED, REMOTE_DOMAIN_GUEST_INFO_PARAMS_MAX, (struct _virTypedParameterRemote **) &ret->params.params_val, &ret->params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) goto cleanup; rv = 0; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index a4efe101a3..d226bedf19 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -72,6 +72,10 @@ VIR_LOG_INIT("remote.remote_driver"); # define HYPER_TO_ULONG(_to, _from) (_to) = (_from) #endif +#define VIR_TYPED_PARAM_OKAY_FLAGS \ + VIR_TYPED_PARAM_STRING_OKAY | \ + VIR_TYPED_PARAM_HISTOGRAM_OKAY + static bool inside_daemon; static bool monolithic_daemon; @@ -6918,7 +6922,7 @@ remoteDomainMigrateBegin3Params(virDomainPtr domain, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_begin3_params_args, (char *) &args); goto cleanup; @@ -6980,7 +6984,7 @@ remoteDomainMigratePrepare3Params(virConnectPtr dconn, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_prepare3_params_args, (char *) &args); goto cleanup; @@ -7062,7 +7066,7 @@ remoteDomainMigratePrepareTunnel3Params(virConnectPtr dconn, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_params_args, (char *) &args); goto cleanup; @@ -7148,7 +7152,7 @@ remoteDomainMigratePerform3Params(virDomainPtr dom, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_perform3_params_args, (char *) &args); goto cleanup; @@ -7215,7 +7219,7 @@ remoteDomainMigrateFinish3Params(virConnectPtr dconn, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_finish3_params_args, (char *) &args); goto cleanup; @@ -7283,7 +7287,7 @@ remoteDomainMigrateConfirm3Params(virDomainPtr domain, REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX, (struct _virTypedParameterRemote **) &args.params.params_val, &args.params.params_len, - VIR_TYPED_PARAM_STRING_OKAY) < 0) { + VIR_TYPED_PARAM_OKAY_FLAGS) < 0) { xdr_free((xdrproc_t) xdr_remote_domain_migrate_confirm3_params_args, (char *) &args); goto cleanup; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 5f2b163ea0..e5615735fd 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -961,7 +961,7 @@ elsif ($mode eq "server") { " $2,\n" . " (struct _virTypedParameterRemote **) &ret->$1.$1_val,\n" . " &ret->$1.$1_len,\n" . - " VIR_TYPED_PARAM_STRING_OKAY) < 0)\n" . + " VIR_TYPED_PARAM_STRING_OKAY | VIR_TYPED_PARAM_HISTOGRAM_OKAY) < 0)\n" . " goto cleanup;\n"); push(@free_list, " virTypedParamsFree($1, $1_len);"); @@ -1445,7 +1445,7 @@ elsif ($mode eq "client") { " $2,\n" . " (struct _virTypedParameterRemote **) &args.$1.$1_val,\n" . " &args.$1.$1_len,\n" . - " VIR_TYPED_PARAM_STRING_OKAY) < 0) {\n" . + " VIR_TYPED_PARAM_STRING_OKAY | VIR_TYPED_PARAM_HISTOGRAM_OKAY) < 0) {\n" . " xdr_free((xdrproc_t)xdr_$call->{args}, (char *)&args);\n" . " goto done;\n" . " }"); diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 87fa69271b..b6ffa64135 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -785,6 +785,13 @@ virTypedParamsSerialize(virTypedParameterPtr params, continue; } + if (!param->type || + (!(flags & VIR_TYPED_PARAM_HISTOGRAM_OKAY) && + param->type == VIR_TYPED_PARAM_HISTOGRAM)) { + --params_len; + continue; + } + /* This will be either freed by virNetServerDispatchCall or call(), * depending on the calling side, i.e. server or client */ val->field = g_strdup(param->field); -- 2.37.1