summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authortw21770 <none@none>2006-03-14 14:53:36 -0800
committertw21770 <none@none>2006-03-14 14:53:36 -0800
commitd7cd82522afdd890a66c7600b499590ad44e84bd (patch)
tree0799996b63c368edd3153e9f46468c93ebed25ff /usr/src/cmd
parenta62bb709433c06fe335121c07822de4984bdcb84 (diff)
downloadillumos-joyent-d7cd82522afdd890a66c7600b499590ad44e84bd.tar.gz
PSARC/2005/153 Bunnahabhain: Descriptive Name Support in SVM
4521995 Allow descriptive names for metadevices and hot spare pools 6396962 metareplace -c is obsolete and no longer needed.
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/devfsadm/Makefile.com10
-rw-r--r--usr/src/cmd/devfsadm/md_link.c54
-rw-r--r--usr/src/cmd/lvm/metassist/layout/layout_svm_util.c20
-rw-r--r--usr/src/cmd/lvm/rpc.metad/metad_svc_subr.c18
-rw-r--r--usr/src/cmd/lvm/util/metaclear.c119
-rw-r--r--usr/src/cmd/lvm/util/metaclust.c59
-rw-r--r--usr/src/cmd/lvm/util/metadb.c9
-rw-r--r--usr/src/cmd/lvm/util/metadetach.c11
-rw-r--r--usr/src/cmd/lvm/util/metahs.c83
-rw-r--r--usr/src/cmd/lvm/util/metainit.c89
-rw-r--r--usr/src/cmd/lvm/util/metaoffline.c11
-rw-r--r--usr/src/cmd/lvm/util/metaonline.c11
-rw-r--r--usr/src/cmd/lvm/util/metaparam.c25
-rw-r--r--usr/src/cmd/lvm/util/metarecover.c9
-rw-r--r--usr/src/cmd/lvm/util/metarename.c12
-rw-r--r--usr/src/cmd/lvm/util/metareplace.c66
-rw-r--r--usr/src/cmd/lvm/util/metaroot.c13
-rw-r--r--usr/src/cmd/lvm/util/metastat.c126
-rw-r--r--usr/src/cmd/lvm/util/metasync.c9
-rw-r--r--usr/src/cmd/lvm/util/metattach.c18
-rw-r--r--usr/src/cmd/rcm_daemon/common/svm_rcm.c249
21 files changed, 592 insertions, 429 deletions
diff --git a/usr/src/cmd/devfsadm/Makefile.com b/usr/src/cmd/devfsadm/Makefile.com
index 41acb0192e..a07e7031df 100644
--- a/usr/src/cmd/devfsadm/Makefile.com
+++ b/usr/src/cmd/devfsadm/Makefile.com
@@ -2,9 +2,8 @@
# 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.
+# Common Development and Distribution License (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
# or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
#
# CDDL HEADER END
#
+
#
-# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -192,7 +192,7 @@ $(POFILE): $(POFILES)
$(RM) $@; cat $(POFILES) > $@
$(DEVFSADM_MOD): $(DEVFSADM_OBJ)
- $(LINK.c) -o $@ $< $(DEVFSADM_OBJ) $(LDLIBS)
+ $(LINK.c) -o $@ $< $(DEVFSADM_OBJ) $(LDLIBS) -lmeta
$(POST_PROCESS)
SUNW_%.so: %.o
diff --git a/usr/src/cmd/devfsadm/md_link.c b/usr/src/cmd/devfsadm/md_link.c
index 6a1617c250..669286126f 100644
--- a/usr/src/cmd/devfsadm/md_link.c
+++ b/usr/src/cmd/devfsadm/md_link.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,13 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
+#include <meta.h>
#include <regex.h>
#include <devfsadm.h>
#include <stdio.h>
@@ -34,8 +34,8 @@
#include <limits.h>
#include <sys/mkdev.h>
-#define MD_LINK_RE_DEVICES "^md/r?dsk/d[0-9]+$"
-#define MD_LINK_RE_SHARED "^md/shared/[0-9]+/r?dsk/d[0-9]+$"
+#define MD_LINK_RE_DEVICES "^md/r?dsk/.+$"
+#define MD_LINK_RE_SHARED "^md/shared/[0-9]+/r?dsk/.+$"
#define MD_LINK_RE_ADMIN "^md/admin"
/*
@@ -77,19 +77,25 @@ DEVFSADM_REMOVE_INIT_V0(md_remove_cbt);
* For the admin device:
* /dev/md/admin -> /devices/pseudo/md@0:admin
*
- * For each other device
- * /dev/md/dsk/dN -> /devices/pseudo/md@0:0,N,blk
- * /dev/md/rdsk/dN -> /devices/pseudo/md@0:0,N,raw
- * /dev/md/shared/M/dsk/dN /devices/pseudo/md@0:M,N,blk
- * /dev/md/shared/M/rdsk/dN /devices/pseudo/md@0:M,N,raw
+ * For metadevice:
+ * /dev/md/dsk/foobar --> /devices/pseudo/md@0:0,100,blk
+ * /dev/md/rdsk/foobar --> /devices/pseudo/md@0:0,100,raw
+ *
+ * Where 'foobar' is user specified arbitrary name and '100'
+ * is the minor number returned by MD_IOCMAKE_DEV ioctl
+ *
*/
static int
md_create(di_minor_t minor, di_node_t node)
{
char mn[MAXNAMELEN + 1];
char path[PATH_MAX + 1];
- int set = -1, mdev = -1, ret;
+ int set = -1, ret;
char *type, *dir;
+ char *device_name;
+ dev_t minor_devt = di_minor_devt(minor);
+ int key;
+ md_error_t ep;
(void) strcpy(mn, di_minor_name(minor));
@@ -115,26 +121,38 @@ md_create(di_minor_t minor, di_node_t node)
* under the "shared" directory entry instead of linking
* into the top level dsk/rdsk directories.
*/
- ret = sscanf(mn, "%d,%d,", &set, &mdev);
- if (ret == 2 && (type = strrchr(mn, ',')) != NULL) {
- type ++;
+ ret = sscanf(mn, "%d,", &set);
+ if (ret == 1 && (type = strrchr(mn, ',')) != NULL) {
+ type++;
if (strcmp(type, "blk") == 0) {
dir = "dsk";
} else {
dir = "rdsk";
}
+
+ (void) memset(&ep, '\0', sizeof (ep));
+ if ((device_name = meta_getnmentbydev(set,
+ MD_SIDEWILD, minor_devt, NULL, NULL,
+ &key, &ep)) == NULL) {
+ (void) close_admin(&ep);
+ return (DEVFSADM_CONTINUE);
+ }
+
if (set == 0) {
/* this is a simple md */
(void) snprintf(path, sizeof (path),
- "md/%s/d%d", dir, mdev);
+ "md/%s/%s", dir, basename(device_name));
} else {
/* this is a shared md */
(void) snprintf(path, sizeof (path),
- "md/shared/%d/%s/d%d",
- set, dir, mdev);
+ "md/shared/%d/%s/%s", set, dir,
+ basename(device_name));
}
(void) devfsadm_mklink(path, node, minor, 0);
+ Free(device_name);
}
}
+
+ (void) close_admin(&ep);
return (DEVFSADM_CONTINUE);
}
diff --git a/usr/src/cmd/lvm/metassist/layout/layout_svm_util.c b/usr/src/cmd/lvm/metassist/layout/layout_svm_util.c
index 661d4306b5..d4fcaa74ee 100644
--- a/usr/src/cmd/lvm/metassist/layout/layout_svm_util.c
+++ b/usr/src/cmd/lvm/metassist/layout/layout_svm_util.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1672,7 +1671,7 @@ diskset_info(
mdname_t *mdn;
md_raid_t *raid;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE, &error);
mdclrerror(&error);
if (mdn == NULL) {
continue;
@@ -1704,7 +1703,7 @@ diskset_info(
mdname_t *mdn;
md_stripe_t *stripe;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE, &error);
mdclrerror(&error);
if (mdn == NULL) {
continue;
@@ -1745,7 +1744,7 @@ diskset_info(
mdname_t *mdn;
md_sp_t *soft_part;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE, &error);
mdclrerror(&error);
if (mdn == NULL) {
continue;
@@ -1901,8 +1900,13 @@ new_entry(
{
mdname_t *mdn;
md_error_t error = mdnullerror;
+ meta_device_type_t uname_type = UNKNOWN;
- mdn = metaname(&sp, slice_name, &error);
+ /* Determine the appropriate uname type for metaname */
+ if (type == SVM_MDB || type == SVM_DRIVE || type == SVM_TRANS)
+ uname_type = LOGICAL_DEVICE;
+
+ mdn = metaname(&sp, slice_name, uname_type, &error);
if (!mdisok(&error)) {
mdn = NULL;
}
diff --git a/usr/src/cmd/lvm/rpc.metad/metad_svc_subr.c b/usr/src/cmd/lvm/rpc.metad/metad_svc_subr.c
index 690b963239..92f6d1c490 100644
--- a/usr/src/cmd/lvm/rpc.metad/metad_svc_subr.c
+++ b/usr/src/cmd/lvm/rpc.metad/metad_svc_subr.c
@@ -2140,7 +2140,7 @@ devinfo(
if ((np = metaslicename(dp, MD_SLICE0, ep)) == NULL)
return;
- if ((real_np = metaname(&sp, np->bname, ep)) == NULL)
+ if ((real_np = metaname(&sp, np->bname, LOGICAL_DEVICE, ep)) == NULL)
return;
res->dev = real_np->dev;
@@ -2262,7 +2262,7 @@ mdrpc_get_devid(
if ((np = metaslicename(dp, MD_SLICE0, ep)) == NULL)
return;
- if (metaname(&sp, np->bname, ep) == NULL)
+ if (metaname(&sp, np->bname, LOGICAL_DEVICE, ep) == NULL)
return;
res->enc_devid = meta_get_devid(np->rname);
@@ -2381,7 +2381,7 @@ mdrpc_devinfo_by_devid_2_svc(
return (TRUE);
}
- np = metaname(&sp, disklist[0].devname, ep);
+ np = metaname(&sp, disklist[0].devname, LOGICAL_DEVICE, ep);
if (np != NULL) {
mdcinfo_t *cinfo;
if ((cinfo = metagetcinfo(np, ep)) != NULL) {
@@ -2493,7 +2493,7 @@ mdrpc_devinfo_by_devid_name_2_svc(
if (disklist[i].dev == NODEV)
i = 0;
- np = metaname(&sp, disklist[i].devname, ep);
+ np = metaname(&sp, disklist[i].devname, LOGICAL_DEVICE, ep);
if (np != NULL) {
mdcinfo_t *cinfo;
if ((cinfo = metagetcinfo(np, ep)) != NULL) {
@@ -5138,9 +5138,9 @@ reset_mirror_owner(
if (metaioctl(MD_MN_GET_MM_OWNER, ownpar, ep,
"MD_MN_GET_MM_OWNER") != 0) {
mde_perror(ep, gettext(
- "Unable to get mirror owner for %s/d%u"),
+ "Unable to get mirror owner for %s/%s"),
local_sp->setname,
- (unsigned)MD_MIN2UNIT(ownpar->d.mnum));
+ get_mdname(local_sp, ownpar->d.mnum));
goto out;
}
@@ -5160,9 +5160,9 @@ reset_mirror_owner(
MD_MN_MM_ALLOW_CHANGE) == -1) {
mde_perror(ep, gettext(
"Unable to reset mirror owner for"
- " %s/d%u"), local_sp->setname,
- (unsigned)MD_MIN2UNIT(
- ownpar->d.mnum));
+ " %s/%s"), local_sp->setname,
+ get_mdname(local_sp,
+ ownpar->d.mnum));
goto out;
}
break;
diff --git a/usr/src/cmd/lvm/util/metaclear.c b/usr/src/cmd/lvm/util/metaclear.c
index dc76d29941..ad4f1e0581 100644
--- a/usr/src/cmd/lvm/util/metaclear.c
+++ b/usr/src/cmd/lvm/util/metaclear.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -47,7 +46,7 @@ clear_name(
{
/* clear hotspare pool */
- if (is_hspname(uname)) {
+ if (is_existing_hsp(*spp, uname)) {
mdhspname_t *hspnp;
/* get hotspare pool name */
@@ -71,8 +70,12 @@ clear_name(
else {
mdname_t *np;
+ /* check for ownership */
+ if (meta_check_ownership(*spp, ep) != 0)
+ return (-1);
+
/* get metadevice name */
- if (((np = metaname(spp, uname, ep)) == NULL) ||
+ if (((np = metaname(spp, uname, META_DEVICE, ep)) == NULL) ||
(metachkmeta(np, ep) != 0)) {
return (-1);
}
@@ -82,10 +85,6 @@ clear_name(
if (meta_lock(*spp, TRUE, ep))
return (-1);
- /* check for ownership */
- if (meta_check_ownership(*spp, ep) != 0)
- return (-1);
-
/* clear metadevice */
return (meta_reset_by_name(*spp, np, options, ep));
}
@@ -119,10 +118,11 @@ main(
char *argv[]
)
{
- char *sname = NULL;
+ char *sname = MD_LOCAL_NAME;
mdsetname_t *sp = NULL;
int aflag = 0;
int pflag = 0;
+ int set_flag = 0;
mdcmdopts_t options = (MDCMD_PRINT|MDCMD_DOIT);
int c;
md_error_t status = mdnullerror;
@@ -172,6 +172,7 @@ main(
case 's':
sname = optarg;
+ set_flag++;
break;
case 'a':
@@ -201,30 +202,20 @@ main(
argc -= optind;
argv += optind;
- if (sname != NULL && (sp = metasetname(sname, ep)) == NULL) {
- goto errout;
+ /* with mn sets if -a, set name must have been specified by -s */
+ if (called_thru_rpc && aflag && !set_flag) {
+ md_eprintf(gettext(
+ "-a parameter requires the use of -s in multi-node sets"));
+ md_exit(sp, 1);
}
- if (called_thru_rpc) {
-
- if (aflag) {
- /* if -a, set name must have been specified by -s */
- if ((sp == NULL) ||
- (metaget_setdesc(sp, ep) == NULL))
- goto errout;
- } else {
- /*
- * setname may be defined by setname in first arg
- * if sp is NULL, meta_is_mn_name() derives sp from
- * argv[0], eg from set/d10
- */
- if (meta_is_mn_name(&sp, argv[0], ep)) {
- if (metaget_setdesc(sp, ep) == NULL)
- goto errout;
- } else
- goto errout;
- }
+ /* get set context */
+ if ((sp = metasetname(sname, ep)) == NULL) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
+ }
+ if (called_thru_rpc) {
/* Check if the device is open on all nodes */
options |= MDCMD_MN_OPEN_CHECK;
}
@@ -233,12 +224,6 @@ main(
if (argc != 0)
usage(sp, 1);
- if (sp == NULL) {
- /* Get sp for local set */
- if ((sp = metasetname(MD_LOCAL_NAME, ep)) == NULL)
- goto errout;
- }
-
/*
* If a MN set, we will generate a series of individual
* metaclear commands which will each grab the set lock.
@@ -271,13 +256,12 @@ main(
*/
if (argc <= 0)
usage(sp, 1);
+
if (meta_is_mn_name(&sp, argv[0], ep))
mnset = TRUE;
eval = 0;
for (; (argc > 0); --argc, ++argv) {
- mdhspname_t *hspnp;
- mdname_t *np;
char *cname;
/*
@@ -287,45 +271,32 @@ main(
* deal with it.
*/
if (!called_thru_rpc && mnset) {
+ /* get the canonical name */
if (pflag) {
/*
* If -p, set cname to the device
* argument.
*/
- cname = argv[0];
+ cname = Strdup(argv[0]);
} else {
/*
* For hotspares and metadevices, set
* cname to the full name,
* setname/hspxxx or setname/dxxx
*/
- if (is_hspname(argv[0])) {
- /* get hotspare pool name */
- if ((hspnp = metahspname(&sp,
- argv[0], ep)) == NULL) {
- mde_perror(ep, "");
- eval = 1;
- continue;
- }
- cname = hspnp->hspname;
- } else {
- /* get metadevice name */
- if (((np = metaname(&sp,
- argv[0], ep)) == NULL) ||
- (metachkmeta(np, ep)
- != 0)) {
- mde_perror(ep, "");
- eval = 1;
- continue;
- }
- cname = np->cname;
+ cname = meta_name_getname(&sp,
+ argv[0], META_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
+ eval = 1;
+ continue;
}
}
if (meta_mn_send_metaclear_command(sp,
cname, options, pflag, ep) != 0) {
eval = 1;
- continue;
}
+ Free(cname);
} else {
if (pflag) {
/*
@@ -339,24 +310,34 @@ main(
continue;
}
} else {
+ /*
+ * get the canonical name and
+ * setup sp if it has been
+ * specified as part of the
+ * metadevice/hsp name param
+ */
+ cname = meta_name_getname(&sp,
+ argv[0], META_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
+ eval = 1;
+ continue;
+ }
+
/* clear named devices */
- if (clear_name(&sp, argv[0],
+ if (clear_name(&sp, cname,
options, ep) != 0) {
mde_perror(ep, "");
eval = 1;
+ Free(cname);
continue;
}
+ Free(cname);
}
}
}
}
/* update md.cf */
- if (sp == NULL) {
- /* Get sp for local set */
- if ((sp = metasetname(MD_LOCAL_NAME, ep)) == NULL)
- goto errout;
- }
-
if (meta_update_md_cf(sp, ep) != 0) {
mde_perror(ep, "");
eval = 1;
diff --git a/usr/src/cmd/lvm/util/metaclust.c b/usr/src/cmd/lvm/util/metaclust.c
index f7baa0908c..ea4d44267d 100644
--- a/usr/src/cmd/lvm/util/metaclust.c
+++ b/usr/src/cmd/lvm/util/metaclust.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -21,7 +20,7 @@
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -238,19 +237,25 @@ static int
compose_path(mdsetname_t *sp, int mnum, char *pathname, int pathlen)
{
int rtn;
+ mdname_t *np;
+ md_error_t status = mdnullerror;
if (MD_MIN2SET(mnum) != sp->setno) {
md_eprintf(gettext("minor number 0x%x invalid for set %d\n"),
mnum, sp->setno);
return (-1);
}
- rtn = snprintf(pathname, pathlen, "/dev/md/%s/rdsk/d%u",
- sp->setname, (unsigned)MD_MIN2UNIT(mnum));
+
+ if ((np = metamnumname(&sp, mnum, 0, &status)) == NULL) {
+ return (-1);
+ }
+
+ rtn = snprintf(pathname, pathlen, "%s", np->rname);
if ((pathname[0] == '\0') || (rtn >= pathlen)) {
md_eprintf(gettext(
- "Could not create path for device %s/d%u\n"),
- sp->setname, (unsigned)MD_MIN2UNIT(mnum));
+ "Could not create path for device %s\n"),
+ get_mdname(sp, mnum));
return (-1);
}
return (0);
@@ -328,15 +333,14 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
mir_state->mnum = meta_getminor(devnp->dev);
MD_SETDRIVERNAME(mir_state, MD_MIRROR, sp->setno);
meta_mc_log(MC_LOG4, gettext("Getting mirror state"
- " for %s/d%u: %s"), sp->setname,
- (unsigned)MD_MIN2UNIT(mir_state->mnum),
+ " for %s: %s"), get_mdname(sp, mir_state->mnum),
meta_print_hrtime(gethrtime() - start_time));
if (metaioctl(MD_MN_GET_MIRROR_STATE, mir_state, ep,
"MD_MN_GET_MIRROR_STATE") != 0) {
mde_perror(ep, gettext("Unable to get "
- "mirror state for %s/d%u"), sp->setname,
- (unsigned)MD_MIN2UNIT(mir_state->mnum));
+ "mirror state for %s"),
+ get_mdname(sp, mir_state->mnum));
goto out;
} else {
continue;
@@ -372,16 +376,15 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
MD_SETDRIVERNAME(ownpar, MD_MIRROR, sp->setno);
meta_mc_log(MC_LOG4, gettext("Setting owner "
- "for %s/d%u: %s"), sp->setname,
- (unsigned)MD_MIN2UNIT(ownpar->d.mnum),
+ "for %s: %s"), get_mdname(sp, ownpar->d.mnum),
meta_print_hrtime(gethrtime() - start_time));
/* get the current owner id */
if (metaioctl(MD_MN_GET_MM_OWNER, ownpar, ep,
"MD_MN_GET_MM_OWNER") != 0) {
mde_perror(ep, gettext("Unable to get "
- "mirror owner for %s/d%u"), sp->setname,
- (unsigned)MD_MIN2UNIT(ownpar->d.mnum));
+ "mirror owner for %s"),
+ get_mdname(sp, ownpar->d.mnum));
goto out;
}
}
@@ -407,18 +410,16 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
MD_MN_MM_ALLOW_CHANGE) == -1) {
md_eprintf(gettext(
"Unable to reset mirror owner "
- "for %s/d%u\n"), sp->setname,
- (unsigned)MD_MIN2UNIT(
- ownpar->d.mnum));
+ "for %s\n"),
+ get_mdname(sp, ownpar->d.mnum));
goto out;
}
if (meta_mirror_resync(sp, devnp, 0, ep,
MD_RESYNC_KILL_NO_WAIT) != 0) {
md_eprintf(gettext(
"Unable to kill resync for"
- " %s/d%u\n"), sp->setname,
- (unsigned)MD_MIN2UNIT(
- ownpar->d.mnum));
+ " %s\n"),
+ get_mdname(sp, ownpar->d.mnum));
goto out;
}
}
@@ -441,8 +442,8 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
ownpar->d.mnum, ownpar->d.owner,
MD_MN_MM_CHOOSE_OWNER) == -1) {
md_eprintf(gettext("Unable to choose "
- "mirror owner for %s/d%u\n"), sp->setname,
- (unsigned)MD_MIN2UNIT(ownpar->d.mnum));
+ "mirror owner for %s\n"),
+ get_mdname(sp, ownpar->d.mnum));
goto out;
}
}
@@ -465,7 +466,7 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
* cluster, ABR will be cleared on all nodes.
*/
char *miscname;
- char name[MD_MAX_CTDLEN];
+ char name[MAXPATHLEN];
int mnum, fd;
name[0] = '\0';
@@ -483,8 +484,7 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
continue;
meta_mc_log(MC_LOG4, gettext("Re-setting ABR state "
- "for %s/d%u: %s"), sp->setname,
- (unsigned)MD_MIN2UNIT(mnum),
+ "for %s: %s"), get_mdname(sp, mnum),
meta_print_hrtime(gethrtime() - start_time));
/* compose the absolute device path and open it */
@@ -507,7 +507,7 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
*/
char *miscname;
- char name[MD_MAX_CTDLEN];
+ char name[MAXPATHLEN];
int mnum, fd;
volcap_t vc;
uint_t tstate;
@@ -535,8 +535,7 @@ reset_state(uint_t mode, mdsetname_t *sp, char *drivername, md_error_t *ep)
continue;
meta_mc_log(MC_LOG4, gettext("Updating ABR state "
- "for %s/d%u: %s"), sp->setname,
- (unsigned)MD_MIN2UNIT(mnum),
+ "for %s: %s"), get_mdname(sp, mnum),
meta_print_hrtime(gethrtime() - start_time));
/* compose the absolute device path and open it */
diff --git a/usr/src/cmd/lvm/util/metadb.c b/usr/src/cmd/lvm/util/metadb.c
index d8fa65af24..6c318b84e6 100644
--- a/usr/src/cmd/lvm/util/metadb.c
+++ b/usr/src/cmd/lvm/util/metadb.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -75,7 +74,7 @@ make_dbname(
{
mdname_t *np;
- if ((np = metaname(&sp, name, ep)) == NULL)
+ if ((np = metaname(&sp, name, LOGICAL_DEVICE, ep)) == NULL)
return (NULL);
return (metanamelist_append(nlp, np));
diff --git a/usr/src/cmd/lvm/util/metadetach.c b/usr/src/cmd/lvm/util/metadetach.c
index 040b1d7108..ab9d74c9db 100644
--- a/usr/src/cmd/lvm/util/metadetach.c
+++ b/usr/src/cmd/lvm/util/metadetach.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -90,7 +89,7 @@ mirror_detach(
usage(*spp, 1);
/* get submirror */
- if ((submirnp = metaname(spp, argv[1], ep)) == NULL)
+ if ((submirnp = metaname(spp, argv[1], META_DEVICE, ep)) == NULL)
return (-1);
/* detach submirror */
@@ -238,7 +237,7 @@ main(
}
/* Get metadevice name */
- if (((np = metaname(&sp, argv[optind], ep)) == NULL) ||
+ if (((np = metaname(&sp, argv[optind], META_DEVICE, ep)) == NULL) ||
(metachkmeta(np, ep) != 0)) {
mde_perror(ep, "");
md_exit(sp, 1);
diff --git a/usr/src/cmd/lvm/util/metahs.c b/usr/src/cmd/lvm/util/metahs.c
index 25a31610e9..4db667d287 100644
--- a/usr/src/cmd/lvm/util/metahs.c
+++ b/usr/src/cmd/lvm/util/metahs.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -60,7 +59,7 @@ status_hsp(
/* must have set */
assert(sp != NULL);
- assert(sp->setno == HSP_SET(hspnp->hsp));
+ assert(hspnp->hsp == MD_HSP_NONE || sp->setno == HSP_SET(hspnp->hsp));
/* print status */
if (meta_hsp_print(sp, hspnp, &nlp, NULL, stdout, options, ep) != 0)
@@ -93,18 +92,6 @@ usage: %s [-s setname] -a hot_spare_pool [component...]\n\
}
/*
- * check for "all"
- */
-static int
-is_all(char *s)
-{
- if ((strcoll(s, gettext("all")) == 0) ||
- (strcoll(s, gettext("ALL")) == 0))
- return (1);
- return (0);
-}
-
-/*
* parse args and add hotspares
*/
static int
@@ -125,11 +112,7 @@ add_hotspares(
/* get hotspare pool name(s) */
if (argc < 1)
usage(*spp, 1);
- if ((argc > 1) && is_all(argv[0])) {
- if ((*spp == NULL) &&
- ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL)) {
- return (-1);
- }
+ if ((argc > 1) && meta_is_all(argv[0])) {
/* check for ownership */
assert(*spp != NULL);
if (meta_check_ownership(*spp, ep) != 0)
@@ -140,9 +123,12 @@ add_hotspares(
} else if (cnt == 0) {
return (mderror(ep, MDE_NO_HSPS, NULL));
}
- } else if ((cnt = metahspnamelist(spp, &hspnlp, 1, &argv[0],
- ep)) < 0) {
- return (-1);
+ } else { /* create the hsp nmlist from the specified hsp name */
+ if (!is_hspname(argv[0]))
+ return (mderror(ep, MDE_NAME_ILLEGAL, argv[0]));
+
+ if ((cnt = metahspnamelist(spp, &hspnlp, 1, &argv[0], ep)) < 0)
+ return (-1);
}
assert(cnt > 0);
--argc, ++argv;
@@ -158,7 +144,8 @@ add_hotspares(
return (-1);
/* get hotspares */
- if (metanamelist(spp, &nlp, argc, argv, ep) < 0) {
+ if (metanamelist(spp, &nlp, argc, argv,
+ LOGICAL_DEVICE, ep) < 0) {
goto out;
}
@@ -201,11 +188,7 @@ delete_hotspares(
/* get hotspare pool name(s) */
if (argc < 1)
usage(*spp, 1);
- if ((argc > 1) && is_all(argv[0])) {
- if ((*spp == NULL) &&
- ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL)) {
- return (-1);
- }
+ if ((argc > 1) && meta_is_all(argv[0])) {
/* check for ownership */
assert(*spp != NULL);
if (meta_check_ownership(*spp, ep) != 0)
@@ -234,7 +217,8 @@ delete_hotspares(
return (-1);
/* get hotspares */
- if (metanamelist(spp, &nlp, argc, argv, ep) < 0) {
+ if (metanamelist(spp, &nlp, argc, argv,
+ LOGICAL_DEVICE, ep) < 0) {
goto out;
}
@@ -292,7 +276,8 @@ enable_hotspares(
usage(*spp, 1);
/* get list of hotspares */
- if (metanamelist(spp, &nlp, argc, argv, ep) < 0)
+ if (metanamelist(spp, &nlp, argc, argv,
+ LOGICAL_DEVICE, ep) < 0)
goto out;
assert(nlp != NULL);
@@ -337,11 +322,7 @@ replace_hotspares(
/* get hotspare pool name(s) */
if (argc != 3)
usage(*spp, 1);
- if (is_all(argv[0])) {
- if ((*spp == NULL) &&
- ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL)) {
- return (-1);
- }
+ if (meta_is_all(argv[0])) {
/* check for ownership */
assert(*spp != NULL);
if (meta_check_ownership(*spp, ep) != 0)
@@ -369,11 +350,11 @@ replace_hotspares(
return (-1);
/* get old component */
- if ((oldnp = metaname(spp, argv[1], ep)) == NULL)
+ if ((oldnp = metaname(spp, argv[1], LOGICAL_DEVICE, ep)) == NULL)
goto out;
/* get new component */
- if ((newnp = metaname(spp, argv[2], ep)) == NULL)
+ if ((newnp = metaname(spp, argv[2], LOGICAL_DEVICE, ep)) == NULL)
goto out;
/* replace hotspares */
@@ -480,10 +461,6 @@ status_hotspares(
/* get hotspare pool name(s) */
if (argc == 0) {
- if ((*spp == NULL) &&
- ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL)) {
- return (-1);
- }
/* check for ownership */
assert(*spp != NULL);
if (meta_check_ownership(*spp, ep) != 0)
@@ -696,6 +673,24 @@ main(
if (which_op == NONE)
usage(sp, 1);
+ /*
+ * if a hot spare pool was specified by name then
+ * get the canonical form of the name and set up
+ * sp if the name was specified in the form 'set/hsp'
+ * unless 'all' is specified or the request is made to
+ * enable a hs which means that argv[0] will be a component
+ */
+ if (argc > 0 && !meta_is_all(argv[0]) && which_op != ENABLE_A_HS) {
+ char *cname = NULL;
+
+ cname = meta_name_getname(&sp, argv[0], HSP_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
+ }
+ Free(cname);
+ }
+
if (which_op == STATUS_A_HSP) {
if (status_hotspares(&sp, argc, argv, ep) != 0) {
mde_perror(ep, "");
diff --git a/usr/src/cmd/lvm/util/metainit.c b/usr/src/cmd/lvm/util/metainit.c
index cc0e687dd2..e48d33d0a0 100644
--- a/usr/src/cmd/lvm/util/metainit.c
+++ b/usr/src/cmd/lvm/util/metainit.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -128,14 +127,18 @@ init_entries(
/* for all matching entries, which haven't already been done */
for (line = 0; (line < tabp->nlines); ++line) {
md_tab_line_t *linep = &tabp->lines[line];
+ char *uname = linep->argv[0];
/* see if already done */
if (linep->flags != DO_AGAIN)
continue;
+ /* clear the metadev/hsp caches between inits */
+ metaflushmetanames();
+
/* try it */
if ((called_thru_rpc == FALSE) &&
- meta_is_mn_name(spp, linep->argv[0], ep)) {
+ meta_is_mn_name(spp, uname, ep)) {
/*
* MN set, send command to all nodes
* Note that is sp is NULL, meta_is_mn_name() derives
@@ -144,15 +147,26 @@ init_entries(
ret = mn_send_command(spp, linep->argc, linep->argv,
options, flags, linep->context, ep);
} else {
- ret = meta_init_name(spp, linep->argc, linep->argv,
- options, ep);
- if (ret != 0) {
- if (!(flags & MD_IGNORE_STDERR)) {
- mderrorextra(ep, linep->context);
- mde_perror(ep, "");
- rval = -1;
- }
+ char *cname = NULL;
+
+ cname = meta_name_getname(spp, uname, META_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
mdclrerror(ep);
+ } else {
+
+ ret = meta_init_name(spp, linep->argc,
+ linep->argv, cname, options, ep);
+ Free(cname);
+
+ if (ret != 0) {
+ if (!(flags & MD_IGNORE_STDERR)) {
+ mderrorextra(ep, linep->context);
+ mde_perror(ep, "");
+ rval = -1;
+ }
+ mdclrerror(ep);
+ }
}
}
if (ret == 0) {
@@ -184,16 +198,6 @@ init_all(
int done;
int eval = -1;
- /* create local set, if necessary */
- if (*spp == NULL) {
- if ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL) {
- mde_perror(ep, "");
- mdclrerror(ep);
- return (eval);
- }
- }
- setlen = strlen((*spp)->setname);
-
/*
* Only take the lock if this is not a MN set
* We can only enter this code for a MN set if we are the initiator
@@ -225,6 +229,7 @@ init_all(
return (eval);
}
+ setlen = strlen((*spp)->setname);
for (more = 0; (more < tabp->nlines); ++more) {
md_tab_line_t *linep = &tabp->lines[more];
char *cname = linep->cname;
@@ -290,11 +295,10 @@ init_name(
md_tab_line_t *linep = NULL;
int rval = -1;
int ret;
+ char *uname = argv[0];
/* look in md.tab */
if (argc == 1) {
- char *name = argv[0];
-
/* get md.tab entries */
if ((tabp = meta_tab_parse(NULL, ep)) == NULL) {
if (! mdissyserror(ep, ENOENT))
@@ -302,7 +306,7 @@ init_name(
}
/* look in md.tab */
- if ((linep = meta_tab_find(*spp, tabp, name, TAB_MD_HSP))
+ if ((linep = meta_tab_find(*spp, tabp, uname, TAB_MD_HSP))
!= NULL) {
argc = linep->argc;
argv = linep->argv;
@@ -310,14 +314,29 @@ init_name(
}
if ((called_thru_rpc == FALSE) &&
- meta_is_mn_name(spp, argv[0], ep)) {
+ meta_is_mn_name(spp, uname, ep)) {
/*
* MN set, send command to all nodes
*/
ret = mn_send_command(spp, argc, argv, options,
MD_DISP_STDERR, NO_CONTEXT_STRING, ep);
- } else
- ret = meta_init_name(spp, argc, argv, options, ep);
+ } else {
+ char *cname = NULL;
+
+ cname = meta_name_getname(spp, uname, META_DEVICE, ep);
+ if (cname == NULL) {
+ goto out;
+ }
+
+ /* check for ownership */
+ if (meta_check_ownership(*spp, ep) != 0) {
+ Free(cname);
+ goto out;
+ }
+
+ ret = meta_init_name(spp, argc, argv, cname, options, ep);
+ Free(cname);
+ }
if (ret != 0) {
if (linep != NULL)
@@ -687,7 +706,7 @@ main(
char *argv[]
)
{
- char *sname = NULL;
+ char *sname = MD_LOCAL_NAME;
mdsetname_t *sp = NULL;
enum action {
NONE,
@@ -784,12 +803,12 @@ main(
}
}
- if (sname != NULL) {
- if ((sp = metasetname(sname, ep)) == NULL) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
+ /* sname is MD_LOCAL_NAME if not specified on the command line */
+ if ((sp = metasetname(sname, ep)) == NULL) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
}
+
argc -= optind;
argv += optind;
if (todo == NONE) {
diff --git a/usr/src/cmd/lvm/util/metaoffline.c b/usr/src/cmd/lvm/util/metaoffline.c
index 124229062f..6fd85fe5b4 100644
--- a/usr/src/cmd/lvm/util/metaoffline.c
+++ b/usr/src/cmd/lvm/util/metaoffline.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -139,8 +138,8 @@ main(
}
/* get names */
- if (((mirnp = metaname(&sp, argv[0], ep)) == NULL) ||
- ((submirnp = metaname(&sp, argv[1], ep)) == NULL)) {
+ if (((mirnp = metaname(&sp, argv[0], META_DEVICE, ep)) == NULL) ||
+ ((submirnp = metaname(&sp, argv[1], META_DEVICE, ep)) == NULL)) {
mde_perror(ep, "");
md_exit(sp, 1);
}
diff --git a/usr/src/cmd/lvm/util/metaonline.c b/usr/src/cmd/lvm/util/metaonline.c
index 03607a28d4..b0cd672417 100644
--- a/usr/src/cmd/lvm/util/metaonline.c
+++ b/usr/src/cmd/lvm/util/metaonline.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -135,8 +134,8 @@ main(
}
/* get names */
- if (((mirnp = metaname(&sp, argv[0], ep)) == NULL) ||
- ((submirnp = metaname(&sp, argv[1], ep)) == NULL)) {
+ if (((mirnp = metaname(&sp, argv[0], META_DEVICE, ep)) == NULL) ||
+ ((submirnp = metaname(&sp, argv[1], META_DEVICE, ep)) == NULL)) {
mde_perror(ep, "");
md_exit(sp, 1);
}
diff --git a/usr/src/cmd/lvm/util/metaparam.c b/usr/src/cmd/lvm/util/metaparam.c
index e4d2df94d2..26754a049f 100644
--- a/usr/src/cmd/lvm/util/metaparam.c
+++ b/usr/src/cmd/lvm/util/metaparam.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -35,18 +34,6 @@
#include <sdssc.h>
/*
- * check for "none"
- */
-static int
-is_none(char *s)
-{
- if ((strcoll(s, gettext("none")) == 0) ||
- (strcoll(s, gettext("NONE")) == 0))
- return (1);
- return (0);
-}
-
-/*
* print usage message
*/
static void
@@ -202,7 +189,7 @@ stripe_params(
break;
case 'h':
- if (is_none(optarg)) {
+ if (meta_is_none(optarg)) {
msp.hsp_id = MD_HSP_NONE;
} else if ((hspnp = metahspname(&sp, optarg,
ep)) == NULL) {
@@ -289,7 +276,7 @@ raid_params(
break;
case 'h':
- if (is_none(optarg)) {
+ if (meta_is_none(optarg)) {
msp.hsp_id = MD_HSP_NONE;
} else if ((hspnp = metahspname(&sp, optarg,
ep)) == NULL) {
@@ -442,7 +429,7 @@ main(
md_exit(sp, result);
}
- if ((np = metaname(&sp, argv[optind], ep)) == NULL) {
+ if ((np = metaname(&sp, argv[optind], META_DEVICE, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
diff --git a/usr/src/cmd/lvm/util/metarecover.c b/usr/src/cmd/lvm/util/metarecover.c
index 3172c4cd87..802841616e 100644
--- a/usr/src/cmd/lvm/util/metarecover.c
+++ b/usr/src/cmd/lvm/util/metarecover.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -142,7 +141,7 @@ main(
argv++;
argc--;
- if ((namep = metaname(&sp, devname, ep)) == NULL) {
+ if ((namep = metaname(&sp, devname, UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
diff --git a/usr/src/cmd/lvm/util/metarename.c b/usr/src/cmd/lvm/util/metarename.c
index fad547cab8..22f3ead803 100644
--- a/usr/src/cmd/lvm/util/metarename.c
+++ b/usr/src/cmd/lvm/util/metarename.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -221,13 +220,14 @@ main(
}
if (i == 1 && !xflag) {
/* rename, create dest metadevice name */
- if (meta_init_make_device(&sp, argv[i], ep) != 0) {
+ if (meta_init_make_device(&sp, argv[i], ep) <= 0) {
mde_perror(ep, argv[i]);
md_exit(sp, 1);
}
}
- if (NULL == (mdnms[i] = metaname(&sp, argv[i], ep))) {
+ if ((mdnms[i] = metaname(&sp, argv[i],
+ META_DEVICE, ep)) == NULL) {
mde_perror(ep, argv[i]);
md_exit(sp, 1);
}
diff --git a/usr/src/cmd/lvm/util/metareplace.c b/usr/src/cmd/lvm/util/metareplace.c
index 00561f096b..3e69ace629 100644
--- a/usr/src/cmd/lvm/util/metareplace.c
+++ b/usr/src/cmd/lvm/util/metareplace.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -47,9 +46,8 @@ usage(
usage: %s [-s setname] mirror component-old component-new\n\
%s [-s setname] -e mirror component\n\
%s [-s setname] [-f] RAID component-old component-new\n\
- %s [-s setname] [-f] -e RAID component\n\
- %s [-s setname] -c metadevice component-old component-new\n"),
- myname, myname, myname, myname, myname);
+ %s [-s setname] [-f] -e RAID component\n"),
+ myname, myname, myname, myname);
md_exit(sp, eval);
}
@@ -67,7 +65,6 @@ main(
mdcmdopts_t options = (MDCMD_PRINT|MDCMD_DOIT);
mdname_t *namep;
int eflag = 0;
- int cflag = 0;
int c;
md_error_t status = mdnullerror;
md_error_t *ep = &status;
@@ -111,7 +108,7 @@ main(
/* parse arguments */
optind = 1;
opterr = 1;
- while ((c = getopt(argc, argv, "hs:cefn?")) != -1) {
+ while ((c = getopt(argc, argv, "hs:efn?")) != -1) {
switch (c) {
case 'h':
usage(sp, 0);
@@ -137,11 +134,6 @@ main(
}
break;
- case 'c':
- options |= MDCMD_CLUSTER_REPLACE;
- ++cflag;
- break;
-
case '?':
if (optopt == '?')
usage(sp, 0);
@@ -167,30 +159,14 @@ main(
uname = argv[0];
- if (((namep = metaname(&sp, argv[0], ep)) == NULL)) {
+ if (((namep = metaname(&sp, uname, META_DEVICE, ep)) == NULL)) {
mde_perror(ep, "");
md_exit(sp, 1);
}
- /*
- * This 'if' statement might look a little strange so I'll 'splain
- * a few things.
- *
- * If 'cflag' is not set then always do the metachkmeta.
- * This is the normal behavior and you're not allowed to run
- * metarplace on a hotspare. metachkmeta will barf.
- *
- * If 'cflag' and uname is not a hotspare do metachkmeta
- * Still need to check out the metadevice as long as it's not
- * a hotspare.
- *
- * Else we've got a hotspare so we can't call metachkmeta
- */
- if ((!cflag) || (cflag && (!is_hspname(uname)))) {
- if (metachkmeta(namep, ep) != 0) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
+ if (metachkmeta(namep, ep) != 0) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
}
assert(sp != NULL);
@@ -274,7 +250,7 @@ main(
if (argc != 1)
usage(sp, 1);
- if ((compnp = metaname(&sp, argv[0], ep)) == NULL) {
+ if ((compnp = metaname(&sp, argv[0], UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
@@ -290,26 +266,18 @@ main(
if (argc != 2)
usage(sp, 1);
- if ((oldnp = metaname(&sp, argv[0], ep)) == NULL) {
+ if ((oldnp = metaname(&sp, argv[0], UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
- if ((newnp = metaname(&sp, argv[1], ep)) == NULL) {
+ if ((newnp = metaname(&sp, argv[1], UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
- if (cflag) { /* new replace stuff */
- if (meta_replace(sp, namep, oldnp, newnp, uname,
- options, ep) != 0) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
- } else {
- if (meta_replace_byname(sp, namep, oldnp, newnp,
- options, ep) != 0) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
+ if (meta_replace_byname(sp, namep, oldnp, newnp,
+ options, ep) != 0) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
}
}
diff --git a/usr/src/cmd/lvm/util/metaroot.c b/usr/src/cmd/lvm/util/metaroot.c
index 796fe43aee..d523e46b3c 100644
--- a/usr/src/cmd/lvm/util/metaroot.c
+++ b/usr/src/cmd/lvm/util/metaroot.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -251,7 +250,7 @@ validate_root_device(
mde_perror(ep, "");
return (METAROOT_ERR);
}
- if ((rootnp = metaname(&sp, curroot, ep)) == NULL) {
+ if ((rootnp = metaname(&sp, curroot, UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
return (METAROOT_ERR);
}
@@ -412,7 +411,7 @@ main(
}
/* get device name */
- if ((rootnp = metaname(&sp, argv[0], ep)) == NULL) {
+ if ((rootnp = metaname(&sp, argv[0], UNKNOWN, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
@@ -425,7 +424,7 @@ main(
* mounted as happens if this command is part of the install
* process, currootnp will be set to NULL.
*/
- currootnp = metaname(&sp, curroot, ep);
+ currootnp = metaname(&sp, curroot, UNKNOWN, ep);
/*
* If the argument is the name of the current root filesystem, then
* the command is allowed, otherwise check that the argument is
diff --git a/usr/src/cmd/lvm/util/metastat.c b/usr/src/cmd/lvm/util/metastat.c
index 7904fa3eab..f70948ff01 100644
--- a/usr/src/cmd/lvm/util/metastat.c
+++ b/usr/src/cmd/lvm/util/metastat.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -110,7 +109,7 @@ print_name(
options |= PRINT_SUBDEVS;
/* hotspare pool */
- if (is_hspname(uname)) {
+ if (is_existing_hsp(*spp, uname)) {
mdhspname_t *hspnamep;
/* get hotsparepool */
@@ -128,7 +127,7 @@ print_name(
}
/* get metadevice */
- if (((namep = metaname(spp, uname, ep)) == NULL) ||
+ if (((namep = metaname(spp, uname, META_DEVICE, ep)) == NULL) ||
(metachkmeta(namep, ep) != 0))
return (-1);
@@ -162,20 +161,20 @@ print_setstat(
)
{
int rval = -1;
+ char *cname = NULL;
char *cp = NULL;
md_gs_stat_parm_t gsp;
- /* create local set, if necessary */
- if (*spp == NULL) {
- if (fname != NULL && (cp = strchr(fname, '/')) != NULL)
- *cp = '\0';
- if (fname != NULL && (*spp = metasetname(fname, ep)) != NULL) {
- *cp = '/';
- } else {
- if ((*spp = metasetname(MD_LOCAL_NAME, ep)) == NULL)
- return (rval);
+ if (fname != NULL && strchr(fname, '/') != NULL) {
+ /* get the canonical name */
+ cname = meta_name_getname(spp, fname, META_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
+ mdclrerror(ep);
+ return (-1);
}
+ Free(cname);
}
if ((cp = getenv("MD_DEBUG")) == NULL)
@@ -264,7 +263,7 @@ usage(
)
{
(void) fprintf(stderr, gettext("\
-usage: %s [-s setname] [-a][-c][-B][-r][-i][-p] [-t] [metadevice...]\n"),
+usage: %s [-s setname] [-a][-c][-B][-D][-r][-i][-p] [-t] [metadevice...]\n"),
myname);
md_exit(sp, eval);
}
@@ -278,7 +277,7 @@ main(
char *argv[]
)
{
- char *sname = NULL;
+ char *sname = MD_LOCAL_NAME;
mdsetname_t *sp = NULL;
mdprtopts_t options = PRINT_HEADER | PRINT_DEVID | PRINT_FAST;
int c;
@@ -288,6 +287,7 @@ main(
int eval = 0;
int inquire = 0;
int quiet_flg = 0;
+ int set_flg = 0;
int error;
int all_sets_flag = 0;
int concise_flag = 0;
@@ -324,7 +324,7 @@ main(
/* parse arguments */
optind = 1;
opterr = 1;
- while ((c = getopt(argc, argv, "acSs:hpBrtiq?")) != -1) {
+ while ((c = getopt(argc, argv, "acSs:hpBDrtiq?")) != -1) {
switch (c) {
case 'a':
all_sets_flag++;
@@ -341,6 +341,7 @@ main(
case 's':
sname = optarg;
+ set_flg++;
break;
case 'h':
@@ -363,6 +364,9 @@ main(
case 'B':
options |= PRINT_LARGEDEVICES;
break;
+ case 'D':
+ options |= PRINT_FN;
+ break;
case 'r': /* defunct option */
break;
case 'q':
@@ -380,23 +384,16 @@ main(
argc -= optind;
argv += optind;
- if (sname != NULL) {
-
- if (all_sets_flag) {
- fprintf(stderr, gettext("metastat: "
- "incompatible options: -a and -s\n"));
- usage(sp, 1);
- }
+ if (all_sets_flag && set_flg) {
+ fprintf(stderr, gettext("metastat: "
+ "incompatible options: -a and -s\n"));
+ usage(sp, 1);
+ }
- if ((sp = metasetname(sname, ep)) == NULL) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
- } else {
- if ((sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
+ /* get set context */
+ if ((sp = metasetname(sname, ep)) == NULL) {
+ mde_perror(ep, "");
+ md_exit(sp, 1);
}
/* make sure that the mddb is not stale. Else print a warning */
@@ -453,26 +450,39 @@ main(
/* print named device types */
while (devcnt < argc) {
char *uname = argv[devcnt];
+ char *cname = NULL;
+
+ /* get the canonical name */
+ cname = meta_name_getname(&sp, uname, META_DEVICE, ep);
+ if (cname == NULL) {
+ /* already printed the error */
+ mdclrerror(ep);
+ eval = 1;
+ ++devcnt;
+ continue;
+ }
if (concise_flag) {
mdname_t *np;
- np = metaname(&sp, uname, ep);
+ np = metaname(&sp, cname, META_DEVICE, ep);
if (np == NULL) {
mde_perror(ep, "");
mdclrerror(ep);
+ eval = 1;
} else {
print_concise_md(0, sp, np);
}
} else {
- if (print_name(&sp, uname, &nlistp, NULL, stdout, options,
+ if (print_name(&sp, cname, &nlistp, NULL, stdout, options,
&meta_print_trans_msg, &lognlp, ep) != 0) {
mde_perror(ep, "");
mdclrerror(ep);
eval = 1;
}
}
+ Free(cname);
++devcnt;
}
@@ -482,14 +492,24 @@ main(
while (devcnt < argc) {
char *uname = argv[devcnt];
+ char *cname = NULL;
+
+ /* get the canonical name */
+ cname = meta_name_getname(&sp, uname, META_DEVICE, ep);
+ if (cname == NULL) {
+ mde_perror(ep, "");
+ mdclrerror(ep);
+ ++devcnt;
+ continue;
+ }
/* hotspare pools */
- if (is_hspname(uname)) {
+ if (is_existing_hsp(sp, cname)) {
mdhspname_t *hspnamep;
md_hsp_t *hsp;
/* get hotsparepool */
- if ((hspnamep = metahspname(&sp, uname,
+ if ((hspnamep = metahspname(&sp, cname,
ep)) == NULL)
eval = 1;
@@ -504,7 +524,8 @@ main(
namep = hsp->hotspares.
hotspares_val[hsi].hsnamep;
- if (!(options & PRINT_LARGEDEVICES)) {
+ if (!(options &
+ (PRINT_LARGEDEVICES | PRINT_FN))) {
/* meta_getdevs populates the */
/* nlistp structure for use */
if (meta_getdevs(sp, namep,
@@ -517,12 +538,13 @@ main(
} else {
/* get metadevice */
- if (((namep = metaname(&sp, uname,
- ep)) == NULL) ||
+ if (((namep = metaname(&sp, cname,
+ META_DEVICE, ep)) == NULL) ||
(metachkmeta(namep, ep) != 0))
eval = 1;
- if (!(options & PRINT_LARGEDEVICES)) {
+ if (!(options &
+ (PRINT_LARGEDEVICES | PRINT_FN))) {
/* meta_getdevs populates the */
/* nlistp structure for use */
if (meta_getdevs(sp, namep, &nlistp, ep)
@@ -530,7 +552,7 @@ main(
eval = 1;
}
}
-
+ Free(cname);
++devcnt;
}
if (print_devid(sp, nlistp, stdout, ep) != 0)
@@ -602,12 +624,6 @@ print_specific_set(mdsetname_t *sp, mdprtopts_t options, int concise_flag,
md_error_t *ep = &status;
int meta_print_trans_msg = 0;
- /* default to local set */
- if ((sp == NULL) && ((sp = metasetname(MD_LOCAL_NAME, ep)) == NULL)) {
- mde_perror(ep, "");
- md_exit(sp, 1);
- }
-
/* check for ownership */
assert(sp != NULL);
if (meta_check_ownership(sp, ep) != 0) {
@@ -638,7 +654,7 @@ print_specific_set(mdsetname_t *sp, mdprtopts_t options, int concise_flag,
* upgrade. Even if meta_getalldevs fails, the
* data in nlistp is still valid.
*/
- if (!(options & PRINT_LARGEDEVICES)) {
+ if (!(options & (PRINT_LARGEDEVICES | PRINT_FN))) {
(void) meta_getalldevs(sp, &nlistp, 0, ep);
}
if (nlistp != NULL) {
@@ -1164,7 +1180,7 @@ print_concise_diskset(mdsetname_t *sp)
md_sp_t *soft_part;
mdnamelist_t *tnlp;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE, &error);
mdclrerror(&error);
if (mdn == NULL) {
print_concise_entry(0, nlp->namep->cname, 0, 'p');
@@ -1195,7 +1211,9 @@ print_concise_diskset(mdsetname_t *sp)
for (tnlp = nlp->next; tnlp != NULL; tnlp = tnlp->next) {
md_sp_t *part;
- mdn = metaname(&sp, tnlp->namep->cname, &error);
+ mdn = metaname(&sp, tnlp->namep->cname,
+ META_DEVICE, &error);
+
mdclrerror(&error);
if (mdn == NULL)
continue;
@@ -1287,7 +1305,7 @@ print_concise_namelist(mdsetname_t *sp, mdnamelist_t **nl, char mtype)
mdname_t *mdn;
md_common_t *u;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE, &error);
mdclrerror(&error);
if (mdn == NULL) {
print_concise_entry(0, nlp->namep->cname, 0, mtype);
@@ -1672,7 +1690,7 @@ get_sm_state(md_mirror_t *mirror, int i, md_status_t mirror_status,
if (mirror_status & MD_UN_RESYNC_ACTIVE) {
- if (mirror->common.revision == MD_64BIT_META_DEV) {
+ if (mirror->common.revision & MD_64BIT_META_DEV) {
(void) snprintf(buf, sizeof (buf),
gettext("resync-%2d.%1d%%"),
mirror->percent_done / 10,
diff --git a/usr/src/cmd/lvm/util/metasync.c b/usr/src/cmd/lvm/util/metasync.c
index 28bf28cea7..e2b7ae70d8 100644
--- a/usr/src/cmd/lvm/util/metasync.c
+++ b/usr/src/cmd/lvm/util/metasync.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -236,7 +235,7 @@ main(
int result;
/* get device */
- if ((np = metaname(&sp, argv[0], ep)) == NULL) {
+ if ((np = metaname(&sp, argv[0], META_DEVICE, ep)) == NULL) {
mde_perror(ep, "");
rval = -1;
continue;
diff --git a/usr/src/cmd/lvm/util/metattach.c b/usr/src/cmd/lvm/util/metattach.c
index f0561bd54e..8bd9551053 100644
--- a/usr/src/cmd/lvm/util/metattach.c
+++ b/usr/src/cmd/lvm/util/metattach.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -163,7 +162,8 @@ stripe_attach(
usage(*spp, 1);
/* get list of components */
- if (metanamelist(spp, &compnlp, argc, argv, ep) < 0)
+ if (metanamelist(spp, &compnlp, argc, argv,
+ UNKNOWN, ep) < 0)
return (-1);
assert(compnlp != NULL);
for (p = compnlp; (p != NULL); p = p->next) {
@@ -256,7 +256,8 @@ raid_attach(
usage(*spp, 1);
/* get list of components */
- if (metanamelist(spp, &compnlp, argc, argv, ep) < 0)
+ if (metanamelist(spp, &compnlp, argc, argv,
+ UNKNOWN, ep) < 0)
return (-1);
assert(compnlp != NULL);
for (p = compnlp; (p != NULL); p = p->next) {
@@ -318,7 +319,8 @@ mirror_attach(
/* get submirror */
if (argc == 1) {
- if (((submirnp = metaname(spp, argv[0], ep)) == NULL) ||
+ if (((submirnp = metaname(spp, argv[0], META_DEVICE,
+ ep)) == NULL) ||
(metachkmeta(submirnp, ep) != 0)) {
return (-1);
}
@@ -427,7 +429,7 @@ main(
}
}
- if (((np = metaname(&sp, argv[optind], ep)) == NULL) ||
+ if (((np = metaname(&sp, argv[optind], META_DEVICE, ep)) == NULL) ||
(metachkmeta(np, ep) != 0)) {
mde_perror(ep, "");
md_exit(sp, 1);
diff --git a/usr/src/cmd/rcm_daemon/common/svm_rcm.c b/usr/src/cmd/rcm_daemon/common/svm_rcm.c
index c8c80a8f78..e522ff4f3c 100644
--- a/usr/src/cmd/rcm_daemon/common/svm_rcm.c
+++ b/usr/src/cmd/rcm_daemon/common/svm_rcm.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -72,6 +71,7 @@
*/
#define MSG_UNRECOGNIZED gettext("SVM: \"%s\" is not a SVM resource")
#define MSG_NODEPS gettext("SVM: can't find dependents")
+#define MSG_NORECACHE gettext("SVM: WARNING: couldn't re-cache.")
#define MSG_OPENERR gettext("SVM: can't open \"%s\"")
#define MSG_CACHEFAIL gettext("SVM: can't malloc cache")
@@ -120,7 +120,8 @@ typedef struct deventry {
struct deventry *next; /* next entry with same hash */
svm_type_t devtype; /* device type */
dev_t devkey; /* key */
- char *devname; /* name */
+ char *devname; /* name in /dev */
+ char *devicesname; /* name in /devices */
struct deventry *dependent; /* 1st dependent */
struct deventry *next_dep; /* next dependent */
struct deventry *antecedent; /* antecedent */
@@ -157,6 +158,7 @@ typedef struct cache {
static int svm_register(rcm_handle_t *hd);
static int svm_unregister(rcm_handle_t *hd);
+static int svm_unregister_device(rcm_handle_t *hd, deventry_t *d);
static deventry_t *cache_dependent(cache_t *cache, char *devname, int devflags,
deventry_t *dependents);
static deventry_t *cache_device(cache_t *cache, char *devname,
@@ -185,7 +187,7 @@ static char *cache_walk(cache_t *cache, uint32_t *i, deventry_t **hashline);
static void free_cache(cache_t **cache);
static void free_deventry(deventry_t **deventry);
static uint32_t hash(uint32_t h, char *s);
-static void register_device(rcm_handle_t *hd, char *devname);
+static void svm_register_device(rcm_handle_t *hd, char *devname);
static int add_dep(int *ndeps, char ***depsp, deventry_t *deventry);
static int get_dependents(deventry_t *deventry, char *** dependentsp);
char *add_to_usage(char ** usagep, char *string);
@@ -341,7 +343,7 @@ svm_register(rcm_handle_t *hd)
/* If not, register the whole cache and mark it as registered. */
while ((devicename = cache_walk(svm_cache, &i, &l)) != NULL) {
- register_device(hd, devicename);
+ svm_register_device(hd, devicename);
}
svm_cache->registered = 1;
@@ -369,7 +371,6 @@ svm_unregister(rcm_handle_t *hd)
{
deventry_t *l = NULL;
uint32_t i = 0;
- char *devicename;
rcm_log_message(RCM_TRACE1, "SVM: unregister\n");
/* Guard against bad arguments */
@@ -378,8 +379,8 @@ svm_unregister(rcm_handle_t *hd)
/* Walk the cache, unregistering everything */
(void) mutex_lock(&svm_cache_lock);
if (svm_cache != NULL) {
- while ((devicename = cache_walk(svm_cache, &i, &l)) != NULL) {
- (void) rcm_unregister_interest(hd, devicename, 0);
+ while (cache_walk(svm_cache, &i, &l) != NULL) {
+ (void) svm_unregister_device(hd, l);
}
svm_cache->registered = 0;
}
@@ -1599,7 +1600,8 @@ cache_all_devices_in_set(cache_t *cache, mdsetname_t *sp)
mdname_t *mdn;
md_trans_t *trans;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE,
+ &error);
if (mdn == NULL) {
continue;
}
@@ -1622,7 +1624,8 @@ cache_all_devices_in_set(cache_t *cache, mdsetname_t *sp)
mdname_t *mdn;
md_mirror_t *mirror;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE,
+ &error);
if (mdn == NULL) {
continue;
}
@@ -1645,7 +1648,8 @@ cache_all_devices_in_set(cache_t *cache, mdsetname_t *sp)
mdname_t *mdn;
md_raid_t *raid;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE,
+ &error);
if (mdn == NULL) {
continue;
}
@@ -1668,7 +1672,8 @@ cache_all_devices_in_set(cache_t *cache, mdsetname_t *sp)
mdname_t *mdn;
md_stripe_t *stripe;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE,
+ &error);
if (mdn == NULL) {
continue;
}
@@ -1691,7 +1696,8 @@ cache_all_devices_in_set(cache_t *cache, mdsetname_t *sp)
mdname_t *mdn;
md_sp_t *soft_part;
- mdn = metaname(&sp, nlp->namep->cname, &error);
+ mdn = metaname(&sp, nlp->namep->cname, META_DEVICE,
+ &error);
if (mdn == NULL) {
continue;
}
@@ -1844,14 +1850,16 @@ static deventry_t *
create_deventry(char *devname, svm_type_t devtype, md_dev64_t devkey,
int devflags)
{
- deventry_t *newdeventry;
- char *newdevname;
+ const char *devprefix = "/dev/";
+ deventry_t *newdeventry = NULL;
+ char *newdevname = NULL;
+ char *devicesname = NULL;
newdeventry = (deventry_t *)malloc(sizeof (*newdeventry));
if (newdeventry == NULL) {
rcm_log_message(RCM_ERROR,
gettext("SVM: can't malloc deventrys"));
- return (NULL);
+ goto errout;
}
(void) memset((char *)newdeventry, 0, sizeof (*newdeventry));
@@ -1859,16 +1867,55 @@ create_deventry(char *devname, svm_type_t devtype, md_dev64_t devkey,
if (newdevname == NULL) {
rcm_log_message(RCM_ERROR,
gettext("SVM: can't malloc devname"));
- free(newdeventry);
- return (NULL);
+ goto errout;
+ }
+
+ /*
+ * When we register interest in a name starting with /dev/, RCM
+ * will use realpath to convert the name to a /devices name before
+ * storing it. metaclear removes both the /dev and the /devices
+ * form of the name of a metadevice from the file system. Thus,
+ * when we later call rcm_unregister_interest to get rid of a
+ * metacleared device, RCM will not be able to derive the /devices
+ * name for the /dev name. Thus, to unregister we will need to use
+ * the /devices name. We will save it now, so that we have it when
+ * it comes time to unregister.
+ */
+ if (strncmp(devname, devprefix, strlen(devprefix)) == 0) {
+ devicesname = (char *)malloc(PATH_MAX);
+ if (devicesname == NULL) {
+ rcm_log_message(RCM_ERROR,
+ gettext("SVM: can't malloc PATH_MAX bytes"));
+ goto errout;
+ }
+ if (realpath(devname, devicesname) == NULL) {
+ free(devicesname);
+ devicesname = NULL;
+ }
}
newdeventry->devname = newdevname;
+ newdeventry->devicesname = devicesname;
newdeventry->devtype = devtype;
newdeventry->devkey = meta_cmpldev(devkey);
newdeventry->flags = devflags;
- rcm_log_message(RCM_TRACE1,
- "SVM created deventry for %s\n", newdeventry->devname);
+ if (newdeventry->devicesname == NULL) {
+ rcm_log_message(RCM_TRACE1,
+ "SVM created deventry for %s\n", newdeventry->devname);
+ } else {
+ rcm_log_message(RCM_TRACE1,
+ "SVM created deventry for %s (%s)\n",
+ newdeventry->devname, newdeventry->devicesname);
+ }
return (newdeventry);
+
+errout:
+ if (devicesname != NULL)
+ free(devicesname);
+ if (newdevname != NULL)
+ free(newdevname);
+ if (newdeventry != NULL)
+ free(newdeventry);
+ return (NULL);
}
/*
@@ -1991,7 +2038,40 @@ cache_lookup(cache_t *cache, char *devname)
/*
* cache_sync()
*
- * Resync cache with the svm database
+ * Resync cache with the svm database. First a new cache is created
+ * that represents the current state of the SVM database. The
+ * function walks the new cache to look for new entries that must be
+ * registered. The new entries are kept in a list, because we cannot
+ * register them at this point. Entries that appear in both caches
+ * are removed from the old cache. Because of this at the end of the
+ * walk, the old cache will only contain devices that have been
+ * removed and need to be unregistered.
+ *
+ * Next the old cache is walked, so that we can unregister the devices
+ * that are no longer present.
+ *
+ * Finally, we process the list of new devices that must be
+ * registered. There is a reason why we must unregister the removed
+ * (metacleared) devices before registering the new ones. It has to
+ * do with the fact that rcm_register_interest calls realpath(3C) to
+ * convert a /dev name to a /devices name. It uses the /devices name
+ * for storing the device information.
+ *
+ * It can happen that between cache_syncs that the administrator
+ * metaclears one metadevice and metacreates a new one. For example,
+ *
+ * metaclear acct
+ * metainit engr 1 1 c1t12d0s0
+ *
+ * The metaclear operation frees up the minor number that was being
+ * used by acct. The metainit operation can then reuse the minor
+ * number. This means that both metadevices would have the same
+ * /devices name even though they had different /dev names. Since
+ * rcm_register_interest uses /devices names for storing records, we
+ * need to unregister acct before registering engr. Otherwise we
+ * would get an EALREADY errno and a failed registration. This is why
+ * cache_sync creates a list of devices to be registered after all the
+ * removed devices have been unregistered.
*
* Input:
* rcm_handle_t *hd rcm handle
@@ -2009,17 +2089,24 @@ cache_sync(rcm_handle_t *hd, cache_t **cachep)
cache_t *new_cache;
cache_t *old_cache = *cachep;
deventry_t *hashline = NULL;
+ deventry_t **register_list = NULL;
+ deventry_t *register_this;
+ uint32_t register_count = 0; /* # entrys in register_list */
+ uint32_t allocated = 0; /* # entrys allocated in */
+ /* register_list */
+ uint32_t allocate_incr = 16;
uint32_t i = 0;
/* Get a new cache */
if ((new_cache = create_cache()) == NULL) {
- rcm_log_message(RCM_WARNING,
- gettext("SVM: WARNING: couldn't re-cache."));
+ rcm_log_message(RCM_WARNING, MSG_NORECACHE);
return;
}
/* For every entry in the new cache... */
while ((devicename = cache_walk(new_cache, &i, &hashline)) != NULL) {
+ register_this = NULL;
+
/* Look for this entry in the old cache */
deventry = cache_lookup(old_cache, devicename);
/*
@@ -2028,12 +2115,32 @@ cache_sync(rcm_handle_t *hd, cache_t **cachep)
* again and remove it from the old cache
*/
if (deventry == NULL) {
- register_device(hd, hashline->devname);
+ register_this = hashline;
} else {
if (deventry->flags&REMOVED)
- register_device(hd, hashline->devname);
+ register_this = hashline;
cache_remove(old_cache, deventry);
}
+
+ /* Save this entry if we need to register it later. */
+ if (register_this) {
+ if (register_count >= allocated) {
+ /* Need to extend our array */
+ allocated += allocate_incr;
+ register_list =
+ (deventry_t **)realloc(register_list,
+ allocated * sizeof (*register_list));
+ if (register_list == NULL) {
+ /* Out of memory. Give up. */
+ rcm_log_message(RCM_WARNING,
+ MSG_NORECACHE);
+ free(new_cache);
+ return;
+ }
+ }
+ *(register_list + register_count) = register_this;
+ register_count++;
+ }
}
/*
@@ -2044,10 +2151,18 @@ cache_sync(rcm_handle_t *hd, cache_t **cachep)
hashline = NULL;
while ((devicename = cache_walk(old_cache, &i, &hashline)) != NULL) {
if (!(hashline->flags&REMOVED)) {
- (void) rcm_unregister_interest(hd, devicename, 0);
+ (void) svm_unregister_device(hd, hashline);
}
}
+ /* Register the new devices. */
+ for (i = 0; i < register_count; i++) {
+ deventry = *(register_list + i);
+ svm_register_device(hd, deventry->devname);
+ }
+ if (register_list)
+ free(register_list);
+
/* Swap pointers */
*cachep = new_cache;
@@ -2204,6 +2319,8 @@ free_deventry(deventry_t **deventry)
free(oldhspentry);
}
}
+ if ((*deventry)->devicesname)
+ free((*deventry)->devicesname);
free((*deventry)->devname);
free (*deventry);
*deventry = olddeventry;
@@ -2240,7 +2357,7 @@ hash(uint32_t h, char *s)
}
/*
- * register_device()
+ * svm_register_device()
*
* Register a device
*
@@ -2251,7 +2368,7 @@ hash(uint32_t h, char *s)
* Locking: None
*/
static void
-register_device(rcm_handle_t *hd, char *devname)
+svm_register_device(rcm_handle_t *hd, char *devname)
{
/* Sanity check */
if (devname == NULL)
@@ -2840,7 +2957,6 @@ check_device(deventry_t *deventry)
mdsetname_t *sp;
md_error_t error = mdnullerror;
char sname[BUFSIZ+1];
- uint32_t d;
mdname_t *np;
deventry_t *dependent;
int rval = NOTREDUNDANT;
@@ -2871,10 +2987,10 @@ check_device(deventry_t *deventry)
* it contains a setname.
*/
ret = sscanf(dependent->devname,
- "/dev/md/%" VAL2STR(BUFSIZ) "[^/]/dsk/d%u",
- sname, &d);
+ "/dev/md/%" VAL2STR(BUFSIZ) "[^/]/dsk/",
+ sname);
- if (ret != 2)
+ if (ret != 1)
(void) strcpy(sname, MD_LOCAL_NAME);
if ((sp = metasetname(sname, &error)) == NULL) {
@@ -2887,7 +3003,7 @@ check_device(deventry_t *deventry)
rcm_log_message(RCM_TRACE1, "SVM: processing: %s\n",
dependent->devname);
- np = metaname(&sp, dependent->devname, &error);
+ np = metaname(&sp, dependent->devname, META_DEVICE, &error);
switch (dependent->devtype) {
case SVM_TRANS:
@@ -2943,3 +3059,66 @@ check_device(deventry_t *deventry)
rcm_log_message(RCM_TRACE1, "SVM: check_device return %d\n", rval);
return (rval);
}
+
+/*
+ * svm_unregister_device
+ *
+ * Unregister the device specified by the deventry
+ *
+ * Input:
+ * rcm_handle_t * information for RCM
+ * deventry_t * description of the device to be
+ * unregistered
+ *
+ * Return:
+ * int 0 - successfully unregistered
+ * != 0 - failed to unregister
+ *
+ * Locking:
+ * None
+ *
+ * If the deventry_t has a devicesname, we will first attempt to unregister
+ * using that name. If that fails then we'll attempt to unregister using
+ * devname. The reason for this strategy has to do with the way that
+ * rcm_register_interest works. If passed a /dev/ name,
+ * rcm_register_interest uses realpath() to convert it to a /devices name.
+ * Thus, we are more likely to succeed if we use devicesname first.
+ */
+
+static int
+svm_unregister_device(rcm_handle_t *hd, deventry_t *d)
+{
+ int deleted;
+
+ if (d->devicesname) {
+ rcm_log_message(RCM_TRACE1, "SVM: unregister_device %s (%s)\n",
+ d->devname, d->devicesname);
+ } else {
+ rcm_log_message(RCM_TRACE1, "SVM: unregister_device %s\n",
+ d->devname);
+ }
+ deleted = -1;
+ if (d->devicesname != NULL) {
+ /*
+ * Try to unregister via the /devices entry first. RCM
+ * converts /dev/ entries to /devices entries before
+ * storing them. Thus, if this item has a /devices name
+ * available, we should use it for unregistering.
+ */
+ deleted = rcm_unregister_interest(hd,
+ d->devicesname, 0);
+ }
+ if (deleted != 0) {
+ /*
+ * Either we did not have a /devices name or the attempt to
+ * unregister using the /devices name failed. Either way
+ * we'll now try to unregister using the conventional name.
+ */
+ deleted = rcm_unregister_interest(hd, d->devname, 0);
+ }
+ if (deleted != 0) {
+ rcm_log_message(RCM_TRACE1, "SVM: unregister_device failed "
+ "for %s\n", d->devname);
+ }
+ return (deleted);
+}