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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kRPC Server for sndr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cred.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stream.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_k.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn 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#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#include <sys/ncall/ncall.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h> /* dtrace is S10 or later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_bitmap.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdcsrv.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_sleepq_t *rdc_newsleepq();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_delsleepq(rdc_sleepq_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_sleepq(rdc_group_t *, rdc_sleepq_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_combywrite(rdc_k_info_t *, nsc_buf_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_writemaxfba(rdc_k_info_t *, rdc_u_info_t *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *, uint_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_setbitind(int *, net_pendvec_t *, rdc_net_dataset_t *, uint_t,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_dopending(rdc_group_t *, netwriteres *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_vec_t *rdc_dset2vec(rdc_net_dataset_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_combyread(rdc_k_info_t *, rdc_u_info_t *, nsc_buf_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_readmaxfba(int, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_dsetcopy(rdc_net_dataset_t *, nsc_vec_t *, nsc_off_t, nsc_size_t,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* direction for dsetcopy() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define COPY_IN 1 /* copy data into the rpc buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define COPY_OUT 2 /* copy data out of the rpc buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_EINTR_COUNT 1000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_rread_slow;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdcsrv_t rdc_srvtab[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_netwrite6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_stall0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_sleepcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_datasetcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_event_notify(int operation, char *volume, char *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ack = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_sync_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_sync_event.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_sync_event.daemon_waiting) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.daemon_waiting = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.event = operation;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_sync_event.master, volume, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_sync_event.group, group, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&rdc_sync_event.cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.kernel_waiting = 1;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni time = cv_reltimedwait_sig(&rdc_sync_event.done_cv,
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni &rdc_sync_event.mutex, rdc_sync_event_timeout,
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni TR_CLOCK_TICK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (time == (clock_t)0 || time == (clock_t)-1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* signalled or timed out */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ack = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_sync_event.ack)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ack = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ack = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_sync_event.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_sync_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ack);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_event_wait(void *arg0, void *arg1, int mode, spcs_s_info_t kstatus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *rvp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static char master[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte master[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg0, master, NSC_MAXPATH, mode))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_sync_event.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_sync_event.kernel_waiting &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_sync_event.lbolt - nsc_lbolt() < rdc_sync_event_timeout)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We haven't been away too long */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (master[0])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.ack = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.ack = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.kernel_waiting = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&rdc_sync_event.done_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.daemon_waiting = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cv_wait_sig(&rdc_sync_event.cv, &rdc_sync_event.mutex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.daemon_waiting = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EAGAIN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_copyout(rdc_sync_event.master, arg0, NSC_MAXPATH,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_copyout(rdc_sync_event.group, arg1, NSC_MAXPATH,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = rdc_sync_event.event;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sync_event.lbolt = nsc_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_sync_event.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_allow_sec_sync(rdc_u_info_t *urdc, int option)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_MULTI(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = krdc->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (option == CCIO_RSYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Reverse sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_mflags(urdc) & RDC_RSYNC_NEEDED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reverse sync needed or in progress.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(option == CCIO_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Forward sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_mflags(urdc) & RDC_SLAVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reverse syncing is bad, as that means that data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is already flowing to the target of the requested
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear "reverse sync needed" on all 1-many volumes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The data on them will be updated from the primary of this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * requested sync operation, so the aborted reverse sync need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not be completed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_mflags(urdc) & RDC_RSYNC_NEEDED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_vflags(urdc) & RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ktmp = krdc->many_next; ktmp != krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = ktmp->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[ktmp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_mflags(utmp) & RDC_RSYNC_NEEDED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(utmp, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_null
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Proc 0 Null action
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_null(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_void, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_read
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_read(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readres resp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread diskio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buffer = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pos, st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nocache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vector = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vecsz = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = SVC_GETARGS(xprt, xdr_rread, (char *)&diskio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache = (diskio.flag & RDC_RREAD_FAIL) ? 0 : NSC_NOCACHE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.cd >= rdc_max_sets) || (diskio.cd < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_read: EPROTO cd out or not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.flag & RDC_RREAD_START) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = rdc_readmaxfba(diskio.cd, diskio.pos, diskio.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!svc_sendreply(xprt, xdr_int, (char *)&st)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (st != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset = rdc_net_get_set(diskio.cd, st)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_read: get_set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "has failed in cleanup");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* data rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.flag & RDC_RREAD_DATA) == 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_read: received non-DATA rpc! flag %x",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana diskio.flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_get_set(diskio.cd, diskio.idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector = rdc_dset2vec(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vector == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cleanup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecsz = (dset->nitems + 1) * sizeof (nsc_vec_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cleanup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDC_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find place in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = vector;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos = diskio.pos - dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; pos >= FBA_NUM(vec->sv_len); vec++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos -= FBA_NUM(vec->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr = vec->sv_addr + FBA_SIZE(pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len - FBA_SIZE(pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IF the data is in a single sb_vec entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * THEN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we can just point to that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ELSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we have to alloc a local buffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy the data in and the point to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the local buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_len >= FBA_SIZE(diskio.len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fast */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data = (char *)sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_bufsize = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* slow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_rread_slow++; /* rough count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_bufsize = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer = kmem_alloc(resp.rr_bufsize, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!buffer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data = buffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_dsetcopy(dset, vector, diskio.pos, diskio.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data, resp.rr_bufsize, COPY_IN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM; /* ??? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_readres, (char *)&resp); /* send data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecleanup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (diskio.flag & RDC_RREAD_END) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (resp.rr_status != RDC_OK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RPC reply failed, OR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Last RPC for this IO operation, OR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We are failing this IO operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do cleanup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buffer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(buffer, resp.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vector) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vector, vecsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-vecsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_read (v6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_read6(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte readres resp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rread6 diskio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buffer = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pos, st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nocache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vector = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vecsz = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = SVC_GETARGS(xprt, xdr_rread6, (char *)&diskio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache = (diskio.flag & RDC_RREAD_FAIL) ? 0 : NSC_NOCACHE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.cd >= rdc_max_sets) || (diskio.cd < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_read6: EPROTO cd out or not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.flag & RDC_RREAD_START) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = rdc_readmaxfba(diskio.cd, diskio.pos, diskio.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!svc_sendreply(xprt, xdr_int, (char *)&st)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (st != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset = rdc_net_get_set(diskio.cd, st)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!read6: get_set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "has failed in cleanup");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* data rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.flag & RDC_RREAD_DATA) == 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!read6: received non-DATA rpc! flag %x",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana diskio.flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_get_set(diskio.cd, diskio.idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector = rdc_dset2vec(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vector == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cleanup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecsz = (dset->nitems + 1) * sizeof (nsc_vec_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_readres, (char *)&resp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cleanup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDC_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find place in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = vector;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos = diskio.pos - dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; pos >= FBA_NUM(vec->sv_len); vec++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos -= FBA_NUM(vec->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr = vec->sv_addr + FBA_SIZE(pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len - FBA_SIZE(pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IF the data is in a single sb_vec entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * THEN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we can just point to that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ELSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we have to alloc a local buffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy the data in and the point to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the local buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_len >= FBA_SIZE(diskio.len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fast */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data = (char *)sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_bufsize = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* slow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_rread_slow++; /* rough count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_bufsize = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer = kmem_alloc(resp.rr_bufsize, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!buffer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data = buffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_dsetcopy(dset, vector, diskio.pos, diskio.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_data, resp.rr_bufsize, COPY_IN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp.rr_status = RDCERR_NOMEM; /* ??? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_readres, (char *)&resp); /* send data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecleanup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (diskio.flag & RDC_RREAD_END) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (resp.rr_status != RDC_OK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RPC reply failed, OR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Last RPC for this IO operation, OR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We are failing this IO operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do cleanup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buffer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(buffer, resp.rr_bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vector) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vector, vecsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-vecsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_write (Version 5)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 reply indicates error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * >0 reply indicates a net handle index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <0 reply indicates errno
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ret net handle index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ret2 general error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ret3 multi-hop errors (never returned)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_write5(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_data5 diskio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nocache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret2 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = kmem_alloc(RDC_MAXDATA, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!diskio.data.data_val) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = SVC_GETARGS(xprt, xdr_net_data5, (char *)&diskio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_write5:SVC_GETARGS failed: st %d", st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.cd >= rdc_max_sets) || (diskio.cd < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_write6: EPROTO cd out or not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache = (diskio.flag & RDC_RWRITE_FAIL) ? 0 : NSC_NOCACHE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc) || IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_write6: cd logging / not enabled (%x)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_vflags(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = NULL; /* so we don't try to unqueue kstat entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* -1 index says allocate a buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.idx < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_add_set(diskio.cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_write5: "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "failed to add dataset");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = dset->id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->pos = diskio.pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->fbalen = diskio.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.idx = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = kmem_alloc(sizeof (rdc_net_dataitem_t), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(sizeof (rdc_net_dataitem_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this is a single transfer, then we don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to allocate any memory for the data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just point the ditem data pointer to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * existing buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.endoblk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->dptr = diskio.data.data_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So we don't free it twice.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->len = diskio.data.data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->mlen = RDC_MAXDATA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate the memory for the complete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * transfer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->dptr = kmem_alloc(FBA_SIZE(diskio.len),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem->dptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(FBA_SIZE(diskio.len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->len = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->mlen = ditem->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy the data to the new buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(diskio.data.data_len == FBA_SIZE(diskio.nfba));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(diskio.data.data_val, ditem->dptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free the old data buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->head = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->nitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = diskio.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_get_set(diskio.cd, diskio.idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write5: net_get_set failed cd %d idx %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.cd, diskio.idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have to copy the data from the rpc buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the data in ditem.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = dset->head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(diskio.data.data_val, (char *)ditem->dptr +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(diskio.sfba - diskio.pos), diskio.data.data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.endoblk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = rdc_writemaxfba(krdc, urdc, dset, diskio.seq, nocache);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(ret2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret2 > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = -ret2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(rdc_svcwrite5_err_ret2, int, ret2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_int, (char *)&ret2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc && krdc->io_kstats && ret2 != ENOMEM) {
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 * On Error we must cleanup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we have a handle, free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we have a network handle, free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st || !RDC_SUCCESS(ret2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_write5 error case? st %x ret %d",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana st, ret2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.data.data_val) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_write (Version 6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * index 0 = error, or net handle index.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * result = 0 , ok.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * result = 1, pending write.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * result < 0 error, and is the -errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ret net handle index.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ret2 general error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_write6(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_data6 diskio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netwriteres netret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret2 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nocache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.vecdata.vecdata_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = kmem_alloc(RDC_MAXDATA, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!diskio.data.data_val) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = SVC_GETARGS(xprt, xdr_net_data6, (char *)&diskio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6:SVC_GETARGS failed: st %d", st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.cd >= rdc_max_sets) || (diskio.cd < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_write6: EPROTO cd out or not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache = (diskio.flag & RDC_RWRITE_FAIL) ? 0 : NSC_NOCACHE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.seq = diskio.seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[diskio.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc) || IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6: cd logging or not enabled (%x)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_vflags(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = NULL; /* so we don't try to unqueue kstat entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6: No group structure for set %s:%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = NULL; /* so we don't try to unqueue kstat entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_netwrite6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6: idx %d seq %u current seq %u pos %llu "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "len %d sfba %llu nfba %d endoblk %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.idx, diskio.seq, group->seq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned long long)diskio.pos, diskio.len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned long long)diskio.sfba, diskio.nfba,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.endoblk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* -1 index says allocate a net dataset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.idx < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_add_set(diskio.cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6: failed to add dataset");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = dset->id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->pos = (nsc_off_t)diskio.pos; /* 64bit! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->fbalen = diskio.len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.idx = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = kmem_alloc(sizeof (rdc_net_dataitem_t), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(sizeof (rdc_net_dataitem_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this is a single transfer, then we don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to allocate any memory for the data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just point the ditem data pointer to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * existing buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.endoblk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->dptr = diskio.data.data_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So we don't free it twice.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->len = diskio.data.data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->mlen = RDC_MAXDATA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate the memory for the complete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * transfer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->dptr = kmem_alloc(FBA_SIZE(diskio.len),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem->dptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(FBA_SIZE(diskio.len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->len = FBA_SIZE(diskio.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->mlen = ditem->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy the data to the new buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(diskio.data.data_len == FBA_SIZE(diskio.nfba));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(diskio.data.data_val, ditem->dptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free the old data buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->head = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->nitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = diskio.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_get_set(diskio.cd, diskio.idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_write6: net_get_set failed cd %d idx %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "packet sequence %u expected seq %u",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.cd, diskio.idx, diskio.seq, group->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have to copy the data from the rpc buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the data in ditem.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = dset->head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(diskio.data.data_val, (char *)ditem->dptr +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(diskio.sfba - diskio.pos), diskio.data.data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.data.data_val = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.endoblk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.seq == (RDC_NEWSEQ + 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_stallzero(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.seq == RDC_NEWSEQ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * magic marker, start of sequence.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if some threads are stuck.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->sleepq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepqdiscard(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((diskio.seq != RDC_NOSEQ) && (diskio.seq != RDC_NEWSEQ)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if we are allowed through here to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do the write, or if we have to q the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * request and send back a pending reply.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.seq != group->seq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int maxseq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check that we have room.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxseq = group->seqack + RDC_MAXPENDQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (maxseq < group->seqack) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * skip magic values.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxseq += RDC_NEWSEQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_INFRONT(diskio.seq, maxseq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!net_write6: Queue "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "size %d exceeded seqack %u "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "this seq %u maxseq %u seq %u",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXPENDQ, group->seqack,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskio.seq, maxseq, group->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
d5508a7fb37e6b070e142ee081bec69a3d20bd6cThomas Atkins DTRACE_PROBE2(qsize_exceeded, int, diskio.seq,
d5508a7fb37e6b070e142ee081bec69a3d20bd6cThomas Atkins int, maxseq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepqdiscard(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq = rdc_newsleepq();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->seq = diskio.seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->sindex = diskio.cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->pindex = diskio.local_cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->idx = diskio.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->qpos = diskio.qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->nocache = nocache;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_sleepq(group, sq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepqdiscard(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_waitq_enter(KSTAT_IO_PTR(krdc->
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pending state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.result = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.index = diskio.idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_netwriteres,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&netret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats && ret2 != ENOMEM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_runq_exit(KSTAT_IO_PTR(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->io_kstats));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(krdc->io_kstats->ks_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2 = rdc_writemaxfba(krdc, urdc, dset, diskio.seq, nocache);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(ret2)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_write6: writemaxfba failed %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.seq != RDC_NOSEQ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = diskio.seq + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->seq < diskio.seq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->sleepq &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (group->sleepq->seq == group->seq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dopending(group, &netret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = group->seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(ret2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(rdc_svcwrite6_err_ret2, int, ret2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.result = -ret2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.result = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netret.index = ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = svc_sendreply(xprt, xdr_netwriteres, (char *)&netret);
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 if (krdc && krdc->io_kstats && ret2 != ENOMEM) {
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 * On Error we must cleanup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we have a handle, free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we have a network handle, free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we hold the main nsc buffer, free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!st || !RDC_SUCCESS(ret2)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_write6 error st %x ret %d seq %u",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st, ret2, diskio.seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(diskio.cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskio.data.data_val) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(diskio.data.data_val, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_ping4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * received on the primary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_ping4(SVCXPRT *xprt, struct svc_req *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdc_ping6 ping;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_rdc_ping6, (char *)&ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update specified interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ip = rdc_if_top; ip; ip = ip->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bcmp(ping.p_ifaddr, ip->ifaddr.buf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_MAXADDR) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(ping.s_ifaddr, ip->r_ifaddr.buf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_MAXADDR) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->new_pulse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->deadness = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Update the rpc protocol version to use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->rpc_version = req->rq_vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svcerr_decode(xprt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: couldn't get ping4 arguments");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_ping7
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * received on the primary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_ping7(SVCXPRT *xprt, struct svc_req *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdc_ping ping;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ping, sizeof (struct rdc_ping));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_rdc_ping, (char *)&ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)ping.p_ifaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)ping.s_ifaddr.buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update specified interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ip = rdc_if_top; ip; ip = ip->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bcmp(ping.p_ifaddr.buf, ip->ifaddr.buf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ping.p_ifaddr.len) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(ping.s_ifaddr.buf, ip->r_ifaddr.buf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana ping.s_ifaddr.len) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->new_pulse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->deadness = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Update the rpc protocol version to use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip->rpc_version = req->rq_vers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svcerr_decode(xprt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: couldn't get ping7 arguments");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_bmap (v5)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WARNING acts as both client and server
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_bmap(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct bmap b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct bmap6 b6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_bmap, (char *)&b);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[b.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[b.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (b.cd >= 0 && b.cd < rdc_max_sets && IS_ENABLED(urdc) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_DISABLEPEND) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version = RDC_VERSION5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.cd = b.cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.dual = b.dual;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte b6.size = b.size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = RDC_SEND_BITMAP(&b6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_bmap (v6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WARNING acts as both client and server
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_bmap6(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct bmap6 b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_bmap6, (char *)&b);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[b.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[b.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (b.cd >= 0 && b.cd < rdc_max_sets && IS_ENABLED(urdc) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_DISABLEPEND) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->rpc_version = RDC_VERSION6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = RDC_SEND_BITMAP(&b);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the bitmap send has succeeded, clear it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!Bitmap clear in r_net_bmap6");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_bdata
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_bdata(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_bdata bd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_bdata6 bd6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have to convert it to the internal form here,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * net_data6, when we know that we will have to convert
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it back to the v5 variant for transmission.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.data.data_val = kmem_alloc(BMAP_BLKSIZE, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bd.data.data_val == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_net_bdata, (char *)&bd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[bd.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[bd.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bd.cd >= 0 && bd.cd < rdc_max_sets && IS_ENABLED(urdc) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_DISABLEPEND) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd6.cd = bd.cd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd6.offset = bd.offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd6.size = bd.size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd6.data.data_len = bd.data.data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd6.data.data_val = bd.data.data_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = RDC_OR_BITMAP(&bd6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(bd.data.data_val, BMAP_BLKSIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_bdata v6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_bdata6(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_bdata6 bd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just allocate the bigger block, regardless of < V7
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bd.size will dictate how much we lor into our bitmap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the other option would be write r_net_bdata7 that is identical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to this function, but a V7 alloc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.data.data_val = kmem_alloc(BMAP_BLKSIZEV7, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bd.data.data_val == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_net_bdata6, (char *)&bd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e == TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[bd.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[bd.cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bd.cd >= 0 && bd.cd < rdc_max_sets && IS_ENABLED(urdc) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_DISABLEPEND) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = RDC_OR_BITMAP(&bd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Write the merged bitmap.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret == 0) && bd.endoblk && (krdc->bitmap_write > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_bdata6: Written bitmap for %s:%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdc_write_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(bd.data.data_val, BMAP_BLKSIZEV7);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_getsize (v5)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_getsize(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = -1, index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_VALID_INDEX(index) && ((krdc->type_flag &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DISABLEPEND) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = mirror_getsize(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_getsize (v6)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_getsize6(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * small change in semantics here, as we can't return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 over the wire anymore.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_VALID_INDEX(index) && ((krdc->type_flag &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DISABLEPEND) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = mirror_getsize(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_u_longlong_t, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_state4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_state4(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state4 state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int options;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int log = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int done = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int slave = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rev_sync = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_set_state4, (char *)&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.netaddr, rdc_set.primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.rnetaddr, rdc_set.secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.primary.addr.len = state.netaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.secondary.addr.len = state.rnetaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.file, state.pfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.secondary.file, state.sfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte options = state.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byaddr(&rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_state: no index or disable pending");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_state: set not enabled ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_state: no valid svp\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc || !krdc->group) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_state: no valid krdc %p\n", (void*)krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_state: disable pending");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(krdc->lsrv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->primary.addr), &(urdc->secondary.addr), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(krdc->lsrv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->secondary.addr), &(urdc->primary.addr), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & CCIO_SLAVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark that the bitmap needs clearing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Starting forward sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_details(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_resume_bitmap(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_allow_sec_sync(urdc, CCIO_SLAVE) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_dsets(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slave = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_RSYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark that the bitmap needs clearing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Starting reverse sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & (RDC_SYNC_NEEDED |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED | RDC_BMP_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_allow_sec_sync(urdc, CCIO_RSYNC) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_dsets(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rev_sync = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync completed OK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNC_NEEDED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done = 1; /* forward sync complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING | RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE | RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_CLR_AFTERSYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_ENABLELOG) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync aborted or logging started */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (slave) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_sync_event_notify(RDC_SYNC_START,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SYNCING | RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rev_sync) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if volume is mounted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_sync_event_notify(RDC_RSYNC_START,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (done) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * special case...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this set is in a group, then sndrsyncd will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * make sure that all sets in the group are REP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before updating the config to "update", telling
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrsyncd that it is ok to take anther snapshot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on a following sync. The important part about
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the whole thing is that syncd needs kernel stats.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * however, this thread must set the set busy to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid disables. since this is the only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync_event_notify() that will cause a status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * call back into the kernel, and we will not be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accessing the group structure, we have to wakeup now
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_sync_event_notify(RDC_SYNC_DONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!done) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (log) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc, RDC_NOFLUSH | RDC_OTHERREMOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "Sync aborted or logging started");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_state(SVCXPRT *xprt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int options;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int log = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int done = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int slave = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rev_sync = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&state, sizeof (struct set_state));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_set_state, (char *)&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)(state.netaddr.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.netaddr.buf, rdc_set.primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)(state.rnetaddr.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.rnetaddr.buf, rdc_set.secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.primary.addr.len = state.netaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.secondary.addr.len = state.rnetaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.file, state.pfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.secondary.file, state.sfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte options = state.flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byaddr(&rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_state: no index or disable pending");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_state: set not enabled ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!r_net_state: no valid svp\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc || !krdc->group) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!r_net_state: no valid krdc %p\n", (void*)krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_DISABLEPEND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!r_net_state: disable pending");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(krdc->lsrv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->primary.addr), &(urdc->secondary.addr), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(krdc->lsrv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->secondary.addr), &(urdc->primary.addr), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & CCIO_SLAVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark that the bitmap needs clearing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Starting forward sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_details(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_resume_bitmap(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_allow_sec_sync(urdc, CCIO_SLAVE) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_dsets(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slave = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_RSYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mark that the bitmap needs clearing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Starting reverse sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & (RDC_SYNC_NEEDED |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED | RDC_BMP_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_allow_sec_sync(urdc, CCIO_RSYNC) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dump_dsets(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rev_sync = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync completed OK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNC_NEEDED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done = 1; /* forward sync complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING | RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE | RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_CLR_AFTERSYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_CLR_AFTERSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options & CCIO_ENABLELOG) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync aborted or logging started */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (slave) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_sync_event_notify(RDC_SYNC_START,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SYNCING | RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rev_sync) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if volume is mounted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_sync_event_notify(RDC_RSYNC_START,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (done) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * special case...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this set is in a group, then sndrsyncd will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * make sure that all sets in the group are REP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before updating the config to "update", telling
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrsyncd that it is ok to take anther snapshot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on a following sync. The important part about
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the whole thing is that syncd needs kernel stats.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * however, this thread must set the set busy to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid disables. since this is the only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync_event_notify() that will cause a status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * call back into the kernel, and we will not be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accessing the group structure, we have to wakeup now
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_sync_event_notify(RDC_SYNC_DONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!done) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (log) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc, RDC_NOFLUSH | RDC_OTHERREMOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "Sync aborted or logging started");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(state.netaddr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(state.rnetaddr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_getstate4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return our state to client
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_getstate4(SVCXPRT *xprt, struct svc_req *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = -1, index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state4 state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&state, sizeof (struct set_state));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_set_state4, (char *)&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.netaddr, rdc_set.primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.rnetaddr, rdc_set.secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.primary.addr.len = state.netaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.secondary.addr.len = state.rnetaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.file, state.pfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.secondary.file, state.sfile,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byaddr(&rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNCING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SLAVE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_LOGGING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_if_vers(urdc, req->rq_vers);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * r_net_getstate7
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return our state to client
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forter_net_getstate7(SVCXPRT *xprt, struct svc_req *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int e, ret = -1, index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct set_state state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pstr[RDC_MAXNAMLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sstr[RDC_MAXNAMLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&state, sizeof (struct set_state));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.pfile = pstr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.sfile = sstr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = SVC_GETARGS(xprt, xdr_set_state, (char *)&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)(state.netaddr.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.netaddr.buf, rdc_set.primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.netaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = (unsigned short *)(state.rnetaddr.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sp = ntohs(*sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.rnetaddr.buf, rdc_set.secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.rnetaddrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.primary.addr.len = state.netaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set.secondary.addr.len = state.rnetaddrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * strncpy(rdc_set.primary.file, state.pfile, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * strncpy(rdc_set.secondary.file, state.sfile, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.pfile, rdc_set.primary.file, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(state.sfile, rdc_set.secondary.file, RDC_MAXNAMLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byaddr(&rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNCING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SLAVE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_LOGGING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret |= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_if_vers(urdc, req->rq_vers);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(rdc_set.secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) svc_sendreply(xprt, xdr_int, (char *)&ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy from/to a dset/vector combination to a network xdr buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dsetcopy(rdc_net_dataset_t *dset, nsc_vec_t *invec, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fba_len, char *bdata, int blen, int dir)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *sv_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!bdata || !dset || !invec) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc: dsetcopy: parameters failed bdata %p, dset %p "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "invec %p", (void *)bdata, (void *)dset, (void *)invec);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fba_len > MAX_RDC_FBAS ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (dir != COPY_IN && dir != COPY_OUT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc: dsetcopy: params failed fba_len %" NSC_SZFMT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " fba_pos %" NSC_SZFMT ", dir %d", fba_len, fba_pos, dir);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = (uchar_t *)bdata; /* pointer to data in rpc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = FBA_SIZE(fba_len); /* length of this transfer in bytes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos = fba_pos; /* start fba offset within buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc: dsetcopy: len = 0");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len != blen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc:dsetcopy: len %d != blen %d", len, blen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > blen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = blen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_DSET_LIMITS(dset, fba_pos, fba_len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should never happen */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc: dsetcopy: handle limits pos %" NSC_SZFMT " (%"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT ") len %" NSC_SZFMT " (%" NSC_SZFMT ")",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fba_pos, dset->pos, fba_len, dset->fbalen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE); /* Don't overrun handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vec = invec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos -= dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find starting position in vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; fpos >= FBA_NUM(vec->sv_len); vec++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpos -= FBA_NUM(vec->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr = vec->sv_addr + FBA_SIZE(fpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len = vec->sv_len - FBA_SIZE(fpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sv_addr) /* end of vec - how did this happen? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(sv_len, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dir == COPY_OUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(data, sv_addr, (size_t)n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(sv_addr, data, (size_t)n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_len -= n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len -= n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_addr += n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data += n;
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 return (TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_start_server
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Starts the kRPC server for rdc. Uses tli file descriptor passed down
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from user level rdc server.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 0 or errno (NOT unistat!).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_start_server(struct rdc_svc_args *args, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_t *fp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct cred *cred;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_HANDLE(rdc_svc_args, rs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_SET_HANDLE(rs, mode, args);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cred = ddi_get_cred();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (drv_priv(cred) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EPERM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp = getf(STRUCT_FGET(rs, fd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_start_server fd %d, fp %p", args->fd,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBADF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdcsrv_load(fp, rdc_srvtab, args, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte releasef(STRUCT_FGET(rs, fd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate a new sleepq element.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_sleepq_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_newsleepq()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq = kmem_alloc(sizeof (rdc_sleepq_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_cntlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_cntlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free memory/resources used by a sleepq element.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_delsleepq(rdc_sleepq_t *sq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sq->idx != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_get_set(sq->sindex, sq->idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(sq->sindex, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sq, sizeof (rdc_sleepq_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_cntlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_cntlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * skip down the sleep q and insert the sleep request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in ascending order. Return 0 on success, 1 on failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_sleepq(rdc_group_t *group, rdc_sleepq_t *sq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *findsq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&group->ra_queue.net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->sleepq == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->sleepq = sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sq->seq == group->sleepq->seq) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sleepq: Attempt to "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "add duplicate request to queue %d", sq->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_INFRONT(sq->seq, group->sleepq->seq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->next = group->sleepq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->sleepq = sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte findsq = group->sleepq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (findsq->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sq->seq == findsq->next->seq) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sleepq: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Attempt to add duplicate "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "request to queue %d", sq->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_INFRONT(sq->seq, findsq->next->seq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->next = findsq->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte findsq->next = sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte findsq = findsq->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (findsq->next == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte findsq->next = sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * run down the sleep q and discard all the sleepq elements.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_sleepqdiscard(rdc_group_t *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&group->ra_queue.net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq = group->sleepq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (sq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *dsq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsq = sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[dsq->sindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
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 sq = sq->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delsleepq(dsq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->sleepq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * split any write requests down to maxfba sized chunks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_writemaxfba(rdc_k_info_t *krdc, rdc_u_info_t *urdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset, uint_t seq, int nocache)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t vector[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t mfba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t wsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int eintr_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *daddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int kstat_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_len = len = dset->fbalen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtype = RDC_RAW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->nitems == 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte eintr_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _rdc_rsrv_devs(krdc, rtype, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == EINTR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++eintr_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((ret == EINTR) && (eintr_count < MAX_EINTR_COUNT));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_writemaxfba: reserve devs "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed %d", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Perhaps we should cache mfba.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_maxfbas(RDC_U_FD(krdc), 0, &mfba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_writemaxfba: msc_maxfbas failed %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->volume_size != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset->pos + len > urdc->volume_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should never happen */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * also need to trim down the vector
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sizes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_len = len = urdc->volume_size - dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->head->len -= FBA_SIZE(len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->head->len > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte daddr = dset->head->dptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos = dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector[1].sv_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector[1].sv_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (len > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wsize = min((nsc_size_t)len, mfba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector[0].sv_addr = daddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vector[0].sv_len = FBA_SIZE(wsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_alloc_buf(RDC_U_FD(krdc), pos, wsize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_WRBUF|NSC_NODATA|nocache, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_writemaxfba: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nsc_alloc (d1) buf failed %d at "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "pos %" NSC_SZFMT " len %" NSC_SZFMT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret, pos, wsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_vec = &vector[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdc_combywrite(krdc, handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_writemaxfba: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "write failed (d1) %d offset %" NSC_SZFMT " "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "length %" NSC_SZFMT, ret, pos, wsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos += wsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len -= wsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte daddr += FBA_SIZE(wsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!(rdc_get_vflags(urdc) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_PRIMARY));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_VOL_FAILED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "svc write failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_netwrite6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This string is used in the ZatoIchi MASNDR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tests, if you change this, update the test.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!writemaxfba: Write "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sequence %u", seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
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(kstat_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_combywrite(rdc_k_info_t *krdc, nsc_buf_t *handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rsync;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int multiret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsync = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Handle multihop I/O even on error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MULTI(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find a target primary that is enabled,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * taking account of the fact that this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * could be a multihop secondary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * connected to a 1-to-many primary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = krdc->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ktmp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto multi_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[ktmp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(utmp) & RDC_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte && IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = ktmp->many_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[ktmp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (ktmp != krdc->multi_next);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(utmp) & RDC_PRIMARY) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !IS_ENABLED(utmp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto multi_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsync = (rdc_get_mflags(utmp) & RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rsync) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* normal case - local io first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_write(handle, handle->sb_pos, handle->sb_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte multiret = _rdc_multi_write(handle, handle->sb_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_len, 0, ktmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(multiret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!combywrite: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "rdc_multi_write failed "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "status %d ret %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_error, multiret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(utmp) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(ktmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(utmp) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(utmp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(utmp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(utmp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(ktmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemulti_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsync != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Either:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reverse sync in progress and so we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to do the local io after the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (multihop) secondary io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Or:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no multihop and this is the only io
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_write(handle, handle->sb_pos, handle->sb_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the pos and len values in the piggyback reply.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_setbitind(int *pendcnt, net_pendvec_t *pvec, rdc_net_dataset_t *dset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t seq, int pindex, int qpos)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(*pendcnt < RDC_MAXPENDQ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pc = *pendcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec[pc].seq = seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec[pc].apos = dset->pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec[pc].qpos = qpos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec[pc].alen = dset->fbalen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pvec[pc].pindex = pindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pendcnt = pc + 1;
d5508a7fb37e6b070e142ee081bec69a3d20bd6cThomas Atkins DTRACE_PROBE1(pvec_reply, int, seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Enters with group->ra_queue.net_qlock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tries to construct the return status data for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all the pending requests in the sleepq that it can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * satisfy.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dopending(rdc_group_t *group, netwriteres *netretp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pendcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_pendvec_t *pendvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepq_t *sq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pendsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&group->ra_queue.net_qlock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pendcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pendsz = RDC_MAXPENDQ * sizeof (net_pendvec_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pendvec = kmem_alloc(pendsz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now look at the Q of pending tasks, attempt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to write any that have been waiting for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * me to complete my write, and piggyback
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * their results in my reply, by setiing pendcnt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the number of extra requests sucessfully
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * processed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (group->sleepq && group->sleepq->seq == group->seq) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdc_net_dataset *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq = group->sleepq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->sleepq = sq->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[sq->sindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[sq->sindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->io_kstats) {
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 dset = rdc_net_get_set(sq->sindex, sq->idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!pending: %s:%s rdc_net_get_set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed", urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as we failed to get the pointer, there
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is no point expecting the cleanup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * code in rdc_delsleepq() to get it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * either.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->idx = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto cleansq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->idx = -1; /* marked as cleaned up */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdc_writemaxfba(krdc, urdc, dset, sq->seq, sq->nocache);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(ret)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_setbitind(&pendcnt, pendvec, dset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->seq, sq->pindex, sq->qpos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!dopending: Write of pending "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "asynchronous task failed, with "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sequence number %u for SNDR set %s:%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sq->seq, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(sq->sindex, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecleansq:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = sq->seq + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group->seq < sq->seq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delsleepq(sq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pendcnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vecsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_netwrite6) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!packing pend, count %d", pendcnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecsz = pendcnt * sizeof (net_pendvec_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netretp->vecdata.vecdata_val =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc(vecsz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netretp->vecdata.vecdata_len = pendcnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(pendvec, netretp->vecdata.vecdata_val, vecsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pendvec, pendsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take the dset and allocate and fill in the vector.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_vec_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dset2vec(rdc_net_dataset_t *dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *vecret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->nitems > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->head);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->tail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecret = kmem_alloc((dset->nitems + 1) * sizeof (nsc_vec_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vecret == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE((dset->nitems + 1) * sizeof (nsc_vec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = dset->head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < dset->nitems; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ditem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecret[i].sv_addr = ditem->dptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecret[i].sv_len = ditem->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = ditem->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Null terminate.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecret[i].sv_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vecret[i].sv_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check the list and count matches.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ditem == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (vecret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Split the local read into maxfba sized chunks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 on an error, or a valid idx on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_readmaxfba(int cd, nsc_off_t pos, nsc_size_t fbalen, int nocache)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t veclist[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t fbaleft;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t mfba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t spos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int eintr_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idx = 0; /* error status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mfba = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtype = RDC_RAW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[cd];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte eintr_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _rdc_rsrv_devs(krdc, rtype, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == EINTR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++eintr_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((ret == EINTR) && (eintr_count < MAX_EINTR_COUNT));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!readmaxfba: reserve failed on set %s:%s %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf, urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * create a dataset that we can hang all the buffers from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = rdc_net_add_set(cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!readmaxfba: Unable to allocate dset on set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s:%s", urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->pos = pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->fbalen = fbalen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_maxfbas(RDC_U_FD(krdc), 0, &mfba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!readmaxfba: msc_maxfbas failed on set %s:%s "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d", urdc->secondary.intf, urdc->secondary.file, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spos = pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fbaleft = fbalen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veclist[1].sv_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veclist[1].sv_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fbaleft > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba = min(mfba, fbaleft);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_alloc_buf(RDC_U_FD(krdc), spos, fba,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nocache|NSC_NODATA, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!readmaxfba: alloc failed on set"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s:%s %d", urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = kmem_alloc(sizeof (rdc_net_dataitem_t), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(sizeof (rdc_net_dataitem_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->len = FBA_SIZE(fba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->mlen = ditem->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->dptr = kmem_alloc(ditem->len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(ditem->len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem->next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * construct a vector list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veclist[0].sv_addr = ditem->dptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veclist[0].sv_len = ditem->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_vec = veclist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rdc_combyread(krdc, urdc, handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * place on linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->nitems++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset->head == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->head = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail->next = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail = ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now its linked, clear this so its not freed twice.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fbaleft -= fba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spos += fba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all the reads have worked, store the results.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idx = dset->id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_put_set(cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_del_set(cd, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ditem) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ditem->dptr, ditem->mlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-ditem->mlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ditem, sizeof (*ditem));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-sizeof (*ditem));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (idx);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * perform both a local read, and if multihop, a remote read.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 on success, or errno on failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_combyread(rdc_k_info_t *krdc, rdc_u_info_t *urdc, nsc_buf_t *handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * read it.
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = nsc_read(handle, handle->sb_pos, handle->sb_len, NSC_READ);
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 (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!combyread: read failed on set %s:%s %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf, urdc->secondary.file, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_VOL_FAILED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "comby read failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MULTI(krdc) && (ktmp = krdc->multi_next) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (utmp = &rdc_u_info[ktmp->index]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_ENABLED(utmp) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_mflags(utmp) & RDC_RSYNC_NEEDED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = _rdc_remote_read(ktmp, handle, handle->sb_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_len, NSC_READ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set NSC_MIXED so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that the cache will throw away this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer when we free it since we have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * combined data from multiple sources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * into a single buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Currently we don't use the cache for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data volumes, so comment this out.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle->sb_flag |= NSC_MIXED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!combyread: remote read failed on "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "set %s:%s %d", utmp->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp->secondary.file, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
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 +=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove and free all the collected dsets for this set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_dump_dsets(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetloop:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((dset = krdc->net_dataset) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset->inuse) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the dset to be in use, the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * service routine r_net_write6() must
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be active with it. It will free
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it eventually.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto tloop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_free_set(krdc, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_stallzero(int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int init = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static kcondvar_t cv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static kmutex_t mu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (init == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&cv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&mu, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&mu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (flag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_stall0 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_stall0 = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 2:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_stall0 == 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&cv, &mu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "Bad flag value passed to rdc_stallzero");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&mu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RDC protocol version 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_disptab_t rdc_disptab5[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PROC Idempotent */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_null, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getsize, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_write5, TRUE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_read, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_state4, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_ping4, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bmap, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bdata, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getstate4, FALSE }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RDC protocol version 6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_disptab_t rdc_disptab6[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PROC Idempotent */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_null, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getsize6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_write6, TRUE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_read6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_state4, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_ping4, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bmap6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bdata6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getstate4, FALSE }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RDC protocol version 7
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_disptab_t rdc_disptab7[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PROC Idempotent */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_null, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getsize6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_write6, TRUE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_read6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_state, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_ping7, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bmap6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_bdata6, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdcsrv_noproc, FALSE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { r_net_getstate7, FALSE }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdcsrv_t rdc_srvtab[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdc_disptab5, sizeof (rdc_disptab5) / sizeof (*rdc_disptab5) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdc_disptab6, sizeof (rdc_disptab6) / sizeof (*rdc_disptab6) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { rdc_disptab7, sizeof (rdc_disptab7) / sizeof (*rdc_disptab7) }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebool_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_xdr_netbuf(XDR *xdrs, struct netbuf *objp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we're decoding and the caller has already allocated a buffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * throw away maxlen, since it doesn't apply to the caller's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer. xdr_bytes will return an error if the buffer isn't big
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * enough.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xdrs->x_op == XDR_DECODE && objp->buf != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t maxlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!xdr_u_int(xdrs, &maxlen))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!xdr_u_int(xdrs, (uint_t *)&objp->maxlen))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xdr_bytes(xdrs, (char **)&(objp->buf),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint_t *)&(objp->len), objp->maxlen));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}