/* * NAME: raid_resync_unit * * DESCRIPTION: RAID metadevice specific resync routine. * Open the unit and start resync_unit as a separate thread. * * PARAMETERS: minor_t mnum - minor number identity of metadevice * md_error_t *ep - output error parameter * * RETURN: On error return 1 or set ep to nonzero, otherwise return 0. * * LOCKS: Acquires and releases Unit Writer Lock. */ int raid_resync_unit( minor_t mnum, md_error_t *ep ) { mdi_unit_t *ui; set_t setno = MD_MIN2SET(mnum); mr_unit_t *un; ui = MDI_UNIT(mnum); un = MD_UNIT(mnum); if (md_get_setstatus(setno) & MD_SET_STALE) return (mdmddberror(ep, MDE_DB_STALE, mnum, setno)); ASSERT(un->un_column[un->un_resync_index].un_devflags & (MD_RAID_COPY_RESYNC | MD_RAID_REGEN_RESYNC)); /* Don't start a resync if the device is not available */ if ((ui == NULL) || (ui->ui_tstate & MD_DEV_ERRORED)) { return (mdmderror(ep, MDE_RAID_OPEN_FAILURE, mnum)); } if (raid_internal_open(mnum, FREAD | FWRITE, OTYP_LYR, 0)) { (void) md_unit_writerlock(ui); release_resync_request(mnum); md_unit_writerexit(ui); SE_NOTIFY(EC_SVM_STATE, ESC_SVM_OPEN_FAIL, SVM_TAG_METADEVICE, setno, MD_SID(un)); return (mdmderror(ep, MDE_RAID_OPEN_FAILURE, mnum)); } /* start resync_unit thread */ (void) thread_create(NULL, 0, resync_unit, (void *)(uintptr_t)mnum, 0, &p0, TS_RUN, minclsyspri); return (0); }
/* * NAME: resync_unit * * DESCRIPTION: Start of RAID resync thread. Perform up front allocations, * initializations and consistency checking, then call * resync_comp to resync the component. * * PARAMETERS: minor_t mnum - minor number identity of metadevice * * LOCKS: Acquires and releases Unit Reader Lock to maintain unit * existence during resync. * Acquires and releases the resync count lock for cpr. */ static void resync_unit( minor_t mnum ) { mdi_unit_t *ui; mr_unit_t *un; md_raidps_t *ps = NULL; md_raidcs_t *cs = NULL; int resync; /* * Increment the raid resync count for cpr */ mutex_enter(&md_cpr_resync.md_resync_mutex); md_cpr_resync.md_raid_resync++; mutex_exit(&md_cpr_resync.md_resync_mutex); ui = MDI_UNIT(mnum); ASSERT(ui != NULL); un = (mr_unit_t *)md_unit_readerlock(ui); /* * Allocate parent and child memory pool structures. These are * only needed to lock raid lines, so only the minimal * required fields for this purpose are initialized. * * Do not use the reserve pool for resync. */ ps = kmem_cache_alloc(raid_parent_cache, MD_ALLOCFLAGS); raid_parent_init(ps); cs = kmem_cache_alloc(raid_child_cache, MD_ALLOCFLAGS); raid_child_init(cs); resync = un->un_resync_index; ps->ps_un = un; ps->ps_ui = ui; ps->ps_flags = MD_RPS_INUSE; cs->cs_ps = ps; cs->cs_un = un; ASSERT(!(un->un_column[resync].un_devflags & MD_RAID_WRITE_ALT)); resync_comp(mnum, cs); release_resync_request(mnum); kmem_cache_free(raid_child_cache, cs); kmem_cache_free(raid_parent_cache, ps); md_unit_readerexit(ui); /* close raid unit */ (void) raid_internal_close(mnum, OTYP_LYR, 0, 0); /* poke hot spare daemon */ (void) raid_hotspares(); /* * Decrement the raid resync count for cpr */ mutex_enter(&md_cpr_resync.md_resync_mutex); md_cpr_resync.md_raid_resync--; mutex_exit(&md_cpr_resync.md_resync_mutex); thread_exit(); }
/* * NAME: check_comp_4_hs * * DESCRIPTION: Check whether the input component has an error and can be * backed with a hot spare (RCS_ERRED state), and initiate * a resync if so. * * PARAMETERS: mr_unit_t *un - raid unit * int hs_index - component to check * * LOCKS: Expects Unit Writer Lock to be held upon entrance. Releases * the lock prior to calling raid_resync_unit, then reacquires * it before returning. */ static void check_comp_4_hs( mr_unit_t *un, int hs_index ) { mddb_recid_t recids[3]; minor_t mnum = MD_SID(un); mdi_unit_t *ui; rcs_state_t state; diskaddr_t size; int err; mr_column_t *col; md_error_t mde = mdnullerror; char devname[MD_MAX_CTDLEN]; char hs_devname[MD_MAX_CTDLEN]; set_t setno; md_dev64_t tmpdev; diskaddr_t tmpdaddr; /* initialize */ setno = MD_UN2SET(un); ui = MDI_UNIT(mnum); md_unit_readerexit(ui); (void) md_io_writerlock(ui); un = (mr_unit_t *)md_unit_writerlock(ui); col = &un->un_column[hs_index]; /* * add a hotspare for erred column only if not resyncing */ if ((!(COLUMN_STATE(un, hs_index) & RCS_ERRED)) || (raid_state_cnt(un, (RCS_ERRED | RCS_LAST_ERRED)) != 1) || (raid_state_cnt(un, RCS_RESYNC) > 0)) { goto errout; } recids[0] = 0; recids[1] = 0; /* if there is already a hotspare then just return */ if (HOTSPARED(un, hs_index) && (col->un_devstate & RCS_ERRED)) { raid_hs_release(HS_BAD, un, &recids[0], hs_index); cmn_err(CE_WARN, "md: %s: %s hotspare errored and released", md_shortname(mnum), md_devname(MD_MIN2SET(mnum), col->un_dev, NULL, 0)); col->un_dev = col->un_orig_dev; col->un_pwstart = col->un_orig_pwstart; col->un_devstart = col->un_orig_devstart; raid_commit(un, recids); SE_NOTIFY(EC_SVM_STATE, ESC_SVM_HS_FREED, SVM_TAG_METADEVICE, setno, MD_SID(un)); } ASSERT(!HOTSPARED(un, hs_index)); state = col->un_devstate; size = col->un_pwstart + un->un_pwsize + (un->un_segsize * un->un_segsincolumn); again: /* quit if resync is already active */ col->un_devflags |= MD_RAID_REGEN_RESYNC; if (resync_request(mnum, hs_index, 0, NULL)) goto errout; recids[0] = 0; recids[1] = 0; tmpdev = col->un_dev; tmpdaddr = col->un_hs_pwstart; /* get a hotspare */ if (md_hot_spare_ifc(HS_GET, un->un_hsp_id, size, ((col->un_orig_pwstart >= 1) && (col->un_orig_pwstart != MD_DISKADDR_ERROR)), &col->un_hs_id, &col->un_hs_key, &tmpdev, &tmpdaddr) != 0) { col->un_dev = tmpdev; col->un_hs_pwstart = tmpdaddr; release_resync_request(mnum); raid_set_state(un, hs_index, state, 1); goto errout; } col->un_hs_pwstart = tmpdaddr; /* * record id is filled in by raid_commit, recids[0] filled in by * md_hot_spare_ifc if needed */ recids[0] = col->un_hs_id; recids[1] = 0; /* * close the device and open the hot spare. The device should * never be a hotspare here. */ if (col->un_devflags & MD_RAID_DEV_ISOPEN) { md_layered_close(col->un_orig_dev, MD_OFLG_NULL); col->un_devflags &= ~MD_RAID_DEV_ISOPEN; } /* * Try open by device id */ tmpdev = md_resolve_bydevid(mnum, tmpdev, col->un_hs_key); if (md_layered_open(mnum, &tmpdev, MD_OFLG_NULL)) { md_dev64_t hs_dev = tmpdev; /* cannot open return to orig */ raid_hs_release(HS_BAD, un, &recids[0], hs_index); release_resync_request(mnum); raid_set_state(un, hs_index, state, 1); col->un_dev = col->un_orig_dev; col->un_devstart = col->un_orig_devstart; col->un_pwstart = col->un_orig_pwstart; col->un_devflags &= ~MD_RAID_DEV_ISOPEN; raid_commit(un, recids); cmn_err(CE_WARN, "md: %s: open error of hotspare %s", md_shortname(mnum), md_devname(MD_MIN2SET(mnum), hs_dev, NULL, 0)); SE_NOTIFY(EC_SVM_STATE, ESC_SVM_HS_FREED, SVM_TAG_HS, setno, MD_SID(un)); goto again; } col->un_dev = tmpdev; col->un_devflags |= MD_RAID_DEV_ISOPEN; /* * move the values into the device fields. Since in some cases * the pwstart is not zero this must be added into the start of * the hotspare to avoid over writting the label */ col->un_hs_pwstart += col->un_orig_pwstart; col->un_pwstart = col->un_hs_pwstart; col->un_hs_devstart = col->un_hs_pwstart + un->un_pwsize; col->un_devstart = col->un_hs_devstart; /* commit unit and hotspare records and release lock */ raid_commit(un, recids); md_unit_writerexit(ui); md_io_writerexit(ui); err = raid_resync_unit(mnum, &mde); /* if resync fails, transition back to erred state and reset */ if (err) { /* reaquire unit writerr lock */ un = (mr_unit_t *)md_unit_writerlock(ui); raid_set_state(un, hs_index, RCS_ERRED, 0); /* * close the hotspare and return it. Then restore the * original device back to the original state */ raid_hs_release(HS_FREE, un, &recids[0], hs_index); col->un_dev = col->un_orig_dev; col->un_devstart = col->un_orig_devstart; col->un_pwstart = col->un_orig_pwstart; raid_commit(un, recids); md_unit_writerexit(ui); un = (mr_unit_t *)md_unit_readerlock(ui); return; } setno = MD_MIN2SET(mnum); (void) md_devname(setno, col->un_orig_dev, devname, sizeof (devname)); (void) md_devname(setno, col->un_dev, hs_devname, sizeof (hs_devname)); cmn_err(CE_NOTE, "md: %s: hotspared device %s with %s", md_shortname(mnum), devname, hs_devname); SE_NOTIFY(EC_SVM_STATE, ESC_SVM_HOTSPARED, SVM_TAG_HS, setno, MD_SID(un)); (void) md_unit_readerlock(ui); return; errout: md_unit_writerexit(ui); md_io_writerexit(ui); un = (mr_unit_t *)md_unit_readerlock(ui); }