meta_rename.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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"
/*
* Just in case we're not in a build environment, make sure that
* TEXT_DOMAIN gets set to something.
*/
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
/*
* change the identity of a metadevice
* These are the "do it" functions for the metarename command.
*/
#include <string.h>
#include <meta.h>
/* private */
#define FORCE (0x00000001)
#define NOISY (0x00000010)
#define NOFLIP (0x00000020)
#define DRYRUN (0x00000040)
/*
* Check if from_np is open
* Return 0 if not open, -1 if open
*/
static int
md_error_t *ep)
{
int rc;
return (-1);
} else if (rc > 0) {
}
return (-1);
}
return (0);
}
/*
* meta_swap is the common code used by the
* meta_rename() and meta_exchange() entry points
*/
static int
int flags,
md_error_t *ep)
{
/*
* If the device exists a key may already exist so need to find it
* otherwise we'll end up adding the key in again which will lead
* to an inconsistent n_count for the namespace record.
*/
}
return (-1);
}
}
return (-1);
}
return (-1);
}
}
return (-1);
}
"\tfrom(mnum,key): %ld, %d\tto: %ld, %d\n",
}
mdclrerror(ep);
}
/* force the name cache to re-read device state */
return (0);
}
/*
* rename a metadevice
*/
int
)
{
int rc = 0;
char *p;
int i, j;
/* must have a set */
mdclrerror(ep);
}
/* if DOIT is not set, we are in dryrun mode */
if ((options & MDCMD_DOIT) == 0) {
}
return (-1);
}
mdclrerror(ep);
return (-1);
}
}
return (-1);
}
mdclrerror(ep);
/* If FORCE is not set, check if metadevice is open */
return (-1);
}
}
/*
* All checks are done, now we do the real work.
* If we are in dryrun mode, we're done.
*/
return (0); /* success */
}
/*
* add key for new name to the namespace
*/
return (-1);
}
if (metaislocalset(sp)) {
} else {
/*
* As this is not the local set we have to create a namespace
* record for each side (host) in the set. We cannot use
* add_key_names() because the destination device (to_np)
* should not exist and so the subsequent metagetcinfo()
* call will fail when it tries to open the device, so we
* have to use the information from the source device (from_np)
*/
return (-1);
}
if (MD_MNSET_DESC(sd)) {
while (nd) {
/*
* Break out if failed to add the key,
* but delete any name space records that
* were added.
*/
side_key == MD_KEYWILD) {
/*
* If we have a valid to_np->key then
* a record was added correctly but
* we do not know for which side, so
* we need to try to delete all of them.
*/
}
/* preserve error key state */
}
break;
}
}
} else {
for (i = 0; i < MD_MAXSIDES; i++) {
/*
* Break out if failed to add the key,
* but delete any name space records
* that were added.
*/
side_key == MD_KEYWILD) {
/*
* If we have a valid
* to_np->key then a record was
* added correctly but we do
* not know for which side, so
* we need to try to delete
* all of them.
*/
for (j = 0; j < i;
j++) {
(side_t)j,
&dummy_ep);
}
/*
* preserve err
* key state
*/
}
break;
}
}
}
}
}
return (-1);
}
if (rc == 0) {
if (options & MDCMD_PRINT) {
"%s: has been renamed to %s\n"),
}
}
return (rc);
}
/*
* return TRUE if current <from>, <to> ordering would
* prevent <from> from being in the role of <self>
*/
static bool_t
)
{
/*
* ?
* \
* <to>
* \
* <from>
*/
return (TRUE);
}
}
}
/*
* <from>
* \
* <to>
* \
* ?
*/
return (TRUE);
}
}
/*
* <to>
* \
* <from>
*/
return (TRUE);
}
}
}
/*
* <from> or <to>
* \ \
* <to> <from>
* \
* ?
*/
return (FALSE);
}
/*
* exchange the names of two metadevices
*/
int
)
{
int rc;
char *p, *p2;
/* must have a set */
return (-1);
}
return (-1);
}
if ((options & MDCMD_DOIT) == 0) {
}
}
}
}
}
return (-1);
}
return (-1);
}
/* If FORCE is not set, check if metadevice is open */
return (-1);
}
}
/*
* All checks are done, now we do the real work.
* If we are in dryrun mode, we're done.
*/
return (0); /* success */
}
/*
* NOFLIP is used only for debugging; the driver
* will catch this and return MDE_RENAME_ORDER, if necessary
*/
} else {
}
if (rc == 0) {
if (options & MDCMD_PRINT) {
"%s and %s have exchanged identities\n"),
}
}
return (rc);
}