fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../solaris/nsc_thread.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../contract.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h> /* dtrace is S10 or later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_bitmap.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_diskq.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_clnt.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_k.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_io_t *_rdc_io_hc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_diskq_coalesce = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_rsrv_diskq(rdc_group_t *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->diskqfd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((group->diskqrsrv == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rc = nsc_reserve(group->diskqfd, 0)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc: nsc_reserve(%s) failed %d\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_pathname(group->diskqfd), rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->diskqrsrv++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_rlse_diskq(rdc_group_t *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->diskqrsrv > 0 && --group->diskqrsrv == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(group->diskqfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_wait_qbusy(disk_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(q)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (q->busycnt > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&q->busycv, QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_set_qbusy(disk_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(q)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->busycnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clr_qbusy(disk_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(q)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->busycnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->busycnt == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->busycv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_diskq(char *pathname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->disk_queue,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_unintercept_diskq(rdc_group_t *grp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(grp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->q_tok)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_unregister_path(grp->q_tok, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->q_tok = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_close_diskq(rdc_group_t *grp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_close_diskq: NULL group!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->diskqfd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsc_close(grp->diskqfd) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsc_close on diskq failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*EMPTY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->diskqfd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->diskqrsrv = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&grp->diskq.disk_hdr, sizeof (diskq_header));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_open the diskq and attach
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the nsc_fd to krdc->diskqfd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_open_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *diskqname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mutexheld = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&grp->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutexheld++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (&urdc->disk_queue[0] == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskqname = &urdc->disk_queue[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->diskqfd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->diskqfd = nsc_open(diskqname,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_RDCHR_ID|NSC_DEVICE|NSC_WRITE, 0, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->diskqfd == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_open_diskq: Unable to open %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskqname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!grp->q_tok)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->q_tok = nsc_register_path(urdc->disk_queue,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_DEVICE | NSC_CACHE, _rdc_io_hc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->diskqrsrv = 0; /* init reserve count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&grp->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutexheld--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* just test a reserve release */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _rdc_rsrv_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(sts)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_open_diskq: Reserve failed for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskqname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = nsc_partsize(grp->diskqfd, &size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sts == 0) && (size < 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&urdc->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mutexheld)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&grp->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_count_vecs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * simply vec++'s until sb_addr is null
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns number of vectors encountered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_count_vecs(nsc_vec_t *vec)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vecp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp = vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (vecp->sv_addr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (i+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_setid2idx
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * given setid, return index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_setid2idx(int setid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_u_info[index].setid == setid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_idx2setid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * given an index, return its setid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_idx2setid(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc_u_info[index].setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_fill_ioheader
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fill in all the stuff you want to save on disk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at the beginnig of each queued write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_fill_ioheader(rdc_aio_t *aio, io_hdr *hd, int qpos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_k_info[aio->index].group->diskq.disk_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.magic = RDC_IOHDR_MAGIC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.type = RDC_QUEUEIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.pos = aio->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.hpos = aio->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.qpos = qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.len = aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.flag = aio->flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.iostatus = aio->iostatus;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.setid = rdc_idx2setid(aio->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.time = nsc_time();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hd->dat.flag |= RDC_NULL_BUF; /* no real data to queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_dump_iohdrs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * give back the iohdr list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and clear out q->lastio
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dump_iohdrs(disk_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *p, *r;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(q)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = q->iohdrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte r = p->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(p, sizeof (*p));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdrcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = r;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->iohdrs = q->hdr_last = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdrcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->lastio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(q->lastio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&(*q->lastio), sizeof (*q->lastio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_fail_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set flags, throw away q info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clean up what you can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for flusher threads to stop (taking into account this may be one)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * takes group_lock, so conf, many, and bitmap may not be held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_fail_diskq(rdc_k_info_t *krdc, int wait, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(q, RDC_DISKQ_FAILED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(flag & RDC_NOFAIL))
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s failure", q->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & RDC_DOLOG) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc, RDC_NOFLUSH | RDC_ALLREMOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "disk queue failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * quick stop of the flushers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * other cleanup is done on the un-failing of the diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QHEAD(dq, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QTAIL(dq, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(dq, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(krdc->bitmap_ref, krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & RDC_DOLOG) /* otherwise, we already have the conf lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (!(flag & RDC_GROUP_LOCKED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(flag & RDC_NOFAIL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(q, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(flag & RDC_NOFAIL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(q, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(p->bitmap_ref, p->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RDC_QUEUING is cleared in group_log() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & RDC_DOLOG)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* can't wait for myself to go away, I'm a flusher */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wait & RDC_WAIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (group->rdc_thrnum)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_stamp_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * write out diskq header info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must have disk_qlock held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if rsrvd flag is 0, the nsc_reserve is done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_stamp_diskq(rdc_k_info_t *krdc, int rsrvd, int failflags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t vec[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *head = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&q->disk_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rsrvd && _rdc_rsrv_diskq(grp)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_stamp_diskq: %s reserve failed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, failflags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = NSC_WRITE | NSC_NOCACHE | NSC_NODATA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(grp->diskqfd, 0, 1, flags, &head);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Alloc buf failed for disk queue %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, failflags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[0].sv_len = FBA_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[0].sv_addr = (uchar_t *)&q->disk_hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[1].sv_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[1].sv_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte head->sb_vec = &vec[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_stamp_diskq: hdr: %p magic: %x state: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%x head: %d tail: %d size: %d nitems: %d blocks: %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q, QMAGIC(q), QSTATE(q), QHEAD(q),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte QTAIL(q), QSIZE(q), QNITEMS(q), QBLOCKS(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_write(head, 0, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rsrvd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_CONT, "!disk queue %s failed rc %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0], rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, failflags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(head);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rsrvd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_init_diskq_header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * load initial values into the header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_init_diskq_header(rdc_group_t *grp, dqheader *header)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int type = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &grp->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(q)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save q type if this is a failure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QSTATE(q) & RDC_QNOBLOCK)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte type = RDC_QNOBLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(header, sizeof (*header));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.magic = RDC_DISKQ_MAGIC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.vers = RDC_DISKQ_VERS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.state |= (RDC_SHUTDOWN_BAD|type); /* SHUTDOWN_OK on suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.head_offset = RDC_DISKQ_DATA_OFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.tail_offset = RDC_DISKQ_DATA_OFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.nitems = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.blocks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->h.qwrap = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(q, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* do this last, as this might be a failure. get the kernel state ok */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!init_diskq_hdr: Reserve failed for queue");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_partsize(grp->diskqfd, &header->h.disk_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_unfail_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the diskq failed for some reason, lets try and re-start it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the old stuff has already been thrown away
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * should just be called from rdc_sync
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_unfail_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* someone else won the race... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(q, RDC_DISKQ_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(q, RDC_QUEUING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(q, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* real i/o to the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear RDC_AUXSYNCIP because we cannot halt a sync that's not here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->aux_state &= ~RDC_AUXSYNCIP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_stamp_diskq(krdc, 0, RDC_GROUP_LOCKED | RDC_DOLOG) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QHDRCNT(dq, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(dq, RDC_SHUTDOWN_BAD); /* only suspend can write good */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq->iohdrs = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq->hdr_last = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should be none, but.. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->aux_state |= RDC_AUXSYNCIP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_read_diskq_header(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq_header *header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->diskqfd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(buf, NSC_MAXPATH, "%s:%s", urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->secondary.intf[0]);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Disk Queue Header read failed for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->group_name[0] == '\0' ? buf:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->group_name[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header = &krdc->group->diskq.disk_hdr.h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_rsrv_diskq(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_ns_io(krdc->group->diskqfd, NSC_RDBUF, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)header, sizeof (diskq_header));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(buf, NSC_MAXPATH, "%s:%s", urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->secondary.file[0]);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Disk Queue Header read failed(%d) for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc, &urdc->group_name[0] == '\0' ? buf :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->group_name[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_stop_diskq_flusher
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_stop_diskq_flusher(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue q, *qp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!stopping flusher threads");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qp = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save the queue info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = *qp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lie a little */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QTAIL(qp, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QHEAD(qp, RDC_DISKQ_DATA_OFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(qp, RDC_QDISABLEPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(qp, RDC_STOPPINGFLUSH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* drop locks to allow flushers to die */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (group->rdc_thrnum)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(qp, RDC_STOPPINGFLUSH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *qp = q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_enable_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * open the diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stamp the header onto it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_enable_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_diskq(krdc) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_stamp_diskq(krdc, 0, RDC_NOLOG) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* caller has to fail diskq after dropping conf & many locks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQNOADD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_resume_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * open the diskq and read the header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_resume_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_diskq(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_read_diskq_header(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check diskq magic number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QMAGIC(q) != RDC_DISKQ_MAGIC) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to resume diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " incorrect magic number in header", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else switch (QVERS(q)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq_header1 h1; /* version 1 header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq_header *hc; /* current header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_DISKQ_VER_ORIG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* version 1 diskq header, upgrade to 64bit version */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h1 = *(diskq_header1 *)(&group->diskq.disk_hdr.h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc = &group->diskq.disk_hdr.h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: old version header for diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " upgrading to current version", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->vers = RDC_DISKQ_VERS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->state = h1.state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->head_offset = h1.head_offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->tail_offset = h1.tail_offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->disk_size = h1.disk_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->nitems = h1.nitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->blocks = h1.blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->qwrap = h1.qwrap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->auxqwrap = h1.auxqwrap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->seq_last = h1.seq_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hc->ack_last = h1.ack_last;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hc->nitems > 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to resume diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " old version Q contains data", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_DISKQ_VER_64BIT:
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to resume diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " diskq header newer than current version",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_DISKQ_VERS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* okay, current version diskq */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to resume diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " unknown diskq header version", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, RDC_SHUTDOWN_BAD)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to resume diskq %s,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " unsafe shutdown", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QBADRESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, RDC_SHUTDOWN_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_SHUTDOWN_BAD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* bad, until proven not bad */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_stamp_diskq(krdc, 0, RDC_NOLOG) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, RDC_NOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->diskq.nitems_hwm = QNITEMS(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->diskq.blocks_hwm = QBLOCKS(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_resume_diskq: resuming diskq %s \n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!qinfo: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* caller has to set the diskq failed after dropping it's locks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_suspend_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* grab both diskq locks as we are going to kill the flusher */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((krdc->group->rdc_thrnum) && (!IS_QSTATE(q, RDC_STOPPINGFLUSH))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_STOPPINGFLUSH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_stop_diskq_flusher(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, RDC_STOPPINGFLUSH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->diskq.disk_hdr.h.state &= ~RDC_SHUTDOWN_BAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->diskq.disk_hdr.h.state |= RDC_SHUTDOWN_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->diskq.disk_hdr.h.state &= ~RDC_QBADRESUME;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* let's make sure that the flusher has stopped.. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->rdc_thrnum) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->group->rdc_thrnum)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* write refcount to the bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = rdc_write_refcount(krdc)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!QEMPTY(q)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fill in diskq header info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->diskq.disk_hdr.h.state &= ~RDC_QDISABLEPEND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!suspending disk queue\n" QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* to avoid a possible deadlock, release in order, and reacquire */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->count > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail; /* just stamp on the last suspend */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc); /* in case this stamp fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_stamp_diskq(krdc, 0, RDC_NOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* diskq already failed if stamp failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy orig aio to copy, including the nsc_buf_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dup_aio(rdc_aio_t *orig, rdc_aio_t *copy)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(orig, copy, sizeof (*orig));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copy->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (orig->handle == NULL) /* no buf to alloc/copy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_abuf(orig->pos, orig->len, 0, &copy->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_dup_aio: alloc_buf failed (%d)", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_copy(orig->handle, copy->handle, orig->pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte orig->pos, orig->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(copy->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_dup_aio: copy buf failed (%d)", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_qfill_shldwakeup()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if the memory queue has filled, and the low water
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark has not been reached. 0 if diskq is empty.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 if less than low water mark
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * net_queue mutex is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_qfill_shldwakeup(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *nq = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&nq->net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->qfill_sleeping != RDC_QFILL_ASLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->qfflags & RDC_QFILLSTOP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->qfflags & RDC_QFILLSLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) || IS_STATE(urdc, RDC_SYNCING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((QNXTIO(dq) == QTAIL(dq)) && !IS_QSTATE(dq, RDC_QFULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->qfill_sleeping == RDC_QFILL_ASLEEP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->hwmhit) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->blocks <= RDC_LOW_QBLOCKS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nq->hwmhit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ_NOISY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Waking up diskq->memq flusher, flags 0x%x"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " idx: %d", rdc_get_vflags(urdc), urdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_diskq_enqueue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * enqueue one i/o to the diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after appending some metadata to the front
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_diskq_enqueue(rdc_k_info_t *krdc, rdc_aio_t *aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *bp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *qbuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *iohdr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int numvecs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j, rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t iofbas; /* len of io + io header len */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qtail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int delay_time = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int print_msg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_WRITER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is a thread that is blocking because the queue is full,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * don't try to set up this write until all is clear
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check before and after for logging or failed queue just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in case a thread was in flight while the queue was full,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and in the proccess of failing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (IS_QSTATE(q, RDC_QFULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_LOGGING) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&q->qfullcv, QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_LOGGING) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, QTAILBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we're only going to write the header to the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numvecs = 2; /* kmem_alloc io header + null terminate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iofbas = FBA_LEN(sizeof (io_hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find out how many vecs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numvecs = rdc_count_vecs(aio->handle->sb_vec) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iofbas = aio->len + FBA_LEN(sizeof (io_hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this, in conjunction with QTAILBUSY, will prevent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * premature dequeuing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, QTAIL(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iohdr = (io_hdr *) kmem_zalloc(sizeof (io_hdr), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = (nsc_vec_t *) kmem_zalloc(sizeof (nsc_vec_t) * numvecs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!vec || !iohdr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!vec) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!vec kmem alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!iohdr kmem alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vec)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vec, sizeof (*vec));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iohdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QTAILBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[numvecs - 1].sv_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[numvecs - 1].sv_addr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now add the write itself */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = aio->handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1, j = 0; bp && bp->sb_vec[j].sv_addr &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i < numvecs; i++, j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[i].sv_len = bp->sb_vec[j].sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[i].sv_addr = bp->sb_vec[j].sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for queue wrap, then check for overflow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_LOGGING) && !IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vec, sizeof (*vec) * numvecs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QTAILBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, RDC_QFULL)) { /* wakeup blocked threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, RDC_QFULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QTAILSHLDWRAP(q, iofbas)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just go back to the beginning of the disk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it's not worth the trouble breaking up the write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQWRAP
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!wrapping Q tail: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRAPQTAIL(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prepend the write's metadata
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fill_ioheader(aio, iohdr, QTAIL(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[0].sv_len = FBA_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec[0].sv_addr = (uchar_t *)iohdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for tail < head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(FITSONQ(q, iofbas))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * don't allow any more writes to start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(q, RDC_QFULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!group->rdc_writer) && !IS_STATE(urdc, RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(delay_time);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->throttle_delay += delay_time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay_time *= 2; /* fairly aggressive */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((retries >= 8) || (delay_time >= 256)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay_time = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (print_msg) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!enqueue: disk queue %s full",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_msg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!qinfo: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_CONT, "!qinfo: " QDISPLAYND(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this is a no-block queue, or this is a blocking
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue that is not flushing. reset and log
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((QSTATE(q) & RDC_QNOBLOCK) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_QUEUING)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: disk queue %s full and not flushing. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "giving up", &urdc->disk_queue[0]);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: %s:%s entering logging mode",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_DOLOG | RDC_NOFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vec, sizeof (*vec) * numvecs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QTAILBUSY | RDC_QFULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qtail = QTAIL(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_WRITER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead = QHEAD(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update tail pointer, nitems on queue and blocks on queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QTAIL(q, iofbas); /* increment tail over i/o size + ioheader size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QNITEMS(q, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increment counter for i/o blocks only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QBLOCKS(q, (iofbas - FBA_LEN(sizeof (io_hdr))));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QNITEMS(q) > q->nitems_hwm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems_hwm = QNITEMS(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QBLOCKS(q) > q->blocks_hwm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks_hwm = QBLOCKS(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, RDC_QFULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, RDC_QFULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat_waitq_enter(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_rsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_rsrv_diskq(group)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_enqueue: %s reserve failed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vec, sizeof (*vec) * numvecs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QTAILBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* XXX for now do this, but later pre-alloc handle in enable/resume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_alloc_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(group->diskqfd, qtail, iofbas,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_NOCACHE | NSC_WRITE | NSC_NODATA, &qbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_alloc_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s alloc failed(%d) %" NSC_SZFMT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0], rc, iofbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move vec and write to queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec = &vec[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_WRITER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!about to write to queue, qbuf: %p, qhead: %d, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "qtail: %d, len: %d contents: %c%c%c%c%c",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) qbuf, qhead, qtail, iofbas,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec[1].sv_addr[0],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec[1].sv_addr[1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec[1].sv_addr[2],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec[1].sv_addr[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec[1].sv_addr[4]);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_CONT, "!qinfo: " QDISPLAYND(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_diskq_nswrite_start, int, qtail, nsc_size_t, iofbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_write(qbuf, qtail, iofbas, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_diskq_nswrite_end, int, qtail, nsc_size_t, iofbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s write failed %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0], rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_LASTQTAIL(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(q, QTAILBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return what should be returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the aio is returned in _rdc_write after status is gathered.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qbuf->sb_vec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(qbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_rlse);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free the iohdr and the vecs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iohdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vec)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vec, sizeof (*vec) * numvecs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if no flusher running, start one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!krdc->group->rdc_writer) && !IS_STATE(urdc, RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * place this on the pending list of io_hdr's out for flushing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_add_iohdr(io_hdr *header, rdc_group_t *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* paranoia */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte header->dat.next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG /* AAAH! double flush!? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = q->iohdrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p->dat.qpos == header->dat.qpos) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!ADDING DUPLICATE HEADER %" NSC_SZFMT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->dat.qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(header, sizeof (*header));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = p->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->iohdrs == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->iohdrs = q->hdr_last = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdrcnt = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdr_last->dat.next = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdr_last = header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdrcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark an io header as flushed. If it is the qhead,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then update the qpointers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free the io_hdrs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called after the bitmap is cleared by flusher
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clr_iohdr(rdc_k_info_t *krdc, nsc_size_t qpos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *hp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(qpos >= 0); /* assertion to validate change for 64bit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qpos < 0) /* not a diskq offset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = p = q->iohdrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find outstanding io_hdr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (hp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp->dat.qpos == qpos) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = hp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = hp->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_BETWEEN(QHEAD(q), QNXTIO(q), qpos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!iohdr already cleared? "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "qpos %" NSC_SZFMT " cnt %d ", qpos, cnt);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Qinfo: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark it as flushed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp->dat.iostatus = RDC_IOHDR_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it is the head pointer, travel the list updating the queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pointers until the next unflushed is reached, freeing on the way.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (hp && (hp->dat.qpos == QHEAD(q)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (hp->dat.iostatus == RDC_IOHDR_DONE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!clr_iohdr info: magic %x type %d pos %d"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " qpos %d hpos %d len %d flag 0x%x iostatus %x setid %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp->dat.magic, hp->dat.type, hp->dat.pos, hp->dat.qpos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp->dat.hpos, hp->dat.len, hp->dat.flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp->dat.iostatus, hp->dat.setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp->dat.flag & RDC_NULL_BUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QHEAD(q, FBA_LEN(sizeof (io_hdr)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QHEAD(q, FBA_LEN(sizeof (io_hdr)) + hp->dat.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DEC_QBLOCKS(q, hp->dat.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DEC_QNITEMS(q, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QHEADSHLDWRAP(q)) { /* simple enough */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQWRAP
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!wrapping Q head: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRAPQHEAD(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get rid of the iohdr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp == q->iohdrs) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->iohdrs = hp->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(hp, sizeof (*hp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = q->iohdrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp == q->hdr_last)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdr_last = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->dat.next = hp->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(hp, sizeof (*hp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = p->dat.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->hdrcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QEMPTY(q) && !IS_QSTATE(q, RDC_QFULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(IS_QSTATE(q, RDC_QDISABLEPEND))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!clr_iohdr: diskq %s empty, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "resetting defaults", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &q->disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wakeup any blocked enqueue threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * put in whatever useful checks we can on the io header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_iohdr_ok(io_hdr *hdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hdr->dat.magic != RDC_IOHDR_MAGIC)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebad:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Bad io header magic %x type %d pos %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " hpos %" NSC_SZFMT " qpos %" NSC_SZFMT " len %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " flag %d iostatus %d setid %d", hdr->dat.magic,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr->dat.type, hdr->dat.pos, hdr->dat.hpos, hdr->dat.qpos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr->dat.len, hdr->dat.flag, hdr->dat.iostatus, hdr->dat.setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Bad io header retrieved");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_netqueue_insert()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add an item to a netqueue. No locks necessary as it should only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be used in a single threaded manor. If that changes, then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a lock or assertion should be done here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_netqueue_insert(rdc_aio_t *aio, net_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* paranoid check for bit set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CHECK_BIT(krdc, aio->pos, aio->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qhead == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = q->net_qtail = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail->next = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->nitems > q->nitems_hwm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems_hwm = q->nitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->blocks > q->blocks_hwm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems_hwm = q->blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_fill_aio(aio, hdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take the pertinent info from an io_hdr and stick it in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an aio, including seq number, abuf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_fill_aio(rdc_group_t *grp, rdc_aio_t *aio, io_hdr *hdr, nsc_buf_t *abuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hdr->dat.flag & RDC_NULL_BUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = abuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle = abuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->pos = hdr->dat.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qpos = hdr->dat.qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->len = hdr->dat.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->flag = hdr->dat.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((aio->index = rdc_setid2idx(hdr->dat.setid)) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&grp->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->ra_queue.qfflags & RDC_QFILLSLEEP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&grp->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->seq = RDC_NOSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abuf && aio->qhandle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte abuf->sb_user++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->seq = grp->seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp->seq < aio->seq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp->seq = RDC_NEWSEQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&grp->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr->dat.iostatus = aio->seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint maxaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint midaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint aveaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint totaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint buf2qcalls = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecalc_perbuf(int items)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (totaios_perbuf < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte midaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aveaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte totaios_perbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf2qcalls = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (items > maxaios_perbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxaios_perbuf = items;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte midaios_perbuf = maxaios_perbuf / 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte totaios_perbuf += items;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aveaios_perbuf = totaios_perbuf / buf2qcalls;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_discard_tmpq()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free up the passed temporary queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: no cv's or mutexes have been initialized
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_discard_tmpq(net_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (q->net_qhead) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = q->net_qhead->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->qhandle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle->sb_user--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->qhandle->sb_user == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fixlen(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->qhandle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(q, sizeof (*q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_diskq_buf2queue()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take a chunk of the diskq, parse it and assemble
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a chain of rdc_aio_t's.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * updates QNXTIO()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenet_queue *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_diskq_buf2queue(rdc_group_t *grp, nsc_buf_t **abuf, int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vecp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *vaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *ioaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *netq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *hdr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *buf = *abuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &grp->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *nq = &grp->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nullbuf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t endobuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t bufoff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long bufcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nullblocks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fail = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netq = kmem_zalloc(sizeof (*netq), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netq == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: unable to allocate net queue");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp = buf->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vlen = vecp->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vaddr = vecp->sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufoff = buf->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte endobuf = bufoff + buf->sb_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!BUFFOFFENTER %d", bufoff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!BUFFOFF_0 %d", bufoff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vaddr == NULL) || (vlen == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vlen <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vaddr = vecp->sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vlen = vecp->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vaddr == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the iohdr information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr = kmem_zalloc(sizeof (*hdr), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hdr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!SNDR: unable to alocate net queue header");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioaddr = (uchar_t *)hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(vaddr, ioaddr, sizeof (*hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_iohdr_ok(hdr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!unable to retrieve i/o data from queue %s "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "at offset %" NSC_SZFMT " bp: %" NSC_SZFMT " bl: %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT, urdc->disk_queue,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufoff, buf->sb_pos, buf->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!FAILING QUEUE state: %x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_vflags(urdc));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!qinfo: " QDISPLAY(dq));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!VADDR %p, IOADDR %p", vaddr, ioaddr);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!BUF %p", buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!qinfo: " QDISPLAYND(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nullbuf = hdr->dat.flag & RDC_NULL_BUF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufoff += FBA_NUM(sizeof (*hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* out of buffer, set nxtio to re read this last hdr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nullbuf && ((bufoff + hdr->dat.len) > endobuf)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufcnt += FBA_NUM(sizeof (*hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = kmem_zalloc(sizeof (*aio), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufcnt -= FBA_NUM(sizeof (*hdr));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: net queue aio alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nullbuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move to next iohdr in big buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufoff += hdr->dat.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufcnt += hdr->dat.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fill_aio(grp, aio, hdr, buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->index < 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Set id %d not found or no longer "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "enabled, failing disk queue", hdr->dat.setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->seq == RDC_NOSEQ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nullblocks += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_add_iohdr(hdr, grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr = NULL; /* don't accidentally free on break or fail */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_netqueue_insert(aio, netq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no more buffer, skip the below logic */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bufoff + FBA_NUM(sizeof (*hdr))) >= endobuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos = bufoff - buf->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp = buf->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; fpos >= FBA_NUM(vecp->sv_len); vecp++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos -= FBA_NUM(vecp->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vlen = vecp->sv_len - FBA_SIZE(fpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vaddr = vecp->sv_addr + FBA_SIZE(fpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* abuf = NULL; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free extraneous header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hdr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(hdr, sizeof (*hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * probably won't happen, but if we didn't goto fail, but
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we don't contain anything meaningful.. return NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and let the flusher or the sleep/wakeup routines
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * decide
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netq && netq->nitems == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netq, sizeof (*netq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf2qcalls++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte calc_perbuf(netq->nitems);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nq->qfflags & RDC_QFILLSLEEP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QNXTIO(dq, bufcnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netq->net_qtail->orig_len = nullblocks; /* overload */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (netq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hdr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(hdr, sizeof (*hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netq->nitems > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the never can happen case ... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((netq->nitems == 1) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (netq->net_qhead->handle == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *abuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_discard_tmpq(netq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fail) { /* real failure, not just state change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_diskq_buf2queue: failing disk queue %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_diskq_unqueue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove one chunk from the diskq belonging to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_k_info[index]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * updates the head and tail pointers in the disk header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but does not write. The header should be written on ack
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flusher should free whatever..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_diskq_unqueue(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, rc1, rc2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nullhandle = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_hdr *iohdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *abuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->diskqfd == NULL) /* we've been disabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = kmem_zalloc(sizeof (*aio), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!aio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iohdr = kmem_zalloc(sizeof (*iohdr), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!iohdr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_qbusy(q); /* make sure no one disables the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_rsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_rsrv_diskq(group)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_unqueue: %s reserve failed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED) || IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QNXTIOSHLDWRAP(q)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQWRAP
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!wrapping Q nxtio: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRAPQNXTIO(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read the metainfo at q->nxt_io first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QNXTIO(q) == QTAIL(q)) { /* empty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->lastio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(q->lastio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&(*q->lastio), sizeof (*q->lastio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead = QNXTIO(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * have to drop the lock here, sigh. Cannot block incoming io
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we have to wait until after this read to find out how
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * much to increment QNXTIO. Might as well grab the seq then too
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((qhead == LASTQTAIL(q)) && (IS_QSTATE(q, QTAILBUSY))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Qtail busy delay lastqtail: %d", qhead);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_iohdr_read_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_ns_io(group->diskqfd, NSC_READ, qhead,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)iohdr, FBA_SIZE(1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_iohdr_read_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc) || !rdc_iohdr_ok(iohdr)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!unable to retrieve i/o data from queue %s"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " at offset %" NSC_SZFMT " rc %d", urdc->disk_queue,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qhead, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!qinfo: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* XXX process buffer here, creating rdc_aio_t's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update the next pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iohdr->dat.flag == RDC_NULL_BUF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QNXTIO(q, FBA_LEN(sizeof (io_hdr)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nullhandle = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INC_QNXTIO(q, (FBA_LEN(sizeof (io_hdr)) + iohdr->dat.len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->seq = group->seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->seq < aio->seq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = &iohdr->dat;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!unqueued iohdr from %d pos: %d len: %d flag: %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iostatus: %d setid: %d time: %d", qhead, p->pos, p->len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->flag, p->iostatus, p->setid, p->time);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nullhandle) /* nothing to get from queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto nullbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now that we know how much to get (iohdr.dat.len), get it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_allocbuf1_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(group->diskqfd, qhead + 1, iohdr->dat.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_NOCACHE | NSC_READ, &buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_allocbuf1_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and get somewhere to keep it for a bit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_allocbuf2_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc1 = nsc_alloc_abuf(qhead + 1, iohdr->dat.len, 0, &abuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_allocbuf2_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc) || !RDC_SUCCESS(rc1)) { /* uh-oh */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s read failure",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move it on over... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc2 = nsc_copy(buf, abuf, qhead + 1, qhead + 1, iohdr->dat.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsc_copy failed for diskq unqueue");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* let go of the real buf, we've got the abuf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = abuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Hack in the original sb_pos */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_pos = iohdr->dat.hpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* skip the RDC_HANDLE_LIMITS check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte abuf->sb_user |= RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenullbuf:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nullhandle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set up the rest of the aio values, seq set above ... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->pos = iohdr->dat.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qpos = iohdr->dat.qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->len = iohdr->dat.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->flag = iohdr->dat.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->index = rdc_setid2idx(iohdr->dat.setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->index < 0) { /* uh-oh */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_diskq_unqueue: index < 0");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE_STAMP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h = &q->disk_hdr.h;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!stamping diskq header:\n"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "magic: %x\nstate: %d\nhead_offset: %d\n"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "tail_offset: %d\ndisk_size: %d\nnitems: %d\nblocks: %d\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->magic, h->state, h->head_offset, h->tail_offset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->disk_size, h->nitems, h->blocks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_unq_rlse);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iohdr->dat.iostatus = aio->seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_add_iohdr(iohdr, group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nullhandle) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!UNQUEUING, %p"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " contents: %c%c%c%c%c pos: %d len: %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)aio->handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_vec[0].sv_addr[0],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_vec[0].sv_addr[1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_vec[0].sv_addr[2],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_vec[0].sv_addr[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_vec[0].sv_addr[4],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_pos, aio->handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!UNQUEUING, NULL " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!qinfo: " QDISPLAY(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iohdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iohdr, sizeof (*iohdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(abuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!diskq_unqueue: failing diskq");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_diskq_inuse(rdc_set_t *set, char *diskq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = set->group_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_lookup_bitmap(diskq) >= 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_lookup_configured(diskq) >= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* same diskq different group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(urdc->disk_queue, diskq) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (urdc->group_name[0] == '\0' ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(urdc->group_name, group))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last, but not least, lets see if someone is getting really funky */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(set->disk_queue, set->primary.file) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(set->disk_queue, set->primary.bitmap) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint maxlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint avelen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint totalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint lencalls = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteupdate_lenstats(int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lencalls == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lencalls = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte avelen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte totalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > maxlen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxlen = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte totalen += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte avelen = totalen / lencalls;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_calc_len()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns the size of the diskq that can be read for dequeuing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * always <= RDC_MAX_DISKQREAD
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_calc_len(rdc_k_info_t *krdc, disk_queue *dq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(QLOCK(dq)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---H-----N-----T--- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QNXTIO(dq) < QTAIL(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(RDC_MAX_DISKQREAD, QTAIL(dq) - QNXTIO(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---T-----H-----N--- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (QNXTIO(dq) > QTAIL(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QWRAP(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(RDC_MAX_DISKQREAD, QWRAP(dq) - QNXTIO(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* should never happen */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(RDC_MAX_DISKQREAD, QSIZE(dq) - QNXTIO(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (QNXTIO(dq) == QTAIL(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QWRAP(dq) && !IS_QSTATE(dq, QNXTIOWRAPD))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(RDC_MAX_DISKQREAD, QWRAP(dq) - QNXTIO(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(len, krdc->maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lencalls++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update_lenstats(len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((int)len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lie a little if we can, so we don't get tied up in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_wait_dbuf() on the next read. sb_len MUST be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * restored before nsc_free_buf() however, or we will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be looking at memory leak city..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so update the entire queue with the info as well
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the one that ends up freeing it, can fix the len
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IMPORTANT: This assumes that we are not cached, in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3.2 caching was turned off for data volumes, if that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * changes, then this must too
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_trim_buf(nsc_buf_t *buf, net_queue *q)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf == NULL || q == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q && (buf->sb_len >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->blocks + q->nitems - q->net_qtail->orig_len))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = buf->sb_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf->sb_len = (q->blocks + q->nitems - q->net_qtail->orig_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->orig_len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = p->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_read_diskq_buf()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * read a large as possible chunk of the diskq into a nsc_buf_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and convert it to a net_queue of rdc_aio_t's to be appended
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the group's netqueue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenet_queue *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_read_diskq_buf(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *tmpnq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *nq = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fail = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group == NULL || group->diskqfd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_read_diskq_buf_bail1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_qbusy(dq); /* prevent disables on the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_rsrv_diskq(group)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_readdiskqbuf: %s reserve failed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(dq); /* prevent disables on the queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_STATE(urdc, RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_read_diskq_buf_bail2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * real corner case here, we need to let the flusher wrap first.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we've gotten too far ahead, so just delay and try again
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(dq, QNXTIOWRAPD) && AUXQWRAP(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (QNXTIOSHLDWRAP(dq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQWRAP
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!wrapping Q nxtio: " QDISPLAY(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WRAPQNXTIO(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read the metainfo at q->nxt_io first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!QNITEMS(dq)) { /* empty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dq->lastio->handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(dq->lastio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&(*dq->lastio), sizeof (*dq->lastio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_read_diskq_buf_bail3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = rdc_calc_len(krdc, dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((len <= 0) || (IS_STATE(urdc, RDC_LOGGING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_DISKQ_FAILED)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a write could be trying to get on the queue, or if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the queue is really really small, a complete image
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of it could be on the net queue waiting for flush.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the latter being a fairly stupid scenario and a gross
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * misconfiguration.. but what the heck, why make the thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * thrash around.. just pause a little here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(50);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE3(rdc_read_diskq_buf_bail4, int, len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, rdc_get_vflags(urdc), int, nq->qfflags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_calc_len, int, len, int, (int)QNXTIO(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!CALC_LEN(%d) h:%d n%d t%d, w%d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len, QHEAD(dq), QNXTIO(dq), QTAIL(dq), QWRAP(dq));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_CONT, "!qinfo: " QDISPLAYND(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(dq, QNXTIO(dq) + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((LASTQTAIL(dq) > 0) && !QWRAP(dq) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((QNXTIO(dq) + len) >= LASTQTAIL(dq)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_QSTATE(dq, QTAILBUSY))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Qtail busy delay nxtio %d len %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "lastqtail: %d", QNXTIO(dq), len, LASTQTAIL(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(20);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset = QNXTIO(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one last check to see if we have gone logging, or should.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we may have released the mutex above, so check again
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((IS_STATE(urdc, RDC_LOGGING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_DISKQ_FAILED)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QHEADLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_buf2q_preread, int, offset, int, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(group->diskqfd, offset, len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_NOCACHE | NSC_READ, &buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s read failure pos %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " len %d", urdc->disk_queue, QNXTIO(dq), len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fail++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_read_diskq_buf_bail5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_buf2q_postread, int, offset, nsc_size_t, buf->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * convert buf to a net_queue. buf2queue will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update the QNXTIO pointer for us, based on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the last readable queue item
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpnq = rdc_diskq_buf2queue(group, &buf, index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_FLUSHER_UBERNOISE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!QBUF p: %d l: %d p+l: %d users: %d qblocks: %d ",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "qitems: %d WASTED: %d", buf->sb_pos, buf->sb_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf->sb_pos+buf->sb_len, buf->sb_user, tmpnq?tmpnq->blocks:-1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpnq?tmpnq->nitems:-1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpnq?((buf->sb_len-tmpnq->nitems) - tmpnq->blocks):-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE3(rdc_buf2que_returned, net_queue *, tmpnq?tmpnq:0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint64_t, tmpnq?tmpnq->nitems:0,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uint_t, tmpnq?tmpnq->net_qhead->seq:0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we don't need to retain the buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmpnq == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_trim_buf(buf, tmpnq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_qbusy(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_NOWAIT, RDC_DOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpnq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (tmpnq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_dequeue()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removes the head of the memory queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dequeue(rdc_k_info_t *krdc, int *rc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (q->nitems != 0 || q->blocks != 0 || q->net_qtail != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "rdc_dequeue(1): q %p, q blocks %" NSC_SZFMT
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " , nitems %" NSC_SZFMT ", qhead %p qtail %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) q, q->blocks, q->nitems,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) aio, (void *) q->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!IS_STATE(urdc, RDC_LOGGING)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!(q->qfflags & RDC_QFILLSLEEP)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!IS_STATE(urdc, RDC_SYNCING)) && (QNITEMS(dq) > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rc = EAGAIN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* aio remove from q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = aio->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qtail == aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks -= aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qhead == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana if (q->nitems != 0 || q->blocks != 0 || q->net_qtail != 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_PANIC, "rdc_dequeue(2): q %p, q blocks %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT " nitems %" NSC_SZFMT
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " , qhead %p qtail %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) q, q->blocks, q->nitems,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) q->net_qhead, (void *) q->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_qfill_shldwakeup(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clear EAGAIN if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logging or q filler thread is sleeping or stopping altogether
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or if q filler thread is dead already
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or if syncing, this will return a null aio, with no error code set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * telling the flusher to die
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*rc == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->qfflags & (RDC_QFILLSLEEP | RDC_QFILLSTOP)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_QSTATE(dq, (RDC_QDISABLEPEND | RDC_STOPPINGFLUSH))) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->qfill_sleeping == RDC_QFILL_DEAD) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_SYNCING)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_qfill_shldsleep()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns 1 if the qfilling code should cv_wait() 0 if not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reasons for going into cv_wait();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is nothing in the diskq to flush to mem.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the memory queue has gotten too big and needs more flushing attn.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_qfill_shldsleep(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *nq = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&nq->net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->qfflags & RDC_QFILLSLEEP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ_NOISY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Sleeping diskq->memq flusher: QFILLSLEEP idx: %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) || IS_STATE(urdc, RDC_SYNCING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ_NOISY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Sleeping diskq->memq flusher: Sync|Log (0x%x)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " idx: %d", rdc_get_vflags(urdc), urdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((QNXTIO(dq) == QTAIL(dq)) && !IS_QSTATE(dq, RDC_QFULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ_NOISY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Sleeping diskq->memq flusher: QEMPTY");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nq->blocks >= RDC_MAX_QBLOCKS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nq->hwmhit = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* stuck flushers ? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ_NOISY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Sleeping diskq->memq flusher: memq full:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " seq: %d seqack %d", krdc->group->seq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->seqack);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_join_netqueues(a, b)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * appends queue b to queue a updating all the queue info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as it is assumed queue a is the important one,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it's mutex must be held. no one can add to queue b
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_join_netqueues(net_queue *q, net_queue *tmpq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&q->net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qhead == NULL) { /* empty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->blocks != 0 || q->nitems != 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_PANIC, "rdc filler: q %p, qhead 0, "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " q blocks %" NSC_SZFMT ", nitems %" NSC_SZFMT,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) q, q->blocks, q->nitems);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = tmpq->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = tmpq->net_qtail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems = tmpq->nitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks = tmpq->blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail->next = tmpq->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = tmpq->net_qtail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems += tmpq->nitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks += tmpq->blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->nitems > q->nitems_hwm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems_hwm = q->nitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->blocks > q->blocks_hwm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks_hwm = q->blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_qfiller_thr() single thread that moves
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data from the diskq to a memory queue for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the flusher to pick up.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_qfiller_thr(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *grp = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q = &grp->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *tmpq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfill_sleeping = RDC_QFILL_AWAKE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!(q->qfflags & RDC_QFILLSTOP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(grp) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_STATE(urdc, RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_STATE(urdc, RDC_DISKQ_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto nulltmpq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(qfiller_top);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpq = rdc_read_diskq_buf(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmpq == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto nulltmpq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((q->qfflags & RDC_QFILLSLEEP) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_discard_tmpq(tmpq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto nulltmpq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* race with log, redundant yet paranoid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((q->qfflags & RDC_QFILLSLEEP) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_discard_tmpq(tmpq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto nulltmpq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_join_netqueues(q, tmpq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmpq, sizeof (*tmpq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenulltmpq:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sleep for a while if we can.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the enqueuing or flushing code will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wake us if if necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_qfill_shldsleep(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfill_sleeping = RDC_QFILL_ASLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(qfiller_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&q->qfcv, &q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(qfiller_wakeup);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfill_sleeping = RDC_QFILL_AWAKE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->qfflags & RDC_QFILLSTOP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_qfiller_thr: recieved kill signal");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(qfiller_bottom);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(qfiller_done);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfill_sleeping = RDC_QFILL_DEAD; /* the big sleep */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_qfiller_thr stopping");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfflags &= ~RDC_QFILLSTOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_add_diskq(int index, char *diskq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc, *kp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc, *up;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!diskq || urdc->disk_queue[0]) { /* how'd that happen? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!NULL diskq in _rdc_add_diskq");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if the enable fails, this is bzero'ed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, diskq, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags &= ~RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags |= RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!adding diskq to group %s", urdc->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_enable_diskq(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == RDC_EQNOADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (kp = krdc->group_next; kp != krdc; kp = kp->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = &rdc_u_info[kp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(up->disk_queue, diskq, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* size lives in the diskq structure, already set by enable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(kp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add a diskq to an existing set/group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_add_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc, *this;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t vol_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t req_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc = &rdc_k_info[index];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana this = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq = uparms->rdc_set->disk_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ASYNC(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQWRONGMODE, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOQUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOTLOGGING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOTLOGGING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make sure that we have enough bitmap vol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req_size = RDC_BITMAP_FBA + FBA_LEN(krdc->bitmap_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req_size += FBA_LEN(krdc->bitmap_size * BITS_IN_BYTE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_devs(krdc, RDC_BMP, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_open_diskq: Bitmap reserve failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBITMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_partsize(krdc->bitmapfd, &vol_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, RDC_BMP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vol_size < req_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP2SMALL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBITMAP2SMALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = krdc->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc != this);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->disk_queue[0] != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQALREADY, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_SECONDARY) { /* how'd we get here? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQWRONGMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQWRONGMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_diskq_inuse(uparms->rdc_set, uparms->rdc_set->disk_queue)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EDISKQINUSE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EDISKQINUSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_add_diskq(urdc->index, diskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0 || rc == RDC_EQNOADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags &= ~RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOADD, uparms->rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOADD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_init_diskq(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_stamp_diskq(krdc, 0, RDC_NOLOG) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inititalize the disk queue. This is a destructive
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * operation that will not check for emptiness of the queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_init_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc, *kp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc, *up;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t *uset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *qp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uset = uparms->rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uset->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uset->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qp = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_SYNCING) && !IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQUEISREP, urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQUEISREP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a couple of big "ifs" here. in the first implementation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * neither of these will be possible. This will come into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * play when we persist the queue across reboots
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_FORCE_QINIT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!QEMPTY(qp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->rdc_writer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQFLUSHING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQFLUSHING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOTEMPTY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOTEMPTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_init_diskq(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(qp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (kp = krdc->group_next; kp != krdc; kp = kp->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = &rdc_u_info[kp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(up, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(qp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* generic queue failure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQINITFAIL, urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQINITFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_kill_diskq(rdc_u_info_t *urdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *up;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags |= RDC_DISKQ_KILL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!disabling disk queue %s", urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(group, &q->disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_close the queue and zero out the queue name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_wait_qbusy(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSIZE(q, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(up, RDC_DISKQ_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(up->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!_rdc_kill_diskq: enabling memory queue");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags &= ~(RDC_DISKQUE|RDC_DISKQ_KILL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove this diskq regardless of whether it is draining or not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stops the flusher by invalidating the qdata (ie, instant empty)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove the disk qeueue from the group, leaving the group with a memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_kill_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t *rdc_set = uparms->rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOQUEUE, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOQUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * spcs_s_add(kstatus, RDC_EQNOTLOGGING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uparms->rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rc = RDC_EQNOTLOGGING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(krdc->group); /* stop protecting queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc); /* to prevent further flushing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_kill_diskq(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove a diskq from a group.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removal of a diskq from a set, or rather
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a set from a queue, is done by reconfigging out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the group. This removes the diskq from a whole
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * group and replaces it with a memory based queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NUM_RETRIES 15 /* Number of retries to wait if no progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_rem_diskq(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *this;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile disk_queue *diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int threads, counter;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana this = &rdc_k_info[index];
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOTLOGGING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQNOTLOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = krdc->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc != this);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If there is no group or diskq configured, we can leave now
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(group = krdc->group) || !(diskq = &group->diskq))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait if not QEMPTY or threads still active
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!QEMPTY(diskq) || group->rdc_thrnum) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Capture counters to determine if progress is being made
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blocks = QBLOCKS(diskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte threads = group->rdc_thrnum;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Has the group or disk queue gone away while delayed?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(group = krdc->group) || !(diskq = &group->diskq))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Are we still seeing progress?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (blocks == QBLOCKS(diskq) && threads == group->rdc_thrnum) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No progress see, decrement retry counter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (counter++ > NUM_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No progress seen, increment retry counter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = group->rdc_thrnum ?
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_EQFLUSHING : RDC_EQNOTEMPTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, rc, urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reset counter, as we've made progress
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}