1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/*
*
* (C) Copyright IBM Corp. 2001, 2003
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: container.c
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "fullengine.h"
#include "container.h"
#include "lists.h"
#include "engine.h"
#include "discover.h"
#include "handlemgr.h"
#include "common.h"
#include "internalAPI.h"
#include "object.h"
#include "message.h"
#include "memman.h"
#include "remote.h"
int evms_create_container(plugin_handle_t plugin_handle,
handle_array_t * input_objects,
option_array_t * options,
object_handle_t * new_container_handle) {
int rc = 0;
void * object;
object_type_t type;
LOG_PROC_ENTRY();
rc = check_engine_write_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_create_container(plugin_handle, input_objects, options, new_container_handle);
LOG_PROC_EXIT_INT(rc);
return rc;
}
rc = translate_handle(plugin_handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == PLUGIN) {
plugin_record_t * pPlugRec = (plugin_record_t *) object;
/* Make sure the plug-in does containers. */
if (pPlugRec->container_functions != NULL) {
STATIC_LIST_DECL(object_list);
rc = make_list(input_objects, &object_list);
if (rc == 0) {
list_element_t iter;
storage_object_t * obj;
storage_container_t * disk_group = NULL;
obj = first_thing(&object_list, NULL);
if (obj != NULL) {
disk_group = obj->disk_group;
}
/*
* Make sure that the input object list contains
* top level objects and none of them insist on
* being a top object.
*/
LIST_FOR_EACH(&object_list, iter, obj) {
rc = isa_valid_input_object(obj, disk_group);
}
if (rc == 0) {
storage_container_t * new_container;
rc = pPlugRec->container_functions->create_container(&object_list, options, &new_container);
if (rc == 0) {
storage_object_t * child_obj = NULL;
/*
* Now that the objects are consumed
* any stop data on them can be
* overwritten.
*/
LIST_FOR_EACH(new_container->objects_consumed, iter, child_obj) {
child_obj->flags &= ~SOFLAG_HAS_STOP_DATA;
}
if (new_container->disk_group != NULL) {
propigate_cluster_info(new_container->objects_produced);
}
sort_list(&containers_list, compare_containers, NULL);
switch (GetPluginType(pPlugRec->id)) {
case EVMS_DEVICE_MANAGER:
sort_list(&disks_list, compare_objects, NULL);
break;
case EVMS_SEGMENT_MANAGER:
sort_list(&segments_list, compare_objects, NULL);
break;
case EVMS_REGION_MANAGER:
sort_list(®ions_list, compare_objects, NULL);
break;
case EVMS_FEATURE:
case EVMS_ASSOCIATIVE_FEATURE:
sort_list(&EVMS_objects_list, compare_objects, NULL);
break;
default:
break;
}
rc = create_handle(new_container,
CONTAINER,
&new_container->app_handle);
if (rc == 0) {
*new_container_handle = new_container->app_handle;
} else {
LOG_WARNING("Error %d creating a handle for container %s.\n", rc, new_container->name);
}
}
}
}
}
} else {
LOG_ERROR("handle is not for a plug-in.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
* evms_get_container_list returns a pointer to a handle_array_t with handles for
* storage containers, optionally filtering on the region manager that manages
* the container. If the object handle for the region manager is 0, handles for
* all of the storage containers will be returned.
*/
int evms_get_container_list(object_handle_t plugin_handle,
object_handle_t disk_group_handle,
container_search_flags_t flags,
handle_array_t * * container_handle_list) {
int rc = 0;
void * object = NULL;
object_type_t type;
plugin_record_t * pPlugRec = NULL;
storage_container_t * disk_group = NULL;
handle_array_t * container_handles;
LOG_PROC_ENTRY();
rc = check_engine_read_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_get_container_list(plugin_handle, disk_group_handle, flags, container_handle_list);
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (plugin_handle != 0) {
/* Translate the handle for the region manager to make sure it is valid */
/* and to get the plugin_record_t for the region manager. */
rc = translate_handle(plugin_handle,
&object,
&type);
if (rc == HANDLE_MANAGER_NO_ERROR) {
if (type == PLUGIN) {
pPlugRec = (plugin_record_t *) object;
} else {
rc = EINVAL;
}
}
}
if (disk_group_handle != 0) {
/*
* Translate the handle for the disk group to make sure
* it is valid and to get the disk group
* storage_container_t.
*/
rc = translate_handle(disk_group_handle,
&object,
&type);
if (rc == HANDLE_MANAGER_NO_ERROR) {
if (type == CONTAINER) {
disk_group = (storage_container_t *) object;
} else {
rc = EINVAL;
}
}
}
if (rc == 0) {
list_anchor_t container_list;
rc = engine_get_container_list(pPlugRec, disk_group, flags, &container_list);
if (rc == 0) {
rc = make_handle_array(container_list, &container_handles);
}
if (rc == 0) {
uint size = sizeof(handle_array_t) + (sizeof(object_handle_t) * container_handles->count);
*container_handle_list = alloc_app_struct(size, NULL);
if (*container_handle_list != NULL) {
/* Fill in the structure returned to the app. */
memcpy(*container_handle_list, container_handles, size);
/*
* Free the internal handle array.
*/
engine_free(container_handles);
} else {
rc = ENOMEM;
}
}
/* We are finished with the list that was returned by */
/* engine_get_container_list(). */
destroy_list(container_list);
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
|