brand.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * CDDL HEADER START
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * The contents of this file are subject to the terms of the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Common Development and Distribution License (the "License").
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * You may not use this file except in compliance with the License.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * See the License for the specific language governing permissions
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * and limitations under the License.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * When distributing Covered Code, include this CDDL HEADER in each
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * If applicable, add the following below this CDDL HEADER, with the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * fields enclosed by brackets "[]" replaced with your own identifying
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * information: Portions Copyright [yyyy] [name of copyright owner]
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * CDDL HEADER END
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Use is subject to license terms.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn#pragma ident "%Z%%M% %I% %E% SMI"
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn#if defined(__sparcv9)
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Used to maintain a list of all the brands currently loaded into the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * This lock protects the integrity of the brand list.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "Branded zones are not allowed on labeled systems.");
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "brand '%s' was built to run on older versions "
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "of Solaris.",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "brand '%s' was built to run on a newer version "
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "of Solaris.",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Sanity checks */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Add the brand to the list of loaded brands. */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Check to be sure we haven't already registered this brand.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (scan = brand_list; scan != NULL; scan = scan->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn if (strcmp(brand->b_name, scan->bl_brand->b_name) == 0) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "Invalid attempt to load a second instance of "
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn return (0);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * The kernel module implementing this brand is being unloaded, so remove
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * it from the list of active brands.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Sanity checks */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (list = brand_list; list != NULL; list = list->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn cmn_err(CE_WARN, "Brand %s wasn't registered", brand->b_name);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn cmn_err(CE_WARN, "Unregistering brand %s which is still in use",
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn /* Remove brand from the list */
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn return (0);
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Record that a zone of this brand has been instantiated. If the kernel
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * module implementing this brand's functionality is not present, this
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * routine attempts to load the module as a side effect.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn "Branded zones are not allowed on labeled systems.");
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We make at most two passes through this loop. The first time
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * through, we're looking to see if this is a new user of an
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * already loaded brand. If the brand hasn't been loaded, we
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * call ddi_modopen() to force it to be loaded and then make a
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * second pass through the list of brands. If we don't find the
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * brand the second time through it means that the modname
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * specified in the brand_attr structure doesn't provide the brand
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * specified in the brandname field. This would suggest a bug in
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * the brand's config.xml file. We close the module and return
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * 'NULL' to the caller.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (;;) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Search list of loaded brands
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We didn't find that the requested brand has been loaded
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * yet, so we trigger the load of the appropriate kernel
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * module and search the list again.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * If we found the matching brand, bump its reference count.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * Return the number of zones currently using this brand.
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn for (list = brand_list; list != NULL; list = list->bl_next) {
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * We should only be called from exec(), when we know the process
9acbbeaf2a1ffe5c14b244867d427714fab43c5cnn * is single-threaded.