/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <string.h>
#include <libintl.h>
#include "volume_error.h"
#include "volume_devconfig.h"
#include "volume_dlist.h"
#include "volume_output.h"
#include "layout_device_cache.h"
#include "layout_device_util.h"
#include "layout_discovery.h"
#include "layout_dlist_util.h"
#include "layout_messages.h"
#include "layout_request.h"
#include "layout_slice.h"
#include "layout_svm_util.h"
#define _LAYOUT_STRIPE_C
static int compose_stripe(
int max,
int min,
devconfig_t **stripe);
static int compose_stripe_within_hba(
devconfig_t **stripe);
static int assemble_stripe(
devconfig_t **stripe);
static dlist_t *
static int compute_usable_stripe_capacity(
/*
* FUNCTION: layout_stripe(devconfig_t *request, uint64_t nbytes,
* dlist_t **results)
*
* INPUT: request - pointer to a devconfig_t of the current request
* nbytes - the desired capacity of the stripe
*
* OUPUT: results - pointer to a list of composed volumes
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Main layout driver for composing stripe volumes.
*
* Attempts to construct a stripe of size nbytes.
*
* Basic goal of all strategies is to build wide-thin stripes:
* build widest stripe possible across as many HBAs as possible.
*
* Several different layout strategies are tried in order
* of preference until one succeeds or there are none left.
*
* 1 - stripe across similar HBAs
* . number of components is driven by # of HBAs
* . requires mincomp available HBAs
*
* 2 - stripe within a single HBA
* . number of components is driven by # of disks
* . requires at least 1 HBA with mincomp disks
*
* 3 - stripe across all available disks on similar HBAs
* . number of components is driven by # of disk
* . requires at least mincomp disks
*
* 4 - stripe across all available HBAs
* . number of components is driven by # of HBAs
* . requires at least mincomp HBAs
*
* 5 - stripe across all available disks on all HBAs
* . number of components is driven by # of disks
* . requires at least mincomp disks
*
* Each strategy tries to compose a stripe with the
* maximum number of components first then reduces the
* number of components down to mincomp.
*
* get allowed minimum number of stripe components
* get allowed maximum number of stripe components
* get available HBAs
*
* group HBAs by characteristics
* for (each HBA grouping) and (stripe not composed) {
* select next HBA group
* for (strategy[1,2,3]) and (stripe not composed) {
* compose stripe using HBAs in group
* }
* }
*
* if (stripe not composed) {
* for (strategy[4,5]) and (stripe not composed) {
* compose stripe using all HBAs
* }
* }
*
* if (stripe composed) {
* append composed stripe to results
* }
*
*/
int
{
/*
* these enums define the # of strategies and the preference order
* in which they are tried
*/
typedef enum {
typedef enum {
int error = 0;
if (error != 0) {
return (error);
}
if (dlist_length(usable_hbas) == 0) {
return (-1);
}
/*
* based on the request, the diskset defaults or the
* global defaults. These are absolute limits, the
* actual values are determined by the number of HBAs
*/
if (error != 0) {
return (error);
}
for (iter = similar_hba_groups;
(order < N_SIMILAR_HBA_STRATEGIES) &&
order++) {
int n = 0;
switch (order) {
if (error == 0) {
/* BEGIN CSTYLED */
gettext(" -->Strategy 1: use 1 disk from %d-%d similar HBAs - stripe across HBAs\n"),
/* END CSTYLED */
} else {
}
}
break;
if (error == 0) {
/* BEGIN CSTYLED */
gettext(" -->Strategy 2: use %d-%d disks from any single HBA - stripe within HBA\n"),
/* END CSTYLED */
if ((n = dlist_length(selhbas)) > 0) {
} else {
}
}
break;
if (error == 0) {
/* BEGIN CSTYLED */
gettext(" -->Strategy 3: use %d-%d disks from %d similar HBAs - stripe across HBAs\n"),
/* END CSTYLED */
if ((n = dlist_length(selhbas)) > 0) {
} else {
}
} else {
}
}
break;
default:
break;
}
}
}
}
/*
* if striping within similar HBA groups failed,
* try across all available HBAs
*/
for (order = STRIPE_ACROSS_ANY_HBAS_DISK_PER;
(order < N_ANY_HBA_STRATEGIES) &&
order++) {
int n = 0;
switch (order) {
if (error == 0) {
/* BEGIN CSTYLED */
gettext(" -->Strategy 4: use 1 disk from %d-%d available HBAs - stripe across any HBAs\n"),
/* END CSTYLED */
} else {
}
}
break;
case STRIPE_ACROSS_ANY_HBAS:
if (error == 0) {
/* BEGIN CSTYLED */
gettext(" -->Strategy 5: use %d-%d disks from %d available HBA - stripe across any HBAs\n"),
/* END CSTYLED */
} else {
}
}
break;
}
}
}
} else {
}
} else if (error != 0) {
} else {
error = -1;
}
return (error);
}
/*
* FUNCTION: populate_stripe(devconfig_t *request, uint64_t nbytes,
* dlist_t *disks, uint16_t ncomp, dlist_t *othervols,
* devconfig_t **stripe)
*
* INPUT: request - pointer to a request devconfig_t
* nbytes - desired stripe size
* disks - pointer to a list of availalb disks
* ncomp - number of components desired
* othervols - pointer to a list of other volumes whose
* composition may affect this stripe
* (e.g., submirrors of the same mirror)
*
* OUTPUT: stripe - pointer to a devconfig_t to hold resulting stripe
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Helper to populate a stripe with the specified number of
* components and aggregate capacity using slices on disks
* in the input list.
*
* If the othervols list is not empty, the slice components
* chosen for the stripe must not on the same disks as any
* of the other volumes.
*
* If sufficient slice components can be found, the stripe
* is assembled and returned.
*/
int
{
int error = 0;
if (error != 0) {
return (error);
}
return (0);
}
/* determine HBAs and disks used by othervols */
&other_hbas, &other_disks);
if (error != 0) {
return (error);
}
/*
* each stripe component needs to be this size.
* Note that the stripe interlace doesn't need to be
* taken into account in this computation because any
* slice selected as a stripe component will be oversized
* to account for interlace and cylinder rounding done
* by libmeta.
*/
/*
* need to select 'ncomp' slices that are at least 'rsize'
* large in order to reach the desired capacity.
*/
ncomps = 0;
/* BEGIN CSTYLED */
/*
* 1st B_TRUE: require a different disk than those used by
* comps and othervols
* 2nd B_TRUE: requested size is minimum acceptable
* 3rd B_TRUE: add an extra cylinder to the resulting slice, this is
* necessary for Stripe components whose sizes get rounded
* down to an interlace multiple and then down to a cylinder
* boundary.
*/
/* END CSTYLED */
++ncomps;
} else {
/* add selected component to comp list */
item,
/* remove it from the available list */
}
/* add the component slice to the used list */
}
}
/* no possible slice */
break;
}
}
} else {
}
} else if (error == 0) {
if (ncomps > 0) {
} else {
}
}
return (error);
}
/*
* FUNCTION: populate_explicit_stripe(devconfig_t *request,
* dlist_t **results)
*
* INPUT: request - pointer to a request devconfig_t
*
* OUTPUT: results - pointer to a list of volume devconfig_t results
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Processes the input stripe request that specifies explicit
* slice components.
*
* The components have already been validated and reserved,
* all that is required is to create devconfig_t structs
* for each requested slice.
*
* The net size of the stripe is determined by the slice
* components.
*
* The stripe devconfig_t is assembled and appended to the
* results list.
*
* This function is also called from
* layout_mirror.populate_explicit_mirror()
*/
int
{
int error = 0;
/* assemble components */
/* slice components have been validated */
/* turn each into a devconfig_t */
if (error == 0) {
} else {
}
}
}
if (error == 0) {
}
if (error == 0) {
} else {
}
} else {
}
return (error);
}
/*
* FUNCTION: compose_stripe(devconfig_t *request, uint64_t nbytes,
* dlist_t *disks, uint16_t max, uint16_t min,
* dlist_t *othervols, devconfig_t **stripe)
*
* INPUT: request - pointer to a request devconfig_t
* nbytes - desired stripe size
* disks - pointer to a list of availalb disks
* max - maximum number of components allowed
* min - minimum number of components allowed
* othervols - pointer to a list of other volumes whose
* composition may affect this stripe
* (e.g., submirrors of the same mirror)
*
* OUTPUT: stripe - pointer to a devconfig_t to hold resulting stripe
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Attempt to compose a stripe of capacity nbytes, with
* component slices chosen from the input list of disks.
* The number of components in the stripe should be in the
* range min <= N <= max, more components are preferred.
*
* If a stripe can be composed, a pointer to it will be
* returned in the stripe devconfig_t.
*
* This is a loop wrapped around populate_stripe which
* varies the number of components between 'max' and 'min'.
*/
static int
int max,
int min,
{
int error = 0;
}
return (error);
}
/*
* FUNCTION: compose_stripe_within_hba(devconfig_t *request,
* dlist_t *hbas, uint64_t nbytes,
* int maxcomp, int mincomp, dlist_t **stripe)
*
* INPUT: request - pointer to a devconfig_t of the current request
* hbas - pointer to a list of available HBAs
* nbytes - the desired capacity for the stripe
* maxcomp - the maximum number of stripe components
* mincomp - the minimum number of stripe components
*
* OUTPUT: stripe - pointer to a stripe devconfig_t result
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Layout function which compose a stripe of the desired size
* using available disks within any single HBA from the input list.
*
* The number of components within the composed stripe will be
* in the range of min to max, preferring more components
* over fewer.
*
* All input HBAs are expected to have at least mincomp
* available disks and total space sufficient for the stripe.
*
* If the stripe can be composed, a pointer to it is returned in
* the stripe devconfig_t *.
*
*
* while (more hbas and stripe not composed) {
* select HBA
* if (not enough available space on this HBA) {
* continue;
* }
* get available disks for HBA
* use # disks as max # of stripe components
* try to compose stripe
* }
*
*/
static int
{
int error = 0;
char *name;
if (error == 0) {
} else {
}
}
}
return (error);
}
/*
* FUNCTION: assemble_stripe(devconfig_t *request, dlist_t *comps,
* devconfig_t **stripe)
*
* INPUT: request - pointer to a devconfig_t of the current request
* comps - pointer to a list of slice components
*
* OUPUT: stripe - pointer to a devconfig_t to hold final stripe
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Helper which creates and populates a stripe devconfig_t
* struct using information from the input request and the
* list of slice components.
*
* Determines the name of the stripe either from the request
* or from the default naming scheme.
*
* Sets the interlace for the stripe if a value is specified
* in the request.
*
* Attaches the input list of components to the devconfig.
*/
static int
{
int error = 0;
/* set stripe name, use requested name if specified */
if (error != ERR_ATTR_UNSET) {
} else {
error = 0;
}
}
if (error == 0) {
TYPE_STRIPE)) == 0) {
}
} else {
}
}
}
if (error == 0) {
error = 0;
}
}
if (error == 0) {
}
}
if (error == 0) {
} else {
}
return (error);
}
/*
* Order the given stripe component list such that the number of
* slices on the same hba adjacent to each other in the list are
* minimized.
*
* @param comps
* the slice component list to order
*
* @return the first element of the resulting list
*/
static dlist_t *
{
gettext("Stripe components before ordering to alternate HBAs:\n"));
char *name;
}
return (dlist_separate_similar_elements(
}
/*
* FUNCTION: compute_usable_stripe_capacity(dlist_t *comps, uint64_t ilace,
* uint64_t *nbytes)
*
* INPUT: comps - pointer to a list of stripe components
* ilace - the expected stripe interlace in bytes
*
* OUPUT: nbytes - pointer to hold the computed capacity
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Helper which computes the usable size of a stripe taking
* into account the interlace and cylinder rounding that
* libmeta uses: a stripe component's size is rounded down to
* an integral multiple of the interlace and then rounded down
* to a cylinder boundary on VTOC labeled disks.
*
* (These libmeta computations are in the meta_stripe_attach()
* function of .../lib/lvm/libmeta/common/meta_stripe.c and
* meta_adjust_geom() in .../lib/lvm/libmeta/common/meta_init.c)
*
* This function's implementation iterates the input list of
* stripe component slices and determines the smallest usable
* component capacity.
*
* The usable stripe capacity is then that component capacity
* times the number of components.
*/
static int
{
int ncomps = 0;
int error = 0;
if (error == 0) {
if (comp_disk_efi == B_FALSE) {
/* do cylinder and interlace rounding for non-EFI disks */
if (error == 0) {
/* compute bytes per cyl */
/* round nbytes down to a multiple of interlace */
/* round nbytes down to a cylinder boundary */
}
}
/* save smallest component size */
if ((bytes_per_component == 0) ||
(comp_nbytes < bytes_per_component)) {
}
++ncomps;
}
}
if (error == 0) {
/* size of stripe = smallest component size * n components */
}
return (error);
}