[libvirt] [PATCH 11/47] vircgroup: extract virCgroupV1DetectControllers
Fabiano Fidêncio
fidencio at redhat.com
Thu Sep 20 06:29:23 UTC 2018
On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <phrdina at redhat.com> wrote:
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
>
Reviewed-by: Fabiano Fidêncio <fidencio at redhat.com>
> ---
> src/util/vircgroup.c | 66 +------------------------------------
> src/util/vircgroupbackend.h | 5 +++
> src/util/vircgroupv1.c | 65 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 71 insertions(+), 65 deletions(-)
>
> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
> index ff102e2cb0..7822eec683 100644
> --- a/src/util/vircgroup.c
> +++ b/src/util/vircgroup.c
> @@ -351,70 +351,6 @@ virCgroupDetectPlacement(virCgroupPtr group,
> }
>
>
> -static int
> -virCgroupDetectControllers(virCgroupPtr group,
> - int controllers)
> -{
> - size_t i;
> - size_t j;
> -
> - if (controllers >= 0) {
> - VIR_DEBUG("Filtering controllers %d", controllers);
> - /* First mark requested but non-existing controllers to be
> ignored */
> - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> - if (((1 << i) & controllers)) {
> - /* Remove non-existent controllers */
> - if (!group->controllers[i].mountPoint) {
> - VIR_DEBUG("Requested controller '%s' not mounted,
> ignoring",
> - virCgroupControllerTypeToString(i));
> - controllers &= ~(1 << i);
> - }
> - }
> - }
> - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> - VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
> - virCgroupControllerTypeToString(i),
> - (1 << i) & controllers ? "yes" : "no",
> - NULLSTR(group->controllers[i].mountPoint));
> - if (!((1 << i) & controllers) &&
> - group->controllers[i].mountPoint) {
> - /* Check whether a request to disable a controller
> - * clashes with co-mounting of controllers */
> - for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
> - if (j == i)
> - continue;
> - if (!((1 << j) & controllers))
> - continue;
> -
> - if (STREQ_NULLABLE(group->controllers[i].mountPoint,
> - group->controllers[j].mountPoint))
> {
> - virReportSystemError(EINVAL,
> - _("Controller '%s' is not
> wanted, but '%s' is co-mounted"),
> -
> virCgroupControllerTypeToString(i),
> -
> virCgroupControllerTypeToString(j));
> - return -1;
> - }
> - }
> - VIR_FREE(group->controllers[i].mountPoint);
> - }
> - }
> - } else {
> - VIR_DEBUG("Auto-detecting controllers");
> - controllers = 0;
> - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> - VIR_DEBUG("Controller '%s' present=%s",
> - virCgroupControllerTypeToString(i),
> - group->controllers[i].mountPoint ? "yes" : "no");
> - if (group->controllers[i].mountPoint == NULL)
> - continue;
> - controllers |= (1 << i);
> - }
> - }
> -
> - return controllers;
> -}
> -
> -
> static int
> virCgroupDetect(virCgroupPtr group,
> pid_t pid,
> @@ -453,7 +389,7 @@ virCgroupDetect(virCgroupPtr group,
> return -1;
> }
>
> - rc = virCgroupDetectControllers(group, controllers);
> + rc = group->backend->detectControllers(group, controllers);
> if (rc < 0)
> return -1;
>
> diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
> index 1856164c6b..31be70688c 100644
> --- a/src/util/vircgroupbackend.h
> +++ b/src/util/vircgroupbackend.h
> @@ -69,6 +69,10 @@ typedef int
> typedef char *
> (*virCgroupGetPlacementCB)(virCgroupPtr group);
>
> +typedef int
> +(*virCgroupDetectControllersCB)(virCgroupPtr group,
> + int controllers);
> +
> struct _virCgroupBackend {
> virCgroupBackendType type;
>
> @@ -81,6 +85,7 @@ struct _virCgroupBackend {
> virCgroupDetectPlacementCB detectPlacement;
> virCgroupValidatePlacementCB validatePlacement;
> virCgroupGetPlacementCB getPlacement;
> + virCgroupDetectControllersCB detectControllers;
> };
> typedef struct _virCgroupBackend virCgroupBackend;
> typedef virCgroupBackend *virCgroupBackendPtr;
> diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
> index ab8988cd59..4dbb3020f5 100644
> --- a/src/util/vircgroupv1.c
> +++ b/src/util/vircgroupv1.c
> @@ -413,6 +413,70 @@ virCgroupV1GetPlacement(virCgroupPtr group)
> }
>
>
> +static int
> +virCgroupV1DetectControllers(virCgroupPtr group,
> + int controllers)
> +{
> + size_t i;
> + size_t j;
> +
> + if (controllers >= 0) {
> + VIR_DEBUG("Filtering controllers %d", controllers);
> + /* First mark requested but non-existing controllers to be
> ignored */
> + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> + if (((1 << i) & controllers)) {
> + /* Remove non-existent controllers */
> + if (!group->controllers[i].mountPoint) {
> + VIR_DEBUG("Requested controller '%s' not mounted,
> ignoring",
> + virCgroupV1ControllerTypeToString(i));
> + controllers &= ~(1 << i);
> + }
> + }
> + }
> + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> + VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
> + virCgroupV1ControllerTypeToString(i),
> + (1 << i) & controllers ? "yes" : "no",
> + NULLSTR(group->controllers[i].mountPoint));
> + if (!((1 << i) & controllers) &&
> + group->controllers[i].mountPoint) {
> + /* Check whether a request to disable a controller
> + * clashes with co-mounting of controllers */
> + for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
> + if (j == i)
> + continue;
> + if (!((1 << j) & controllers))
> + continue;
> +
> + if (STREQ_NULLABLE(group->controllers[i].mountPoint,
> + group->controllers[j].mountPoint))
> {
> + virReportSystemError(EINVAL,
> + _("V1 controller '%s' is not
> wanted, but '%s' is co-mounted"),
> +
> virCgroupV1ControllerTypeToString(i),
> +
> virCgroupV1ControllerTypeToString(j));
> + return -1;
> + }
> + }
> + VIR_FREE(group->controllers[i].mountPoint);
> + }
> + }
> + } else {
> + VIR_DEBUG("Auto-detecting controllers");
> + controllers = 0;
> + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
> + VIR_DEBUG("Controller '%s' present=%s",
> + virCgroupV1ControllerTypeToString(i),
> + group->controllers[i].mountPoint ? "yes" : "no");
> + if (group->controllers[i].mountPoint == NULL)
> + continue;
> + controllers |= (1 << i);
> + }
> + }
> +
> + return controllers;
> +}
> +
> +
> virCgroupBackend virCgroupV1Backend = {
> .type = VIR_CGROUP_BACKEND_TYPE_V1,
>
> @@ -424,6 +488,7 @@ virCgroupBackend virCgroupV1Backend = {
> .detectPlacement = virCgroupV1DetectPlacement,
> .validatePlacement = virCgroupV1ValidatePlacement,
> .getPlacement = virCgroupV1GetPlacement,
> + .detectControllers = virCgroupV1DetectControllers,
> };
>
>
> --
> 2.17.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180920/977dc904/attachment-0001.htm>
More information about the libvir-list
mailing list