2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <stdarg.h>
2N/A#include <ctype.h>
2N/A#include <sys/fcntl.h>
2N/A#include <sys/types.h>
2N/A#include <devid.h>
2N/A#include <ftw.h>
2N/A#include <string.h>
2N/A#include <mdiox.h>
2N/A#include <sys/lvm/mdio.h>
2N/A#include <meta.h>
2N/A#include <syslog.h>
2N/A#include <sdssc.h>
2N/A#include <libdevinfo.h>
2N/A#include "meta_set_prv.h"
2N/A
2N/A/*
2N/A * Just in case we're not in a build environment, make sure that
2N/A * TEXT_DOMAIN gets set to something.
2N/A */
2N/A#if !defined(TEXT_DOMAIN)
2N/A#define TEXT_DOMAIN "SYS_TEST"
2N/A#endif
2N/A
2N/A#define RAW_PATH 0x001 /* rdsk */
2N/A#define BLOCK_PATH 0x002 /* dsk */
2N/A#define DSK_TYPE 0x004 /* normal /dev/[r]dsk */
2N/A#define TEST_TYPE 0x008 /* test driver path */
2N/A#define DID_TYPE 0x010 /* cluster did path */
2N/A#define AP_TYPE 0x020 /* should be obsolete */
2N/A
2N/Atypedef struct path_list {
2N/A char *search_path;
2N/A char *search_type;
2N/A int path_type;
2N/A} path_list_t;
2N/A
2N/A/*
2N/A * A table of the supported path types - this should ideally be generated
2N/A * by reading the /etc/lvm/devpath file
2N/A */
2N/Astatic path_list_t plist[] = {
2N/A {"/dev/rdsk", DEVID_MINOR_NAME_ALL_CHR, RAW_PATH|DSK_TYPE},
2N/A {"/dev/dsk", DEVID_MINOR_NAME_ALL_BLK, BLOCK_PATH|DSK_TYPE},
2N/A {"/dev/did/rdsk", DEVID_MINOR_NAME_ALL_CHR, RAW_PATH|DID_TYPE},
2N/A {"/dev/did/dsk", DEVID_MINOR_NAME_ALL_BLK, BLOCK_PATH|DID_TYPE},
2N/A {"/dev/td/dsk", DEVID_MINOR_NAME_ALL_BLK, BLOCK_PATH|TEST_TYPE},
2N/A {"/dev/td/rdsk", DEVID_MINOR_NAME_ALL_CHR, RAW_PATH|TEST_TYPE},
2N/A};
2N/Astatic int num = sizeof (plist)/sizeof (path_list_t);
2N/A
2N/Astatic mddevopts_t dev_options = 0;
2N/A
2N/A/* indicate whether to print an error message or not */
2N/Astatic int firsttime = 1;
2N/A
2N/A#define DEV_MATCH 0x1
2N/A#define NAME_MATCH 0x2
2N/A
2N/A#define DEBUGON 1
2N/A#define DEBUGOFF 2
2N/A
2N/A/*
2N/A * Debug function: to turn on devadm function debugging include DEVADM
2N/A * in the MD_DEBUG enviroment variable: MD_DEBUG=...,DEVADM...
2N/A */
2N/A/*PRINTFLIKE1*/
2N/Astatic void
2N/Amda_debug(char *format, ...)
2N/A{
2N/A char *p;
2N/A static int debug_set = 0;
2N/A va_list ap;
2N/A
2N/A if (debug_set == 0) {
2N/A if (((p = getenv("MD_DEBUG")) != NULL) &&
2N/A (strstr(p, "DEVADM") != NULL))
2N/A debug_set = DEBUGON;
2N/A else
2N/A debug_set = DEBUGOFF;
2N/A }
2N/A if (debug_set == DEBUGON) {
2N/A va_start(ap, format);
2N/A (void) vfprintf(stderr, format, ap);
2N/A va_end(ap);
2N/A }
2N/A}
2N/A
2N/A/* print error messages to the terminal or syslog */
2N/A/*PRINTFLIKE1*/
2N/Astatic void
2N/Amda_print(char *message, ...)
2N/A{
2N/A va_list ap;
2N/A
2N/A va_start(ap, message);
2N/A if (dev_options & DEV_LOG) {
2N/A /*
2N/A * The program is a daemon in the sense that it
2N/A * is a system utility.
2N/A */
2N/A (void) vsyslog((LOG_ERR | LOG_DAEMON), message, ap);
2N/A } else {
2N/A (void) vfprintf(stderr, message, ap);
2N/A }
2N/A va_end(ap);
2N/A}
2N/A
2N/A/*
2N/A * Utility to find the correct options to use for the devid search
2N/A * based upon the path of the device.
2N/A *
2N/A * RETURN:
2N/A * -1 Error, the path passed in is not in the table
2N/A * >= 0 The element number for the options within the table
2N/A */
2N/Astatic int
2N/Amda_findpath(char *path)
2N/A{
2N/A int i = 0;
2N/A
2N/A for (i = 0; i < num; i++) {
2N/A if (strncmp(plist[i].search_path, path,
2N/A strlen(plist[i].search_path)) == 0)
2N/A return (i);
2N/A }
2N/A return (-1);
2N/A}
2N/A
2N/A/*
2N/A * Utility to get the path of a device
2N/A */
2N/Astatic char *
2N/Amda_getpath(char *devname)
2N/A{
2N/A char *ptr;
2N/A char *pathname;
2N/A size_t len;
2N/A
2N/A if ((ptr = strrchr(devname, '/')) == NULL) {
2N/A mda_debug("Invalid format: %s\n", devname);
2N/A return (NULL);
2N/A }
2N/A ptr++;
2N/A len = strlen(devname) - strlen(ptr);
2N/A pathname = Malloc(len + 1);
2N/A (void) strncpy(pathname, devname, len);
2N/A pathname[len] = '\0';
2N/A return (pathname);
2N/A}
2N/A
2N/A/*
2N/A * meta_update_devtree -- Update the /dev/md namespace for metadevices.
2N/A *
2N/A * Only update the specific link if a valid minor(not NODEV) is given.
2N/A * Otherwise, update the entire /dev/md .
2N/A */
2N/A
2N/Aint
2N/Ameta_update_devtree(minor_t mnum)
2N/A{
2N/A char nodename[40];
2N/A di_devlink_handle_t hdl;
2N/A
2N/A /*
2N/A * di_devlink_init() returns once the /dev links have been
2N/A * updated(created or removed). If di_devlink_init returns
2N/A * a NULL, the link operation failed.
2N/A *
2N/A * Use the enhanced di_devlink_init interface if the mnum
2N/A * is available.
2N/A */
2N/A if (mnum == NODEV) {
2N/A /*
2N/A * NOTE: This will take a _long_ time for large numbers
2N/A * of metadevices.
2N/A */
2N/A hdl = di_devlink_init("md", DI_MAKE_LINK);
2N/A } else {
2N/A /* Call di_devlink_init twice, for block and raw devices */
2N/A (void) sprintf(nodename, "/pseudo/md@0:%lu,%lu,raw",
2N/A MD_MIN2SET(mnum), MD_MIN2UNIT(mnum));
2N/A hdl = di_devlink_init(nodename, DI_MAKE_LINK);
2N/A
2N/A if (hdl == NULL)
2N/A return (-1);
2N/A else
2N/A (void) di_devlink_fini(&hdl);
2N/A
2N/A (void) sprintf(nodename, "/pseudo/md@0:%lu,%lu,blk",
2N/A MD_MIN2SET(mnum), MD_MIN2UNIT(mnum));
2N/A hdl = di_devlink_init(nodename, DI_MAKE_LINK);
2N/A }
2N/A
2N/A if (hdl != NULL) {
2N/A (void) di_devlink_fini(&hdl);
2N/A return (0);
2N/A }
2N/A
2N/A return (-1);
2N/A}
2N/A
2N/A/*
2N/A * update_locator_namespace -- Contains the ioctl call that will update
2N/A * the ctds and pathname (ie. /dev/dsk etc) within the
2N/A * locator block namespace.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR ioctl failed and ep is updated with the error
2N/A * METADEVADM_SUCCESS success
2N/A */
2N/Astatic int
2N/Aupdate_locator_namespace(
2N/A set_t setno,
2N/A side_t sideno,
2N/A char *devname,
2N/A md_dev64_t dev,
2N/A char *pname,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A mdnm_params_t nm;
2N/A
2N/A (void) memset(&nm, '\0', sizeof (nm));
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = sideno;
2N/A nm.devname = (uintptr_t)devname;
2N/A nm.devname_len = strlen(devname);
2N/A nm.devt = dev;
2N/A nm.pathname = (uintptr_t)pname;
2N/A nm.pathname_len = strlen(pname);
2N/A if (metaioctl(MD_IOCUPD_LOCNM, &nm, &nm.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A return (METADEVADM_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * meta_update_namespace -- Contains the ioctl call that will update the
2N/A * device name and pathname in the namespace area.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR ioctl failed and ep is updated with the error
2N/A * METADEVADM_SUCCESS success
2N/A */
2N/Aint
2N/Ameta_update_namespace(
2N/A set_t setno,
2N/A side_t sideno,
2N/A char *devname,
2N/A md_dev64_t dev,
2N/A mdkey_t key,
2N/A char *pname,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A mdnm_params_t nm;
2N/A
2N/A (void) memset(&nm, '\0', sizeof (nm));
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = sideno;
2N/A nm.devname = (uintptr_t)devname;
2N/A nm.devname_len = strlen(devname);
2N/A nm.mnum = meta_getminor(dev);
2N/A nm.major = meta_getmajor(dev);
2N/A nm.key = key;
2N/A nm.pathname = (uintptr_t)pname;
2N/A nm.pathname_len = strlen(pname);
2N/A if (metaioctl(MD_IOCUPD_NM, &nm, &nm.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A return (METADEVADM_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * stripS - Strip s<digits> off the end of the ctds name if it exists
2N/A */
2N/Astatic void
2N/AstripS(char *name)
2N/A{
2N/A char *p;
2N/A
2N/A /* gobble number and 's' */
2N/A p = name + strlen(name) - 1;
2N/A for (; (p > name); --p) {
2N/A if (!isdigit(*p))
2N/A break;
2N/A }
2N/A
2N/A if (*p == 's') {
2N/A *p = '\0';
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * getdiskname -- to be used when scanning the input from the -u arg.
2N/A * This routine will strip off input that is anything but cxtxdx.
2N/A * ie. it will call stripS to get rid of slice info. Will also
2N/A * strip off /dev/dsk, /dev/rdsk, /dev/ap/dsk, /dev/ap/rdsk,
2N/A * /dev/did/dsk, or /dev/did/rdsk. The caller will need to free
2N/A * the return value.
2N/A *
2N/A * RETURN
2N/A * string that has the disk name in it ie. c0t0d0
2N/A */
2N/Astatic char *
2N/Agetdiskname(
2N/A char *name
2N/A)
2N/A{
2N/A char *p;
2N/A char *diskname;
2N/A
2N/A /* regular device */
2N/A if ((strncmp(name, "/dev/dsk/", strlen("/dev/dsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/dsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A if ((strncmp(name, "/dev/rdsk/", strlen("/dev/rdsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/rdsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A if ((strncmp(name, "/dev/ap/dsk/", strlen("/dev/ap/dsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/ap/dsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A if ((strncmp(name, "/dev/ap/rdsk/", strlen("/dev/ap/rdsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/ap/rdsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A if ((strncmp(name, "/dev/did/dsk/", strlen("/dev/did/dsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/did/dsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A if ((strncmp(name, "/dev/did/rdsk/", strlen("/dev/did/rdsk/")) == 0) &&
2N/A (strchr((p = name + strlen("/dev/did/rdsk/")), '/') == NULL)) {
2N/A diskname = Strdup(p);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A }
2N/A
2N/A diskname = Strdup(name);
2N/A stripS(diskname);
2N/A return (diskname);
2N/A}
2N/A
2N/A/*
2N/A * has_devid -- return the device ID for a given key
2N/A *
2N/A * RETURN
2N/A * NULL error
2N/A * devid devid found that corresponds to the given key.
2N/A */
2N/Astatic ddi_devid_t
2N/Ahas_devid(set_t setno, side_t sideno, mdkey_t key, md_error_t *ep)
2N/A{
2N/A return (meta_getdidbykey(setno, sideno, key, ep));
2N/A}
2N/A
2N/A/*
2N/A * Go through the existing list of replicas and check to see
2N/A * if their disk has moved, if so update the replica list
2N/A *
2N/A * RETURN
2N/A * -1 error
2N/A * 0 success
2N/A */
2N/Astatic int
2N/Afix_replicanames(
2N/A mdsetname_t *sp,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A md_replicalist_t *rlp = NULL;
2N/A md_replicalist_t *rl;
2N/A int ret = -1;
2N/A int match_type = 0;
2N/A devid_nmlist_t *disklist = NULL;
2N/A dev_t small_dev = (dev_t)NODEV;
2N/A side_t sideno;
2N/A set_t setno = sp->setno;
2N/A char *search_path;
2N/A int search_number;
2N/A char *ctds_name;
2N/A char *path_name;
2N/A int i;
2N/A
2N/A sideno = getmyside(sp, ep);
2N/A if (sideno == MD_SIDEWILD) {
2N/A mda_debug("Failed to find the side number\n");
2N/A return (-1);
2N/A }
2N/A
2N/A if (metareplicalist(sp, MD_BASICNAME_OK | PRINT_FAST, &rlp, ep) < 0) {
2N/A mda_debug("Unable to get a list of replicas\n");
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A for (rl = rlp; (rl != NULL); rl = rl->rl_next) {
2N/A md_replica_t *r = rl->rl_repp;
2N/A
2N/A small_dev = meta_cmpldev(r->r_namep->dev);
2N/A search_number = mda_findpath(r->r_namep->bname);
2N/A if (search_number == -1) {
2N/A mda_debug("replica update: invalid path: %s",
2N/A r->r_namep->bname);
2N/A continue;
2N/A } else {
2N/A search_path = plist[search_number].search_path;
2N/A }
2N/A
2N/A if (r->r_devid == NULL)
2N/A continue;
2N/A
2N/A ret = meta_deviceid_to_nmlist(search_path, r->r_devid,
2N/A r->r_minor_name, &disklist);
2N/A
2N/A mda_debug("replica update: search_path %s\n", search_path);
2N/A
2N/A if (ret != 0) {
2N/A /*
2N/A * Failed to find the disk, nothing can be done.
2N/A * The replica will be marked as bad later.
2N/A */
2N/A mda_debug("replica update: failed to find disk %s\n",
2N/A r->r_namep->cname);
2N/A continue;
2N/A }
2N/A mda_debug("replica update: current %s (%p)\n",
2N/A r->r_namep->bname, (void *) small_dev);
2N/A
2N/A /*
2N/A * Check to see if the returned disk matches the stored one
2N/A */
2N/A for (i = 0; disklist[i].dev != NODEV; i++) {
2N/A match_type = 0;
2N/A
2N/A mda_debug("replica update: devid list: %s (%p)\n",
2N/A disklist[i].devname, (void *) disklist[i].dev);
2N/A
2N/A if (disklist[i].dev == small_dev) {
2N/A match_type |= DEV_MATCH;
2N/A }
2N/A
2N/A if (strncmp(r->r_namep->bname, disklist[i].devname,
2N/A strlen(r->r_namep->bname)) == 0) {
2N/A match_type |= NAME_MATCH;
2N/A }
2N/A
2N/A /*
2N/A * break out if some sort of match is found because
2N/A * we already match on the devid.
2N/A */
2N/A if (match_type != 0)
2N/A break;
2N/A }
2N/A
2N/A mda_debug("fix_replicanames: match: %x i: %d\n", match_type, i);
2N/A
2N/A if (match_type == (DEV_MATCH|NAME_MATCH)) {
2N/A /* no change */
2N/A mda_debug("replica update: no change %s\n",
2N/A disklist[i].devname);
2N/A devid_free_nmlist(disklist);
2N/A continue;
2N/A }
2N/A
2N/A /* No match found - use the first entry in disklist */
2N/A if (disklist[i].dev == NODEV)
2N/A i = 0;
2N/A
2N/A mda_debug("replica update: reloading %s %p\n",
2N/A disklist[i].devname,
2N/A (void *)(uintptr_t)meta_expldev(disklist[i].dev));
2N/A
2N/A if (firsttime) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Disk movement detected\n"));
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Updating device names in Solaris Volume "
2N/A "Manager\n"));
2N/A firsttime = 0;
2N/A }
2N/A
2N/A if (dev_options & DEV_VERBOSE) {
2N/A char *devidstr;
2N/A
2N/A devidstr =
2N/A devid_str_encode(r->r_devid, r->r_minor_name);
2N/A if (devidstr == NULL) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Failed to encode the devid\n"));
2N/A continue;
2N/A }
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s changed to %s from device relocation "
2N/A "information %s\n"),
2N/A (char *)r->r_namep->cname, disklist[i].devname,
2N/A devidstr);
2N/A }
2N/A
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A mda_debug("Updating locator name\n");
2N/A ctds_name = strrchr(disklist[i].devname, '/');
2N/A ctds_name++;
2N/A if ((path_name = mda_getpath(disklist[i].devname))
2N/A == NULL) {
2N/A continue;
2N/A }
2N/A if (update_locator_namespace(setno, sideno,
2N/A ctds_name, meta_expldev(disklist[i].dev),
2N/A path_name, ep) != 0) {
2N/A mda_debug("replica update: ioctl failed\n");
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Failed to update locator "
2N/A "namespace on change from %s "
2N/A "to %s\n"), ctds_name,
2N/A disklist[i].devname);
2N/A }
2N/A }
2N/A }
2N/A Free(path_name);
2N/A devid_free_nmlist(disklist);
2N/A }
2N/A metafreereplicalist(rlp);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * pathname_reload - main function for the -r option. Will reload the
2N/A * pathname in both the main namespace and the locator namespace.
2N/A * Also, checks both areas for invalid device ID's and prints them
2N/A * out.
2N/A *
2N/A * If the set is a multi-node diskset that means there are no devid's
2N/A * so just return.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR error
2N/A * METADEVADM_SUCCESS success
2N/A * METADEVADM_DEVIDINVALID success, but invalid devids detected
2N/A */
2N/Aint
2N/Apathname_reload(
2N/A mdsetname_t **spp,
2N/A set_t setno,
2N/A md_error_t *ep)
2N/A{
2N/A char *drvnmp;
2N/A minor_t mnum = 0;
2N/A md_dev64_t dev = 0;
2N/A mdnm_params_t nm;
2N/A char *ctds_name;
2N/A ddi_devid_t devidp;
2N/A md_i_didstat_t ds;
2N/A side_t sideno;
2N/A char *search_path = NULL;
2N/A int search_number;
2N/A devid_nmlist_t *disklist = NULL;
2N/A char *minor_name = NULL;
2N/A char *devidstr = NULL;
2N/A char *path = NULL;
2N/A int ret;
2N/A dev_t small_dev = (dev_t)NODEV;
2N/A int match_type;
2N/A char *tmp = NULL;
2N/A int i;
2N/A
2N/A /*
2N/A * Get the entry of the namespace via the key. To do this
2N/A * call MD_IOCNXTKEY until no more.
2N/A * For each entry in the namespace we want to check
2N/A * for devid and update
2N/A */
2N/A
2N/A (void) memset(&nm, '\0', sizeof (nm));
2N/A nm.key = MD_KEYWILD;
2N/A
2N/A sideno = getmyside(*spp, ep);
2N/A if (sideno == MD_SIDEWILD) {
2N/A /* failed to find this node in the set */
2N/A mda_debug("Failed to find the side number\n");
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A /* LINTED */
2N/A while (1) {
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = sideno;
2N/A /* look at each key in the namespace */
2N/A if (metaioctl(MD_IOCNXTKEY_NM, &nm, &nm.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A if (nm.key == MD_KEYWILD) {
2N/A /* no more entries */
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * get the nm entry using the key. Then check to see if
2N/A * there's a devid associated with this entry
2N/A * If not, go onto next key.
2N/A */
2N/A if ((nm.devname = (uintptr_t)meta_getnmentbykey(setno, sideno,
2N/A nm.key, &drvnmp, &mnum, &dev, ep)) == NULL) {
2N/A mda_debug("pathname_reload: no name for key: %d\n",
2N/A nm.key);
2N/A continue;
2N/A }
2N/A
2N/A mda_debug("pathname_reload: examining %s\n",
2N/A (char *)(uintptr_t)nm.devname);
2N/A
2N/A if ((devidp = has_devid(setno, sideno, nm.key, ep)) == NULL) {
2N/A /* metadevices do not have devid's in them */
2N/A mda_debug("pathname_reload: no devid for %s\n",
2N/A (char *)(uintptr_t)nm.devname);
2N/A /* Clear error if no devid and go to next nm entry */
2N/A mdclrerror(ep);
2N/A continue;
2N/A }
2N/A
2N/A if ((minor_name = meta_getdidminorbykey(setno, sideno,
2N/A nm.key, ep)) == NULL) {
2N/A /*
2N/A * In theory this is impossible because if the
2N/A * devidp is non-null then the minor_name has
2N/A * already been looked up.
2N/A */
2N/A mda_debug("No minor name for %s\n",
2N/A (char *)(uintptr_t)nm.devname);
2N/A free(devidp);
2N/A continue;
2N/A }
2N/A /*
2N/A * If there is a devid then we have a real device that
2N/A * could have moved.
2N/A */
2N/A devidstr = devid_str_encode(devidp, minor_name);
2N/A if (devidstr == NULL) {
2N/A mda_debug("Failed to encode the devid\n");
2N/A free(devidp);
2N/A continue;
2N/A }
2N/A mda_debug("devid: %s\n", devidstr);
2N/A
2N/A /*
2N/A * Find the search path that should be used. This is an
2N/A * optimization to try and prevent a search for the complete
2N/A * /dev namespace.
2N/A */
2N/A search_number = mda_findpath((char *)(uintptr_t)nm.devname);
2N/A if (search_number == -1) {
2N/A search_path = "/dev";
2N/A } else {
2N/A search_path = plist[search_number].search_path;
2N/A }
2N/A
2N/A /* now look for the disk name using the devid */
2N/A ret = meta_deviceid_to_nmlist(search_path, devidp,
2N/A minor_name, &disklist);
2N/A free(devidp);
2N/A
2N/A if (ret != 0) {
2N/A /*
2N/A * Failed to find the disk
2N/A */
2N/A devid_str_free(devidstr);
2N/A continue;
2N/A }
2N/A
2N/A small_dev = meta_cmpldev(dev);
2N/A mda_debug("Old device lookup: %s (%p)\n",
2N/A (char *)(uintptr_t)nm.devname, (void *)small_dev);
2N/A
2N/A /*
2N/A * Check to see if the returned disk matches the stored one
2N/A */
2N/A for (i = 0; disklist[i].dev != NODEV; i++) {
2N/A match_type = 0;
2N/A mda_debug("From devid lookup: %s (%p)\n",
2N/A (char *)disklist[i].devname,
2N/A (void *)disklist[i].dev);
2N/A
2N/A if (disklist[i].dev == small_dev) {
2N/A match_type |= DEV_MATCH;
2N/A }
2N/A
2N/A if (strncmp((char *)(uintptr_t)nm.devname,
2N/A disklist[i].devname,
2N/A strlen((char *)(uintptr_t)nm.devname)) == 0) {
2N/A mda_debug("Name match: %s and %s (%d)\n",
2N/A disklist[i].devname,
2N/A (char *)(uintptr_t)nm.devname,
2N/A strlen((char *)(uintptr_t)nm.devname));
2N/A match_type |= NAME_MATCH;
2N/A }
2N/A
2N/A if (match_type == (DEV_MATCH|NAME_MATCH))
2N/A break;
2N/A }
2N/A
2N/A if (match_type == (DEV_MATCH|NAME_MATCH)) {
2N/A /* no change */
2N/A devid_str_free(devidstr);
2N/A mda_debug("All matched %s\n", disklist[i].devname);
2N/A devid_free_nmlist(disklist);
2N/A continue;
2N/A }
2N/A
2N/A /* No match found - use the first entry in disklist */
2N/A i = 0;
2N/A
2N/A if (firsttime) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Disk movement detected\n"));
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Updating device names in "
2N/A "Solaris Volume Manager\n"));
2N/A firsttime = 0;
2N/A }
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s changed to %s from device relocation "
2N/A "information %s\n"),
2N/A (char *)(uintptr_t)nm.devname, disklist[i].devname,
2N/A devidstr);
2N/A }
2N/A devid_str_free(devidstr);
2N/A
2N/A /* need to build up the path of the disk */
2N/A if ((path = Strdup(disklist[i].devname)) == NULL) {
2N/A mda_debug("Failed to duplicate path: %s\n",
2N/A disklist[i].devname);
2N/A devid_free_nmlist(disklist);
2N/A continue;
2N/A }
2N/A if ((tmp = strrchr(path, '/')) == NULL) {
2N/A mda_debug("Failed to parse %s\n", path);
2N/A devid_free_nmlist(disklist);
2N/A Free(path);
2N/A continue;
2N/A }
2N/A tmp += sizeof (char);
2N/A *tmp = '\0';
2N/A
2N/A if ((ctds_name = strrchr(disklist[i].devname, '/')) == NULL) {
2N/A mda_debug("Failed to parse ctds name: %s\n",
2N/A disklist[i].devname);
2N/A devid_free_nmlist(disklist);
2N/A Free(path);
2N/A continue;
2N/A }
2N/A ctds_name += sizeof (char);
2N/A
2N/A mda_debug("Reloading disk %s %s %p\n",
2N/A ctds_name, path,
2N/A (void *)(uintptr_t)meta_expldev(disklist[i].dev));
2N/A
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A /* Something has changed so update the namespace */
2N/A if (meta_update_namespace(setno, sideno, ctds_name,
2N/A meta_expldev(disklist[i].dev), nm.key, path,
2N/A ep) != 0) {
2N/A mda_debug("Failed to update namespace\n");
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Failed to update namespace on "
2N/A "change from %s to %s\n"),
2N/A ctds_name, disklist[i].devname);
2N/A }
2N/A }
2N/A }
2N/A devid_free_nmlist(disklist);
2N/A Free(path);
2N/A }
2N/A
2N/A if (fix_replicanames(*spp, ep) == -1)
2N/A mda_debug("Failed to update replicas\n");
2N/A
2N/A /*
2N/A * check for invalid device id's
2N/A */
2N/A (void) memset(&ds, '\0', sizeof (ds));
2N/A ds.setno = setno;
2N/A ds.side = sideno;
2N/A ds.mode = MD_FIND_INVDID;
2N/A /* get count of number of invalid device id's */
2N/A if (metaioctl(MD_IOCDID_STAT, &ds, &ds.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &ds.mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A if (ds.cnt != 0) {
2N/A char *ctdptr, *ctdp;
2N/A /*
2N/A * we have some invalid device id's so we need to
2N/A * print them out
2N/A */
2N/A ds.mode = MD_GET_INVDID;
2N/A /* malloc buffer for kernel to place devid list into */
2N/A if ((ctdptr = (char *)Malloc((ds.cnt * ds.maxsz) + 1)) == 0) {
2N/A return (METADEVADM_ERR);
2N/A }
2N/A ds.ctdp = (uintptr_t)ctdptr;
2N/A /* get actual list of invalid device id's */
2N/A if (metaioctl(MD_IOCDID_STAT, &ds, &ds.mde, NULL) != 0) {
2N/A Free(ctdptr);
2N/A (void) mdstealerror(ep, &ds.mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A /* print out the invalid devid's */
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Invalid device relocation information "
2N/A "detected in Solaris Volume Manager\n"));
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Please check the status of the following disk(s):\n"));
2N/A ctdp = (char *)(uintptr_t)ds.ctdp;
2N/A while (*ctdp != NULL) {
2N/A mda_print("\t%s\n", ctdp);
2N/A ctdp += ds.maxsz;
2N/A }
2N/A Free(ctdptr);
2N/A return (METADEVADM_DEVIDINVALID);
2N/A }
2N/A return (METADEVADM_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * replica_update_devid - cycle through the replica list, rlp, and
2N/A * update the device ids on all of the replicas that are on the
2N/A * device specified by lp. A side effect is to update the value of
2N/A * cdevidpp to contain the character representation of the device
2N/A * id before updating if it is not already set.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR error
2N/A * METADEVADM_SUCCESS success
2N/A */
2N/Astatic int
2N/Areplica_update_devid(
2N/A md_replicalist_t *rlp,
2N/A mddrivename_t *dnp,
2N/A set_t setno,
2N/A char **cdevidpp,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A mddb_config_t db_c;
2N/A md_replicalist_t *rl;
2N/A ddi_devid_t devidp;
2N/A int ret;
2N/A
2N/A if (cdevidpp == NULL)
2N/A return (METADEVADM_ERR);
2N/A
2N/A ret = devid_str_decode(dnp->devid, &devidp, NULL);
2N/A if (ret != 0) {
2N/A /* failed to encode the devid */
2N/A mda_debug("Failed to decode %s into a valid devid\n",
2N/A dnp->devid);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A /* search replica list for give ctd name */
2N/A for (rl = rlp; (rl != NULL); rl = rl->rl_next) {
2N/A md_replica_t *r = rl->rl_repp;
2N/A mdname_t *rnp = r->r_namep;
2N/A
2N/A if (strncmp(rnp->cname, dnp->cname, strlen(dnp->cname)) == 0) {
2N/A
2N/A /* found the replica, now grab the devid */
2N/A if (*cdevidpp == NULL) {
2N/A *cdevidpp = devid_str_encode(r->r_devid, NULL);
2N/A }
2N/A
2N/A if (*cdevidpp == NULL) {
2N/A devid_free(devidp);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A mda_debug("Updating replica %s, set %d, old devid %s\n",
2N/A rnp->cname, setno, *cdevidpp);
2N/A
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Updating replica %s of set number %d from "
2N/A "device id %s to device id %s\n"),
2N/A rnp->cname, setno, *cdevidpp, dnp->devid);
2N/A }
2N/A
2N/A (void) memset(&db_c, '\0', sizeof (db_c));
2N/A
2N/A db_c.c_setno = setno;
2N/A db_c.c_devt = rnp->dev;
2N/A
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A
2N/A mda_debug("Updating replica\n");
2N/A
2N/A /*
2N/A * call into kernel to update lb
2N/A * namespace device id
2N/A * of given devt
2N/A */
2N/A if (metaioctl(MD_DB_SETDID, &db_c,
2N/A &db_c.c_mde, NULL) != 0) {
2N/A devid_free(devidp);
2N/A (void) mdstealerror(ep, &db_c.c_mde);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A }
2N/A
2N/A }
2N/A }
2N/A devid_free(devidp);
2N/A return (METADEVADM_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * devid_update -- main routine for the -u option. Will update both the
2N/A * namespace and the locator block with the correct devid for the
2N/A * disk specified.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR error
2N/A * METADEVADM_SUCCESS success
2N/A */
2N/Astatic int
2N/Adevid_update(
2N/A mdsetname_t **spp,
2N/A set_t setno,
2N/A char *ctd,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A md_drive_desc *dd, *ddp;
2N/A mddrivename_t *dnp;
2N/A mdnm_params_t nm;
2N/A ddi_devid_t devidp;
2N/A side_t side;
2N/A char *old_cdevidp = NULL;
2N/A md_replicalist_t *rlp = NULL;
2N/A int rval = METADEVADM_ERR;
2N/A mdname_t *np = NULL;
2N/A uint_t rep_slice;
2N/A char *pathname = NULL;
2N/A char *diskname = NULL;
2N/A int fd = -1;
2N/A int len;
2N/A char *fp;
2N/A
2N/A side = getmyside(*spp, ep);
2N/A if (side == MD_SIDEWILD) {
2N/A /* failed to find this node in the set */
2N/A mda_debug("Failed to find the side number\n");
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A if ((dnp = metadrivename(spp, ctd, ep)) == NULL) {
2N/A mda_debug("Failed to create a dnp for %s\n", ctd);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A if (dnp->devid == NULL) {
2N/A /*
2N/A * Disk does not have a devid! So cannot update the
2N/A * devid within the replica.
2N/A */
2N/A mda_debug("%s does not have a devid\n", dnp->cname);
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s does not have a device id. Cannot update "
2N/A "device id if none exists\n"), ctd);
2N/A }
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A mda_debug("Devid update to: %s\n", dnp->devid);
2N/A
2N/A /*
2N/A * Check if we own the set, if we do then do some processing
2N/A * on the replicas.
2N/A */
2N/A if (meta_check_ownership(*spp, ep) == 0) {
2N/A
2N/A /* get the replicas */
2N/A if (metareplicalist(*spp, MD_BASICNAME_OK | PRINT_FAST, &rlp,
2N/A ep) < 0)
2N/A return (METADEVADM_ERR);
2N/A
2N/A /* update the devids in the replicas if necessary */
2N/A if (replica_update_devid(rlp, dnp, setno, &old_cdevidp,
2N/A ep) != METADEVADM_SUCCESS) {
2N/A metafreereplicalist(rlp);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A metafreereplicalist(rlp);
2N/A }
2N/A
2N/A /*
2N/A * If this is not the LOCAL set then need to update the LOCAL
2N/A * replica with the new disk record.
2N/A */
2N/A
2N/A if (setno != MD_LOCAL_SET) {
2N/A mda_debug("Non-local set: %d side %d\n", setno, side);
2N/A
2N/A /*
2N/A * Need to find the disk record within the set and then
2N/A * update it.
2N/A */
2N/A if ((dd =
2N/A metaget_drivedesc(*spp, MD_FULLNAME_ONLY, ep)) == NULL) {
2N/A if (! mdisok(ep))
2N/A goto out;
2N/A /* no disks in the set - no point continuing */
2N/A mda_debug("No disks in diskset\n");
2N/A rval = METADEVADM_SUCCESS;
2N/A goto out;
2N/A }
2N/A
2N/A for (ddp = dd; ddp != NULL; ddp = ddp->dd_next) {
2N/A if (strncmp(ddp->dd_dnp->cname, dnp->cname,
2N/A strlen(dnp->cname)) == 0)
2N/A break;
2N/A }
2N/A
2N/A if (ddp == NULL) {
2N/A /* failed to finddisk in the set */
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s not found in set %s. Check your syntax\n"),
2N/A ctd, (*spp)->setname);
2N/A (void) mddserror(ep, MDE_DS_DRIVENOTINSET, setno, NULL,
2N/A ctd, (*spp)->setname);
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now figure out the correct slice, for a diskset the slice
2N/A * we care about is always the 'replica' slice.
2N/A */
2N/A if (meta_replicaslice(dnp, &rep_slice, ep) != 0) {
2N/A mda_debug("Unable to find replica slice for %s\n",
2N/A dnp->cname);
2N/A goto out;
2N/A }
2N/A
2N/A mda_debug("slice no: %d disk %s\n", rep_slice, dnp->cname);
2N/A
2N/A if ((np = metaslicename(dnp, rep_slice, ep)) == NULL) {
2N/A mda_debug("Unable to build namespace\n");
2N/A goto out;
2N/A }
2N/A
2N/A mda_debug("check: ctdname: %s\n", np->cname);
2N/A mda_debug("check: ctdname: %s\n", np->rname);
2N/A mda_debug("check: ctdname: %s\n", np->bname);
2N/A
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A
2N/A mda_debug("Updating record: key %d name %s\n",
2N/A ddp->dd_dnp->side_names_key, np->cname);
2N/A
2N/A pathname = mda_getpath(np->bname);
2N/A
2N/A if (meta_update_namespace(MD_LOCAL_SET, side + SKEW,
2N/A np->cname, np->dev, ddp->dd_dnp->side_names_key,
2N/A pathname, ep) != 0) {
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Now update the devid entry as well, this works
2N/A * correctly because the prior call to
2N/A * meta_update_namespace() above puts the correct dev_t
2N/A * in the namespace which will then be resolved
2N/A * to the new devid by the ioctl now called.
2N/A */
2N/A nm.mde = mdnullerror;
2N/A nm.setno = MD_LOCAL_SET;
2N/A nm.side = side + SKEW;
2N/A nm.key = ddp->dd_dnp->side_names_key;
2N/A if (metaioctl(MD_SETNMDID, &nm, &nm.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A goto out;
2N/A }
2N/A }
2N/A }
2N/A
2N/A if ((dev_options & DEV_LOCAL_SET) && (setno != MD_LOCAL_SET)) {
2N/A /*
2N/A * Only want to update the local set so do not continue.
2N/A */
2N/A rval = METADEVADM_SUCCESS;
2N/A goto out;
2N/A }
2N/A
2N/A /*
2N/A * Iterate through all of the metadevices looking for the
2N/A * passed in ctd. If found then update the devid
2N/A */
2N/A (void) memset(&nm, '\0', sizeof (nm));
2N/A nm.key = MD_KEYWILD;
2N/A /* LINTED */
2N/A while (1) {
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = side;
2N/A
2N/A /* search each namespace entry */
2N/A if (metaioctl(MD_IOCNXTKEY_NM, &nm, &nm.mde, NULL) != 0) {
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A rval = METADEVADM_ERR;
2N/A goto out;
2N/A }
2N/A if (nm.key == MD_KEYWILD) {
2N/A if (setno != MD_LOCAL_SET) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s not found in set %s. Check your "
2N/A "syntax\n"), ctd, (*spp)->setname);
2N/A goto out;
2N/A } else {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s not found in local set. "
2N/A "Check your syntax\n"), ctd);
2N/A goto out;
2N/A }
2N/A }
2N/A
2N/A nm.devname = (uintptr_t)meta_getnmentbykey(setno, side, nm.key,
2N/A NULL, NULL, NULL, ep);
2N/A if (nm.devname == NULL) {
2N/A rval = METADEVADM_ERR;
2N/A goto out;
2N/A }
2N/A
2N/A diskname = getdiskname((char *)(uintptr_t)nm.devname);
2N/A
2N/A mda_debug("Checking %s with %s\n", diskname, dnp->cname);
2N/A if (strcmp(diskname, dnp->cname) != 0)
2N/A continue;
2N/A
2N/A mda_debug("Updating device %s in namespace\n",
2N/A (char *)(uintptr_t)nm.devname);
2N/A
2N/A /*
2N/A * found disk, does it have a devid within the namespace ?
2N/A * It might not because it does not support devid's or was
2N/A * put into the namespace when there was no devid support
2N/A */
2N/A if ((devidp = has_devid(setno, side, nm.key, ep)) == NULL) {
2N/A mda_debug("%s has no devid in the namespace",
2N/A (char *)(uintptr_t)nm.devname);
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "SVM has no device id for "
2N/A "%s, cannot update.\n"),
2N/A (char *)(uintptr_t)nm.devname);
2N/A }
2N/A continue; /* no devid. go on to next */
2N/A }
2N/A if (old_cdevidp == NULL) {
2N/A old_cdevidp = devid_str_encode(devidp, NULL);
2N/A }
2N/A free(devidp);
2N/A
2N/A /*
2N/A * has devid so update namespace, note the key has been set
2N/A * by the prior MD_IOCNXTKEY_NM ioctl.
2N/A */
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = side;
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A /*
2N/A * The call below may fail if the -u option is being
2N/A * used to update a disk that has been replaced.
2N/A * The -u option to metadevadm should not be used
2N/A * for this purpose because we trust the dev_t of
2N/A * the device in the replica and if we have replaced
2N/A * the device and it is a fibre one then the dev_t
2N/A * will have changed. This means we end up looking for
2N/A * the devid of a non-existant disk and we subsequently
2N/A * fail with NODEVID.
2N/A */
2N/A if (metaioctl(MD_SETNMDID, &nm,
2N/A &nm.mde, NULL) != 0) {
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "SVM failed to update the device "
2N/A "id for %s probably due to both "
2N/A "devt and device id changing.\n"),
2N/A (char *)(uintptr_t)nm.devname);
2N/A }
2N/A (void) mdstealerror(ep, &nm.mde);
2N/A mde_perror(ep, "");
2N/A rval = METADEVADM_ERR;
2N/A goto out;
2N/A }
2N/A }
2N/A if (old_cdevidp == NULL) {
2N/A rval = METADEVADM_ERR;
2N/A goto out;
2N/A }
2N/A break;
2N/A } /* end while */
2N/A
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Updating Solaris Volume Manager device relocation "
2N/A "information for %s\n"), ctd);
2N/A
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Old device reloc information:\n\t%s\n"), old_cdevidp);
2N/A
2N/A len = strlen(dnp->rname) + strlen("s0");
2N/A if ((fp = (char *)Malloc(len + 1)) == NULL) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "insufficient memory, device Reloc info not "
2N/A "available\n"));
2N/A } else {
2N/A (void) snprintf(fp, len + 1, "%ss0", dnp->rname);
2N/A if ((fd = open(fp, O_RDONLY|O_NDELAY)) < 0) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Open of %s failed\n"), fp);
2N/A } else {
2N/A int rc = -1;
2N/A ddi_devid_t devid1 = NULL;
2N/A char *cdevidp;
2N/A
2N/A rc = devid_get(fd, &devid1);
2N/A if (close(fd) < 0) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Close of %s failed\n"), fp);
2N/A }
2N/A if (rc != 0) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Unable to obtain device "
2N/A "Reloc info for %s\n"), fp);
2N/A } else {
2N/A cdevidp = devid_str_encode(devid1, NULL);
2N/A if (cdevidp == NULL) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Unable to print "
2N/A "device Reloc info for %s\n"), fp);
2N/A } else {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "New device reloc "
2N/A "information:\n\t%s\n"), cdevidp);
2N/A devid_str_free(cdevidp);
2N/A }
2N/A devid_free(devid1);
2N/A }
2N/A }
2N/A Free(fp);
2N/A }
2N/A
2N/A rval = METADEVADM_SUCCESS;
2N/A
2N/Aout:
2N/A if (diskname)
2N/A Free(diskname);
2N/A if (pathname)
2N/A Free(pathname);
2N/A if (old_cdevidp) {
2N/A devid_str_free(old_cdevidp);
2N/A }
2N/A return (rval);
2N/A
2N/A}
2N/A
2N/A/*
2N/A * Check the ctd name of the disk to see if the disk has moved. If it
2N/A * has moved then the newname is returned in 'newname', it is up to
2N/A * the caller to free the memory associated with it.
2N/A *
2N/A * RETURN
2N/A * METADEVADM_ERR error
2N/A * METADEVADM_SUCCESS success
2N/A * METADEVADM_DISKMOVE success, and the disk has moved
2N/A * METADEVADM_DSKNAME_ERR error creating the disk name structures.
2N/A */
2N/Aint
2N/Ameta_upd_ctdnames(
2N/A mdsetname_t **spp,
2N/A set_t setno,
2N/A side_t sideno,
2N/A int mn_set,
2N/A mddrivename_t *dnp,
2N/A char **newname,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A char *drvnmp;
2N/A int i;
2N/A minor_t mnum = 0;
2N/A md_dev64_t dev = 0;
2N/A dev_t small_dev = (dev_t)NODEV;
2N/A mdnm_params_t nm;
2N/A char *pathname;
2N/A char *minor_name = NULL;
2N/A ddi_devid_t devidp;
2N/A devid_nmlist_t *disklist = NULL;
2N/A int ret = 0;
2N/A mdsidenames_t *snp;
2N/A int match_type;
2N/A int search_number = -1;
2N/A char *search_type = NULL;
2N/A char *search_path = NULL;
2N/A uint_t rep_slice;
2N/A mddrivename_t *newdnp;
2N/A mdname_t *np;
2N/A mdsetname_t *sp = *spp;
2N/A md_set_desc *sd;
2N/A
2N/A if (!metaislocalset(sp)) {
2N/A mda_debug("Updating the ctd names for set: %s\n", sp->setname);
2N/A if ((sd = metaget_setdesc(sp, ep)) == NULL)
2N/A return (METADEVADM_ERR);
2N/A
2N/A if (MD_MNSET_DESC(sd))
2N/A mn_set = 1;
2N/A } else {
2N/A mda_debug("Updating the ctd names for the local set\n");
2N/A }
2N/A
2N/A if (dnp->devid == NULL) {
2N/A /* no devid, nothing can be done */
2N/A mda_debug("meta_upd_ctdnames: %s has no devid\n", dnp->cname);
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "%s has no devid, cannot detect "
2N/A "disk movement for this disk.\n"), dnp->cname);
2N/A }
2N/A return (ret);
2N/A }
2N/A
2N/A /*
2N/A * Find the correct side name for the disk. There is a sidename
2N/A * for each host associated with the diskset.
2N/A */
2N/A for (snp = dnp->side_names; snp != NULL; snp = snp->next) {
2N/A mda_debug("meta_upd_ctdnames: %s %d args: setno %d sideno %d\n",
2N/A snp->cname, snp->sideno, setno, sideno);
2N/A /*
2N/A * Only use SKEW for the local replica and for traditional
2N/A * disksets.
2N/A */
2N/A if (setno == 0 && mn_set == 0) {
2N/A if (snp->sideno + SKEW == sideno)
2N/A break;
2N/A } else {
2N/A if (snp->sideno == sideno)
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (snp == NULL) {
2N/A /*
2N/A * Failed to find the side name, this should not
2N/A * be possible. However if it does happen this is an
2N/A * indication of an inconsistant replica - something
2N/A * might have gone wrong during an add or a delete of
2N/A * a host.
2N/A */
2N/A mda_debug("Unable to find the side information for disk %s\n",
2N/A dnp->cname);
2N/A (void) mddserror(ep, MDE_DS_HOSTNOSIDE, (*spp)->setno, mynode(),
2N/A NULL, dnp->cname);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A /*
2N/A * Find the type of device we are to be searching on
2N/A */
2N/A search_number = mda_findpath(snp->cname);
2N/A if (search_number == -1) {
2N/A search_path = "/dev";
2N/A search_type = DEVID_MINOR_NAME_ALL;
2N/A } else {
2N/A search_path = plist[search_number].search_path;
2N/A search_type = plist[search_number].search_type;
2N/A }
2N/A
2N/A mda_debug("Search path :%s searth_type: %x\n",
2N/A search_path, (int)search_type);
2N/A mda_debug("Side name: sideno: %d dname: %s cname: %s minor: %lx\n",
2N/A snp->sideno, snp->dname, snp->cname, snp->mnum);
2N/A
2N/A (void) memset(&nm, '\0', sizeof (nm));
2N/A
2N/A nm.mde = mdnullerror;
2N/A nm.setno = setno;
2N/A nm.side = sideno;
2N/A
2N/A /*
2N/A * Get the devname from the name space.
2N/A */
2N/A if ((nm.devname = (uintptr_t)meta_getnmentbykey(setno, sideno,
2N/A dnp->side_names_key, &drvnmp, &mnum, &dev, ep)) == NULL) {
2N/A mda_debug("No devname with setno: %d sideno: %d key %d\n",
2N/A setno, sideno, dnp->side_names_key);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A ret = devid_str_decode(dnp->devid, &devidp, &minor_name);
2N/A devid_str_free(minor_name);
2N/A
2N/A if (ret != 0) {
2N/A /*
2N/A * Failed to encode the devid.
2N/A */
2N/A mda_debug("Failed to decode the devid string: %s",
2N/A (char *)(uintptr_t)nm.devname);
2N/A devid_free(devidp);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A
2N/A /*
2N/A * Use the stored devid to find the existing device node and check
2N/A * to see if the disk has moved. Use the raw devices as the name
2N/A * of the disk is stored as the raw device, if this is not done
2N/A * then the disk will not be found.
2N/A */
2N/A ret = meta_deviceid_to_nmlist(search_path, devidp,
2N/A search_type, &disklist);
2N/A
2N/A if (ret != 0) {
2N/A if (dev_options & DEV_VERBOSE) {
2N/A mda_print(dgettext(TEXT_DOMAIN,
2N/A "Device ID %s last associated with "
2N/A "disk %s no longer found in system\n"),
2N/A dnp->devid, dnp->cname);
2N/A }
2N/A devid_free(devidp);
2N/A devid_free_nmlist(disklist);
2N/A return (METADEVADM_SUCCESS);
2N/A }
2N/A
2N/A small_dev = meta_cmpldev(dev);
2N/A mda_debug("Old device lookup: %s (%p)\n",
2N/A (char *)(uintptr_t)nm.devname, (void *)small_dev);
2N/A /*
2N/A * Check to see if the returned disk matches the stored one
2N/A */
2N/A for (i = 0; disklist[i].dev != NODEV; i++) {
2N/A match_type = 0;
2N/A mda_debug("From devid lookup: %s (%p)\n",
2N/A disklist[i].devname, (void *)disklist[i].dev);
2N/A
2N/A if (disklist[i].dev == small_dev) {
2N/A match_type |= DEV_MATCH;
2N/A }
2N/A
2N/A if (strncmp((char *)(uintptr_t)nm.devname, disklist[i].devname,
2N/A strlen((char *)(uintptr_t)nm.devname)) == 0) {
2N/A match_type |= NAME_MATCH;
2N/A }
2N/A
2N/A if (match_type != 0)
2N/A break;
2N/A }
2N/A devid_free(devidp);
2N/A
2N/A mda_debug("meta_upd_ctdnames: match: %x i: %d\n", match_type, i);
2N/A
2N/A if (match_type == (DEV_MATCH|NAME_MATCH)) {
2N/A /* no change */
2N/A devid_free_nmlist(disklist);
2N/A return (METADEVADM_SUCCESS);
2N/A }
2N/A
2N/A /* No match found - use the first entry in disklist */
2N/A if (disklist[i].dev == NODEV)
2N/A i = 0;
2N/A
2N/A if (!(match_type & DEV_MATCH)) {
2N/A /* did not match on the dev, so dev_t has changed */
2N/A mda_debug("Did not match on dev: %p %p\n",
2N/A (void *) small_dev, (void *) disklist[i].dev);
2N/A dev = meta_expldev(disklist[i].dev);
2N/A }
2N/A
2N/A if (!(match_type & NAME_MATCH)) {
2N/A mda_debug("Did not match on name: %s (%p)\n",
2N/A (char *)(uintptr_t)nm.devname, (void *) disklist[i].dev);
2N/A }
2N/A
2N/A /*
2N/A * If here, then the name in the disklist is the one we
2N/A * want in any case so use it.
2N/A */
2N/A mda_debug("devname: %s\n", disklist[i].devname);
2N/A /*
2N/A * Need to remove the slice as metadrivename() expects a diskname
2N/A */
2N/A stripS(disklist[i].devname);
2N/A /*
2N/A * Build an mddrivename_t to use
2N/A */
2N/A if ((newdnp = metadrivename(spp, disklist[i].devname, ep)) == NULL) {
2N/A mda_debug("Unable to make a dnp out of %s\n",
2N/A disklist[i].devname);
2N/A return (METADEVADM_DSKNAME_ERR);
2N/A }
2N/A /*
2N/A * Need to find the correct slice used for the replica
2N/A */
2N/A if (meta_replicaslice(newdnp, &rep_slice, ep) != 0) {
2N/A return (METADEVADM_DSKNAME_ERR);
2N/A }
2N/A
2N/A if ((np = metaslicename(newdnp, rep_slice, ep)) == NULL) {
2N/A mda_debug("Failed to build an np for %s\n", dnp->rname);
2N/A return (METADEVADM_DSKNAME_ERR);
2N/A }
2N/A mda_debug("check: cname: %s\n", np->cname);
2N/A mda_debug("check: rname: %s\n", np->rname);
2N/A mda_debug("check: bname: %s\n", np->bname);
2N/A
2N/A if (newname != NULL)
2N/A *newname = Strdup(np->bname);
2N/A
2N/A if (!(dev_options & DEV_NOACTION)) {
2N/A
2N/A mda_debug("update namespace\n");
2N/A
2N/A /* get the block path */
2N/A pathname = mda_getpath(np->bname);
2N/A
2N/A if (meta_update_namespace(setno, sideno, np->cname,
2N/A dev, dnp->side_names_key, pathname, ep) != 0) {
2N/A /* finished with the list so return the memory */
2N/A Free(pathname);
2N/A devid_free_nmlist(disklist);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A }
2N/A /* finished with the list so return the memory */
2N/A Free(pathname);
2N/A devid_free_nmlist(disklist);
2N/A ret = METADEVADM_DISKMOVE;
2N/A return (ret);
2N/A}
2N/A
2N/Aint
2N/Ameta_fixdevid(
2N/A mdsetname_t *sp,
2N/A mddevopts_t options,
2N/A char *diskname,
2N/A md_error_t *ep
2N/A)
2N/A{
2N/A set_t setno = sp->setno;
2N/A int ret = 0;
2N/A char *pathname = NULL;
2N/A mdsetname_t *local_sp = NULL;
2N/A md_drive_desc *d = NULL;
2N/A char *newname = NULL;
2N/A md_drive_desc *dd;
2N/A side_t sideno;
2N/A md_set_desc *sd;
2N/A int mn_set = 0;
2N/A
2N/A
2N/A if (!metaislocalset(sp)) {
2N/A if ((sd = metaget_setdesc(sp, ep)) == NULL) {
2N/A return (METADEVADM_ERR);
2N/A }
2N/A if (MD_MNSET_DESC(sd))
2N/A mn_set = 1;
2N/A }
2N/A
2N/A dev_options |= options;
2N/A mda_debug("dev_options: %x mn_set: %d\n", dev_options, mn_set);
2N/A if (dev_options & DEV_RELOAD) {
2N/A /*
2N/A * If it's not the local set we need to check the local
2N/A * namespace to see if disks have moved as it contains
2N/A * entries for the disks in the set.
2N/A */
2N/A if (setno != MD_LOCAL_SET) {
2N/A if ((dd = metaget_drivedesc(sp, MD_BASICNAME_OK |
2N/A PRINT_FAST, ep)) == NULL) {
2N/A mde_perror(ep, "");
2N/A mdclrerror(ep);
2N/A return (METADEVADM_ERR);
2N/A }
2N/A local_sp = metasetname(MD_LOCAL_NAME, ep);
2N/A /*
2N/A * Only add a SKEW to traditional disksets because
2N/A * multi-owner disksets use the node id for the side.
2N/A */
2N/A if (mn_set)
2N/A sideno = getmyside(sp, ep);
2N/A else
2N/A sideno = getmyside(sp, ep) + SKEW;
2N/A
2N/A mda_debug("meta_fixdevid: sideno: %d\n", sideno);
2N/A
2N/A for (d = dd; d != NULL; d = d->dd_next) {
2N/A /*
2N/A * Actually do the check of the disks.
2N/A */
2N/A ret = meta_upd_ctdnames(&local_sp, 0, sideno,
2N/A mn_set, d->dd_dnp, &newname, ep);
2N/A
2N/A if ((ret == METADEVADM_ERR) ||
2N/A (ret == METADEVADM_DSKNAME_ERR)) {
2N/A /* check failed in unknown manner */
2N/A mda_debug("meta_upd_ctdnames failed\n");
2N/A return (METADEVADM_ERR);
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* do a reload of the devid namespace */
2N/A ret = pathname_reload(&sp, setno, ep);
2N/A } else if (dev_options & DEV_UPDATE) {
2N/A pathname = getdiskname(diskname);
2N/A ret = devid_update(&sp, setno, pathname, ep);
2N/A free(pathname);
2N/A }
2N/A return (ret);
2N/A}