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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
|
/*
* (C) Copyright IBM Corp. 2004
*
* 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: Multipath Plugin
* File: evms2/engine/plugins/multipath/multipath.c
*
* This is the generic EVMS multipath plugin. It is intended to detect and
* activate multipath devices based on multiple types of metadata (and even
* without metadata). It utilizes the multipath module in Device-Mapper.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <plugin.h>
#include "multipath.h"
/* Pointer to engine-services table. */
engine_functions_t *EngFncs;
/**
* mp_modules
*
* Array of multipath sub-modules. Index into this array using a
* multipath_type_t value.
**/
multipath_module_t mp_modules[] = {
{ .name = "lvm",
.setup = mp_lvm_setup,
.cleanup = mp_lvm_cleanup,
.probe = mp_lvm_probe,
.process = mp_lvm_process,
.allocate = mp_lvm_allocate,
.discard = mp_lvm_discard,
.delete = mp_lvm_delete,
.map = mp_lvm_map,
.build_targets= mp_lvm_build_targets,
},
};
/**
* multipath_setup_evms_plugin
*
* Perform all setup when the plugin is loaded.
**/
static int multipath_setup_evms_plugin(engine_functions_t *functions)
{
int rc, i;
EngFncs = functions;
LOG_ENTRY();
/* Setup each sub-module. */
for (i = 0; i < MULTIPATH_TYPE_MAX; i++) {
rc = mp_modules[i].setup();
if (rc) {
goto out;
}
}
/* Register the base namespace. */
rc = EngFncs->register_name(MP_NAME);
if (rc) {
goto out;
}
out:
if (rc) {
for (; i >= 0; i--) {
mp_modules[i].cleanup();
}
EngFncs->unregister_name(MP_NAME);
}
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_cleanup_evms_plugin
*
* Cleanup the plugin when the engine closes.
**/
static void multipath_cleanup_evms_plugin(void)
{
int i;
LOG_ENTRY();
/* Cleanup each sub-module and release the namespace. */
for (i = 0; i < MULTIPATH_TYPE_MAX; i++) {
mp_modules[i].cleanup();
}
EngFncs->unregister_name(MP_NAME);
LOG_EXIT_VOID();
}
/**
* multipath_can_delete
**/
static int multipath_can_delete(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_can_unassign
*
* Just like can_delete().
**/
static int multipath_can_unassign(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(ENOSYS);
return ENOSYS;
}
/**
* multipath_can_set_volume
*
* We aren't yet going to support volumes directly on MP objects, since
* we're initially targetting this for LVM MP-PVs.
**/
static int multipath_can_set_volume(storage_object_t *object, boolean flag)
{
LOG_ENTRY();
LOG_EXIT_INT(EINVAL);
return EINVAL;
}
/**
* multipath_discover
*
* Probe all input objects for multipath metadata and create new segments as
* necessary.
**/
static int multipath_discover(list_anchor_t input_objects,
list_anchor_t output_objects,
boolean final_call)
{
storage_object_t *child;
list_element_t itr;
int i, rc, count = 0;
LOG_ENTRY();
LIST_FOR_EACH(input_objects, itr, child) {
/* Only interested in DATA objects. */
if (child->data_type != DATA_TYPE) {
LOG_DEBUG("%s is not a DATA object.\n", child->name);
EngFncs->insert_thing(output_objects, child, 0, NULL);
continue;
}
/* Don't re-examine multipath objects. */
if (child->plugin == &multipath_plugin) {
LOG_DEBUG("%s is a multipath object.\n", child->name);
EngFncs->insert_thing(output_objects, child, 0, NULL);
continue;
}
/* Give each sub-module a chance to see if they recognize
* this object. If they do, they'll put it on an internal
* list to be processed later in discovery.
*/
for (i = 0; i < MULTIPATH_TYPE_MAX; i++) {
rc = mp_modules[i].probe(child);
if (!rc) {
break;
}
}
if (i == MULTIPATH_TYPE_MAX) {
/* If nobody recognizes it, put it on the output list. */
EngFncs->insert_thing(output_objects, child, 0, NULL);
}
}
/* Now process each type-specific list to actually construct the
* multipath segments.
*/
for (i = 0; i < MULTIPATH_TYPE_MAX; i++) {
count += mp_modules[i].process(output_objects);
}
if (final_call) {
cleanup_stale_daemons();
}
LOG_EXIT_INT(count);
return count;
}
/**
* multipath_discard
*
* Forget about these objects. Don't delete them. Just clean up any data
* structures you may have associated with them. The Engine will call to
* deactivate the objects during commit.
*
* Since we need part of the private data to properly deactivate, we should
* only free it if the object is not active (and hence doesn't need to be
* deactivated). If the object is active, we'll free the private-data after
* deactivation.
**/
static int multipath_discard(list_anchor_t objects)
{
storage_object_t *object;
list_element_t itr;
multipath_t *mp;
LOG_ENTRY();
LIST_FOR_EACH(objects, itr, object) {
mp = object->private_data;
mp_modules[mp->type].discard(object);
if (!(object->flags & SOFLAG_ACTIVE)) {
EngFncs->engine_free(mp);
object->private_data = NULL;
} else {
mp->flags |= MP_FLAG_DELETE_PRIVATE_DATA;
}
EngFncs->free_segment(object);
}
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_delete
*
* Delete this segment. Erase all necessary metadata and free up the private
* data structures.
*
* Since we need part of the private data to properly deactivate, we should
* only free it if the object is not active (and hence doesn't need to be
* deactivated). If the object is active, we'll free the private-data after
* deactivation.
**/
static int multipath_delete(storage_object_t *object,
list_anchor_t child_objects)
{
multipath_t *mp = object->private_data;
LOG_ENTRY();
EngFncs->concatenate_lists(child_objects, object->child_objects);
mp_modules[mp->type].delete(object);
if (!(object->flags & SOFLAG_ACTIVE)) {
EngFncs->engine_free(mp);
object->private_data = NULL;
} else {
mp->flags |= MP_FLAG_DELETE_PRIVATE_DATA;
}
EngFncs->free_segment(object);
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_unassign
*
* Don't support unassign yet.
**/
static int multipath_unassign(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(ENOSYS);
return ENOSYS;
}
/**
* multipath_add_sectors_to_kill_list
*
* Send the kill-sectors command to one of the child objects.
**/
static int multipath_add_sectors_to_kill_list(storage_object_t *object,
lsn_t lsn, sector_count_t count)
{
multipath_t *mp = object->private_data;
int rc = EIO;
LOG_ENTRY();
rc = mp_modules[mp->type].map(&object, &lsn, &count);
if (!rc) {
rc = KILL_SECTORS(object, lsn, count);
}
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_commit_changes
*
* Nothing to do yet for commit, since we don't yet have any metadata.
**/
static int multipath_commit_changes(storage_object_t *object,
commit_phase_t phase)
{
LOG_ENTRY();
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_can_activate
*
* Multipath segments can always be activated.
**/
static int multipath_can_activate(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_activate
*
* Activate this multipath segment using Device-Mapper.
**/
static int multipath_activate(storage_object_t *object)
{
int rc;
LOG_ENTRY();
rc = stop_daemon(object);
if (rc) {
goto out;
}
rc = activate_segment(object);
if (rc) {
goto out;
}
rc = start_daemon(object);
if (rc) {
goto out;
}
object->flags &= ~SOFLAG_NEEDS_ACTIVATE;
out:
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_can_deactivate
*
* Multipath segments can always be deactivated.
**/
static int multipath_can_deactivate(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(0);
return 0;
}
/**
* multipath_deactivate
*
* Deactivation will only happen when the segment has been deleted or
* discarded. Since we need part of the private-data to do the deactivation,
* we need to free that private-data once we're done with it.
**/
static int multipath_deactivate(storage_object_t *object)
{
multipath_t *mp = object->private_data;
int rc;
LOG_ENTRY();
stop_daemon(object);
rc = EngFncs->dm_deactivate(object);
if (!rc) {
object->flags &= ~SOFLAG_NEEDS_DEACTIVATE;
if (mp->flags & MP_FLAG_DELETE_PRIVATE_DATA) {
/* If this deactivate is due to deleting or discarding
* the segment, we need to delete the private data.
*/
EngFncs->engine_free(mp);
}
}
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_get_info
*
* Return any additional information that you wish to provide about the object.
* The Engine provides an external API to get the information stored in the
* storage_object_t. This call is to get any other information about the object
* that is not specified in the storage_object_t. Any piece of information you
* wish to provide must be in an extended_info_t structure. Use the Engine's
* engine_alloc() to allocate the memory for the extended_info_t. Also use
* engine_alloc() to allocate any strings that may go into the extended_info_t.
* Then use engine_alloc() to allocate an extended_info_array_t with enough
* entries for the number of extended_info_t structures you are returning. Fill
* in the array and return it in *info.
*
* If you have extended_info_t descriptors that themselves may have more
* extended information, set the EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE flag in
* the extended_info_t flags field. If the caller wants more information about
* a particular extended_info_t item, this API will be called with a pointer to
* the storage_object_t and with a pointer to the name of the extended_info_t
* item. In that case, return an extended_info_array_t with further information
* about the item. Each of those items may have the
* EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE flag set if you desire. It is your
* responsibility to give the items unique names so that you know which item the
* caller is asking additional information for. If info_name is NULL, the caller
* just wants top level information about the object.
*
* Return:
* - 0 for success.
* - Non-zero error-code for failure.
*
* OPTIONAL
**/
static int multipath_get_info(storage_object_t *object,
char *info_name,
extended_info_array_t **info)
{
LOG_ENTRY();
LOG_EXIT_INT(ENOSYS);
return ENOSYS;
}
/**
* multipath_get_plugin_info
*
* Return any additional information that you wish to provide about your plugin.
* The Engine provides an external API to get the information stored in the
* plugin_record_t. This call is to get any other information about the plugin
* that is not specified in the plugin_record_t. Any piece of information you
* wish to provide must be in an extended_info_t structure. Use the Engine's
* engine_alloc() to allocate the memory for the extended_info_t. Also use
* engine_alloc() to allocate any strings that may go into the extended_info_t.
* Then use engine_alloc() to allocate an extended_info_array_t with enough
* entries for the number of extended_info_t structures you are returning. Fill
* in the array and return it in *info.
*
* If you have extended_info_t descriptors that themselves may have more
* extended information, set the EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE flag in
* the extended_info_t flags field. If the caller wants more information about
* a particular extended_info_t item, this API will be called with a pointer to
* the name of the extended_info_t item. In that case, return an
* extended_info_array_t with further information about the item. Each of those
* items may have the EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE flag set if you
* desire. It is your responsibility to give the items unique names so that you
* know which item the caller is asking additional information for. If
* info_name is NULL, the caller just wants top level information about the
* plugin.
*
* Return:
* - 0 for success.
* - Non-zero error-code for failure.
*
* OPTIONAL
**/
static int multipath_get_plugin_info(char *info_name,
extended_info_array_t **info)
{
LOG_ENTRY();
LOG_EXIT_INT(ENOSYS);
return ENOSYS;
}
/**
* multipath_read
*
* Read from one of the child objects.
**/
static int multipath_read(storage_object_t *object, lsn_t lsn,
sector_count_t count, void *buffer)
{
multipath_t *mp = object->private_data;
int rc;
LOG_ENTRY();
rc = mp_modules[mp->type].map(&object, &lsn, &count);
if (!rc) {
rc = READ(object, lsn, count, buffer);
}
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_write
*
* Write to one of the child objects.
**/
static int multipath_write(storage_object_t *object, lsn_t lsn,
sector_count_t count, void *buffer)
{
multipath_t *mp = object->private_data;
int rc;
LOG_ENTRY();
rc = mp_modules[mp->type].map(&object, &lsn, &count);
if (!rc) {
rc = WRITE(object, lsn, count, buffer);
}
LOG_EXIT_INT(rc);
return rc;
}
/**
* multipath_backup_metadata
*
* Nothing to do yet for backup, since we don't yet have any metadata.
**/
static int multipath_backup_metadata(storage_object_t *object)
{
LOG_ENTRY();
LOG_EXIT_INT(0);
return 0;
}
/* Plugin-Functions table for the Multipath plugin. */
static plugin_functions_t multipath_functions = {
.setup_evms_plugin = multipath_setup_evms_plugin,
.cleanup_evms_plugin = multipath_cleanup_evms_plugin,
.can_delete = multipath_can_delete,
.can_unassign = multipath_can_unassign,
.can_set_volume = multipath_can_set_volume,
.discover = multipath_discover,
.discard = multipath_discard,
.delete = multipath_delete,
.unassign = multipath_unassign,
.add_sectors_to_kill_list = multipath_add_sectors_to_kill_list,
.commit_changes = multipath_commit_changes,
.can_activate = multipath_can_activate,
.activate = multipath_activate,
.can_deactivate = multipath_can_deactivate,
.deactivate = multipath_deactivate,
.get_info = multipath_get_info,
.get_plugin_info = multipath_get_plugin_info,
.read = multipath_read,
.write = multipath_write,
.backup_metadata = multipath_backup_metadata,
};
/* Plugin-record for the Multipath plugin.*/
plugin_record_t multipath_plugin = {
.id = SetPluginID(EVMS_OEM_IBM,
EVMS_SEGMENT_MANAGER,
9),
.version = {
.major = MAJOR_VERSION,
.minor = MINOR_VERSION,
.patchlevel = PATCH_LEVEL
},
.required_engine_api_version = {
.major = 15,
.minor = 0,
.patchlevel = 0
},
.required_plugin_api_version = {
.plugin = {
.major = 13,
.minor = 1,
.patchlevel = 0
}
},
.short_name = "Multipath",
.long_name = "Multipath Segment Manager",
.oem_name = "IBM",
.functions = {
.plugin = &multipath_functions
},
};
plugin_record_t *evms_plugin_records[] = {
&multipath_plugin,
NULL
};
|