ncp.c revision 71ed50cf049ab14d8e0ef8d48ba17d91223e81e7
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * CDDL HEADER START
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The contents of this file are subject to the terms of the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Common Development and Distribution License (the "License").
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * You may not use this file except in compliance with the License.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * or http://www.opensolaris.org/os/licensing.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * See the License for the specific language governing permissions
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * and limitations under the License.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * When distributing Covered Code, include this CDDL HEADER in each
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If applicable, add the following below this CDDL HEADER, with the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * fields enclosed by brackets "[]" replaced with your own identifying
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * information: Portions Copyright [yyyy] [name of copyright owner]
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * CDDL HEADER END
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <arpa/inet.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <assert.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libdllink.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libdlstat.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libnwam.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libscf.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <netinet/in.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <stdlib.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <sys/socket.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <sys/time.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <sys/types.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <values.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "conditions.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "events.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "objects.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "ncp.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "ncu.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "util.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * ncp.c - handles NCP actions.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeychar active_ncp[NWAM_MAX_NAME_LEN];
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwam_ncp_handle_t active_ncph = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint64_t current_ncu_priority_group = INVALID_PRIORITY_GROUP;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * active_ncp_mutex protects active_ncp, active_ncph and
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * current_ncu_priority_group.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeypthread_mutex_t active_ncp_mutex = PTHREAD_MUTEX_INITIALIZER;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The variable ncu_wait_time specifies how long to wait to obtain a
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * DHCP lease before giving up on that NCU and moving on to the next/lower
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * priority-group.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyuint64_t ncu_wait_time = NCU_WAIT_TIME_DEFAULT;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Specifies if this is the first time the NCP has been enabled. True
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * on startup so that we can differentiate between when we start up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * with a given NCP versus when we are asked to reenable it.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyboolean_t initial_ncp_enable = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * nwamd_ncp_handle_enable_event() should be called in the event handling
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * loop in response to an _ENABLE event, triggered as a result of an
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * nwam_ncp_enable() call from a libnwam consumer. To enable the new NCP,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * we first call nwamd_fini_ncus() on the old NCP. This results in enqueueing
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * of a set of _FINI events for each NCU. These events are handled and in
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * order to tear down config, (online*, uninitialized) state change events
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * are created and consumed directly by the fini event handler (these events
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * are not enqueued as this would result in state events for the old NCP
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * appearing after the new NCP has been enabled. After the _FINI events are
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * enqueued, we enqueue an NCP _OBJECT_STATE event for the new NCP. Since
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * it is enqueued after the _FINI events, we are guaranteed no events for the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * old NCP will appear after the new NCP is activated.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_handle_enable_event(nwamd_event_t event)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char *new_ncp = event->event_object;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_ncp_handle_t new_ncph;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_error_t err;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (new_ncp[0] == '\0')
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (strcmp(active_ncp, new_ncp) == 0 && !initial_ncp_enable) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_handle_enable_event: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "%s is already active", new_ncp);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_handle_enable_event: activating NCP %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey new_ncp);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * To activate new NCP, run nwamd_fini_ncus(), reset the active
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * priority-group, set the active_ncp property and refresh the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * daemon. The refresh action will trigger a re-read of the NCUs
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * for the activated NCP.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_fini_ncus();
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey if ((err = nwam_ncp_read(new_ncp, 0, &new_ncph))
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey == NWAM_ENTITY_NOT_FOUND) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey err = nwam_ncp_create(new_ncp, 0, &new_ncph);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (err == NWAM_SUCCESS) {
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey nwam_ncp_free(new_ncph);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCP, new_ncp,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_STATE_ONLINE, NWAM_AUX_STATE_ACTIVE);
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey } else if (initial_ncp_enable) {
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey /*
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey * We weren't able to enable the NCP when nwamd starts up,
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey * retry in a few seconds.
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey */
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey nwamd_event_t retry_event = nwamd_event_init_object_action
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey (NWAM_OBJECT_TYPE_NCP, new_ncp, NULL, NWAM_ACTION_ENABLE);
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey if (retry_event == NULL) {
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_handle_enable_event: "
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey "could not create retry event to enable %s NCP",
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey new_ncp);
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey return;
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey }
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_handle_enable_event: "
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey "failed to enable %s NCP, retrying in %d seconds",
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey new_ncp, NWAMD_READONLY_RETRY_INTERVAL);
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey nwamd_event_enqueue_timed(retry_event,
71ed50cf049ab14d8e0ef8d48ba17d91223e81e7Anurag S. Maskey NWAMD_READONLY_RETRY_INTERVAL);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } else {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_handle_enable_event: error %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_strerror(err));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_handle_action_event(nwamd_event_t event)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey switch (event->event_msg->nwe_data.nwe_object_action.nwe_action) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_ACTION_ENABLE:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncp_handle_enable_event(event);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_ACTION_ADD:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_ACTION_DESTROY:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* nothing to do */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey default:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "nwam_ncp_handle_action_event: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "unexpected action");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_do_not_send(event);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The only state events we create are (online, active) events which are
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * generated as part of an NCP enable action (see above).
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_handle_state_event(nwamd_event_t event)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char *new_ncp = event->event_object;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_ncp_handle_t new_ncph, old_ncph;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_error_t err;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* The NCP to be activated should always exist. */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((err = nwam_ncp_read(new_ncp, 0, &new_ncph)) != NWAM_SUCCESS) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_handle_state_event: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "cannot read NCP %s: : %s", new_ncp, nwam_strerror(err));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_do_not_send(event);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * To activate new NCP, reset the active priority-group, set the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * active_ncp property and refresh the daemon. The refresh action will
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * trigger a re-read of the NCUs for the activated NCP.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey old_ncph = active_ncph;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey active_ncph = new_ncph;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_ncp_free(old_ncph);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey current_ncu_priority_group = INVALID_PRIORITY_GROUP;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) strlcpy(active_ncp, event->event_object,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey sizeof (active_ncp));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) nwamd_set_string_property(OUR_FMRI, OUR_PG,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey OUR_ACTIVE_NCP_PROP_NAME, new_ncp);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) smf_refresh_instance(OUR_FMRI);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey initial_ncp_enable = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_action(const char *ncp, nwam_action_t action)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_t event = nwamd_event_init_object_action
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (NWAM_OBJECT_TYPE_NCP, ncp, NULL, action);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (event == NULL)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_enqueue(event);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Below this point are routines handling NCU prioritization
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * policy for the active NCP.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystruct priority_group_cbarg {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t minpriority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t currpriority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t found;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey};
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* Callback used to find next pg in NCP that is >= start_pg */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfind_next_priority_group_cb(nwamd_object_t object, void *data)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct priority_group_cbarg *cbarg = data;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t priority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_t *ncu = object->nwamd_object_data;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (ncu->ncu_node.u_link.nwamd_link_activation_mode !=
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_ACTIVATION_MODE_PRIORITIZED)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey priority = ncu->ncu_node.u_link.nwamd_link_priority_group;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority >= cbarg->minpriority && priority < cbarg->currpriority) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey cbarg->found = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey cbarg->currpriority = priority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* Set current_pg to next pg in NCP that is >= start_pg */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyboolean_t
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_find_next_priority_group(int64_t minpriority,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int64_t *nextpriorityp)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct priority_group_cbarg cbarg;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey cbarg.minpriority = minpriority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey cbarg.currpriority = MAXINT;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey cbarg.found = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey find_next_priority_group_cb, &cbarg);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (cbarg.found) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_find_next_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "next priority group >= %lld is %lld",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey minpriority, cbarg.currpriority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *nextpriorityp = cbarg.currpriority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_TRUE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } else {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_find_next_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "no priority groups >= %lld exist", minpriority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Struct for walking NCUs in the selected priority group. We count
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * how many of the exclusive, all and shared NCUs are online, and
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * if activate_or_deactivate is true, we either activate or deactivate
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * (depending on the value of activate) offline/online NCUs.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystruct nwamd_ncu_check_walk_arg {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t manual; /* enable manual NCUs only */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int64_t priority_group; /* interested priority-group for this walk */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t exclusive_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t exclusive_online_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t shared_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t shared_online_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t all_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t all_online_ncus;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t activate_or_deactivate;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t activate;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey};
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * This function serves a number of purposes:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - it supports activation/deactivation of manual NCUs in the current NCP
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * (when wa->manual is true, wa->activate determines if we activate or
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * deactivate the current NCU)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - it supports checking/activation of a particular priority group in
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the active NCP. This works as follows:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Count up numbers of exclusive, shared and all NCUs, and how many of each
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * are online. If an NCU is waiting for IP address to be assigned, it is
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * also considered online. If activate_or_deactivate is true, we also
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * either activate (if activate is true) or deactivate prioritized NCUs
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * that are offline or online.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncu_check_or_activate(nwamd_object_t object, void *data)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ncu_check_walk_arg *wa = data;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_t *ncu;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t priority_group, priority_mode;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_t if_obj;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_state_t state, if_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_aux_state_t aux_state, if_aux_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char *name;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey state = object->nwamd_object_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey aux_state = object->nwamd_object_aux_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name = object->nwamd_object_name;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey ncu = object->nwamd_object_data;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* skip NCUs in UNINITIALIZED state */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_UNINITIALIZED) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "skipping uninitialized ncu %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!wa->manual && wa->priority_group == INVALID_PRIORITY_GROUP)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (ncu->ncu_type != NWAM_NCU_TYPE_LINK) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "skipping interface NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!wa->manual && ncu->ncu_node.u_link.nwamd_link_activation_mode !=
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_ACTIVATION_MODE_PRIORITIZED) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "skipping non-prioritized NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->manual && ncu->ncu_node.u_link.nwamd_link_activation_mode !=
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_ACTIVATION_MODE_MANUAL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "skipping non-manual NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey priority_group = ncu->ncu_node.u_link.nwamd_link_priority_group;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey priority_mode = ncu->ncu_node.u_link.nwamd_link_priority_mode;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Only work with NCUs in the requested priority-group */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!wa->manual && priority_group != wa->priority_group) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "skipping NCU %s in different priority-group", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Get the state of the corresponding interface NCU */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((if_obj = nwamd_ncu_object_find(NWAM_NCU_TYPE_INTERFACE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey ncu->ncu_name)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "interface NCU of %s not found, skipping", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_state = if_obj->nwamd_object_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_aux_state = if_obj->nwamd_object_aux_state;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_release(if_obj);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: %s ncu %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->activate_or_deactivate ?
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (wa->activate ? "activating" : "deactivating") :
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "checking", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->manual) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_OFFLINE && ncu->ncu_enabled) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "moving NCU %s to offline* from offline",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_OFFLINE_TO_ONLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_INITIALIZED);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state != NWAM_STATE_DISABLED &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey !ncu->ncu_enabled) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "moving NCU %s to online* (disabling)",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_ONLINE_TO_OFFLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_MANUAL_DISABLE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey switch (priority_mode) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_PRIORITY_MODE_EXCLUSIVE:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->exclusive_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_ONLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (if_state == NWAM_STATE_ONLINE ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_aux_state == NWAM_AUX_STATE_IF_WAITING_FOR_ADDR))
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->exclusive_online_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * For exclusive NCUs, we activate offline NCUs as long
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * as no other exclusive NCUs are active.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_OFFLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->exclusive_online_ncus == 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "moving NCU %s to offline* from offline",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_OFFLINE_TO_ONLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_INITIALIZED);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && !wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (aux_state != NWAM_AUX_STATE_CONDITIONS_NOT_MET) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "deactivating NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_ONLINE_TO_OFFLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_CONDITIONS_NOT_MET);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If we are activating or checking the priority group and
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * too many exclusive NCUs are online, take this NCU down.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((wa->activate_or_deactivate && wa->activate) ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey !wa->activate_or_deactivate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_ONLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_state == NWAM_STATE_ONLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->exclusive_online_ncus > 1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "moving NCU %s to online* since another "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "NCU is already active",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_ONLINE_TO_OFFLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_CONDITIONS_NOT_MET);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_PRIORITY_MODE_SHARED:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->shared_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_ONLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (if_state == NWAM_STATE_ONLINE ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_aux_state == NWAM_AUX_STATE_IF_WAITING_FOR_ADDR))
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->shared_online_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_OFFLINE) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "activating NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_OFFLINE_TO_ONLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_INITIALIZED);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && !wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (aux_state != NWAM_AUX_STATE_CONDITIONS_NOT_MET) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "deactivating NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_ONLINE_TO_OFFLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_CONDITIONS_NOT_MET);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey case NWAM_PRIORITY_MODE_ALL:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->all_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_ONLINE &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (if_state == NWAM_STATE_ONLINE ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if_aux_state == NWAM_AUX_STATE_IF_WAITING_FOR_ADDR))
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->all_online_ncus++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * For "all" NCUs, activate/deactivate all offline/online
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * NCUs.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (state == NWAM_STATE_OFFLINE) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "activating NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_OFFLINE_TO_ONLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_INITIALIZED);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa->activate_or_deactivate && !wa->activate) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (aux_state != NWAM_AUX_STATE_CONDITIONS_NOT_MET) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "deactivating NCU %s", name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_object_set_state(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey name, NWAM_STATE_ONLINE_TO_OFFLINE,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NWAM_AUX_STATE_CONDITIONS_NOT_MET);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey default:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncu_check_or_activate: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "invalid priority-mode");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey break;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_activate_priority_group(int64_t priority)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ncu_check_walk_arg wa;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_t check_event, priority_event;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority == INVALID_PRIORITY_GROUP)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority == current_ncu_priority_group) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_activate_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "activating priority group %lld", priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.manual = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.priority_group = priority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.exclusive_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.exclusive_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.shared_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.shared_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.all_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.all_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate_or_deactivate = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_check_or_activate, &wa) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_activate_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "nwamd_walk_objects() failed");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Enqueue event to update current_ncu_priority_group and send to
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * any event listeners.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey priority_event = nwamd_event_init_priority_group_change(priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority_event == NULL)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_enqueue(priority_event);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Now we've activated a new priority group, enqueue an event
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * to check up on the state of this priority group.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey check_event = nwamd_event_init_ncu_check();
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (check_event == NULL)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_enqueue_timed(check_event, ncu_wait_time);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_deactivate_priority_group(int64_t priority)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ncu_check_walk_arg wa;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority == INVALID_PRIORITY_GROUP)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_deactivate_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "deactivating priority group %lld", priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.manual = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.priority_group = priority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.exclusive_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.exclusive_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.shared_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.shared_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.all_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.all_online_ncus = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate_or_deactivate = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_check_or_activate, &wa) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_deactivate_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "nwamd_walk_objects() failed");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * This function deactivates all priority groups at level 'priority' and lower
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * (which is, numerically, all priorities >= priority).
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_deactivate_priority_group_all(int64_t priority)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (priority == INVALID_PRIORITY_GROUP)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_deactivate_priority_group_all: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "deactivating priority group less than or equal to %lld", priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey do {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncp_deactivate_priority_group(priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } while (nwamd_ncp_find_next_priority_group(priority + 1, &priority));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns 'true' if it found the highest priority group no higher then what
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * is passed that should be activated and sets *priority to that.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyboolean_t
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_check_priority_group(int64_t *priority)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ncu_check_walk_arg wa;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t conditions_met = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_check_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "checking priority group %lld", *priority);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (*priority == INVALID_PRIORITY_GROUP) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!nwamd_ncp_find_next_priority_group(0, priority))
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey while (!conditions_met) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) memset(&wa, 0, sizeof (wa));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.manual = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.priority_group = *priority;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate_or_deactivate = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_check_or_activate, &wa) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_check_priority_group: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "nwamd_walk_objects() failed");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Are activation conditons satisifed? In other words:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - exactly one of the exclusive NCUs is online
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - 1 or more shared NCUs are online
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - all of the all NCUs are online.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If any of these is untrue, conditions are not satisfied.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey conditions_met = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa.exclusive_ncus > 0 && wa.exclusive_online_ncus != 1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey conditions_met = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa.shared_ncus > 0 && wa.shared_online_ncus == 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey conditions_met = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa.all_ncus > 0 && wa.all_ncus != wa.all_online_ncus)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey conditions_met = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (wa.exclusive_online_ncus == 0 &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.shared_online_ncus == 0 && wa.all_online_ncus == 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey conditions_met = B_FALSE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (conditions_met) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_TRUE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } else {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If there is a next pg, activate it. If not, do
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * nothing - we're stuck here unless an event occurs
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * for our or a higher pg.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!nwamd_ncp_find_next_priority_group
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (wa.priority_group + 1, priority)) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "ran out of prio groups");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_ncp_activate_manual_ncus(void)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ncu_check_walk_arg wa;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_ncp_activate_manual_ncus: activating NCUs");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.manual = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate_or_deactivate = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa.activate = B_TRUE;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_check_or_activate, &wa) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_ncp_activate_manual_ncus: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "nwamd_walk_objects() failed");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_create_ncu_check_event(uint64_t when)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_t check_event = nwamd_event_init_ncu_check();
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (check_event != NULL)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_enqueue_timed(check_event, when);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}