fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cred.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/buf.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_ft.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_misc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sd_pcu.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_k.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/safestore.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi_impldefs.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kstat_t *sdbc_global_stats_kstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_global_stats_update(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_loc_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_rdhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_rdmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_wrhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_wrmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_blksize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_lru_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_lru_noreq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_lru_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_wlru_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cachesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_numblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_num_shared;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_wrcancelns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_destaged;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_nodehints;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_global_stats_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sdbc_global_stats_t sdbc_global_stats = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_COUNT, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_LOC_COUNT, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_RDHITS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_RDMISS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_WRHITS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_WRMISS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_BLKSIZE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_LRU_BLOCKS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_LRU_NOREQ, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_LRU_REQ, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_WLRU_INQ, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_CACHESIZE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_NUMBLOCKS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_NUM_SHARED, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_WRCANCELNS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_DESTAGED, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_GKSTAT_NODEHINTS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kstat_t **sdbc_cd_kstats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kstat_t **sdbc_cd_io_kstats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t *sdbc_cd_io_kstats_mutexes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kstat_t *sdbc_global_io_kstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t sdbc_global_io_kstat_mutex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_cd_stats_update(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cd_kstat_add(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cd_kstat_remove(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_vol_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_disk_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_numdirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_numio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_numfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_destaged;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_wrcancelns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cdhints;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_cd_stats_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sdbc_cd_stats_t sdbc_cd_stats = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_VOL_NAME, KSTAT_DATA_CHAR},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_FAILED, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_CD, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_CACHE_READ, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_CACHE_WRITE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_DISK_READ, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_DISK_WRITE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_FILESIZE, KSTAT_DATA_UINT64},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_FILESIZE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_NUMDIRTY, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_NUMIO, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_NUMFAIL, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_DESTAGED, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_WRCANCELNS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_CDKSTAT_CDHINTS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem kstat interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kstat_t *sdbc_dynmem_kstat_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int simplect_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_dynmem_kstat_update_dm(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_monitor_dynmem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_ct1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_ct2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_ct3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_sec1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_sec2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_sec3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_pcnt1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_cache_aging_pcnt2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_max_holds_pcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_alloc_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_dealloc_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_history;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_nodatas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_candidates;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_deallocs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_hosts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_pests;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_metas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_holds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_others;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_notavail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_process_directive;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_named_t ci_sdbc_simplect;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sdbc_dynmem_dm_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sdbc_dynmem_dm_t sdbc_dynmem_dm = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_MONITOR_DYNMEM, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_MAX_DYN_LIST, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_CT1, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_CT2, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_CT3, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_SEC1, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_SEC2, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_SEC3, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_PCNT1, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CACHE_AGING_PCNT2, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_MAX_HOLDS_PCNT, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_ALLOC_CNT, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_DEALLOC_CNT, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_HISTORY, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_NODATAS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_CANDIDATES, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_DEALLOCS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_HOSTS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_PESTS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_METAS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_HOLDS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_OTHERS, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_NOTAVAIL, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_PROCESS_DIRECTIVE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {SDBC_DMKSTAT_SIMPLECT, KSTAT_DATA_ULONG}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* End of dynmem kstats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *dmchainpull_table; /* dmchain wastage stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem process vars
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern _dm_process_vars_t dynmem_processing_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* metadata for volumes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortess_voldata_t *_sdbc_gl_file_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t _sdbc_gl_file_info_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* metadata for cache write blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ss_centry_info_t *_sdbc_gl_centry_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* wblocks * sizeof(ss_centry_info_t) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t _sdbc_gl_centry_info_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _SD_DELAY_QUEUE = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_allocb_inuse, sdbc_allocb_lost, sdbc_allocb_hit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_allocb_pageio1, sdbc_allocb_pageio2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_centry_hit, sdbc_centry_inuse, sdbc_centry_lost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_dmchain_not_avail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_allocb_deallocd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_centry_deallocd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_check_cot;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_ra_hash; /* 1-block read-ahead fails due to hash hit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_ra_none; /* 1-block read-ahead fails due to "would block" */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set the following variable to 1 to enable pagelist io mutual
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exclusion on all _sd_alloc_buf() operations.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is set to ON to prevent front end / back end races between new
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_WRTHRU io operations coming in through _sd_alloc_buf(), and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * previously written data being flushed out to disk by the sdbc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flusher at the back end.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -- see bugtraq 4287564
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -- Simon Crosland, Mon Nov 8 16:34:09 GMT 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_pageio_always = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_use_dmchain = 0; /* start time switch for dm chaining */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_prefetch1 = 1; /* do 1-block read-ahead */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if sdbc_static_cache is 1 allocate all cache memory at startup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * deallocate only at shutdown.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_static_cache = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Pagelist io mutual exclusion debug facility.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_PAGEIO_OFF 0 /* no debug */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_PAGEIO_RDEV 1 /* force NSC_PAGEIO for specified dev */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_PAGEIO_RAND 2 /* randomly force NSC_PAGEIO */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SDBC_PAGEIO_ALL 3 /* always force NSC_PAGEIO */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_pageio_debug = SDBC_PAGEIO_OFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic dev_t sdbc_pageio_rdev = (dev_t)-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INF SD cache global data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cd_info_t *_sd_cache_files;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_stats_t *_sd_cache_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t _sd_cache_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_hash_table_t *_sd_htable;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_queue_t _sd_lru_q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cctl_t *_sd_cctl[_SD_CCTL_GROUPS];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _sd_cctl_groupsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_net_t _sd_net_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern krwlock_t sdbc_queue_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteunsigned int _sd_node_hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_LRU_Q (&_sd_lru_q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint BLK_FBAS; /* number of FBA's in a cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint CACHE_BLOCK_SIZE; /* size in bytes of a cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint CBLOCKS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_bitmap_t BLK_FBA_BITS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_valid_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_busy_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_trailing;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_deallocd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_pageio1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_pageio2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_hit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_prefetch_lost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_prefetch_opt = 1; /* 0 to disable & use _prefetch_sb_vec[] */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_vec_t _prefetch_sb_vec[_SD_MAX_BLKS + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_bitmap_t _fba_bits[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x0000, 0x0001, 0x0003, 0x0007,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x000f, 0x001f, 0x003f, 0x007f,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00ff,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_8K_BLKSIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x01ff, 0x03ff, 0x07ff,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x0fff, 0x1fff, 0x3fff, 0x7fff,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xffff,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_ccsync_cnt = 256;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_sync_t *_sd_ccent_sync;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_io_t *sdbc_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_stats32_t *_sd_cache_stats32 = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint cmn_level = CE_PANIC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint cmn_level = CE_WARN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
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 _sdbc_stats_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_stats_configure(int cblocks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_lruq_configure(_sd_queue_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_lruq_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_mem_configure(int cblocks, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_mem_deconfigure(int cblocks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_ins_queue(_sd_queue_t *, _sd_cctl_t *centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_flush_cd(int cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_check_buffer_alloc(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t **hp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_doread(_sd_buf_handle_t *handle, _sd_cctl_t *cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos, nsc_size_t fba_len, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_async_read_ea(blind_t xhandle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_async_write_ea(blind_t xhandle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_queue_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_remote_store(_sd_cctl_t *cc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_copy_direct(_sd_buf_handle_t *handle1, _sd_buf_handle_t *handle2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos1, nsc_off_t fba_pos2, nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_sync_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_sync_write2(_sd_buf_handle_t *wr_handle, nsc_off_t wr_st_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag, _sd_buf_handle_t *rd_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t rd_st_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_fd_attach_cd(blind_t xcd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_fd_detach_cd(blind_t xcd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_fd_flush_cd(blind_t xcd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_gl_centry_configure(spcs_s_info_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_gl_file_configure(spcs_s_info_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_gl_centry_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_gl_file_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_doread_prefetch(_sd_cctl_t *cc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_bitmap_t update_dirty(_sd_cctl_t *cc_ent, sdbc_cblk_fba_t st_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_prefetch_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag, _sd_buf_handle_t *handle, int locked);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* dynmem support */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_setup_category_on_type(_sd_cctl_t *header);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_setup_mem_chaining(_sd_cctl_t *header, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_check_cctl_cot(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_dmqueues_configure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_dmqueues_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *sdbc_get_dmchain(int, int *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_dmchain_avail(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_requeue_dmchain(_sd_queue_t *, _sd_cctl_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_ins_dmqueue_back(_sd_queue_t *, _sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_ins_dmqueue_front(_sd_queue_t *, _sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_remq_dmchain(_sd_queue_t *, _sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_clear_dmchain(_sd_cctl_t *, _sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_requeue_head_dm_try(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *sdbc_alloc_dmc(int, nsc_off_t, nsc_size_t, int *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *sdbc_alloc_lru(int, nsc_off_t, int *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *sdbc_alloc_from_dmchain(int, nsc_off_t, sdbc_allocbuf_t *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_centry_init_dm(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_centry_memalloc_dm(_sd_cctl_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_centry_alloc_end(sdbc_allocbuf_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* _SD_DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG) || defined(DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_cctl_valid(_sd_cctl_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_def_t _sdbc_fd_def[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Attach", (uintptr_t)sdbc_fd_attach_cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Detach", (uintptr_t)sdbc_fd_detach_cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Flush", (uintptr_t)sdbc_fd_flush_cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_cache_configure - initialize cache blocks, queues etc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SDBC_EENABLEFAIL or SDBC_EMEMCONFIG on failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_cache_configure(int cblocks, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CBLOCKS = cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files = (_sd_cd_info_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sdbc_max_devs * sizeof (_sd_cd_info_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_stats_configure(cblocks))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SDBC_EENABLEFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_dmqueues_configure())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SDBC_EENABLEFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_lruq_configure(_SD_LRU_Q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SDBC_EENABLEFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_mem_configure(cblocks, kstatus))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SDBC_EMEMCONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_BLOCK_SIZE = BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBAS = FBA_NUM(CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBA_BITS = _fba_bits[BLK_FBAS];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_pageio1 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_pageio2 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_hit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_inuse = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_lost = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_inuse = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_lost = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_hit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_deallocd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dmchain_not_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_deallocd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_valid_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_busy_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_trailing = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_deallocd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_pageio1 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_pageio2 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_hit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_lost = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_check_cot = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch1 = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ra_hash = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ra_none = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_cache_deconfigure - cache is being deconfigured. Release any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory that we acquired during the configuration process and return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the unconfigured state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: all users of the cache should be inactive at this point,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i.e. we are unregistered from sd and all cache daemons/threads are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gone.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_cache_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CCIO shutdown must happen before memory is free'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sd_cache_files,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_max_devs * sizeof (_sd_cd_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files = (_sd_cd_info_t *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBA_BITS = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBAS = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_BLOCK_SIZE = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_mem_deconfigure(CBLOCKS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_file_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dmqueues_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_lruq_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_stats_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CBLOCKS = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_stats_deconfigure - cache is being deconfigured turn off
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stats. This could seemingly do more but we leave most of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data intact until cache is configured again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_stats_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_dynmem_kstat_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_dynmem_kstat_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_stats_kstat) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_global_stats_kstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_kstat = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_kstats[i]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_cd_kstats[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[i] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_cd_kstats, sizeof (kstat_t *) * sdbc_max_devs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_global_io_kstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&sdbc_global_io_kstat_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_io_kstat = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats[i]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_cd_io_kstats[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[i] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_cd_io_kstats, sizeof (kstat_t *) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_max_devs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats_mutexes) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mutexes are already destroyed in cd_kstat_remove() */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana kmem_free(sdbc_cd_io_kstats_mutexes,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sizeof (kmutex_t) * sdbc_max_devs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats_mutexes = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_stats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sd_cache_stats,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (_sd_stats_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devs - 1) * sizeof (_sd_shared_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_stats32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sd_cache_stats32, sizeof (_sd_stats32_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devs - 1) * sizeof (_sd_shared_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32 = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_stats_configure(int cblocks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats = kmem_zalloc(sizeof (_sd_stats_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devs - 1) * sizeof (_sd_shared_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_blksize = (int)BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_cachesize = cblocks * BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_numblocks = cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_wrcancelns = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_destaged = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32 = kmem_zalloc(sizeof (_sd_stats32_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devs - 1) * sizeof (_sd_shared_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* kstat implementation - global stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_kstat = kstat_create(SDBC_KSTAT_MODULE, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_KSTAT_GSTATS, SDBC_KSTAT_CLASS, KSTAT_TYPE_NAMED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (sdbc_global_stats)/sizeof (kstat_named_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_FLAG_VIRTUAL|KSTAT_FLAG_WRITABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_stats_kstat != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_kstat->ks_data = &sdbc_global_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_kstat->ks_update = sdbc_global_stats_update;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_kstat->ks_private = _sd_cache_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_install(sdbc_global_stats_kstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc: gstats kstat failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* global I/O kstats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_io_kstat = kstat_create(SDBC_KSTAT_MODULE, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_IOKSTAT_GSTATS, "disk", KSTAT_TYPE_IO, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global_io_kstat) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&sdbc_global_io_kstat_mutex, NULL, MUTEX_DRIVER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_io_kstat->ks_lock =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sdbc_global_io_kstat_mutex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_install(sdbc_global_io_kstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat implementation - cd stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: one kstat instance for each open cache descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats = kmem_zalloc(sizeof (kstat_t *) * sdbc_max_devs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat implementation - i/o kstats per cache descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: one I/O kstat instance for each cd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats = kmem_zalloc(sizeof (kstat_t *) * sdbc_max_devs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats_mutexes = kmem_zalloc(sizeof (kmutex_t) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_max_devs, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* kstat implementation - dynamic memory stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm = kstat_create(SDBC_KSTAT_MODULE, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_KSTAT_DYNMEM, SDBC_KSTAT_CLASS, KSTAT_TYPE_NAMED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (sdbc_dynmem_dm)/sizeof (kstat_named_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_FLAG_VIRTUAL|KSTAT_FLAG_WRITABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_dynmem_kstat_dm != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm->ks_data = &sdbc_dynmem_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm->ks_update = sdbc_dynmem_kstat_update_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm->ks_private = &dynmem_processing_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_install(sdbc_dynmem_kstat_dm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc: dynmem kstat failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_dmqueues_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize the queues of dynamic memory chains.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_queue_t *sdbc_dm_queues;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int max_dm_queues;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dmqueues_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CAUTION! this code depends on max_dyn_list not changing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it does change behavior may be incorrect, as cc_alloc_size_dm
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depends on max_dyn_list and indexes to dmqueues are derived from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_alloc_size_dm.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see _sd_setup_category_on_type() and _sd_dealloc_dm()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * TODO: prevent max_dyn_list from on-the-fly modification (easy) or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allow for on-the-fly changes to number of dm queues (hard).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_dm_queues = dynmem_processing_dm.max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++max_dm_queues; /* need a "0" queue for centrys with no memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dm_queues = (_sd_queue_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana kmem_zalloc(max_dm_queues * sizeof (_sd_queue_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmchainpull_table = (int *)kmem_zalloc(max_dm_queues *
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana max_dm_queues * sizeof (int), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < max_dm_queues; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sdbc_lruq_configure(&sdbc_dm_queues[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dm_queues[i].sq_dmchain_cblocks = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dmqueues_deconfigure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CAUTION! this code depends on max_dyn_list not changing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_dm_queues)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_dm_queues, max_dm_queues * sizeof (_sd_queue_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dm_queues = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_dm_queues = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define GOOD_LRUSIZE(q) ((q->sq_inq >= 0) || (q->sq_inq <= CBLOCKS))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_lruq_configure - initialize the lru queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: NONE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS: 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_lruq_configure(_sd_queue_t *_sd_lru)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lru->sq_inq = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_lru->sq_qlock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lru->sq_qhead.cc_next = _sd_lru->sq_qhead.cc_prev
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana = &(_sd_lru->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_lruq_deconfigure - deconfigure the lru queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: NONE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_lruq_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *_sd_lru;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lru = _SD_LRU_Q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_sd_lru->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(_sd_lru, sizeof (_sd_queue_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_mem_configure - initialize the cache memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create and initialize the hash table.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create cache control blocks and fill them with relevent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information and enqueue onto the lru queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize the Write control blocks (blocks that contain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information as to where the data will be mirrored)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize the Fault tolerant blocks (blocks that contain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information about the mirror nodes dirty writes)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS: 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_mem_configure(int cblocks, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_blks, i, blk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_net_t *netc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *prev_entry_dm, *first_entry_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_htable = _sdbc_hash_configure(cblocks)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_ENOHASH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_groupsz = (cblocks / _SD_CCTL_GROUPS) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((cblocks % _SD_CCTL_GROUPS) != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl[i] = (_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_zalloc(_sd_cctl_groupsz * sizeof (_sd_cctl_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP, sdbc_cache_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cctl[i] == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_ENOCB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ccent_sync = (_sd_cctl_sync_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_zalloc(_sd_ccsync_cnt * sizeof (_sd_cctl_sync_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP, sdbc_local_mem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_ccent_sync == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_ENOCCTL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _sd_ccsync_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_ccent_sync[i]._cc_lock, NULL, MUTEX_DRIVER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&_sd_ccent_sync[i]._cc_blkcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blk = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netc = &_sd_net_config;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_blks = (netc->sn_cpages * (int)netc->sn_psize)/BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_entry_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_entry_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < num_blks; i++, blk++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = _sd_cctl[(blk/_sd_cctl_groupsz)] +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (blk%_sd_cctl_groupsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_sync = &_sd_ccent_sync[blk % _sd_ccsync_cnt];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next = centry->cc_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_dirty_next = centry->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_await_use = centry->cc_await_page = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_inuse = centry->cc_pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_iocount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!first_entry_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_entry_dm = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_entry_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_entry_dm->cc_link_list_dm = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_entry_dm = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_link_list_dm = first_entry_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_cblocks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = _SD_LRU_Q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ins_queue(q, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_gl_centry_configure(kstatus) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_gl_file_configure(kstatus) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_gl_file_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate and initialize space for the global filename data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_gl_file_configure(spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *fileinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t tempfinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_vdir_t vdir;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_vdirkey_t key;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_file_info_size = safestore_config.ssc_maxfiles *
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sizeof (ss_voldata_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sdbc_gl_file_info = kmem_zalloc(_sdbc_gl_file_info_size,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana KM_NOSLEEP)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_ENOSFNV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup the key to get a directory stream of all volumes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte key.vk_type = CDIR_ALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileinfo = _sdbc_gl_file_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if coming up after a crash, "refresh" the host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory copy from safestore.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_warm_start()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_GETVDIR(sdbc_safestore, &key, &vdir)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the vdir getting volume data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and volume tokens
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETVDIRENT(sdbc_safestore, &vdir, fileinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == SS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++fileinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != SS_EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail to configure since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is not possible.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_ENOREFRESH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* normal initialization, not a warm start */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this fails, continue: cache will start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in writethru mode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_GETVDIR(sdbc_safestore, &key, &vdir)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the vdir getting just the volume tokens
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and initializing volume entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETVDIRENT(sdbc_safestore, &vdir,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &tempfinfo)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize the host memory copy of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global file region. this means setting the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _pinned and _attached fields to _SD_NO_HOST
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * because the default of zero conflicts with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the min nodeid of zero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileinfo->sv_vol = tempfinfo.sv_vol;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileinfo->sv_pinned = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileinfo->sv_attached = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fileinfo->sv_cd = _SD_NO_CD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize the directory entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = SSOP_SETVOL(sdbc_safestore, fileinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == SS_ERR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "volume entry write failure %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)fileinfo->sv_vol);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++fileinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* coming up clean, continue in w-t mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != SS_EOF)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "unable to init safe store volinfo");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_gl_centry_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_gl_centry_info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sdbc_gl_centry_info, _sdbc_gl_centry_info_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_info_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_gl_centry_configure(spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int wblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *cinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_cdirkey_t key;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_cdir_t cdir;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wblocks = safestore_config.ssc_wsize / BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_info_size = sizeof (ss_centry_info_t) * wblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sdbc_gl_centry_info = kmem_zalloc(_sdbc_gl_centry_info_size,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana KM_NOSLEEP)) == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "alloc failed for gl_centry_info region");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * synchronize the centry info area with safe store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup the key to get a directory stream of all centrys */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte key.ck_type = CDIR_ALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cinfo = _sdbc_gl_centry_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_warm_start()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_GETCDIR(sdbc_safestore, &key, &cdir)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the cdir getting resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tokens and reading centrys
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETCDIRENT(sdbc_safestore, &cdir, cinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++cinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != SS_EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail to configure since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is not possible.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_centry_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, SDBC_EGLDMAFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_GETCDIR(sdbc_safestore, &key, &cdir)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the cdir getting resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tokens and initializing centrys
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETCDIRENT(sdbc_safestore, &cdir, cinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cinfo->sc_cd = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cinfo->sc_fpos = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = SSOP_SETCENTRY(sdbc_safestore, cinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == SS_ERR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cache entry write failure %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)cinfo->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++cinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* coming up clean, continue in w-t mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != SS_EOF) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(sdbc_gl_centry_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "_sdbc_gl_centry_info initialization failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_gl_file_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_gl_file_info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sdbc_gl_file_info, _sdbc_gl_file_info_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_file_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_file_info_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_mem_deconfigure - deconfigure the cache memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release any memory/locks/sv's acquired during _sdbc_mem_configure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_mem_deconfigure(int cblocks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_ccent_sync) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _sd_ccsync_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_sd_ccent_sync[i]._cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&_sd_ccent_sync[i]._cc_blkcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(_sd_ccent_sync,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_ccsync_cnt * sizeof (_sd_cctl_sync_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ccent_sync = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cctl[i] != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(_sd_cctl[i],
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_groupsz * sizeof (_sd_cctl_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl[i] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_groupsz = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_hash_deconfigure(_sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG) || defined(DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cctl_valid(_sd_cctl_t *addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *end;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, valid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end = _sd_cctl[i] + _sd_cctl_groupsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addr >= _sd_cctl[i] && addr < end) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (valid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_ins_queue - insert centry into LRU queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (during initialization, locking not required)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_ins_queue(_sd_queue_t *q, _sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *q_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(centry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q_head = &q->sq_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_prev = q_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next = q_head->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q_head->cc_next->cc_prev = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q_head->cc_next = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_inq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(GOOD_LRUSIZE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_requeue(_sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q = _SD_LRU_Q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cp, *cn, *qp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = centry->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cn = centry->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qp = (q->sq_qhead).cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cctl_valid(centry) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cp != &(q->sq_qhead) && !_sd_cctl_valid(cp)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cn != &(q->sq_qhead) && !_sd_cctl_valid(cn)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !_sd_cctl_valid(qp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_requeue %x prev %x next %x qp %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry, cp, cn, qp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_prev->cc_next = centry->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next->cc_prev = centry->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_prev = q->sq_qhead.cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_qhead.cc_prev->cc_next = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_qhead.cc_prev = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->sq_req_stat)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_requeue_head(_sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q = _SD_LRU_Q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cp, *cn, *qn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = centry->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cn = centry->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qn = (q->sq_qhead).cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cctl_valid(centry) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cp != &(q->sq_qhead) && !_sd_cctl_valid(cp)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cn != &(q->sq_qhead) && !_sd_cctl_valid(cn)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !_sd_cctl_valid(qn))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_requeue_head %x prev %x next %x qn %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry, cp, cn, qn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_prev->cc_next = centry->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next->cc_prev = centry->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_prev = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next = q->sq_qhead.cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_qhead.cc_next->cc_prev = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_qhead.cc_next = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag &= ~CC_QHEAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_open - Open a file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * filename - Name of the file to be opened.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - Flag associated with open.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (currently used to determine a ckd device)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_open(char *filename, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_open) cache not initialized");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = _sd_open_cd(filename, -1, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_OPEN, (cd < 0) ? SDT_INV_CD : cd, 0, SDT_INV_BL, 0, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_open_io(char *filename, int flag, blind_t *cdp, nsc_iodev_t *iodev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cd = _sd_open(filename, flag)) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_iodev = iodev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_set_owner(cdi->cd_rawfd, cdi->cd_iodev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cdp = (blind_t)(unsigned long)cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_open_cd(char *filename, const int cd, const int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int new_cd, rc = 0, alloc_cd = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_voldata_t *cdg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int preexists = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int failover_open, open_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte major_t devmaj;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_t devmin;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(filename) > (NSC_MAXPATH-1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-ENAMETOOLONG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the cd is >= 0, then this is a open for a specific cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This happens when the mirror node crashes, and we attempt to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reopen the files with the same cache descriptors as existed on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the other node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_open:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte failover_open = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte open_failed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte failover_open++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info = &_sd_cache_stats->st_shared[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (cdi->cd_info->sh_alloc &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(cdi->cd_info->sh_filename, filename)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_open_cd) cd %d mismatch",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-EEXIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_alloc != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte preexists = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc = CD_ALLOC_IN_PROGRESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(cdi->cd_info->sh_filename,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_stats->st_count < sdbc_max_devs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_cd = cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto known_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_cd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cdi = &(_sd_cache_files[new_cd]),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cdg = _sdbc_gl_file_info + new_cd;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana new_cd < (sdbc_max_devs); new_cd++, cdi++, cdg++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(cdg->sv_volname) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(cdg->sv_volname, filename))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info = &_sd_cache_stats->st_shared[new_cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_alloc != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte preexists = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == -2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc = CD_ALLOC_IN_PROGRESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(cdi->cd_info->sh_filename,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(cdg->sv_volname, filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdg->sv_cd = new_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update safestore */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_stats->st_count < sdbc_max_devs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_cd = new_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (alloc_cd == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-ENOSPC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteknown_cd:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If preexists: someone else is attempting to open this file as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * well. Do only one open, but block everyone else here till the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * open is completed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (preexists) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cdi->cd_info->sh_alloc == CD_ALLOC_IN_PROGRESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(20000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info->sh_alloc != CD_ALLOCATED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_open;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(cdi->cd_rawfd =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_open(filename, NSC_SDBC_ID|NSC_DEVICE, _sdbc_fd_def,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (blind_t)(unsigned long)alloc_cd, &rc)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !nsc_getval(cdi->cd_rawfd, "DevMaj", (int *)&devmaj) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !nsc_getval(cdi->cd_rawfd, "DevMin", (int *)&devmin)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_rawfd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_close(cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_rawfd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take into account that there may be pinned data on a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * device that can no longer be opened
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte open_failed++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(cdi->cd_info->sh_failed) && !failover_open) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_strategy = nsc_get_strategy(devmaj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_crdev = makedevice(devmaj, devmin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_desc = alloc_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = cdi->cd_dirty_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_io_head = cdi->cd_io_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_hint = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put the dev_t in the ioerr_inject_table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ioj_set_dev(alloc_cd, cdi->cd_crdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global = (_sdbc_gl_file_info + alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (open_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cdi->cd_info->sh_failed != 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_global->sv_pinned == _SD_SELF_HOST) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana !failover_open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_flag |= flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&cdi->cd_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SD_NOTRACE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sdbc_tr_configure(alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc = CD_ALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global = (_sdbc_gl_file_info + alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_cd = (unsigned short) alloc_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_loc_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd_kstat_add(alloc_cd) < 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Could not create kstats for cache descriptor"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " %d", alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (open_failed ? -EIO : alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_close - Close a cache descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to be closed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: Under Construction.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_close(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info->sh_alloc == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_info->sh_alloc & CD_CLOSE_IN_PROGRESS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc |= CD_CLOSE_IN_PROGRESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_flush_cd() will return -1 for the case where pinned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data is present, but has been transfered to the mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node. In this case it is safe to close the device as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * though _sd_flush_cd() had returned 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_flush_cd(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc == EAGAIN) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cdi->cd_global->sv_pinned == _SD_NO_HOST)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cdi->cd_global->sv_pinned = _SD_SELF_HOST;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc &= ~CD_CLOSE_IN_PROGRESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _SD_CD_WBLK_USED(cd), rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_close(cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc &= ~CD_CLOSE_IN_PROGRESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_loc_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd_kstat_remove(cd) < 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Could not remove kstat for cache descriptor "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_alloc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_failed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cdi->cd_info = NULL; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = NSC_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_close_io(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = _sd_close((int)cd)) == NSC_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_iodev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_remote_store_pinned - reflect pinned/failed blocks for cd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to our remote mirror. Returns count of blocks reflected or -1 on error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_remote_store_pinned(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *cc_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_pinned == _SD_NO_HOST) {
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 mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_list = cdi->cd_fail_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* is this always necessary? jgk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_WRITE_CBLOCK(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_write->sc_res, cc_ent->cc_data,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CACHE_BLOCK_SIZE, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update the cache block metadata */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_SET_FTPOS(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write->sc_flag = cc_ent->cc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write->sc_dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, cc_ent->cc_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_list = cc_list->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_flush_cd()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reflect pinned blocks to mirrored node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for dirty blocks to be flushed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EIO I/O failure, or pinned blocks and no mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EAGAIN Hang: count of outstanding writes isn't decreasing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 pinned blocks, reflected to mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_flush_cd(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = _sd_wait_for_flush(cd)) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we timed out simply return otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it must be an i/o type of error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_is_mirror_down())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO); /* already failed, no mirror */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flush any pinned/failed blocks to mirror */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_remote_store_pinned(cd) >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * At this point it looks like we have blocks on the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failed list and taking up space on this node but
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no longer have responsibility for the blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * These blocks will in fact be freed from the cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the failed list when the mirror picks them up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from safe storage and then calls _sd_cd_discard_mirror
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which will issue an rpc telling us to finish up.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Should the other node die before sending the rpc then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we are safe with these blocks simply waiting on the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failed list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_io_attach_cd -- set up for client access to device, reserve raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to attach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_io_attach_cd(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_shutdown_in_progress ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sdbc_io_attach_cd_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check if disk is failed without raw device open. If it is,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it has to be recovered using _sd_disk_online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_pinned == _SD_SELF_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_print(3,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sdbc_io_attach_cd: pinned data. returning EINVAL");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sdbc_io_attach_cd_end2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info == NULL) || (cdi->cd_info->sh_failed)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sdbc_io_attach_cd_end3,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana struct _sd_shared *, cdi->cd_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for node recovery to finish */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (_sd_node_recovery)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void) _sd_recovery_wait();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will provoke a sdbc_fd_attach_cd call .. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_reserve(cdi->cd_rawfd, NSC_MULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_fd_attach_cd -- setup cache for access to raw device underlying cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is provoked by some piece of sdbc doing a reserve on the raw device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to attach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_fd_attach_cd(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized || !FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_fd_attach_cd_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* retrieve pinned/failed data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_node_recovery) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_repin_cd(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_partsize(cdi->cd_rawfd, &cdi->cd_info->sh_filesize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_fd_attach_cd_end3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global->sv_attached = _SD_SELF_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_flag |= CD_ATTACHED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_io_detach_cd -- release raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called when a cache client is being detached from this cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_io_detach_cd(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized || !FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_DETACH, cd, 0, SDT_INV_BL, 0, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sdbc_io_detach_cd_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_FAULT_RES)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (_sd_node_recovery)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void) _sd_recovery_wait();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* relinquish responsibility for device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(cdi->cd_rawfd) || !nsc_held(cdi->cd_rawfd)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_detach_cd)(%d) not attached", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_DETACH, cd, 0, SDT_INV_BL, 0, EPROTO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sdbc_io_detach_cd_end2,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana nsc_fd_t *, cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EPROTO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will provoke/allow a call to sdbc_fd_detach_cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(cdi->cd_rawfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_detach_cd -- flush dirty writes to disk, release raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called when raw device is being detached from this cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rd_only - non-zero if detach is for read access.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_detach_cd(blind_t xcd, int rd_only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cache_initialized || !FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_detach_cd_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_flush_cd(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(sdbc_detach_cd_end2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rd_only) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_invalidate_cd(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_attached == _SD_SELF_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global->sv_attached = _SD_NO_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_detach_cd) (%d) attached by node %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, cdi->cd_global->sv_attached);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_DETACH, cd, 0, SDT_INV_BL, 0, EPROTO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(sdbc_detach_cd_end3,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, cdi->cd_global->sv_attached);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EPROTO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_flag &= ~CD_ATTACHED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_cache_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_fd_detach_cd -- flush dirty writes to disk, release raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called when raw device is being detached from this cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xcd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_fd_detach_cd(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sdbc_detach_cd(xcd, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_fd_flush_cd - raw device "xcd" is being detached and needs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flushing. We only need to flush we don't need to hash invalidate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_fd_flush_cd(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sdbc_detach_cd(xcd, 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_get_pinned - re-issue PINNED callbacks for cache device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to reissue pinned calbacks from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_pinned(blind_t xcd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_list, *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd < 0 || cd >= sdbc_max_devs) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_get_pinned_end1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_get_pinned_end2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cdi->cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_get_pinned_end3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_list = cdi->cd_fail_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PINNED(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_pinned_data(cdi->cd_iodev,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_list = cc_list->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_allocate_buf - allocate a vector of buffers for io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * *This call has been replaced by _sd_alloc_buf*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_buf_handle_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_allocate_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *sts)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sts = _sd_alloc_buf((blind_t)(unsigned long)cd, fba_pos, fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*sts == NSC_HIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sts = NSC_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_prefetch_buf - _sd_alloc_buf w/flag = NSC_RDAHEAD|NSC_RDBUF
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no 'bufvec' (data is not read by caller)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * skip leading valid or busy entries (data available sooner)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * truncate on busy block (to avoid deadlock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * release trailing valid entries, adjust length before starting I/O.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_prefetch_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle, int locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t cblk; /* position of temp cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t io_pos; /* offset in FBA's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_orig_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sts, stall;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *lentry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *ioent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *last_ioent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t alloc_tok = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int this_entry_type = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t request_blocks = 0; /* number of cache blocks required */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pageio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: truncate if req'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > sdbc_max_fbas)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = sdbc_max_fbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_pos + fba_len) > cdi->cd_info->sh_filesize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_pos >= cdi->cd_info->sh_filesize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = cdi->cd_info->sh_filesize - fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SETUP_HANDLE(handle, cd, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk = FBA_TO_BLK_NUM(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count number of blocks on chain that is required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte request_blocks = 1; /* at least one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* middle piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte request_blocks += (fba_len - (st_cblk_len + end_cblk_len)) >>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBA_SHFT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (end_cblk_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stall = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = ((flag & NSC_PAGEIO) != 0 || sdbc_pageio_always != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecget:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry = (_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_search(cd, cblk, _sd_htable)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: skip leading valid blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ioent == NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_VALID_BITS(st_cblk_off, st_cblk_len, centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteskip:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_valid_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((fba_len > (nsc_size_t)BLK_FBAS) ?
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS : fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto skip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_busy_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len -= fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = lentry; /* backup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bug 4529671
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now that we own the centry make sure that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is still good. it could have been processed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by _sd_dealloc_dm() in the window between
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_hash_search() and SET_CENTRY_INUSE().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_search(cd, cblk, _sd_htable) != centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_deallocd++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!prefetch centry %p cd %d cblk %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " fba_len %" NSC_SZFMT " lost to dealloc?! "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cc_data %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)centry, cd, cblk, fba_orig_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)centry->cc_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before messing with the centry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pageio && SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flusher not done with pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto skip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_pageio1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len -= fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = lentry; /* backup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_hit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HASH_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_hits++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will reset the age flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_init_dm(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_prefetch_buf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* block mismatch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_lost++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_centry_alloc(cd, cblk, request_blocks,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &stall, &alloc_tok, ALLOC_NOWAIT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: cache is very busy. just do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the i/o for the blocks already acquired,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if any.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len -= fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we have a chain of centry's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then back up (set centry to lentry).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if there is no chain (ioent == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then centry remains NULL. this can occur
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if all previous centrys were hash hits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on valid blocks that were processed in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the skip logic above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = lentry; /* backup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dmchaining adjustment.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if centry was obtained from the dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then clear local pageio variable because the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry already has cc_pageio set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PAGEIO(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE1(_sd_alloc_buf, _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = ELIGIBLE_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_IN_HASH_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HASH_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_HOLD_OVER_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HOLD_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion now if we did not do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pageio && SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flusher not done with pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_pageio2++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto skip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_busy_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len -= fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = lentry; /* backup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_pos = BLK_TO_FBA_NUM(cblk) + st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioent = last_ioent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_ALLOC, centry, st_cblk_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_prefetch_buf_data1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t, (uint64_t)(BLK_TO_FBA_NUM(cblk) +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana st_cblk_off), int, st_cblk_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)(centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off)), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off + st_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_centry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((fba_len > (nsc_size_t)BLK_FBAS) ?
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS : fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len, centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_ioent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_prefetch_buf_data2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t, (uint64_t)(BLK_TO_FBA_NUM(cblk) +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana st_cblk_off), int, st_cblk_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off)), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off + st_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry->cc_chain = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len < (nsc_size_t)BLK_FBAS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if this block has a new identity clear prefetch history */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (this_entry_type != HASH_ENTRY_DM)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_aging_dm &=
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ~(PREFETCH_BUF_I | PREFETCH_BUF_E);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(ENTRY_FIELD_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= this_entry_type | PREFETCH_BUF_E;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_METADATA)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= STICKY_METADATA_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (fba_len > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_alloc_end(&alloc_tok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts = _sd_setup_category_on_type(handle->bh_centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_setup_mem_chaining(handle->bh_centry, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: trailing valid can be released, adjust len */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((centry != last_ioent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = last_ioent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_ioent->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~PREFETCH_BUF_E;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = lentry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_prefetch_trailing++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = (CENTRY_BLK(last_ioent) -
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CENTRY_BLK(ioent) + 1) * BLK_FBAS -
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBA_OFF(io_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len = fba_len + (io_pos - fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _sd_doread(handle, ioent, io_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (fba_pos + fba_orig_len - io_pos), flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_FBA_READ(cd, fba_orig_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_READ_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_READ_IO_KSTATS(cd, FBA_SIZE(fba_orig_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = NSC_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait - wait for inuse cache block to become available
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Usage:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (SET_CENTRY_INUSE(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait(cd, blk, centry, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * goto try_again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -or-
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait(cd, blk, centry, CC_PAGEIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * goto try_again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cc_wait(int cd, nsc_off_t cblk, _sd_cctl_t *centry, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile ushort_t *waiters;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t *uflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag == CC_INUSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte waiters = &(centry->cc_await_use);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uflag = &(CENTRY_INUSE(centry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (flag == CC_PAGEIO) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte waiters = &(centry->cc_await_page);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uflag = &(CENTRY_PAGEIO(centry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Oops! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_sd_cc_wait: unknown flag value (%x)", flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, centry) && (*uflag) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*waiters)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_serialize();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*uflag) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned stime = nsc_usec();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&centry->cc_blkcv, &centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*waiters)--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ENT_GET,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cd, 0, BLK_TO_FBA_NUM(cblk), (nsc_usec()-stime), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*waiters)--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_alloc_buf - Allocate a vector of buffers for io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk position (512-byte FBAs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in disk FBAs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - allocation type. Flag is one or more of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_RDBUF, NSC_WRBUF, NSC_NOBLOCK and hints.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_RDAHEAD - prefetch for future read.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle_p - pointer to a handle pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the handle pointer is non-null, its used as a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pre-allocated handle. Else a new handle will be allocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stored in *handle_p
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * else NSC_HIT or NSC_DONE on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or NSC_PENDING on io in progress and NSC_NOBLOCK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * specified in the flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine allocates the cache blocks requested and creates a list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of entries for this request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If NSC_NOBLOCK was not specified, this call could block on read io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If flag specified NSC_RDBUF and the request is not an entire
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hit, an io is initiated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_alloc_buf(blind_t xcd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t **handle_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t st_cblk, cblk; /* position of start and temp cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t io_pos; /* offset in FBA's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bufvec_t *bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry, *lentry, *ioent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_orig_len = fba_len; /* FBA length of orig request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stall, pageio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char cc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int this_entry_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t dmchain_request_blocks; /* size of dmchain in cache blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t alloc_tok = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int min_frag = 0; /* frag statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int max_frag = 0; /* frag statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nfrags = 0; /* frag statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(*handle_p != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = *handle_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xcd == NSC_ANON_CD)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = _CD_NOHASH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_ENTER(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Force large writes on nvram systems to be write-through to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid the (slow) bcopy into nvram.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_WRBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > (nsc_size_t)sdbc_wrthru_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag |= NSC_WRTHRU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_pageio_debug != SDBC_PAGEIO_OFF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (sdbc_pageio_debug) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SDBC_PAGEIO_RDEV:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd != _CD_NOHASH &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_pageio_rdev != (dev_t)-1 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[cd].cd_crdev == sdbc_pageio_rdev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag |= NSC_PAGEIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SDBC_PAGEIO_RAND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_lbolt() % 3) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag |= NSC_PAGEIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SDBC_PAGEIO_ALL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag |= NSC_PAGEIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > (nsc_size_t)BLK_FBAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _CD_NOHASH: client wants temporary (not hashed) cache memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not associated with a local disk. Skip local disk checks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == _CD_NOHASH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag &= ~(NSC_RDBUF | NSC_WRBUF | NSC_RDAHEAD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = *handle_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto setup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ALLOCBUF, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & NSC_RDAHEAD) && _sd_prefetch_opt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _sd_prefetch_buf(cd, fba_pos, fba_len, flag, handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_NOCHECKS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDAHEAD) { /* _sd_prefetch_opt == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t file_size; /* file_size in FBA's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: truncate if req'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > sdbc_max_fbas)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = sdbc_max_fbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_size = _sd_cache_files[(cd)].cd_info->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_pos + fba_len) > file_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = file_size - fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((int64_t)fba_len <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((int32_t)fba_len <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos, flag, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts = _sd_check_buffer_alloc(cd, fba_pos, fba_len, handle_p)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos, flag, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana flag, EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_recovering) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If recovering this device, then block all allocates
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for reading or writing. If we allow reads then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this path could see old data before we recover.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we allow writes then new data could be overwritten
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by old data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is clearly still not a complete solution as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the thread doing this allocate could conceivably be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by this point (and in _sd_write/_sd_read for that matter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which don't even have this protection). But this type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of path seems to only exist in a failover situation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * where a device has failed on the other node and works
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on this node so the problem is not a huge one but exists
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * never the less.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts = _sd_recovery_wblk_wait(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag &= ~NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* write & disk failed, return error immediately */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & NSC_WRBUF) && cdi->cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag &= ~NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos, flag, EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesetup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SETUP_HANDLE(handle, cd, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec = handle->bh_bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDAHEAD) { /* _sd_prefetch_opt == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CKD prefetch: bufvec not req'd, use placeholder */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufvmeaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->buflen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec = _prefetch_sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk = FBA_TO_BLK_NUM(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk = st_cblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count number of blocks on chain that is required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* middle piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmchain_request_blocks =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (fba_len - (st_cblk_len + end_cblk_len)) >> BLK_FBA_SHFT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++dmchain_request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* end piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (end_cblk_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++dmchain_request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_PINNABLE) && (handle->bh_flag & NSC_WRBUF))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_flag |= CC_PINNABLE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle->bh_flag & (NSC_NOCACHE|NSC_SEQ_IO))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_flag |= CC_QHEAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stall = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = ((flag & NSC_PAGEIO) != 0 || sdbc_pageio_always != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecget:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((centry = (_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_search(cd, cblk, _sd_htable)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* already inuse: wait for block, retry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_inuse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, cblk, centry, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cget;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bug 4529671
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now that we own the centry make sure that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is still good. it could have been processed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by _sd_dealloc_dm() in the window between
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_hash_search() and SET_CENTRY_INUSE().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_search(cd, cblk, _sd_htable) != centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_deallocd++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!centry %p cd %d cblk %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " fba_len %" NSC_SZFMT " lost to dealloc?! "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cc_data %p", (void *)centry, cd, cblk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len, (void *)centry->cc_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cget;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before messing with the centry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pageio && SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for flusher to finish pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_pageio1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, cblk, centry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CC_PAGEIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cget;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_hit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HASH_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_hits++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will reset the age flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_init_dm(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_alloc_buf1,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* block mismatch: release, alloc new block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_lost++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cget;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_centry_alloc(cd, cblk,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana dmchain_request_blocks, &stall,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &alloc_tok, locked ? ALLOC_LOCKED : 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dmchaining adjustment.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if centry was obtained from the dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then clear local pageio variable because the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry already has cc_pageio set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_PAGEIO(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE1(_sd_alloc_buf2, _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = ELIGIBLE_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_IN_HASH_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HASH_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_HOLD_OVER_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_entry_type = HOLD_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion now if we did not do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pageio && SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for flusher to finish pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocb_pageio2++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, cblk, centry, CC_PAGEIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cget;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * end action might set PEND_DIRTY flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must lock if need to change flag bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_flag != (centry->cc_flag | cc_flag)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag |= cc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag |= cc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * step 0:check valid bits in each cache ele as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the chain grows - set ioent/io_pos to first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * instance of invalid data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cblk == st_cblk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_centry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_pos = fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_ALLOC, centry, st_cblk_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE4(_sd_alloc_data1,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (BLK_TO_FBA_NUM(cblk) +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana st_cblk_off), int, st_cblk_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off + st_cblk_len)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fba_len == (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry->cc_chain = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= end_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(0, end_cblk_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_pos = BLK_TO_FBA_NUM(cblk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_ALLOC, centry, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_alloc_data2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(cblk),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, end_cblk_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(end_cblk_len)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry->cc_chain = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FULLY_VALID(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_pos = BLK_TO_FBA_NUM(cblk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_ALLOC, centry, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_alloc_data3,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(cblk),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, BLK_FBAS,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (centry->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBAS) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblk++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if this block has a new identity clear prefetch history */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (this_entry_type != HASH_ENTRY_DM)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_aging_dm &=
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ~(PREFETCH_BUF_I | PREFETCH_BUF_E);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(ENTRY_FIELD_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= this_entry_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_METADATA)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= STICKY_METADATA_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --dmchain_request_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dmchain_request_blocks == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do any necessary cleanup now that all the blocks are allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_alloc_end(&alloc_tok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* be sure you nul term. the chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * step one: establish HOST/PARASITE/OTHER relationships
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * between the centry ele in the list and calc the alloc size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (fill in CATAGORY based on TYPE and immediate neighbors)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts = _sd_setup_category_on_type(handle->bh_centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = _sd_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_alloc_buf): _sd_free_buf "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed: err:%d handle:%p", err, (void *)handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * step two: alloc the needed mem and fill in the data and chaining
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields (leave bufvec for step three)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_setup_mem_chaining(handle->bh_centry, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * step three: do the bufvec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len = fba_orig_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec = handle->bh_bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (centry) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE3(_sd_alloc_buf_centrys, _sd_cctl_t *, centry,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, cd, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(centry)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == fba_orig_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufaddr = (centry->cc_data +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(st_cblk_off));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufvmeaddr = 0; /* not used */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->buflen = FBA_SIZE(st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fba_len == (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bufvec_t *pbufvec = bufvec - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pbufvec->bufaddr + pbufvec->buflen) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* contiguous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pbufvec->buflen += FBA_SIZE(end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufaddr = centry->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufvmeaddr = 0; /* not used */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->buflen = FBA_SIZE(end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= end_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bufvec_t *pbufvec = bufvec - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pbufvec->bufaddr + pbufvec->buflen) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* contiguous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pbufvec->buflen += CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufaddr = centry->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufvmeaddr = 0; /* not used */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->buflen = CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* be sure you nul term. the chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->bufvmeaddr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufvec->buflen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* frag statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bufvec_t *tbufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tbufvec = handle->bh_bufvec; tbufvec != bufvec;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ++tbufvec) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((min_frag > tbufvec->buflen) || (min_frag == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte min_frag = tbufvec->buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (max_frag < tbufvec->buflen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_frag = tbufvec->buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nfrags = bufvec - handle->bh_bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte min_frag = FBA_LEN(min_frag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_frag = FBA_LEN(max_frag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* buffer memory frag stats */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_alloc_buf_frag, uint64_t, (uint64_t)fba_orig_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, nfrags, int, min_frag, int, max_frag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_WRBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_IS_WRTHRU(handle))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_alloc_write(handle->bh_centry, &stall)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_FORCED_WRTHRU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (centry = handle->bh_centry;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry; centry = centry->cc_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_SET_FTPOS(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortealloc_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _sd_doread(handle, ioent, io_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (fba_pos + fba_orig_len - io_pos), flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDBUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_FBA_READ(cd, fba_orig_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_READ_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_READ_IO_KSTATS(cd, FBA_SIZE(fba_orig_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = NSC_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = (stall) ? NSC_DONE : NSC_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_orig_len, fba_pos, flag, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_EXIT(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consistency checking for ccents
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ELIGIBLE(p) (p & ELIGIBLE_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HOLD(p) (p & HOLD_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HASHE(p) (p & HASH_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HOST(p) (p & HOST_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PARA(p) (p & PARASITIC_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OTHER(p) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!(p & (HOST_ENTRY_DM | PARASITIC_ENTRY_DM | ELIGIBLE_ENTRY_DM)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define AVAIL(p) (p & AVAIL_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_check_cctl_cot -- consistency check for _sd_setup_category_on_type()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * may only be called on entry to state machine (when ccent is either
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ELIGIBLE_ENTRY_DM, HOLD_ENTRY_DM or HASH_ENTRY_DM).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print message or panic (DEBUG) if inconsistency detected.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_check_cctl_cot(_sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t age;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int host_or_other;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int para;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ccent_ok = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte age = centry->cc_aging_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = centry->cc_alloc_size_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = centry->cc_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host_or_other = size && data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte para = !size && data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on entry to _sd_setup_category_on_type(),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one of three mutually exclusive entry field bits must be set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch ((age & (ELIGIBLE_ENTRY_DM | HOLD_ENTRY_DM | HASH_ENTRY_DM))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ELIGIBLE_ENTRY_DM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case HOLD_ENTRY_DM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case HASH_ENTRY_DM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ok */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* zero or multiple flag bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* categories are mutually exclusive */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (HOST(age) && PARA(age))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* these bits should be cleared out (STICKY_METADATA_DM not used) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (age & (AVAIL_ENTRY_DM | FOUND_HOLD_OVER_DM | FOUND_IN_HASH_DM |
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana STICKY_METADATA_DM))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* eligible has no data and no size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ELIGIBLE(age) && (size || data))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* parasite has zero size and non-zero data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (PARA(age) && !para)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host has non-zero size and non-zero data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (HOST(age) && !host_or_other)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* "other" is just like a host */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (OTHER(age) && !host_or_other)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* a HOLD or a HASH must have a size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((size) && !(age & (HASH_ENTRY_DM | HOLD_ENTRY_DM)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccent_ok = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ccent_ok)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(cmn_level,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(sdbc_check_cctl_cot): inconsistent ccent %p "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "age %x size %d data %p", (void *)centry, age, size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ccent_ok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_mark_cctl_cot -- mark cctls bad and invalidate when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inconsistency found in _sd_setup_category_on_type()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns nothing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: this is an error recovery path that is triggered when an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inconsistency in a cctl is detected. _sd_centry_release() will take
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * these cache entries out of circulation and place them on a separate list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for debugging purposes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_mark_cctl_cot(_sd_cctl_t *header, _sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cur_ent = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the entire chain is guilty by association */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete((struct _sd_hash_hd *)cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent->cc_aging_dm |= BAD_CHAIN_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_ent = cur_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= BAD_ENTRY_DM; /* this is the problem child */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_setup_category_on_type(_sd_cctl_t *) - Setup the centry CATEGORY based on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry TYPE and immediate neighbors. Identify each eligible (ie not HASH)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry as a host/parasite. host actually have memory allocated to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * them and parasites are chained to the host and point to page offsets within
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the host's memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success, EINTR if inconsistency detected in centry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * none
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_setup_category_on_type(_sd_cctl_t *header)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *prev_ent, *next_ent, *centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *anchor = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int current_pest_count, local_max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(header);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_max_dyn_list = max_dm_queues - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pickup a fresh copy - has the world changed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_max_dyn_list = dynmem_processing_dm.max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_pest_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try to recover from bad cctl */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_check_cot && !sdbc_check_cctl_cot(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cl && (ret == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (1): /* chain to next/monitor for completion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = next_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_check_cot &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana !sdbc_check_cctl_cot(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (2): /* vector to appropriate routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(centry->cc_aging_dm & ELIGIBLE_ENTRY_DM))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (prev_ent && (prev_ent->cc_aging_dm &
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ELIGIBLE_ENTRY_DM))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 15;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (5): /* process NON-ELIGIBLE entries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(centry->cc_aging_dm &
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (HASH_ENTRY_DM|HOLD_ENTRY_DM))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no catagory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_alloc_size_dm ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(cmn_level,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(setup_cot): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "OTHER with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~CATAGORY_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm = BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_setup_category,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no prev entry (ie top of list) or no prev
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ELIGIBLE entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (10):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is an eligible entry, does it start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a list or is it a loner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_alloc_size_dm ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_data) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(cmn_level, "!sdbc(setup_cot): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "HOST with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (next_ent && (next_ent->cc_aging_dm &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ELIGIBLE_ENTRY_DM)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* it starts a list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host catagory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= HOST_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start out with one page */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm = BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_setup_category,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, anchor);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it's a loner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drop status to no category and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * restart
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~ELIGIBLE_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (15): /* default to parasite catagory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_alloc_size_dm ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_data) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(cmn_level, "!sdbc(setup_cot): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "PARA with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (current_pest_count < local_max_dyn_list-1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* continue to grow the pest list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_pest_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PARASITIC_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * offset of host ent mem this will pt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor->cc_alloc_size_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * up the host mem req by one for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this parasite
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(_sd_setup_category,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor->cc_alloc_size_dm += BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * term this pest list - restart fresh
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on this entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte current_pest_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent->cc_aging_dm &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~(HOST_ENTRY_DM|ELIGIBLE_ENTRY_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* switch(cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_mark_cctl_cot(header, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_setup_mem_chaining(_sd_cctl_t *) - Allocate memory, setup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mem ptrs an host/pest chaining. Do the actual allocation as described in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_setup_category_on_type().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if called with ALLOC_NOWAIT, caller must check for non-zero return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_setup_mem_chaining(_sd_cctl_t *header, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *prev_ent, *next_ent, *centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *anchor = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cl, rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(header);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!header)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (1): /* chain to next/monitor for completion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~ELIGIBLE_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = next_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_ent = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (2): /* vector to appropriate routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & HOST_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (centry->cc_aging_dm &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PARASITIC_ENTRY_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 15;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (5): /* OTHER processing - alloc mem */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc = sdbc_centry_memalloc_dm(centry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm, flag))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The allocation failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HOST entry processing - save the anchor pt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc the memory,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (10): /* setup head and nxt ptrs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc = sdbc_centry_memalloc_dm(centry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm, flag))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The allocation failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARASITIC entry processing - setup w/no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory, setup head/next ptrs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (15):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fudge the data mem ptr to an offset from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the anchor alloc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(centry->cc_aging_dm &
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (HASH_ENTRY_DM| HOLD_ENTRY_DM))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_head_dm = anchor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* chain prev to this */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent->cc_next_dm = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * generate the actual data ptr into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host entry memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data = anchor->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry->cc_alloc_size_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_size_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* switch(cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_check_buffer_alloc - Check if buffer allocation is invalid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if its ok to continue with allocation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else errno to be returned to the user.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine could block if the device is not local and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is in progress.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_check_buffer_alloc(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t **hp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This check exists to ensure that someone will not pass in an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arbitrary pointer and try to pass it off as a handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*hp)->bh_flag & (~_SD_VALID_FLAGS)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_check_buffer_alloc) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cd %d invalid handle %p flags %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, (void *)*hp, (*hp)->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_cache_initialized == 0) || (FILE_OPENED(cd) == 0)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_check_buffer_alloc) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cd %d not open. Cache init %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, _sd_cache_initialized);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(_sd_cache_files[cd].cd_rawfd) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !nsc_held(_sd_cache_files[cd].cd_rawfd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_check_buffer_alloc) cd %d is not attached", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_IO_SIZE(fba_pos, fba_len, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_LEN(fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_check_handle -- check that handle is valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 1 if ok, 0 otherwise (if debug then panic).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_check_handle(_sd_buf_handle_t *handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(cmn_level, "!sdbc(_sd_free_buf): invalid handle %p"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cd %d fpos %" NSC_SZFMT " flen %" NSC_SZFMT " flag %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle, HANDLE_CD(handle), handle->bh_fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_fba_len, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_free_buf - Free the buffers allocated in _sd_alloc_buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - The handle allocated in _sd_alloc_buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If handle was allocated through _sd_alloc_buf, the handle allocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag (NSC_HALLOCATED) will be reset by _sd_alloc_buf. This indicates
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that _sd_free_buf should free up the handle as well.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All other handles directly allocated from _sd_alloc_handle will have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that flag set. Any handle with valid blocks will have the handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * active flag. It is an error if the active flag is not set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (if free_buf were called without going through alloc_buf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_free_buf(_sd_buf_handle_t *handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry, *cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flen = handle->bh_fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fpos = handle->bh_fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_FREEBUF, HANDLE_CD(handle),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_check_handle(handle) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle->bh_flag & NSC_MIXED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Data in this handle will be a mix of data from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * source device and data from another device, so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invalidate all the blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag &= ~NSC_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_QUEUE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag &= ~NSC_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_write(handle, handle->bh_fba_pos, handle->bh_fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag &= ~NSC_HACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_chain = centry->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * help prevent dup call to _sd_centry_release if this handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is erroneously _sd_free_buf'd twice. (should not happen).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_HALLOCATED) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_HALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_free_handle(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag = NSC_HALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_FREEBUF, cd, flen, fpos, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_lruq_srch = 0x2000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_get_dmchain -- get a candidate centry chain pointing to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * contiguous memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - number of cache blocks requested
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - ALLOC_NOWAIT flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a cache entry or possible NULL if ALLOC_NOWAIT set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to satisfy entire request from queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that has no memory allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this fails then attempt a partial allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with a preallocated block of requested size up to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * max_dyn_list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then look for largest chain less than max_dyn_list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_get_dmchain(int cblocks, int *stall, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_dmchain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_tries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cblocks_orig = cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nowait = flag & ALLOC_NOWAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = _sd_lruq_srch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cblocks != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!cc_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get it from the os if possible */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->sq_inq >= cblocks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->sq_inq >= cblocks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_dmchain = qhead->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the inuse and pageio bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: this code expects the cc_ent to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be available. no other thread may set the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inuse or pageio bit for an entry on the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < cblocks; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "centry inuse on 0 q! %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_PAGEIO(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "centry pageio on 0 q! %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* got a dmchain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove this chain from the 0 queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_dmchain->cc_prev->cc_next = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next->cc_prev = cc_dmchain->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_dmchain->cc_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_inq -= cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(GOOD_LRUSIZE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* look for a pre-allocated block of the requested size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cblocks > (max_dm_queues - 1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks = max_dm_queues - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[cblocks];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->sq_inq != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *tmp_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tmp_dmchain = qhead->cc_next; tmp_dmchain != qhead;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana tmp_dmchain = tmp_dmchain->cc_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get a dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the inuse and pageio bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_dmchain_avail(tmp_dmchain)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put on MRU end of queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_dmchain(q, tmp_dmchain,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_dmchain = tmp_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dmchain_not_avail++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * spin block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nudge the deallocator, accelerate ageing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&dynmem_processing_dm.thread_dm_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(--num_tries)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(20000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) (*stall)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = _sd_lruq_srch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks = cblocks_orig;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* see if smaller request size is available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(--cblocks))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks = cblocks_orig;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (!cc_dmchain) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cc_dmchain);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dmchain_avail(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int chain_avail = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *anchor = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_aging_dm & BAD_CHAIN_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chain_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chain_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chain_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((SET_CENTRY_PAGEIO(cc_ent))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chain_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chain_avail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!chain_avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_clear_dmchain(anchor, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = anchor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prevent possible deadlocks in _sd_cc_wait():
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove from hash and wakeup any waiters now that we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * have acquired the chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete((struct _sd_hash_hd *)cc_ent,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_await_use) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&cc_ent->cc_blkcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_creat = nsc_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_hits = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (chain_avail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_clear_dmchain(_sd_cctl_t *cc_ent_start, _sd_cctl_t *cc_ent_end)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent = cc_ent_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *prev_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_ent != cc_ent_end) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ent = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(prev_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(prev_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * put a dmchain on the LRU end of a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_ins_dmqueue_front(_sd_queue_t *q, _sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = qhead->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_next->cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_inq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_cblocks = q->sq_dmchain_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(GOOD_LRUSIZE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * put a dmchain on the MRU end of a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_ins_dmqueue_back(_sd_queue_t *q, _sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev = qhead->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev->cc_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_inq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_cblocks = q->sq_dmchain_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(GOOD_LRUSIZE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove dmchain from a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_remq_dmchain(_sd_queue_t *q, _sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev->cc_next = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next->cc_prev = cc_ent->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = cc_ent->cc_prev = NULL; /* defensive programming */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_cblocks = -1; /* indicate not on any queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->sq_inq--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(GOOD_LRUSIZE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * requeue a dmchain to the MRU end of its queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if getlock is 0 on entry the queue lock (sq_qlock) must be held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_requeue_dmchain(_sd_queue_t *q, _sd_cctl_t *cc_ent, int mru,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int getlock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getlock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_remq_dmchain() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev->cc_next = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next->cc_prev = cc_ent->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mru) { /* put on MRU end of queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_ins_dmqueue_back */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev = qhead->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev->cc_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->sq_req_stat)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* put on LRU end of queue i.e. requeue to head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_ins_dmqueue_front */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = qhead->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_next->cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear the CC_QHEAD bit on all members of the chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *tcent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tcent = cc_ent; tcent; tcent = tcent->cc_next_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tcent->cc_flag &= ~CC_QHEAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getlock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_dmchain_dirty(cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return first dirty cc_ent in dmchain, NULL if chain is not dirty
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dmchain_dirty(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (/* CSTYLED */; cc_ent; cc_ent = cc_ent->cc_next_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_requeue_head_dm_try()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to requeue a dmchain to the head of the queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_requeue_head_dm_try(_sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qidx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_dmchain_dirty(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qidx = cc_ent->cc_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[qidx];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_dmchain(q, cc_ent, 0, 1); /* requeue head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc_blks -- allocate cache entries with memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblk - cache block number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reqblks - number of cache blocks to be allocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - can be ALLOC_NOWAIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A cache block chain or NULL if ALLOC_NOWAIT and request fails
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: caller must check for null return if called with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ALLOC_NOWAIT set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_alloc_blks(int cd, nsc_off_t cblk, nsc_size_t reqblks, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t alloc_tok = {0}; /* must be 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stall = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *lentry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *anchor = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *next_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(reqblks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (reqblks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_centry_alloc(cd, cblk, reqblks, &stall,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &alloc_tok, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lentry == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry->cc_chain = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lentry = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(ENTRY_FIELD_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_IN_HASH_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= HASH_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_aging_dm & FOUND_HOLD_OVER_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= HOLD_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= ELIGIBLE_ENTRY_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --reqblks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_alloc_end(&alloc_tok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reqblks || (_sd_setup_category_on_type(anchor))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = anchor;
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 anchor = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is where the memory is actually allocated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_setup_mem_chaining(anchor, flag))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte anchor = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (anchor);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc - sdbc internal function to allocate a new cache block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblk - cache block number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * req_blocks - number of cache blocks remaining in caller's i/o request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc_tok - pointer to token initialized to 0 on first call to function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - lock status of sdbc_queue_lock or ALLOC_NOWAIT flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A cache block, or possibly NULL if ALLOC_NOWAIT set .
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * switch to the appropriate allocation function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this function is used when callers need more than one cache block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is called repeatedly until the entire request is satisfied,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at which time the caller will then do the memory allocation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if only one cache block is needed callers may use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc_blks() which also allocates memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: caller must check for null return if called with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ALLOC_NOWAIT set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_alloc(int cd, nsc_off_t cblk, nsc_size_t req_blocks, int *stall,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t *alloc_tok, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_alloc_dmc(cd, cblk, req_blocks, stall, alloc_tok,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_alloc_lru(cd, cblk, stall, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_alloc_dmc -- allocate a centry from a dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblk - cache block number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * req_blocks - number of cache blocks in clients i/o request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc_tok - pointer to token initialized to 0 on first call to function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - lock status of sdbc_queue_lock, or ALLOC_NOWAIT flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A cache block or possibly NULL if ALLOC_NOWAIT set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if dmchain is empty, allocate one.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_dmc(int cd, nsc_off_t cblk, nsc_size_t req_blocks, int *stall,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_t *alloc_tok, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *centry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!dmc->sab_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note - sdbc_get_dmchain() returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with cc_inuse and cc_pageio set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for all members of dmchain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dmc->sab_dmchain =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sdbc_get_dmchain(req_blocks, stall, flag)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remember q it came from */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dmc->sab_dmchain->cc_alloc_size_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmc->sab_q = dmc->sab_dmchain->cc_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: dmchain pointer is advanced in sdbc_alloc_from_dmchain()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dmc->sab_dmchain) /* could be NULL if ALLOC_NOWAIT set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_alloc_from_dmchain(cd, cblk, alloc_tok, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_alloc_from_dmchain -- allocate centry from a dmchain of centrys
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblk - cache block number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc_tok - pointer to token
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - lock status of sdbc_queue_lock or ALLOC_NOWAIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A cache block or possibly NULL if ALLOC_NOWAIT set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine allocates a new cache block from the supplied dmchain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Assumes that dmchain is non-NULL and that all cache entries in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the dmchain have been removed from hash and have their cc_inuse and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_pageio bits set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_from_dmchain(int cd, nsc_off_t cblk, sdbc_allocbuf_t *alloc_tok,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *old_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int categorize_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int locked = flag & ALLOC_LOCKED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nowait = flag & ALLOC_NOWAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dmc->sab_dmchain);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = dmc->sab_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_sd_cctl_valid(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = FOUND_HOLD_OVER_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortealloc_try:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == _CD_NOHASH)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_BLK(cc_ent) = cblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((old_ent = (_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_insert(cd, cblk, (struct _sd_hash_hd *)cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable)) != cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(old_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_inuse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, cblk, old_ent, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bug 4529671
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now that we own the centry make sure that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is still good. it could have been processed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by _sd_dealloc_dm() in the window between
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_hash_insert() and SET_CENTRY_INUSE().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_cctl_t *)_sd_hash_search(cd, cblk, _sd_htable)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana != old_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_deallocd++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!cc_ent %p cd %d cblk %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " lost to dealloc?! cc_data %p", (void *)old_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, cblk, (void *)old_ent->cc_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(old_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, old_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_hit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_ent->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* _sd_centry_release(cc_ent); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = old_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = FOUND_IN_HASH_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_lost++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(old_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * advance the dmchain pointer, but only if we got the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_ent from the dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (categorize_centry != FOUND_IN_HASH_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmc->sab_dmchain = dmc->sab_dmchain->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmc->sab_dmchain = dmc->sab_dmchain->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDTRACE(ST_EXIT|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_await_use) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&cc_ent->cc_blkcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_init_dm(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_aging_dm |= categorize_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc_end -- tidy up after all cache blocks have been
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocated for a request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc_tok - pointer to allocation token
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nothing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at this time only useful when sdbc_use_dmchain is true.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if there are cache blocks remaining on the chain then the inuse and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pageio bits must be cleared (they were set in sdbc_get_dmchain().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_alloc_end(sdbc_allocbuf_t *alloc_tok)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *next_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *prev_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int chainpull = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_centry = dmc->sab_dmchain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (next_centry != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(next_centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_centry = next_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (next_centry->cc_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++chainpull;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_centry = next_centry->cc_next_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear bit after final reference */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(prev_centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next_centry = next_centry->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a floater from the 0 queue, insert on q.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since this centry is not on any queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the inuse bit can be cleared before
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inserting on the q. this is also required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since sdbc_get_dmchain() does not expect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inuse bits to be set on 0 queue entry's.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(prev_centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ins_dmqueue_front(q, prev_centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* compute wastage stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((chainpull >= 0) && (chainpull < max_dm_queues));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chainpull)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*(dmchainpull_table + (dmc->sab_q *
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana max_dm_queues + chainpull)))++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_alloc_lru - allocate a new cache block from the lru queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - Cache descriptor (from a previous open)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblk - cache block number.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - lock status of sdbc_queue_lock or ALLOC_NOWAIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A cache block or NULL if ALLOC_NOWAIT specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine allocates a new cache block from the lru.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If an allocation cannot be done, we block, unless ALLOC_NOWAIT is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_cctl_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_lru(int cd, nsc_off_t cblk, int *stall, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, *old_ent, *ccnext;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q = _SD_LRU_Q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *qhead = &(q->sq_qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0, num_tries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int categorize_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int locked = flag & ALLOC_LOCKED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nowait = flag & ALLOC_NOWAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = q->sq_inq / 100; /* only search 1% of q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_tries <= 0) /* ensure num_tries is non-zero */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = q->sq_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = _sd_lruq_srch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_alloc_centry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cc_ent = (qhead->cc_next); cc_ent != qhead; cc_ent = ccnext) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (--num_tries <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ccnext = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_aging_dm & BAD_CHAIN_DM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_lost++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag = 0; /* CC_INUSE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inlined requeue of the LRU. (should match _sd_requeue)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cp, *cn, *qp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = cc_ent->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cn = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qp = (q->sq_qhead).cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_cctl_valid(cc_ent) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cp != &(q->sq_qhead) && !_sd_cctl_valid(cp)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cn != &(q->sq_qhead) && !_sd_cctl_valid(cn)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !_sd_cctl_valid(qp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_centry_alloc %x prev %x next %x qp %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent, cp, cn, qp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev->cc_next = cc_ent->cc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next->cc_prev = cc_ent->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_next = qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_prev = qhead->cc_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev->cc_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead->cc_prev = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_seq = q->sq_seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->sq_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * End inlined requeue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_STATS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_hash_delete(cc_ent, _sd_htable) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_REPLACE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_CD(cc_ent), cc_ent->cc_hits,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_lbolt(), cc_ent->cc_creat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_creat = nsc_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_hits = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_hash_delete(cc_ent, _sd_htable) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_REPLACE|ST_DL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_CD(cc_ent),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, BLK_TO_FBA_NUM(cblk));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_await_use ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((cd == CENTRY_CD(cc_ent)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cblk == CENTRY_BLK(cc_ent))))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_REPLACE|ST_DL, cc_ent, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete((struct _sd_hash_hd *)cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_creat = nsc_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_hits = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = FOUND_HOLD_OVER_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_try:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == _CD_NOHASH)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CENTRY_BLK(cc_ent) = cblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((old_ent = (_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_insert(cd, cblk, (struct _sd_hash_hd *)cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_htable)) != cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SET_CENTRY_INUSE(old_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_inuse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&sdbc_queue_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cc_wait(cd, cblk, old_ent, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&sdbc_queue_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bug 4529671
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now that we own the centry make sure that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is still good. it could have been processed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by _sd_dealloc_dm() in the window between
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_hash_insert() and SET_CENTRY_INUSE().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_cctl_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_search(cd, cblk, _sd_htable) != old_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_deallocd++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!cc_ent %p cd %d cblk %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " lost to dealloc?! cc_data %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)old_ent, cd, cblk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)old_ent->cc_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(old_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, old_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_hit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_ent->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = old_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte categorize_centry = FOUND_IN_HASH_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_lost++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(old_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nowait) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto alloc_try;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ENT_ALLOC, cd, tries,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent->cc_await_use) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&cc_ent->cc_blkcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_centry_init_dm(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_aging_dm |= categorize_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ENT_ALLOC, cd, ++tries, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(20000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) (*stall)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = _sd_lruq_srch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_alloc_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_init_dm - setup the cache block for dynamic memory allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Cache block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is the central point in which cache entry blocks are setup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_init_dm(_sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* an entry already setup - don't touch simply refresh age */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FINAL_AGING_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(sdbc_centry_init_dm_end,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, centry->cc_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FINAL_AGING_DM | CATAGORY_ENTRY_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_head_dm || centry->cc_next_dm)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(cmn_level, "!sdbc(sdbc_centry_init_dm): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "non-zero mem chain in ccent %p", (void *)centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_head_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_next_dm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_memalloc_dm
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Actually allocate the cache memory, storing it in the cc_data field for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the cctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry: cache control block for which to allocate the memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc_request: number of bytes to allocate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag: if called with ALLOC_NOWAIT, caller must check for non-zero return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_memalloc_dm(_sd_cctl_t *centry, int alloc_request, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *newq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sleep;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep = (flag & ALLOC_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!centry->cc_data && (alloc_request > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host or other */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dynmem_processing_dm.alloc_ct++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_data = (unsigned char *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc((size_t)centry->cc_alloc_size_dm, sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks = centry->cc_alloc_size_dm >> _sd_cblock_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newq = &sdbc_dm_queues[cblocks];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the dmqueue index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_cblocks = cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put on appropriate queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_ins_dmqueue_back(newq, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for KM_NOSLEEP (should never happen with KM_SLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!centry->cc_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (LOW_RESOURCES_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_head_dm = centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_alloc_ct_dm++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_centry_release - release a cache block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Cache block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine frees up a cache block. It also frees up a write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * block if allocated and its valid to release it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_centry_release(_sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ENT_FREE, CENTRY_CD(centry), 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(centry)), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_PAGEIO(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((wctl = centry->cc_write) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag &= ~(CC_PINNABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&centry->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wctl) {
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(centry->cc_aging_dm & BAD_CHAIN_DM)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_use_dmchain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_alloc_size_dm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* see if this can be queued to head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_QHEAD(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_head_dm_try(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qidx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_queue_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qidx = centry->cc_cblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &sdbc_dm_queues[qidx];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_lru_reinsert(q, centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_dmchain(q,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana centry, 1, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fix for bug 4949134:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If an internal block is marked with CC_QHEAD
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but the HOST block is not, the chain will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * never age properly, and will never be made
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * available. Only the HOST of the dmchain is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * checked for CC_QHEAD, so clearing an internal
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * block indiscriminately (as is being done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * here) does no damage.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The same result could instead be achieved by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not setting the CC_QHEAD flag in the first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * place, if the block is an internal dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * block, and if it is found in the hash table.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The current solution was chosen since it is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the least intrusive.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_flag &= ~CC_QHEAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_QHEAD(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!CENTRY_DIRTY(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (_sd_lru_reinsert(_SD_LRU_Q, centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ENT_FREE, CENTRY_CD(centry), 0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(centry)), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* only clear inuse after final reference to centry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLEAR_CENTRY_INUSE(centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup to centry info associated with safestore resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return pointer to the centry info structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortess_centry_info_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_get_cinfo_byres(ss_resource_t *res)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *cinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *cend;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(res != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (res == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cinfo = _sdbc_gl_centry_info;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cend = _sdbc_gl_centry_info +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (_sdbc_gl_centry_info_size / sizeof (ss_centry_info_t)) - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; cinfo <= cend; ++cinfo)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cinfo->sc_res == res) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++found;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cinfo = NULL; /* bad */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cinfo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_alloc_write - Allocate a write block (for remote mirroring)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and set centry->cc_write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Head of Cache chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - and sets cc_write for all entries when write contl block obtained.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - if a write control block could not be obtained.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_alloc_write(_sd_cctl_t *centry, int *stall)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resourcelist_t *reslist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resourcelist_t *savereslist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resource_t *res;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *ce;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int need;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte need = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ce = centry; ce; ce = ce->cc_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(ce->cc_write))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte need++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!need)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((SSOP_ALLOCRESOURCE(sdbc_safestore, need, stall, &reslist))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana == SS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte savereslist = reslist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ce = centry; ce; ce = ce->cc_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ce->cc_write)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = SSOP_GETRESOURCE(sdbc_safestore, &reslist, &res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == SS_OK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ce->cc_write = sdbc_get_cinfo_byres(res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(err == SS_OK); /* panic if DEBUG on */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ce->cc_write != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is bad and should not happen.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we use the saved reslist to cleanup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err != SS_OK) || !ce->cc_write) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_sd_alloc_write: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "bad resource list 0x%p"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "changing to forced write thru mode",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)savereslist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_set_node_hint(NSC_FORCED_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (SSOP_GETRESOURCE(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &savereslist, &res) == SS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no safestore resources available. do sync write */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_unblock(&_sd_flush_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_read - Interface call to do read.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - flag: (NSC_NOBLOCK for async io)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine checks if the request is valid and calls the underlying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doread routine (also called by alloc_buf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_read(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_orig_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress || (handle->bh_flag & NSC_ABUF)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_NOCHECKS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_read) handle %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NSC_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_ENTER(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len, cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto need_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RD, cc_ent, st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_data1, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)(BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + st_cblk_off),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)st_cblk_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(st_cblk_off)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off + st_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos += st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FULLY_VALID(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto need_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RD, cc_ent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_data2, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)BLK_FBAS,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana 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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos += BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(0, end_cblk_len, cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto need_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RD, cc_ent, 0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_data3, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)end_cblk_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(end_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_FBA_READ(handle->bh_cd, fba_orig_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_READ_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_READ_IO_KSTATS(handle->bh_cd, FBA_SIZE(fba_orig_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NSC_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stats_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteneed_io:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _sd_doread(handle, cc_ent, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestats_exit:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_EXIT(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_doread_prefetch - read ahead one cache block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_ent - cache entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to read from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * number of fbas, if any, that are to be read beyond (fba_pos + fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if readahead is to be done allocate a cache block and place
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the cc_chain of cc_ent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_doread_prefetch(_sd_cctl_t *cc_ent, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t st_cblk = FBA_TO_BLK_NUM(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t next_cblk = FBA_TO_BLK_NUM(fba_pos + BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fba_count = 0; /* number of fbas to prefetch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ra; /* the read ahead cache entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = CENTRY_CD(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t vol_fill;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte filesize = _sd_cache_files[cd].cd_info->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vol_fill = filesize - (fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* readahead only for small reads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_len <= FBA_LEN(CACHE_BLOCK_SIZE)) && (fba_pos != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (vol_fill > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if prev block is in cache and next block is not,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then read ahead one block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_hash_search(cd, st_cblk - 1, _sd_htable)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_sd_hash_search(cd, next_cblk, _sd_htable)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ra = sdbc_centry_alloc_blks
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cd, next_cblk, 1, ALLOC_NOWAIT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ra) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if in cache don't readahead */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (cc_ra->cc_aging_dm &
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana HASH_ENTRY_DM) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ++sdbc_ra_hash;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_centry_release(cc_ra);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_chain = cc_ra;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ra->cc_chain = 0;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_count =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (vol_fill >
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (nsc_size_t)BLK_FBAS) ?
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS : (int)vol_fill;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana /*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * indicate implicit prefetch
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * and mark for release in
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * _sd_read_complete()
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ra->cc_aging_dm |=
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (PREFETCH_BUF_I |
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana PREFETCH_BUF_IR);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana }
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++sdbc_ra_none;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (fba_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_doread - Check if blocks in cache. If not completely true, do io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - flag: (NSC_NOBLOCK for async io)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE(from disk), or NSC_PENDING otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It initiates an io and either blocks waiting for the completion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or return NSC_PENDING, depending on whether the flag bit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_NOBLOCK is reset or set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_doread(_sd_buf_handle_t *handle, _sd_cctl_t *cc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd, err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_orig_len; /* length in FBA's of the original request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t file_len; /* length in bytes of io to be done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_bdl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_temp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *bp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int want_bits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*fn)(blind_t, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_fill; /* FBA's to fill to end of last block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t vol_end_fill; /* # of FBA's to fill to end of the volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_READ, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files[cd].cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_len, fba_pos, flag, EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * adjust the position and length so that the entire cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * block is read in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first, adjust to beginning of cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len += BLK_FBA_OFF(fba_pos); /* add start offset to length */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos &= ~BLK_FBA_MASK; /* move position back to start of block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* compute fill to end of cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_fill = (BLK_FBAS - 1) - ((fba_len - 1) % BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vol_end_fill = _sd_cache_files[(cd)].cd_info->sh_filesize -
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fill to lesser of cache block or end of volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len += ((nsc_size_t)end_cblk_fill < vol_end_fill) ? end_cblk_fill :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vol_end_fill;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(_sd_doread_rfill, nsc_off_t, fba_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana nsc_size_t, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for small reads do 1-block readahead if previous block is in cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_prefetch1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len += sdbc_doread_prefetch(cc_ent, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_orig_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_temp = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_bdl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cc_temp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_bdl += (SDBC_LOOKUP_IOCOUNT(CENTRY_DIRTY(cc_temp)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_temp = cc_temp->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = sd_alloc_iob(_sd_cache_files[cd].cd_crdev,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_pos, num_bdl, B_READ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_len, fba_pos, flag, E2BIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (E2BIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte want_bits = SDBC_GET_BITS(st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (want_bits & CENTRY_DIRTY(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ccent_rd(cc_ent, want_bits, bp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_len = FBA_SIZE(st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ccent_rd(cc_ent, (uint_t)BLK_FBA_BITS, bp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_len += CACHE_BLOCK_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte want_bits = SDBC_GET_BITS(0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (want_bits & CENTRY_DIRTY(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_ccent_rd(cc_ent, want_bits, bp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_len += FBA_SIZE(end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_READ_MISS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_READ_IO_KSTATS(cd, file_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DISK_FBA_READ(cd, FBA_NUM(file_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fn = (handle->bh_flag & NSC_NOBLOCK) ? _sd_async_read_ea : NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = sd_start_io(bp, _sd_cache_files[cd].cd_strategy, fn, handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != NSC_PENDING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_read_complete(handle, fba_pos, fba_orig_len, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_orig_len, fba_pos, flag, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_read_complete - Do whatever is necessary after a read io is done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * error - error from io if any.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine marks the cache blocks valid if the io completed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sucessfully. Called from the async end action as well as after
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a synchrnous read completes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_read_complete(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t cur_fba_len; /* length in FBA's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_iocent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *first_iocent; /* first buffer when processing prefetch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_iocent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_error = error) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_iocent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_iocent = cc_iocent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_VALID_BITS(st_cblk_off, st_cblk_len, cc_iocent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RDIO, cc_iocent, st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_complete_data1, uint64_t, (uint64_t)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_iocent)) + st_cblk_off,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, st_cblk_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_iocent->cc_data + FBA_SIZE(st_cblk_off)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_iocent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off + st_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_iocent = cc_iocent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_iocent = cc_iocent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_FULLY_VALID(cc_iocent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RDIO, cc_iocent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_complete_data2, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_iocent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, BLK_FBAS, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_iocent->cc_data), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_iocent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(BLK_FBAS) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 4755485 release implicit prefetch buffers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the cc_chain of the first buffer must NULL'd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * else _sd_free_buf() will do a double free when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it traverses the chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if a buffer has been marked PREFETCH_BUF_IR then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is guaranteed that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1. it is the second in a chain of two.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2. cur_fba_len is BLK_FBAS.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3. end_cblk_len is zero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * because of 1 (and 2) above, we can safely exit the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * while loop via the break statement without
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * executing the last two statements. the break
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * statement is necessary because it would be unsafe
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to access cc_iocent which could be reallocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * immediately after the _sd_centry_release().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_iocent->cc_aging_dm & PREFETCH_BUF_IR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_iocent->cc_aging_dm &= ~(PREFETCH_BUF_IR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_centry_release(cc_iocent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte first_iocent->cc_chain = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_iocent = cc_iocent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_VALID_BITS(0, end_cblk_len, cc_iocent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RDIO, cc_iocent, 0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_complete_data3, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_iocent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, end_cblk_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_iocent->cc_data), char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_iocent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(end_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_read_ea - End action for async reads.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xhandle - handle allocated earlier on (cast to blind_t).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * error - error from io if any.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is called at interrupt level when the io is done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is called only when read is asynchronous (NSC_NOBLOCK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_async_read_ea(blind_t xhandle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle = xhandle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[cd].cd_info->sh_failed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_READ_EA, HANDLE_CD(handle),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_read_complete(handle, fba_pos, fba_len, error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG_PATTERN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte check_buf_consistency(handle, "rd");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ_EA, HANDLE_CD(handle),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_READ_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_write_ea - End action for async writes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xhandle - handle allocated earlier on. (cast to blind_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number written to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * error - error from io if any.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is called at interrupt level when the write io is done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is called only when we are in write-through mode and the write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * call indicated asynchronous callback. (NSC_NOBLOCK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_async_write_ea(blind_t xhandle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle = xhandle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_error = error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (error)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[HANDLE_CD(handle)].cd_info->sh_failed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_WRITE_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update_dirty - set dirty bits in cache block which is already dirty
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_inuse is held, need cc_lock to avoid race with _sd_process_pending
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must check for I/O in-progress and set PEND_DIRTY.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return previous dirty bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * [if set _sd_process_pending will re-issue]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_bitmap_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteupdate_dirty(_sd_cctl_t *cc_ent, sdbc_cblk_fba_t st_off, sdbc_cblk_fba_t st_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t old;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we are writing to an FBA that is still marked dirty,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * record a write cancellation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & SDBC_GET_BITS(st_off, st_len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_WRITE_CANCELLATION(CENTRY_CD(cc_ent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is a write to a block that was already dirty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_DIRTY(st_off, st_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_serialize();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_IO_INPROGRESS(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag |= CC_PEND_DIRTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_write - Interface call to commit part of handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - handle allocated earlier o.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to write to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - (NSC_NOBLOCK | NSC_WRTHRU)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_HIT (in cache), NSC_DONE (to disk) or NSC_PENDING otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine checks validity of the handle and then calls the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync-write function if this write is determined to be write-through.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else, it reflects the data to the write blocks on the mirror node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (allocated in alloc_buf). If the cache block is not dirty, it is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * marked dirty and queued up for io processing later on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If parts are already dirty but io is not in progress yet, it is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * marked dirty and left alone (it is already in the queue)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If parts are already dirty but io is in progress, it is marked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dirty and also a flag is set indicating that this buffer should
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be reprocessed after the io-end-action.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Attempt is made to coalesce multiple writes into a single list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for io processing later on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issuing of writes may be delayed until the handle is released;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_queue_write() sets NSC_QUEUE, indicating that dirty bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and reflection to mirror have already been done, just queue I/O.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_queued, ret, queue_only, store_only;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t cur_fba_len; /* position in disk blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cur_chain = NULL, *dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDALERT(SDF_WRITE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDT_INV_CD, 0, SDT_INV_BL, handle->bh_flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_NOCHECKS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_WRBUF) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NSC_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * store_only: don't queue this I/O yet
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue_only: queue I/O to disk, don't store in mirror node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_QUEUE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_only = 1, store_only = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_DELAY_QUEUE && (fba_len != handle->bh_fba_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_only = 0, store_only = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_only = store_only = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!queue_only && _SD_FORCE_DISCONNECT(fba_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_files[cd].cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_ENTER(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_WRITE, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG_PATTERN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte check_buf_consistency(handle, "wr");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((handle->bh_flag | flag) & _SD_WRTHRU_MASK) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!queue_only && _sd_remote_store(cc_ent, fba_pos, fba_len))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag |= NSC_WRTHRU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _sd_sync_write(handle, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stats_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (store_only) /* enqueue in _sd_free_buf() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, st_cblk_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (store_only) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_TOFLUSH(st_cblk_off, st_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_DIRTY(st_cblk_off, st_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_chain = dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_queued = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteloop1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_WR, cc_ent, st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_write_data1, uint64_t, (uint64_t)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + st_cblk_off),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, st_cblk_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(st_cblk_off)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off+ st_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, 0, BLK_FBAS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty(cd, cur_chain, dirty_next,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana num_queued);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_chain = dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (store_only) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_TOFLUSH(0, BLK_FBAS, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_DIRTY(0, BLK_FBAS, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_next->cc_dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_queued++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_chain = dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_queued = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte loop2:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_WR, cc_ent, 0, BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_write_data2, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)(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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_fba_len != end_cblk_len)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!fba_len %" NSC_SZFMT " end_cblk_len %d in "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_write", cur_fba_len, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty(cd, cur_chain, dirty_next,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana num_queued);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_chain = dirty_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (store_only) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_TOFLUSH(0, end_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_DIRTY(0, end_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dirty_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_next->cc_dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_queued++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_chain = dirty_next = cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_queued = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteloop3:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_WR, cc_ent, 0, end_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_write_data3, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)(BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent))),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, end_cblk_len, char *, *(int64_t *)(cc_ent->cc_data),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(cc_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(end_cblk_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!store_only && cur_chain) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty(cd, cur_chain, dirty_next, num_queued);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!queue_only) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_FBA_WRITE(cd, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_WRITE_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_WRITE_IO_KSTATS(cd, FBA_SIZE(fba_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NSC_HIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestats_exit:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_WRITE, cd, fba_len, fba_pos, flag, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_RUNQ_EXIT(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_queue_write(handle, fba_pos, fba_len): Queues delayed writes for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flushing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: handle - handle allocated with NSC_WRBUF
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - starting fba pos from _sd_alloc_buf()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - fba len from _sd_alloc_buf()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * USAGE : Called if _SD_DELAY_QUEUE is set. Finds all blocks in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle marked for flushing and queues them to be written in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optimized (i.e. sequential) order
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_queue_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_end;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t sblk, len, dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t flush_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flush_pos_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t flush_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_end = fba_pos + fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)); /* 1st block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_pos < fba_end) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = cc_ent->cc_toflush;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_toflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Full block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_BMAP_ISFULL(dirty)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flush_pos_valid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos = fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_len += BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Partial block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else 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 if (sblk && flush_pos_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_write(handle, flush_pos, flush_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flush_pos_valid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos = fba_pos + sblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_len += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos += BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we find a gap, write out what we've got
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flush_pos_valid && (flush_pos + flush_len) != fba_pos) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_write(handle, flush_pos, flush_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_pos_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flush_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flush_pos_valid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_write(handle, flush_pos, flush_len, NSC_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_remote_store(_sd_cctl_t *cc_ent, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_resource_t *ss_res;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_nodes_configured <= 2 && _sd_is_mirror_down())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_res = cc_ent->cc_write->sc_res;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_WRITE_CBLOCK(sdbc_safestore, ss_res,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(st_cblk_off))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_write) safe store failed. Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_REFLECT, CENTRY_CD(cc_ent), fba_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_pos, 0, -1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (SSOP_WRITE_CBLOCK(sdbc_safestore, ss_res, cc_ent->cc_data,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CACHE_BLOCK_SIZE, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_write) safe store failed. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_REFLECT, CENTRY_CD(cc_ent), fba_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_pos, 0, -1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end while */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_WRITE_CBLOCK(sdbc_safestore, ss_res,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data, FBA_SIZE(end_cblk_len), 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_write) nvmem dma failed. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_REFLECT, CENTRY_CD(cc_ent), fba_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_pos, 0, -1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_sync_write2 - Write-through function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wr_handle - handle into which to write the data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wr_st_pos - starting FBA position in wr_handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - NSC_NOBLOCK for async io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rd_handle - handle from which to read the data, or NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rd_st_pos - starting FBA position in rd_handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine initiates io of the indicated portion. It returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * synchronously after io is completed if NSC_NOBLOCK is not set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else NSC_PENDING is returned with a subsequent write callback on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * io completion.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See _sd_copy_direct() for usage when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (wr_handle != rd_handle && rd_handle != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_sync_write2(_sd_buf_handle_t *wr_handle, nsc_off_t wr_st_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, int flag, _sd_buf_handle_t *rd_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t rd_st_pos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*fn)(blind_t, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *wr_ent, *rd_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t this_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t rd_pos, wr_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t log_bytes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = HANDLE_CD(wr_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct buf *bp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LINTUSED(flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(wr_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rd_handle == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_handle = wr_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_st_pos = wr_st_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent = wr_handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(wr_ent) != FBA_TO_BLK_NUM(wr_st_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent = wr_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_ent = rd_handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(rd_ent) != FBA_TO_BLK_NUM(rd_st_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_ent = rd_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = sd_alloc_iob(_sd_cache_files[cd].cd_crdev,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_st_pos, FBA_TO_BLK_LEN(fba_len) + 2, B_WRITE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bp == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (E2BIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_pos = BLK_FBA_OFF(wr_st_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_pos = BLK_FBA_OFF(rd_st_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_bytes = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_len = min((BLK_FBAS - rd_pos), (BLK_FBAS - wr_pos));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (this_len > fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear dirty bits in the write handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(wr_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&wr_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(wr_ent)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (this_len == (nsc_size_t)BLK_FBAS ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_handle != wr_handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optimization for when we have a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * full cache block, or are doing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy_direct (see below).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent->cc_write->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty = wr_ent->cc_write->sc_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirty &= ~(SDBC_GET_BITS(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_pos, this_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent->cc_write->sc_dirty = dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wr_ent->cc_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&wr_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update valid bits in the write handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rd_handle == wr_handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (this_len == (nsc_size_t)BLK_FBAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_FULLY_VALID(wr_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_VALID_BITS(wr_pos, this_len, wr_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doing copy_direct, so mark the write handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as invalid since the data is on disk, but not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in cache.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent->cc_valid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_WRSYNC, rd_ent, rd_pos, this_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_sync_write2_data, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(rd_ent)) + rd_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, (uint64_t)this_len, char *,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(rd_ent->cc_data + FBA_SIZE(rd_pos)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana char *, *(int64_t *)(rd_ent->cc_data +
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(rd_pos + this_len) - 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &rd_ent->cc_addr, rd_pos, this_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_bytes += FBA_SIZE(this_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= this_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_pos += this_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wr_pos >= (nsc_size_t)BLK_FBAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_ent = wr_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_pos = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_pos += this_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rd_pos >= (nsc_size_t)BLK_FBAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_ent = rd_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rd_pos = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (fba_len > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DISK_FBA_WRITE(cd, FBA_NUM(log_bytes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CACHE_WRITE_MISS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_WRITE_IO_KSTATS(cd, log_bytes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fn = (wr_handle->bh_flag & NSC_NOBLOCK) ? _sd_async_write_ea : NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = sd_start_io(bp, _sd_cache_files[cd].cd_strategy, fn, wr_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != NSC_PENDING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG_CHAIN(SDF_WRSYEA, wr_handle->bh_centry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_st_pos, FBA_NUM(log_bytes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_sync_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_sd_sync_write2(handle, fba_pos, fba_len, flag, NULL, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_zero - Interface call to zero out a portion of cache blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - disk block number to zero from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - NSC_NOBLOCK for async io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine zeroes out the indicated portion of the cache blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and commits the data to disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (See write for more details on the commit)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_zero(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t cur_fba_len; /* position in disk blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(shutdown);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_zero) handle %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle_active, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_WRBUF) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle_write, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(zero_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_FORCE_DISCONNECT(fba_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_DISCONNECT_CALLBACK(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd = HANDLE_CD(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ZERO, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = handle->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(cc_ent->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(cc_ent->cc_data, CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent = cc_ent->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(cc_ent->cc_data, FBA_SIZE(cur_fba_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _sd_write(handle, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ZERO, cd, fba_len, fba_pos, flag, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_copy - Copies portions of 2 handles.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle1 - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle2 - handle allocated earlier on.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos1 - disk block number to read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos2 - disk block number to write to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine copies the 2 handles.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WARNING: this could put the cache blocks in the destination handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in an inconsistent state. (the blocks could be valid in cache,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but the copy makes the cache different from disk)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_copy(_sd_buf_handle_t *handle1, _sd_buf_handle_t *handle2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos1, nsc_off_t fba_pos2, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_len; /* FBA len of starting cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t end_cblk_len; /* FBA len of ending cache block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cblk_fba_t st_cblk_off; /* FBA offset into starting cblock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t off1, off2; /* offsets in FBA's into the disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t cur_fba_len; /* position in disk blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent1, *cc_ent2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(shutdown);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle1) || !_SD_HANDLE_ACTIVE(handle2)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_copy) handle %p or %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle1, (void *)handle2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(handle_active1, int, handle1->bh_flag,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, handle2->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle1, fba_pos1, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle2, fba_pos2, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent1 = handle1->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent1) != FBA_TO_BLK_NUM(fba_pos1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent1 = cc_ent1->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2 = handle2->bh_centry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent2) != FBA_TO_BLK_NUM(fba_pos2))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2 = cc_ent2->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (BLK_FBA_OFF(fba_pos1) != BLK_FBA_OFF(fba_pos2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Different offsets, do it slowly (per fba) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte off1 = FBA_SIZE(BLK_FBA_OFF(fba_pos1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte off2 = FBA_SIZE(BLK_FBA_OFF(fba_pos2));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data+off1, cc_ent2->cc_data+off2,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos2++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_TO_BLK_NUM(fba_pos1) != CENTRY_BLK(cc_ent1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent1 = cc_ent1->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_TO_BLK_NUM(fba_pos2) != CENTRY_BLK(cc_ent2))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2 = cc_ent2->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_copy_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len = fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_off = BLK_FBA_OFF(fba_pos1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = BLK_FBAS - st_cblk_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nsc_size_t)st_cblk_len >= fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st_cblk_len = (sdbc_cblk_fba_t)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_cblk_len = BLK_FBA_OFF(fba_pos1 + fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data + FBA_SIZE(st_cblk_off),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= st_cblk_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent1 = cc_ent1->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2 = cc_ent2->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (cur_fba_len > (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data, cc_ent2->cc_data, CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent1 = cc_ent1->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2 = cc_ent2->cc_chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_fba_len -= BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur_fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data, cc_ent2->cc_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(end_cblk_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NSC_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_copy_direct - Copies data from one handle direct to another disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle1 - handle to read from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle2 - handle to write to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos1 - disk block number to read from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos2 - disk block number to write to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - length in fbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine copies data from handle1 directly (sync write)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * onto the disk pointed to by handle2. The handle2 is then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invalidated since the data it contains is now stale compared to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_copy_direct(_sd_buf_handle_t *handle1, _sd_buf_handle_t *handle2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos1, nsc_off_t fba_pos2, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sdbc_shutdown_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(shutdown);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!_SD_HANDLE_ACTIVE(handle1) || !_SD_HANDLE_ACTIVE(handle2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_copy_direct) handle %p or %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle1, (void *)handle2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(handle_active2, int, handle1->bh_flag,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, handle2->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle1, fba_pos1, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle2, fba_pos2, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle2->bh_flag & NSC_WRITE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_copy_direct) handle2 %p is not writeable",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle2_write, int, handle2->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_sync_write2(handle2, fba_pos2, fba_len, 0, handle1, fba_pos1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_enqueue_dirty - Enqueue a list of dirty buffers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - cache descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chain - pointer to list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_last - last entry in the chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * numq - number of entries in the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine queues up the dirty blocks for io processing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It uses the cc_last to try to coalesce multiple lists into a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * single list, if consecutive writes are sequential in nature.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_enqueue_dirty(int cd, _sd_cctl_t *chain, _sd_cctl_t *cc_last, int numq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *last_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int start_write = 0, maxq = SGIO_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_SD_DEBUG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chain->cc_dirty_link)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!dirty_link set in enq %x fl %x",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana chain->cc_dirty_link, chain->cc_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&(cdi->cd_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numdirty += numq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_last == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numq = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_dirty_head == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = cdi->cd_dirty_tail = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_last_ent = cc_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain_ptr = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain = numq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cc_last) && (last_ent = cdi->cd_last_ent) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (CENTRY_BLK(chain) == (CENTRY_BLK(last_ent)+1)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (SDBC_DIRTY_NEIGHBORS(last_ent, chain)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_lastchain + numq < maxq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_last_ent->cc_dirty_next = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_last_ent = cc_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain += numq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail->cc_dirty_link = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_last_ent = cc_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain_ptr = chain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain = numq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_write = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&(cdi->cd_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start_write)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _SD_CD_WRITER(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_enqueue_dirty_chain - Enqueue a chain of a list of dirty buffers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - cache descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chain_first - first list in this chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chain_last - last list in this chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * numq - number of entries being queue (total of all lists)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NONE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Comments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is called from the processing after io completions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the buffers are still dirty, they are queued up in one shot.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_enqueue_dirty_chain(int cd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *chain_first,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *chain_last,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int numq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cd >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chain_last->cc_dirty_link)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_sd_enqueue_dirty_chain: chain_last %p dirty_link %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)chain_last, (void *)chain_last->cc_dirty_link);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&(cdi->cd_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_last_ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_lastchain = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numdirty += numq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_dirty_head == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_head = chain_first;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail = chain_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail->cc_dirty_link = chain_first;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_dirty_tail = chain_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&(cdi->cd_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconvert_stats(_sd_stats32_t *uptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Convert the 64 bit statistic structure to 32bit version.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Possibly losing information when cache is > 4gb. Ha!
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: this code isn't really MT ready since the copied to struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is static. However the race is pretty benign and isn't a whole
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lot worse than the vanilla version which copies data to user
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * space from kernel structures that can be changing under it too.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We can't use a local stack structure since the data size is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 70k or so and kernel stacks are tiny (8k).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (SDBC_EMODELCONVERT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This could be done in less code with bcopy type operations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but this is simpler to follow and easier to change if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the structures change.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->net_dirty = _sd_cache_stats->net_dirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->net_pending = _sd_cache_stats->net_pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->net_free = _sd_cache_stats->net_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_count = _sd_cache_stats->st_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_loc_count = _sd_cache_stats->st_loc_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_rdhits = _sd_cache_stats->st_rdhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_rdmiss = _sd_cache_stats->st_rdmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_wrhits = _sd_cache_stats->st_wrhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_wrmiss = _sd_cache_stats->st_wrmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_blksize = _sd_cache_stats->st_blksize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_lru_blocks = _sd_cache_stats->st_lru_blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_lru_noreq = _sd_cache_stats->st_lru_noreq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_lru_req = _sd_cache_stats->st_lru_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_wlru_inq = _sd_cache_stats->st_wlru_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_cachesize = _sd_cache_stats->st_cachesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_numblocks = _sd_cache_stats->st_numblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_wrcancelns = _sd_cache_stats->st_wrcancelns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats32->st_destaged = _sd_cache_stats->st_destaged;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bcopy the shared stats which has nothing that needs conversion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in them
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(_sd_cache_stats->st_shared, _sd_cache_stats32->st_shared,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (_sd_shared_t) * sdbc_max_devs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyout(_sd_cache_stats32, uptr, sizeof (_sd_stats32_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devs - 1) * sizeof (_sd_shared_t)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _MULTI_DATAMODEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_stats(_sd_stats_t *uptr, int convert_32)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_cache_stats == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static _sd_stats_t dummy;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static _sd_stats32_t dummy32;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (convert_32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _MULTI_DATAMODEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyout(&dummy32, uptr, sizeof (_sd_stats32_t)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = SDBC_EMODELCONVERT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (copyout(&dummy, uptr, sizeof (_sd_stats_t)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_lru_blocks = _sd_lru_q.sq_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_lru_noreq = _sd_lru_q.sq_noreq_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_lru_req = _sd_lru_q.sq_req_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_safestore) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssioc_stats_t ss_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SSOP_CTL(sdbc_safestore, SSIOC_STATS,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uintptr_t)&ss_stats) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_wlru_inq = ss_stats.wq_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_stats->st_wlru_inq = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (convert_32)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = convert_stats((_sd_stats32_t *)uptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (copyout(_sd_cache_stats, uptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (_sd_stats_t) + (sdbc_max_devs - 1) * sizeof (_sd_shared_t)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_set_hint(int cd, uint_t hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, cd, 1, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[cd].cd_hint |= (hint & _SD_HINT_MASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, cd, 1, SDT_INV_BL, hint, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_clear_hint(int cd, uint_t hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, cd, 2, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[cd].cd_hint &= ~(hint & _SD_HINT_MASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, cd, 2, SDT_INV_BL, hint, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_cd_hint(int cd, uint_t *hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *hint = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *hint = _sd_cache_files[cd].cd_hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_node_hint_caller(blind_t hint, int hint_action)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (hint_action) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSC_GET_NODE_HINT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_get_node_hint((uint_t *)hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSC_SET_NODE_HINT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_set_node_hint((uint_t)(unsigned long)hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSC_CLEAR_NODE_HINT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_clear_node_hint((uint_t)(unsigned long)hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_set_node_hint(uint_t hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, SDT_INV_CD, 3, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_node_hint & NSC_NO_FORCED_WRTHRU) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (hint & NSC_FORCED_WRTHRU))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_hint |= (hint & _SD_HINT_MASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, SDT_INV_CD, 3, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_clear_node_hint(uint_t hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, SDT_INV_CD, 4, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_node_hint &= ~(hint & _SD_HINT_MASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, SDT_INV_CD, 4, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_node_hint(uint_t *hint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *hint = _sd_node_hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_partsize(blind_t xcd, nsc_size_t *ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FILE_OPENED(cd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = _sd_cache_files[cd].cd_info->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_maxfbas(blind_t xcd, int flag, nsc_size_t *ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!FILE_OPENED(cd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_CACHEBLK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = BLK_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = sdbc_max_fbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_control(blind_t xcd, int cmd, void *ptr, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi = &(_sd_cache_files[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nsc_control(cdi->cd_rawfd, cmd, ptr, len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_discard_pinned(blind_t xcd, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cd = (int)(unsigned long)xcd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cctl_t *cc_ent, **cc_lst, **cc_tmp, *nxt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss_centry_info_t *wctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t cblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cd_info_t *cdi = &_sd_cache_files[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!FILE_OPENED(cd)) || (!cdi->cd_info->sh_failed)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cblk = FBA_TO_BLK_NUM(fba_pos);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cblk < FBA_TO_BLK_LEN(fba_pos + fba_len); cblk++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_ent =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cctl_t *)_sd_hash_search(cd, cblk, _sd_htable)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!CENTRY_PINNED(cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove cc_ent from failed links
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_lst - pointer to "cc_dirty_link" pointer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * starts at &cd_failed_head.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_tmp - pointer to "cc_dirty_next"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * except when equal to cc_lst.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_tmp = cc_lst = &(cdi->cd_fail_head);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*cc_tmp != cc_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_tmp = &((*cc_tmp)->cc_dirty_next);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!*cc_tmp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_lst = &((*cc_lst)->cc_dirty_link),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_tmp = cc_lst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*cc_tmp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cc_lst != cc_tmp) /* break chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cc_tmp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt = cc_ent->cc_dirty_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nxt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt->cc_dirty_link =
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (*cc_lst)->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cc_lst = nxt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cc_lst = (*cc_lst)->cc_dirty_link;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info->sh_numfail--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_unpinned_data(cdi->cd_iodev,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_FBAS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cdi->cd_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear dirty bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_valid = cc_ent->cc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~(CC_QHEAD|CC_PEND_DIRTY|CC_PINNED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl = cc_ent->cc_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&cc_ent->cc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release cache block to head of LRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wctl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wctl->sc_dirty = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, wctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_use_dmchain)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_requeue_head(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = found ? NSC_DONE : EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handle allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_buf_hlist_t _sd_handle_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_handles_unload - cache is being unloaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_handles_unload(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_sd_handle_list.hl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_handles_load - cache is being unloaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_handles_load(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_handle_list.hl_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_handles_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_top.bh_next = &_sd_handle_list.hl_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_top.bh_prev = &_sd_handle_list.hl_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_handles_deconfigure - cache is being deconfigured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_handles_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_buf_handle_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_alloc_handle(sdbc_callback_fn_t d_cb, sdbc_callback_fn_t r_cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_callback_fn_t w_cb)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buf_handle_t *handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = (_sd_buf_handle_t *)kmem_zalloc(sizeof (_sd_buf_handle_t),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* maintain list and count for debugging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_handle_list.hl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_prev = &_sd_handle_list.hl_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_next = _sd_handle_list.hl_top.bh_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_top.bh_next->bh_prev = handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_handle_list.hl_top.bh_next = handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++_sd_handle_list.hl_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_handle_list.hl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined(_SD_NOCHECKS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!(handle->bh_flag & (NSC_HALLOCATED | NSC_HACTIVE)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_disconnect_cb = d_cb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_read_cb = r_cb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_write_cb = w_cb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_flag |= NSC_HALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_alloc_thread = nsc_threadp();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_free_handle(_sd_buf_handle_t *handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_HALLOCATED) == 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_free_handle) handle %p not valid",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(_sd_free_handle_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_SD_HANDLE_ACTIVE(handle)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_free_handle) attempt to free active handle %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(free_handle_active, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove from queue before free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_sd_handle_list.hl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_prev->bh_next = handle->bh_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->bh_next->bh_prev = handle->bh_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --_sd_handle_list.hl_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_sd_handle_list.hl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(handle, sizeof (_sd_buf_handle_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if !defined (_SD_8K_BLKSIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_MAX_MAP 0x100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !(_SD_8K_BLKSIZE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SD_MAX_MAP 0x10000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* !(_SD_8K_BLKSIZE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar _sd_contig_bmap[_SD_MAX_MAP];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_map_info_t _sd_lookup_map[_SD_MAX_MAP];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_init_contig_bmap(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; i < _SD_MAX_MAP; i = ((i << 1) | 1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = i; j < _SD_MAX_MAP; j <<= 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_contig_bmap[j] = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_init_lookup_map(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int i, j, k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stpos, len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_bitmap_t mask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_MAX_MAP; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = i, k = 0; j && ((j & 1) == 0); j >>= 1, k++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stpos = k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_stpos = (unsigned char)k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (k = 0; j & 1; j >>= 1, k++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_len = (unsigned char)k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_mask = SDBC_GET_BITS(stpos, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_MAX_MAP; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mask = (_sd_bitmap_t)i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; mask; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_LOOKUP_MODIFY(mask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_dirty_count = (unsigned char)j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_MAX_MAP; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_io_count = SDBC_LOOKUP_DTCOUNT(i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mask = ~i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_io_count += SDBC_LOOKUP_DTCOUNT(mask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_def_t _sd_sdbc_def[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Open", (uintptr_t)_sd_open_io, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Close", (uintptr_t)_sd_close_io, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Attach", (uintptr_t)_sdbc_io_attach_cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Detach", (uintptr_t)_sdbc_io_detach_cd, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "AllocBuf", (uintptr_t)_sd_alloc_buf, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FreeBuf", (uintptr_t)_sd_free_buf, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Read", (uintptr_t)_sd_read, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Write", (uintptr_t)_sd_write, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Zero", (uintptr_t)_sd_zero, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Copy", (uintptr_t)_sd_copy, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "CopyDirect", (uintptr_t)_sd_copy_direct, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Uncommit", (uintptr_t)_sd_uncommit, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "AllocHandle", (uintptr_t)_sd_alloc_handle, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FreeHandle", (uintptr_t)_sd_free_handle, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Discard", (uintptr_t)_sd_discard_pinned, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Sizes", (uintptr_t)_sd_cache_sizes, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "GetPinned", (uintptr_t)_sd_get_pinned, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "NodeHints", (uintptr_t)_sd_node_hint_caller, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "PartSize", (uintptr_t)_sd_get_partsize, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "MaxFbas", (uintptr_t)_sd_get_maxfbas, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Control", (uintptr_t)_sd_control, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Provide", NSC_CACHE, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the SD_GET_CD_CLUSTER_DATA ioctl (get the global filename data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_get_file_info_data(char *uaddrp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOTTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the SD_GET_CD_CLUSTER_SIZE ioctl (get size of global filename area)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_get_file_info_size(void *uaddrp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyout(&_sdbc_gl_file_info_size, uaddrp,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sizeof (_sdbc_gl_file_info_size))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SD_GET_GLMUL_SIZES ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get sizes of the global info regions (for this node only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_get_glmul_sizes(int *uaddrp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOTTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SD_GET_GLMUL_INFO ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the global metadata for write blocks (for this node only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_get_glmul_info(char *uaddrp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOTTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_global_stats_update(kstat_t *ksp, int rw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global_stats_t *sdbc_gstats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_stats_t *gstats_vars;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats = (sdbc_global_stats_t *)(ksp->ks_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gstats_vars = _sd_cache_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rw == KSTAT_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* default to READ */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_count.value.ul = gstats_vars->st_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_loc_count.value.ul = gstats_vars->st_loc_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_rdhits.value.ul = (ulong_t)gstats_vars->st_rdhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_rdmiss.value.ul = (ulong_t)gstats_vars->st_rdmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_wrhits.value.ul = (ulong_t)gstats_vars->st_wrhits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_wrmiss.value.ul = (ulong_t)gstats_vars->st_wrmiss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_blksize.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_blksize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_lru_blocks.value.ul = (ulong_t)_sd_lru_q.sq_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_lru_noreq.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)_sd_lru_q.sq_noreq_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_lru_req.value.ul = (ulong_t)_sd_lru_q.sq_req_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_wlru_inq.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_wlru_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_cachesize.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_cachesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_numblocks.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_numblocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_wrcancelns.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_wrcancelns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_destaged.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)gstats_vars->st_destaged;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_num_shared.value.ul = (ulong_t)sdbc_max_devs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_get_node_hint(&hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_nodehints.value.ul = (ulong_t)hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_cd_stats_update(kstat_t *ksp, int rw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_stats_t *sdbc_shstats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_shared_t *shstats_vars;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats = (sdbc_cd_stats_t *)(ksp->ks_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shstats_vars = (_sd_shared_t *)(ksp->ks_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rw == KSTAT_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy tail of filename to kstat. leave 1 byte for null char */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (shstats_vars->sh_filename != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name_len = (int)strlen(shstats_vars->sh_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name_len -= (KSTAT_DATA_CHAR_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (name_len < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strlcpy(sdbc_shstats->ci_sdbc_vol_name.value.c,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shstats_vars->sh_filename + name_len, KSTAT_DATA_CHAR_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Kstat error: no volume name associated "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "with cache descriptor");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_failed.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_cd.value.ul = (ulong_t)shstats_vars->sh_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_cache_read.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_cache_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_cache_write.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_cache_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_disk_read.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_disk_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_disk_write.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_filesize.value.ui64 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint64_t)shstats_vars->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_filesize.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_numdirty.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_numdirty;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_numio.value.ul = (ulong_t)shstats_vars->sh_numio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_numfail.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_numfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_destaged.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_destaged;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_wrcancelns.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ulong_t)shstats_vars->sh_wrcancelns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_get_cd_hint(shstats_vars->sh_cd, &hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_cdhints.value.ul = (ulong_t)hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd_kstat_add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Installs all kstats and associated infrastructure (mutex, buffer),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associated with a particular cache descriptor. This function is called
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when the cache descriptor is opened in _sd_open().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cd" -- cache descriptor number whose kstats we wish to add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns: 0 on success, -1 on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecd_kstat_add(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char name[KSTAT_STRLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd < 0 || cd >= sdbc_max_devs) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!invalid cache descriptor: %d", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a regular kstat for this cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_cd_kstats) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_kstats not allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(name, KSTAT_STRLEN, "%s%d", SDBC_KSTAT_CDSTATS, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd] = kstat_create(SDBC_KSTAT_MODULE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd, name, SDBC_KSTAT_CLASS, KSTAT_TYPE_NAMED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (sdbc_cd_stats)/sizeof (kstat_named_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_FLAG_VIRTUAL|KSTAT_FLAG_WRITABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_kstats[cd] != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd]->ks_data = &sdbc_cd_stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd]->ks_update = sdbc_cd_stats_update;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd]->ks_private =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &_sd_cache_stats->st_shared[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_install(sdbc_cd_kstats[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!cdstats %d kstat allocation failed", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create an I/O kstat for this cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_cd_io_kstats) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_io_kstats not allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(name, KSTAT_STRLEN, "%s%d", SDBC_IOKSTAT_CDSTATS, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[cd] = kstat_create(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_KSTAT_MODULE, cd, name, "disk", KSTAT_TYPE_IO, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats[cd]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sdbc_cd_io_kstats_mutexes) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_io_kstats_mutexes not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&sdbc_cd_io_kstats_mutexes[cd], NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[cd]->ks_lock = &sdbc_cd_io_kstats_mutexes[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_install(sdbc_cd_io_kstats[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc cd %d io kstat allocation failed", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd_kstat_remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Uninstalls all kstats and associated infrastructure (mutex, buffer),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associated with a particular cache descriptor. This function is called
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when the cache descriptor is closed in _sd_close().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "cd" -- cache descriptor number whose kstats we wish to remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns: 0 on success, -1 on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecd_kstat_remove(int cd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd < 0 || cd >= sdbc_max_devs) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!invalid cache descriptor: %d", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete the regular kstat corresponding to this cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_kstats && sdbc_cd_kstats[cd]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_cd_kstats[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete the I/O kstat corresponding to this cache descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats && sdbc_cd_io_kstats[cd]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_delete(sdbc_cd_io_kstats[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[cd] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_cd_io_kstats_mutexes) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* destroy the mutex associated with this I/O kstat */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&sdbc_cd_io_kstats_mutexes[cd]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat update
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_dynmem_kstat_update_dm(kstat_t *ksp, int rw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_dm_t *sdbc_dynmem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _dm_process_vars_t *process_vars;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _dm_process_vars_t local_dm_process_vars;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte simplect_dm++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem = (sdbc_dynmem_dm_t *)(ksp->ks_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* global dynmem_processing_dm */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars = (_dm_process_vars_t *)(ksp->ks_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rw == KSTAT_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte simplect_dm = sdbc_dynmem->ci_sdbc_simplect.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.monitor_dynmem_process =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_monitor_dynmem.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.max_dyn_list =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_max_dyn_list.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_ct1 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct1.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_ct2 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct2.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_ct3 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct3.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_sec1 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec1.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_sec2 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec2.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_sec3 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec3.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_pcnt1 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt1.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.cache_aging_pcnt2 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt2.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.max_holds_pcnt =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_max_holds_pcnt.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_dm_process_vars.process_directive =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_process_directive.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sdbc_edit_xfer_process_vars_dm(&local_dm_process_vars);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (process_vars->process_directive & WAKE_DEALLOC_THREAD_DM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->process_directive &=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~WAKE_DEALLOC_THREAD_DM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&dynmem_processing_dm.thread_dm_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&dynmem_processing_dm.thread_dm_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* default to READ */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_simplect.value.ul = simplect_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_monitor_dynmem.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->monitor_dynmem_process;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_max_dyn_list.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct1.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_ct1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct2.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_ct2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_ct3.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_ct3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec1.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_sec1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec2.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_sec2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_sec3.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_sec3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt1.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_pcnt1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt2.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->cache_aging_pcnt2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_max_holds_pcnt.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->max_holds_pcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_process_directive.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars->process_directive;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_alloc_ct.value.ul = process_vars->alloc_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_dealloc_ct.value.ul = process_vars->dealloc_ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_history.value.ul = process_vars->history;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_nodatas.value.ul = process_vars->nodatas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_candidates.value.ul = process_vars->candidates;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_deallocs.value.ul = process_vars->deallocs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_hosts.value.ul = process_vars->hosts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_pests.value.ul = process_vars->pests;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_metas.value.ul = process_vars->metas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_holds.value.ul = process_vars->holds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_others.value.ul = process_vars->others;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_notavail.value.ul = process_vars->notavail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif