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 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <libintl.h> 30 #include "volume_request.h" 31 #include "volume_error.h" 32 33 /* 34 * Methods which manipulate a request_t struct 35 */ 36 37 /* 38 * Constructor: Create a request_t struct. This request_t must be 39 * freed. 40 * 41 * @param request 42 * RETURN: a pointer to a new request_t 43 * 44 * @return 0 45 * if successful 46 * 47 * @return non-zero 48 * if an error occurred. Use get_error_string() to 49 * retrieve the associated error message. 50 */ 51 int 52 new_request( 53 request_t **request) 54 { 55 int error; 56 devconfig_t *diskset_req; 57 devconfig_t *diskset_config; 58 59 *request = (request_t *)calloc(1, sizeof (request_t)); 60 if (*request == NULL) { 61 (void) volume_set_error(gettext("new_request calloc() failed\n")); 62 return (-1); 63 } 64 65 /* Create a new diskset_req */ 66 if ((error = new_devconfig(&diskset_req, TYPE_DISKSET)) != 0) { 67 free_request(*request); 68 return (error); 69 } 70 request_set_diskset_req(*request, diskset_req); 71 72 /* Create a new diskset_config */ 73 if ((error = new_devconfig(&diskset_config, TYPE_DISKSET)) != 0) { 74 free_request(*request); 75 return (error); 76 } 77 request_set_diskset_config(*request, diskset_config); 78 79 return (0); 80 } 81 82 /* 83 * Free memory (recursively) allocated to a request_t struct 84 * 85 * @param arg 86 * pointer to the request_t struct to free 87 */ 88 void 89 free_request( 90 void *arg) 91 { 92 request_t *request = (request_t *)arg; 93 94 if (request == NULL) { 95 return; 96 } 97 98 /* Free the diskset_req */ 99 if (request->diskset_req != NULL) { 100 free_devconfig(request->diskset_req); 101 } 102 103 /* Free the diskset_config */ 104 if (request->diskset_config != NULL) { 105 free_devconfig(request->diskset_config); 106 } 107 108 /* Free the devconfig itself */ 109 free(request); 110 } 111 112 /* 113 * Set the disk set at the top of the request hierarchy 114 * 115 * @param request 116 * The request_t representing the request to modify 117 * 118 * @param diskset 119 * The devconfig_t representing the toplevel (disk set) 120 * device in the volume request hierarchy 121 */ 122 void 123 request_set_diskset_req( 124 request_t *request, 125 devconfig_t *diskset) 126 { 127 request->diskset_req = diskset; 128 } 129 130 /* 131 * Get the disk set at the top of the request hierarchy 132 * 133 * @param request 134 * The request_t representing the request to examine 135 * 136 * @return The devconfig_t representing the toplevel (disk set) 137 * device in the volume request hierarchy 138 */ 139 devconfig_t * 140 request_get_diskset_req( 141 request_t *request) 142 { 143 return (request->diskset_req); 144 } 145 146 /* 147 * Set/get the disk set at the top of the proposed volume hierarchy 148 * 149 * @param request 150 * The request_t representing the request to modify 151 * 152 * @param diskset 153 * The devconfig_t representing the toplevel (disk set) 154 * device in the proposed volume hierarchy 155 */ 156 void 157 request_set_diskset_config( 158 request_t *request, 159 devconfig_t *diskset) 160 { 161 request->diskset_config = diskset; 162 } 163 164 /* 165 * Get the disk set at the top of the request hierarchy 166 * 167 * @param request 168 * The request_t representing the request to examine 169 * 170 * @return The devconfig_t representing the toplevel (disk set) 171 * device in the proposed volume hierarchy 172 */ 173 devconfig_t * 174 request_get_diskset_config( 175 request_t *request) 176 { 177 return (request->diskset_config); 178 } 179