1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _LAYOUT_DEVICE_CACHE_H 28 #define _LAYOUT_DEVICE_CACHE_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * This module manages cached copies of a dm_descriptor_t's nvpair 38 * list of attributes and its device name. The caches are used to 39 * make sure that the memory allocated to these objects is correctly 40 * released after the layout process has finished. The cached attrs 41 * also allow the layout code to store and retrieve transient, 42 * layout-private data in the same data structure as the other 43 * relevant device information. 44 * 45 * There are two primary caches of information: 46 * 47 * descriptor->name - which maps a dm_descriptor_t handle to 48 * the associated device's name 49 * 50 * name->attributes - which maps a device name to an nvlist_t 51 * attribute collection. 52 * 53 * These two data structures thus allow the following lookup chain: 54 * descriptor->name->attributes. 55 * 56 * The attributes are accessed by device name because the it is the 57 * unique identifier for the device. The descriptor returned by 58 * libdiskmgt is just an arbitrary handle, multiple calls into the 59 * library may return different descriptors for the same device. 60 * 61 * Descriptors are also get re-cycled by the library which could 62 * result in the same descriptor being used to represent different 63 * devices (although not concurrently). To prevent such recycling 64 * all of the descriptors are held until the layout process has 65 * completed. 66 * 67 * Performance testing indicated that searching the lists of known 68 * devices by display (CTD or DID) name or alias was a significant 69 * bottleneck. A mapping from display name to descriptor was added 70 * to address this. 71 * 72 * The module should be initialized once by calling create_device_caches() 73 * prior to any call which accesses data maintained by the cache. 74 * 75 * The caches should be flushed after all accesses have completed by 76 * calling release_device_caches. 77 */ 78 79 #include "libdiskmgt.h" 80 #include "layout_device_util.h" 81 82 extern int create_device_caches(); 83 extern int release_device_caches(); 84 85 extern int add_cached_descriptor(char *name, dm_descriptor_t desc); 86 extern dm_descriptor_t find_cached_descriptor(char *name); 87 88 extern int add_cached_name(dm_descriptor_t desc, char *name); 89 extern int get_name(dm_descriptor_t desc, char **name); 90 91 extern int add_cached_attributes(char *name, nvlist_t *attrs); 92 extern int get_cached_attributes(dm_descriptor_t desc, nvlist_t **list); 93 94 extern int new_descriptor(dm_descriptor_t *desc); 95 extern int add_descriptors_to_free(dm_descriptor_t *desc_list); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif /* _LAYOUT_DEVICE_CACHE_H */ 102