fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_global_stats_update(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_cd_stats_update(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem kstat interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_dynmem_kstat_update_dm(kstat_t *ksp, int rw);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
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_PROCESS_DIRECTIVE, KSTAT_DATA_ULONG},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* End of dynmem kstats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *dmchainpull_table; /* dmchain wastage stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dynmem process vars
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* metadata for volumes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* metadata for cache write blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* wblocks * sizeof(ss_centry_info_t) */
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_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 * Set the following variable to 1 to enable pagelist io mutual
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exclusion on all _sd_alloc_buf() operations.
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 Forteint sdbc_use_dmchain = 0; /* start time switch for dm chaining */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_prefetch1 = 1; /* do 1-block read-ahead */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if sdbc_static_cache is 1 allocate all cache memory at startup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * deallocate only at shutdown.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Pagelist io mutual exclusion debug facility.
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 Forte * INF SD cache global data
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 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 * 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 Fortestatic void _sdbc_stats_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_lruq_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sdbc_mem_configure(int cblocks, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_ins_queue(_sd_queue_t *, _sd_cctl_t *centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_check_buffer_alloc(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
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 Fortestatic void _sd_async_write_ea(blind_t xhandle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_queue_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_remote_store(_sd_cctl_t *cc_ent, nsc_off_t fba_pos,
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 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 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_file_deconfigure(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sdbc_doread_prefetch(_sd_cctl_t *cc_ent, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic _sd_bitmap_t update_dirty(_sd_cctl_t *cc_ent, sdbc_cblk_fba_t st_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_prefetch_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
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 Fortestatic _sd_cctl_t *sdbc_get_dmchain(int, int *, int);
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 Fortestatic _sd_cctl_t *sdbc_alloc_dmc(int, nsc_off_t, nsc_size_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 Fortestatic int sdbc_centry_memalloc_dm(_sd_cctl_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sdbc_centry_alloc_end(sdbc_allocbuf_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* _SD_DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_cache_configure - initialize cache blocks, queues etc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SDBC_EENABLEFAIL or SDBC_EMEMCONFIG on failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_cache_configure(int cblocks, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sdbc_max_devs * sizeof (_sd_cd_info_t),
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 * 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 /* CCIO shutdown must happen before memory is free'd */
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 for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_cd_kstats, sizeof (kstat_t *) * sdbc_max_devs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_cd_io_kstats, sizeof (kstat_t *) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mutexes are already destroyed in cd_kstat_remove() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sd_cache_stats32, sizeof (_sd_stats32_t) +
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_cachesize = cblocks * BLK_SIZE(1);
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 /* 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 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;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc: gstats kstat failed");
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 mutex_init(&sdbc_global_io_kstat_mutex, NULL, MUTEX_DRIVER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat implementation - cd stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: one kstat instance for each open cache descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats = kmem_zalloc(sizeof (kstat_t *) * sdbc_max_devs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat implementation - i/o kstats per cache descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: one I/O kstat instance for each cd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats = kmem_zalloc(sizeof (kstat_t *) * sdbc_max_devs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats_mutexes = kmem_zalloc(sizeof (kmutex_t) *
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 sdbc_dynmem_kstat_dm->ks_update = sdbc_dynmem_kstat_update_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem_kstat_dm->ks_private = &dynmem_processing_dm;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc: dynmem kstat failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_dmqueues_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize the queues of dynamic memory chains.
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 max_dm_queues = dynmem_processing_dm.max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++max_dm_queues; /* need a "0" queue for centrys with no memory */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana kmem_zalloc(max_dm_queues * sizeof (_sd_queue_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dmchainpull_table = (int *)kmem_zalloc(max_dm_queues *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < max_dm_queues; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CAUTION! this code depends on max_dyn_list not changing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sdbc_dm_queues, max_dm_queues * sizeof (_sd_queue_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define GOOD_LRUSIZE(q) ((q->sq_inq >= 0) || (q->sq_inq <= CBLOCKS))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_lruq_configure - initialize the lru queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: NONE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS: 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_lru->sq_qlock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lru->sq_qhead.cc_next = _sd_lru->sq_qhead.cc_prev
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_lruq_deconfigure - deconfigure the lru queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS: NONE
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 * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS: 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sdbc_mem_configure(int cblocks, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_htable = _sdbc_hash_configure(cblocks)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_zalloc(_sd_cctl_groupsz * sizeof (_sd_cctl_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_zalloc(_sd_ccsync_cnt * sizeof (_sd_cctl_sync_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
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 cv_init(&_sd_ccent_sync[i]._cc_blkcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_blks = (netc->sn_cpages * (int)netc->sn_psize)/BLK_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_sync = &_sd_ccent_sync[blk % _sd_ccsync_cnt];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_dirty_next = centry->cc_dirty_link = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_await_use = centry->cc_await_page = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_gl_file_configure()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate and initialize space for the global filename data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_gl_file_info_size = safestore_config.ssc_maxfiles *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sdbc_gl_file_info = kmem_zalloc(_sdbc_gl_file_info_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup the key to get a directory stream of all volumes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if coming up after a crash, "refresh" the host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory copy from safestore.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the vdir getting volume data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and volume tokens
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETVDIRENT(sdbc_safestore, &vdir, fileinfo))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail to configure since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is not possible.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* normal initialization, not a warm start */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this fails, continue: cache will start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in writethru mode
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the vdir getting just the volume tokens
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and initializing volume entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETVDIRENT(sdbc_safestore, &vdir,
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 /* initialize the directory entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = SSOP_SETVOL(sdbc_safestore, fileinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_gl_file_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "volume entry write failure %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* coming up clean, continue in w-t mode */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_file_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "unable to init safe store volinfo");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sdbc_gl_centry_info, _sdbc_gl_centry_info_size);
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 if ((_sdbc_gl_centry_info = kmem_zalloc(_sdbc_gl_centry_info_size,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "alloc failed for gl_centry_info region");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * synchronize the centry info area with safe store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup the key to get a directory stream of all centrys */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the cdir getting resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tokens and reading centrys
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETCDIRENT(sdbc_safestore, &cdir, cinfo))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail to configure since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is not possible.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cannot read safestore");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cycle through the cdir getting resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tokens and initializing centrys
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((err = SSOP_GETCDIRENT(sdbc_safestore, &cdir, cinfo))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = SSOP_SETCENTRY(sdbc_safestore, cinfo))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_gl_centry_configure): "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "cache entry write failure %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* coming up clean, continue in w-t mode */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(sdbc_gl_centry_configure) "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "_sdbc_gl_centry_info initialization failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(_sdbc_gl_file_info, _sdbc_gl_file_info_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_mem_deconfigure - deconfigure the cache memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release any memory/locks/sv's acquired during _sdbc_mem_configure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cblocks - Number of cache blocks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _sd_ccsync_cnt; i++) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana _sd_ccsync_cnt * sizeof (_sd_cctl_sync_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_CCTL_GROUPS; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_ins_queue - insert centry into LRU queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (during initialization, locking not required)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_requeue %x prev %x next %x qp %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_requeue_head %x prev %x next %x qn %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_open - Open a file.
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 * cd - the cache descriptor.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_open) cache not initialized");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_OPEN, (cd < 0) ? SDT_INV_CD : cd, 0, SDT_INV_BL, 0, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_open_io(char *filename, int flag, blind_t *cdp, nsc_iodev_t *iodev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_open_cd(char *filename, const int cd, const int flag)
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 if (cd >= 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_open_cd) cd %d mismatch",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana new_cd < (sdbc_max_devs); new_cd++, cdi++, cdg++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_info = &_sd_cache_stats->st_shared[new_cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update safestore */
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 while (cdi->cd_info->sh_alloc == CD_ALLOC_IN_PROGRESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_open(filename, NSC_SDBC_ID|NSC_DEVICE, _sdbc_fd_def,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !nsc_getval(cdi->cd_rawfd, "DevMaj", (int *)&devmaj) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !nsc_getval(cdi->cd_rawfd, "DevMin", (int *)&devmin)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take into account that there may be pinned data on a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * device that can no longer be opened
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(cdi->cd_info->sh_failed) && !failover_open) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put the dev_t in the ioerr_inject_table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global = (_sdbc_gl_file_info + alloc_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_global->sv_pinned == _SD_SELF_HOST) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&cdi->cd_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdi->cd_global = (_sdbc_gl_file_info + alloc_cd);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Could not create kstats for cache descriptor"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_close - Close a cache descriptor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to be closed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: Under Construction.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cdi->cd_info->sh_alloc & CD_CLOSE_IN_PROGRESS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, EINVAL);
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 if (rc != 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (cdi->cd_global->sv_pinned == _SD_NO_HOST)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SSOP_SETVOL(sdbc_safestore, cdi->cd_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, rc);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Could not remove kstat for cache descriptor "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cdi->cd_info = NULL; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_CLOSE, cd, 0, SDT_INV_BL, 0, NSC_DONE);
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 /* is this always necessary? jgk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update the cache block metadata */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_write->sc_dirty = CENTRY_DIRTY(cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_SETCENTRY(sdbc_safestore, cc_ent->cc_write);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_flush_cd()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reflect pinned blocks to mirrored node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for dirty blocks to be flushed
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 * if we timed out simply return otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it must be an i/o type of error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flush any pinned/failed blocks to mirror */
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 * 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 return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_io_attach_cd -- set up for client access to device, reserve raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to attach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, EINVAL);
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 if (cdi->cd_global->sv_pinned == _SD_SELF_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sdbc_io_attach_cd: pinned data. returning EINVAL");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdi->cd_info == NULL) || (cdi->cd_info->sh_failed)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for node recovery to finish */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will provoke a sdbc_fd_attach_cd call .. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ATTACH, cd, 0, SDT_INV_BL, 0, rc);
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 * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to attach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
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 /* retrieve pinned/failed data */
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 * _sdbc_io_detach_cd -- release raw device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called when a cache client is being detached from this cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
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 /* relinquish responsibility for device */
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 /* this will provoke/allow a call to sdbc_fd_detach_cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
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 * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rd_only - non-zero if detach is for read access.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
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 SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdi->cd_global->sv_attached == _SD_SELF_HOST) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sdbc_detach_cd) (%d) attached by node %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(SDF_DETACH, cd, 0, SDT_INV_BL, 0, EPROTO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_DETACH, cd, 0, SDT_INV_BL, 0, 0);
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 * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xcd - the cache descriptor to detach.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
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 * _sd_get_pinned - re-issue PINNED callbacks for cache device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd - the cache descriptor to reissue pinned calbacks from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error otherwise.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)), BLK_FBAS);
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_sd_allocate_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sts = _sd_alloc_buf((blind_t)(unsigned long)cd, fba_pos, fba_len,
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_sd_prefetch_buf(int cd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
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_size_t request_blocks = 0; /* number of cache blocks required */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: truncate if req'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_pos + fba_len) > cdi->cd_info->sh_filesize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SETUP_HANDLE(handle, cd, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count number of blocks on chain that is required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* middle piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte request_blocks += (fba_len - (st_cblk_len + end_cblk_len)) >>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = ((flag & NSC_PAGEIO) != 0 || sdbc_pageio_always != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: skip leading valid blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_VALID_BITS(st_cblk_off, st_cblk_len, centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
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 _sd_hash_search(cd, cblk, _sd_htable) != centry) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!prefetch centry %p cd %d cblk %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cc_data %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before messing with the centry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flusher not done with pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will reset the age flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* block mismatch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_centry_alloc(cd, cblk, request_blocks,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: cache is very busy. just do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the i/o for the blocks already acquired,
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 * 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.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE1(_sd_alloc_buf, _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion now if we did not do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flusher not done with pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prefetch: skip leading busy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or truncate at busy block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len, centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if this block has a new identity clear prefetch history */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= this_entry_type | PREFETCH_BUF_E;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (fba_len > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts = _sd_setup_category_on_type(handle->bh_centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_setup_mem_chaining(handle->bh_centry, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: trailing valid can be released, adjust len */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait - wait for inuse cache block to become available
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (SET_CENTRY_INUSE(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait(cd, blk, centry, CC_INUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * goto try_again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (SET_CENTRY_PAGEIO(centry)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_cc_wait(cd, blk, centry, CC_PAGEIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * goto try_again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_cc_wait(int cd, nsc_off_t cblk, _sd_cctl_t *centry, int flag)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_sd_cc_wait: unknown flag value (%x)", flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CC_CD_BLK_MATCH(cd, cblk, centry) && (*uflag) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*uflag) != 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cd, 0, BLK_TO_FBA_NUM(cblk), (nsc_usec()-stime), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_alloc_buf - Allocate a vector of buffers for io.
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 * 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 * 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_sd_alloc_buf(blind_t xcd, nsc_off_t fba_pos, nsc_size_t fba_len, int flag,
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_size_t fba_orig_len = fba_len; /* FBA length of orig request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t dmchain_request_blocks; /* size of dmchain in cache blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Force large writes on nvram systems to be write-through to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid the (slow) bcopy into nvram.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[cd].cd_crdev == sdbc_pageio_rdev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG */
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 SDTRACE(ST_ENTER|SDF_ALLOCBUF, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _sd_prefetch_buf(cd, fba_pos, fba_len, flag, handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDAHEAD) { /* _sd_prefetch_opt == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prefetch: truncate if req'd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_size = _sd_cache_files[(cd)].cd_info->sh_filesize;
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 SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos,
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 SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* write & disk failed, return error immediately */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & NSC_WRBUF) && cdi->cd_info->sh_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_len, fba_pos, flag, EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _SD_SETUP_HANDLE(handle, cd, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_RDAHEAD) { /* _sd_prefetch_opt == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CKD prefetch: bufvec not req'd, use placeholder */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count number of blocks on chain that is required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* middle piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (fba_len - (st_cblk_len + end_cblk_len)) >> BLK_FBA_SHFT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* end piece */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle->bh_flag & NSC_PINNABLE) && (handle->bh_flag & NSC_WRBUF))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pageio = ((flag & NSC_PAGEIO) != 0 || sdbc_pageio_always != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* already inuse: wait for block, retry */
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 _sd_hash_search(cd, cblk, _sd_htable) != centry) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before messing with the centry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for flusher to finish pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this will reset the age flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* block mismatch: release, alloc new block */
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.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE1(_sd_alloc_buf2, _sd_cctl_t *, centry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do pagelist io mutual exclusion now if we did not do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for flusher to finish pageio */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * end action might set PEND_DIRTY flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must lock if need to change flag bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (centry->cc_flag != (centry->cc_flag | cc_flag)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
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 } else if (fba_len == (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if this block has a new identity clear prefetch history */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do any necessary cleanup now that all the blocks are allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* be sure you nul term. the chain */
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 if (sts = _sd_setup_category_on_type(handle->bh_centry)) {
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 * step two: alloc the needed mem and fill in the data and chaining
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields (leave bufvec for step three)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_setup_mem_chaining(handle->bh_centry, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * step three: do the bufvec
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE3(_sd_alloc_buf_centrys, _sd_cctl_t *, centry,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(centry)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fba_len == (nsc_size_t)end_cblk_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* contiguous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* contiguous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* be sure you nul term. the chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* frag statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tbufvec = handle->bh_bufvec; tbufvec != bufvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((min_frag > tbufvec->buflen) || (min_frag == 0))
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 if (_sd_alloc_write(handle->bh_centry, &stall)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ALLOCBUF, cd, fba_orig_len, fba_pos, flag, sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consistency checking for ccents
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!(p & (HOST_ENTRY_DM | PARASITIC_ENTRY_DM | ELIGIBLE_ENTRY_DM)))
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 * print message or panic (DEBUG) if inconsistency detected.
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 switch ((age & (ELIGIBLE_ENTRY_DM | HOLD_ENTRY_DM | HASH_ENTRY_DM))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* zero or multiple flag bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* categories are mutually exclusive */
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 |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* eligible has no data and no size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* parasite has zero size and non-zero data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host has non-zero size and non-zero data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* "other" is just like a host */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* a HOLD or a HASH must have a size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((size) && !(age & (HASH_ENTRY_DM | HOLD_ENTRY_DM)))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(sdbc_check_cctl_cot): inconsistent ccent %p "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "age %x size %d data %p", (void *)centry, age, size,
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 * 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 Fortesdbc_mark_cctl_cot(_sd_cctl_t *header, _sd_cctl_t *centry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the entire chain is guilty by association */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete((struct _sd_hash_hd *)cur_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm |= BAD_ENTRY_DM; /* this is the problem child */
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 * 0 on success, EINTR if inconsistency detected in centry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pickup a fresh copy - has the world changed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_max_dyn_list = dynmem_processing_dm.max_dyn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try to recover from bad cctl */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_check_cot && !sdbc_check_cctl_cot(centry))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (1): /* chain to next/monitor for completion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no catagory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(setup_cot): "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "OTHER with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no prev entry (ie top of list) or no prev
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ELIGIBLE entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is an eligible entry, does it start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a list or is it a loner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "HOST with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* it starts a list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host catagory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start out with one page */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it's a loner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drop status to no category and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consistency check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "PARA with data/size %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* continue to grow the pest list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * offset of host ent mem this will pt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * up the host mem req by one for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this parasite
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * term this pest list - restart fresh
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on this entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* switch(cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (cl) */
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 * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if called with ALLOC_NOWAIT, caller must check for non-zero return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_setup_mem_chaining(_sd_cctl_t *header, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (1): /* chain to next/monitor for completion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The allocation failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HOST entry processing - save the anchor pt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc the memory,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The allocation failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARASITIC entry processing - setup w/no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory, setup head/next ptrs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fudge the data mem ptr to an offset from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the anchor alloc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* chain prev to this */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * generate the actual data ptr into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host entry memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* switch(cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (cl) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_check_buffer_alloc - Check if buffer allocation is invalid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if its ok to continue with allocation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else errno to be returned to the user.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine could block if the device is not local and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * recovery is in progress.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_check_buffer_alloc(int cd, nsc_off_t fba_pos, nsc_size_t fba_len,
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.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_check_buffer_alloc) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cd %d invalid handle %p flags %x",
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",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_check_buffer_alloc) cd %d is not attached", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_check_handle -- check that handle is valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 1 if ok, 0 otherwise (if debug then panic).
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 * _sd_free_buf - Free the buffers allocated in _sd_alloc_buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - The handle allocated in _sd_alloc_buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Else errno.
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)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, 0);
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 _sd_queue_write(handle, handle->bh_fba_pos, handle->bh_fba_len);
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 SDTRACE(ST_EXIT|SDF_FREEBUF, cd, flen, fpos, 0, 0);
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 * a cache entry or possible NULL if ALLOC_NOWAIT set
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 Fortesdbc_get_dmchain(int cblocks, int *stall, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get it from the os if possible */
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 for (i = 0; i < cblocks; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "centry inuse on 0 q! %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "centry pageio on 0 q! %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* got a dmchain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove this chain from the 0 queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* look for a pre-allocated block of the requested size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->sq_inq != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tmp_dmchain = qhead->cc_next; tmp_dmchain != qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get a dmchain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the inuse and pageio bits
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put on MRU end of queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * spin block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nudge the deallocator, accelerate ageing
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 (void) (*stall)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* see if smaller request size is available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while (!cc_dmchain) */
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 (void) _sd_hash_delete((struct _sd_hash_hd *)cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_clear_dmchain(_sd_cctl_t *cc_ent_start, _sd_cctl_t *cc_ent_end)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * put a dmchain on the LRU end of a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_ins_dmqueue_front(_sd_queue_t *q, _sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * put a dmchain on the MRU end of a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_ins_dmqueue_back(_sd_queue_t *q, _sd_cctl_t *cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove dmchain from a queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_remq_dmchain(_sd_queue_t *q, _sd_cctl_t *cc_ent)
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 * 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 Fortesdbc_requeue_dmchain(_sd_queue_t *q, _sd_cctl_t *cc_ent, int mru,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_remq_dmchain() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_ins_dmqueue_back */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* put on LRU end of queue i.e. requeue to head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inline of sdbc_ins_dmqueue_front */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear the CC_QHEAD bit on all members of the chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tcent = cc_ent; tcent; tcent = tcent->cc_next_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_dmchain_dirty(cc_ent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return first dirty cc_ent in dmchain, NULL if chain is not dirty
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (/* CSTYLED */; cc_ent; cc_ent = cc_ent->cc_next_dm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_requeue_head_dm_try()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to requeue a dmchain to the head of the queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_requeue_dmchain(q, cc_ent, 0, 1); /* requeue head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc_blks -- allocate cache entries with memory
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 * A cache block chain or NULL if ALLOC_NOWAIT and request fails
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: caller must check for null return if called with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ALLOC_NOWAIT set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_alloc_blks(int cd, nsc_off_t cblk, nsc_size_t reqblks, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_centry_alloc(cd, cblk, reqblks, &stall,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FOUND_IN_HASH_DM|FOUND_HOLD_OVER_DM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reqblks || (_sd_setup_category_on_type(anchor))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is where the memory is actually allocated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_alloc - sdbc internal function to allocate a new cache block.
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 * A cache block, or possibly NULL if ALLOC_NOWAIT set .
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 * Note: caller must check for null return if called with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ALLOC_NOWAIT set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_alloc(int cd, nsc_off_t cblk, nsc_size_t req_blocks, int *stall,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry = sdbc_alloc_dmc(cd, cblk, req_blocks, stall, alloc_tok,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_alloc_dmc -- allocate a centry from a dmchain
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 * A cache block or possibly NULL if ALLOC_NOWAIT set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if dmchain is empty, allocate one.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_alloc_dmc(int cd, nsc_off_t cblk, nsc_size_t req_blocks, int *stall,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note - sdbc_get_dmchain() returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with cc_inuse and cc_pageio set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for all members of dmchain.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana sdbc_get_dmchain(req_blocks, stall, flag)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remember q it came from */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: dmchain pointer is advanced in sdbc_alloc_from_dmchain()
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 * sdbc_alloc_from_dmchain -- allocate centry from a dmchain of centrys
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 * A cache block or possibly NULL if ALLOC_NOWAIT set.
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 Fortesdbc_alloc_from_dmchain(int cd, nsc_off_t cblk, sdbc_allocbuf_t *alloc_tok,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_insert(cd, cblk, (struct _sd_hash_hd *)cc_ent,
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 if ((_sd_cctl_t *)_sd_hash_search(cd, cblk, _sd_htable)
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 /* _sd_centry_release(cc_ent); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * advance the dmchain pointer, but only if we got the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cc_ent from the dmchain
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDTRACE(ST_EXIT|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
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 * 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 sdbc_allocbuf_impl_t *dmc = (sdbc_allocbuf_impl_t *)alloc_tok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear bit after final reference */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a floater from the 0 queue, insert on q.
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 /* compute wastage stats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((chainpull >= 0) && (chainpull < max_dm_queues));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_alloc_lru - allocate a new cache block from the lru queue
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 * A cache block or NULL if ALLOC_NOWAIT specified
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 Fortesdbc_alloc_lru(int cd, nsc_off_t cblk, int *stall, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_tries = q->sq_inq / 100; /* only search 1% of q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_tries <= 0) /* ensure num_tries is non-zero */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ENT_ALLOC, cd, 0, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cc_ent = (qhead->cc_next); cc_ent != qhead; cc_ent = ccnext) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inlined requeue of the LRU. (should match _sd_requeue)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_centry_alloc %x prev %x next %x qp %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * End inlined requeue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_hash_delete((struct _sd_hash_hd *)cc_ent,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_hash_insert(cd, cblk, (struct _sd_hash_hd *)cc_ent,
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 _sd_hash_search(cd, cblk, _sd_htable) != old_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_INFO|SDF_ENT_ALLOC, cd, ++tries, BLK_TO_FBA_NUM(cblk), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) (*stall)++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_centry_init_dm - setup the cache block for dynamic memory allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Cache block.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is the central point in which cache entry blocks are setup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* an entry already setup - don't touch simply refresh age */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte centry->cc_aging_dm &= ~(FINAL_AGING_DM | CATAGORY_ENTRY_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 * sdbc_centry_memalloc_dm
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Actually allocate the cache memory, storing it in the cc_data field for
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 * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_centry_memalloc_dm(_sd_cctl_t *centry, int alloc_request, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep = (flag & ALLOC_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* host or other */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc((size_t)centry->cc_alloc_size_dm, sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cblocks = centry->cc_alloc_size_dm >> _sd_cblock_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the dmqueue index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put on appropriate queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for KM_NOSLEEP (should never happen with KM_SLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_centry_release - release a cache block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Cache block.
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 SDTRACE(ST_ENTER|SDF_ENT_FREE, CENTRY_CD(centry), 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSOP_DEALLOCRESOURCE(sdbc_safestore, wctl->sc_res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* see if this can be queued to head */
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 * 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 SDTRACE(ST_EXIT|SDF_ENT_FREE, CENTRY_CD(centry), 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* only clear inuse after final reference to centry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup to centry info associated with safestore resource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return pointer to the centry info structure
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (_sdbc_gl_centry_info_size / sizeof (ss_centry_info_t)) - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_alloc_write - Allocate a write block (for remote mirroring)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and set centry->cc_write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * centry - Head of Cache chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stall - pointer to stall count (no blocks avail)
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 if ((SSOP_ALLOCRESOURCE(sdbc_safestore, need, stall, &reslist))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = SSOP_GETRESOURCE(sdbc_safestore, &reslist, &res);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is bad and should not happen.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we use the saved reslist to cleanup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "bad resource list 0x%p"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "changing to forced write thru mode",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no safestore resources available. do sync write */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_read - Interface call to do read.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
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_sd_read(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
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 if (_sdbc_shutdown_in_progress || (handle->bh_flag & NSC_ABUF)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_read) handle %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!SDBC_VALID_BITS(st_cblk_off, st_cblk_len, cc_ent))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_RD, cc_ent, st_cblk_off, st_cblk_len);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)(BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)) + st_cblk_off),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana *(int64_t *)(cc_ent->cc_data + FBA_SIZE(st_cblk_off)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_READ_IO_KSTATS(handle->bh_cd, FBA_SIZE(fba_orig_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _sd_doread(handle, cc_ent, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_doread_prefetch - read ahead one cache block
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 * number of fbas, if any, that are to be read beyond (fba_pos + fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if readahead is to be done allocate a cache block and place
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the cc_chain of cc_ent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_doread_prefetch(_sd_cctl_t *cc_ent, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t next_cblk = FBA_TO_BLK_NUM(fba_pos + BLK_FBAS);
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 filesize = _sd_cache_files[cd].cd_info->sh_filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* readahead only for small reads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fba_len <= FBA_LEN(CACHE_BLOCK_SIZE)) && (fba_pos != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if prev block is in cache and next block is not,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then read ahead one block
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 /* if in cache don't readahead */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * indicate implicit prefetch
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * and mark for release in
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * _sd_read_complete()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_doread - Check if blocks in cache. If not completely true, do io.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE(from disk), or NSC_PENDING otherwise.
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_sd_doread(_sd_buf_handle_t *handle, _sd_cctl_t *cc_ent, nsc_off_t fba_pos,
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 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 SDTRACE(ST_ENTER|SDF_READ, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_len, fba_pos, flag, EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * adjust the position and length so that the entire cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * block is read in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first, adjust to beginning of cache block */
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 /* 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 -
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 :
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(_sd_doread_rfill, nsc_off_t, fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for small reads do 1-block readahead if previous block is in cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len += sdbc_doread_prefetch(cc_ent, fba_pos, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_bdl += (SDBC_LOOKUP_IOCOUNT(CENTRY_DIRTY(cc_temp)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_len, fba_pos, flag, E2BIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte want_bits = SDBC_GET_BITS(st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, st_cblk_off, st_cblk_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &cc_ent->cc_addr, 0, end_cblk_len);
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 _sd_read_complete(handle, fba_pos, fba_orig_len, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_READ, cd, fba_orig_len, fba_pos, flag, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_read_complete - Do whatever is necessary after a read io is done.
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 * 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_sd_read_complete(_sd_buf_handle_t *handle, nsc_off_t fba_pos,
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 *first_iocent; /* first buffer when processing prefetch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_iocent) != FBA_TO_BLK_NUM(fba_pos))
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);
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 *(int64_t *)(cc_iocent->cc_data + FBA_SIZE(st_cblk_off)),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_complete_data2, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_iocent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 4755485 release implicit prefetch buffers
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 * 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 * 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().
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE4(_sd_read_complete_data3, uint64_t,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (uint64_t)BLK_TO_FBA_NUM(CENTRY_BLK(cc_iocent)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_read_ea - End action for async reads.
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 * 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_sd_async_read_ea(blind_t xhandle, nsc_off_t fba_pos, nsc_size_t fba_len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_read_complete(handle, fba_pos, fba_len, error);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->bh_fba_len, handle->bh_fba_pos, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_write_ea - End action for async writes.
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 * 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/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_async_write_ea(blind_t xhandle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_cache_files[HANDLE_CD(handle)].cd_info->sh_failed = 1;
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 Forteupdate_dirty(_sd_cctl_t *cc_ent, sdbc_cblk_fba_t st_off, sdbc_cblk_fba_t st_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we are writing to an FBA that is still marked dirty,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * record a write cancellation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is a write to a block that was already dirty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_write - Interface call to commit part of handle.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_HIT (in cache), NSC_DONE (to disk) or NSC_PENDING otherwise.
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 * 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_sd_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
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 *cur_chain = NULL, *dirty_next = NULL;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana SDT_INV_CD, 0, SDT_INV_BL, handle->bh_flag, 0);
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 if (_SD_DELAY_QUEUE && (fba_len != handle->bh_fba_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!queue_only && _SD_FORCE_DISCONNECT(fba_len))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_WRITE, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
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 ret = _sd_sync_write(handle, fba_pos, fba_len, flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, st_cblk_off,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_TOFLUSH(st_cblk_off, st_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_SET_DIRTY(st_cblk_off, st_cblk_len, cc_ent);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DATA_LOG(SDF_WR, cc_ent, st_cblk_off, st_cblk_len);
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 *(int64_t *)(cc_ent->cc_data + FBA_SIZE(st_cblk_off)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, 0, BLK_FBAS)) {
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 cmn_err(CE_WARN, "!fba_len %" NSC_SZFMT " end_cblk_len %d in "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CENTRY_DIRTY(cc_ent) && update_dirty(cc_ent, 0,
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),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_enqueue_dirty(cd, cur_chain, dirty_next, num_queued);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_WRITE, cd, fba_len, fba_pos, flag, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_queue_write(handle, fba_pos, fba_len): Queues delayed writes for
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 * 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_sd_queue_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos = BLK_TO_FBA_NUM(CENTRY_BLK(cc_ent)); /* 1st block */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Full block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Partial block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else while (dirty) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we find a gap, write out what we've got
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flush_pos_valid && (flush_pos + flush_len) != fba_pos) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _sd_write(handle, flush_pos, flush_len, NSC_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_remote_store(_sd_cctl_t *cc_ent, nsc_off_t fba_pos, nsc_size_t fba_len)
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 if (_sd_nodes_configured <= 2 && _sd_is_mirror_down())
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_write) safe store failed. Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (SSOP_WRITE_CBLOCK(sdbc_safestore, ss_res, cc_ent->cc_data,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_write) safe store failed. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end while */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cc_ent->cc_data, FBA_SIZE(end_cblk_len), 0)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_write) nvmem dma failed. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Going synchronous");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_sync_write2 - Write-through function.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
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 * See _sd_copy_direct() for usage when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (wr_handle != rd_handle && rd_handle != NULL)
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 while (CENTRY_BLK(wr_ent) != FBA_TO_BLK_NUM(wr_st_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(rd_ent) != FBA_TO_BLK_NUM(rd_st_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wr_st_pos, FBA_TO_BLK_LEN(fba_len) + 2, B_WRITE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this_len = min((BLK_FBAS - rd_pos), (BLK_FBAS - wr_pos));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear dirty bits in the write handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * optimization for when we have a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * full cache block, or are doing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy_direct (see below).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update valid bits in the write handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doing copy_direct, so mark the write handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as invalid since the data is on disk, but not
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 *(int64_t *)(rd_ent->cc_data + FBA_SIZE(rd_pos)),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_add_fba(bp, &rd_ent->cc_addr, rd_pos, this_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (fba_len > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fn = (wr_handle->bh_flag & NSC_NOBLOCK) ? _sd_async_write_ea : NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = sd_start_io(bp, _sd_cache_files[cd].cd_strategy, fn, wr_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_sync_write(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_sd_sync_write2(handle, fba_pos, fba_len, flag, NULL, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_zero - Interface call to zero out a portion of cache blocks.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE or NSC_PENDING otherwise.
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_sd_zero(_sd_buf_handle_t *handle, nsc_off_t fba_pos, nsc_size_t fba_len,
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 */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_zero) handle %p not active",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle_active, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle_write, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_ZERO, cd, fba_len, fba_pos, flag, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent) != FBA_TO_BLK_NUM(fba_pos))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(cc_ent->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_ZERO, cd, fba_len, fba_pos, flag, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_copy - Copies portions of 2 handles.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE otherwise.
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_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 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 if (!_SD_HANDLE_ACTIVE(handle1) || !_SD_HANDLE_ACTIVE(handle2)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_copy) handle %p or %p not active",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(handle_active1, int, handle1->bh_flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle1, fba_pos1, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle2, fba_pos2, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent1) != FBA_TO_BLK_NUM(fba_pos1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (CENTRY_BLK(cc_ent2) != FBA_TO_BLK_NUM(fba_pos2))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (BLK_FBA_OFF(fba_pos1) != BLK_FBA_OFF(fba_pos2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Different offsets, do it slowly (per fba) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data+off1, cc_ent2->cc_data+off2,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_TO_BLK_NUM(fba_pos1) != CENTRY_BLK(cc_ent1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_TO_BLK_NUM(fba_pos2) != CENTRY_BLK(cc_ent2))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent2->cc_data + FBA_SIZE(st_cblk_off), FBA_SIZE(st_cblk_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cc_ent1->cc_data, cc_ent2->cc_data, CACHE_BLOCK_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_copy_direct - Copies data from one handle direct to another disk.
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 * errno if return > 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_DONE otherwise.
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_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 if (!_SD_HANDLE_ACTIVE(handle1) || !_SD_HANDLE_ACTIVE(handle2)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_copy_direct) handle %p or %p not active",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(handle_active2, int, handle1->bh_flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle1, fba_pos1, fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT_HANDLE_LIMITS(handle2, fba_pos2, fba_len);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_copy_direct) handle2 %p is not writeable",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(handle2_write, int, handle2->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_sync_write2(handle2, fba_pos2, fba_len, 0, handle1, fba_pos1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_enqueue_dirty - Enqueue a list of dirty buffers.
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 * 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_sd_enqueue_dirty(int cd, _sd_cctl_t *chain, _sd_cctl_t *cc_last, int numq)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!dirty_link set in enq %x fl %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cc_last) && (last_ent = cdi->cd_last_ent) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (CENTRY_BLK(chain) == (CENTRY_BLK(last_ent)+1)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_enqueue_dirty_chain - Enqueue a chain of a list of dirty buffers.
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 * 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.
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 /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Convert the 64 bit statistic structure to 32bit version.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Possibly losing information when cache is > 4gb. Ha!
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 * 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 _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 _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 _sd_cache_stats32->st_wlru_inq = _sd_cache_stats->st_wlru_inq;
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 * bcopy the shared stats which has nothing that needs conversion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(_sd_cache_stats->st_shared, _sd_cache_stats32->st_shared,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyout(_sd_cache_stats32, uptr, sizeof (_sd_stats32_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _MULTI_DATAMODEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copyout(&dummy32, uptr, sizeof (_sd_stats32_t)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (copyout(&dummy, uptr, sizeof (_sd_stats_t)))
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 sizeof (_sd_stats_t) + (sdbc_max_devs - 1) * sizeof (_sd_shared_t)))
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 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_sd_node_hint_caller(blind_t hint, int hint_action)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_set_node_hint((uint_t)(unsigned long)hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _sd_clear_node_hint((uint_t)(unsigned long)hint);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, SDT_INV_CD, 3, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, SDT_INV_CD, 3, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_ENTER|SDF_HINT, SDT_INV_CD, 4, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDTRACE(ST_EXIT|SDF_HINT, SDT_INV_CD, 4, SDT_INV_BL, hint, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_get_maxfbas(blind_t xcd, int flag, nsc_size_t *ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_control(blind_t xcd, int cmd, void *ptr, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nsc_control(cdi->cd_rawfd, cmd, ptr, len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_discard_pinned(blind_t xcd, nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!FILE_OPENED(cd)) || (!cdi->cd_info->sh_failed)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cblk < FBA_TO_BLK_LEN(fba_pos + fba_len); cblk++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_sd_cctl_t *)_sd_hash_search(cd, cblk, _sd_htable)) {
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 /* clear dirty bits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cc_ent->cc_flag &= ~(CC_QHEAD|CC_PEND_DIRTY|CC_PINNED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was FAST */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release cache block to head of LRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handle allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_handles_unload - cache is being unloaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_handles_load - cache is being unloaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_handle_list.hl_lock, NULL, MUTEX_DRIVER, NULL);
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 * _sdbc_handles_deconfigure - cache is being deconfigured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_alloc_handle(sdbc_callback_fn_t d_cb, sdbc_callback_fn_t r_cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = (_sd_buf_handle_t *)kmem_zalloc(sizeof (_sd_buf_handle_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* maintain list and count for debugging */
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 ASSERT(!(handle->bh_flag & (NSC_HALLOCATED | NSC_HACTIVE)));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc(_sd_free_handle) handle %p not valid",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!sdbc(_sd_free_handle) attempt to free active handle %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(free_handle_active, int, handle->bh_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove from queue before free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !(_SD_8K_BLKSIZE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* !(_SD_8K_BLKSIZE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int i, j, k;
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 _sd_lookup_map[i].mi_mask = SDBC_GET_BITS(stpos, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _SD_MAX_MAP; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; mask; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_lookup_map[i].mi_dirty_count = (unsigned char)j;
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 _sd_lookup_map[i].mi_io_count += SDBC_LOOKUP_DTCOUNT(mask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the SD_GET_CD_CLUSTER_DATA ioctl (get the global filename data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the SD_GET_CD_CLUSTER_SIZE ioctl (get size of global filename area)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SD_GET_GLMUL_SIZES ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get sizes of the global info regions (for this node only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SD_GET_GLMUL_INFO ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the global metadata for write blocks (for this node only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats = (sdbc_global_stats_t *)(ksp->ks_data);
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 sdbc_gstats->ci_sdbc_lru_blocks.value.ul = (ulong_t)_sd_lru_q.sq_inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_lru_req.value.ul = (ulong_t)_sd_lru_q.sq_req_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_num_shared.value.ul = (ulong_t)sdbc_max_devs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_gstats->ci_sdbc_nodehints.value.ul = (ulong_t)hint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats = (sdbc_cd_stats_t *)(ksp->ks_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shstats_vars = (_sd_shared_t *)(ksp->ks_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy tail of filename to kstat. leave 1 byte for null char */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name_len = (int)strlen(shstats_vars->sh_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strlcpy(sdbc_shstats->ci_sdbc_vol_name.value.c,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shstats_vars->sh_filename + name_len, KSTAT_DATA_CHAR_LEN);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Kstat error: no volume name associated "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "with cache descriptor");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_cd.value.ul = (ulong_t)shstats_vars->sh_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_shstats->ci_sdbc_numio.value.ul = (ulong_t)shstats_vars->sh_numio;
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 * cd_kstat_add
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
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!invalid cache descriptor: %d", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a regular kstat for this cache descriptor */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_kstats not allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(name, KSTAT_STRLEN, "%s%d", SDBC_KSTAT_CDSTATS, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd] = kstat_create(SDBC_KSTAT_MODULE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_kstats[cd]->ks_update = sdbc_cd_stats_update;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!cdstats %d kstat allocation failed", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create an I/O kstat for this cache descriptor */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_io_kstats not allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(name, KSTAT_STRLEN, "%s%d", SDBC_IOKSTAT_CDSTATS, cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_KSTAT_MODULE, cd, name, "disk", KSTAT_TYPE_IO, 1, 0);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc_cd_io_kstats_mutexes not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "allocated");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_cd_io_kstats[cd]->ks_lock = &sdbc_cd_io_kstats_mutexes[cd];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!sdbc cd %d io kstat allocation failed", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cd_kstat_remove
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
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!invalid cache descriptor: %d", cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete the regular kstat corresponding to this cache descriptor */
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 /* destroy the mutex associated with this I/O kstat */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat update
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem = (sdbc_dynmem_dm_t *)(ksp->ks_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* global dynmem_processing_dm */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte process_vars = (_dm_process_vars_t *)(ksp->ks_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte simplect_dm = sdbc_dynmem->ci_sdbc_simplect.value.ul;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sdbc_edit_xfer_process_vars_dm(&local_dm_process_vars);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (process_vars->process_directive & 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 /* default to READ */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_simplect.value.ul = simplect_dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt1.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_cache_aging_pcnt2.value.ul =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_dynmem->ci_sdbc_process_directive.value.ul =
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;