fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _RDC_DISKQ_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _RDC_DISKQ_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_HEADER_OFF 0 /* beginning of disk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_DATA_OFF FBA_LEN(1024) /* beginning of queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct qentry {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int magic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int type; /* special data ? io? bitmap? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos; /* position it will be in the rdc_aio_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t hpos; /* starting pos of orig nsc_buf_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t qpos; /* where this info is in the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len; /* len */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int iostatus;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t setid; /* krdc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} q_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef union io_dat {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q_data dat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char dummy[512];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} io_hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_IOHDR_MAGIC 0x494F4844 /* IOHD */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_IOHDR_DONE 0xDEADCAFE /* this q entry has been flushed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_IOHDR_WAITING 0xBEEFCAFE /* this q entry is waiting for ack */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QUEUEIO 0x02
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_MAGIC 0x44534B51
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_VER_ORIG 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_VER_64BIT 0x02
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_VERS RDC_DISKQ_VER_64BIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DISKQ_VERS RDC_DISKQ_VER_ORIG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct diskqheader1 {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int magic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int head_offset; /* offset of meta-info of head (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tail_offset; /* addr of next write (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int disk_size; /* allow growing ? (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long nitems; /* items */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long blocks; /* fbas */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qwrap; /* where the tail wrapped */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int auxqwrap; /* if the tail wraps again, before head wraps once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t seq_last; /* last sequence before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t ack_last; /* last ack before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} diskq_header1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct diskqheader2 {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int magic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t head_offset; /* offset of meta-info of head (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tail_offset; /* addr of next write (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t disk_size; /* allow growing ? (fbas) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t nitems; /* items */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t blocks; /* fbas */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t qwrap; /* where the tail wrapped */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t auxqwrap; /* if the tail wraps again, before head wraps once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t seq_last; /* last sequence before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t ack_last; /* last ack before suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} diskq_header2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef diskq_header2 diskq_header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _LP64
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DQFMT "lu"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DQFMT "llu"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef diskq_header1 diskq_header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DQFMT "ld"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef union headr {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq_header h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char dummy[512];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} dqheader;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* flags for the state field in the header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_SHUTDOWN_OK 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_SHUTDOWN_BAD 0x02
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QNXTIOWRAPD 0x04
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QHEADWRAPD 0x08
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAILBUSY 0x10 /* tell flusher not to grab, incomplete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QNOBLOCK 0x10000 /* can also be passed out by status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QBADRESUME 0x20 /* don't resume bit ref */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFULL 0x40 /* the queue is in a full delay loop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_STOPPINGFLUSH 0x80
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILLSTOP 0x01 /* diskq->memq flusher kill switch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILLSLEEP 0x02 /* explicit diskq->memq flusher sleep */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_MAX_DISKQREAD 0x1000 /* max 2 mb q read */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct diskqueue { /* the incore info about the diskq */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dqheader disk_hdr; /* info about the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long nitems_hwm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long blocks_hwm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long throttle_delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t last_tail; /* pos of the last tail write */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int inflbls; /* number of inflight blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int inflitems; /* number of inflight blocks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t disk_qlock; /* protects all things in diskq */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and all things in dqheader */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t head_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t busycv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int busycnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t nxt_io; /* flushers head pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int hdrcnt; /* number of io_hdrs on list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t coalesc_bounds; /* don't coalesce below this offset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *lastio; /* cached copy of the last write on q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *iohdrs; /* flushed, not ack'd on queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *hdr_last; /* tail of iohdr list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kcondvar_t qfullcv; /* block, queue is full */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} disk_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq macros (gets) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QHEAD(q) q->disk_hdr.h.head_offset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QNXTIO(q) q->nxt_io
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAIL(q) q->disk_hdr.h.tail_offset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QNITEMS(q) q->disk_hdr.h.nitems
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QBLOCKS(q) q->disk_hdr.h.blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QSTATE(q) q->disk_hdr.h.state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IS_QSTATE(q, s) (q->disk_hdr.h.state & s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QSIZE(q) q->disk_hdr.h.disk_size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QMAGIC(q) q->disk_hdr.h.magic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QVERS(q) q->disk_hdr.h.vers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QSEQ(q) q->disk_hdr.h.seq_last
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QACK(q) q->disk_hdr.h.ack_last
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QEMPTY(q) ((QTAIL(q) == QHEAD(q))&&(!(QNITEMS(q))))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QWRAP(q) q->disk_hdr.h.qwrap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define AUXQWRAP(q) q->disk_hdr.h.auxqwrap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LASTQTAIL(q) q->last_tail
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QCOALBOUNDS(q) q->coalesc_bounds
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq macros (sets) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QHEAD(q, n) q->disk_hdr.h.head_offset += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QNXTIO(q, n) q->nxt_io += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QNXTIO(q, n) q->nxt_io -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QHEAD(q, n) q->disk_hdr.h.head_offset -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QTAIL(q, n) q->disk_hdr.h.tail_offset += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QTAIL(q, n) q->disk_hdr.h.tail_offset -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QNITEMS(q, n) q->disk_hdr.h.nitems += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QNITEMS(q, n) q->disk_hdr.h.nitems -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define INC_QBLOCKS(q, n) q->disk_hdr.h.blocks += n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEC_QBLOCKS(q, n) q->disk_hdr.h.blocks -= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QMAGIC(q, n) q->disk_hdr.h.magic = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QSTATE(q, n) q->disk_hdr.h.state |= n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLR_QSTATE(q, n) q->disk_hdr.h.state &= ~n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QHEAD(q, n) q->disk_hdr.h.head_offset = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QNXTIO(q, n) q->nxt_io = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QHDRCNT(q, n) q->hdrcnt = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QTAIL(q, n) q->disk_hdr.h.tail_offset = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_LASTQTAIL(q, n) q->last_tail = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_LASTQWRITE(q, w) q->last_qwrite = w
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QSIZE(q, n) q->disk_hdr.h.disk_size = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QNITEMS(q, n) q->disk_hdr.h.nitems = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QBLOCKS(q, n) q->disk_hdr.h.blocks = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QWRAP(q, n) q->disk_hdr.h.qwrap = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLR_QWRAP(q) q->disk_hdr.h.qwrap = 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_AUXQWRAP(q, n) q->disk_hdr.h.auxqwrap = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CLR_AUXQWRAP(q) q->disk_hdr.h.auxqwrap = 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SET_QCOALBOUNDS(q, n) q->coalesc_bounds = n
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WRAPQTAIL(q) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QWRAP(q)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_AUXQWRAP(q, QTAIL(q)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QWRAP(q, QTAIL(q)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QTAIL(q, RDC_DISKQ_DATA_OFF); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DO_AUXQWRAP(q) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QWRAP(q, AUXQWRAP(q)); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_AUXQWRAP(q, 0); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* these can be wrapped by different threads, avoid the race */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WRAPQHEAD(q) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, QNXTIOWRAPD)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (AUXQWRAP(q)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DO_AUXQWRAP(q); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QWRAP(q, 0); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QNXTIOWRAPD); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, QHEADWRAPD); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QHEAD(q, RDC_DISKQ_DATA_OFF); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WRAPQNXTIO(q) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, QHEADWRAPD)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (AUXQWRAP(q)) { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DO_AUXQWRAP(q); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QWRAP(q, 0); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QHEADWRAPD); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, QNXTIOWRAPD); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, RDC_DISKQ_DATA_OFF); \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DQEND(q) (QWRAP(q)?QWRAP(q):QSIZE(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FITSONQ(q, n) \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((QBLOCKS(q)+QNITEMS(q)+RDC_DISKQ_DATA_OFF+n) >= \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint64_t)DQEND(q))?0:1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* diskq defines/macros (non-specific) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_NOLOG 0x00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_WAIT 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_NOWAIT 0x02
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_DOLOG 0x04 /* put the group into logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_NOFAIL 0x08 /* don't fail the queue, just init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_GROUP_LOCKED 0x10 /* trust me, I have the group lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_WRITTEN 0x10 /* data has been commited to queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_LAST 0x20 /* end of dequeued buffer, discard */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_BETWEEN(a,b,c) (a<b?((c>=a)&&(c<=b)):((a!=b)&&((c<b)||(c>=a))))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QHEADSHLDWRAP(q) (QWRAP(q) && (QHEAD(q) >= QWRAP(q)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QNXTIOSHLDWRAP(q) (QWRAP(q) && (QNXTIO(q) >= QWRAP(q)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAILSHLDWRAP(q, size) (QTAIL(q) + size > QSIZE(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QCOALESCEOK(q, dec) ((q->lastio->iostatus & RDC_WRITTEN) && \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((QTAIL(q) > QNXTIO(q)) ? \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((QTAIL(q) - dec) > QNXTIO(q)) && ((QTAIL(q) - dec) > \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QCOALBOUNDS(q))):\
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (QNXTIOSHLDWRAP(q) && QTAIL(q) > RDC_DISKQ_DATA_OFF)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QLOCK(q) &q->disk_qlock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QTAILLOCK(q) &q->tail_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QHEADLOCK(q) &q->head_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QDISPLAY(q) "qmagic: %x qvers: %d qstate: %x qhead: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " qnxtio: %" NSC_SZFMT " qtail: %" NSC_SZFMT " qtaillast: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " qsize: %" NSC_SZFMT " qnitems: %" RDC_DQFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " qblocks: %" RDC_DQFMT " coalbounds %" NSC_SZFMT, QMAGIC(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QVERS(q), QSTATE(q), QHEAD(q), QNXTIO(q), QTAIL(q), LASTQTAIL(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QSIZE(q), QNITEMS(q), QBLOCKS(q), QCOALBOUNDS(q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define QDISPLAYND(q) "m: %x v: %d s: %d h: %" NSC_SZFMT " n: %" \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " t: %" NSC_SZFMT " l: %" NSC_SZFMT " z: %" NSC_SZFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " i: %" RDC_DQFMT " b: %" RDC_DQFMT " w: %" NSC_SZFMT \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " a: %" NSC_SZFMT, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QMAGIC(q), QVERS(q), QSTATE(q), QHEAD(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QNXTIO(q), QTAIL(q), LASTQTAIL(q), QSIZE(q), QNITEMS(q), \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QBLOCKS(q), QWRAP(q), AUXQWRAP(q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Disk queue flusher state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILL_AWAKE (0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILL_ASLEEP (1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_QFILL_DEAD (-1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* functions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_add_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_rem_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_kill_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_init_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_lookup_diskq(char *path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_diskq_inuse(rdc_set_t *set, char *diskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_dump_iohdrs(disk_queue *q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void rdc_fixlen(rdc_aio_t *aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _RDC_DISKQ_H */