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/* Network data replicator Client side */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/debug.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cred.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/byteorder.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _SunOS_2_6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on 2.6 both dki_lock.h and rpc/types.h define bool_t so we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * define enum_t here as it is all we need from rpc/types.h
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * anyway and make it look like we included it. Yuck.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _RPC_TYPES_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef int enum_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SunOS_2_6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/auth.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/svc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/xdr.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsc_thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/contract.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h> /* dtrace is S10 or later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_clnt.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_bitmap.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_diskq.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t rdc_clnt_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint noflush = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_rpc_tmout = RDC_CLNT_TMOUT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_clnt_free(struct chtab *, CLIENT *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _rdc_remote_flush(rdc_aio_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_flush_memq(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_flush_diskq(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_drain_net_queue(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_flusher_thread(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_diskq_enqueue(rdc_k_info_t *krdc, rdc_aio_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_init_diskq_header(rdc_group_t *grp, dqheader *hd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_dump_iohdrs(disk_queue *dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_t *rdc_dequeue(rdc_k_info_t *krdc, int *rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_clr_iohdr(rdc_k_info_t *krdc, nsc_off_t qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_close_diskq(rdc_group_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_writer(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct chtab *rdc_chtable = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_clnt_toomany;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_ooreply;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void rdc_fail_diskq(rdc_k_info_t *krdc, int wait, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _rdc_rsrv_diskq(rdc_group_t *group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _rdc_rlse_diskq(rdc_group_t *group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic enum clnt_stat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecl_call_sig(struct __client *rh, rpcproc_t proc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xargs, caddr_t argsp, xdrproc_t xres,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte caddr_t resp, struct timeval secs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enum clnt_stat stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte k_sigset_t smask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigintr(&smask, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rh->cl_nosignal = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stat = ((*(rh)->cl_ops->cl_call)\
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (rh, proc, xargs, argsp, xres, resp, secs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rh->cl_nosignal = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigunintr(&smask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (stat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_getsize(int index, uint64_t *sizeptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err, size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int remote_index = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sizeptr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_getsize: null intf for index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_GETSIZE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_int, (char *)&remote_index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_int, (char *)&size, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sizeptr = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_GETSIZE6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_int, (char *)&remote_index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_u_longlong_t, (char *)sizeptr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_state(int index, int options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state4 s4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char neta[32], rneta[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version < RDC_VERSION7) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.netaddrlen = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.rnetaddrlen = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->primary.addr.buf, s4.netaddr, s4.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->secondary.addr.buf, s4.rnetaddr, s4.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(s4.pfile, urdc->primary.file, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(s4.sfile, urdc->secondary.file, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.flag = options;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_STATE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_set_state4, (char *)&s4, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&remote_index, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddrlen = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddrlen = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.buf = neta;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.buf = rneta;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->primary.addr.buf, s.netaddr.buf, s.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->secondary.addr.buf, s.rnetaddr.buf, s.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.len = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.len = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.maxlen = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.maxlen = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)s.netaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = htons(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)s.rnetaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = htons(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.pfile = urdc->primary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.sfile = urdc->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.flag = options;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_STATE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_set_state, (char *)&s, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&remote_index, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (remote_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_net_getbmap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gets the bitmaps from remote side and or's them with remote bitmap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_getbmap(int index, int size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct bmap b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct bmap6 b6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_getbmap: null intf for index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b.cd = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b.dual = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b.size = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_BMAP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_bmap, (char *)&b, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&err, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.cd = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.dual = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.size = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_BMAP6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_bmap6, (char *)&b6, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&err, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sndr_proto = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return state corresponding to rdc_host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_getstate(rdc_k_info_t *krdc, int *serial_mode, int *use_mirror,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *mirror_down, int network)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef sparc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state4 s4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char neta[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char rneta[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *setp = (char *)&s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xdr_proc = xdr_set_state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv && (krdc->intf == NULL || krdc->intf->if_down) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte network) /* fail fast */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddrlen = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddrlen = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.pfile = urdc->primary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.sfile = urdc->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.buf = neta;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.buf = rneta;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->primary.addr.buf, s.netaddr.buf, s.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->secondary.addr.buf, s.rnetaddr.buf, s.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *) s.netaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = htons(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *) s.rnetaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = htons(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.len = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.len = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.netaddr.maxlen = urdc->primary.addr.maxlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.rnetaddr.maxlen = urdc->secondary.addr.maxlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s.flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sndr_proto)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version = sndr_proto;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version = RDC_VERS_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteagain:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_GETSTATE4, krdc->rpc_version,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_proc, setp, xdr_int, (char *)&state, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == RPC_PROGVERSMISMATCH && (krdc->rpc_version !=
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_VERS_MIN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version-- == RDC_VERSION7) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set_state struct changed with v7 of protocol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef sparc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.netaddrlen = urdc->primary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.rnetaddrlen = urdc->secondary.addr.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->primary.addr.buf, s4.netaddr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(urdc->secondary.addr.buf, s4.rnetaddr,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana s4.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(s4.pfile, urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(s4.sfile, urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s4.flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_proc = xdr_set_state4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setp = (char *)&s4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* x64 can not use protocols < 7 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sndr get_state: Protocol ver %d", krdc->rpc_version);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (serial_mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_mode = (state >> 2) & 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (use_mirror)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *use_mirror = (state >> 1) & 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror_down)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mirror_down = state & 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct xdr_discrim rdres_discrim[2] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { (int)RDC_OK, xdr_readok },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { __dontcare__, NULL_xdrproc_t }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reply from remote read (client side)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic bool_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortexdr_rdresult(XDR *xdrs, readres *rr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xdr_union(xdrs, (enum_t *)&(rr->rr_status),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (caddr_t)&(rr->rr_ok), rdres_discrim, xdr_void));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_rrstatus_decode(int status)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != RDC_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDCERR_NOENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDCERR_NOMEM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_read(int local_index, int remote_index, nsc_buf_t *handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos, nsc_size_t fba_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdcrdresult rr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread6 list6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rpc_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_HANDLE_LIMITS(handle, fba_pos, fba_len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_read: handle bounds");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[local_index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[local_index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxfbas = MAX_RDC_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_fd && !(rdc_get_vflags(urdc) & RDC_FCAL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *remote_h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_reserve(krdc->remote_fd, NSC_MULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_alloc_buf(krdc->remote_fd, fba_pos, fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_RDBUF, &remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_copy(remote_h, handle, fba_pos, fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(krdc->remote_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (remote_h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(krdc->remote_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_VOL_FAILED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rpc_flag = RDC_RREAD_FAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rpc_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_read: null intf for index %d", local_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * switch on proto version.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = fba_len; /* length (FBAs) still to xfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_bufsize = 0; /* rpc data buffer length (bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_data = NULL; /* rpc data buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transflag = rpc_flag | RDC_RREAD_START; /* setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(fba_pos <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.pos = (int)fba_pos; /* fba position of start of chunk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.cd = remote_index; /* remote end cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* send setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.len = (int)len; /* total fba length */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_rread, (char *)&list, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&ret, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.pos = fba_pos; /* fba position of start of chunk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.cd = remote_index; /* remote end cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* send setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.flag = transflag; /* setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.len = (int)len; /* total fba length */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_rread6, (char *)&list6, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&ret, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_read: setup err %d", err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == RPC_INTR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOLINK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_rerror;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0) { /* No valid index from r_net_read */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_read: no valid index from r_net_read");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOBUFS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transflag = rpc_flag | RDC_RREAD_DATA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.idx = ret; /* save idx to return to server */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move onto to data xfer rpcs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.idx = ret; /* save idx to return to server */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find starting position in handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = handle->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos -= handle->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; fba_pos >= FBA_NUM(vec->sv_len); vec++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_pos -= FBA_NUM(vec->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr = vec->sv_addr + FBA_SIZE(fba_pos); /* data in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len - FBA_SIZE(fba_pos); /* bytes in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > maxfbas) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_SIZE(translen) > sv_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = FBA_NUM(sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len -= translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last data xfer rpc - tell server to cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transflag |= RDC_RREAD_END;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rr.rr_data || (nsc_size_t)rr.rr_bufsize !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(translen)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rr.rr_data, rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FBA_SIZE(translen) <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_bufsize = FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_data = kmem_alloc(rr.rr_bufsize, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rr.rr_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_read: kmem_alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get data from remote end */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_read: null intf for index %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_enter(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTCOND*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(RDC_MAXDATA <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(translen <= RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.len = (int)translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_rread, (char *)&list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_rdresult, (char *)&rr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.len = (int)translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_rread6, (char *)&list6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_rdresult, (char *)&rr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_exit(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_read: rpc err %d", err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == RPC_INTR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOLINK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_rerror;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_status != RDC_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdc_rrstatus_decode(rr.rr_status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_rerror;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy into handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(rr.rr_data, sv_addr, (size_t)rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update counters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr += rr.rr_bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list.pos += translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list6.pos += translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(krdc->io_kstats)->reads++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(krdc->io_kstats)->nread += rr.rr_bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(sv_len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(sv_len >= (nsc_size_t)rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len -= rr.rr_bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* goto next vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr = vec->sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rr.rr_data, rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteremote_rerror:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rr.rr_data, rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret ? ret : ENOLINK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_net_write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Main remote write client side
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handles protocol selection as well as requests for remote allocation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and data transfer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Does local IO for FCAL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * caller must clear bitmap on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_write(int local_index, int remote_index, nsc_buf_t *handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba_pos, nsc_size_t fba_len, uint_t aseq, int qpos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netwriteres *netres)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netwriteres netret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netwriteres *netresptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_data5 dlist5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_data6 dlist6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int transendoblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *transptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if not a diskq buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((qpos == -1) && (!RDC_HANDLE_LIMITS(handle, fba_pos, fba_len))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_write: handle bounds");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[local_index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[local_index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxfbas = MAX_RDC_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FCAL IO */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_fd && !(rdc_get_vflags(urdc) & RDC_FCAL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *remote_h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_reserve(krdc->remote_fd, NSC_MULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_alloc_buf(krdc->remote_fd, fba_pos, fba_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_WRBUF, &remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_copy(handle, remote_h, fba_pos, fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_write(remote_h, fba_pos, fba_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(krdc->remote_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (remote_h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(remote_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_release(krdc->remote_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * At this point we must decide which protocol we are using and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the right thing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netres) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr = netres;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr = &netret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = rdc_get_vflags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vflags & (RDC_VOL_FAILED|RDC_BMP_FAILED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transflag = RDC_RWRITE_FAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_net_write: null intf for index %d",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana local_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = handle->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find starting position in vector
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((qpos == -1) || (handle->sb_user == RDC_NULLBUFREAD))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos = fba_pos - handle->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos = (qpos + 1) - handle->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; fpos >= FBA_NUM(vec->sv_len); vec++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos -= FBA_NUM(vec->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len - FBA_SIZE(fpos); /* bytes in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transptr = (char *)vec->sv_addr + FBA_SIZE(fpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.local_cd = local_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.cd = remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(fba_len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(fba_pos <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.len = (int)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.pos = (int)fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.idx = -1; /* Starting index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.seq = aseq; /* sequence number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.sfba = (int)fba_pos; /* starting fba for this xfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.local_cd = local_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.cd = remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(fba_len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.len = (int)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.qpos = qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.pos = fba_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.idx = -1; /* Starting index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.flag = transflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.seq = aseq; /* sequence number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.sfba = fba_pos; /* starting fba for this xfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transendoblk = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fba_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!transptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_write: walked off end of handle!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > maxfbas) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(maxfbas <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = (int)maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(fba_len <= INT32_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = (int)fba_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FBA_SIZE(translen) > sv_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte translen = FBA_NUM(sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba_len -= translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last data xfer - tell server to commit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transendoblk = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_write: null intf for index %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_netwrite_clntcall_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_enter(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.nfba = translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.endoblk = transendoblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.data.data_len = FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.data.data_val = transptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_WRITE5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_net_data5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&dlist5, xdr_int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&ret, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr->result = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr->index = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr->result = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netresptr->result = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.nfba = translen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.endoblk = transendoblk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.data.data_len = FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.data.data_val = transptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_WRITE6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version, xdr_net_data6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&dlist6, xdr_netwriteres,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)netresptr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_exit(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_netwrite_clntcall_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = netresptr->result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == RPC_INTR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINTR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (err && ret != EPROTO)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOLINK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_write(5): cd %d err %d ret %d",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana remote_index, err, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Error from r_net_write5 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netresptr->result < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_write: r_net_write(5) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "returned: %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte -netresptr->result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = -netresptr->result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (netresptr->index == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_net_write: no valid index from "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "r_net_write(5)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOBUFS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto remote_error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version <= RDC_VERSION5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.idx = netresptr->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist5.sfba += dlist5.nfba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.idx = netresptr->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist6.sfba += dlist6.nfba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update counters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(krdc->io_kstats)->writes++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_IO_PTR(krdc->io_kstats)->nwritten +=
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transptr += FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len -= FBA_SIZE(translen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_len <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* goto next vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transptr = (char *)vec->sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this can't happen.....
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteremote_error:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret ? ret : ENOLINK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_fixlen(rdc_aio_t *aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vecp = aio->qhandle->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (vecp->sv_addr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len += FBA_NUM(vecp->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle->sb_len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_dump_alloc_bufs_cd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Dump allocated buffers (rdc_net_hnd's) for the specified cd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this could be the flusher failing, if so, don't do the delay forever
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 0 (success), EAGAIN (caller needs to try again).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dump_alloc_bufs_cd(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->c_fd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannot do anything! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_dump_alloc_bufs_cd(%d): c_fd NULL",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_dsets(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = QLOCK(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_rsrv_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &krdc->group->ra_queue.net_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now dump the async queue anonymous buffers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we are a diskq, the we are using the diskq mutex.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * However, we are flushing from diskq to memory queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so we now need to grab the memory lock also
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->qfill_sleeping == RDC_QFILL_AWAKE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!dumpalloccd sending diskq->memq flush to sleep");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfflags |= RDC_QFILLSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (q->qfill_sleeping == RDC_QFILL_AWAKE && tries--)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((q->net_qhead != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *tmpkrdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpkrdc = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
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 aio->qhandle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmpkrdc->io_kstats && !RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(tmpkrdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_waitq_exit(KSTAT_IO_PTR(tmpkrdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(tmpkrdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = q->net_qhead->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks -= aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CHECK_BIT(tmpkrdc, aio->pos, aio->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->asyncstall) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->asyncdis = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->sleepq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepqdiscard(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->seq = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_dump_alloc_bufs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have an error on the link
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try to dump all of the allocated bufs so we can cleanly recover
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and not hang
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dump_alloc_bufs(rdc_if_t *ip)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int repeat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte repeat = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf == ip) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_dump_alloc_bufs_cd(index) == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte repeat = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (repeat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns 1 if the the throttle should throttle, 0 if not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_diskq_isfull(disk_queue *q, long len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---T----H----N--- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (FITSONQ(q, len + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_async_throttle(rdc_k_info_t *this, long len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int print_msg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = RDC_FUTILE_ATTEMPTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Throttle entries on queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Need to take the 1-many case into account, checking all sets */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ADD HANDY HUERISTIC HERE TO SLOW DOWN IO */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = this; /* CSTYLED */; krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this may be the last set standing in a one to many setup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we may also be stuck in unintercept, after marking
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the volume as not enabled, but have not removed it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the many list resulting in an endless loop if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we just continue here. Lets jump over this stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and check to see if we are the only dude here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thischeck;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ASYNC(urdc) && RDC_IS_MEMQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((q->blocks + q->inflbls) > urdc->maxqfbas ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->nitems + q->inflitems) > urdc->maxqitems) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) /* disable race */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thischeck;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->group->rdc_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->throttle_delay++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* do a much more aggressive delay, get disk flush going */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ASYNC(urdc) && RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((!IS_QSTATE(q, RDC_QNOBLOCK)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (_rdc_diskq_isfull(q, len)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!IS_STATE(urdc, RDC_DISKQ_FAILED))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (print_msg) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc async throttle:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " disk queue %s full",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_msg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) /* disable race */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thischeck;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->group->rdc_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(10);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->throttle_delay += 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(tries--) && IS_STATE(urdc, RDC_QUEUING)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: disk queue "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "%s full & not flushing. giving up",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &urdc->disk_queue[0]);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!SNDR: %s:%s entering"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " logging mode",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DOLOG | RDC_NOFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((IS_QSTATE(q, RDC_QNOBLOCK)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_diskq_isfull(q, len) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !IS_STATE(urdc, RDC_DISKQ_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (print_msg) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s full",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &urdc->disk_queue[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_msg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DOLOG | RDC_NOFAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&q->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortethischeck:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->many_next == this)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_coalesce = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_joins = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_coalesce(rdc_aio_t *queued, rdc_aio_t *new)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t bitmask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_coalesce == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* don't even try */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((queued == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (queued->handle == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (new->handle == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* existing queue is empty */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (queued->index != new->index || queued->len + new->len >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_FBAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* I/O to big */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((queued->pos + queued->len == new->pos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (new->pos + new->len == queued->pos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_abuf(queued->pos, queued->len + new->len, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* couldn't do coalesce */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_copy(queued->handle, h, queued->pos, queued->pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queued->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* couldn't do coalesce */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_copy(new->handle, h, new->pos, new->pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0); /* couldn't do coalesce */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[queued->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SET_BITMASK(queued->pos, queued->len, &bitmask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdc, queued->pos, queued->len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitmask, RDC_BIT_BUMP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SET_BITMASK(new->pos, new->len, &bitmask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdc, new->pos, new->len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitmask, RDC_BIT_BUMP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(queued->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(new->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queued->handle = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queued->len += new->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitmask = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bump the ref count back up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SET_BITMAP(krdc, queued->pos, queued->len, &bitmask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* new I/O succeeds last I/O queued */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_memq_enqueue(rdc_k_info_t *krdc, rdc_aio_t *aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_aio_coalesce(q->net_qtail, aio)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_joins++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->seq = group->seq++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->seq < aio->seq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ + 1; /* skip magics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qhead == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* adding to empty q */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = q->net_qtail = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->blocks != 0 || q->nitems != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "rdc enqueue: q %p, qhead 0, q blocks %" NSC_SZFMT
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ", nitems %" NSC_SZFMT,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) q, q->blocks, q->nitems);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* discontiguous, add aio to q tail */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail->next = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems++;
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 Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* sum the q and check for sanity */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t qblocks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t nitems = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *a;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (a = q->net_qhead; a != NULL; a = a->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qblocks += a->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qblocks != q->blocks || nitems != q->nitems) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "rdc enqueue: q %p, q blocks %" NSC_SZFMT " (%"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT "), nitems %" NSC_SZFMT " (%"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT ")", (void *) q, q->blocks, qblocks,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana q->nitems, nitems);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
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 if (!krdc->group->rdc_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_enqueue_write(rdc_k_info_t *krdc, nsc_off_t pos, nsc_size_t len, int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = kmem_zalloc(sizeof (*aio), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!aio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->pos = pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qpos = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->flag = flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->index = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->flags & RDC_MEMQUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc_memq_enqueue(krdc, aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((group->flags & RDC_DISKQUE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !IS_STATE(urdc, RDC_DISKQ_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_diskq_enqueue(krdc, aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* keep lint quiet */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Async Network RDC flusher
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * don't allow any new writer threads to start if a member of the set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is disable pending
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteis_disable_pending(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *this = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = this;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = krdc->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc != this);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_writer -- spawn new writer if not running already
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called after enqueing the dirty blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_writer(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const int MAX_TRIES = 16;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &group->diskq.disk_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &group->ra_queue.net_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (noflush) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->rdc_writer) || is_disable_pending(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->rdc_thrnum >= 1) && (group->seqack == RDC_NEWSEQ)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We also need to check if we are starting a new
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sequence, and if so don't create a new thread,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as we must ensure that the start of new sequence
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * requests arrives first to re-init the server.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For version 6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if we can fit in another thread.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_thrnum++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf && (krdc->intf->rpc_version >= RDC_VERSION6)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->rdc_thrnum >= urdc->asyncthr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_writer = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_writer = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we got here, we know that we have not exceeded the allowed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * number of async threads for our group. If we run out of threads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in _rdc_flset, we add a new thread to the set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first try to grab a thread from the free list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t = nst_create(_rdc_flset, rdc_flusher_thread,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (blind_t)(unsigned long)index, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* that failed; add a thread to the set and try again */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nst_add_thread(_rdc_flset, 1) != 1) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_writer index %d nst_add_thread "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "error, tries: %d", index, tries);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (++tries < MAX_TRIES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->addthrnumlk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_addthrnum += tries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->addthrnumlk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_writer: index %d nst_create error", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_thrnum--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_writer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->count == 0) && (group->rdc_thrnum == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Race with remove_from_group while write thread was
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failing to be created.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_writer: group being destroyed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delgroup(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Either we need to flush the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kmem (net_queue) queue or the disk (disk_queue)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine which, and do it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_flusher_thread(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->flags & RDC_MEMQUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_flush_memq(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (krdc->group->flags & RDC_DISKQUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_flush_diskq(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* uh-oh, big time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "flusher trying to flush unknown queue type");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_flush_memq(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dowork;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!group || group->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_memq: no group left!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->c_fd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_memq: no c_fd!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISABLE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_memq: DISABLE PENDING!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Need to continue as we may be trying to flush IO
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * while trying to disable or suspend
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dowork = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (dowork) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (net_exit == ATM_EXIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!group || group->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_memq: no group left!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->nitems != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "rdc_flush_memq(1): q %p, q blocks %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT ", nitems %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ", qhead %p qtail %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q, q->blocks, q->nitems,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) aio, (void *) q->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
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 /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in flight numbers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflbls += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->net_qhead == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->nitems != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "rdc_flush_memq(2): q %p, q blocks %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT ", nitems %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ", qhead %p qtail %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q, q->blocks, q->nitems,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q->net_qhead,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef NSC_MULTI_TERABYTE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->blocks < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "rdc_flush_memq(3): q %p, q blocks %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ", nitems %d, qhead %p, qtail %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q, q->blocks, q->nitems,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *) q->net_qhead, (void *) q->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* blocks and nitems are unsigned for NSC_MULTI_TERABYTE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_remote_flush(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflbls -= aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->seqack == RDC_NEWSEQ) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (group->seq != RDC_NEWSEQ + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((q->net_qhead == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (q->net_qhead->seq != RDC_NEWSEQ + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We are an old thread, and the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue sequence has been reset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * during the network write above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * As such we mustn't pull another
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * job from the queue until the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * first sequence message has been ack'ed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just die instead. Unless this thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is the first sequence that has just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * been ack'ed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dowork = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((aio->iostatus != RDC_IO_DONE) && (group->count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdctmp = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdctmp->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc, RDC_NOFLUSH | RDC_ALLREMOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "memq flush aio status not RDC_IO_DONE");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_queue(aio->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0 || !krdc->lsrv || !krdc->intf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortethread_death:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_thrnum--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_writer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all threads must be dead.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->count == 0) && (group->rdc_thrnum == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Group now empty, so destroy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Race with remove_from_group while write thread was running
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_memq: group being destroyed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delgroup(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_flush_diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * disk queue flusher
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_flush_diskq(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
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_aio_t *aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *nq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dowork;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!group || group->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_diskq: no group left!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->c_fd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_diskq: no c_fd!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISABLE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_diskq: DISABLE PENDING!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Need to continue as we may be trying to flush IO
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * while trying to disable or suspend
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nq = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, RDC_QDISABLEPEND) || IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!flusher thread death 1 %x", QSTATE(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dowork = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (dowork) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (net_exit == ATM_EXIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!group || group->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_diskq: no group left!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((IS_STATE(urdc, RDC_LOGGING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_SYNCING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = rdc_dequeue(krdc, &rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((IS_STATE(urdc, RDC_LOGGING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_SYNCING)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->qfflags & RDC_QFILLSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(40);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (rc == EAGAIN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflbls += aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_remote_flush(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflbls -= aio->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->inflitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->seqack == RDC_NEWSEQ) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (group->seq != RDC_NEWSEQ + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nq->net_qhead == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nq->net_qhead->seq != RDC_NEWSEQ + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We are an old thread, and the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue sequence has been reset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * during the network write above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * As such we mustn't pull another
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * job from the queue until the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * first sequence message has been ack'ed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just die instead. Unless of course,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this thread is the first sequence that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has just been ack'ed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dowork = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->iostatus == RDC_IO_CANCELLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_queue(aio->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group) { /* seq gets bumped on dequeue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((aio->iostatus != RDC_IO_DONE) && (group->count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdctmp = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdctmp->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto thread_death;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_NOFLUSH | RDC_ALLREMOTE | RDC_QUEUING,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "diskq flush aio status not RDC_IO_DONE");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_queue(aio->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISABLE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_flush_diskq: DISABLE PENDING after IO!");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0 || !krdc->lsrv || !krdc->intf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(q, RDC_QDISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!flusher thread death 2");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortethread_death:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_thrnum--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_writer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio && aio->qhandle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle->sb_user--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->qhandle->sb_user == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_rsrv_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fixlen(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->qhandle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->count == 0) && (group->rdc_thrnum == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Group now empty, so destroy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Race with remove_from_group while write thread was running
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_flush_diskq: group being destroyed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delgroup(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_remote_flush
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Flush a single block ANON block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this function will flush from either the disk queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or the memory queue. The appropriate locks must be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * taken out etc, etc ...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_remote_flush(rdc_aio_t *aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtype = RDC_RAW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t maxseq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netwriteres netret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int waitq = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Where did we get this aio from anyway? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &group->diskq.disk_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &group->ra_queue.net_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * quench transmission if we are too far ahead of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * server Q, or it will overflow.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must fail all requests while asyncdis is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It will be cleared when the last thread to be discarded
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sets the asyncstall counter to zero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note the thread within rdc_net_write
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * also bumps the asyncstall counter.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncdis) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't go to sleep if we have gone logging! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = rdc_get_vflags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vflags & (RDC_BMP_FAILED|RDC_VOL_FAILED|RDC_LOGGING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vflags & RDC_LOGGING) && RDC_IS_DISKQ(group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (maxseq = group->seqack + RDC_MAXPENDQ + 1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxseq = (maxseq < group->seqack) ? maxseq + RDC_NEWSEQ + 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte : maxseq, !RDC_INFRONT(aio->seq, maxseq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncstall++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!IS_STATE(urdc, RDC_LOGGING));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&group->asyncqcv, qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncstall--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(group->asyncstall >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncdis) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncdis = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if we have gone into logging mode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since sleeping.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = rdc_get_vflags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vflags & (RDC_BMP_FAILED|RDC_VOL_FAILED|RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vflags & RDC_LOGGING) && RDC_IS_DISKQ(group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((krdc->io_kstats) && (!RDC_IS_DISKQ(krdc->group))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_waitq_exit(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte waitq = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_devs(krdc, rtype, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_rdc_remote_flush: reserve, index %d, rc %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->index, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Case where we are multihop and calling with no ANON bufs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Need to do the read to fill the buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!aio->handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(RDC_U_FD(krdc), aio->pos, aio->len,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (aio->flag & ~NSC_WRITE) | NSC_READ, &h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_remote_flush: alloc_buf, index %d, pos %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT ", len %" NSC_SZFMT ", rc %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->index, aio->pos, aio->len, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle->sb_user = RDC_NULLBUFREAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncdis) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncdis = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncstall++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this should be ok, we are flushing, not rev syncing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remote_index could be -1 if we lost a race with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resume and the flusher trys to flush an io from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * another set that has not resumed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = rdc_net_state(krdc->index, CCIO_SLAVE);
d5508a7fb37e6b070e142ee081bec69a3d20bd6cThomas Atkins DTRACE_PROBE1(remote_index_negative, int, krdc->remote_index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * double check for logging, no check in net_write()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * skip the write if you can, otherwise, if logging
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid clearing the bit .. you don't know whose bit it may
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * also be.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) || IS_STATE(urdc, RDC_SYNCING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncstall--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_net_write(krdc->index, krdc->remote_index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle, aio->pos, aio->len, aio->seq, aio->qpos, &netret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncstall--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncdis) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncdis = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_LOGGING) || IS_STATE(urdc, RDC_SYNCING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_CANCELLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_remote_flush: write, index %d, pos %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ", len %" NSC_SZFMT ", "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "rc %d seq %u group seq %u seqack %u qpos %" NSC_SZFMT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->index, aio->pos, aio->len, rc, aio->seq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq, group->seqack, aio->qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == ENOLINK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!Hard timeout detected (%d sec) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "on SNDR set %s:%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_rpc_tmout, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free locally alloc'd handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle->sb_user == RDC_NULLBUFREAD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle->sb_user--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->qhandle->sb_user == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_rsrv_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fixlen(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->qhandle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.result == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = rdc_get_vflags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(vflags & (RDC_BMP_FAILED|RDC_VOL_FAILED|RDC_LOGGING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdc, aio->pos, aio->len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xffffffff, RDC_BIT_BUMP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* tell queue data has been flushed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_iohdr(krdc, aio->qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* throw away queue, logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check to see if the reply has arrived out of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * order, if so don't update seqack.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_INFRONT(aio->seq, group->seqack)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = aio->seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_ooreply++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (netret.result < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if we have any pending async requests we can mark
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_pendvec_t *vecp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_pendvec_t *vecpe;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp = netret.vecdata.vecdata_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecpe = netret.vecdata.vecdata_val + netret.vecdata.vecdata_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (vecp < vecpe) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdcp = &rdc_k_info[vecp->pindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdcp = &rdc_u_info[vecp->pindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we must always still be in the same group.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdcp->group == group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = rdc_get_vflags(urdcp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(vflags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (RDC_BMP_FAILED|RDC_VOL_FAILED|RDC_LOGGING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdcp, vecp->apos, vecp->alen, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xffffffff, RDC_BIT_BUMP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdcp->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update queue info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_iohdr(krdc, vecp->qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* we've gone logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(q, QHEAD(q));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if we can re-start transmission
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_INFRONT(vecp->seq, group->seqack)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = vecp->seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_ooreply++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
d5508a7fb37e6b070e142ee081bec69a3d20bd6cThomas Atkins DTRACE_PROBE1(pendvec_return, int, vecp->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecp++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len * sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* perhaps we have a few threads stuck .. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncdis = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len * sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free locally alloc'd hanlde */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((aio->handle) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (aio->handle->sb_user == RDC_NULLBUFREAD)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle->sb_user--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->qhandle->sb_user == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_rsrv_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fixlen(aio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->qhandle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->qhandle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((waitq && krdc->io_kstats) && (!RDC_IS_DISKQ(krdc->group))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_waitq_exit(KSTAT_IO_PTR(krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make sure that the bit is still set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CHECK_BIT(krdc, aio->pos, aio->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->iostatus != RDC_IO_CANCELLED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->iostatus = RDC_IO_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_drain_disk_queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drain the async network queue for the whole group. Bail out if nothing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * happens in 20 sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns -1 if it bails before the queues are drained.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NUM_RETRIES 15 /* Number of retries to wait if no progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_drain_disk_queue(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
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 /* Sanity checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index > rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
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 * No need to wait if EMPTY and threads are gone
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 seen, increment retry counter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (counter++ > NUM_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
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}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * decide what needs to be drained, disk or core
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and drain it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_drain_queue(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc_drain_disk_queue(index));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_MEMQ(group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc_drain_net_queue(index));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* oops.. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_drain_queue: "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "attempting drain of unknown Q type");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_drain_net_queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drain the async network queue for the whole group. Bail out if nothing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * happens in 20 sec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns -1 if it bails before the queues are drained.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_drain_net_queue(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile net_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bail = 20; /* bail out in about 20 secs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sanity checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index > rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(q = &krdc->group->ra_queue))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((volatile rdc_aio_t *)q->net_qhead == NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->group->rdc_thrnum == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blocks = q->blocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = (volatile net_queue *)&krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((blocks == q->blocks) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (--bail <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bail <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_dump_queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We want to release all the blocks currently on the network flushing queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We already have them logged in the bitmap.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dump_queue(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t *qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq = &group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gotta have both locks here for diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q->qfill_sleeping == RDC_QFILL_AWAKE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_DISKQ
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!dumpq sending diskq->memq flusher to sleep");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->qfflags |= RDC_QFILLSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (q->qfill_sleeping == RDC_QFILL_AWAKE && tries--)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &dq->disk_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_rsrv_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qlock = &q->net_qlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ; /* reset the sequence number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if the q is on disk, dump the q->iohdr chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_iohdrs(dq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* back up the nxtio pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QCOALBOUNDS(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (q->net_qhead) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *tmpkrdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio = q->net_qhead;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmpkrdc = &rdc_k_info[aio->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
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 aio->qhandle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (aio->handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(aio->handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio->handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qhead = aio->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CHECK_BIT(tmpkrdc, aio->pos, aio->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(aio, sizeof (*aio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmpkrdc->io_kstats && !RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(tmpkrdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_waitq_exit(KSTAT_IO_PTR(tmpkrdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(tmpkrdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->net_qtail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->blocks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->nitems = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if we have stalled threads.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->asyncstall) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->asyncdis = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&q->net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_clnt_get
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get a CLIENT handle and cache it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_get(rdc_srv_t *svp, rpcvers_t vers, struct chtab **rch, CLIENT **clp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t max_msgsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct cred *cred;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_clnts = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte register struct chtab *ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct chtab **plistp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLIENT *client = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rch) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rch = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (clp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *clp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retries = 6; /* Never used for COTS in Solaris */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cred = ddi_get_cred();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte max_msgsize = RDC_RPC_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch = rdc_chtable;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte plistp = &rdc_chtable;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find the right ch_list chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ch = rdc_chtable; ch != NULL; ch = ch->ch_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_prog == RDC_PROGRAM &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_vers == vers &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_dev == svp->ri_knconf->knc_rdev &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_protofmly != NULL &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(ch->ch_protofmly,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana svp->ri_knconf->knc_protofmly) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found the correct chain to walk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte plistp = &ch->ch_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* walk the ch_list and try and find a free client */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (num_clnts = 0; ch != NULL; ch = ch->ch_list, num_clnts++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_inuse == FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* suitable handle to reuse */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte plistp = &ch->ch_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch == NULL && num_clnts >= MAXCLIENTS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* alloc a temporary handle and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clnt_toomany++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = clnt_tli_kcreate(svp->ri_knconf, &(svp->ri_addr),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_PROGRAM, vers, max_msgsize, retries, cred, &client);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_call: tli_kcreate failed %d", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rch = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *clp = client;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) CLNT_CONTROL(client, CLSET_PROGRESS, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reuse a cached handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_inuse = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_timesused++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rch = ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_client == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = clnt_tli_kcreate(svp->ri_knconf, &(svp->ri_addr),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_PROGRAM, vers, max_msgsize, retries,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cred, &ch->ch_client);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_inuse = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) CLNT_CONTROL(ch->ch_client, CLSET_PROGRESS,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *clp = ch->ch_client;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Consecutive calls to CLNT_CALL() on the same client handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the same transaction ID. We want a new xid per call,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so we first reinitialise the handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clnt_tli_kinit(ch->ch_client, svp->ri_knconf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana &(svp->ri_addr), max_msgsize, retries, cred);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *clp = ch->ch_client;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create new handle and cache it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch = (struct chtab *)kmem_zalloc(sizeof (*ch), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_inuse = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_prog = RDC_PROGRAM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_vers = vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_dev = svp->ri_knconf->knc_rdev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_protofmly = (char *)kmem_zalloc(
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana strlen(svp->ri_knconf->knc_protofmly)+1, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_protofmly)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ch->ch_protofmly,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp->ri_knconf->knc_protofmly);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *plistp = ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = clnt_tli_kcreate(svp->ri_knconf, &(svp->ri_addr),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_PROGRAM, vers, max_msgsize, retries, cred, clp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_inuse = FALSE;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_call: tli_kcreate failed %d", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rch = ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_client = *clp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) CLNT_CONTROL(*clp, CLSET_PROGRESS, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelong rdc_clnt_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_clnt_call
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_srv_t *svp - rdc servinfo
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rpcproc_t proc; - rpcid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rpcvers_t vers; - protocol version
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xdrproc_t xargs;- xdr function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * caddr_t argsp;- args to xdr function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * xdrproc_t xres;- xdr function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * caddr_t resp;- args to xdr function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * struct timeval timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Performs RPC client call using specific protocol and version
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_call(rdc_srv_t *svp, rpcproc_t proc, rpcvers_t vers,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xargs, caddr_t argsp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xres, caddr_t resp, struct timeval *timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLIENT *rh = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct chtab *ch = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_get(svp, vers, &ch, &rh);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err || !rh)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE3(rdc_clnt_call_1,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CLIENT *, rh, rpcproc_t, proc, xdrproc_t, xargs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = cl_call_sig(rh, proc, xargs, argsp, xres, resp, *timeout);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(rdc_clnt_call_end, int, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_SUCCESS: /* bail now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_INTR: /* No recovery from this */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_PROGVERSMISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_TLIERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fall thru */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_XPRTFAILED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delay here to err on side of caution */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fall thru */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RPC_VERSMISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_UNRECOVERABLE_RPC(err)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The call is in progress (over COTS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try the CLNT_CALL again, but don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print a noisy error message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == RPC_INPROGRESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR client: err %d %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana err, clnt_sperrno(err));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (tries && (tries < 2));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++rdc_clnt_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clnt_free(ch, rh);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Call an rpc from the client side, not caring which protocol is used.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_call_any(rdc_srv_t *svp, rdc_if_t *ip, rpcproc_t proc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xargs, caddr_t argsp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdrproc_t xres, caddr_t resp, struct timeval *timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rpcvers_t vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ip != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vers = ip->rpc_version;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vers = RDC_VERS_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_clnt_call(svp, proc, vers, xargs, argsp,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana xres, resp, timeout);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == RPC_PROGVERSMISMATCH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Downgrade and try again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vers--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((vers >= RDC_VERS_MIN) && (rc == RPC_PROGVERSMISMATCH));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc == 0) && (ip != NULL) && (vers != ip->rpc_version)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->rpc_version = vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Call an rpc from the client side, starting with protocol specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_call_walk(rdc_k_info_t *krdc, rpcproc_t proc, xdrproc_t xargs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte caddr_t argsp, xdrproc_t xres, caddr_t resp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval *timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rpcvers_t vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_srv_t *svp = krdc->lsrv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip = krdc->intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vers = krdc->rpc_version;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_clnt_call(svp, proc, vers, xargs, argsp,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana xres, resp, timeout);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == RPC_PROGVERSMISMATCH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Downgrade and try again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vers--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((vers >= RDC_VERS_MIN) && (rc == RPC_PROGVERSMISMATCH));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc == 0) && (ip != NULL) && (vers != ip->rpc_version)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->rpc_version = vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_clnt_free
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free a client structure into the cache, or if this was a temporary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle allocated above MAXCLIENTS, destroy it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_free(struct chtab *ch, CLIENT *clp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cached client, just clear inuse flag and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ch->ch_client == clp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_inuse = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* temporary handle allocated above MAXCLIENTS, so destroy it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (clp->cl_auth) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AUTH_DESTROY(clp->cl_auth);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clp->cl_auth = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLNT_DESTROY(clp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_clnt_destroy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free a chain (ch_list or ch_next) of cached clients
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_clnt_destroy(struct chtab **p, const int list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct chtab *ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int leak = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*p != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch = *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unlink from the chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - this leaks the client if it was inuse
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p = list ? ch->ch_list : ch->ch_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ch->ch_inuse) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unused client - destroy it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_client) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_client->cl_auth) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AUTH_DESTROY(ch->ch_client->cl_auth);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_client->cl_auth = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLNT_DESTROY(ch->ch_client);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch->ch_client = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ch->ch_protofmly)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ch->ch_protofmly,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana strlen(ch->ch_protofmly)+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ch, sizeof (*ch));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remember client leak */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte leak++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (leak);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_clnt_destroy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free client caching table on unconfigure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clnt_destroy(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct chtab *ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int leak = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* destroy each ch_list chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ch = rdc_chtable; ch; ch = ch->ch_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte leak += _rdc_clnt_destroy(&ch->ch_list, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* destroy the main ch_next chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte leak += _rdc_clnt_destroy(&rdc_chtable, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (leak) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we are about to leak clients */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_clnt_destroy: leaking %d inuse clients", leak);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to send an asynchronous net_data6 request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * direct to a server to allow the generation of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * out of order requests for ZatoIchi tests.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_async6(void *arg, int mode, int *rvp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_async6_t async6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_data6 data6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int datasz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *datap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netwriteres netret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copyin the user's arguments.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, &async6, sizeof (async6), mode) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * search by the secondary host and file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ASYNC(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->rpc_version < RDC_VERSION6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strncmp(urdc->secondary.intf, async6.sechost,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strncmp(urdc->secondary.file, async6.secfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOENT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (async6.spos != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((async6.spos < async6.pos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((async6.spos + async6.slen) >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (async6.pos + async6.len))) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Sub task not within range "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "start %d length %d sub start %d sub length %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte async6.pos, async6.len, async6.spos, async6.slen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datasz = FBA_SIZE(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = kmem_alloc(datasz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datap = data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (datap < &data[datasz]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *datap++ = async6.pat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fill in the net databuffer prior to transmission.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.local_cd = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index == -1) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Remote index not known");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, datasz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.cd = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.pos = async6.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.len = async6.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.idx = async6.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.seq = async6.seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (async6.spos == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.sfba = async6.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.nfba = async6.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.endoblk = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.sfba = async6.spos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.nfba = async6.slen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.endoblk = async6.endind;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.data.data_len = datasz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data6.data.data_val = data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_clnt_call(krdc->lsrv, RDCPROC_WRITE6, krdc->rpc_version,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_net_data6, (char *)&data6, xdr_netwriteres, (char *)&netret,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, datasz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.result < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -netret.result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!async6: seq %u result %d index %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "pendcnt %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.seq, netret.result, netret.index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < netret.vecdata.vecdata_len; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_pendvec_t pvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(netret.vecdata.vecdata_val + i, &pvec,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (net_pendvec_t));
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Seq %u pos %llu len %llu",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec.seq, (unsigned long long)pvec.apos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned long long)pvec.alen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netret.vecdata.vecdata_val)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(netret.vecdata.vecdata_val,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (net_pendvec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!async6: rpc call failed %d", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = netret.index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to send an net_read6 request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * direct to a server to allow the generation of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * read requests.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_readgen(void *arg, int mode, int *rvp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_readgen_t readgen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_readgen32_t readgen32;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread6 read6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread read5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdcrdresult rr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_bufsize = 0; /* rpc data buffer length (bytes) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_data = NULL; /* rpc data buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, &readgen32, sizeof (readgen32), mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(readgen.sechost, readgen32.sechost,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(readgen.secfile, readgen32.secfile, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.len = readgen32.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.pos = readgen32.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.idx = readgen32.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.flag = readgen32.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.data = (void *)(unsigned long)readgen32.data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readgen.rpcversion = readgen32.rpcversion;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, &readgen, sizeof (readgen), mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (readgen.rpcversion) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 5:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byhostdev(readgen.sechost, readgen.secfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we should really call setbusy here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_sec = rdc_rpc_tmout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index == -1) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!Remote index not known");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (readgen.rpcversion == 6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read6.cd = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read6.len = readgen.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read6.pos = readgen.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read6.idx = readgen.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read6.flag = readgen.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read5.cd = krdc->remote_index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read5.len = readgen.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read5.pos = readgen.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read5.idx = readgen.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte read5.flag = readgen.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (readgen.flag & RDC_RREAD_START) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (readgen.rpcversion == 6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VERSION6, xdr_rread6, (char *)&read6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_int, (char *)&ret, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VERSION5, xdr_rread, (char *)&read5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_int, (char *)&ret, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (readgen.rpcversion == 6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VERSION6, xdr_rread6, (char *)&read6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_rdresult, (char *)&rr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = rdc_clnt_call(krdc->lsrv, RDCPROC_READ5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VERSION5, xdr_rread, (char *)&read5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xdr_rdresult, (char *)&rr, &t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_status != RDC_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = rr.rr_bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyout(rr.rr_data, readgen.data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rr.rr_bufsize, mode) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rr.rr_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rr.rr_data, rr.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif