Print this page
11929 mac_minor_hold() gets id_alloc_nosleep() wrong


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2017, Joyent, Inc.
  25  * Copyright 2015 Garrett D'Amore <garrett@damore.org>
  26  */
  27 
  28 /*
  29  * MAC Services Module
  30  *
  31  * The GLDv3 framework locking -  The MAC layer
  32  * --------------------------------------------
  33  *
  34  * The MAC layer is central to the GLD framework and can provide the locking
  35  * framework needed for itself and for the use of MAC clients. MAC end points
  36  * are fairly disjoint and don't share a lot of state. So a coarse grained
  37  * multi-threading scheme is to single thread all create/modify/delete or set
  38  * type of control operations on a per mac end point while allowing data threads
  39  * concurrently.
  40  *
  41  * Control operations (set) that modify a mac end point are always serialized on
  42  * a per mac end point basis, We have at most 1 such thread per mac end point
  43  * at a time.
  44  *


2270 void
2271 mac_client_quiesce(mac_client_impl_t *mcip)
2272 {
2273         mac_rx_client_quiesce((mac_client_handle_t)mcip);
2274         mac_tx_client_quiesce((mac_client_handle_t)mcip);
2275 }
2276 
2277 void
2278 mac_client_restart(mac_client_impl_t *mcip)
2279 {
2280         mac_rx_client_restart((mac_client_handle_t)mcip);
2281         mac_tx_client_restart((mac_client_handle_t)mcip);
2282 }
2283 
2284 /*
2285  * Allocate a minor number.
2286  */
2287 minor_t
2288 mac_minor_hold(boolean_t sleep)
2289 {
2290         minor_t minor;
2291 
2292         /*
2293          * Grab a value from the arena.
2294          */
2295         atomic_inc_32(&minor_count);
2296 
2297         if (sleep)
2298                 minor = (uint_t)id_alloc(minor_ids);
2299         else
2300                 minor = (uint_t)id_alloc_nosleep(minor_ids);
2301 
2302         if (minor == 0) {
2303                 atomic_dec_32(&minor_count);
2304                 return (0);
2305         }
2306 
2307         return (minor);
2308 }
2309 
2310 /*
2311  * Release a previously allocated minor number.
2312  */
2313 void
2314 mac_minor_rele(minor_t minor)
2315 {
2316         /*
2317          * Return the value to the arena.
2318          */
2319         id_free(minor_ids, minor);
2320         atomic_dec_32(&minor_count);
2321 }
2322 
2323 uint32_t
2324 mac_no_notification(mac_handle_t mh)
2325 {
2326         mac_impl_t *mip = (mac_impl_t *)mh;
2327 




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2019 Joyent, Inc.
  25  * Copyright 2015 Garrett D'Amore <garrett@damore.org>
  26  */
  27 
  28 /*
  29  * MAC Services Module
  30  *
  31  * The GLDv3 framework locking -  The MAC layer
  32  * --------------------------------------------
  33  *
  34  * The MAC layer is central to the GLD framework and can provide the locking
  35  * framework needed for itself and for the use of MAC clients. MAC end points
  36  * are fairly disjoint and don't share a lot of state. So a coarse grained
  37  * multi-threading scheme is to single thread all create/modify/delete or set
  38  * type of control operations on a per mac end point while allowing data threads
  39  * concurrently.
  40  *
  41  * Control operations (set) that modify a mac end point are always serialized on
  42  * a per mac end point basis, We have at most 1 such thread per mac end point
  43  * at a time.
  44  *


2270 void
2271 mac_client_quiesce(mac_client_impl_t *mcip)
2272 {
2273         mac_rx_client_quiesce((mac_client_handle_t)mcip);
2274         mac_tx_client_quiesce((mac_client_handle_t)mcip);
2275 }
2276 
2277 void
2278 mac_client_restart(mac_client_impl_t *mcip)
2279 {
2280         mac_rx_client_restart((mac_client_handle_t)mcip);
2281         mac_tx_client_restart((mac_client_handle_t)mcip);
2282 }
2283 
2284 /*
2285  * Allocate a minor number.
2286  */
2287 minor_t
2288 mac_minor_hold(boolean_t sleep)
2289 {
2290         id_t id;
2291 
2292         /*
2293          * Grab a value from the arena.
2294          */
2295         atomic_inc_32(&minor_count);
2296 
2297         if (sleep)
2298                 return ((uint_t)id_alloc(minor_ids));


2299 
2300         if ((id = id_alloc_nosleep(minor_ids)) == -1) {
2301                 atomic_dec_32(&minor_count);
2302                 return (0);
2303         }
2304 
2305         return ((uint_t)id);
2306 }
2307 
2308 /*
2309  * Release a previously allocated minor number.
2310  */
2311 void
2312 mac_minor_rele(minor_t minor)
2313 {
2314         /*
2315          * Return the value to the arena.
2316          */
2317         id_free(minor_ids, minor);
2318         atomic_dec_32(&minor_count);
2319 }
2320 
2321 uint32_t
2322 mac_no_notification(mac_handle_t mh)
2323 {
2324         mac_impl_t *mip = (mac_impl_t *)mh;
2325