fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cred.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsc_thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h> /* dtrace is S10 or later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_bcache.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_ft.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_misc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ncall/ncall.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_ft_info_t _sd_ft_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic volatile int _sd_ft_exit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kcondvar_t _sd_ft_cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_node_recovery; /* node recovery in progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_recovery:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 = flush and wait
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 = clone and async-write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2 = quicksort, clone, and async-write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * quicksort allows contiguous blocks to be joined,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which may greatly improve recovery time for raid devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if kmem_alloc fails, acts as _sd_async_recovery == 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_async_recovery = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int xmem_inval_hit, xmem_inval_miss, xmem_inval_inuse;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag to inhibit reset of remote SCSI buses and sending of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nodedown callback if mirror was deconfigured properly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - prevents trashing any I/O that may be happening on the mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node during a normal shutdown and prevents undesired simckd failover.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int mirror_clean_shutdown = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Forward declare all statics that are used before defined to enforce
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameter checking
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Some (if not all) of these could be removed if the code were reordered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_health_thread(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_cache_recover(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_ft_clone(ss_centry_info_t *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_remote_enable(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_setmodeandftdata();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_cd_discard_mirror(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_failover_file_open(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_failover_done(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_wait_for_dirty(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_clear_warm_start(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_recover_vol(ss_vol_t *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid _ncall_poke(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sdbc_ft_hold_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekcondvar_t _sdbc_ft_hold_io_cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t _sdbc_ft_hold_io_lk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sdbc_use_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sdbc_requeue_head_dm_try(_sd_cctl_t *cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_ft_unload - cache is being unloaded (or failed to load).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Deallocate any global lock/sv that we created.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_ft_unload(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&_sd_ft_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&_sd_ft_data.fi_rem_sv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_sd_ft_data.fi_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&_sd_ft_data, sizeof (_sd_ft_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_ft_load - cache is being loaded. Allocate all global lock/sv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that we need. Return 0 if we succeed. If we fail return -1 (don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to do the unload step as we expect our caller to do that).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_ft_load(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* _sd_ft_data is sure to be zeroes, don't need to bzero it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_ft_data.fi_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&_sd_ft_data.fi_rem_sv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&_sd_ft_cv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_ft_data.fi_sleep, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_ft_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_exit = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nsc_create_process(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void (*)(void *))_sd_health_thread, 0, TRUE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_ft_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_exit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_ft_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_recovery = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&_sd_ft_data.fi_rem_sv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_health_thread -- daemon thread on each node watches if mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node to has crashed, and it needs to flush the mirrors cache entries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note we do *not* detect that the node has come up again, but wait
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the node to inform us that it is up via _sd_cache_reenable().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_health_thread(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int warm_started = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_dem_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear _sd_ft_data in case this is a cache re-enable w/o unload */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&_sd_ft_data, sizeof (_sd_ft_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_setmodeandftdata();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sdbc(_sd_health_thread) safestore "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "is %s. Fast writes %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_SD_MIRROR_CONFIGD) ? "up" : "down",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_SD_NODE_HINTS & _SD_WRTHRU_MASK) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disabled" : "enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_timed_block(HZ/8, &_sd_ft_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_ft_exit == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_dem_cnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NB evaluation order is important here for nvmem systems */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_is_mirror_crashed() ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (warm_started = _sdbc_warm_start())) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Hash invalidate here. We do not want data from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * previous failover incarnation to be cache hits, if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the 2 failover happens within a short time
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_invalidate_cd(-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * don't change mirror state when warm starting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvmem systems. _sd_mirror_down() is called in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in _sd_remote_enable() on nvmem systems if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * media is down.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!warm_started)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mirror_clean_shutdown)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_down();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_cache_down();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!warm_started) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_recovery = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Assume other side is still up */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Safestore is down. Fast writes %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_SD_NODE_HINTS & _SD_WRTHRU_MASK) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disabled" : "enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SAFESTORE_LOCAL(sdbc_safestore))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wait for cache to drain and panic */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_wait_for_dirty();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " dirty blocks flushed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_recovery = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SAFESTORE_LOCAL(sdbc_safestore))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Cache on node %d is down. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Fast writes %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_SD_NODE_HINTS & _SD_WRTHRU_MASK) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disabled" : "enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Cache recovery in progress");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_recover();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_recovery = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_clear_warm_start(); /* nvmem systems */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&_sd_ft_data.fi_rem_sv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread) %s Cache recovery done",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_recovery ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "asynchronous" : "synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* restore previous state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (warm_started && !_sd_is_mirror_down()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_clear_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_health_thread) Fast writes %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_SD_NODE_HINTS & _SD_WRTHRU_MASK) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disabled" : "enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warm_started = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (_sd_is_mirror_node_down()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_down();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_recovery_io_wait - wait for i/o being done directly
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * out of safe storage to complete. If the i/o does not make any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * progress within about 25 seconds we return EIO otherwise return 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_recovery_io_wait(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int last_numio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait for numio to reach 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If numio has not changed for 85+ seconds,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * break & pin blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (_sd_ft_data.fi_numio > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (last_numio == _sd_ft_data.fi_numio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++tries > 512) break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_numio = _sd_ft_data.fi_numio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ/8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_ft_data.fi_numio != 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_recovery_io_wait) %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "recovery i/o's not done", _sd_ft_data.fi_numio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_recovery_wait()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * while _sd_node_recovery is set, accesses to mirrored devices will block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (_sd_node_recovery-1) is count of blocked threads.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_recovery_wait(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int blk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blk = _sd_node_recovery ? _sd_node_recovery++ : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (blk)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&_sd_ft_data.fi_rem_sv, &_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_recovery_wblk_wait - wait for recovery i/o to a device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to cease. If the file is closed or the cache is disabled
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * first return an error otherwise return 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A device is being recovered from our point of view either
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * during failover or by putting a disk back online after
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a disk failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This code is used to delay access to a device while recovery
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * writes are in progress from either a failover or while flushing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i/o after a failed disk has been repaired.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_recovery_wblk_wait(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (_sd_cache_initialized &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FILE_OPENED(cd) && cdi->cd_recovering) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* spawn writer if none */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cdi->cd_writer) (void) cd_writer(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ/8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized || !FILE_OPENED(cd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Recover from a crash of another node:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1) Open all remote files
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2) Allocate other node's buffers and new buffer headers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3) Flush all dirty buffers to disk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 4) Deallocate resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cache_recover(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cblocks_processed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_RECOVER, SDT_INV_CD, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_numio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _SD_DRIVE_RESP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mirror_clean_shutdown)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _raw_reset_other();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_clean_shutdown = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks_processed = _sd_failover_file_open();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allow cache config to proceed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sdbc_ft_hold_io_lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ft_hold_io = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&_sdbc_ft_hold_io_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sdbc_ft_hold_io_lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for sequential recovery to complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_async_recovery && cblocks_processed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sdbc_recovery_io_wait();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_failover_done();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cblocks_processed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc %ssynchronous recovery complete "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d cache blocks processed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_recovery ? "a" : "",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks_processed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_RECOVER, SDT_INV_CD, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_mirror_iodone(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_numio--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_ft_data.fi_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_ft_clone -- clone cache block from ft area, retry write or pin.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_ft_clone(ss_centry_info_t *ft_cent, int async)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = ft_cent->sc_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t cblk = ft_cent->sc_fpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dirty = ft_cent->sc_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resource_t *res = ft_cent->sc_res;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FT_CLONE, cd, BLK_FBAS, cblk, dirty, _SD_NO_NET);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info->sh_failed != 2) && !FILE_OPENED(cd)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_ft_clone) recovery "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "write failed: cd %x; cblk %" NSC_SZFMT "; dirty %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, cblk, dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FT_CLONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, BLK_FBAS, cblk, dirty, EINTR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate new cache entry and read data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = sdbc_centry_alloc_blks(cd, cblk, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_READ_CBLOCK(sdbc_safestore, res, (void *)ent->cc_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_BLOCK_SIZE, 0) == SS_ERR) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_ft_clone) read of "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "pinned data block failed. cannot recover "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "0x%p size 0x%x", (void *)res, CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* _sd_process_failure ?? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->cc_write = ft_cent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->cc_dirty = ent->cc_valid = (ushort_t)dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->cc_flag |= (ft_cent->sc_flag & CC_PINNABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_process_failure() adds to failed list & does pinned callback
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise async flush
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed) { /* raw device open/reserve failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_info->sh_numio)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_process_failure(ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_pinned != _SD_NO_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global->sv_pinned = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (async) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty(cd, ent, ent, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is sync write with asynchronous callback
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (queue to disk and return).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&(cdi->cd_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_info->sh_numio)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_flcent(ent, cdi->cd_crdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FT_CLONE, cd, BLK_FBAS, cblk, dirty, _SD_NO_NET);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_repin_cd - scan for dirty blocks held by mirror node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc on this node is being attached to cd. If sdbc on other
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node had failed writes (pinnable or not) we need to take
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * responsbility for them now here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_repin_cd(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *cd_gl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FILE_OPENED(cd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_pinned == _SD_NO_HOST)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_gl = _sdbc_gl_file_info + cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_recover_vol(cd_gl->sv_vol, cd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_discard_mirror(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cache_mirror_enable(int host)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_initialized) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host != _SD_MIRROR_HOST) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_cache_mirror_enable) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Configured mirror %x. Got message from %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_MIRROR_HOST, host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_node_recovery) (void) _sd_recovery_wait();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_initialized && _sd_is_mirror_down()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make sure any pinned data we have is now refreshed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(i))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sdbc_remote_store_pinned(i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_cache_mirror_enable) Cache on "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "mirror node %d is up. Fast writes enabled",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_up();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_clear_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state = _SD_HOST_CONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_sd_cache_initialized);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * two stage mirror disable:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stage 0: set FORCED_WRTHRU hint (cache shutdown started)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stage 1: mirror shutdown completed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cache_mirror_disable(int host, int stage)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_initialized) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host != _SD_MIRROR_HOST)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stage == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state = _SD_HOST_DECONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_clean_shutdown = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_ft_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state = _SD_HOST_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the fault tolerant data to indicate the state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the safestore host. set mode to writethru if appropriate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_setmodeandftdata()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if single node local safestore or ram safestore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then mark host state as carashed/_SD_HOST_NONE and set writethru
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SAFESTORE_LOCAL(sdbc_safestore)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SAFESTORE_SAFE(sdbc_safestore)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_down(); /* mirror node down */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state = _SD_HOST_CONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_warm_start())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_remote_enable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_remote_enable(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_t *ncall;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long r;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ncall_alloc(_SD_MIRROR_HOST, 0, _SD_NO_NET, &ncall)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_down(); /* mirror node down */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte r = ncall_send(ncall, 0, SD_ENABLE, _SD_SELF_HOST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!r) (void) ncall_read_reply(ncall, 1, &r);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_free(ncall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (r == 1) { /* _sd_cache_initialized */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_is_mirror_crashed() &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state == _SD_HOST_NONE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_data.fi_host_state = _SD_HOST_CONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (r == ENOLINK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_down(); /* mirror node down */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mirror_cache_down(); /* mirror up, but no cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_remote_disable(int stage)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_t *ncall;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ncall_alloc(_SD_MIRROR_HOST, 0, 0, &ncall) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ncall_send(ncall, NCALL_ASYNC, SD_DISABLE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SELF_HOST, stage);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_sd_ifs_cache_enable(ncall_t *ncall, int *ap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_reply(ncall, _sd_cache_mirror_enable(*ap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_sd_ifs_cache_disable(ncall_t *ncall, int *ap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_cache_mirror_disable(ap[0], ap[1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_done(ncall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* (_SD_FAULT_RES) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid r_sd_ifs_cache_enable() {; }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid r_sd_ifs_cache_disable() {; }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* (_SD_FAULT_RES) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invalidate cache hash table entries for given device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or (-1) all devices belonging to mirrored node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_hash_invalidate_cd(int CD)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_hd_t *hptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_bucket_t *bucket;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t blk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < (_sd_htable->ht_size); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bucket = (_sd_htable->ht_buckets + i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(bucket->hb_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hptr = bucket->hb_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (hptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = (_sd_cctl_t *)hptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blk = CENTRY_BLK(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Skip if device doesn't match or pinned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (-1) skip attached cd's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if ((CD != -1 && (cd != CD || CENTRY_PINNED(cc_ent))) ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (CD == -1 && nsc_held(cdi->cd_rawfd))) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana hptr = hptr->hh_next;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(bucket->hb_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fl1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, blk, ent) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ent = (_sd_cctl_t *)_sd_hash_search(cd, blk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xmem_inval_inuse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, blk, ent, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fl1; /* try again */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cc_inuse is set, delete on block match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, blk, ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xmem_inval_hit++;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void) _sd_hash_delete(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (struct _sd_hash_hd *)ent,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* attempt to que head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ent->cc_alloc_size_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_head_dm_try
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xmem_inval_miss++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(bucket->hb_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hptr = bucket->hb_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(bucket->hb_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cd_online(cd,discard)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear local error state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (discard && _attached != _SD_SELF_HOST) then release buffers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (!discard && _attached != _SD_MIRROR_HOST) then re-issue I/Os
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (add to dirty pending queue).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EINVAL invalid device or not failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EBUSY attached by this node, or by active mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cd_online(int cd, int discard)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int failed, num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *cc_next, *cc_last, *cc_first, *cc_next_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in the case where a failed device has been closed and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then re-opened, sh_failed will be zero because it is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cleared in _sd_open_cd(). hence the test for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _pinned != _SD_SELF_HOST which allows the restore to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * proceed in this scenario.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd < 0 || cd >= sdbc_max_devs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cdi->cd_info || !cdi->cd_global)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info->sh_failed == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_global->sv_pinned != _SD_SELF_HOST))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_nodes_configured > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* can't discard while attached on multinode systems */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discard && (cdi->cd_global->sv_attached == _SD_SELF_HOST))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!discard && /* attached by active mirror! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_global->sv_attached == _SD_MIRROR_HOST) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !_sd_is_mirror_down())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cdi->cd_fail_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte failed = cdi->cd_info->sh_numfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_fail_head = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numfail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global->sv_pinned = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prevent any new i/o from arriving for this cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!discard)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_recovering = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_first = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; cc_ent; cc_ent = cc_next_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_next_chain = cc_ent->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; cc_ent; cc_ent = cc_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_next = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_last = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discard) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid = cc_ent->cc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~(CC_PEND_DIRTY|CC_PINNED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cc_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wctl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear PEND_DIRTY, iocount & iostatus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~CC_PEND_DIRTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = 0; /* _SD_IO_NONE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~CC_PEND_DIRTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = 0; /* _SD_IO_NONE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num != failed)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_cd_online) count %d vs numfail %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num, failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discard) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_invalidate_cd(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty_chain(cd, cc_first, cc_last, num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make sure data gets flushed in case there is no new I/O */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_reserve(cdi->cd_rawfd, NSC_MULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_wait_for_flush(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_recovering = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This node has disk attached, discard pins held by mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cd_discard_mirror(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_t *ncall;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ncall_alloc(_SD_MIRROR_HOST, 0, 0, &ncall))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ncall_send(ncall, NCALL_ASYNC, SD_CD_DISCARD, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_cd_discard(ncall_t *ncall, int *ap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int r, cd = *ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_initialized) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ONLINE, cd, 1, SDT_INV_BL, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte r = _sd_cd_online(cd, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ONLINE, cd, 1, SDT_INV_BL, 1, r);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_done(ncall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_failover_file_open -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on failover, open devices which are not attached by this node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_failover_file_open(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, cd, flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *cd_gl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cblocks_processed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern ss_voldata_t *_sdbc_gl_file_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cd = 0; cd < sdbc_max_devs; cd++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_gl = _sdbc_gl_file_info + cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the cd is open and reserved we certainly don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to do it again. However the recovery code
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must be racing some other cache usage which could
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be bad. We really need to be able to lock out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all cache activity for this cd that is not tied
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the recovery process. This doesn't seem to be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * feasible in sdbc since a competing thread could
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * already be finished doing an alloc_buf. If this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hole is to be closed sd-ctl must be more in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * control of the failover process.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd) && nsc_held(cdi->cd_rawfd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this constuct says that, on non-nvmem systems,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we are attempting to open a "local" device and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nothing is pinned, then continue. i.e. open only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remote devices or devices that have pinned data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for recovery on nvmem systems we open all devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!_sdbc_warm_start()) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ((cd_gl->sv_attached != _SD_MIRROR_HOST) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cd_gl->sv_pinned != _SD_MIRROR_HOST) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cd_gl->sv_pinned != _SD_SELF_HOST)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (!cd_gl->sv_volname || !cd_gl->sv_volname[0])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_open_cd(cd_gl->sv_volname, cd, flag) < 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_failover_file_open) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Unable to open disk partition %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_gl->sv_volname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_RECOVER, cd, 0, 0, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_reserve(cdi->cd_rawfd, NSC_MULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_failover = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) cdi->cd_info->sh_failed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks_processed += sdbc_recover_vol(cd_gl->sv_vol, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cblocks_processed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_recover_vol(ss_vol_t *vol, int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_cdirkey_t key;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_cdir_t cdir;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *cd_gl = _sdbc_gl_file_info + cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *cinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cblocks_processed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *sdbc_get_cinfo_byres(ss_resource_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup the key to get a volume directory stream of centrys */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte key.ck_type = CDIR_VOL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte key.cdk_u.ck_vol = vol;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_GETCDIR(sdbc_safestore, &key, &cdir)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(sdbc_recover_vol): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cannot recover volume %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_gl->sv_volname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cycle through the cdir getting resource tokens and reading centrys */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTANTCONDITION*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = SSOP_GETCDIRENT(sdbc_safestore, &cdir, &centry))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == SS_ERR) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(sdbc_recover_vol): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cache entry read failure %s %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cd_gl->sv_volname, (void *)centry.sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == SS_EOF)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this get into double caching consistency
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to resolve this jgk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cinfo = sdbc_get_cinfo_byres(centry.sc_res)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should not happen */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(sdbc_recover_vol): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "invalid ss resource %p", (void *)centry.sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&centry, cinfo, sizeof (ss_centry_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * note
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ss should return a stream of dirty blocks ordered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by block number. if it turns out that ss will not support
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this then sorting for async recovery will have to be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * done here jgk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cinfo->sc_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cinfo->sc_dirty) /* should not happen */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clone mirror cache entry and do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * async I/O or sync I/O or pin if sh_failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_ft_clone(cinfo, _sd_async_recovery);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++cblocks_processed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cblocks_processed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(sdbc_recover_vol) %d cache blocks processed for "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "volume %s", cblocks_processed, cd_gl->sv_volname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cblocks_processed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_failover_done -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark failover open'd devices as requiring nsc_release()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when all queued I/O's have drained.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_failover_done(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cd = 0; cd < sdbc_max_devs; cd++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd) && cdi->cd_failover)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_failover = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* (_SD_FAULT_RES) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_uncommit - discard local buffer modifications
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear the valid bits.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_uncommit(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t cc_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_WRBUF) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_uncommit_end_handle_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_uncommit_end_zero_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_UNCOMMIT, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_len = fba_len; /* current length */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (BLK_FBAS - st_cblk_off);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if remote write-cache spool is dirty,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if not, we can just discard local valid bits.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bits = SDBC_GET_BITS(st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid &= ~bits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bits = SDBC_GET_BITS(0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_len != end_cblk_len)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!fba_len %" NSC_SZFMT " end_cblk_len %d in "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_write", fba_len, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bits = SDBC_GET_BITS(0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid &= ~bits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_UNCOMMIT, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_wait_for_dirty(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cd = 0; cd < sdbc_max_devs; cd++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (_SD_CD_WBLK_USED(cd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_wait_for_flush - wait for all i/o for this cd to cease.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function assumes that no further i/o are being issued
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * against this device. This assumption is enforced by sd-ctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when called from _sd_flush_cd. Recovery also uses this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait and it enforces this assumption (somewhat imperfectly)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by using cd_recovering.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We must see progress in getting i/o complete within 25 seconds
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or we will return an error. If we complete normally (all i/o done)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we return 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_wait_for_flush(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0, used, last_used = 0, inprogress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(_SD_CD_WBLK_USED(cd)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait for WBLK_USED to reach 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If unchanged for 32+ seconds returns EAGAIN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cdi->cd_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cd_writer(cd); /* spawn writer if not already running */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (((used = _SD_CD_WBLK_USED(cd)) != 0) || cdi->cd_writer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (last_used == used &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inprogress == cdi->cd_write_inprogress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++tries > 128) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_wait_for_flush) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s still has %d blocks pending %d"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " in progress (@ %lx)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_filename, last_used,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inprogress, nsc_lbolt());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EAGAIN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_used = used;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inprogress = cdi->cd_write_inprogress;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ/4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_ft_warm_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_warm_start(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_sd_ft_warm_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_clear_warm_start(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_warm_start = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_set_warm_start(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ft_warm_start = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_ncall_poke(int host)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, " NYI - _ncall_poke");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}