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/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/buf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cred.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.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_trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_bio.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_misc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_ft.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_pcu.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynamic memory support
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_dm_process_vars_t dynmem_processing_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sd_dealloc_flag_dm = NO_THREAD_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_dealloc_dm(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_entry_availability_dm(_sd_cctl_t *cc_ent, int *nodata);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sdbc_requeue_dmchain(_sd_queue_t *, _sd_cctl_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sdbc_ins_dmqueue_front(_sd_queue_t *q, _sd_cctl_t *cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sdbc_remq_dmchain(_sd_queue_t *q, _sd_cctl_t *cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void sdbc_requeue_head_dm_try(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int sdbc_use_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _sd_queue_t *sdbc_dm_queues;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekcondvar_t _sd_flush_cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic volatile int _sd_flush_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* secret flush toggle flag for testing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sdbc_flush_flag = 1; /* 0 ==> noflushing, 1 ==> flush */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_flush_pageio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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_flcent_ea(blind_t xcc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_flclist_ea(blind_t xcc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_process_reflush(_sd_cctl_t *cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_flush_thread(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_flush_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_flush_exit = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_flush_pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nsc_create_process(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void (*)(void *))_sd_flush_thread, 0, TRUE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_flush_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_flush_exit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_static_cache(int reqblks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *next_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry = sdbc_centry_alloc_blks(_CD_NOHASH, 0, reqblks,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ALLOC_NOWAIT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release the blocks to the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_centry = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = next_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (reqblks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_dealloc_configure_dm(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reqblks = MEGABYTE/BLK_SIZE(1); /* alloc in mb chunks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int blk_groups; /* number of ~MB groups */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int blks_remaining;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int blks_allocd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dynmem_processing_dm.alloc_ct = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dynmem_processing_dm.dealloc_ct = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_static_cache) { /* alloc all static cache memory here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dynmem_processing_dm.max_dyn_list = reqblks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blk_groups = CBLOCKS / reqblks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blks_remaining = CBLOCKS % reqblks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < blk_groups; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_alloc_static_cache(reqblks))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blks_allocd += reqblks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(_sdbc_dealloc_configure_dm1,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, i, int, blks_allocd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if successful then allocate any remaining blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i == blk_groups) && blks_remaining)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_alloc_static_cache(blks_remaining))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blks_allocd += blks_remaining;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(_sdbc_dealloc_configure_dm2,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, i, int, blks_allocd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = NO_THREAD_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (blks_allocd < CBLOCKS) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Failed to allocate sdbc cache "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "memory.\n requested mem: %d MB; actual mem: %d MB",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CBLOCKS/reqblks, blks_allocd/reqblks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sdbc(_sdbc_dealloc_configure_dm) %d bytes "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "(%d cache blocks) allocated for static cache, "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "block size %d", blks_allocd * BLK_SIZE(1), blks_allocd,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_SIZE(1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = PROCESS_CACHE_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_create_process((void (*)(void *))_sd_dealloc_dm, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = NO_THREAD_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_dealloc_dm_shutdown - deallocate cache memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: none
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS: nothing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this function is intended for use after all i/o has stopped and all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * other cache threads have terminated. write cache resources, if any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are released, except in the case of pinned data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dealloc_dm_shutdown()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = _sd_cctl[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_alloc_size_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* HOST or OTHER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(cc_ent->cc_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_alloc_size_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_alloc_size_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dynmem_processing_dm.dealloc_ct++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(sdbc_dealloc_dm_shutdown, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data, int, cc_ent->cc_alloc_size_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release safestore resource, if any. preserve pinned data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(CENTRY_DIRTY(cc_ent)) && (wctl = cc_ent->cc_write)) {
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, wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_link_list_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (cc_ent != _sd_cctl[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_dealloc_deconfigure_dm(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int one_sec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_static_cache) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dealloc_dm_shutdown();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sd_dealloc_flag_dm == NO_THREAD_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return; /* thread never started */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte one_sec = HZ; /* drv_usectohz(1000000); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = CACHE_SHUTDOWN_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&dynmem_processing_dm.thread_dm_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (sd_dealloc_flag_dm != CACHE_THREAD_TERMINATED_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(one_sec);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = NO_THREAD_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This complicated - possibly overly complicated routine works as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In general the routine sleeps a specified amount of time then wakes and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * examines the entire centry list. If an entry is avail. it ages it by one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tick else it clears the aging flag completely. It then determines if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry has aged sufficiently to have its memory deallocated and for it to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be placed at the top of the lru.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There are two deallocation schemes in place depending on whether the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry is a standalone entry or it is a member of a host/parasite chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The behavior for a standalone entry is as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the given centry is selected it will age normally however at full
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * aging it will only be placed at the head of the lru. It's memory will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not be deallocated until a further aging level has been reached. The
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entries selected for this behavior are goverend by counting the number
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of these holdovers in existence on each wakeup and and comparing it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to a specified percentage. This comparision is always one cycle out of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * date and will float in the relative vicinity of the specified number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The behavior for a host/parasite chain is as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The chain is examined. If all entries are fully aged the entire chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is removed - ie mem is dealloc. from the host entry and all memory ref.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removed from the parasitic entries and each entry requeued on to the lru.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There are three delay timeouts and two percentage levels specified. Timeout
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * level 1 is honored between 100% free and pcnt level 1. Timeout level 2 is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * honored between pcnt level 1 and pcnt level 2, Timeout level 3 is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * honored between pcnt level 2 and 0% free. In addition there exist an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accelerated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * aging flag which mimics hysterisis behavior. If the available centrys fall
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * between pcnt1 and pcnt2 an 8 bit counter is switched on. The effect is to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * keep the timer value at timer level 2 for 8 cycles even if the number
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * available cache entries drifts above pcnt1. If it falls below pcnt2 an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * additional 8 bit counter is switched on. This causes the sleep timer to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remain at timer level 3 for at least 8 cycles even if it floats above
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pcnt2 or even pcnt1. The effect of all this is to accelerate the release
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of system resources under a heavy load.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All of the footwork can be stubbed out by a judicious selection of values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the times, aging counts and pcnts.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All of these behavior parameters are adjustable on the fly via the kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mechanism. In addition there is a thread wakeup msg available through the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * same mechanism.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_dealloc_dm(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int one_sec_tics, tic_delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sleep_tics_lvl1, sleep_tics_lvl2, sleep_tics_lvl3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int transition_lvl1, transition_lvl2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int host_cache_aging_ct, meta_cache_aging_ct, hold_cache_aging_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int max_holds_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cache_aging_ct, hold_candidate, last_holds_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *next_ccentry, *cur_ent, *nxt_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int current_breakout_count, number_cache_entries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dealloc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _dm_process_vars_t *ppvars;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int write_dealloc; /* remove after debugging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars = &dynmem_processing_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup a one sec time var */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte one_sec_tics = HZ; /* drv_usectohz(1000000); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = _sd_cctl[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number_cache_entries = _sd_net_config.sn_cpages;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_holds_ct = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTANTCONDITION*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sd_dealloc_flag_dm == CACHE_SHUTDOWN_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* finished. shutdown - get out */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dealloc_dm_shutdown(); /* free all memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = CACHE_THREAD_TERMINATED_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* has the world changed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get num cctl entries (%) below which different sleep
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rates kick in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transition_lvl1 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ppvars->cache_aging_pcnt1*number_cache_entries) / 100;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transition_lvl2 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ppvars->cache_aging_pcnt2*number_cache_entries) / 100;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get sleep rates for each level */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep_tics_lvl1 = ppvars->cache_aging_sec1 * one_sec_tics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep_tics_lvl2 = ppvars->cache_aging_sec2 * one_sec_tics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep_tics_lvl3 = ppvars->cache_aging_sec3 * one_sec_tics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get num of cycles for full normal aging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host_cache_aging_ct = ppvars->cache_aging_ct1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get num of cycles for full meta aging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte meta_cache_aging_ct = ppvars->cache_aging_ct2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get num of cycles for full extended holdover aging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hold_cache_aging_ct = ppvars->cache_aging_ct3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get maximum holds count in % */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_holds_ct = (ppvars->max_holds_pcnt*number_cache_entries)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte / 100;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* apply the delay */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tic_delay = sleep_tics_lvl1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sd_dealloc_flag_dm == TIME_DELAY_LVL1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tic_delay = sleep_tics_lvl2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sd_dealloc_flag_dm == TIME_DELAY_LVL2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tic_delay = sleep_tics_lvl3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ppvars->thread_dm_lock);
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni (void) cv_reltimedwait(&ppvars->thread_dm_cv,
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni &ppvars->thread_dm_lock, tic_delay, TR_CLOCK_TICK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ppvars->thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for special directives on wakeup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->process_directive &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_OUT_ACCEL_HIST_FLAG_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->process_directive &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~MAX_OUT_ACCEL_HIST_FLAG_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (HISTORY_LVL1|HISTORY_LVL2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Start of deallocation loop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_breakout_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->nodatas = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte write_dealloc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->deallocs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->candidates = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->hosts = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->pests = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->metas = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->holds = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->others = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->notavail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (sd_dealloc_flag_dm != CACHE_SHUTDOWN_DM &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_breakout_count < number_cache_entries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ccentry = cc_ent->cc_link_list_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_entry_availability_dm(cc_ent, &ppvars->nodatas)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->notavail++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next_dealloc_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_aging_ct = host_cache_aging_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hold_candidate = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_aging_dm & HOST_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->hosts++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_aging_dm & PARASITIC_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->pests++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_aging_dm & STICKY_METADATA_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_aging_ct = meta_cache_aging_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->metas++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (last_holds_ct < max_holds_ct)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hold_candidate = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->others++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->candidates++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cc_ent->cc_aging_dm & FINAL_AGING_DM) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_aging_ct) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_aging_dm += FIRST_AGING_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next_dealloc_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* bonafide aged entry - examine its chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dealloc = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = cc_ent->cc_head_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_ent == cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm |= AVAIL_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_entry_availability_dm(cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0) == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm |=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AVAIL_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur_ent->cc_aging_dm &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FINAL_AGING_DM) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_aging_ct)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dealloc = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dealloc = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = cur_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = cc_ent->cc_head_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* chain not fully free - free inuse for all entries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dealloc == FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt_ent = cur_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_ent->cc_aging_dm &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AVAIL_ENTRY_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~AVAIL_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = nxt_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* OK - free memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hold_candidate == TRUE &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cur_ent->cc_aging_dm & FINAL_AGING_DM) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hold_cache_aging_ct) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->holds++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cur_ent == cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_aging_dm += FIRST_AGING_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm &= ~AVAIL_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cur_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wctl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte write_dealloc++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next_dealloc_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* if (hold_candidate == TRUE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_dealloc_dm,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *, cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, CENTRY_CD(cur_ent),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, CENTRY_BLK(cur_ent),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t, cur_ent->cc_aging_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur_ent->cc_aging_dm
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana & BAD_CHAIN_DM)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_hash_hd_t *)cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt_ent = cur_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = nxt_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->deallocs++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_ent->cc_alloc_size_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qidx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* HOST or OTHER */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* debugging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->dealloc_ct++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_dealloc_ct_dm++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(cur_ent->cc_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_alloc_size_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove from queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in preparation for putting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the 0 queue after
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory is freed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qidx =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana [qidx];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_remq_dmchain(q,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cur_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_write = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_data = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_alloc_size_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_head_dm = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~(FINAL_AGING_DM | ENTRY_FIELD_DM |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CATAGORY_ENTRY_DM | AVAIL_ENTRY_DM |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PREFETCH_BUF_I | PREFETCH_BUF_E);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_hash_hd_t *)cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt_ent = cur_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_next_dm = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ins_dmqueue_front(q,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt_ent = cur_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_next_dm = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cur_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = nxt_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wctl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte write_dealloc++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (cur_ent) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* else OK - free memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenext_dealloc_entry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_breakout_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = next_ccentry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (entries) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->monitor_dynmem_process & RPT_DEALLOC_STATS1_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!notavl=%x, nodat=%x, cand=%x, hosts=%x,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " pests=%x, metas=%x, holds=%x, others=%x,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " deallo=%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->notavail, ppvars->nodatas,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->candidates, ppvars->hosts, ppvars->pests,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->metas, ppvars->holds, ppvars->others,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->deallocs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->monitor_dynmem_process & RPT_DEALLOC_STATS2_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!hist=%x, gross a/d=%x %x", ppvars->history,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->alloc_ct, ppvars->dealloc_ct);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sd_dealloc_flag_dm == CACHE_SHUTDOWN_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_holds_ct = ppvars->holds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the history flag which will govern the sleep rate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->nodatas > transition_lvl1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* upper - lots of virgin cctls */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->history)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->nodatas > transition_lvl2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* middle - not so many virgin cctls */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->history & (HISTORY_LVL1-1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history = HISTORY_LVL1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * appear to be running low - accelerate the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * aging to free more
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->history & HISTORY_LVL2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppvars->history =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (HISTORY_LVL1|HISTORY_LVL2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = TIME_DELAY_LVL0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->history & HISTORY_LVL2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = TIME_DELAY_LVL2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppvars->history & HISTORY_LVL1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_dealloc_flag_dm = TIME_DELAY_LVL1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (TRUE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_entry_availability_dm(_sd_cctl_t *cc_ent, int *nodata)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if using dmchaining return immediately and do not attempt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to acquire the cc_ent if there is no memory associated with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this cc_ent.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this avoids conflicts for centrys on the 0 queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see sdbc_get_dmchain()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sdbc_use_dmchain) && (cc_ent->cc_data == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodata)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*nodata)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_availability_dm_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((SET_CENTRY_INUSE(cc_ent))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_availability_dm_end2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((SET_CENTRY_PAGEIO(cc_ent))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_availability_dm_end3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we allow the QHEAD flag as it does not affect the availabilty
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of memory for aging
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((CENTRY_DIRTY(cc_ent)) || (CENTRY_IO_INPROGRESS(cc_ent)) ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cc_ent->cc_flag & ~(CC_QHEAD)) ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_dirty_next || cc_ent->cc_dirty_link ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_aging_dm &= ~FINAL_AGING_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodata)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_data == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*nodata)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_availability_dm_end4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * function below to prohibit code movement by compiler
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and avoid using spinlocks for syncronization
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cc_iostatus_initiate(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_INITIATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_serialize();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Yet another switch!
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc mem and coalesce if at least this number of frags
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_coalesce_backend = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optimization for _sd_async_flclist()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called only if not doing pageio and sdbc_coalesce_backend > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns with pagio bit set in the centrys in list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic unsigned char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_io_mem(_sd_cctl_t *cc_ent, int first_dirty, int last_dirty)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *prev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent_orig = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int total_len_bytes = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *start_addr = NULL; /* function return value */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *next_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_frags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (first_dirty && (!_SD_BMAP_ISFULL(first_dirty))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WAIT_CENTRY_PAGEIO(cc_ent, sdbc_flush_pageio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_len_bytes += FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_addr = cc_ent->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WAIT_CENTRY_PAGEIO(cc_ent, sdbc_flush_pageio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for contiguity */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_addr &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana !((prev_addr + CACHE_BLOCK_SIZE) == cc_ent->cc_data))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++num_frags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* compute length */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FULLY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_len_bytes += CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(last_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_len_bytes += FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_addr = cc_ent->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_frags >= sdbc_coalesce_backend) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * TODO - determine metric for deciding
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * whether to coalesce memory or do separate i/o's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_io_mem_kmem_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start_addr = kmem_alloc(total_len_bytes, KM_NOSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sblk, offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent_orig;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_anon_addr.sa_virt = start_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_anon_len = total_len_bytes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_addr = start_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(sdbc_io_mem_bcopy_start,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, num_frags, int, total_len_bytes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy the first dirty piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (first_dirty && (!_SD_BMAP_ISFULL(first_dirty))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sblk = SDBC_LOOKUP_STPOS(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset = FBA_SIZE(sblk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent->cc_data + offset, next_addr,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(fba_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_addr += FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy the rest of data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FULLY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent->cc_data, next_addr,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_addr += CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(last_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent->cc_data, next_addr,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(fba_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_addr += FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_io_mem_bcopy_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_io_mem_kmem_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (start_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_async_flclist(_sd_cctl_t *cclist, dev_t rdev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flushed, i, cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t first_dirty, last_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *cc_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *bp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dblk, fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int toflush;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int coalesce; /* convenience boolean */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *anon_mem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern int sdbc_do_page;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FLCLIST, CENTRY_CD(cclist),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana 0, BLK_TO_FBA_NUM(CENTRY_BLK(cclist)), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte coalesce = (!sdbc_do_page && sdbc_coalesce_backend);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_iostatus_initiate(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_IS_FRAGMENTED(first_dirty)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cclist = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_flcent(cc_ent, rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent->cc_dirty_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_iocount)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_FLCLIST, CENTRY_CD(cc_ent), 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_iocount, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte toflush++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_iostatus_initiate(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_IS_FRAGMENTED(last_dirty)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_prev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_prev->cc_dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_flcent(cc_ent, rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte toflush++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (toflush == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk = BLK_TO_FBA_NUM(CENTRY_BLK(cclist));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (first_dirty && (!_SD_BMAP_ISFULL(first_dirty)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk += SDBC_LOOKUP_STPOS(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cclist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = sd_alloc_iob(rdev, dblk, toflush, B_WRITE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (coalesce && (anon_mem = sdbc_alloc_io_mem(cc_ent, first_dirty,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana last_dirty)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_anon_addr, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_NUM(cc_ent->cc_anon_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (first_dirty && (!_SD_BMAP_ISFULL(first_dirty))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = flushed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pageio bit already set in sdbc_alloc_io_mem() above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!coalesce)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WAIT_CENTRY_PAGEIO(cc_ent, sdbc_flush_pageio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* build buffer only if it was not done above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!anon_mem) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = SDBC_LOOKUP_STPOS(first_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, i, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSHLIST, cc_ent, i, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_async_flclist_data1, int,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + i,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, fba_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(i)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(i + fba_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flushed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_iostatus_initiate(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pageio bit already set in sdbc_alloc_io_mem() above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!coalesce)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WAIT_CENTRY_PAGEIO(cc_ent, sdbc_flush_pageio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FULLY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flushed++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* build buffer only if it was not done above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!anon_mem) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSHLIST, cc_ent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_async_flclist_data2,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_FBAS, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBAS) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len += CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consistency check.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!last_dirty || cc_ent->cc_dirty_next ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_IS_FRAGMENTED(last_dirty)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_FLCLIST, cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_next, last_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_sd_err: flclist: last_dirty %x next %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_dirty, cc_ent->cc_dirty_next);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flushed++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = SDBC_LOOKUP_LEN(last_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* build buffer only if it was not done above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!anon_mem) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSHLIST, cc_ent, 0, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_async_flclist_data3, int,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, fba_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(fba_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len += FBA_SIZE(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (anon_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(len == cclist->cc_anon_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* SDTRACE(ST_INFO|SDF_FLCLIST, cd, FBA_NUM(len), dblk, flushed, bp); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sd_start_io(bp, _sd_cache_files[cd].cd_strategy,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_flclist_ea, cclist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DISK_FBA_WRITE(cd, FBA_NUM(len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increment number of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRITE_DESTAGED(cd, FBA_NUM(len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_io_pending(cd, cclist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLCLIST, cd, FBA_NUM(len), dblk, flushed, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_enqueue_io_pending(int cd, _sd_cctl_t *cclist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_io_head == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_io_head = cdi->cd_io_tail = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_io_tail->cc_dirty_link = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_io_tail = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_async_flcent(_sd_cctl_t *cc_ent, dev_t rdev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dblk, len, sblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *bp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FLCENT, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG_PATTERN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte check_write_consistency(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_iocount)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDALERT(SDF_FLCENT, cd, 0, BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_iocount, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_iostatus_initiate(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WAIT_CENTRY_PAGEIO(cc_ent, sdbc_flush_pageio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_BMAP_ISFULL(dirty)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = sd_alloc_iob(rdev, dblk, 1, B_WRITE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSHENT, cc_ent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_async_flcent_data1,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_FBAS, char *, *(int64_t *)(cc_ent->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBAS) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sd_start_io(bp, _sd_cache_files[cd].cd_strategy,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_flcent_ea, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DISK_FBA_WRITE(cd, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increment number of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRITE_DESTAGED(cd, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = SDBC_LOOKUP_DTCOUNT(dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (dirty) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sblk = SDBC_LOOKUP_STPOS(dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = SDBC_LOOKUP_LEN(dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_LOOKUP_MODIFY(dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + sblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = sd_alloc_iob(rdev, dblk, 1, B_WRITE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, sblk, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSHENT, cc_ent, sblk, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_async_flcent_data2, int,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + sblk,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(sblk)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(sblk + len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* SDTRACE(ST_INFO|SDF_FLCENT, cd, len, dblk, 0, bp); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sd_start_io(bp, _sd_cache_files[cd].cd_strategy,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_flcent_ea, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DISK_FBA_WRITE(cd, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increment number of bytes destaged to disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRITE_DESTAGED(cd, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_io_pending(cd, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLCENT, cd, 0, dblk, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_process_pending(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dirty_enq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *dirty_hd, **dirty_nxt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sts, processed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FLDONE, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDT_INV_BL, cdi->cd_info->sh_numio, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprocess_loop:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_io_head == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (processed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio -= processed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLDONE, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDT_INV_BL, cdi->cd_info->sh_numio, processed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cdi->cd_io_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sts = cc_ent->cc_iostatus) == _SD_IO_INITIATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (processed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio -= processed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLDONE, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDT_INV_BL, cdi->cd_info->sh_numio, processed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LINTUSED(sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sts != _SD_IO_DONE) && (sts != _SD_IO_FAILED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_FLDONE, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), 0, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_io_head = cc_ent->cc_dirty_link) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_io_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_iostatus == _SD_IO_FAILED &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_process_failure(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto process_loop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_enq = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_nxt = &(dirty_hd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE1(_sd_process_pending_cd, int, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; cc_ent; cc_ent = cc_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_process_pending_cc_ent,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processed++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_next = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PINNED(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_process_reflush(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Optimize for common case where block not inuse
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Grabbing cc_inuse is faster than cc_lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto must_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY_PENDING(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~CC_PEND_DIRTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_enq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_nxt = &((*dirty_nxt)->cc_dirty_link);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*dirty_nxt) = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_enq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cc_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~(CC_PINNABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore, wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this was a QHEAD cache block, then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_centry_release() did not requeue it as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it was dirty. Requeue it now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_QHEAD(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* attempt to que head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_alloc_size_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_head_dm_try(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Block is inuse, must take cc_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if DIRTY_PENDING, must re-issue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte must_lock:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY_PENDING(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~CC_PEND_DIRTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_enq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_nxt = &((*dirty_nxt)->cc_dirty_link);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*dirty_nxt) = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_enq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear dirty bits, if block no longer inuse release cc_write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cc_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~(CC_PINNABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore, wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this was a QHEAD cache block, then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_centry_release() did not requeue it as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it was dirty. Requeue it now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_QHEAD(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* attempt to que head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_alloc_size_dm) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sdbc_requeue_head_dm_try
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_enq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty_chain(cd, dirty_hd, (*dirty_nxt), dirty_enq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto process_loop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_flcent_ea(blind_t xcc_ent, nsc_off_t fba_pos, nsc_size_t fba_len, int error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent = (_sd_cctl_t *)xcc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t dblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FLCENT_EA, cd, 0, dblk, 2, (unsigned long)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 1;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_flcent_ea) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Disk write failed cd %d (%s): err %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, cdi->cd_info->sh_filename, error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (--(cc_ent->cc_iocount) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* more io's to complete before the cc_ent is done. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_iocount < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_FLCENT_EA, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana dblk, cc_ent->cc_iocount, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLCENT_EA, cd, 0, dblk, 2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned long)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_flcent_ea_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLEA, cc_ent, BLK_FBA_OFF(fba_pos), fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_flcent_ea_data, uint64_t, ((uint64_t)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent) + BLK_FBA_OFF(fba_pos))),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)fba_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(BLK_FBA_OFF(fba_pos))),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBA_OFF(fba_pos) + fba_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All io's are done for this cc_ent.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear the pagelist io flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLCENT_EA, cd, 0, dblk, 2, (unsigned long)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_flclist_ea(blind_t xcc_ent, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent = (_sd_cctl_t *)xcc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *first_cc = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t dblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dblk = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FLCLIST_EA, cd, 0, dblk, 1, (unsigned long)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 1;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_flclist_ea) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Disk write failed cd %d (%s): err %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, cdi->cd_info->sh_filename, error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Important: skip the first cc_ent in the list. Marking this will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * make the writer think the io is done, though the rest of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chain have not been processed here. so mark the first cc_ent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * last. Optimization, so as not to use locks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(_sd_flclist_ea, _sd_cctl_t *, cc_ent,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, CENTRY_CD(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_iocount != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_FLCLIST_EA, cd, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_iocount, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear the pagelist io flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_dirty_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSTEA, cc_ent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_flclist_ea_data1, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_FBAS, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBAS) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSTEA, cc_ent, 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBA_OFF(fba_pos + fba_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_flclist_ea_data2, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)BLK_FBA_OFF(fba_pos + fba_len),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)(cc_ent->cc_data),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBA_OFF(fba_pos + fba_len)) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now process the first cc_ent in the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = first_cc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_FLSTEA, cc_ent, BLK_FBA_OFF(fba_pos),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS - BLK_FBA_OFF(fba_pos));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_flclist_ea_data3, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)fba_pos, int, BLK_FBAS - BLK_FBA_OFF(fba_pos),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBA_OFF(fba_pos))), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(BLK_FBA_OFF(fba_pos) +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS - BLK_FBA_OFF(fba_pos)) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iocount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_anon_addr.sa_virt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(cc_ent->cc_anon_addr.sa_virt, cc_ent->cc_anon_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_anon_addr.sa_virt = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_anon_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear the pagelist io flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FLCLIST_EA, cd, 0, dblk, 1, (unsigned long)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_mark_failed(_sd_cctl_t *cclist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cclist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_iostatus = _SD_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_io_pending(cd, cclist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fail single chain of cache blocks, updating numfail/numio counts.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For dual-copy, log & clear PINNED, fall thru to regular processing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_process_failure(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd, num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_chain = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cdi->cd_global->sv_pinned) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global->sv_pinned = _SD_SELF_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (num = 0; cc_ent; cc_ent = cc_ent->cc_dirty_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag |= (CC_PEND_DIRTY |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (CENTRY_PINNABLE(cc_ent) ? CC_PINNED : 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_write) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write->sc_flag = cc_ent->cc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, cc_ent->cc_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PINNED(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_pinned_data(cdi->cd_iodev,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In normal processing we wouldn't need a lock here as all i/o
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is single threaded by cd. However during failover blocks can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be failing from real i/o and as soon as the disk is marked bad
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the failover code which is furiously cloning safe-store into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * more blocks will short circuit to here (see _sd_ft_clone)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and two threads can be executing in here simultaneously.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_chain->cc_dirty_link = cdi->cd_fail_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_fail_head = cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numfail += num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio -= num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* blocks are failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_process_reflush(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PINNABLE(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unpinned_data(_sd_cache_files[cd].cd_iodev,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~CC_PINNED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd_write_thread -- flush dirty buffers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - cache descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called by cd's writer thread, returns when no more entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: if sdbc is being shutdown (for powerfail) then we will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process pending i/o's but issue no more new ones.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int SD_LOOP_DELAY = 32;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(m88k) && !defined(sun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int SD_WRITE_HIGH = 255; /* cache blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecd_write_thread(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_list, *dirty_head, *last_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_RUNNING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_process_pending(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_write_inprogress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(m88k) && !defined(sun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_numio > SD_WRITE_HIGH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* let I/Os complete before issuing more */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sdbc_flush_flag) { /* hang the flusher for testing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_write_inprogress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_head = cdi->cd_dirty_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_head && (dirty_head != cdi->cd_lastchain_ptr ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ++cdi->cd_info->sh_flushloop > SD_LOOP_DELAY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_flushloop = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SD_LOOP_DELAY == 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_head == cdi->cd_lastchain_ptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio += cdi->cd_info->sh_numdirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numdirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(m88k) && !defined(sun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_numdirty > SD_WRITE_HIGH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (last_chain = dirty_head; last_chain;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana last_chain = last_chain->cc_dirty_next)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_chain = dirty_head->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = last_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cdi->cd_dirty_tail is unchanged */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio += count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numdirty -= count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_chain = cdi->cd_lastchain_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = last_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail = last_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numio += cdi->cd_info->sh_numdirty -
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cdi->cd_lastchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numdirty = cdi->cd_lastchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (((cc_list = dirty_head) != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_list != last_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_head = cc_list->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_list->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_mark_failed(cc_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (cc_list->cc_dirty_next == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_flcent(cc_list, cdi->cd_crdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_async_flclist(cc_list, cdi->cd_crdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_write_inprogress++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_write_inprogress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd_writer -- spawn new writer if not running already
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called after enqueing the dirty blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecd_writer(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nstset_t *tset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_USE_THREADS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tset = _sd_ioset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_USE_THREADS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_writer || xmem_bu(_SD_WRITER_CREATE, &cdi->cd_writer))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = nst_create(tset, cd_write_thread, (blind_t)(unsigned long)cd, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(cd_writer) cd %d nst_create error", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_writer = _SD_WRITER_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_ccent_rd - add appropriate parts of cc_ent to struct buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optimized not to read dirty FBAs from disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_ent - single cache block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wanted - bitlist of FBAs that need to be read
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - struct buf to extend
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called for each dirty in a read I/O.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The bp must be sized to allow for one entry per FBA that needs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be read (see _sd_doread()).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_ccent_rd(_sd_cctl_t *cc_ent, uint_t wanted, struct buf *bp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index, offset = 0, size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int state, state1 = -3; /* state1 is previous state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_addr_t *addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < BLK_FBAS; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_BIT_ISSET(wanted, index))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state = _SD_BIT_ISSET(dirty, index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state == state1) /* same state, expand size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state1 != -3) /* not first FBA */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, addr, offset, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state1 = state; /* new previous state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state) { /* dirty, don't overwrite */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr = &cc_ent->cc_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state1 != -3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, addr, offset, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _SD_WR_THRESHOLD = 1000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_flush_thread(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_shared_t *shi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int short_sleep = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long tics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int waiting_for_idle = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int check_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pending, last_pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int SD_LONG_SLEEP_TICS, SD_SHORT_SLEEP_TICS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nstset_t *tset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_USE_THREADS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tset = _sd_ioset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_USE_THREADS */
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 /* .2 seconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SD_LONG_SLEEP_TICS = drv_usectohz(200000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* .02 seconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SD_SHORT_SLEEP_TICS = drv_usectohz(20000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_flush_exit == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait until no i/o's pending (on two successive
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iterations) or we see no progress after
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * GIVE_UP_WAITING total sleeps.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* at most 5*128 ticks about 6 seconds of no progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define GIVE_UP_WAITING 128
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (waiting_for_idle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pending = _sd_pending_iobuf();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pending == last_pending) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pending != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte check_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte check_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((last_pending == 0 && (pending == 0)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (check_count == GIVE_UP_WAITING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_dem_cnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (check_count == GIVE_UP_WAITING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_sd_flush_thread "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "exiting with %d IOs "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "pending", pending);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_pending = pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte waiting_for_idle = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_pending = _sd_pending_iobuf();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Normally wakeup every SD_LONG_SLEEP_TICS to flush.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!short_sleep) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssioc_stats_t ss_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = SSOP_CTL(sdbc_safestore, SSIOC_STATS,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uintptr_t)&ss_stats)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ss_stats.wq_inq < _SD_WR_THRESHOLD)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte short_sleep = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == SS_ERR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_flush_thread)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cannot get safestore inq");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (short_sleep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tics = SD_SHORT_SLEEP_TICS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tics = SD_LONG_SLEEP_TICS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_timed_block(tics, &_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt = short_sleep = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; (cnt < _sd_cache_stats->st_loc_count) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cd < sdbc_max_devs); cd++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shi = cdi->cd_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (shi == NULL || (shi->sh_failed == 2))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(shi->sh_alloc & CD_ALLOCATED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(shi->sh_flag & CD_ATTACHED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_CD_WBLK_USED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_failover == 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_failover = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_writer ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xmem_bu(_SD_WRITER_CREATE, &cdi->cd_writer))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = nst_create(tset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_write_thread, (blind_t)(unsigned long)cd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_write_thread(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG_PATTERN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheck_write_consistency(cc_entry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, dirty_bl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_entry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_bl = CENTRY_DIRTY(cc_entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_bl == 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!check: no dirty");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = (int *)cc_entry->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos = BLK_TO_FBA_NUM(CENTRY_BLK(cc_entry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < 8; i++, data += 128, fba_pos++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_bl & 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*((int *)(data + 2)) != fba_pos) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!wr exp %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " got %x", fba_pos, *(data + 2));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_bl >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_entry = cc_entry->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheck_buf_consistency(handle, rw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *rw;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bufvec_t *bvec1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bvec1 = handle->bh_bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos = handle->bh_fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (bvec1->bufaddr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = FBA_NUM(bvec1->buflen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = (int *)bvec1->bufaddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < fba_len; i++, data += 128, fpos++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*(data+2) != fpos) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!%s exp%" NSC_SZFMT " got%x",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana rw, fpos, *(data + 2));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bvec1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle->bh_fba_len != len) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!len %" NSC_SZFMT " real %" NSC_SZFMT, len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_wait_pending(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries, pend, last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last = _sd_pending_iobuf();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((pend = _sd_pending_iobuf()) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pend == last) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++tries > 60) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pend);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pend = last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}